blob: 915706675a70920839a551ab67f256e7ebba24bf [file] [log] [blame]
Mathias Agopian875d8e12013-06-07 15:35:48 -07001/*
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 Agopian875d8e12013-06-07 15:35:48 -070017#ifndef SF_RENDERENGINE_H_
18#define SF_RENDERENGINE_H_
19
20#include <stdint.h>
21#include <sys/types.h>
Peiyong Lin833074a2018-08-28 11:53:54 -070022#include <memory>
Mathias Agopian875d8e12013-06-07 15:35:48 -070023
Chia-I Wu767fcf72017-11-30 22:07:38 -080024#include <android-base/unique_fd.h>
Chia-I Wub027f802017-11-29 14:00:52 -080025#include <math/mat4.h>
Alec Mouri6e57f682018-09-29 20:45:08 -070026#include <renderengine/DisplaySettings.h>
Peiyong Line5a9a7f2018-08-30 15:32:13 -070027#include <renderengine/Framebuffer.h>
Peiyong Lin60bedb52018-09-05 10:47:31 -070028#include <renderengine/Image.h>
Alec Mouri6e57f682018-09-29 20:45:08 -070029#include <renderengine/LayerSettings.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070030#include <ui/GraphicTypes.h>
31#include <ui/Transform.h>
Mathias Agopian875d8e12013-06-07 15:35:48 -070032
Peiyong Linb491b3c2018-08-15 14:53:34 -070033/**
Ana Krulec70d15b1b2020-12-01 10:05:15 -080034 * Allows to set RenderEngine backend to GLES (default) or SkiaGL (NOT yet supported).
Peiyong Linb491b3c2018-08-15 14:53:34 -070035 */
36#define PROPERTY_DEBUG_RENDERENGINE_BACKEND "debug.renderengine.backend"
Jesse Hall19e87292013-12-23 21:02:15 -080037
Ana Krulec70d15b1b2020-12-01 10:05:15 -080038/**
39 * Turns on recording of skia commands in SkiaGL version of the RE. This property
40 * defines number of milliseconds for the recording to take place. A non zero value
41 * turns on the recording.
42 */
43#define PROPERTY_DEBUG_RENDERENGINE_CAPTURE_SKIA_MS "debug.renderengine.capture_skia_ms"
44
Chia-I Wueadbaa62017-11-09 11:26:15 -080045struct ANativeWindowBuffer;
46
Mathias Agopian875d8e12013-06-07 15:35:48 -070047namespace android {
Mathias Agopian875d8e12013-06-07 15:35:48 -070048
Mathias Agopian3f844832013-08-07 21:24:32 -070049class Rect;
50class Region;
Peiyong Lin833074a2018-08-28 11:53:54 -070051
52namespace renderengine {
53
Chia-I Wu401ef832017-12-01 10:52:22 -080054class Image;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070055class Mesh;
Peiyong Lin833074a2018-08-28 11:53:54 -070056class Texture;
Peiyong Lin4137a1d2019-10-09 10:39:09 -070057struct RenderEngineCreationArgs;
Lloyd Pique144e1162017-12-20 16:44:52 -080058
Ana Krulec9bc9dc62020-02-26 12:16:40 -080059namespace threaded {
60class RenderEngineThreaded;
61}
62
Lloyd Pique144e1162017-12-20 16:44:52 -080063namespace impl {
64class RenderEngine;
65}
Chia-I Wuf846a352017-11-10 09:22:52 -080066
Peiyong Linfb530cf2018-12-15 05:07:38 +000067enum class Protection {
68 UNPROTECTED = 1,
69 PROTECTED = 2,
70};
71
Mathias Agopian875d8e12013-06-07 15:35:48 -070072class RenderEngine {
Mathias Agopian875d8e12013-06-07 15:35:48 -070073public:
Peiyong Lin4137a1d2019-10-09 10:39:09 -070074 enum class ContextPriority {
75 LOW = 1,
76 MEDIUM = 2,
77 HIGH = 3,
Alec Mourid6f09462020-12-07 11:18:17 -080078 REALTIME = 4,
Kalle Raitabbdcf1f2017-05-22 15:47:46 -070079 };
Jesse Hall05f8c702013-12-23 20:44:38 -080080
Ana Krulec9bc9dc62020-02-26 12:16:40 -080081 enum class RenderEngineType {
82 GLES = 1,
83 THREADED = 2,
John Reck67b1e2b2020-08-26 13:17:24 -070084 SKIA_GL = 3,
Ana Krulec9bc9dc62020-02-26 12:16:40 -080085 };
86
Ana Krulec15f7cf32020-05-12 11:57:42 -070087 static std::unique_ptr<RenderEngine> create(const RenderEngineCreationArgs& args);
Peiyong Linf11f39b2018-09-05 14:37:41 -070088
Lloyd Pique144e1162017-12-20 16:44:52 -080089 virtual ~RenderEngine() = 0;
Mathias Agopian875d8e12013-06-07 15:35:48 -070090
Alec Mouri6e57f682018-09-29 20:45:08 -070091 // ----- BEGIN DEPRECATED INTERFACE -----
92 // This interface, while still in use until a suitable replacement is built,
93 // should be considered deprecated, minus some methods which still may be
94 // used to support legacy behavior.
Lloyd Pique144e1162017-12-20 16:44:52 -080095 virtual void primeCache() const = 0;
Dan Stoza4e637772016-07-28 13:31:51 -070096
Mathias Agopian458197d2013-08-15 14:56:51 -070097 // dump the extension strings. always call the base class.
Yiwei Zhang5434a782018-12-05 18:06:32 -080098 virtual void dump(std::string& result) = 0;
Mathias Agopian458197d2013-08-15 14:56:51 -070099
Lloyd Pique144e1162017-12-20 16:44:52 -0800100 virtual void genTextures(size_t count, uint32_t* names) = 0;
101 virtual void deleteTextures(size_t count, uint32_t const* names) = 0;
Alec Mourid7b3a8b2019-03-21 11:44:18 -0700102 // Caches Image resources for this buffer, but does not bind the buffer to
103 // a particular texture.
Alec Mouri16a99402019-07-29 16:37:30 -0700104 // Note that work is deferred to an additional thread, i.e. this call
105 // is made asynchronously, but the caller can expect that cache/unbind calls
106 // are performed in a manner that's conflict serializable, i.e. unbinding
107 // a buffer should never occur before binding the buffer if the caller
108 // called {bind, cache}ExternalTextureBuffer before calling unbind.
109 virtual void cacheExternalTextureBuffer(const sp<GraphicBuffer>& buffer) = 0;
Alec Mourib5c4f352019-02-19 19:46:38 -0800110 // Removes internal resources referenced by the bufferId. This method should be
111 // invoked when the caller will no longer hold a reference to a GraphicBuffer
112 // and needs to clean up its resources.
Alec Mouri16a99402019-07-29 16:37:30 -0700113 // Note that work is deferred to an additional thread, i.e. this call
114 // is made asynchronously, but the caller can expect that cache/unbind calls
115 // are performed in a manner that's conflict serializable, i.e. unbinding
116 // a buffer should never occur before binding the buffer if the caller
117 // called {bind, cache}ExternalTextureBuffer before calling unbind.
Alec Mourib5c4f352019-02-19 19:46:38 -0800118 virtual void unbindExternalTextureBuffer(uint64_t bufferId) = 0;
Alec Mouri368e1582020-08-13 10:14:29 -0700119
120 enum class CleanupMode {
121 CLEAN_OUTPUT_RESOURCES,
122 CLEAN_ALL,
123 };
Lingfeng Yang2e4fef62020-04-24 14:48:43 +0000124 // Clean-up method that should be called on the main thread after the
125 // drawFence returned by drawLayers fires. This method will free up
126 // resources used by the most recently drawn frame. If the frame is still
127 // being drawn, then this call is silently ignored.
128 //
Alec Mouri368e1582020-08-13 10:14:29 -0700129 // If mode is CLEAN_OUTPUT_RESOURCES, then only resources related to the
130 // output framebuffer are cleaned up, including the sibling texture.
131 //
132 // If mode is CLEAN_ALL, then we also cleanup resources related to any input
133 // buffers.
134 //
Lingfeng Yang2e4fef62020-04-24 14:48:43 +0000135 // Returns true if resources were cleaned up, and false if we didn't need to
136 // do any work.
Alec Mouri368e1582020-08-13 10:14:29 -0700137 virtual bool cleanupPostRender(CleanupMode mode = CleanupMode::CLEAN_OUTPUT_RESOURCES) = 0;
Mathias Agopian3f844832013-08-07 21:24:32 -0700138
Mathias Agopian3f844832013-08-07 21:24:32 -0700139 // queries
Mathias Agopian875d8e12013-06-07 15:35:48 -0700140 virtual size_t getMaxTextureSize() const = 0;
141 virtual size_t getMaxViewportDims() const = 0;
Alec Mouri6e57f682018-09-29 20:45:08 -0700142
143 // ----- END DEPRECATED INTERFACE -----
144
145 // ----- BEGIN NEW INTERFACE -----
146
Peiyong Linfb530cf2018-12-15 05:07:38 +0000147 virtual bool isProtected() const = 0;
148 virtual bool supportsProtectedContent() const = 0;
149 virtual bool useProtectedContext(bool useProtectedContext) = 0;
150
Alec Mouri6e57f682018-09-29 20:45:08 -0700151 // Renders layers for a particular display via GPU composition. This method
152 // should be called for every display that needs to be rendered via the GPU.
Alec Mouri1089aed2018-10-25 21:33:57 -0700153 // @param display The display-wide settings that should be applied prior to
Alec Mouri6e57f682018-09-29 20:45:08 -0700154 // drawing any layers.
Alec Mouri3d7c5612019-07-09 13:51:37 -0700155 //
156 // Assumptions when calling this method:
157 // 1. There is exactly one caller - i.e. multi-threading is not supported.
158 // 2. Additional threads may be calling the {bind,cache}ExternalTexture
159 // methods above. But the main thread is responsible for holding resources
160 // such that Image destruction does not occur while this method is called.
161 //
162 // TODO(b/136806342): This should behavior should ideally be fixed since
163 // the above two assumptions are brittle, as conditional thread safetyness
164 // may be insufficient when maximizing rendering performance in the future.
165 //
Alec Mouri6e57f682018-09-29 20:45:08 -0700166 // @param layers The layers to draw onto the display, in Z-order.
167 // @param buffer The buffer which will be drawn to. This buffer will be
Alec Mouri6338c9d2019-02-07 16:57:51 -0800168 // ready once drawFence fires.
Alec Mourife0d72b2019-03-21 14:05:56 -0700169 // @param useFramebufferCache True if the framebuffer cache should be used.
170 // If an implementation does not cache output framebuffers, then this
171 // parameter does nothing.
Alec Mouri6338c9d2019-02-07 16:57:51 -0800172 // @param bufferFence Fence signalling that the buffer is ready to be drawn
173 // to.
Alec Mouri1089aed2018-10-25 21:33:57 -0700174 // @param drawFence A pointer to a fence, which will fire when the buffer
Alec Mouri6e57f682018-09-29 20:45:08 -0700175 // has been drawn to and is ready to be examined. The fence will be
176 // initialized by this method. The caller will be responsible for owning the
177 // fence.
178 // @return An error code indicating whether drawing was successful. For
179 // now, this always returns NO_ERROR.
Alec Mouri1089aed2018-10-25 21:33:57 -0700180 virtual status_t drawLayers(const DisplaySettings& display,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800181 const std::vector<const LayerSettings*>& layers,
Ana Krulecfc874ae2020-02-22 15:39:32 -0800182 const sp<GraphicBuffer>& buffer, const bool useFramebufferCache,
Alec Mourife0d72b2019-03-21 14:05:56 -0700183 base::unique_fd&& bufferFence, base::unique_fd* drawFence) = 0;
Marin Shalamanov23c31af2020-09-09 15:01:47 +0200184 virtual void cleanFramebufferCache() = 0;
Alec Mourid6f09462020-12-07 11:18:17 -0800185 // Returns the priority this context was actually created with. Note: this may not be
186 // the same as specified at context creation time, due to implementation limits on the
187 // number of contexts that can be created at a specific priority level in the system.
188 virtual int getContextPriority() = 0;
Alec Mouri6e57f682018-09-29 20:45:08 -0700189
Alec Mouri820c7402019-01-23 13:02:39 -0800190protected:
Ana Krulec9bc9dc62020-02-26 12:16:40 -0800191 friend class threaded::RenderEngineThreaded;
Lloyd Pique144e1162017-12-20 16:44:52 -0800192};
193
Peiyong Lin4137a1d2019-10-09 10:39:09 -0700194struct RenderEngineCreationArgs {
195 int pixelFormat;
196 uint32_t imageCacheSize;
197 bool useColorManagement;
198 bool enableProtectedContext;
199 bool precacheToneMapperShaderOnly;
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800200 bool supportsBackgroundBlur;
Peiyong Lin4137a1d2019-10-09 10:39:09 -0700201 RenderEngine::ContextPriority contextPriority;
Ana Krulec9bc9dc62020-02-26 12:16:40 -0800202 RenderEngine::RenderEngineType renderEngineType;
Peiyong Lin4137a1d2019-10-09 10:39:09 -0700203
204 struct Builder;
205
206private:
207 // must be created by Builder via constructor with full argument list
Ana Krulec9bc9dc62020-02-26 12:16:40 -0800208 RenderEngineCreationArgs(int _pixelFormat, uint32_t _imageCacheSize, bool _useColorManagement,
209 bool _enableProtectedContext, bool _precacheToneMapperShaderOnly,
210 bool _supportsBackgroundBlur,
211 RenderEngine::ContextPriority _contextPriority,
212 RenderEngine::RenderEngineType _renderEngineType)
213 : pixelFormat(_pixelFormat),
214 imageCacheSize(_imageCacheSize),
215 useColorManagement(_useColorManagement),
216 enableProtectedContext(_enableProtectedContext),
217 precacheToneMapperShaderOnly(_precacheToneMapperShaderOnly),
218 supportsBackgroundBlur(_supportsBackgroundBlur),
219 contextPriority(_contextPriority),
220 renderEngineType(_renderEngineType) {}
Peiyong Lin4137a1d2019-10-09 10:39:09 -0700221 RenderEngineCreationArgs() = delete;
222};
223
224struct RenderEngineCreationArgs::Builder {
225 Builder() {}
226
227 Builder& setPixelFormat(int pixelFormat) {
228 this->pixelFormat = pixelFormat;
229 return *this;
230 }
231 Builder& setImageCacheSize(uint32_t imageCacheSize) {
232 this->imageCacheSize = imageCacheSize;
233 return *this;
234 }
235 Builder& setUseColorManagerment(bool useColorManagement) {
236 this->useColorManagement = useColorManagement;
237 return *this;
238 }
239 Builder& setEnableProtectedContext(bool enableProtectedContext) {
240 this->enableProtectedContext = enableProtectedContext;
241 return *this;
242 }
243 Builder& setPrecacheToneMapperShaderOnly(bool precacheToneMapperShaderOnly) {
244 this->precacheToneMapperShaderOnly = precacheToneMapperShaderOnly;
245 return *this;
246 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800247 Builder& setSupportsBackgroundBlur(bool supportsBackgroundBlur) {
248 this->supportsBackgroundBlur = supportsBackgroundBlur;
249 return *this;
250 }
Peiyong Lin4137a1d2019-10-09 10:39:09 -0700251 Builder& setContextPriority(RenderEngine::ContextPriority contextPriority) {
252 this->contextPriority = contextPriority;
253 return *this;
254 }
Ana Krulec9bc9dc62020-02-26 12:16:40 -0800255 Builder& setRenderEngineType(RenderEngine::RenderEngineType renderEngineType) {
256 this->renderEngineType = renderEngineType;
257 return *this;
258 }
Peiyong Lin4137a1d2019-10-09 10:39:09 -0700259 RenderEngineCreationArgs build() const {
260 return RenderEngineCreationArgs(pixelFormat, imageCacheSize, useColorManagement,
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800261 enableProtectedContext, precacheToneMapperShaderOnly,
Ana Krulec9bc9dc62020-02-26 12:16:40 -0800262 supportsBackgroundBlur, contextPriority, renderEngineType);
Peiyong Lin4137a1d2019-10-09 10:39:09 -0700263 }
264
265private:
266 // 1 means RGBA_8888
267 int pixelFormat = 1;
268 uint32_t imageCacheSize = 0;
269 bool useColorManagement = true;
270 bool enableProtectedContext = false;
271 bool precacheToneMapperShaderOnly = false;
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800272 bool supportsBackgroundBlur = false;
Peiyong Lin4137a1d2019-10-09 10:39:09 -0700273 RenderEngine::ContextPriority contextPriority = RenderEngine::ContextPriority::MEDIUM;
Ana Krulec9bc9dc62020-02-26 12:16:40 -0800274 RenderEngine::RenderEngineType renderEngineType = RenderEngine::RenderEngineType::GLES;
Peiyong Lin4137a1d2019-10-09 10:39:09 -0700275};
276
Peiyong Lin46080ef2018-10-26 18:43:14 -0700277} // namespace renderengine
278} // namespace android
Mathias Agopian875d8e12013-06-07 15:35:48 -0700279
280#endif /* SF_RENDERENGINE_H_ */