From a0ed6f03f6f06eb41cbcc15c0a99b4a78fd91bef Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Mon, 12 Dec 2016 18:21:32 -0800 Subject: Pre-multiply gradient colors the right way Alpha pre-multiplication must be done after applying the opto-electronic transfer function when linear blending is disabled. The correct way would be to pre-multiply before gamma encoding but this leads to improper blending which cannot be corrected without using sRGB frame buffers and texture sampling. Bug: 33010587 Test: cts-tradefed run singleCommand cts-dev --module CtsUiRenderingTestCases --test android.uirendering.cts.testclasses.GradientTests Change-Id: I5f04bda4cb9f63674537aef5931621c14d601884 --- libs/hwui/ProgramCache.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'libs/hwui/ProgramCache.cpp') diff --git a/libs/hwui/ProgramCache.cpp b/libs/hwui/ProgramCache.cpp index 0c2309faf4ea..2688ba484212 100644 --- a/libs/hwui/ProgramCache.cpp +++ b/libs/hwui/ProgramCache.cpp @@ -175,10 +175,11 @@ const char* gFS_Gradient_Functions = const char* gFS_Gradient_Preamble[2] = { // Linear framebuffer "\nvec4 dither(const vec4 color) {\n" - " return vec4(color.rgb + (triangleNoise(gl_FragCoord.xy * screenSize.xy) / 255.0), color.a);" + " return vec4(color.rgb + (triangleNoise(gl_FragCoord.xy * screenSize.xy) / 255.0), color.a);\n" "}\n" "\nvec4 gammaMix(const vec4 a, const vec4 b, float v) {\n" - " return pow(mix(a, b, v), vec4(vec3(1.0 / 2.2), 1.0));" + " vec4 c = pow(mix(a, b, v), vec4(vec3(1.0 / 2.2), 1.0));\n" + " return vec4(c.rgb * c.a, c.a);\n" "}\n", // sRGB framebuffer "\nvec4 dither(const vec4 color) {\n" @@ -186,7 +187,8 @@ const char* gFS_Gradient_Preamble[2] = { " return vec4(dithered * dithered, color.a);\n" "}\n" "\nvec4 gammaMix(const vec4 a, const vec4 b, float v) {\n" - " return mix(a, b, v);" + " vec4 c = mix(a, b, v);\n" + " return vec4(c.rgb * c.a, c.a);\n" "}\n" }; -- cgit v1.2.3-59-g8ed1b