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

Side by Side Diff: tests/GradientTest.cpp

Issue 1456783005: Fix nearly-vertical gradient assert (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month 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"
11 #include "SkShader.h" 11 #include "SkShader.h"
12 #include "SkSurface.h"
12 #include "SkTemplates.h" 13 #include "SkTemplates.h"
13 #include "Test.h" 14 #include "Test.h"
14 15
15 // https://code.google.com/p/chromium/issues/detail?id=448299 16 // https://code.google.com/p/chromium/issues/detail?id=448299
16 // Giant (inverse) matrix causes overflow when converting/computing using 32.32 17 // Giant (inverse) matrix causes overflow when converting/computing using 32.32
17 // Before the fix, we would assert (and then crash). 18 // Before the fix, we would assert (and then crash).
18 static void test_big_grad(skiatest::Reporter* reporter) { 19 static void test_big_grad(skiatest::Reporter* reporter) {
19 const SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; 20 const SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
20 const SkPoint pts[] = {{ 15, 14.7112684f }, { 0.709064007f, 12.6108112f }}; 21 const SkPoint pts[] = {{ 15, 14.7112684f }, { 0.709064007f, 12.6108112f }};
21 SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShad er::kClamp_TileMode); 22 SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShad er::kClamp_TileMode);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 radial_gradproc, 190 radial_gradproc,
190 sweep_gradproc, 191 sweep_gradproc,
191 conical_gradproc, 192 conical_gradproc,
192 }; 193 };
193 194
194 for (size_t i = 0; i < SK_ARRAY_COUNT(gProcs); ++i) { 195 for (size_t i = 0; i < SK_ARRAY_COUNT(gProcs); ++i) {
195 gProcs[i](reporter, rec); 196 gProcs[i](reporter, rec);
196 } 197 }
197 } 198 }
198 199
200 static void test_nearly_vertical(skiatest::Reporter* reporter) {
201 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(200, 200));
202
203 const SkPoint pts[] = {{ 100, 50 }, { 100.0001f, 50000 }};
204 const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
205 const SkScalar pos[] = { 0, 1 };
206 SkAutoTUnref<SkShader> gradient(
207 SkGradientShader::CreateLinear(pts, colors, pos, 2, SkShader::kClamp_Til eMode));
208
209 SkPaint paint;
210 paint.setShader(gradient);
211
212 surface->getCanvas()->drawPaint(paint);
213 }
214
199 DEF_TEST(Gradient, reporter) { 215 DEF_TEST(Gradient, reporter) {
200 TestGradientShaders(reporter); 216 TestGradientShaders(reporter);
201 TestConstantGradient(reporter); 217 TestConstantGradient(reporter);
202 test_big_grad(reporter); 218 test_big_grad(reporter);
219 test_nearly_vertical(reporter);
203 } 220 }
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