diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-04-18 19:59:38 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-04-18 19:59:38 +0000 |
commit | 13659f1f8d2e705c565203d45870b1afcd47cf98 (patch) | |
tree | 37bcae73b9ebb93f7d33fefc0ed30c858b3c4564 /src/effects | |
parent | 8b484419e80762ccdecca9ac2c10c1c29368cf2f (diff) |
handle overflow
note: gradient caller doesn't so we can still draw wrong when the caller
converts its initial fx from float->fixed. Perhaps SkClampRange should offer
a float interface as well.
git-svn-id: http://skia.googlecode.com/svn/trunk@1149 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/effects')
-rw-r--r-- | src/effects/SkGradientShader.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/effects/SkGradientShader.cpp b/src/effects/SkGradientShader.cpp index 068913f03f..5af04862f2 100644 --- a/src/effects/SkGradientShader.cpp +++ b/src/effects/SkGradientShader.cpp @@ -27,7 +27,7 @@ #define USE_DITHER_32BIT_GRADIENT #endif -//#define SK_ENABLE_FAST_LINEAR_GRADIENTS +#define SK_ENABLE_FAST_LINEAR_GRADIENTS #ifdef SK_ENABLE_FAST_LINEAR_GRADIENTS static void sk_memset32_dither(uint32_t dst[], uint32_t v0, uint32_t v1, @@ -819,11 +819,13 @@ static inline bool no_need_for_clamp(int fx, int dx, int count) { #include "SkClampRange.h" #define NO_CHECK_ITER \ - fi = fx >> 8; \ + do { \ + unsigned fi = fx >> 8; \ SkASSERT(fi <= 0xFF); \ fx += dx; \ *dstC++ = cache[toggle + fi]; \ - toggle ^= TOGGLE_MASK + toggle ^= TOGGLE_MASK; \ + } while (0) void Linear_Gradient::shadeSpan(int x, int y, SkPMColor dstC[], int count) { @@ -874,9 +876,9 @@ void Linear_Gradient::shadeSpan(int x, int y, SkPMColor dstC[], int count) { dstC += count; } if ((count = range.fCount1) > 0) { - unsigned fi; - int i, unroll = count >> 3; - for (i = 0; i < unroll; i++) { + int unroll = count >> 3; + fx = range.fFx1; + for (int i = 0; i < unroll; i++) { NO_CHECK_ITER; NO_CHECK_ITER; NO_CHECK_ITER; NO_CHECK_ITER; NO_CHECK_ITER; NO_CHECK_ITER; @@ -978,11 +980,13 @@ static void dither_memset16(uint16_t dst[], uint16_t value, uint16_t other, } #define NO_CHECK_ITER_16 \ - fi = fx >> kCache16Shift; \ + do { \ + unsigned fi = fx >> kCache16Shift; \ SkASSERT(fi <= kCache16Mask); \ fx += dx; \ *dstC++ = cache[toggle + fi]; \ - toggle ^= TOGGLE_MASK + toggle ^= TOGGLE_MASK; \ + } while (0) void Linear_Gradient::shadeSpan16(int x, int y, uint16_t dstC[], int count) { @@ -1028,9 +1032,9 @@ void Linear_Gradient::shadeSpan16(int x, int y, uint16_t dstC[], int count) { dstC += count; } if ((count = range.fCount1) > 0) { - unsigned fi; - int i, unroll = count >> 3; - for (i = 0; i < unroll; i++) { + int unroll = count >> 3; + fx = range.fFx1; + for (int i = 0; i < unroll; i++) { NO_CHECK_ITER_16; NO_CHECK_ITER_16; NO_CHECK_ITER_16; NO_CHECK_ITER_16; NO_CHECK_ITER_16; NO_CHECK_ITER_16; |