1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/patches/archive/0008-Bug-687188-Skia-radial-gradients.patch Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,173 @@ 1.4 +From f941ea32e44a2436d235e83ef1a434289a9d9c1e Mon Sep 17 00:00:00 2001 1.5 +From: George Wright <gwright@mozilla.com> 1.6 +Date: Wed, 23 May 2012 11:40:25 -0400 1.7 +Subject: [PATCH 08/10] Bug 755869 - [11] Re-apply bug 687188 - Skia 1.8 + radial gradients should use the 0/1 color stop values 1.9 + for clamping. r=mattwoodrow 1.10 + 1.11 +--- 1.12 + gfx/skia/src/effects/SkGradientShader.cpp | 76 +++++++++++++++++++++++------ 1.13 + 1 files changed, 61 insertions(+), 15 deletions(-) 1.14 + 1.15 +diff --git a/gfx/skia/src/effects/SkGradientShader.cpp b/gfx/skia/src/effects/SkGradientShader.cpp 1.16 +index 59ba48c..ea05a39 100644 1.17 +--- a/gfx/skia/src/effects/SkGradientShader.cpp 1.18 ++++ b/gfx/skia/src/effects/SkGradientShader.cpp 1.19 +@@ -204,6 +204,7 @@ private: 1.20 + mutable SkMallocPixelRef* fCache32PixelRef; 1.21 + mutable unsigned fCacheAlpha; // the alpha value we used when we computed the cache. larger than 8bits so we can store uninitialized value 1.22 + 1.23 ++ static SkPMColor PremultiplyColor(SkColor c0, U8CPU alpha); 1.24 + static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int count); 1.25 + static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int count, 1.26 + U8CPU alpha); 1.27 +@@ -507,6 +508,21 @@ static inline U8CPU dither_ceil_fixed_to_8(SkFixed n) { 1.28 + return ((n << 1) - (n | (n >> 8))) >> 8; 1.29 + } 1.30 + 1.31 ++SkPMColor Gradient_Shader::PremultiplyColor(SkColor c0, U8CPU paintAlpha) 1.32 ++{ 1.33 ++ SkFixed a = SkMulDiv255Round(SkColorGetA(c0), paintAlpha); 1.34 ++ SkFixed r = SkColorGetR(c0); 1.35 ++ SkFixed g = SkColorGetG(c0); 1.36 ++ SkFixed b = SkColorGetB(c0); 1.37 ++ 1.38 ++ a = SkIntToFixed(a) + 0x8000; 1.39 ++ r = SkIntToFixed(r) + 0x8000; 1.40 ++ g = SkIntToFixed(g) + 0x8000; 1.41 ++ b = SkIntToFixed(b) + 0x8000; 1.42 ++ 1.43 ++ return SkPremultiplyARGBInline(a >> 16, r >> 16, g >> 16, b >> 16); 1.44 ++} 1.45 ++ 1.46 + void Gradient_Shader::Build32bitCache(SkPMColor cache[], SkColor c0, SkColor c1, 1.47 + int count, U8CPU paintAlpha) { 1.48 + SkASSERT(count > 1); 1.49 +@@ -628,14 +644,14 @@ static void complete_32bit_cache(SkPMColor* cache, int stride) { 1.50 + const SkPMColor* Gradient_Shader::getCache32() const { 1.51 + if (fCache32 == NULL) { 1.52 + // double the count for dither entries 1.53 +- const int entryCount = kCache32Count * 2; 1.54 ++ const int entryCount = kCache32Count * 2 + 2; 1.55 + const size_t allocSize = sizeof(SkPMColor) * entryCount; 1.56 + 1.57 + if (NULL == fCache32PixelRef) { 1.58 + fCache32PixelRef = SkNEW_ARGS(SkMallocPixelRef, 1.59 + (NULL, allocSize, NULL)); 1.60 + } 1.61 +- fCache32 = (SkPMColor*)fCache32PixelRef->getAddr(); 1.62 ++ fCache32 = (SkPMColor*)fCache32PixelRef->getAddr() + 1; 1.63 + if (fColorCount == 2) { 1.64 + Build32bitCache(fCache32, fOrigColors[0], fOrigColors[1], 1.65 + kGradient32Length, fCacheAlpha); 1.66 +@@ -659,7 +675,7 @@ const SkPMColor* Gradient_Shader::getCache32() const { 1.67 + SkMallocPixelRef* newPR = SkNEW_ARGS(SkMallocPixelRef, 1.68 + (NULL, allocSize, NULL)); 1.69 + SkPMColor* linear = fCache32; // just computed linear data 1.70 +- SkPMColor* mapped = (SkPMColor*)newPR->getAddr(); // storage for mapped data 1.71 ++ SkPMColor* mapped = (SkPMColor*)newPR->getAddr() + 1; // storage for mapped data 1.72 + SkUnitMapper* map = fMapper; 1.73 + for (int i = 0; i < kGradient32Length; i++) { 1.74 + int index = map->mapUnit16((i << 8) | i) >> 8; 1.75 +@@ -668,10 +684,13 @@ const SkPMColor* Gradient_Shader::getCache32() const { 1.76 + } 1.77 + fCache32PixelRef->unref(); 1.78 + fCache32PixelRef = newPR; 1.79 +- fCache32 = (SkPMColor*)newPR->getAddr(); 1.80 ++ fCache32 = (SkPMColor*)newPR->getAddr() + 1; 1.81 + } 1.82 + complete_32bit_cache(fCache32, kCache32Count); 1.83 + } 1.84 ++ //Write the clamp colours into the first and last entries of fCache32 1.85 ++ fCache32[-1] = PremultiplyColor(fOrigColors[0], fCacheAlpha); 1.86 ++ fCache32[kCache32Count * 2] = PremultiplyColor(fOrigColors[fColorCount - 1], fCacheAlpha); 1.87 + return fCache32; 1.88 + } 1.89 + 1.90 +@@ -857,6 +876,18 @@ void shadeSpan_linear_vertical(TileProc proc, SkFixed dx, SkFixed fx, 1.91 + SkPMColor* SK_RESTRICT dstC, 1.92 + const SkPMColor* SK_RESTRICT cache, 1.93 + int toggle, int count) { 1.94 ++ if (proc == clamp_tileproc) { 1.95 ++ // Read out clamp values from beginning/end of the cache. No need to lerp 1.96 ++ // or dither 1.97 ++ if (fx < 0) { 1.98 ++ sk_memset32(dstC, cache[-1], count); 1.99 ++ return; 1.100 ++ } else if (fx > 0xFFFF) { 1.101 ++ sk_memset32(dstC, cache[Gradient_Shader::kCache32Count * 2], count); 1.102 ++ return; 1.103 ++ } 1.104 ++ } 1.105 ++ 1.106 + // We're a vertical gradient, so no change in a span. 1.107 + // If colors change sharply across the gradient, dithering is 1.108 + // insufficient (it subsamples the color space) and we need to lerp. 1.109 +@@ -875,6 +906,18 @@ void shadeSpan_linear_vertical_lerp(TileProc proc, SkFixed dx, SkFixed fx, 1.110 + SkPMColor* SK_RESTRICT dstC, 1.111 + const SkPMColor* SK_RESTRICT cache, 1.112 + int toggle, int count) { 1.113 ++ if (proc == clamp_tileproc) { 1.114 ++ // Read out clamp values from beginning/end of the cache. No need to lerp 1.115 ++ // or dither 1.116 ++ if (fx < 0) { 1.117 ++ sk_memset32(dstC, cache[-1], count); 1.118 ++ return; 1.119 ++ } else if (fx > 0xFFFF) { 1.120 ++ sk_memset32(dstC, cache[Gradient_Shader::kCache32Count * 2], count); 1.121 ++ return; 1.122 ++ } 1.123 ++ } 1.124 ++ 1.125 + // We're a vertical gradient, so no change in a span. 1.126 + // If colors change sharply across the gradient, dithering is 1.127 + // insufficient (it subsamples the color space) and we need to lerp. 1.128 +@@ -900,10 +943,8 @@ void shadeSpan_linear_clamp(TileProc proc, SkFixed dx, SkFixed fx, 1.129 + range.init(fx, dx, count, 0, Gradient_Shader::kGradient32Length); 1.130 + 1.131 + if ((count = range.fCount0) > 0) { 1.132 +- sk_memset32_dither(dstC, 1.133 +- cache[toggle + range.fV0], 1.134 +- cache[(toggle ^ Gradient_Shader::kDitherStride32) + range.fV0], 1.135 +- count); 1.136 ++ // Shouldn't be any need to dither for clamping? 1.137 ++ sk_memset32(dstC, cache[-1], count); 1.138 + dstC += count; 1.139 + } 1.140 + if ((count = range.fCount1) > 0) { 1.141 +@@ -922,10 +963,8 @@ void shadeSpan_linear_clamp(TileProc proc, SkFixed dx, SkFixed fx, 1.142 + } 1.143 + } 1.144 + if ((count = range.fCount2) > 0) { 1.145 +- sk_memset32_dither(dstC, 1.146 +- cache[toggle + range.fV1], 1.147 +- cache[(toggle ^ Gradient_Shader::kDitherStride32) + range.fV1], 1.148 +- count); 1.149 ++ // Shouldn't be any need to dither for clamping? 1.150 ++ sk_memset32(dstC, cache[Gradient_Shader::kCache32Count * 2], count); 1.151 + } 1.152 + } 1.153 + 1.154 +@@ -1796,9 +1835,16 @@ void shadeSpan_twopoint_clamp(SkScalar fx, SkScalar dx, 1.155 + for (; count > 0; --count) { 1.156 + SkFixed t = two_point_radial(b, fx, fy, fSr2D2, foura, 1.157 + fOneOverTwoA, posRoot); 1.158 +- SkFixed index = SkClampMax(t, 0xFFFF); 1.159 +- SkASSERT(index <= 0xFFFF); 1.160 +- *dstC++ = cache[index >> Gradient_Shader::kCache32Shift]; 1.161 ++ 1.162 ++ if (t < 0) { 1.163 ++ *dstC++ = cache[-1]; 1.164 ++ } else if (t > 0xFFFF) { 1.165 ++ *dstC++ = cache[Gradient_Shader::kCache32Count * 2]; 1.166 ++ } else { 1.167 ++ SkASSERT(t <= 0xFFFF); 1.168 ++ *dstC++ = cache[t >> Gradient_Shader::kCache32Shift]; 1.169 ++ } 1.170 ++ 1.171 + fx += dx; 1.172 + fy += dy; 1.173 + b += db; 1.174 +-- 1.175 +1.7.5.4 1.176 +