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