summaryrefslogtreecommitdiff
path: root/libs/hwui/GradientCache.cpp
diff options
context:
space:
mode:
author Derek Sollenberger <djsollen@google.com> 2017-03-31 12:09:24 -0400
committer Derek Sollenberger <djsollen@google.com> 2017-04-04 12:07:28 -0400
commit669b15a93548b82135c73196665bcb7f03d87795 (patch)
tree7ff6e8179d2ac972db944e94b30f036af659ec52 /libs/hwui/GradientCache.cpp
parent3f2bbcbe92cd2500746153ed2378278c1b2a53e2 (diff)
Fix HWUI/Skia Gradients to premultiply the colors prior to interpolation
This is fixed in Skia by passing the appropriate flag when the shader is generated. The fix in HWUI is to reverse the premultiplication and interpolation steps. Test: bit CtsUiRenderingTestCases:.testclasses.ShaderTests Bug: 34323783 Change-Id: I3417141949f62fcc696b6d8213a4b446d7d0cbf8
Diffstat (limited to 'libs/hwui/GradientCache.cpp')
-rw-r--r--libs/hwui/GradientCache.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/libs/hwui/GradientCache.cpp b/libs/hwui/GradientCache.cpp
index dceb28518db3..d4d0c997be11 100644
--- a/libs/hwui/GradientCache.cpp
+++ b/libs/hwui/GradientCache.cpp
@@ -189,9 +189,9 @@ void GradientCache::mixBytes(const FloatColor& start, const FloatColor& end,
float amount, uint8_t*& dst) const {
float oppAmount = 1.0f - amount;
float a = start.a * oppAmount + end.a * amount;
- *dst++ = uint8_t(a * OECF(start.r * oppAmount + end.r * amount) * 255.0f);
- *dst++ = uint8_t(a * OECF(start.g * oppAmount + end.g * amount) * 255.0f);
- *dst++ = uint8_t(a * OECF(start.b * oppAmount + end.b * amount) * 255.0f);
+ *dst++ = uint8_t(OECF(start.r * oppAmount + end.r * amount) * 255.0f);
+ *dst++ = uint8_t(OECF(start.g * oppAmount + end.g * amount) * 255.0f);
+ *dst++ = uint8_t(OECF(start.b * oppAmount + end.b * amount) * 255.0f);
*dst++ = uint8_t(a * 255.0f);
}
@@ -202,13 +202,13 @@ void GradientCache::mixFloats(const FloatColor& start, const FloatColor& end,
float* d = (float*) dst;
#ifdef ANDROID_ENABLE_LINEAR_BLENDING
// We want to stay linear
- *d++ = a * (start.r * oppAmount + end.r * amount);
- *d++ = a * (start.g * oppAmount + end.g * amount);
- *d++ = a * (start.b * oppAmount + end.b * amount);
+ *d++ = (start.r * oppAmount + end.r * amount);
+ *d++ = (start.g * oppAmount + end.g * amount);
+ *d++ = (start.b * oppAmount + end.b * amount);
#else
- *d++ = a * OECF(start.r * oppAmount + end.r * amount);
- *d++ = a * OECF(start.g * oppAmount + end.g * amount);
- *d++ = a * OECF(start.b * oppAmount + end.b * amount);
+ *d++ = OECF(start.r * oppAmount + end.r * amount);
+ *d++ = OECF(start.g * oppAmount + end.g * amount);
+ *d++ = OECF(start.b * oppAmount + end.b * amount);
#endif
*d++ = a;
dst += 4 * sizeof(float);
@@ -229,10 +229,10 @@ void GradientCache::generateTexture(uint32_t* colors, float* positions,
ChannelMixer mix = gMixers[mUseFloatTexture];
FloatColor start;
- start.setUnPreMultiplied(colors[0]);
+ start.set(colors[0]);
FloatColor end;
- end.setUnPreMultiplied(colors[1]);
+ end.set(colors[1]);
int currentPos = 1;
float startPos = positions[0];
@@ -247,7 +247,7 @@ void GradientCache::generateTexture(uint32_t* colors, float* positions,
currentPos++;
- end.setUnPreMultiplied(colors[currentPos]);
+ end.set(colors[currentPos]);
distance = positions[currentPos] - startPos;
}