diff options
author | Romain Guy <romainguy@google.com> | 2016-10-12 12:14:07 -0700 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2016-10-12 13:28:26 -0700 |
commit | 8762e332e3797fb41929a1c6069207f4906ca329 (patch) | |
tree | b97249defbda418d2adc8af6f4bb22dfa3def07f /libs/hwui/GradientCache.cpp | |
parent | 21986f2ae73e9ae3395a37dd3976af55e75d4f9d (diff) |
Various fixes for linear blending and gradients
With linear blending turned off some textures were still
created as sRGB textures instead of linear textures.
Multi-stop gradients were not behaving properly on devices
with no support for float textures.
Gradients are now always interpolated in linear space
even if linear blending is off.
New functions to always force sRGB->linear->sRGB conversions.
Test: Manual testing
Bug: 29940137
Change-Id: Ie2f84ee2a65fd85570e88af813e841e0e625df6c
Diffstat (limited to 'libs/hwui/GradientCache.cpp')
-rw-r--r-- | libs/hwui/GradientCache.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/libs/hwui/GradientCache.cpp b/libs/hwui/GradientCache.cpp index 8573ab078aaf..cd3ccf9b8fc7 100644 --- a/libs/hwui/GradientCache.cpp +++ b/libs/hwui/GradientCache.cpp @@ -185,22 +185,28 @@ size_t GradientCache::sourceBytesPerPixel() const { return 4 * (mUseFloatTexture ? sizeof(float) : sizeof(uint8_t)); } -void GradientCache::mixBytes(FloatColor& start, FloatColor& end, float amount, - uint8_t*& dst) const { +void GradientCache::mixBytes(const FloatColor& start, const FloatColor& end, + float amount, uint8_t*& dst) const { float oppAmount = 1.0f - amount; - *dst++ = uint8_t(OECF_sRGB((start.r * oppAmount + end.r * amount) * 255.0f)); - *dst++ = uint8_t(OECF_sRGB((start.g * oppAmount + end.g * amount) * 255.0f)); - *dst++ = uint8_t(OECF_sRGB((start.b * oppAmount + end.b * amount) * 255.0f)); - *dst++ = uint8_t( (start.a * oppAmount + end.a * amount) * 255.0f); + *dst++ = uint8_t(OECF_sRGB(start.r * oppAmount + end.r * amount) * 255.0f); + *dst++ = uint8_t(OECF_sRGB(start.g * oppAmount + end.g * amount) * 255.0f); + *dst++ = uint8_t(OECF_sRGB(start.b * oppAmount + end.b * amount) * 255.0f); + *dst++ = uint8_t( (start.a * oppAmount + end.a * amount) * 255.0f); } -void GradientCache::mixFloats(FloatColor& start, FloatColor& end, float amount, - uint8_t*& dst) const { +void GradientCache::mixFloats(const FloatColor& start, const FloatColor& end, + float amount, uint8_t*& dst) const { float oppAmount = 1.0f - amount; float* d = (float*) dst; +#if ANDROID_LINEAR_BLENDING_ENABLED *d++ = start.r * oppAmount + end.r * amount; *d++ = start.g * oppAmount + end.g * amount; *d++ = start.b * oppAmount + end.b * amount; +#else + *d++ = OECF_sRGB(start.r * oppAmount + end.r * amount); + *d++ = OECF_sRGB(start.g * oppAmount + end.g * amount); + *d++ = OECF_sRGB(start.b * oppAmount + end.b * amount); +#endif *d++ = start.a * oppAmount + end.a * amount; dst += 4 * sizeof(float); } @@ -217,10 +223,10 @@ void GradientCache::generateTexture(uint32_t* colors, float* positions, ChannelMixer mix = gMixers[mUseFloatTexture]; FloatColor start; - start.set(colors[0]); + start.setSRGB(colors[0]); FloatColor end; - end.set(colors[1]); + end.setSRGB(colors[1]); int currentPos = 1; float startPos = positions[0]; @@ -235,7 +241,7 @@ void GradientCache::generateTexture(uint32_t* colors, float* positions, currentPos++; - end.set(colors[currentPos]); + end.setSRGB(colors[currentPos]); distance = positions[currentPos] - startPos; } |