diff options
author | reed <reed@google.com> | 2016-01-05 10:01:38 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-05 10:01:38 -0800 |
commit | aeab8ea4d7492dc996fa72de7298de81f8deed93 (patch) | |
tree | 6199717e6ea013b7e8e535a2e5f5268b5db9042d /src/effects/gradients | |
parent | 05dd251e5e135626d170b9e77eb64729bd482169 (diff) |
fix linear gradient assert, by explicitly clamping
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1556993003
Review URL: https://codereview.chromium.org/1556993003
Diffstat (limited to 'src/effects/gradients')
-rw-r--r-- | src/effects/gradients/SkLinearGradient.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp index 298466c8a6..4f90c27c8c 100644 --- a/src/effects/gradients/SkLinearGradient.cpp +++ b/src/effects/gradients/SkLinearGradient.cpp @@ -668,12 +668,12 @@ void SkLinearGradient::LinearGradientContext::shade4_dx_clamp(SkPMColor dstC[], } fx += n * dx; - count -= n; - SkASSERT(count >= 0); + // fx should now outside of the p0..p1 interval. However, due to float precision loss, + // its possible that fx is slightly too small/large, so we clamp it. if (dx_is_pos) { - SkASSERT(0 == count || fx >= p1); + fx = SkTMax(fx, p1); } else { - SkASSERT(0 == count || fx <= p0); + fx = SkTMin(fx, p0); } ramp<apply_alpha>(dstC, n, c, dc, dither0, dither1); @@ -683,6 +683,9 @@ void SkLinearGradient::LinearGradientContext::shade4_dx_clamp(SkPMColor dstC[], if (n & 1) { SkTSwap(dither0, dither1); } + + count -= n; + SkASSERT(count >= 0); } } |