| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2013 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
| Peiyong Lin | 7e219eb | 2018-12-03 05:40:42 -0800 | [diff] [blame] | 17 | #ifndef SF_GLESRENDERENGINE_H_ | 
|  | 18 | #define SF_GLESRENDERENGINE_H_ | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 19 |  | 
| Alec Mouri | 554d06e | 2018-12-20 00:15:33 -0800 | [diff] [blame] | 20 | #include <condition_variable> | 
| Alec Mouri | da4cf3b | 2019-02-12 15:33:01 -0800 | [diff] [blame] | 21 | #include <deque> | 
| Alec Mouri | 554d06e | 2018-12-20 00:15:33 -0800 | [diff] [blame] | 22 | #include <mutex> | 
|  | 23 | #include <queue> | 
|  | 24 | #include <thread> | 
| Alec Mouri | da4cf3b | 2019-02-12 15:33:01 -0800 | [diff] [blame] | 25 | #include <unordered_map> | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 26 |  | 
| Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 27 | #include <EGL/egl.h> | 
|  | 28 | #include <EGL/eglext.h> | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 29 | #include <GLES2/gl2.h> | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 30 | #include <android-base/thread_annotations.h> | 
| Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 31 | #include <renderengine/RenderEngine.h> | 
| Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 32 | #include <renderengine/private/Description.h> | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 33 | #include <sys/types.h> | 
| Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 34 | #include <ui/FenceResult.h> | 
| Vishnu Nair | f19544f | 2020-02-03 11:23:26 -0800 | [diff] [blame] | 35 | #include "GLShadowTexture.h" | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 36 | #include "ImageManager.h" | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 37 |  | 
| Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 38 | #define EGL_NO_CONFIG ((EGLConfig)0) | 
|  | 39 |  | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 40 | namespace android { | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 41 |  | 
| Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 42 | namespace renderengine { | 
|  | 43 |  | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 44 | class Mesh; | 
| Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 45 | class Texture; | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 46 |  | 
| Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 47 | namespace gl { | 
| Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 48 |  | 
| Peiyong Lin | f1bada9 | 2018-08-29 09:39:31 -0700 | [diff] [blame] | 49 | class GLImage; | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 50 | class BlurFilter; | 
| Peiyong Lin | f1bada9 | 2018-08-29 09:39:31 -0700 | [diff] [blame] | 51 |  | 
| Alec Mouri | 081be4c | 2020-09-16 10:24:47 -0700 | [diff] [blame] | 52 | class GLESRenderEngine : public RenderEngine { | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 53 | public: | 
| Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 54 | static std::unique_ptr<GLESRenderEngine> create(const RenderEngineCreationArgs& args); | 
| Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 55 |  | 
| Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 56 | GLESRenderEngine(const RenderEngineCreationArgs& args, EGLDisplay display, EGLConfig config, | 
| Peiyong Lin | d8460c8 | 2020-07-28 16:04:22 -0700 | [diff] [blame] | 57 | EGLContext ctxt, EGLSurface stub, EGLContext protectedContext, | 
|  | 58 | EGLSurface protectedStub); | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 59 | ~GLESRenderEngine() override EXCLUDES(mRenderingMutex); | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 60 |  | 
| Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 61 | std::future<void> primeCache() override; | 
| Peiyong Lin | 60bedb5 | 2018-09-05 10:47:31 -0700 | [diff] [blame] | 62 | void genTextures(size_t count, uint32_t* names) override; | 
|  | 63 | void deleteTextures(size_t count, uint32_t const* names) override; | 
| Patrick Williams | 8aed5d2 | 2022-10-31 22:18:10 +0000 | [diff] [blame] | 64 | bool isProtected() const { return mInProtectedContext; } | 
| Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 65 | bool supportsProtectedContent() const override; | 
| Derek Sollenberger | 1ec2fb5 | 2021-06-16 15:11:27 -0400 | [diff] [blame] | 66 | void useProtectedContext(bool useProtectedContext) override; | 
| Derek Sollenberger | d3f6065 | 2021-06-11 15:34:36 -0400 | [diff] [blame] | 67 | void cleanupPostRender() override; | 
| Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 68 | int getContextPriority() override; | 
| Derek Sollenberger | b399837 | 2021-02-16 15:16:56 -0500 | [diff] [blame] | 69 | bool supportsBackgroundBlur() override { return mBlurFilter != nullptr; } | 
| Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 70 | void onActiveDisplaySizeChanged(ui::Size size) override {} | 
| Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 71 |  | 
| Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 72 | EGLDisplay getEGLDisplay() const { return mEGLDisplay; } | 
| Alec Mouri | da4cf3b | 2019-02-12 15:33:01 -0800 | [diff] [blame] | 73 | // Creates an output image for rendering to | 
| Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 74 | EGLImageKHR createFramebufferImageIfNeeded(ANativeWindowBuffer* nativeBuffer, bool isProtected, | 
| Alec Mouri | ef44c2d | 2019-07-15 15:27:22 -0700 | [diff] [blame] | 75 | bool useFramebufferCache) | 
|  | 76 | EXCLUDES(mFramebufferImageCacheMutex); | 
| Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 77 |  | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 78 | // Test-only methods | 
|  | 79 | // Returns true iff mImageCache contains an image keyed by bufferId | 
|  | 80 | bool isImageCachedForTesting(uint64_t bufferId) EXCLUDES(mRenderingMutex); | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 81 | // Returns true iff texName was previously generated by RenderEngine and was | 
|  | 82 | // not destroyed. | 
|  | 83 | bool isTextureNameKnownForTesting(uint32_t texName); | 
|  | 84 | // Returns the buffer ID of the content bound to texName, or nullopt if no | 
|  | 85 | // such mapping exists. | 
|  | 86 | std::optional<uint64_t> getBufferIdForTextureNameForTesting(uint32_t texName); | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 87 | // Returns true iff mFramebufferImageCache contains an image keyed by bufferId | 
| Alec Mouri | ef44c2d | 2019-07-15 15:27:22 -0700 | [diff] [blame] | 88 | bool isFramebufferImageCachedForTesting(uint64_t bufferId) | 
|  | 89 | EXCLUDES(mFramebufferImageCacheMutex); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 90 | // These are wrappers around public methods above, but exposing Barrier | 
|  | 91 | // objects so that tests can block. | 
|  | 92 | std::shared_ptr<ImageManager::Barrier> cacheExternalTextureBufferForTesting( | 
|  | 93 | const sp<GraphicBuffer>& buffer); | 
|  | 94 | std::shared_ptr<ImageManager::Barrier> unbindExternalTextureBufferForTesting(uint64_t bufferId); | 
| Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 95 |  | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 96 | protected: | 
| John Reck | 992a2ca | 2020-09-03 17:20:56 -0700 | [diff] [blame] | 97 | Framebuffer* getFramebufferForDrawing(); | 
| Alec Mouri | ef44c2d | 2019-07-15 15:27:22 -0700 | [diff] [blame] | 98 | void dump(std::string& result) override EXCLUDES(mRenderingMutex) | 
|  | 99 | EXCLUDES(mFramebufferImageCacheMutex); | 
| Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 100 | size_t getMaxTextureSize() const override; | 
|  | 101 | size_t getMaxViewportDims() const override; | 
| Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 102 | void mapExternalTextureBuffer(const sp<GraphicBuffer>& buffer, bool isRenderable) | 
|  | 103 | EXCLUDES(mRenderingMutex); | 
|  | 104 | void unmapExternalTextureBuffer(const sp<GraphicBuffer>& buffer) EXCLUDES(mRenderingMutex); | 
| Derek Sollenberger | d3f6065 | 2021-06-11 15:34:36 -0400 | [diff] [blame] | 105 | bool canSkipPostRenderCleanup() const override; | 
| Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 106 | void drawLayersInternal(const std::shared_ptr<std::promise<FenceResult>>&& resultPromise, | 
| Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 107 | const DisplaySettings& display, | 
| Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 108 | const std::vector<LayerSettings>& layers, | 
| Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 109 | const std::shared_ptr<ExternalTexture>& buffer, | 
|  | 110 | const bool useFramebufferCache, base::unique_fd&& bufferFence) override; | 
| Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 111 |  | 
|  | 112 | private: | 
| John Reck | 992a2ca | 2020-09-03 17:20:56 -0700 | [diff] [blame] | 113 | friend class BindNativeBufferAsFramebuffer; | 
|  | 114 |  | 
| Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 115 | enum GlesVersion { | 
|  | 116 | GLES_VERSION_1_0 = 0x10000, | 
|  | 117 | GLES_VERSION_1_1 = 0x10001, | 
|  | 118 | GLES_VERSION_2_0 = 0x20000, | 
|  | 119 | GLES_VERSION_3_0 = 0x30000, | 
|  | 120 | }; | 
|  | 121 |  | 
| Alec Mouri | 8002fca | 2019-06-28 15:24:13 -0700 | [diff] [blame] | 122 | static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig); | 
| Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 123 | static GlesVersion parseGlesVersion(const char* str); | 
| Peiyong Lin | a5e9f1b | 2018-11-27 22:49:37 -0800 | [diff] [blame] | 124 | static EGLContext createEglContext(EGLDisplay display, EGLConfig config, | 
| Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 125 | EGLContext shareContext, | 
|  | 126 | std::optional<ContextPriority> contextPriority, | 
| Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 127 | Protection protection); | 
| Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 128 | static std::optional<RenderEngine::ContextPriority> createContextPriority( | 
|  | 129 | const RenderEngineCreationArgs& args); | 
| Peiyong Lin | d8460c8 | 2020-07-28 16:04:22 -0700 | [diff] [blame] | 130 | static EGLSurface createStubEglPbufferSurface(EGLDisplay display, EGLConfig config, | 
|  | 131 | int hwcFormat, Protection protection); | 
| Alec Mouri | 8002fca | 2019-06-28 15:24:13 -0700 | [diff] [blame] | 132 | std::unique_ptr<Framebuffer> createFramebuffer(); | 
|  | 133 | std::unique_ptr<Image> createImage(); | 
|  | 134 | void checkErrors() const; | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 135 | void checkErrors(const char* tag) const; | 
| Peiyong Lin | 1c09761 | 2019-03-22 16:21:46 -0700 | [diff] [blame] | 136 | void setScissor(const Rect& region); | 
|  | 137 | void disableScissor(); | 
| Alec Mouri | 554d06e | 2018-12-20 00:15:33 -0800 | [diff] [blame] | 138 | bool waitSync(EGLSyncKHR sync, EGLint flags); | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 139 | status_t cacheExternalTextureBufferInternal(const sp<GraphicBuffer>& buffer) | 
|  | 140 | EXCLUDES(mRenderingMutex); | 
|  | 141 | void unbindExternalTextureBufferInternal(uint64_t bufferId) EXCLUDES(mRenderingMutex); | 
| John Reck | 992a2ca | 2020-09-03 17:20:56 -0700 | [diff] [blame] | 142 | status_t bindFrameBuffer(Framebuffer* framebuffer); | 
|  | 143 | void unbindFrameBuffer(Framebuffer* framebuffer); | 
|  | 144 | void bindExternalTextureImage(uint32_t texName, const Image& image); | 
| Alec Mouri | 04eae7d | 2020-09-14 15:34:16 -0700 | [diff] [blame] | 145 | void bindExternalTextureBuffer(uint32_t texName, const sp<GraphicBuffer>& buffer, | 
|  | 146 | const sp<Fence>& fence) EXCLUDES(mRenderingMutex); | 
| Marin Shalamanov | 23c31af | 2020-09-09 15:01:47 +0200 | [diff] [blame] | 147 | void cleanFramebufferCache() EXCLUDES(mFramebufferImageCacheMutex) override; | 
| Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 148 |  | 
| Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 149 | // A data space is considered HDR data space if it has BT2020 color space | 
|  | 150 | // with PQ or HLG transfer function. | 
|  | 151 | bool isHdrDataSpace(const ui::Dataspace dataSpace) const; | 
|  | 152 | bool needsXYZTransformMatrix() const; | 
| Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 153 | // Defines the viewport, and sets the projection matrix to the projection | 
|  | 154 | // defined by the clip. | 
|  | 155 | void setViewportAndProjection(Rect viewport, Rect clip); | 
| Alec Mouri | 539319f | 2018-12-19 17:56:23 -0800 | [diff] [blame] | 156 | // Evicts stale images from the buffer cache. | 
|  | 157 | void evictImages(const std::vector<LayerSettings>& layers); | 
| Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 158 | // Computes the cropping window for the layer and sets up cropping | 
|  | 159 | // coordinates for the mesh. | 
|  | 160 | FloatRect setupLayerCropping(const LayerSettings& layer, Mesh& mesh); | 
| Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 161 |  | 
| Peiyong Lin | 1c09761 | 2019-03-22 16:21:46 -0700 | [diff] [blame] | 162 | // We do a special handling for rounded corners when it's possible to turn off blending | 
|  | 163 | // for the majority of the layer. The rounded corners needs to turn on blending such that | 
|  | 164 | // we can set the alpha value correctly, however, only the corners need this, and since | 
|  | 165 | // blending is an expensive operation, we want to turn off blending when it's not necessary. | 
|  | 166 | void handleRoundedCorners(const DisplaySettings& display, const LayerSettings& layer, | 
|  | 167 | const Mesh& mesh); | 
| Alec Mouri | 8002fca | 2019-06-28 15:24:13 -0700 | [diff] [blame] | 168 | base::unique_fd flush(); | 
|  | 169 | bool finish(); | 
|  | 170 | bool waitFence(base::unique_fd fenceFd); | 
|  | 171 | void clearWithColor(float red, float green, float blue, float alpha); | 
|  | 172 | void fillRegionWithColor(const Region& region, float red, float green, float blue, float alpha); | 
| Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 173 | void handleShadow(const FloatRect& casterRect, float casterCornerRadius, | 
|  | 174 | const ShadowSettings& shadowSettings); | 
| Alec Mouri | 8002fca | 2019-06-28 15:24:13 -0700 | [diff] [blame] | 175 | void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture, | 
|  | 176 | const half4& color, float cornerRadius); | 
|  | 177 | void setupLayerTexturing(const Texture& texture); | 
|  | 178 | void setupFillWithColor(float r, float g, float b, float a); | 
|  | 179 | void setColorTransform(const mat4& colorTransform); | 
| KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 180 | void setDisplayColorTransform(const mat4& colorTransform); | 
| Alec Mouri | 8002fca | 2019-06-28 15:24:13 -0700 | [diff] [blame] | 181 | void disableTexturing(); | 
|  | 182 | void disableBlending(); | 
|  | 183 | void setupCornerRadiusCropSize(float width, float height); | 
|  | 184 |  | 
|  | 185 | // HDR and color management related functions and state | 
|  | 186 | void setSourceY410BT2020(bool enable); | 
|  | 187 | void setSourceDataSpace(ui::Dataspace source); | 
|  | 188 | void setOutputDataSpace(ui::Dataspace dataspace); | 
|  | 189 | void setDisplayMaxLuminance(const float maxLuminance); | 
|  | 190 |  | 
|  | 191 | // drawing | 
|  | 192 | void drawMesh(const Mesh& mesh); | 
| Peiyong Lin | 1c09761 | 2019-03-22 16:21:46 -0700 | [diff] [blame] | 193 |  | 
| Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 194 | EGLDisplay mEGLDisplay; | 
|  | 195 | EGLConfig mEGLConfig; | 
|  | 196 | EGLContext mEGLContext; | 
| Peiyong Lin | d8460c8 | 2020-07-28 16:04:22 -0700 | [diff] [blame] | 197 | EGLSurface mStubSurface; | 
| Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 198 | EGLContext mProtectedEGLContext; | 
| Peiyong Lin | d8460c8 | 2020-07-28 16:04:22 -0700 | [diff] [blame] | 199 | EGLSurface mProtectedStubSurface; | 
| Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 200 | GLint mMaxViewportDims[2]; | 
|  | 201 | GLint mMaxTextureSize; | 
|  | 202 | GLuint mVpWidth; | 
|  | 203 | GLuint mVpHeight; | 
|  | 204 | Description mState; | 
| Alec Mouri | 2725c09 | 2020-11-25 09:53:56 -0800 | [diff] [blame] | 205 | std::unique_ptr<GLShadowTexture> mShadowTexture = nullptr; | 
| Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 206 |  | 
| Peiyong Lin | 70b26ce | 2018-09-18 19:02:39 -0700 | [diff] [blame] | 207 | mat4 mSrgbToXyz; | 
| Peiyong Lin | 70b26ce | 2018-09-18 19:02:39 -0700 | [diff] [blame] | 208 | mat4 mDisplayP3ToXyz; | 
| Valerie Hau | eb8e076 | 2018-11-06 10:10:42 -0800 | [diff] [blame] | 209 | mat4 mBt2020ToXyz; | 
| Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 210 | mat4 mXyzToSrgb; | 
|  | 211 | mat4 mXyzToDisplayP3; | 
|  | 212 | mat4 mXyzToBt2020; | 
| Valerie Hau | eb8e076 | 2018-11-06 10:10:42 -0800 | [diff] [blame] | 213 | mat4 mSrgbToDisplayP3; | 
|  | 214 | mat4 mSrgbToBt2020; | 
|  | 215 | mat4 mDisplayP3ToSrgb; | 
|  | 216 | mat4 mDisplayP3ToBt2020; | 
|  | 217 | mat4 mBt2020ToSrgb; | 
|  | 218 | mat4 mBt2020ToDisplayP3; | 
| Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 219 |  | 
| Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 220 | bool mInProtectedContext = false; | 
| Alec Mouri | 554d06e | 2018-12-20 00:15:33 -0800 | [diff] [blame] | 221 | // If set to true, then enables tracing flush() and finish() to systrace. | 
|  | 222 | bool mTraceGpuCompletion = false; | 
| Alec Mouri | da4cf3b | 2019-02-12 15:33:01 -0800 | [diff] [blame] | 223 | // Maximum size of mFramebufferImageCache. If more images would be cached, then (approximately) | 
|  | 224 | // the last recently used buffer should be kicked out. | 
|  | 225 | uint32_t mFramebufferImageCacheSize = 0; | 
|  | 226 |  | 
|  | 227 | // Cache of output images, keyed by corresponding GraphicBuffer ID. | 
| Alec Mouri | ef44c2d | 2019-07-15 15:27:22 -0700 | [diff] [blame] | 228 | std::deque<std::pair<uint64_t, EGLImageKHR>> mFramebufferImageCache | 
|  | 229 | GUARDED_BY(mFramebufferImageCacheMutex); | 
|  | 230 | // The only reason why we have this mutex is so that we don't segfault when | 
|  | 231 | // dumping info. | 
|  | 232 | std::mutex mFramebufferImageCacheMutex; | 
| Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 233 |  | 
|  | 234 | // Current dataspace of layer being rendered | 
|  | 235 | ui::Dataspace mDataSpace = ui::Dataspace::UNKNOWN; | 
|  | 236 |  | 
|  | 237 | // Current output dataspace of the render engine | 
|  | 238 | ui::Dataspace mOutputDataSpace = ui::Dataspace::UNKNOWN; | 
|  | 239 |  | 
| Peiyong Lin | 13effd1 | 2018-07-24 17:01:47 -0700 | [diff] [blame] | 240 | // Whether device supports color management, currently color management | 
|  | 241 | // supports sRGB, DisplayP3 color spaces. | 
|  | 242 | const bool mUseColorManagement = false; | 
| Alec Mouri | 554d06e | 2018-12-20 00:15:33 -0800 | [diff] [blame] | 243 |  | 
| Alec Mouri | 081be4c | 2020-09-16 10:24:47 -0700 | [diff] [blame] | 244 | // Whether only shaders performing tone mapping from HDR to SDR will be generated on | 
|  | 245 | // primeCache(). | 
|  | 246 | const bool mPrecacheToneMapperShaderOnly = false; | 
|  | 247 |  | 
| Alec Mouri | 539319f | 2018-12-19 17:56:23 -0800 | [diff] [blame] | 248 | // Cache of GL images that we'll store per GraphicBuffer ID | 
| Alec Mouri | f049727 | 2019-03-11 15:53:11 -0700 | [diff] [blame] | 249 | std::unordered_map<uint64_t, std::unique_ptr<Image>> mImageCache GUARDED_BY(mRenderingMutex); | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 250 | std::unordered_map<uint32_t, std::optional<uint64_t>> mTextureView; | 
|  | 251 |  | 
| Alec Mouri | f049727 | 2019-03-11 15:53:11 -0700 | [diff] [blame] | 252 | // Mutex guarding rendering operations, so that: | 
|  | 253 | // 1. GL operations aren't interleaved, and | 
|  | 254 | // 2. Internal state related to rendering that is potentially modified by | 
|  | 255 | // multiple threads is guaranteed thread-safe. | 
|  | 256 | std::mutex mRenderingMutex; | 
|  | 257 |  | 
| Alec Mouri | 820c740 | 2019-01-23 13:02:39 -0800 | [diff] [blame] | 258 | std::unique_ptr<Framebuffer> mDrawingBuffer; | 
| Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 259 | // this is a 1x1 RGB buffer, but over-allocate in case a driver wants more | 
|  | 260 | // memory or if it needs to satisfy alignment requirements. In this case: | 
|  | 261 | // assume that each channel requires 4 bytes, and add 3 additional bytes to | 
|  | 262 | // ensure that we align on a word. Allocating 16 bytes will provide a | 
|  | 263 | // guarantee that we don't clobber memory. | 
|  | 264 | uint32_t mPlaceholderDrawBuffer[4]; | 
| Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 265 | // Placeholder buffer and image, similar to mPlaceholderDrawBuffer, but | 
|  | 266 | // instead these are intended for cleaning up texture memory with the | 
|  | 267 | // GL_TEXTURE_EXTERNAL_OES target. | 
|  | 268 | ANativeWindowBuffer* mPlaceholderBuffer = nullptr; | 
|  | 269 | EGLImage mPlaceholderImage = EGL_NO_IMAGE_KHR; | 
| Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 270 | sp<Fence> mLastDrawFence; | 
|  | 271 | // Store a separate boolean checking if prior resources were cleaned up, as | 
|  | 272 | // devices that don't support native sync fences can't rely on a last draw | 
|  | 273 | // fence that doesn't exist. | 
|  | 274 | bool mPriorResourcesCleaned = true; | 
| Alec Mouri | 820c740 | 2019-01-23 13:02:39 -0800 | [diff] [blame] | 275 |  | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 276 | // Blur effect processor, only instantiated when a layer requests it. | 
|  | 277 | BlurFilter* mBlurFilter = nullptr; | 
|  | 278 |  | 
| Alec Mouri | 554d06e | 2018-12-20 00:15:33 -0800 | [diff] [blame] | 279 | class FlushTracer { | 
|  | 280 | public: | 
|  | 281 | FlushTracer(GLESRenderEngine* engine); | 
|  | 282 | ~FlushTracer(); | 
|  | 283 | void queueSync(EGLSyncKHR sync) EXCLUDES(mMutex); | 
|  | 284 |  | 
|  | 285 | struct QueueEntry { | 
|  | 286 | EGLSyncKHR mSync = nullptr; | 
|  | 287 | uint64_t mFrameNum = 0; | 
|  | 288 | }; | 
|  | 289 |  | 
|  | 290 | private: | 
|  | 291 | void loop(); | 
|  | 292 | GLESRenderEngine* const mEngine; | 
|  | 293 | std::thread mThread; | 
|  | 294 | std::condition_variable_any mCondition; | 
|  | 295 | std::mutex mMutex; | 
|  | 296 | std::queue<QueueEntry> mQueue GUARDED_BY(mMutex); | 
|  | 297 | uint64_t mFramesQueued GUARDED_BY(mMutex) = 0; | 
|  | 298 | bool mRunning = true; | 
|  | 299 | }; | 
|  | 300 | friend class FlushTracer; | 
| Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 301 | friend class ImageManager; | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 302 | friend class GLFramebuffer; | 
|  | 303 | friend class BlurFilter; | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 304 | friend class GenericProgram; | 
| Alec Mouri | 554d06e | 2018-12-20 00:15:33 -0800 | [diff] [blame] | 305 | std::unique_ptr<FlushTracer> mFlushTracer; | 
| Alec Mouri | 2725c09 | 2020-11-25 09:53:56 -0800 | [diff] [blame] | 306 | std::unique_ptr<ImageManager> mImageManager; | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 307 | }; | 
|  | 308 |  | 
| Peiyong Lin | 46080ef | 2018-10-26 18:43:14 -0700 | [diff] [blame] | 309 | } // namespace gl | 
|  | 310 | } // namespace renderengine | 
|  | 311 | } // namespace android | 
| Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 312 |  | 
| Peiyong Lin | 7e219eb | 2018-12-03 05:40:42 -0800 | [diff] [blame] | 313 | #endif /* SF_GLESRENDERENGINE_H_ */ |