gfx/skia/patches/archive/0008-Bug-687188-Skia-radial-gradients.patch

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:35b72ab0cfd5
1 From f941ea32e44a2436d235e83ef1a434289a9d9c1e Mon Sep 17 00:00:00 2001
2 From: George Wright <gwright@mozilla.com>
3 Date: Wed, 23 May 2012 11:40:25 -0400
4 Subject: [PATCH 08/10] Bug 755869 - [11] Re-apply bug 687188 - Skia
5 radial gradients should use the 0/1 color stop values
6 for clamping. r=mattwoodrow
7
8 ---
9 gfx/skia/src/effects/SkGradientShader.cpp | 76 +++++++++++++++++++++++------
10 1 files changed, 61 insertions(+), 15 deletions(-)
11
12 diff --git a/gfx/skia/src/effects/SkGradientShader.cpp b/gfx/skia/src/effects/SkGradientShader.cpp
13 index 59ba48c..ea05a39 100644
14 --- a/gfx/skia/src/effects/SkGradientShader.cpp
15 +++ b/gfx/skia/src/effects/SkGradientShader.cpp
16 @@ -204,6 +204,7 @@ private:
17 mutable SkMallocPixelRef* fCache32PixelRef;
18 mutable unsigned fCacheAlpha; // the alpha value we used when we computed the cache. larger than 8bits so we can store uninitialized value
19
20 + static SkPMColor PremultiplyColor(SkColor c0, U8CPU alpha);
21 static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int count);
22 static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int count,
23 U8CPU alpha);
24 @@ -507,6 +508,21 @@ static inline U8CPU dither_ceil_fixed_to_8(SkFixed n) {
25 return ((n << 1) - (n | (n >> 8))) >> 8;
26 }
27
28 +SkPMColor Gradient_Shader::PremultiplyColor(SkColor c0, U8CPU paintAlpha)
29 +{
30 + SkFixed a = SkMulDiv255Round(SkColorGetA(c0), paintAlpha);
31 + SkFixed r = SkColorGetR(c0);
32 + SkFixed g = SkColorGetG(c0);
33 + SkFixed b = SkColorGetB(c0);
34 +
35 + a = SkIntToFixed(a) + 0x8000;
36 + r = SkIntToFixed(r) + 0x8000;
37 + g = SkIntToFixed(g) + 0x8000;
38 + b = SkIntToFixed(b) + 0x8000;
39 +
40 + return SkPremultiplyARGBInline(a >> 16, r >> 16, g >> 16, b >> 16);
41 +}
42 +
43 void Gradient_Shader::Build32bitCache(SkPMColor cache[], SkColor c0, SkColor c1,
44 int count, U8CPU paintAlpha) {
45 SkASSERT(count > 1);
46 @@ -628,14 +644,14 @@ static void complete_32bit_cache(SkPMColor* cache, int stride) {
47 const SkPMColor* Gradient_Shader::getCache32() const {
48 if (fCache32 == NULL) {
49 // double the count for dither entries
50 - const int entryCount = kCache32Count * 2;
51 + const int entryCount = kCache32Count * 2 + 2;
52 const size_t allocSize = sizeof(SkPMColor) * entryCount;
53
54 if (NULL == fCache32PixelRef) {
55 fCache32PixelRef = SkNEW_ARGS(SkMallocPixelRef,
56 (NULL, allocSize, NULL));
57 }
58 - fCache32 = (SkPMColor*)fCache32PixelRef->getAddr();
59 + fCache32 = (SkPMColor*)fCache32PixelRef->getAddr() + 1;
60 if (fColorCount == 2) {
61 Build32bitCache(fCache32, fOrigColors[0], fOrigColors[1],
62 kGradient32Length, fCacheAlpha);
63 @@ -659,7 +675,7 @@ const SkPMColor* Gradient_Shader::getCache32() const {
64 SkMallocPixelRef* newPR = SkNEW_ARGS(SkMallocPixelRef,
65 (NULL, allocSize, NULL));
66 SkPMColor* linear = fCache32; // just computed linear data
67 - SkPMColor* mapped = (SkPMColor*)newPR->getAddr(); // storage for mapped data
68 + SkPMColor* mapped = (SkPMColor*)newPR->getAddr() + 1; // storage for mapped data
69 SkUnitMapper* map = fMapper;
70 for (int i = 0; i < kGradient32Length; i++) {
71 int index = map->mapUnit16((i << 8) | i) >> 8;
72 @@ -668,10 +684,13 @@ const SkPMColor* Gradient_Shader::getCache32() const {
73 }
74 fCache32PixelRef->unref();
75 fCache32PixelRef = newPR;
76 - fCache32 = (SkPMColor*)newPR->getAddr();
77 + fCache32 = (SkPMColor*)newPR->getAddr() + 1;
78 }
79 complete_32bit_cache(fCache32, kCache32Count);
80 }
81 + //Write the clamp colours into the first and last entries of fCache32
82 + fCache32[-1] = PremultiplyColor(fOrigColors[0], fCacheAlpha);
83 + fCache32[kCache32Count * 2] = PremultiplyColor(fOrigColors[fColorCount - 1], fCacheAlpha);
84 return fCache32;
85 }
86
87 @@ -857,6 +876,18 @@ void shadeSpan_linear_vertical(TileProc proc, SkFixed dx, SkFixed fx,
88 SkPMColor* SK_RESTRICT dstC,
89 const SkPMColor* SK_RESTRICT cache,
90 int toggle, int count) {
91 + if (proc == clamp_tileproc) {
92 + // Read out clamp values from beginning/end of the cache. No need to lerp
93 + // or dither
94 + if (fx < 0) {
95 + sk_memset32(dstC, cache[-1], count);
96 + return;
97 + } else if (fx > 0xFFFF) {
98 + sk_memset32(dstC, cache[Gradient_Shader::kCache32Count * 2], count);
99 + return;
100 + }
101 + }
102 +
103 // We're a vertical gradient, so no change in a span.
104 // If colors change sharply across the gradient, dithering is
105 // insufficient (it subsamples the color space) and we need to lerp.
106 @@ -875,6 +906,18 @@ void shadeSpan_linear_vertical_lerp(TileProc proc, SkFixed dx, SkFixed fx,
107 SkPMColor* SK_RESTRICT dstC,
108 const SkPMColor* SK_RESTRICT cache,
109 int toggle, int count) {
110 + if (proc == clamp_tileproc) {
111 + // Read out clamp values from beginning/end of the cache. No need to lerp
112 + // or dither
113 + if (fx < 0) {
114 + sk_memset32(dstC, cache[-1], count);
115 + return;
116 + } else if (fx > 0xFFFF) {
117 + sk_memset32(dstC, cache[Gradient_Shader::kCache32Count * 2], count);
118 + return;
119 + }
120 + }
121 +
122 // We're a vertical gradient, so no change in a span.
123 // If colors change sharply across the gradient, dithering is
124 // insufficient (it subsamples the color space) and we need to lerp.
125 @@ -900,10 +943,8 @@ void shadeSpan_linear_clamp(TileProc proc, SkFixed dx, SkFixed fx,
126 range.init(fx, dx, count, 0, Gradient_Shader::kGradient32Length);
127
128 if ((count = range.fCount0) > 0) {
129 - sk_memset32_dither(dstC,
130 - cache[toggle + range.fV0],
131 - cache[(toggle ^ Gradient_Shader::kDitherStride32) + range.fV0],
132 - count);
133 + // Shouldn't be any need to dither for clamping?
134 + sk_memset32(dstC, cache[-1], count);
135 dstC += count;
136 }
137 if ((count = range.fCount1) > 0) {
138 @@ -922,10 +963,8 @@ void shadeSpan_linear_clamp(TileProc proc, SkFixed dx, SkFixed fx,
139 }
140 }
141 if ((count = range.fCount2) > 0) {
142 - sk_memset32_dither(dstC,
143 - cache[toggle + range.fV1],
144 - cache[(toggle ^ Gradient_Shader::kDitherStride32) + range.fV1],
145 - count);
146 + // Shouldn't be any need to dither for clamping?
147 + sk_memset32(dstC, cache[Gradient_Shader::kCache32Count * 2], count);
148 }
149 }
150
151 @@ -1796,9 +1835,16 @@ void shadeSpan_twopoint_clamp(SkScalar fx, SkScalar dx,
152 for (; count > 0; --count) {
153 SkFixed t = two_point_radial(b, fx, fy, fSr2D2, foura,
154 fOneOverTwoA, posRoot);
155 - SkFixed index = SkClampMax(t, 0xFFFF);
156 - SkASSERT(index <= 0xFFFF);
157 - *dstC++ = cache[index >> Gradient_Shader::kCache32Shift];
158 +
159 + if (t < 0) {
160 + *dstC++ = cache[-1];
161 + } else if (t > 0xFFFF) {
162 + *dstC++ = cache[Gradient_Shader::kCache32Count * 2];
163 + } else {
164 + SkASSERT(t <= 0xFFFF);
165 + *dstC++ = cache[t >> Gradient_Shader::kCache32Shift];
166 + }
167 +
168 fx += dx;
169 fy += dy;
170 b += db;
171 --
172 1.7.5.4
173

mercurial