diff options
author | Romain Guy <romainguy@google.com> | 2012-09-24 16:01:35 -0700 |
---|---|---|
committer | Jean-Baptiste Queru <jbq@google.com> | 2012-09-25 09:33:22 -0700 |
commit | e83221c547cf2038752e5378e72e49a62cfd9954 (patch) | |
tree | 04530c1c08620b4c2c5b8209dc6bf7ba713d3f50 /libs | |
parent | f8538594fe6ba6db3310da042597840601d78cda (diff) | |
download | frameworks_base-e83221c547cf2038752e5378e72e49a62cfd9954.zip frameworks_base-e83221c547cf2038752e5378e72e49a62cfd9954.tar.gz frameworks_base-e83221c547cf2038752e5378e72e49a62cfd9954.tar.bz2 |
Fix alpha channel computation with ColorMatrixColorFilter
Bug #7222476
There were two issues:
- Blending was ignored with color filters
- The addition vector of a color filter was treated as integer values
instead of float values
Change-Id: Id94065704a30ee8aaaa5724a9f3a3cff7c50ced7
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 4 | ||||
-rw-r--r-- | libs/hwui/ProgramCache.cpp | 1 | ||||
-rw-r--r-- | libs/hwui/SkiaColorFilter.cpp | 19 |
3 files changed, 13 insertions, 11 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 35cc716..d0d1d93 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -1398,8 +1398,8 @@ void OpenGLRenderer::setupDrawBlending(bool blend, SkXfermode::Mode mode, bool s // When the blending mode is kClear_Mode, we need to use a modulate color // argb=1,0,0,0 accountForClear(mode); - chooseBlending(blend || (mColorSet && mColorA < 1.0f) || (mShader && mShader->blend()), mode, - mDescription, swapSrcDst); + chooseBlending(blend || (mColorSet && mColorA < 1.0f) || (mShader && mShader->blend()) || + (mColorFilter && mColorFilter->blend()), mode, mDescription, swapSrcDst); } void OpenGLRenderer::setupDrawProgram() { diff --git a/libs/hwui/ProgramCache.cpp b/libs/hwui/ProgramCache.cpp index c81319e..7bc2b37 100644 --- a/libs/hwui/ProgramCache.cpp +++ b/libs/hwui/ProgramCache.cpp @@ -347,7 +347,6 @@ const char* gFS_Main_ApplyColorOp[4] = { // None "", // Matrix - // TODO: Fix premultiplied alpha computations for color matrix " fragColor *= colorMatrix;\n" " fragColor += colorMatrixVector;\n" " fragColor.rgb *= fragColor.a;\n", diff --git a/libs/hwui/SkiaColorFilter.cpp b/libs/hwui/SkiaColorFilter.cpp index b86bbc5..f754388 100644 --- a/libs/hwui/SkiaColorFilter.cpp +++ b/libs/hwui/SkiaColorFilter.cpp @@ -34,13 +34,10 @@ SkiaColorFilter::~SkiaColorFilter() { // Color matrix filter /////////////////////////////////////////////////////////////////////////////// -SkiaColorMatrixFilter::SkiaColorMatrixFilter(SkColorFilter *skFilter, float* matrix, float* vector): +SkiaColorMatrixFilter::SkiaColorMatrixFilter(SkColorFilter* skFilter, float* matrix, float* vector): SkiaColorFilter(skFilter, kColorMatrix, true), mMatrix(matrix), mVector(vector) { - // Skia uses the range [0..255] for the addition vector, but we need - // the [0..1] range to apply the vector in GLSL - for (int i = 0; i < 4; i++) { - mVector[i] /= 255.0f; - } + // TODO: We should be smarter about this + mBlend = true; } SkiaColorMatrixFilter::~SkiaColorMatrixFilter() { @@ -62,7 +59,7 @@ void SkiaColorMatrixFilter::setupProgram(Program* program) { // Lighting color filter /////////////////////////////////////////////////////////////////////////////// -SkiaLightingFilter::SkiaLightingFilter(SkColorFilter *skFilter, int multiply, int add): +SkiaLightingFilter::SkiaLightingFilter(SkColorFilter* skFilter, int multiply, int add): SkiaColorFilter(skFilter, kLighting, true) { mMulR = ((multiply >> 16) & 0xFF) / 255.0f; mMulG = ((multiply >> 8) & 0xFF) / 255.0f; @@ -71,6 +68,9 @@ SkiaLightingFilter::SkiaLightingFilter(SkColorFilter *skFilter, int multiply, in mAddR = ((add >> 16) & 0xFF) / 255.0f; mAddG = ((add >> 8) & 0xFF) / 255.0f; mAddB = ((add ) & 0xFF) / 255.0f; + + // A lighting filter always ignores alpha + mBlend = false; } void SkiaLightingFilter::describe(ProgramDescription& description, const Extensions& extensions) { @@ -86,13 +86,16 @@ void SkiaLightingFilter::setupProgram(Program* program) { // Blend color filter /////////////////////////////////////////////////////////////////////////////// -SkiaBlendFilter::SkiaBlendFilter(SkColorFilter *skFilter, int color, SkXfermode::Mode mode): +SkiaBlendFilter::SkiaBlendFilter(SkColorFilter* skFilter, int color, SkXfermode::Mode mode): SkiaColorFilter(skFilter, kBlend, true), mMode(mode) { const int alpha = (color >> 24) & 0xFF; mA = alpha / 255.0f; mR = mA * ((color >> 16) & 0xFF) / 255.0f; mG = mA * ((color >> 8) & 0xFF) / 255.0f; mB = mA * ((color ) & 0xFF) / 255.0f; + + // TODO: We should do something smarter here + mBlend = true; } void SkiaBlendFilter::describe(ProgramDescription& description, const Extensions& extensions) { |