Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -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 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 17 | #ifndef SF_RENDERENGINE_H_ |
| 18 | #define SF_RENDERENGINE_H_ |
| 19 | |
Chia-I Wu | 767fcf7 | 2017-11-30 22:07:38 -0800 | [diff] [blame] | 20 | #include <android-base/unique_fd.h> |
Chia-I Wu | b027f80 | 2017-11-29 14:00:52 -0800 | [diff] [blame] | 21 | #include <math/mat4.h> |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 22 | #include <renderengine/DisplaySettings.h> |
Alec Mouri | 2daef3c | 2021-04-02 16:29:27 -0700 | [diff] [blame] | 23 | #include <renderengine/ExternalTexture.h> |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 24 | #include <renderengine/Framebuffer.h> |
Peiyong Lin | 60bedb5 | 2018-09-05 10:47:31 -0700 | [diff] [blame] | 25 | #include <renderengine/Image.h> |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 26 | #include <renderengine/LayerSettings.h> |
Alec Mouri | 2daef3c | 2021-04-02 16:29:27 -0700 | [diff] [blame] | 27 | #include <stdint.h> |
| 28 | #include <sys/types.h> |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 29 | #include <ui/GraphicTypes.h> |
| 30 | #include <ui/Transform.h> |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 31 | |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 32 | #include <future> |
Alec Mouri | 2daef3c | 2021-04-02 16:29:27 -0700 | [diff] [blame] | 33 | #include <memory> |
| 34 | |
Peiyong Lin | b491b3c | 2018-08-15 14:53:34 -0700 | [diff] [blame] | 35 | /** |
Ana Krulec | 70d15b1b | 2020-12-01 10:05:15 -0800 | [diff] [blame] | 36 | * Allows to set RenderEngine backend to GLES (default) or SkiaGL (NOT yet supported). |
Peiyong Lin | b491b3c | 2018-08-15 14:53:34 -0700 | [diff] [blame] | 37 | */ |
| 38 | #define PROPERTY_DEBUG_RENDERENGINE_BACKEND "debug.renderengine.backend" |
Jesse Hall | 19e8729 | 2013-12-23 21:02:15 -0800 | [diff] [blame] | 39 | |
Ana Krulec | 70d15b1b | 2020-12-01 10:05:15 -0800 | [diff] [blame] | 40 | /** |
| 41 | * Turns on recording of skia commands in SkiaGL version of the RE. This property |
| 42 | * defines number of milliseconds for the recording to take place. A non zero value |
| 43 | * turns on the recording. |
| 44 | */ |
| 45 | #define PROPERTY_DEBUG_RENDERENGINE_CAPTURE_SKIA_MS "debug.renderengine.capture_skia_ms" |
| 46 | |
Leon Scroggins III | 2eca03f | 2021-05-25 15:30:43 -0400 | [diff] [blame] | 47 | /** |
| 48 | * Set to the most recently saved file once the capture is finished. |
| 49 | */ |
| 50 | #define PROPERTY_DEBUG_RENDERENGINE_CAPTURE_FILENAME "debug.renderengine.capture_filename" |
| 51 | |
rnlee | c6a7364 | 2021-06-04 14:16:42 -0700 | [diff] [blame] | 52 | /** |
| 53 | * Allows recording of Skia drawing commands with systrace. |
| 54 | */ |
| 55 | #define PROPERTY_SKIA_ATRACE_ENABLED "debug.renderengine.skia_atrace_enabled" |
| 56 | |
Chia-I Wu | eadbaa6 | 2017-11-09 11:26:15 -0800 | [diff] [blame] | 57 | struct ANativeWindowBuffer; |
| 58 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 59 | namespace android { |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 60 | |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 61 | class Rect; |
| 62 | class Region; |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 63 | |
| 64 | namespace renderengine { |
| 65 | |
Alec Mouri | 2daef3c | 2021-04-02 16:29:27 -0700 | [diff] [blame] | 66 | class ExternalTexture; |
Chia-I Wu | 401ef83 | 2017-12-01 10:52:22 -0800 | [diff] [blame] | 67 | class Image; |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 68 | class Mesh; |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 69 | class Texture; |
Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 70 | struct RenderEngineCreationArgs; |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 71 | struct RenderEngineResult; |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 72 | |
Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame] | 73 | namespace threaded { |
| 74 | class RenderEngineThreaded; |
| 75 | } |
| 76 | |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 77 | namespace impl { |
| 78 | class RenderEngine; |
| 79 | } |
Chia-I Wu | f846a35 | 2017-11-10 09:22:52 -0800 | [diff] [blame] | 80 | |
Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 81 | enum class Protection { |
| 82 | UNPROTECTED = 1, |
| 83 | PROTECTED = 2, |
| 84 | }; |
| 85 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 86 | class RenderEngine { |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 87 | public: |
Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 88 | enum class ContextPriority { |
| 89 | LOW = 1, |
| 90 | MEDIUM = 2, |
| 91 | HIGH = 3, |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 92 | REALTIME = 4, |
Kalle Raita | bbdcf1f | 2017-05-22 15:47:46 -0700 | [diff] [blame] | 93 | }; |
Jesse Hall | 05f8c70 | 2013-12-23 20:44:38 -0800 | [diff] [blame] | 94 | |
Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame] | 95 | enum class RenderEngineType { |
| 96 | GLES = 1, |
| 97 | THREADED = 2, |
John Reck | 67b1e2b | 2020-08-26 13:17:24 -0700 | [diff] [blame] | 98 | SKIA_GL = 3, |
Ana Krulec | 243dbc2 | 2021-01-06 13:17:08 -0800 | [diff] [blame] | 99 | SKIA_GL_THREADED = 4, |
Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame] | 100 | }; |
| 101 | |
Leon Scroggins III | c77162c | 2021-11-16 17:13:08 -0500 | [diff] [blame] | 102 | static std::unique_ptr<RenderEngine> create(const RenderEngineCreationArgs& args); |
Peiyong Lin | f11f39b | 2018-09-05 14:37:41 -0700 | [diff] [blame] | 103 | |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 104 | virtual ~RenderEngine() = 0; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 105 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 106 | // ----- BEGIN DEPRECATED INTERFACE ----- |
| 107 | // This interface, while still in use until a suitable replacement is built, |
| 108 | // should be considered deprecated, minus some methods which still may be |
| 109 | // used to support legacy behavior. |
Ady Abraham | fe2a6db | 2021-06-09 15:41:37 -0700 | [diff] [blame] | 110 | virtual std::future<void> primeCache() = 0; |
Dan Stoza | 4e63777 | 2016-07-28 13:31:51 -0700 | [diff] [blame] | 111 | |
Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 112 | // dump the extension strings. always call the base class. |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 113 | virtual void dump(std::string& result) = 0; |
Mathias Agopian | 458197d | 2013-08-15 14:56:51 -0700 | [diff] [blame] | 114 | |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 115 | virtual void genTextures(size_t count, uint32_t* names) = 0; |
| 116 | virtual void deleteTextures(size_t count, uint32_t const* names) = 0; |
Alec Mouri | 368e158 | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 117 | |
Derek Sollenberger | 4bea01e | 2021-04-09 13:59:37 -0400 | [diff] [blame] | 118 | // queries that are required to be thread safe |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 119 | virtual size_t getMaxTextureSize() const = 0; |
| 120 | virtual size_t getMaxViewportDims() const = 0; |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 121 | |
| 122 | // ----- END DEPRECATED INTERFACE ----- |
| 123 | |
| 124 | // ----- BEGIN NEW INTERFACE ----- |
| 125 | |
Derek Sollenberger | 4bea01e | 2021-04-09 13:59:37 -0400 | [diff] [blame] | 126 | // queries that are required to be thread safe |
Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 127 | virtual bool isProtected() const = 0; |
| 128 | virtual bool supportsProtectedContent() const = 0; |
Derek Sollenberger | 4bea01e | 2021-04-09 13:59:37 -0400 | [diff] [blame] | 129 | |
| 130 | // Attempt to switch RenderEngine into and out of protectedContext mode |
Derek Sollenberger | 1ec2fb5 | 2021-06-16 15:11:27 -0400 | [diff] [blame] | 131 | virtual void useProtectedContext(bool useProtectedContext) = 0; |
Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 132 | |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 133 | // Notify RenderEngine of changes to the dimensions of the active display |
Derek Sollenberger | c4a05e1 | 2021-03-24 16:45:20 -0400 | [diff] [blame] | 134 | // so that it can configure its internal caches accordingly. |
Ady Abraham | ed3290f | 2021-05-17 15:12:14 -0700 | [diff] [blame] | 135 | virtual void onActiveDisplaySizeChanged(ui::Size size) = 0; |
Derek Sollenberger | c4a05e1 | 2021-03-24 16:45:20 -0400 | [diff] [blame] | 136 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 137 | // Renders layers for a particular display via GPU composition. This method |
| 138 | // should be called for every display that needs to be rendered via the GPU. |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 139 | // @param display The display-wide settings that should be applied prior to |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 140 | // drawing any layers. |
Alec Mouri | 3d7c561 | 2019-07-09 13:51:37 -0700 | [diff] [blame] | 141 | // |
| 142 | // Assumptions when calling this method: |
| 143 | // 1. There is exactly one caller - i.e. multi-threading is not supported. |
| 144 | // 2. Additional threads may be calling the {bind,cache}ExternalTexture |
| 145 | // methods above. But the main thread is responsible for holding resources |
| 146 | // such that Image destruction does not occur while this method is called. |
| 147 | // |
| 148 | // TODO(b/136806342): This should behavior should ideally be fixed since |
| 149 | // the above two assumptions are brittle, as conditional thread safetyness |
| 150 | // may be insufficient when maximizing rendering performance in the future. |
| 151 | // |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 152 | // @param layers The layers to draw onto the display, in Z-order. |
| 153 | // @param buffer The buffer which will be drawn to. This buffer will be |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 154 | // ready once drawFence fires. |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 155 | // @param useFramebufferCache True if the framebuffer cache should be used. |
| 156 | // If an implementation does not cache output framebuffers, then this |
| 157 | // parameter does nothing. |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 158 | // @param bufferFence Fence signalling that the buffer is ready to be drawn |
| 159 | // to. |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 160 | // @return A future object of RenderEngineResult struct indicating whether |
| 161 | // drawing was successful in async mode. |
| 162 | virtual std::future<RenderEngineResult> drawLayers( |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 163 | const DisplaySettings& display, const std::vector<LayerSettings>& layers, |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 164 | const std::shared_ptr<ExternalTexture>& buffer, const bool useFramebufferCache, |
| 165 | base::unique_fd&& bufferFence); |
Derek Sollenberger | d3f6065 | 2021-06-11 15:34:36 -0400 | [diff] [blame] | 166 | |
| 167 | // Clean-up method that should be called on the main thread after the |
| 168 | // drawFence returned by drawLayers fires. This method will free up |
| 169 | // resources used by the most recently drawn frame. If the frame is still |
| 170 | // being drawn, then the implementation is free to silently ignore this call. |
| 171 | virtual void cleanupPostRender() = 0; |
| 172 | |
Marin Shalamanov | 23c31af | 2020-09-09 15:01:47 +0200 | [diff] [blame] | 173 | virtual void cleanFramebufferCache() = 0; |
Alec Mouri | d6f0946 | 2020-12-07 11:18:17 -0800 | [diff] [blame] | 174 | // Returns the priority this context was actually created with. Note: this may not be |
| 175 | // the same as specified at context creation time, due to implementation limits on the |
| 176 | // number of contexts that can be created at a specific priority level in the system. |
| 177 | virtual int getContextPriority() = 0; |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 178 | |
Derek Sollenberger | b399837 | 2021-02-16 15:16:56 -0500 | [diff] [blame] | 179 | // Returns true if blur was requested in the RenderEngineCreationArgs and the implementation |
Derek Sollenberger | 4bea01e | 2021-04-09 13:59:37 -0400 | [diff] [blame] | 180 | // also supports background blur. If false, no blur will be applied when drawing layers. This |
| 181 | // query is required to be thread safe. |
Derek Sollenberger | b399837 | 2021-02-16 15:16:56 -0500 | [diff] [blame] | 182 | virtual bool supportsBackgroundBlur() = 0; |
| 183 | |
Alec Mouri | 0d99510 | 2021-02-24 16:53:38 -0800 | [diff] [blame] | 184 | // Returns the current type of RenderEngine instance that was created. |
| 185 | // TODO(b/180767535): This is only implemented to allow for backend-specific behavior, which |
| 186 | // we should not allow in general, so remove this. |
| 187 | RenderEngineType getRenderEngineType() const { return mRenderEngineType; } |
| 188 | |
Ady Abraham | 193426d | 2021-02-18 14:01:53 -0800 | [diff] [blame] | 189 | static void validateInputBufferUsage(const sp<GraphicBuffer>&); |
| 190 | static void validateOutputBufferUsage(const sp<GraphicBuffer>&); |
| 191 | |
Matt Buckley | ef51fba | 2021-10-12 19:30:12 +0000 | [diff] [blame^] | 192 | // Allows flinger to get the render engine thread id for power management with ADPF |
| 193 | // Returns the tid of the renderengine thread if it's threaded, and std::nullopt otherwise |
| 194 | virtual std::optional<pid_t> getRenderEngineTid() const { return std::nullopt; } |
| 195 | |
Alec Mouri | 820c740 | 2019-01-23 13:02:39 -0800 | [diff] [blame] | 196 | protected: |
rnlee | c6a7364 | 2021-06-04 14:16:42 -0700 | [diff] [blame] | 197 | RenderEngine() : RenderEngine(RenderEngineType::GLES) {} |
| 198 | |
| 199 | RenderEngine(RenderEngineType type) : mRenderEngineType(type) {} |
| 200 | |
Alec Mouri | 2daef3c | 2021-04-02 16:29:27 -0700 | [diff] [blame] | 201 | // Maps GPU resources for this buffer. |
| 202 | // Note that work may be deferred to an additional thread, i.e. this call |
| 203 | // is made asynchronously, but the caller can expect that map/unmap calls |
| 204 | // are performed in a manner that's conflict serializable, i.e. unmapping |
| 205 | // a buffer should never occur before binding the buffer if the caller |
| 206 | // called mapExternalTextureBuffer before calling unmap. |
| 207 | // Note also that if the buffer contains protected content, then mapping those GPU resources may |
| 208 | // be deferred until the buffer is really used for drawing. This is because typical SoCs that |
| 209 | // support protected memory only support a limited amount, so optimisitically mapping protected |
| 210 | // memory may be too burdensome. If a buffer contains protected content and the RenderEngine |
| 211 | // implementation supports protected context, then GPU resources may be mapped into both the |
| 212 | // protected and unprotected contexts. |
| 213 | // If the buffer may ever be written to by RenderEngine, then isRenderable must be true. |
| 214 | virtual void mapExternalTextureBuffer(const sp<GraphicBuffer>& buffer, bool isRenderable) = 0; |
| 215 | // Unmaps GPU resources used by this buffer. This method should be |
| 216 | // invoked when the caller will no longer hold a reference to a GraphicBuffer |
| 217 | // and needs to clean up its resources. |
| 218 | // Note that if there are multiple callers holding onto the same buffer, then the buffer's |
| 219 | // resources may be internally ref-counted to guard against use-after-free errors. Note that |
| 220 | // work may be deferred to an additional thread, i.e. this call is expected to be made |
| 221 | // asynchronously, but the caller can expect that map/unmap calls are performed in a manner |
| 222 | // that's conflict serializable, i.e. unmap a buffer should never occur before binding the |
| 223 | // buffer if the caller called mapExternalTextureBuffer before calling unmap. |
| 224 | virtual void unmapExternalTextureBuffer(const sp<GraphicBuffer>& buffer) = 0; |
Derek Sollenberger | d3f6065 | 2021-06-11 15:34:36 -0400 | [diff] [blame] | 225 | |
| 226 | // A thread safe query to determine if any post rendering cleanup is necessary. Returning true |
| 227 | // is a signal that calling the postRenderCleanup method would be a no-op and that callers can |
| 228 | // avoid any thread synchronization that may be required by directly calling postRenderCleanup. |
| 229 | virtual bool canSkipPostRenderCleanup() const = 0; |
| 230 | |
Alec Mouri | 2daef3c | 2021-04-02 16:29:27 -0700 | [diff] [blame] | 231 | friend class ExternalTexture; |
Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame] | 232 | friend class threaded::RenderEngineThreaded; |
Derek Sollenberger | d3f6065 | 2021-06-11 15:34:36 -0400 | [diff] [blame] | 233 | friend class RenderEngineTest_cleanupPostRender_cleansUpOnce_Test; |
Alec Mouri | 0d99510 | 2021-02-24 16:53:38 -0800 | [diff] [blame] | 234 | const RenderEngineType mRenderEngineType; |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 235 | |
| 236 | virtual void drawLayersInternal( |
| 237 | const std::shared_ptr<std::promise<RenderEngineResult>>&& resultPromise, |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 238 | const DisplaySettings& display, const std::vector<LayerSettings>& layers, |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 239 | const std::shared_ptr<ExternalTexture>& buffer, const bool useFramebufferCache, |
| 240 | base::unique_fd&& bufferFence) = 0; |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 241 | }; |
| 242 | |
Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 243 | struct RenderEngineCreationArgs { |
| 244 | int pixelFormat; |
| 245 | uint32_t imageCacheSize; |
| 246 | bool useColorManagement; |
| 247 | bool enableProtectedContext; |
| 248 | bool precacheToneMapperShaderOnly; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 249 | bool supportsBackgroundBlur; |
Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 250 | RenderEngine::ContextPriority contextPriority; |
Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame] | 251 | RenderEngine::RenderEngineType renderEngineType; |
Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 252 | |
| 253 | struct Builder; |
| 254 | |
| 255 | private: |
| 256 | // must be created by Builder via constructor with full argument list |
Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame] | 257 | RenderEngineCreationArgs(int _pixelFormat, uint32_t _imageCacheSize, bool _useColorManagement, |
| 258 | bool _enableProtectedContext, bool _precacheToneMapperShaderOnly, |
| 259 | bool _supportsBackgroundBlur, |
| 260 | RenderEngine::ContextPriority _contextPriority, |
| 261 | RenderEngine::RenderEngineType _renderEngineType) |
| 262 | : pixelFormat(_pixelFormat), |
| 263 | imageCacheSize(_imageCacheSize), |
| 264 | useColorManagement(_useColorManagement), |
| 265 | enableProtectedContext(_enableProtectedContext), |
| 266 | precacheToneMapperShaderOnly(_precacheToneMapperShaderOnly), |
| 267 | supportsBackgroundBlur(_supportsBackgroundBlur), |
| 268 | contextPriority(_contextPriority), |
| 269 | renderEngineType(_renderEngineType) {} |
Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 270 | RenderEngineCreationArgs() = delete; |
| 271 | }; |
| 272 | |
| 273 | struct RenderEngineCreationArgs::Builder { |
| 274 | Builder() {} |
| 275 | |
| 276 | Builder& setPixelFormat(int pixelFormat) { |
| 277 | this->pixelFormat = pixelFormat; |
| 278 | return *this; |
| 279 | } |
| 280 | Builder& setImageCacheSize(uint32_t imageCacheSize) { |
| 281 | this->imageCacheSize = imageCacheSize; |
| 282 | return *this; |
| 283 | } |
| 284 | Builder& setUseColorManagerment(bool useColorManagement) { |
| 285 | this->useColorManagement = useColorManagement; |
| 286 | return *this; |
| 287 | } |
| 288 | Builder& setEnableProtectedContext(bool enableProtectedContext) { |
| 289 | this->enableProtectedContext = enableProtectedContext; |
| 290 | return *this; |
| 291 | } |
| 292 | Builder& setPrecacheToneMapperShaderOnly(bool precacheToneMapperShaderOnly) { |
| 293 | this->precacheToneMapperShaderOnly = precacheToneMapperShaderOnly; |
| 294 | return *this; |
| 295 | } |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 296 | Builder& setSupportsBackgroundBlur(bool supportsBackgroundBlur) { |
| 297 | this->supportsBackgroundBlur = supportsBackgroundBlur; |
| 298 | return *this; |
| 299 | } |
Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 300 | Builder& setContextPriority(RenderEngine::ContextPriority contextPriority) { |
| 301 | this->contextPriority = contextPriority; |
| 302 | return *this; |
| 303 | } |
Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame] | 304 | Builder& setRenderEngineType(RenderEngine::RenderEngineType renderEngineType) { |
| 305 | this->renderEngineType = renderEngineType; |
| 306 | return *this; |
| 307 | } |
Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 308 | RenderEngineCreationArgs build() const { |
| 309 | return RenderEngineCreationArgs(pixelFormat, imageCacheSize, useColorManagement, |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 310 | enableProtectedContext, precacheToneMapperShaderOnly, |
Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame] | 311 | supportsBackgroundBlur, contextPriority, renderEngineType); |
Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | private: |
| 315 | // 1 means RGBA_8888 |
| 316 | int pixelFormat = 1; |
| 317 | uint32_t imageCacheSize = 0; |
| 318 | bool useColorManagement = true; |
| 319 | bool enableProtectedContext = false; |
| 320 | bool precacheToneMapperShaderOnly = false; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 321 | bool supportsBackgroundBlur = false; |
Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 322 | RenderEngine::ContextPriority contextPriority = RenderEngine::ContextPriority::MEDIUM; |
Derek Sollenberger | 8b305ef | 2021-04-09 14:11:47 +0000 | [diff] [blame] | 323 | RenderEngine::RenderEngineType renderEngineType = |
| 324 | RenderEngine::RenderEngineType::SKIA_GL_THREADED; |
Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 325 | }; |
| 326 | |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 327 | struct RenderEngineResult { |
| 328 | // status indicates if drawing is successful |
| 329 | status_t status; |
| 330 | // drawFence will fire when the buffer has been drawn to and is ready to be examined. |
| 331 | base::unique_fd drawFence; |
| 332 | }; |
| 333 | |
Peiyong Lin | 46080ef | 2018-10-26 18:43:14 -0700 | [diff] [blame] | 334 | } // namespace renderengine |
| 335 | } // namespace android |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 336 | |
| 337 | #endif /* SF_RENDERENGINE_H_ */ |