diff options
-rw-r--r-- | libs/renderengine/RenderEngine.cpp | 9 | ||||
-rw-r--r-- | libs/renderengine/gl/GLESRenderEngine.cpp | 43 | ||||
-rw-r--r-- | libs/renderengine/gl/GLESRenderEngine.h | 10 | ||||
-rw-r--r-- | libs/renderengine/include/renderengine/RenderEngine.h | 91 | ||||
-rw-r--r-- | libs/renderengine/tests/RenderEngineTest.cpp | 12 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 23 |
6 files changed, 126 insertions, 62 deletions
diff --git a/libs/renderengine/RenderEngine.cpp b/libs/renderengine/RenderEngine.cpp index 166c267bc8..0fdf093b2f 100644 --- a/libs/renderengine/RenderEngine.cpp +++ b/libs/renderengine/RenderEngine.cpp @@ -24,23 +24,22 @@ namespace android { namespace renderengine { -std::unique_ptr<impl::RenderEngine> RenderEngine::create(int hwcFormat, uint32_t featureFlags, - uint32_t imageCacheSize) { +std::unique_ptr<impl::RenderEngine> RenderEngine::create(const RenderEngineCreationArgs& args) { char prop[PROPERTY_VALUE_MAX]; property_get(PROPERTY_DEBUG_RENDERENGINE_BACKEND, prop, "gles"); if (strcmp(prop, "gles") == 0) { ALOGD("RenderEngine GLES Backend"); - return renderengine::gl::GLESRenderEngine::create(hwcFormat, featureFlags, imageCacheSize); + return renderengine::gl::GLESRenderEngine::create(args); } ALOGE("UNKNOWN BackendType: %s, create GLES RenderEngine.", prop); - return renderengine::gl::GLESRenderEngine::create(hwcFormat, featureFlags, imageCacheSize); + return renderengine::gl::GLESRenderEngine::create(args); } RenderEngine::~RenderEngine() = default; namespace impl { -RenderEngine::RenderEngine(uint32_t featureFlags) : mFeatureFlags(featureFlags) {} +RenderEngine::RenderEngine(const RenderEngineCreationArgs& args) : mArgs(args) {} RenderEngine::~RenderEngine() = default; diff --git a/libs/renderengine/gl/GLESRenderEngine.cpp b/libs/renderengine/gl/GLESRenderEngine.cpp index b8cf0ea083..15d025b6f7 100644 --- a/libs/renderengine/gl/GLESRenderEngine.cpp +++ b/libs/renderengine/gl/GLESRenderEngine.cpp @@ -227,8 +227,7 @@ static status_t selectEGLConfig(EGLDisplay display, EGLint format, EGLint render return err; } -std::unique_ptr<GLESRenderEngine> GLESRenderEngine::create(int hwcFormat, uint32_t featureFlags, - uint32_t imageCacheSize) { +std::unique_ptr<GLESRenderEngine> GLESRenderEngine::create(const RenderEngineCreationArgs& args) { // initialize EGL for the default display EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (!eglInitialize(display, nullptr, nullptr)) { @@ -243,14 +242,13 @@ std::unique_ptr<GLESRenderEngine> GLESRenderEngine::create(int hwcFormat, uint32 // supported. EGLConfig config = EGL_NO_CONFIG; if (!extensions.hasNoConfigContext()) { - config = chooseEglConfig(display, hwcFormat, /*logConfig*/ true); + config = chooseEglConfig(display, args.pixelFormat, /*logConfig*/ true); } - bool useContextPriority = extensions.hasContextPriority() && - (featureFlags & RenderEngine::USE_HIGH_PRIORITY_CONTEXT); + bool useContextPriority = + extensions.hasContextPriority() && args.contextPriority == ContextPriority::HIGH; EGLContext protectedContext = EGL_NO_CONTEXT; - if ((featureFlags & RenderEngine::ENABLE_PROTECTED_CONTEXT) && - extensions.hasProtectedContent()) { + if (args.enableProtectedContext && extensions.hasProtectedContent()) { protectedContext = createEglContext(display, config, nullptr, useContextPriority, Protection::PROTECTED); ALOGE_IF(protectedContext == EGL_NO_CONTEXT, "Can't create protected context"); @@ -264,7 +262,8 @@ std::unique_ptr<GLESRenderEngine> GLESRenderEngine::create(int hwcFormat, uint32 EGLSurface dummy = EGL_NO_SURFACE; if (!extensions.hasSurfacelessContext()) { - dummy = createDummyEglPbufferSurface(display, config, hwcFormat, Protection::UNPROTECTED); + dummy = createDummyEglPbufferSurface(display, config, args.pixelFormat, + Protection::UNPROTECTED); LOG_ALWAYS_FATAL_IF(dummy == EGL_NO_SURFACE, "can't create dummy pbuffer"); } EGLBoolean success = eglMakeCurrent(display, dummy, dummy, ctxt); @@ -274,8 +273,8 @@ std::unique_ptr<GLESRenderEngine> GLESRenderEngine::create(int hwcFormat, uint32 EGLSurface protectedDummy = EGL_NO_SURFACE; if (protectedContext != EGL_NO_CONTEXT && !extensions.hasSurfacelessContext()) { - protectedDummy = - createDummyEglPbufferSurface(display, config, hwcFormat, Protection::PROTECTED); + protectedDummy = createDummyEglPbufferSurface(display, config, args.pixelFormat, + Protection::PROTECTED); ALOGE_IF(protectedDummy == EGL_NO_SURFACE, "can't create protected dummy pbuffer"); } @@ -291,9 +290,8 @@ std::unique_ptr<GLESRenderEngine> GLESRenderEngine::create(int hwcFormat, uint32 break; case GLES_VERSION_2_0: case GLES_VERSION_3_0: - engine = std::make_unique<GLESRenderEngine>(featureFlags, display, config, ctxt, dummy, - protectedContext, protectedDummy, - imageCacheSize); + engine = std::make_unique<GLESRenderEngine>(args, display, config, ctxt, dummy, + protectedContext, protectedDummy); break; } @@ -347,10 +345,10 @@ EGLConfig GLESRenderEngine::chooseEglConfig(EGLDisplay display, int format, bool return config; } -GLESRenderEngine::GLESRenderEngine(uint32_t featureFlags, EGLDisplay display, EGLConfig config, - EGLContext ctxt, EGLSurface dummy, EGLContext protectedContext, - EGLSurface protectedDummy, uint32_t imageCacheSize) - : renderengine::impl::RenderEngine(featureFlags), +GLESRenderEngine::GLESRenderEngine(const RenderEngineCreationArgs& args, EGLDisplay display, + EGLConfig config, EGLContext ctxt, EGLSurface dummy, + EGLContext protectedContext, EGLSurface protectedDummy) + : renderengine::impl::RenderEngine(args), mEGLDisplay(display), mEGLConfig(config), mEGLContext(ctxt), @@ -359,8 +357,8 @@ GLESRenderEngine::GLESRenderEngine(uint32_t featureFlags, EGLDisplay display, EG mProtectedDummySurface(protectedDummy), mVpWidth(0), mVpHeight(0), - mFramebufferImageCacheSize(imageCacheSize), - mUseColorManagement(featureFlags & USE_COLOR_MANAGEMENT) { + mFramebufferImageCacheSize(args.imageCacheSize), + mUseColorManagement(args.useColorManagement) { glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims); @@ -457,10 +455,9 @@ Framebuffer* GLESRenderEngine::getFramebufferForDrawing() { } void GLESRenderEngine::primeCache() const { - ProgramCache::getInstance().primeCache( - mInProtectedContext ? mProtectedEGLContext : mEGLContext, - mFeatureFlags & USE_COLOR_MANAGEMENT, - mFeatureFlags & PRECACHE_TONE_MAPPER_SHADER_ONLY); + ProgramCache::getInstance().primeCache(mInProtectedContext ? mProtectedEGLContext : mEGLContext, + mArgs.useColorManagement, + mArgs.precacheToneMapperShaderOnly); } base::unique_fd GLESRenderEngine::flush() { diff --git a/libs/renderengine/gl/GLESRenderEngine.h b/libs/renderengine/gl/GLESRenderEngine.h index 501b0441e3..397bc1619b 100644 --- a/libs/renderengine/gl/GLESRenderEngine.h +++ b/libs/renderengine/gl/GLESRenderEngine.h @@ -49,13 +49,11 @@ class GLImage; class GLESRenderEngine : public impl::RenderEngine { public: - static std::unique_ptr<GLESRenderEngine> create(int hwcFormat, uint32_t featureFlags, - uint32_t imageCacheSize); + static std::unique_ptr<GLESRenderEngine> create(const RenderEngineCreationArgs& args); - GLESRenderEngine(uint32_t featureFlags, // See RenderEngine::FeatureFlag - EGLDisplay display, EGLConfig config, EGLContext ctxt, EGLSurface dummy, - EGLContext protectedContext, EGLSurface protectedDummy, - uint32_t imageCacheSize); + GLESRenderEngine(const RenderEngineCreationArgs& args, EGLDisplay display, EGLConfig config, + EGLContext ctxt, EGLSurface dummy, EGLContext protectedContext, + EGLSurface protectedDummy); ~GLESRenderEngine() override EXCLUDES(mRenderingMutex); void primeCache() const override; diff --git a/libs/renderengine/include/renderengine/RenderEngine.h b/libs/renderengine/include/renderengine/RenderEngine.h index 9dcd5103fa..4db5c57d6d 100644 --- a/libs/renderengine/include/renderengine/RenderEngine.h +++ b/libs/renderengine/include/renderengine/RenderEngine.h @@ -48,6 +48,7 @@ class BindNativeBufferAsFramebuffer; class Image; class Mesh; class Texture; +struct RenderEngineCreationArgs; namespace impl { class RenderEngine; @@ -60,19 +61,13 @@ enum class Protection { class RenderEngine { public: - enum FeatureFlag { - USE_COLOR_MANAGEMENT = 1 << 0, // Device manages color - USE_HIGH_PRIORITY_CONTEXT = 1 << 1, // Use high priority context - - // Create a protected context when if possible - ENABLE_PROTECTED_CONTEXT = 1 << 2, - - // Only precache HDR to SDR tone-mapping shaders - PRECACHE_TONE_MAPPER_SHADER_ONLY = 1 << 3, + enum class ContextPriority { + LOW = 1, + MEDIUM = 2, + HIGH = 3, }; - static std::unique_ptr<impl::RenderEngine> create(int hwcFormat, uint32_t featureFlags, - uint32_t imageCacheSize); + static std::unique_ptr<impl::RenderEngine> create(const RenderEngineCreationArgs& args); virtual ~RenderEngine() = 0; @@ -173,6 +168,76 @@ protected: friend class BindNativeBufferAsFramebuffer; }; +struct RenderEngineCreationArgs { + int pixelFormat; + uint32_t imageCacheSize; + bool useColorManagement; + bool enableProtectedContext; + bool precacheToneMapperShaderOnly; + RenderEngine::ContextPriority contextPriority; + + 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, + RenderEngine::ContextPriority _contextPriority) + : pixelFormat(_pixelFormat) + , imageCacheSize(_imageCacheSize) + , useColorManagement(_useColorManagement) + , enableProtectedContext(_enableProtectedContext) + , precacheToneMapperShaderOnly(_precacheToneMapperShaderOnly) + , contextPriority(_contextPriority) {} + RenderEngineCreationArgs() = delete; +}; + +struct RenderEngineCreationArgs::Builder { + Builder() {} + + Builder& setPixelFormat(int pixelFormat) { + this->pixelFormat = pixelFormat; + return *this; + } + Builder& setImageCacheSize(uint32_t imageCacheSize) { + this->imageCacheSize = imageCacheSize; + return *this; + } + Builder& setUseColorManagerment(bool useColorManagement) { + this->useColorManagement = useColorManagement; + return *this; + } + Builder& setEnableProtectedContext(bool enableProtectedContext) { + this->enableProtectedContext = enableProtectedContext; + return *this; + } + Builder& setPrecacheToneMapperShaderOnly(bool precacheToneMapperShaderOnly) { + this->precacheToneMapperShaderOnly = precacheToneMapperShaderOnly; + return *this; + } + Builder& setContextPriority(RenderEngine::ContextPriority contextPriority) { + this->contextPriority = contextPriority; + return *this; + } + RenderEngineCreationArgs build() const { + return RenderEngineCreationArgs(pixelFormat, imageCacheSize, useColorManagement, + enableProtectedContext, precacheToneMapperShaderOnly, contextPriority); + } + +private: + // 1 means RGBA_8888 + int pixelFormat = 1; + uint32_t imageCacheSize = 0; + bool useColorManagement = true; + bool enableProtectedContext = false; + bool precacheToneMapperShaderOnly = false; + RenderEngine::ContextPriority contextPriority = RenderEngine::ContextPriority::MEDIUM; +}; + class BindNativeBufferAsFramebuffer { public: BindNativeBufferAsFramebuffer(RenderEngine& engine, ANativeWindowBuffer* buffer, @@ -206,8 +271,8 @@ public: bool useWaitSync() const override; protected: - RenderEngine(uint32_t featureFlags); - const uint32_t mFeatureFlags; + RenderEngine(const RenderEngineCreationArgs& args); + const RenderEngineCreationArgs mArgs; }; } // namespace impl diff --git a/libs/renderengine/tests/RenderEngineTest.cpp b/libs/renderengine/tests/RenderEngineTest.cpp index f47c7fd053..d01c740155 100644 --- a/libs/renderengine/tests/RenderEngineTest.cpp +++ b/libs/renderengine/tests/RenderEngineTest.cpp @@ -31,9 +31,15 @@ namespace android { struct RenderEngineTest : public ::testing::Test { static void SetUpTestSuite() { - sRE = renderengine::gl::GLESRenderEngine::create(static_cast<int32_t>( - ui::PixelFormat::RGBA_8888), - 0, 1); + sRE = renderengine::gl::GLESRenderEngine::create( + renderengine::RenderEngineCreationArgs::Builder() + .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888)) + .setImageCacheSize(1) + .setUseColorManagerment(false) + .setEnableProtectedContext(false) + .setPrecacheToneMapperShaderOnly(false) + .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM) + .build()); } static void TearDownTestSuite() { diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index ef9a598b84..057669b376 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -601,20 +601,19 @@ void SurfaceFlinger::init() { Mutex::Autolock _l(mStateLock); // Get a RenderEngine for the given display / config (can't fail) - int32_t renderEngineFeature = 0; - renderEngineFeature |= (useColorManagement ? - renderengine::RenderEngine::USE_COLOR_MANAGEMENT : 0); - renderEngineFeature |= (useContextPriority ? - renderengine::RenderEngine::USE_HIGH_PRIORITY_CONTEXT : 0); - renderEngineFeature |= - (enable_protected_contents(false) ? renderengine::RenderEngine::ENABLE_PROTECTED_CONTEXT - : 0); - // TODO(b/77156734): We need to stop casting and use HAL types when possible. // Sending maxFrameBufferAcquiredBuffers as the cache size is tightly tuned to single-display. - mCompositionEngine->setRenderEngine( - renderengine::RenderEngine::create(static_cast<int32_t>(defaultCompositionPixelFormat), - renderEngineFeature, maxFrameBufferAcquiredBuffers)); + mCompositionEngine->setRenderEngine(renderengine::RenderEngine::create( + renderengine::RenderEngineCreationArgs::Builder() + .setPixelFormat(static_cast<int32_t>(defaultCompositionPixelFormat)) + .setImageCacheSize(maxFrameBufferAcquiredBuffers) + .setUseColorManagerment(useColorManagement) + .setEnableProtectedContext(enable_protected_contents(false)) + .setPrecacheToneMapperShaderOnly(false) + .setContextPriority(useContextPriority + ? renderengine::RenderEngine::ContextPriority::HIGH + : renderengine::RenderEngine::ContextPriority::MEDIUM) + .build())); LOG_ALWAYS_FATAL_IF(mVrFlingerRequestsDisplay, "Starting with vr flinger active is not currently supported."); |