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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/effects/gradients/SkLinearGradient.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkColorShader.h" 9 #include "SkColorShader.h"
10 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 const SkScalar pos[] = { 0, 1 }; 205 const SkScalar pos[] = { 0, 1 };
206 SkAutoTUnref<SkShader> gradient( 206 SkAutoTUnref<SkShader> gradient(
207 SkGradientShader::CreateLinear(pts, colors, pos, 2, SkShader::kClamp_Til eMode)); 207 SkGradientShader::CreateLinear(pts, colors, pos, 2, SkShader::kClamp_Til eMode));
208 208
209 SkPaint paint; 209 SkPaint paint;
210 paint.setShader(gradient); 210 paint.setShader(gradient);
211 211
212 surface->getCanvas()->drawPaint(paint); 212 surface->getCanvas()->drawPaint(paint);
213 } 213 }
214 214
215 // A linear gradient interval can, due to numerical imprecision (likely in the d ivide)
216 // finish an interval with the final fx not landing outside of [p0...p1].
217 // The old code had an assert which this test triggered.
218 // We now explicitly clamp the resulting fx value.
219 static void test_linear_fuzz(skiatest::Reporter* reporter) {
220 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(1300, 630));
221
222 const SkPoint pts[] = {{ 179.5f, -179.5f }, { 1074.5f, 715.5f }};
223 const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_C olorWHITE };
224 const SkScalar pos[] = {0, 0.200000003f, 0.800000012f, 1 };
225
226
227 SkAutoTUnref<SkShader> gradient(
228 SkGradientShader::CreateLinear(pts, colors, pos, 4, SkShader: :kClamp_TileMode));
229
230 SkPaint paint;
231 paint.setShader(gradient);
232 SkRect r = {0, 83, 1254, 620};
233 surface->getCanvas()->drawRect(r, paint);
234 }
235
215 DEF_TEST(Gradient, reporter) { 236 DEF_TEST(Gradient, reporter) {
216 TestGradientShaders(reporter); 237 TestGradientShaders(reporter);
217 TestConstantGradient(reporter); 238 TestConstantGradient(reporter);
218 test_big_grad(reporter); 239 test_big_grad(reporter);
219 test_nearly_vertical(reporter); 240 test_nearly_vertical(reporter);
241 test_linear_fuzz(reporter);
220 } 242 }
OLDNEW
« 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