Skip to content

Commit e83221c

Browse files
Romain GuyJean-Baptiste Queru
authored andcommitted
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
1 parent f853859 commit e83221c

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

libs/hwui/OpenGLRenderer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,8 +1398,8 @@ void OpenGLRenderer::setupDrawBlending(bool blend, SkXfermode::Mode mode, bool s
13981398
// When the blending mode is kClear_Mode, we need to use a modulate color
13991399
// argb=1,0,0,0
14001400
accountForClear(mode);
1401-
chooseBlending(blend || (mColorSet && mColorA < 1.0f) || (mShader && mShader->blend()), mode,
1402-
mDescription, swapSrcDst);
1401+
chooseBlending(blend || (mColorSet && mColorA < 1.0f) || (mShader && mShader->blend()) ||
1402+
(mColorFilter && mColorFilter->blend()), mode, mDescription, swapSrcDst);
14031403
}
14041404

14051405
void OpenGLRenderer::setupDrawProgram() {

libs/hwui/ProgramCache.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ const char* gFS_Main_ApplyColorOp[4] = {
347347
// None
348348
"",
349349
// Matrix
350-
// TODO: Fix premultiplied alpha computations for color matrix
351350
" fragColor *= colorMatrix;\n"
352351
" fragColor += colorMatrixVector;\n"
353352
" fragColor.rgb *= fragColor.a;\n",

libs/hwui/SkiaColorFilter.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@ SkiaColorFilter::~SkiaColorFilter() {
3434
// Color matrix filter
3535
///////////////////////////////////////////////////////////////////////////////
3636

37-
SkiaColorMatrixFilter::SkiaColorMatrixFilter(SkColorFilter *skFilter, float* matrix, float* vector):
37+
SkiaColorMatrixFilter::SkiaColorMatrixFilter(SkColorFilter* skFilter, float* matrix, float* vector):
3838
SkiaColorFilter(skFilter, kColorMatrix, true), mMatrix(matrix), mVector(vector) {
39-
// Skia uses the range [0..255] for the addition vector, but we need
40-
// the [0..1] range to apply the vector in GLSL
41-
for (int i = 0; i < 4; i++) {
42-
mVector[i] /= 255.0f;
43-
}
39+
// TODO: We should be smarter about this
40+
mBlend = true;
4441
}
4542

4643
SkiaColorMatrixFilter::~SkiaColorMatrixFilter() {
@@ -62,7 +59,7 @@ void SkiaColorMatrixFilter::setupProgram(Program* program) {
6259
// Lighting color filter
6360
///////////////////////////////////////////////////////////////////////////////
6461

65-
SkiaLightingFilter::SkiaLightingFilter(SkColorFilter *skFilter, int multiply, int add):
62+
SkiaLightingFilter::SkiaLightingFilter(SkColorFilter* skFilter, int multiply, int add):
6663
SkiaColorFilter(skFilter, kLighting, true) {
6764
mMulR = ((multiply >> 16) & 0xFF) / 255.0f;
6865
mMulG = ((multiply >> 8) & 0xFF) / 255.0f;
@@ -71,6 +68,9 @@ SkiaLightingFilter::SkiaLightingFilter(SkColorFilter *skFilter, int multiply, in
7168
mAddR = ((add >> 16) & 0xFF) / 255.0f;
7269
mAddG = ((add >> 8) & 0xFF) / 255.0f;
7370
mAddB = ((add ) & 0xFF) / 255.0f;
71+
72+
// A lighting filter always ignores alpha
73+
mBlend = false;
7474
}
7575

7676
void SkiaLightingFilter::describe(ProgramDescription& description, const Extensions& extensions) {
@@ -86,13 +86,16 @@ void SkiaLightingFilter::setupProgram(Program* program) {
8686
// Blend color filter
8787
///////////////////////////////////////////////////////////////////////////////
8888

89-
SkiaBlendFilter::SkiaBlendFilter(SkColorFilter *skFilter, int color, SkXfermode::Mode mode):
89+
SkiaBlendFilter::SkiaBlendFilter(SkColorFilter* skFilter, int color, SkXfermode::Mode mode):
9090
SkiaColorFilter(skFilter, kBlend, true), mMode(mode) {
9191
const int alpha = (color >> 24) & 0xFF;
9292
mA = alpha / 255.0f;
9393
mR = mA * ((color >> 16) & 0xFF) / 255.0f;
9494
mG = mA * ((color >> 8) & 0xFF) / 255.0f;
9595
mB = mA * ((color ) & 0xFF) / 255.0f;
96+
97+
// TODO: We should do something smarter here
98+
mBlend = true;
9699
}
97100

98101
void SkiaBlendFilter::describe(ProgramDescription& description, const Extensions& extensions) {

0 commit comments

Comments
 (0)