Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | From: George Wright <gw@gwright.org.uk> |
michael@0 | 2 | Date: Thu, 25 Apr 2013 20:47:06 -0400 |
michael@0 | 3 | Subject: Bug 848491 - Re-apply bug 687188 - Expand the gradient cache by 2 to store 0/1 colour stop values for clamping. |
michael@0 | 4 | |
michael@0 | 5 | |
michael@0 | 6 | diff --git a/gfx/skia/src/effects/gradients/SkGradientShader.cpp b/gfx/skia/src/effects/gradients/SkGradientShader.cpp |
michael@0 | 7 | index 684355d..27a9c46 100644 |
michael@0 | 8 | --- a/gfx/skia/src/effects/gradients/SkGradientShader.cpp |
michael@0 | 9 | +++ b/gfx/skia/src/effects/gradients/SkGradientShader.cpp |
michael@0 | 10 | @@ -453,15 +453,15 @@ const uint16_t* SkGradientShaderBase::getCache16() const { |
michael@0 | 11 | |
michael@0 | 12 | const SkPMColor* SkGradientShaderBase::getCache32() const { |
michael@0 | 13 | if (fCache32 == NULL) { |
michael@0 | 14 | - // double the count for dither entries |
michael@0 | 15 | - const int entryCount = kCache32Count * 4; |
michael@0 | 16 | + // double the count for dither entries, and have an extra two entries for clamp values |
michael@0 | 17 | + const int entryCount = kCache32Count * 4 + 2; |
michael@0 | 18 | const size_t allocSize = sizeof(SkPMColor) * entryCount; |
michael@0 | 19 | |
michael@0 | 20 | if (NULL == fCache32PixelRef) { |
michael@0 | 21 | fCache32PixelRef = SkNEW_ARGS(SkMallocPixelRef, |
michael@0 | 22 | (NULL, allocSize, NULL)); |
michael@0 | 23 | } |
michael@0 | 24 | - fCache32 = (SkPMColor*)fCache32PixelRef->getAddr(); |
michael@0 | 25 | + fCache32 = (SkPMColor*)fCache32PixelRef->getAddr() + 1; |
michael@0 | 26 | if (fColorCount == 2) { |
michael@0 | 27 | Build32bitCache(fCache32, fOrigColors[0], fOrigColors[1], |
michael@0 | 28 | kCache32Count, fCacheAlpha); |
michael@0 | 29 | @@ -484,7 +484,7 @@ const SkPMColor* SkGradientShaderBase::getCache32() const { |
michael@0 | 30 | SkMallocPixelRef* newPR = SkNEW_ARGS(SkMallocPixelRef, |
michael@0 | 31 | (NULL, allocSize, NULL)); |
michael@0 | 32 | SkPMColor* linear = fCache32; // just computed linear data |
michael@0 | 33 | - SkPMColor* mapped = (SkPMColor*)newPR->getAddr(); // storage for mapped data |
michael@0 | 34 | + SkPMColor* mapped = (SkPMColor*)newPR->getAddr() + 1; // storage for mapped data |
michael@0 | 35 | SkUnitMapper* map = fMapper; |
michael@0 | 36 | for (int i = 0; i < kCache32Count; i++) { |
michael@0 | 37 | int index = map->mapUnit16((i << 8) | i) >> 8; |
michael@0 | 38 | @@ -495,9 +495,21 @@ const SkPMColor* SkGradientShaderBase::getCache32() const { |
michael@0 | 39 | } |
michael@0 | 40 | fCache32PixelRef->unref(); |
michael@0 | 41 | fCache32PixelRef = newPR; |
michael@0 | 42 | - fCache32 = (SkPMColor*)newPR->getAddr(); |
michael@0 | 43 | + fCache32 = (SkPMColor*)newPR->getAddr() + 1; |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | + |
michael@0 | 47 | + // Write the clamp colours into the first and last entries of fCache32 |
michael@0 | 48 | + fCache32[kCache32ClampLower] = SkPackARGB32(fCacheAlpha, |
michael@0 | 49 | + SkColorGetR(fOrigColors[0]), |
michael@0 | 50 | + SkColorGetG(fOrigColors[0]), |
michael@0 | 51 | + SkColorGetB(fOrigColors[0])); |
michael@0 | 52 | + |
michael@0 | 53 | + fCache32[kCache32ClampUpper] = SkPackARGB32(fCacheAlpha, |
michael@0 | 54 | + SkColorGetR(fOrigColors[fColorCount - 1]), |
michael@0 | 55 | + SkColorGetG(fOrigColors[fColorCount - 1]), |
michael@0 | 56 | + SkColorGetB(fOrigColors[fColorCount - 1])); |
michael@0 | 57 | + |
michael@0 | 58 | return fCache32; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | diff --git a/gfx/skia/src/effects/gradients/SkGradientShaderPriv.h b/gfx/skia/src/effects/gradients/SkGradientShaderPriv.h |
michael@0 | 62 | index 729ce4e..2cb6a9d 100644 |
michael@0 | 63 | --- a/gfx/skia/src/effects/gradients/SkGradientShaderPriv.h |
michael@0 | 64 | +++ b/gfx/skia/src/effects/gradients/SkGradientShaderPriv.h |
michael@0 | 65 | @@ -86,6 +86,9 @@ public: |
michael@0 | 66 | /// if dithering is disabled. |
michael@0 | 67 | kDitherStride32 = kCache32Count, |
michael@0 | 68 | kDitherStride16 = kCache16Count, |
michael@0 | 69 | + |
michael@0 | 70 | + kCache32ClampLower = -1, |
michael@0 | 71 | + kCache32ClampUpper = kCache32Count * 4 |
michael@0 | 72 | }; |
michael@0 | 73 | |
michael@0 | 74 | |
michael@0 | 75 | diff --git a/gfx/skia/src/effects/gradients/SkLinearGradient.cpp b/gfx/skia/src/effects/gradients/SkLinearGradient.cpp |
michael@0 | 76 | index e0f216c..40ab918 100644 |
michael@0 | 77 | --- a/gfx/skia/src/effects/gradients/SkLinearGradient.cpp |
michael@0 | 78 | +++ b/gfx/skia/src/effects/gradients/SkLinearGradient.cpp |
michael@0 | 79 | @@ -127,6 +127,17 @@ void shadeSpan_linear_vertical_lerp(TileProc proc, SkFixed dx, SkFixed fx, |
michael@0 | 80 | SkPMColor* SK_RESTRICT dstC, |
michael@0 | 81 | const SkPMColor* SK_RESTRICT cache, |
michael@0 | 82 | int toggle, int count) { |
michael@0 | 83 | + if (proc == clamp_tileproc) { |
michael@0 | 84 | + // No need to lerp or dither for clamp values |
michael@0 | 85 | + if (fx < 0) { |
michael@0 | 86 | + sk_memset32(dstC, cache[SkGradientShaderBase::kCache32ClampLower], count); |
michael@0 | 87 | + return; |
michael@0 | 88 | + } else if (fx > 0xffff) { |
michael@0 | 89 | + sk_memset32(dstC, cache[SkGradientShaderBase::kCache32ClampUpper], count); |
michael@0 | 90 | + return; |
michael@0 | 91 | + } |
michael@0 | 92 | + } |
michael@0 | 93 | + |
michael@0 | 94 | // We're a vertical gradient, so no change in a span. |
michael@0 | 95 | // If colors change sharply across the gradient, dithering is |
michael@0 | 96 | // insufficient (it subsamples the color space) and we need to lerp. |
michael@0 | 97 | @@ -154,10 +165,7 @@ void shadeSpan_linear_clamp(TileProc proc, SkFixed dx, SkFixed fx, |
michael@0 | 98 | range.init(fx, dx, count, 0, SkGradientShaderBase::kCache32Count - 1); |
michael@0 | 99 | |
michael@0 | 100 | if ((count = range.fCount0) > 0) { |
michael@0 | 101 | - sk_memset32_dither(dstC, |
michael@0 | 102 | - cache[toggle + range.fV0], |
michael@0 | 103 | - cache[next_dither_toggle(toggle) + range.fV0], |
michael@0 | 104 | - count); |
michael@0 | 105 | + sk_memset32(dstC, cache[SkGradientShaderBase::kCache32ClampLower], count); |
michael@0 | 106 | dstC += count; |
michael@0 | 107 | } |
michael@0 | 108 | if ((count = range.fCount1) > 0) { |
michael@0 | 109 | @@ -176,10 +184,7 @@ void shadeSpan_linear_clamp(TileProc proc, SkFixed dx, SkFixed fx, |
michael@0 | 110 | } |
michael@0 | 111 | } |
michael@0 | 112 | if ((count = range.fCount2) > 0) { |
michael@0 | 113 | - sk_memset32_dither(dstC, |
michael@0 | 114 | - cache[toggle + range.fV1], |
michael@0 | 115 | - cache[next_dither_toggle(toggle) + range.fV1], |
michael@0 | 116 | - count); |
michael@0 | 117 | + sk_memset32(dstC, cache[SkGradientShaderBase::kCache32ClampUpper], count); |
michael@0 | 118 | } |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | diff --git a/gfx/skia/src/effects/gradients/SkTwoPointConicalGradient.cpp b/gfx/skia/src/effects/gradients/SkTwoPointConicalGradient.cpp |
michael@0 | 122 | index abd974b..601fff4 100644 |
michael@0 | 123 | --- a/gfx/skia/src/effects/gradients/SkTwoPointConicalGradient.cpp |
michael@0 | 124 | +++ b/gfx/skia/src/effects/gradients/SkTwoPointConicalGradient.cpp |
michael@0 | 125 | @@ -124,10 +124,14 @@ static void twopoint_clamp(TwoPtRadial* rec, SkPMColor* SK_RESTRICT dstC, |
michael@0 | 126 | if (TwoPtRadial::DontDrawT(t)) { |
michael@0 | 127 | *dstC++ = 0; |
michael@0 | 128 | } else { |
michael@0 | 129 | - SkFixed index = SkClampMax(t, 0xFFFF); |
michael@0 | 130 | - SkASSERT(index <= 0xFFFF); |
michael@0 | 131 | - *dstC++ = cache[toggle + |
michael@0 | 132 | - (index >> SkGradientShaderBase::kCache32Shift)]; |
michael@0 | 133 | + if (t < 0) { |
michael@0 | 134 | + *dstC++ = cache[SkGradientShaderBase::kCache32ClampLower]; |
michael@0 | 135 | + } else if (t > 0xFFFF) { |
michael@0 | 136 | + *dstC++ = cache[SkGradientShaderBase::kCache32ClampUpper]; |
michael@0 | 137 | + } else { |
michael@0 | 138 | + SkASSERT(t <= 0xFFFF); |
michael@0 | 139 | + *dstC++ = cache[t >> SkGradientShaderBase::kCache32Shift]; |
michael@0 | 140 | + } |
michael@0 | 141 | } |
michael@0 | 142 | toggle = next_dither_toggle(toggle); |
michael@0 | 143 | } |
michael@0 | 144 | diff --git a/gfx/skia/src/effects/gradients/SkTwoPointRadialGradient.cpp b/gfx/skia/src/effects/gradients/SkTwoPointRadialGradient.cpp |
michael@0 | 145 | index f70b67d..ec2ae75 100644 |
michael@0 | 146 | --- a/gfx/skia/src/effects/gradients/SkTwoPointRadialGradient.cpp |
michael@0 | 147 | +++ b/gfx/skia/src/effects/gradients/SkTwoPointRadialGradient.cpp |
michael@0 | 148 | @@ -120,9 +120,14 @@ void shadeSpan_twopoint_clamp(SkScalar fx, SkScalar dx, |
michael@0 | 149 | for (; count > 0; --count) { |
michael@0 | 150 | SkFixed t = two_point_radial(b, fx, fy, fSr2D2, foura, |
michael@0 | 151 | fOneOverTwoA, posRoot); |
michael@0 | 152 | - SkFixed index = SkClampMax(t, 0xFFFF); |
michael@0 | 153 | - SkASSERT(index <= 0xFFFF); |
michael@0 | 154 | - *dstC++ = cache[index >> SkGradientShaderBase::kCache32Shift]; |
michael@0 | 155 | + if (t < 0) { |
michael@0 | 156 | + *dstC++ = cache[SkGradientShaderBase::kCache32ClampLower]; |
michael@0 | 157 | + } else if (t > 0xFFFF) { |
michael@0 | 158 | + *dstC++ = cache[SkGradientShaderBase::kCache32ClampUpper]; |
michael@0 | 159 | + } else { |
michael@0 | 160 | + SkASSERT(t <= 0xFFFF); |
michael@0 | 161 | + *dstC++ = cache[t >> SkGradientShaderBase::kCache32Shift]; |
michael@0 | 162 | + } |
michael@0 | 163 | fx += dx; |
michael@0 | 164 | fy += dy; |
michael@0 | 165 | b += db; |
michael@0 | 166 | -- |
michael@0 | 167 | 1.7.11.7 |
michael@0 | 168 |