diff options
Diffstat (limited to 'libs/renderengine/include/renderengine/RenderEngine.h')
-rw-r--r-- | libs/renderengine/include/renderengine/RenderEngine.h | 245 |
1 files changed, 135 insertions, 110 deletions
diff --git a/libs/renderengine/include/renderengine/RenderEngine.h b/libs/renderengine/include/renderengine/RenderEngine.h index e06e1287c1..5964bc3927 100644 --- a/libs/renderengine/include/renderengine/RenderEngine.h +++ b/libs/renderengine/include/renderengine/RenderEngine.h @@ -17,24 +17,43 @@ #ifndef SF_RENDERENGINE_H_ #define SF_RENDERENGINE_H_ -#include <stdint.h> -#include <sys/types.h> -#include <memory> - #include <android-base/unique_fd.h> #include <math/mat4.h> #include <renderengine/DisplaySettings.h> +#include <renderengine/ExternalTexture.h> #include <renderengine/Framebuffer.h> #include <renderengine/Image.h> #include <renderengine/LayerSettings.h> +#include <stdint.h> +#include <sys/types.h> #include <ui/GraphicTypes.h> #include <ui/Transform.h> +#include <future> +#include <memory> + /** - * Allows to set RenderEngine backend to GLES (default) or Vulkan (NOT yet supported). + * Allows to set RenderEngine backend to GLES (default) or SkiaGL (NOT yet supported). */ #define PROPERTY_DEBUG_RENDERENGINE_BACKEND "debug.renderengine.backend" +/** + * Turns on recording of skia commands in SkiaGL version of the RE. This property + * defines number of milliseconds for the recording to take place. A non zero value + * turns on the recording. + */ +#define PROPERTY_DEBUG_RENDERENGINE_CAPTURE_SKIA_MS "debug.renderengine.capture_skia_ms" + +/** + * Set to the most recently saved file once the capture is finished. + */ +#define PROPERTY_DEBUG_RENDERENGINE_CAPTURE_FILENAME "debug.renderengine.capture_filename" + +/** + * Allows recording of Skia drawing commands with systrace. + */ +#define PROPERTY_SKIA_ATRACE_ENABLED "debug.renderengine.skia_atrace_enabled" + struct ANativeWindowBuffer; namespace android { @@ -44,12 +63,16 @@ class Region; namespace renderengine { -class BindNativeBufferAsFramebuffer; +class ExternalTexture; class Image; class Mesh; class Texture; struct RenderEngineCreationArgs; +namespace threaded { +class RenderEngineThreaded; +} + namespace impl { class RenderEngine; } @@ -65,9 +88,17 @@ public: LOW = 1, MEDIUM = 2, HIGH = 3, + REALTIME = 4, + }; + + enum class RenderEngineType { + GLES = 1, + THREADED = 2, + SKIA_GL = 3, + SKIA_GL_THREADED = 4, }; - static std::unique_ptr<impl::RenderEngine> create(const RenderEngineCreationArgs& args); + static std::unique_ptr<RenderEngine> create(const RenderEngineCreationArgs& args); virtual ~RenderEngine() = 0; @@ -75,52 +106,15 @@ public: // This interface, while still in use until a suitable replacement is built, // should be considered deprecated, minus some methods which still may be // used to support legacy behavior. - virtual void primeCache() const = 0; + virtual std::future<void> primeCache() = 0; // dump the extension strings. always call the base class. virtual void dump(std::string& result) = 0; - virtual bool useNativeFenceSync() const = 0; - virtual bool useWaitSync() const = 0; virtual void genTextures(size_t count, uint32_t* names) = 0; virtual void deleteTextures(size_t count, uint32_t const* names) = 0; - virtual void bindExternalTextureImage(uint32_t texName, const Image& image) = 0; - // Legacy public method used by devices that don't support native fence - // synchronization in their GPU driver, as this method provides implicit - // synchronization for latching buffers. - virtual status_t bindExternalTextureBuffer(uint32_t texName, const sp<GraphicBuffer>& buffer, - const sp<Fence>& fence) = 0; - // Caches Image resources for this buffer, but does not bind the buffer to - // a particular texture. - // Note that work is deferred to an additional thread, i.e. this call - // is made asynchronously, but the caller can expect that cache/unbind calls - // are performed in a manner that's conflict serializable, i.e. unbinding - // a buffer should never occur before binding the buffer if the caller - // called {bind, cache}ExternalTextureBuffer before calling unbind. - virtual void cacheExternalTextureBuffer(const sp<GraphicBuffer>& buffer) = 0; - // Removes internal resources referenced by the bufferId. This method should be - // invoked when the caller will no longer hold a reference to a GraphicBuffer - // and needs to clean up its resources. - // Note that work is deferred to an additional thread, i.e. this call - // is made asynchronously, but the caller can expect that cache/unbind calls - // are performed in a manner that's conflict serializable, i.e. unbinding - // a buffer should never occur before binding the buffer if the caller - // called {bind, cache}ExternalTextureBuffer before calling unbind. - virtual void unbindExternalTextureBuffer(uint64_t bufferId) = 0; - // When binding a native buffer, it must be done before setViewportAndProjection - // Returns NO_ERROR when binds successfully, NO_MEMORY when there's no memory for allocation. - virtual status_t bindFrameBuffer(Framebuffer* framebuffer) = 0; - virtual void unbindFrameBuffer(Framebuffer* framebuffer) = 0; - // Clean-up method that should be called on the main thread after the - // drawFence returned by drawLayers fires. This method will free up - // resources used by the most recently drawn frame. If the frame is still - // being drawn, then this call is silently ignored. - // - // Returns true if resources were cleaned up, and false if we didn't need to - // do any work. - virtual bool cleanupPostRender() = 0; - // queries + // queries that are required to be thread safe virtual size_t getMaxTextureSize() const = 0; virtual size_t getMaxViewportDims() const = 0; @@ -128,9 +122,16 @@ public: // ----- BEGIN NEW INTERFACE ----- + // queries that are required to be thread safe virtual bool isProtected() const = 0; virtual bool supportsProtectedContent() const = 0; - virtual bool useProtectedContext(bool useProtectedContext) = 0; + + // Attempt to switch RenderEngine into and out of protectedContext mode + virtual void useProtectedContext(bool useProtectedContext) = 0; + + // Notify RenderEngine of changes to the dimensions of the primary display + // so that it can configure its internal caches accordingly. + virtual void onPrimaryDisplaySizeChanged(ui::Size size) = 0; // Renders layers for a particular display via GPU composition. This method // should be called for every display that needs to be rendered via the GPU. @@ -163,17 +164,74 @@ public: // now, this always returns NO_ERROR. virtual status_t drawLayers(const DisplaySettings& display, const std::vector<const LayerSettings*>& layers, - ANativeWindowBuffer* buffer, const bool useFramebufferCache, - base::unique_fd&& bufferFence, base::unique_fd* drawFence) = 0; + const std::shared_ptr<ExternalTexture>& buffer, + const bool useFramebufferCache, base::unique_fd&& bufferFence, + base::unique_fd* drawFence) = 0; + + // Clean-up method that should be called on the main thread after the + // drawFence returned by drawLayers fires. This method will free up + // resources used by the most recently drawn frame. If the frame is still + // being drawn, then the implementation is free to silently ignore this call. + virtual void cleanupPostRender() = 0; + + virtual void cleanFramebufferCache() = 0; + // Returns the priority this context was actually created with. Note: this may not be + // the same as specified at context creation time, due to implementation limits on the + // number of contexts that can be created at a specific priority level in the system. + virtual int getContextPriority() = 0; + + // Returns true if blur was requested in the RenderEngineCreationArgs and the implementation + // also supports background blur. If false, no blur will be applied when drawing layers. This + // query is required to be thread safe. + virtual bool supportsBackgroundBlur() = 0; + + // Returns the current type of RenderEngine instance that was created. + // TODO(b/180767535): This is only implemented to allow for backend-specific behavior, which + // we should not allow in general, so remove this. + RenderEngineType getRenderEngineType() const { return mRenderEngineType; } + + static void validateInputBufferUsage(const sp<GraphicBuffer>&); + static void validateOutputBufferUsage(const sp<GraphicBuffer>&); protected: - // Gets a framebuffer to render to. This framebuffer may or may not be - // cached depending on the implementation. - // - // Note that this method does not transfer ownership, so the caller most not - // live longer than RenderEngine. - virtual Framebuffer* getFramebufferForDrawing() = 0; - friend class BindNativeBufferAsFramebuffer; + RenderEngine() : RenderEngine(RenderEngineType::GLES) {} + + RenderEngine(RenderEngineType type) : mRenderEngineType(type) {} + + // Maps GPU resources for this buffer. + // Note that work may be deferred to an additional thread, i.e. this call + // is made asynchronously, but the caller can expect that map/unmap calls + // are performed in a manner that's conflict serializable, i.e. unmapping + // a buffer should never occur before binding the buffer if the caller + // called mapExternalTextureBuffer before calling unmap. + // Note also that if the buffer contains protected content, then mapping those GPU resources may + // be deferred until the buffer is really used for drawing. This is because typical SoCs that + // support protected memory only support a limited amount, so optimisitically mapping protected + // memory may be too burdensome. If a buffer contains protected content and the RenderEngine + // implementation supports protected context, then GPU resources may be mapped into both the + // protected and unprotected contexts. + // If the buffer may ever be written to by RenderEngine, then isRenderable must be true. + virtual void mapExternalTextureBuffer(const sp<GraphicBuffer>& buffer, bool isRenderable) = 0; + // Unmaps GPU resources used by this buffer. This method should be + // invoked when the caller will no longer hold a reference to a GraphicBuffer + // and needs to clean up its resources. + // Note that if there are multiple callers holding onto the same buffer, then the buffer's + // resources may be internally ref-counted to guard against use-after-free errors. Note that + // work may be deferred to an additional thread, i.e. this call is expected to be made + // asynchronously, but the caller can expect that map/unmap calls are performed in a manner + // that's conflict serializable, i.e. unmap a buffer should never occur before binding the + // buffer if the caller called mapExternalTextureBuffer before calling unmap. + virtual void unmapExternalTextureBuffer(const sp<GraphicBuffer>& buffer) = 0; + + // A thread safe query to determine if any post rendering cleanup is necessary. Returning true + // is a signal that calling the postRenderCleanup method would be a no-op and that callers can + // avoid any thread synchronization that may be required by directly calling postRenderCleanup. + virtual bool canSkipPostRenderCleanup() const = 0; + + friend class ExternalTexture; + friend class threaded::RenderEngineThreaded; + friend class RenderEngineTest_cleanupPostRender_cleansUpOnce_Test; + const RenderEngineType mRenderEngineType; }; struct RenderEngineCreationArgs { @@ -184,26 +242,25 @@ struct RenderEngineCreationArgs { bool precacheToneMapperShaderOnly; bool supportsBackgroundBlur; RenderEngine::ContextPriority contextPriority; + RenderEngine::RenderEngineType renderEngineType; struct Builder; private: // must be created by Builder via constructor with full argument list - RenderEngineCreationArgs( - int _pixelFormat, - uint32_t _imageCacheSize, - bool _useColorManagement, - bool _enableProtectedContext, - bool _precacheToneMapperShaderOnly, - bool _supportsBackgroundBlur, - RenderEngine::ContextPriority _contextPriority) - : pixelFormat(_pixelFormat) - , imageCacheSize(_imageCacheSize) - , useColorManagement(_useColorManagement) - , enableProtectedContext(_enableProtectedContext) - , precacheToneMapperShaderOnly(_precacheToneMapperShaderOnly) - , supportsBackgroundBlur(_supportsBackgroundBlur) - , contextPriority(_contextPriority) {} + RenderEngineCreationArgs(int _pixelFormat, uint32_t _imageCacheSize, bool _useColorManagement, + bool _enableProtectedContext, bool _precacheToneMapperShaderOnly, + bool _supportsBackgroundBlur, + RenderEngine::ContextPriority _contextPriority, + RenderEngine::RenderEngineType _renderEngineType) + : pixelFormat(_pixelFormat), + imageCacheSize(_imageCacheSize), + useColorManagement(_useColorManagement), + enableProtectedContext(_enableProtectedContext), + precacheToneMapperShaderOnly(_precacheToneMapperShaderOnly), + supportsBackgroundBlur(_supportsBackgroundBlur), + contextPriority(_contextPriority), + renderEngineType(_renderEngineType) {} RenderEngineCreationArgs() = delete; }; @@ -238,10 +295,14 @@ struct RenderEngineCreationArgs::Builder { this->contextPriority = contextPriority; return *this; } + Builder& setRenderEngineType(RenderEngine::RenderEngineType renderEngineType) { + this->renderEngineType = renderEngineType; + return *this; + } RenderEngineCreationArgs build() const { return RenderEngineCreationArgs(pixelFormat, imageCacheSize, useColorManagement, enableProtectedContext, precacheToneMapperShaderOnly, - supportsBackgroundBlur, contextPriority); + supportsBackgroundBlur, contextPriority, renderEngineType); } private: @@ -253,46 +314,10 @@ private: bool precacheToneMapperShaderOnly = false; bool supportsBackgroundBlur = false; RenderEngine::ContextPriority contextPriority = RenderEngine::ContextPriority::MEDIUM; + RenderEngine::RenderEngineType renderEngineType = + RenderEngine::RenderEngineType::SKIA_GL_THREADED; }; -class BindNativeBufferAsFramebuffer { -public: - BindNativeBufferAsFramebuffer(RenderEngine& engine, ANativeWindowBuffer* buffer, - const bool useFramebufferCache) - : mEngine(engine), mFramebuffer(mEngine.getFramebufferForDrawing()), mStatus(NO_ERROR) { - mStatus = mFramebuffer->setNativeWindowBuffer(buffer, mEngine.isProtected(), - useFramebufferCache) - ? mEngine.bindFrameBuffer(mFramebuffer) - : NO_MEMORY; - } - ~BindNativeBufferAsFramebuffer() { - mFramebuffer->setNativeWindowBuffer(nullptr, false, /*arbitrary*/ true); - mEngine.unbindFrameBuffer(mFramebuffer); - } - status_t getStatus() const { return mStatus; } - -private: - RenderEngine& mEngine; - Framebuffer* mFramebuffer; - status_t mStatus; -}; - -namespace impl { - -// impl::RenderEngine contains common implementation that is graphics back-end agnostic. -class RenderEngine : public renderengine::RenderEngine { -public: - virtual ~RenderEngine() = 0; - - bool useNativeFenceSync() const override; - bool useWaitSync() const override; - -protected: - RenderEngine(const RenderEngineCreationArgs& args); - const RenderEngineCreationArgs mArgs; -}; - -} // namespace impl } // namespace renderengine } // namespace android |