Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Unified Diff: tests/GradientTest.cpp

Issue 1556993003: fix linear gradient assert, by explicitly clamping (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/effects/gradients/SkLinearGradient.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/GradientTest.cpp
diff --git a/tests/GradientTest.cpp b/tests/GradientTest.cpp
index 8d73569f649d53ff04be9837f400f38579c08ff1..6a277d520efa64d51b654d853cf0297bff95ac31 100644
--- a/tests/GradientTest.cpp
+++ b/tests/GradientTest.cpp
@@ -212,9 +212,31 @@ static void test_nearly_vertical(skiatest::Reporter* reporter) {
surface->getCanvas()->drawPaint(paint);
}
+// A linear gradient interval can, due to numerical imprecision (likely in the divide)
+// finish an interval with the final fx not landing outside of [p0...p1].
+// The old code had an assert which this test triggered.
+// We now explicitly clamp the resulting fx value.
+static void test_linear_fuzz(skiatest::Reporter* reporter) {
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(1300, 630));
+
+ const SkPoint pts[] = {{ 179.5f, -179.5f }, { 1074.5f, 715.5f }};
+ const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE };
+ const SkScalar pos[] = {0, 0.200000003f, 0.800000012f, 1 };
+
+
+ SkAutoTUnref<SkShader> gradient(
+ SkGradientShader::CreateLinear(pts, colors, pos, 4, SkShader::kClamp_TileMode));
+
+ SkPaint paint;
+ paint.setShader(gradient);
+ SkRect r = {0, 83, 1254, 620};
+ surface->getCanvas()->drawRect(r, paint);
+}
+
DEF_TEST(Gradient, reporter) {
TestGradientShaders(reporter);
TestConstantGradient(reporter);
test_big_grad(reporter);
test_nearly_vertical(reporter);
+ test_linear_fuzz(reporter);
}
« no previous file with comments | « src/effects/gradients/SkLinearGradient.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698