aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects/gradients
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2016-11-20 19:10:59 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-29 21:24:44 +0000
commit5b1a7c21006175d313aad09ef40f9453a21480e2 (patch)
treea448958c0ff79193095f277dd0eb7e36cc18a293 /src/effects/gradients
parent8b7a7ddea344eed96f095652359c5c86349f86d0 (diff)
Fuzzer assert in GradientShaderBase4fContext::TSampler
Similar to https://codereview.chromium.org/2472763002, we also need to clamp the tiled value in kRepeat mode, to avoid snapping to 1.0f. R=reed@google.com,herb@google.com BUG=skia:5975 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5079 Change-Id: I8fdac36c0d112d5eb76e47c3e4156a79a4d13b36 Reviewed-on: https://skia-review.googlesource.com/5079 Reviewed-by: Herb Derby <herb@google.com> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'src/effects/gradients')
-rw-r--r--src/effects/gradients/Sk4fGradientBase.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/effects/gradients/Sk4fGradientBase.cpp b/src/effects/gradients/Sk4fGradientBase.cpp
index 0c54ba27bf..91f418564f 100644
--- a/src/effects/gradients/Sk4fGradientBase.cpp
+++ b/src/effects/gradients/Sk4fGradientBase.cpp
@@ -337,9 +337,19 @@ public:
TSampler(const GradientShaderBase4fContext& ctx)
: fFirstInterval(ctx.fIntervals.begin())
, fLastInterval(ctx.fIntervals.end() - 1)
- , fInterval(nullptr)
- , fLargestLessThanTwo(nextafterf(2, 0)) {
+ , fInterval(nullptr) {
SkASSERT(fLastInterval >= fFirstInterval);
+ switch (tileMode) {
+ case kClamp_TileMode:
+ fLargestIntervalValue = SK_ScalarInfinity;
+ break;
+ case kRepeat_TileMode:
+ fLargestIntervalValue = nextafterf(1, 0);
+ break;
+ case kMirror_TileMode:
+ fLargestIntervalValue = nextafterf(2.0f, 0);
+ break;
+ }
}
Sk4f sample(SkScalar t) {
@@ -368,11 +378,12 @@ private:
return t;
case kRepeat_TileMode:
// t % 1 (intervals range: [0..1))
- return t - SkScalarFloorToScalar(t);
+ // Due to the extra arithmetic, we must clamp to ensure the value remains less than 1.
+ return SkTMin(t - SkScalarFloorToScalar(t), fLargestIntervalValue);
case kMirror_TileMode:
// t % 2 (synthetic mirror intervals expand the range to [0..2)
// Due to the extra arithmetic, we must clamp to ensure the value remains less than 2.
- return SkTMin(t - SkScalarFloorToScalar(t / 2) * 2, fLargestLessThanTwo);
+ return SkTMin(t - SkScalarFloorToScalar(t / 2) * 2, fLargestIntervalValue);
}
SK_ABORT("Unhandled tile mode.");
@@ -442,7 +453,7 @@ private:
const Interval* fLastInterval;
const Interval* fInterval;
SkScalar fPrevT;
- SkScalar fLargestLessThanTwo;
+ SkScalar fLargestIntervalValue;
Sk4f fCc;
Sk4f fDc;
};