Loading services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp +4 −1 Original line number Original line Diff line number Diff line Loading @@ -112,7 +112,10 @@ namespace impl { using ui::Dataspace; using ui::Dataspace; GLES20RenderEngine::GLES20RenderEngine(uint32_t featureFlags) GLES20RenderEngine::GLES20RenderEngine(uint32_t featureFlags) : mVpWidth(0), mVpHeight(0), mPlatformHasWideColor((featureFlags & WIDE_COLOR_SUPPORT) != 0) { : RenderEngine(featureFlags), mVpWidth(0), mVpHeight(0), mPlatformHasWideColor((featureFlags & WIDE_COLOR_SUPPORT) != 0) { glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims); glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims); Loading services/surfaceflinger/RenderEngine/ProgramCache.cpp +30 −8 Original line number Original line Diff line number Diff line Loading @@ -14,10 +14,13 @@ * limitations under the License. * limitations under the License. */ */ #define ATRACE_TAG ATRACE_TAG_GRAPHICS #include <GLES2/gl2.h> #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> #include <GLES2/gl2ext.h> #include <utils/String8.h> #include <utils/String8.h> #include <utils/Trace.h> #include "Description.h" #include "Description.h" #include "Program.h" #include "Program.h" Loading Loading @@ -75,15 +78,11 @@ Formatter& dedent(Formatter& f) { ANDROID_SINGLETON_STATIC_INSTANCE(ProgramCache) ANDROID_SINGLETON_STATIC_INSTANCE(ProgramCache) ProgramCache::ProgramCache() { ProgramCache::ProgramCache() {} // Until surfaceflinger has a dependable blob cache on the filesystem, // generate shaders on initialization so as to avoid jank. primeCache(); } ProgramCache::~ProgramCache() {} ProgramCache::~ProgramCache() {} void ProgramCache::primeCache() { void ProgramCache::primeCache(bool hasWideColor) { uint32_t shaderCount = 0; uint32_t shaderCount = 0; uint32_t keyMask = Key::BLEND_MASK | Key::OPACITY_MASK | Key::ALPHA_MASK | Key::TEXTURE_MASK; uint32_t keyMask = Key::BLEND_MASK | Key::OPACITY_MASK | Key::ALPHA_MASK | Key::TEXTURE_MASK; // Prime the cache for all combinations of the above masks, // Prime the cache for all combinations of the above masks, Loading @@ -104,6 +103,27 @@ void ProgramCache::primeCache() { shaderCount++; shaderCount++; } } } } // Prime for sRGB->P3 conversion if (hasWideColor) { Key shaderKey; shaderKey.set(Key::BLEND_MASK | Key::TEXTURE_MASK | Key::OUTPUT_TRANSFORM_MATRIX_MASK | Key::INPUT_TF_MASK | Key::OUTPUT_TF_MASK, Key::BLEND_PREMULT | Key::TEXTURE_EXT | Key::OUTPUT_TRANSFORM_MATRIX_ON | Key::INPUT_TF_SRGB | Key::OUTPUT_TF_SRGB); for (int i = 0; i < 4; i++) { shaderKey.set(Key::OPACITY_MASK, (i & 1) ? Key::OPACITY_OPAQUE : Key::OPACITY_TRANSLUCENT); shaderKey.set(Key::ALPHA_MASK, (i & 2) ? Key::ALPHA_LT_ONE : Key::ALPHA_EQ_ONE); Program* program = mCache.valueFor(shaderKey); if (program == nullptr) { program = generateProgram(shaderKey); mCache.add(shaderKey, program); shaderCount++; } } } nsecs_t timeAfter = systemTime(); nsecs_t timeAfter = systemTime(); float compileTimeMs = static_cast<float>(timeAfter - timeBefore) / 1.0E6; float compileTimeMs = static_cast<float>(timeAfter - timeBefore) / 1.0E6; ALOGD("shader cache generated - %u shaders in %f ms\n", shaderCount, compileTimeMs); ALOGD("shader cache generated - %u shaders in %f ms\n", shaderCount, compileTimeMs); Loading Loading @@ -631,6 +651,8 @@ String8 ProgramCache::generateFragmentShader(const Key& needs) { } } Program* ProgramCache::generateProgram(const Key& needs) { Program* ProgramCache::generateProgram(const Key& needs) { ATRACE_CALL(); // vertex shader // vertex shader String8 vs = generateVertexShader(needs); String8 vs = generateVertexShader(needs); Loading @@ -654,8 +676,8 @@ void ProgramCache::useProgram(const Description& description) { mCache.add(needs, program); mCache.add(needs, program); time += systemTime(); time += systemTime(); // ALOGD(">>> generated new program: needs=%08X, time=%u ms (%d programs)", ALOGV(">>> generated new program: needs=%08X, time=%u ms (%zu programs)", needs.mKey, // needs.mNeeds, uint32_t(ns2ms(time)), mCache.size()); uint32_t(ns2ms(time)), mCache.size()); } } // here we have a suitable program for this description // here we have a suitable program for this description Loading services/surfaceflinger/RenderEngine/ProgramCache.h +3 −2 Original line number Original line Diff line number Diff line Loading @@ -160,13 +160,14 @@ public: ProgramCache(); ProgramCache(); ~ProgramCache(); ~ProgramCache(); // Generate shaders to populate the cache void primeCache(bool hasWideColor); // useProgram lookup a suitable program in the cache or generates one // useProgram lookup a suitable program in the cache or generates one // if none can be found. // if none can be found. void useProgram(const Description& description); void useProgram(const Description& description); private: private: // Generate shaders to populate the cache void primeCache(); // compute a cache Key from a Description // compute a cache Key from a Description static Key computeKey(const Description& description); static Key computeKey(const Description& description); // Generate EOTF based from Key. // Generate EOTF based from Key. Loading services/surfaceflinger/RenderEngine/RenderEngine.cpp +6 −5 Original line number Original line Diff line number Diff line Loading @@ -150,8 +150,11 @@ bool RenderEngine::overrideUseContextPriorityFromConfig(bool useContextPriority) } } } } RenderEngine::RenderEngine() RenderEngine::RenderEngine(uint32_t featureFlags) : mEGLDisplay(EGL_NO_DISPLAY), mEGLConfig(nullptr), mEGLContext(EGL_NO_CONTEXT) {} : mEGLDisplay(EGL_NO_DISPLAY), mEGLConfig(nullptr), mEGLContext(EGL_NO_CONTEXT), mFeatureFlags(featureFlags) {} RenderEngine::~RenderEngine() { RenderEngine::~RenderEngine() { eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); Loading Loading @@ -588,9 +591,7 @@ EGLConfig RenderEngine::chooseEglConfig(EGLDisplay display, int format, bool log } } void RenderEngine::primeCache() const { void RenderEngine::primeCache() const { // Getting the ProgramCache instance causes it to prime its shader cache, ProgramCache::getInstance().primeCache(mFeatureFlags & WIDE_COLOR_SUPPORT); // which is performed in its constructor ProgramCache::getInstance(); } } // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- Loading services/surfaceflinger/RenderEngine/RenderEngine.h +3 −1 Original line number Original line Diff line number Diff line Loading @@ -172,7 +172,9 @@ class RenderEngine : public RE::RenderEngine { static bool overrideUseContextPriorityFromConfig(bool useContextPriority); static bool overrideUseContextPriorityFromConfig(bool useContextPriority); protected: protected: RenderEngine(); RenderEngine(uint32_t featureFlags); const uint32_t mFeatureFlags; public: public: virtual ~RenderEngine() = 0; virtual ~RenderEngine() = 0; Loading Loading
services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp +4 −1 Original line number Original line Diff line number Diff line Loading @@ -112,7 +112,10 @@ namespace impl { using ui::Dataspace; using ui::Dataspace; GLES20RenderEngine::GLES20RenderEngine(uint32_t featureFlags) GLES20RenderEngine::GLES20RenderEngine(uint32_t featureFlags) : mVpWidth(0), mVpHeight(0), mPlatformHasWideColor((featureFlags & WIDE_COLOR_SUPPORT) != 0) { : RenderEngine(featureFlags), mVpWidth(0), mVpHeight(0), mPlatformHasWideColor((featureFlags & WIDE_COLOR_SUPPORT) != 0) { glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims); glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims); Loading
services/surfaceflinger/RenderEngine/ProgramCache.cpp +30 −8 Original line number Original line Diff line number Diff line Loading @@ -14,10 +14,13 @@ * limitations under the License. * limitations under the License. */ */ #define ATRACE_TAG ATRACE_TAG_GRAPHICS #include <GLES2/gl2.h> #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> #include <GLES2/gl2ext.h> #include <utils/String8.h> #include <utils/String8.h> #include <utils/Trace.h> #include "Description.h" #include "Description.h" #include "Program.h" #include "Program.h" Loading Loading @@ -75,15 +78,11 @@ Formatter& dedent(Formatter& f) { ANDROID_SINGLETON_STATIC_INSTANCE(ProgramCache) ANDROID_SINGLETON_STATIC_INSTANCE(ProgramCache) ProgramCache::ProgramCache() { ProgramCache::ProgramCache() {} // Until surfaceflinger has a dependable blob cache on the filesystem, // generate shaders on initialization so as to avoid jank. primeCache(); } ProgramCache::~ProgramCache() {} ProgramCache::~ProgramCache() {} void ProgramCache::primeCache() { void ProgramCache::primeCache(bool hasWideColor) { uint32_t shaderCount = 0; uint32_t shaderCount = 0; uint32_t keyMask = Key::BLEND_MASK | Key::OPACITY_MASK | Key::ALPHA_MASK | Key::TEXTURE_MASK; uint32_t keyMask = Key::BLEND_MASK | Key::OPACITY_MASK | Key::ALPHA_MASK | Key::TEXTURE_MASK; // Prime the cache for all combinations of the above masks, // Prime the cache for all combinations of the above masks, Loading @@ -104,6 +103,27 @@ void ProgramCache::primeCache() { shaderCount++; shaderCount++; } } } } // Prime for sRGB->P3 conversion if (hasWideColor) { Key shaderKey; shaderKey.set(Key::BLEND_MASK | Key::TEXTURE_MASK | Key::OUTPUT_TRANSFORM_MATRIX_MASK | Key::INPUT_TF_MASK | Key::OUTPUT_TF_MASK, Key::BLEND_PREMULT | Key::TEXTURE_EXT | Key::OUTPUT_TRANSFORM_MATRIX_ON | Key::INPUT_TF_SRGB | Key::OUTPUT_TF_SRGB); for (int i = 0; i < 4; i++) { shaderKey.set(Key::OPACITY_MASK, (i & 1) ? Key::OPACITY_OPAQUE : Key::OPACITY_TRANSLUCENT); shaderKey.set(Key::ALPHA_MASK, (i & 2) ? Key::ALPHA_LT_ONE : Key::ALPHA_EQ_ONE); Program* program = mCache.valueFor(shaderKey); if (program == nullptr) { program = generateProgram(shaderKey); mCache.add(shaderKey, program); shaderCount++; } } } nsecs_t timeAfter = systemTime(); nsecs_t timeAfter = systemTime(); float compileTimeMs = static_cast<float>(timeAfter - timeBefore) / 1.0E6; float compileTimeMs = static_cast<float>(timeAfter - timeBefore) / 1.0E6; ALOGD("shader cache generated - %u shaders in %f ms\n", shaderCount, compileTimeMs); ALOGD("shader cache generated - %u shaders in %f ms\n", shaderCount, compileTimeMs); Loading Loading @@ -631,6 +651,8 @@ String8 ProgramCache::generateFragmentShader(const Key& needs) { } } Program* ProgramCache::generateProgram(const Key& needs) { Program* ProgramCache::generateProgram(const Key& needs) { ATRACE_CALL(); // vertex shader // vertex shader String8 vs = generateVertexShader(needs); String8 vs = generateVertexShader(needs); Loading @@ -654,8 +676,8 @@ void ProgramCache::useProgram(const Description& description) { mCache.add(needs, program); mCache.add(needs, program); time += systemTime(); time += systemTime(); // ALOGD(">>> generated new program: needs=%08X, time=%u ms (%d programs)", ALOGV(">>> generated new program: needs=%08X, time=%u ms (%zu programs)", needs.mKey, // needs.mNeeds, uint32_t(ns2ms(time)), mCache.size()); uint32_t(ns2ms(time)), mCache.size()); } } // here we have a suitable program for this description // here we have a suitable program for this description Loading
services/surfaceflinger/RenderEngine/ProgramCache.h +3 −2 Original line number Original line Diff line number Diff line Loading @@ -160,13 +160,14 @@ public: ProgramCache(); ProgramCache(); ~ProgramCache(); ~ProgramCache(); // Generate shaders to populate the cache void primeCache(bool hasWideColor); // useProgram lookup a suitable program in the cache or generates one // useProgram lookup a suitable program in the cache or generates one // if none can be found. // if none can be found. void useProgram(const Description& description); void useProgram(const Description& description); private: private: // Generate shaders to populate the cache void primeCache(); // compute a cache Key from a Description // compute a cache Key from a Description static Key computeKey(const Description& description); static Key computeKey(const Description& description); // Generate EOTF based from Key. // Generate EOTF based from Key. Loading
services/surfaceflinger/RenderEngine/RenderEngine.cpp +6 −5 Original line number Original line Diff line number Diff line Loading @@ -150,8 +150,11 @@ bool RenderEngine::overrideUseContextPriorityFromConfig(bool useContextPriority) } } } } RenderEngine::RenderEngine() RenderEngine::RenderEngine(uint32_t featureFlags) : mEGLDisplay(EGL_NO_DISPLAY), mEGLConfig(nullptr), mEGLContext(EGL_NO_CONTEXT) {} : mEGLDisplay(EGL_NO_DISPLAY), mEGLConfig(nullptr), mEGLContext(EGL_NO_CONTEXT), mFeatureFlags(featureFlags) {} RenderEngine::~RenderEngine() { RenderEngine::~RenderEngine() { eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); Loading Loading @@ -588,9 +591,7 @@ EGLConfig RenderEngine::chooseEglConfig(EGLDisplay display, int format, bool log } } void RenderEngine::primeCache() const { void RenderEngine::primeCache() const { // Getting the ProgramCache instance causes it to prime its shader cache, ProgramCache::getInstance().primeCache(mFeatureFlags & WIDE_COLOR_SUPPORT); // which is performed in its constructor ProgramCache::getInstance(); } } // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- Loading
services/surfaceflinger/RenderEngine/RenderEngine.h +3 −1 Original line number Original line Diff line number Diff line Loading @@ -172,7 +172,9 @@ class RenderEngine : public RE::RenderEngine { static bool overrideUseContextPriorityFromConfig(bool useContextPriority); static bool overrideUseContextPriorityFromConfig(bool useContextPriority); protected: protected: RenderEngine(); RenderEngine(uint32_t featureFlags); const uint32_t mFeatureFlags; public: public: virtual ~RenderEngine() = 0; virtual ~RenderEngine() = 0; Loading