Loading libs/hwui/Debug.h +3 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,9 @@ // Turn on to enable additional debugging in the font renderers #define DEBUG_FONT_RENDERER 0 // Force gamma correction in shaders #define DEBUG_FONT_RENDERER_FORCE_SHADER_GAMMA 0 // Turn on to dump display list state #define DEBUG_DISPLAY_LIST 0 Loading libs/hwui/GammaFontRenderer.cpp +42 −7 Original line number Diff line number Diff line Loading @@ -23,6 +23,18 @@ namespace android { namespace uirenderer { /////////////////////////////////////////////////////////////////////////////// // Utils /////////////////////////////////////////////////////////////////////////////// static int luminance(const SkPaint* paint) { uint32_t c = paint->getColor(); const int r = (c >> 16) & 0xFF; const int g = (c >> 8) & 0xFF; const int b = (c ) & 0xFF; return (r * 2 + g * 5 + b) >> 3; } /////////////////////////////////////////////////////////////////////////////// // Base class GammaFontRenderer /////////////////////////////////////////////////////////////////////////////// Loading @@ -36,7 +48,11 @@ GammaFontRenderer* GammaFontRenderer::createRenderer() { } } #if DEBUG_FONT_RENDERER_FORCE_SHADER_GAMMA return new ShaderGammaFontRenderer(); #else return new LookupGammaFontRenderer(); #endif } GammaFontRenderer::GammaFontRenderer() { Loading Loading @@ -82,6 +98,29 @@ GammaFontRenderer::~GammaFontRenderer() { ShaderGammaFontRenderer::ShaderGammaFontRenderer(): GammaFontRenderer() { INIT_LOGD("Creating shader gamma font renderer"); mRenderer = NULL; } void ShaderGammaFontRenderer::describe(ProgramDescription& description, const SkPaint* paint) const { if (paint->getShader() == NULL) { const int l = luminance(paint); if (l <= mBlackThreshold) { description.hasGammaCorrection = true; description.gamma = mGamma; } else if (l >= mWhiteThreshold) { description.hasGammaCorrection = true; description.gamma = 1.0f / mGamma; } } } void ShaderGammaFontRenderer::setupProgram(ProgramDescription& description, Program* program) const { if (description.hasGammaCorrection) { glUniform1f(program->getUniform("gamma"), description.gamma); } } /////////////////////////////////////////////////////////////////////////////// Loading Loading @@ -164,15 +203,11 @@ FontRenderer* LookupGammaFontRenderer::getRenderer(Gamma gamma) { FontRenderer& LookupGammaFontRenderer::getFontRenderer(const SkPaint* paint) { if (paint->getShader() == NULL) { uint32_t c = paint->getColor(); const int r = (c >> 16) & 0xFF; const int g = (c >> 8) & 0xFF; const int b = (c ) & 0xFF; const int luminance = (r * 2 + g * 5 + b) >> 3; const int l = luminance(paint); if (luminance <= mBlackThreshold) { if (l <= mBlackThreshold) { return *getRenderer(kGammaBlack); } else if (luminance >= mWhiteThreshold) { } else if (l >= mWhiteThreshold) { return *getRenderer(kGammaWhite); } } Loading libs/hwui/GammaFontRenderer.h +13 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <SkPaint.h> #include "FontRenderer.h" #include "Program.h" namespace android { namespace uirenderer { Loading @@ -34,9 +35,11 @@ public: virtual FontRenderer& getFontRenderer(const SkPaint* paint) = 0; virtual uint32_t getFontRendererCount() const = 0; virtual uint32_t getFontRendererSize(uint32_t fontRenderer) const = 0; virtual void describe(ProgramDescription& description, const SkPaint* paint) const = 0; virtual void setupProgram(ProgramDescription& description, Program* program) const = 0; static GammaFontRenderer* createRenderer(); protected: Loading Loading @@ -79,6 +82,9 @@ public: return mRenderer->getCacheSize(); } void describe(ProgramDescription& description, const SkPaint* paint) const; void setupProgram(ProgramDescription& description, Program* program) const; private: ShaderGammaFontRenderer(); Loading Loading @@ -109,6 +115,12 @@ public: return renderer->getCacheSize(); } void describe(ProgramDescription& description, const SkPaint* paint) const { } void setupProgram(ProgramDescription& description, Program* program) const { } private: LookupGammaFontRenderer(); Loading libs/hwui/OpenGLRenderer.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -1174,6 +1174,10 @@ void OpenGLRenderer::setupDrawAlpha8Color(int color, int alpha) { mSetShaderColor = mDescription.setAlpha8Color(mColorR, mColorG, mColorB, mColorA); } void OpenGLRenderer::setupDrawTextGamma(const SkPaint* paint) { mCaches.fontRenderer->describe(mDescription, paint); } void OpenGLRenderer::setupDrawColor(float r, float g, float b, float a) { mColorA = a; mColorR = r; Loading Loading @@ -1301,6 +1305,10 @@ void OpenGLRenderer::setupDrawColorFilterUniforms() { } } void OpenGLRenderer::setupDrawTextGammaUniforms() { mCaches.fontRenderer->setupProgram(mDescription, mCaches.currentProgram); } void OpenGLRenderer::setupDrawSimpleMesh() { bool force = mCaches.bindMeshBuffer(); mCaches.bindPositionVertexPointer(force, mCaches.currentProgram->position, 0); Loading Loading @@ -2302,6 +2310,7 @@ status_t OpenGLRenderer::drawPosText(const char* text, int bytesCount, int count mCaches.activeTexture(0); setupDraw(); setupDrawTextGamma(paint); setupDrawDirtyRegionsDisabled(); setupDrawWithTexture(true); setupDrawAlpha8Color(paint->getColor(), alpha); Loading @@ -2314,6 +2323,7 @@ status_t OpenGLRenderer::drawPosText(const char* text, int bytesCount, int count setupDrawPureColorUniforms(); setupDrawColorFilterUniforms(); setupDrawShaderUniforms(pureTranslate); setupDrawTextGammaUniforms(); const Rect* clip = pureTranslate ? mSnapshot->clipRect : &mSnapshot->getLocalClip(); Rect bounds(FLT_MAX / 2.0f, FLT_MAX / 2.0f, FLT_MIN / 2.0f, FLT_MIN / 2.0f); Loading Loading @@ -2387,6 +2397,8 @@ status_t OpenGLRenderer::drawText(const char* text, int bytesCount, int count, if (CC_UNLIKELY(mHasShadow)) { mCaches.activeTexture(0); // NOTE: The drop shadow will not perform gamma correction // if shader-based correction is enabled mCaches.dropShadowCache.setFontRenderer(fontRenderer); const ShadowTexture* shadow = mCaches.dropShadowCache.get( paint, text, bytesCount, count, mShadowRadius); Loading Loading @@ -2427,6 +2439,7 @@ status_t OpenGLRenderer::drawText(const char* text, int bytesCount, int count, // The font renderer will always use texture unit 0 mCaches.activeTexture(0); setupDraw(); setupDrawTextGamma(paint); setupDrawDirtyRegionsDisabled(); setupDrawWithTexture(true); setupDrawAlpha8Color(paint->getColor(), alpha); Loading @@ -2441,6 +2454,7 @@ status_t OpenGLRenderer::drawText(const char* text, int bytesCount, int count, setupDrawPureColorUniforms(); setupDrawColorFilterUniforms(); setupDrawShaderUniforms(pureTranslate); setupDrawTextGammaUniforms(); const Rect* clip = pureTranslate ? mSnapshot->clipRect : &mSnapshot->getLocalClip(); Rect bounds(FLT_MAX / 2.0f, FLT_MAX / 2.0f, FLT_MIN / 2.0f, FLT_MIN / 2.0f); Loading Loading @@ -2485,6 +2499,7 @@ status_t OpenGLRenderer::drawTextOnPath(const char* text, int bytesCount, int co mCaches.activeTexture(0); setupDraw(); setupDrawTextGamma(paint); setupDrawDirtyRegionsDisabled(); setupDrawWithTexture(true); setupDrawAlpha8Color(paint->getColor(), alpha); Loading @@ -2497,6 +2512,7 @@ status_t OpenGLRenderer::drawTextOnPath(const char* text, int bytesCount, int co setupDrawPureColorUniforms(); setupDrawColorFilterUniforms(); setupDrawShaderUniforms(false); setupDrawTextGammaUniforms(); const Rect* clip = &mSnapshot->getLocalClip(); Rect bounds(FLT_MAX / 2.0f, FLT_MAX / 2.0f, FLT_MIN / 2.0f, FLT_MIN / 2.0f); Loading libs/hwui/OpenGLRenderer.h +2 −0 Original line number Diff line number Diff line Loading @@ -572,6 +572,7 @@ private: void setupDrawColor(int color, int alpha); void setupDrawColor(float r, float g, float b, float a); void setupDrawAlpha8Color(int color, int alpha); void setupDrawTextGamma(const SkPaint* paint); void setupDrawShader(); void setupDrawColorFilter(); void setupDrawBlending(SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode, Loading @@ -596,6 +597,7 @@ private: void setupDrawExternalTexture(GLuint texture); void setupDrawTextureTransform(); void setupDrawTextureTransformUniforms(mat4& transform); void setupDrawTextGammaUniforms(); void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords = NULL, GLuint vbo = 0); void setupDrawMeshIndices(GLvoid* vertices, GLvoid* texCoords); void setupDrawVertices(GLvoid* vertices); Loading Loading
libs/hwui/Debug.h +3 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,9 @@ // Turn on to enable additional debugging in the font renderers #define DEBUG_FONT_RENDERER 0 // Force gamma correction in shaders #define DEBUG_FONT_RENDERER_FORCE_SHADER_GAMMA 0 // Turn on to dump display list state #define DEBUG_DISPLAY_LIST 0 Loading
libs/hwui/GammaFontRenderer.cpp +42 −7 Original line number Diff line number Diff line Loading @@ -23,6 +23,18 @@ namespace android { namespace uirenderer { /////////////////////////////////////////////////////////////////////////////// // Utils /////////////////////////////////////////////////////////////////////////////// static int luminance(const SkPaint* paint) { uint32_t c = paint->getColor(); const int r = (c >> 16) & 0xFF; const int g = (c >> 8) & 0xFF; const int b = (c ) & 0xFF; return (r * 2 + g * 5 + b) >> 3; } /////////////////////////////////////////////////////////////////////////////// // Base class GammaFontRenderer /////////////////////////////////////////////////////////////////////////////// Loading @@ -36,7 +48,11 @@ GammaFontRenderer* GammaFontRenderer::createRenderer() { } } #if DEBUG_FONT_RENDERER_FORCE_SHADER_GAMMA return new ShaderGammaFontRenderer(); #else return new LookupGammaFontRenderer(); #endif } GammaFontRenderer::GammaFontRenderer() { Loading Loading @@ -82,6 +98,29 @@ GammaFontRenderer::~GammaFontRenderer() { ShaderGammaFontRenderer::ShaderGammaFontRenderer(): GammaFontRenderer() { INIT_LOGD("Creating shader gamma font renderer"); mRenderer = NULL; } void ShaderGammaFontRenderer::describe(ProgramDescription& description, const SkPaint* paint) const { if (paint->getShader() == NULL) { const int l = luminance(paint); if (l <= mBlackThreshold) { description.hasGammaCorrection = true; description.gamma = mGamma; } else if (l >= mWhiteThreshold) { description.hasGammaCorrection = true; description.gamma = 1.0f / mGamma; } } } void ShaderGammaFontRenderer::setupProgram(ProgramDescription& description, Program* program) const { if (description.hasGammaCorrection) { glUniform1f(program->getUniform("gamma"), description.gamma); } } /////////////////////////////////////////////////////////////////////////////// Loading Loading @@ -164,15 +203,11 @@ FontRenderer* LookupGammaFontRenderer::getRenderer(Gamma gamma) { FontRenderer& LookupGammaFontRenderer::getFontRenderer(const SkPaint* paint) { if (paint->getShader() == NULL) { uint32_t c = paint->getColor(); const int r = (c >> 16) & 0xFF; const int g = (c >> 8) & 0xFF; const int b = (c ) & 0xFF; const int luminance = (r * 2 + g * 5 + b) >> 3; const int l = luminance(paint); if (luminance <= mBlackThreshold) { if (l <= mBlackThreshold) { return *getRenderer(kGammaBlack); } else if (luminance >= mWhiteThreshold) { } else if (l >= mWhiteThreshold) { return *getRenderer(kGammaWhite); } } Loading
libs/hwui/GammaFontRenderer.h +13 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <SkPaint.h> #include "FontRenderer.h" #include "Program.h" namespace android { namespace uirenderer { Loading @@ -34,9 +35,11 @@ public: virtual FontRenderer& getFontRenderer(const SkPaint* paint) = 0; virtual uint32_t getFontRendererCount() const = 0; virtual uint32_t getFontRendererSize(uint32_t fontRenderer) const = 0; virtual void describe(ProgramDescription& description, const SkPaint* paint) const = 0; virtual void setupProgram(ProgramDescription& description, Program* program) const = 0; static GammaFontRenderer* createRenderer(); protected: Loading Loading @@ -79,6 +82,9 @@ public: return mRenderer->getCacheSize(); } void describe(ProgramDescription& description, const SkPaint* paint) const; void setupProgram(ProgramDescription& description, Program* program) const; private: ShaderGammaFontRenderer(); Loading Loading @@ -109,6 +115,12 @@ public: return renderer->getCacheSize(); } void describe(ProgramDescription& description, const SkPaint* paint) const { } void setupProgram(ProgramDescription& description, Program* program) const { } private: LookupGammaFontRenderer(); Loading
libs/hwui/OpenGLRenderer.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -1174,6 +1174,10 @@ void OpenGLRenderer::setupDrawAlpha8Color(int color, int alpha) { mSetShaderColor = mDescription.setAlpha8Color(mColorR, mColorG, mColorB, mColorA); } void OpenGLRenderer::setupDrawTextGamma(const SkPaint* paint) { mCaches.fontRenderer->describe(mDescription, paint); } void OpenGLRenderer::setupDrawColor(float r, float g, float b, float a) { mColorA = a; mColorR = r; Loading Loading @@ -1301,6 +1305,10 @@ void OpenGLRenderer::setupDrawColorFilterUniforms() { } } void OpenGLRenderer::setupDrawTextGammaUniforms() { mCaches.fontRenderer->setupProgram(mDescription, mCaches.currentProgram); } void OpenGLRenderer::setupDrawSimpleMesh() { bool force = mCaches.bindMeshBuffer(); mCaches.bindPositionVertexPointer(force, mCaches.currentProgram->position, 0); Loading Loading @@ -2302,6 +2310,7 @@ status_t OpenGLRenderer::drawPosText(const char* text, int bytesCount, int count mCaches.activeTexture(0); setupDraw(); setupDrawTextGamma(paint); setupDrawDirtyRegionsDisabled(); setupDrawWithTexture(true); setupDrawAlpha8Color(paint->getColor(), alpha); Loading @@ -2314,6 +2323,7 @@ status_t OpenGLRenderer::drawPosText(const char* text, int bytesCount, int count setupDrawPureColorUniforms(); setupDrawColorFilterUniforms(); setupDrawShaderUniforms(pureTranslate); setupDrawTextGammaUniforms(); const Rect* clip = pureTranslate ? mSnapshot->clipRect : &mSnapshot->getLocalClip(); Rect bounds(FLT_MAX / 2.0f, FLT_MAX / 2.0f, FLT_MIN / 2.0f, FLT_MIN / 2.0f); Loading Loading @@ -2387,6 +2397,8 @@ status_t OpenGLRenderer::drawText(const char* text, int bytesCount, int count, if (CC_UNLIKELY(mHasShadow)) { mCaches.activeTexture(0); // NOTE: The drop shadow will not perform gamma correction // if shader-based correction is enabled mCaches.dropShadowCache.setFontRenderer(fontRenderer); const ShadowTexture* shadow = mCaches.dropShadowCache.get( paint, text, bytesCount, count, mShadowRadius); Loading Loading @@ -2427,6 +2439,7 @@ status_t OpenGLRenderer::drawText(const char* text, int bytesCount, int count, // The font renderer will always use texture unit 0 mCaches.activeTexture(0); setupDraw(); setupDrawTextGamma(paint); setupDrawDirtyRegionsDisabled(); setupDrawWithTexture(true); setupDrawAlpha8Color(paint->getColor(), alpha); Loading @@ -2441,6 +2454,7 @@ status_t OpenGLRenderer::drawText(const char* text, int bytesCount, int count, setupDrawPureColorUniforms(); setupDrawColorFilterUniforms(); setupDrawShaderUniforms(pureTranslate); setupDrawTextGammaUniforms(); const Rect* clip = pureTranslate ? mSnapshot->clipRect : &mSnapshot->getLocalClip(); Rect bounds(FLT_MAX / 2.0f, FLT_MAX / 2.0f, FLT_MIN / 2.0f, FLT_MIN / 2.0f); Loading Loading @@ -2485,6 +2499,7 @@ status_t OpenGLRenderer::drawTextOnPath(const char* text, int bytesCount, int co mCaches.activeTexture(0); setupDraw(); setupDrawTextGamma(paint); setupDrawDirtyRegionsDisabled(); setupDrawWithTexture(true); setupDrawAlpha8Color(paint->getColor(), alpha); Loading @@ -2497,6 +2512,7 @@ status_t OpenGLRenderer::drawTextOnPath(const char* text, int bytesCount, int co setupDrawPureColorUniforms(); setupDrawColorFilterUniforms(); setupDrawShaderUniforms(false); setupDrawTextGammaUniforms(); const Rect* clip = &mSnapshot->getLocalClip(); Rect bounds(FLT_MAX / 2.0f, FLT_MAX / 2.0f, FLT_MIN / 2.0f, FLT_MIN / 2.0f); Loading
libs/hwui/OpenGLRenderer.h +2 −0 Original line number Diff line number Diff line Loading @@ -572,6 +572,7 @@ private: void setupDrawColor(int color, int alpha); void setupDrawColor(float r, float g, float b, float a); void setupDrawAlpha8Color(int color, int alpha); void setupDrawTextGamma(const SkPaint* paint); void setupDrawShader(); void setupDrawColorFilter(); void setupDrawBlending(SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode, Loading @@ -596,6 +597,7 @@ private: void setupDrawExternalTexture(GLuint texture); void setupDrawTextureTransform(); void setupDrawTextureTransformUniforms(mat4& transform); void setupDrawTextGammaUniforms(); void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords = NULL, GLuint vbo = 0); void setupDrawMeshIndices(GLvoid* vertices, GLvoid* texCoords); void setupDrawVertices(GLvoid* vertices); Loading