From 8762e332e3797fb41929a1c6069207f4906ca329 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Wed, 12 Oct 2016 12:14:07 -0700 Subject: 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 --- libs/hwui/GradientCache.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'libs/hwui/GradientCache.cpp') 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; } -- cgit v1.2.3-59-g8ed1b