1 /*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "include/core/SkCanvas.h"
9 #include "include/core/SkColorPriv.h"
10 #include "include/core/SkShader.h"
11 #include "include/core/SkSurface.h"
12 #include "include/effects/SkGradientShader.h"
13 #include "include/private/SkTemplates.h"
14 #include "src/core/SkTLazy.h"
15 #include "src/shaders/SkColorShader.h"
16 #include "tests/Test.h"
17
18 // https://code.google.com/p/chromium/issues/detail?id=448299
19 // Giant (inverse) matrix causes overflow when converting/computing using 32.32
20 // Before the fix, we would assert (and then crash).
test_big_grad(skiatest::Reporter * reporter)21 static void test_big_grad(skiatest::Reporter* reporter) {
22 const SkColor colors[] = { SK_ColorRED, SK_ColorBLUE };
23 const SkPoint pts[] = {{ 15, 14.7112684f }, { 0.709064007f, 12.6108112f }};
24 SkPaint paint;
25 paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp));
26
27 SkBitmap bm;
28 bm.allocN32Pixels(2000, 1);
29 SkCanvas c(bm);
30
31 const SkScalar affine[] = {
32 1.06608627e-06f, 4.26434525e-07f, 6.2855f, 2.6611f, 273.4393f, 244.0046f
33 };
34 SkMatrix matrix;
35 matrix.setAffine(affine);
36 c.concat(matrix);
37
38 c.drawPaint(paint);
39 }
40
41 struct GradRec {
42 int fColorCount;
43 const SkColor* fColors;
44 const SkScalar* fPos;
45 const SkPoint* fPoint; // 2
46 const SkScalar* fRadius; // 2
47 SkTileMode fTileMode;
48
gradCheckGradRec49 void gradCheck(skiatest::Reporter* reporter, const sk_sp<SkShader>& shader,
50 SkShader::GradientInfo* info,
51 SkShader::GradientType gt) const {
52 SkAutoTMalloc<SkColor> colorStorage(fColorCount);
53 SkAutoTMalloc<SkScalar> posStorage(fColorCount);
54
55 info->fColorCount = fColorCount;
56 info->fColors = colorStorage;
57 info->fColorOffsets = posStorage.get();
58 REPORTER_ASSERT(reporter, shader->asAGradient(info) == gt);
59
60 REPORTER_ASSERT(reporter, info->fColorCount == fColorCount);
61 REPORTER_ASSERT(reporter,
62 !memcmp(info->fColors, fColors, fColorCount * sizeof(SkColor)));
63 REPORTER_ASSERT(reporter,
64 !memcmp(info->fColorOffsets, fPos, fColorCount * sizeof(SkScalar)));
65 REPORTER_ASSERT(reporter, fTileMode == (SkTileMode)info->fTileMode);
66 }
67 };
68
69
none_gradproc(skiatest::Reporter * reporter,const GradRec &,const GradRec &)70 static void none_gradproc(skiatest::Reporter* reporter, const GradRec&, const GradRec&) {
71 sk_sp<SkShader> s(SkShaders::Empty());
72 REPORTER_ASSERT(reporter, SkShader::kNone_GradientType == s->asAGradient(nullptr));
73 }
74
color_gradproc(skiatest::Reporter * reporter,const GradRec & rec,const GradRec &)75 static void color_gradproc(skiatest::Reporter* reporter, const GradRec& rec, const GradRec&) {
76 sk_sp<SkShader> s(new SkColorShader(rec.fColors[0]));
77 REPORTER_ASSERT(reporter, SkShader::kColor_GradientType == s->asAGradient(nullptr));
78
79 SkShader::GradientInfo info;
80 info.fColors = nullptr;
81 info.fColorCount = 0;
82 s->asAGradient(&info);
83 REPORTER_ASSERT(reporter, 1 == info.fColorCount);
84 }
85
linear_gradproc(skiatest::Reporter * reporter,const GradRec & buildRec,const GradRec & checkRec)86 static void linear_gradproc(skiatest::Reporter* reporter, const GradRec& buildRec,
87 const GradRec& checkRec) {
88 sk_sp<SkShader> s(SkGradientShader::MakeLinear(buildRec.fPoint, buildRec.fColors, buildRec.fPos,
89 buildRec.fColorCount, buildRec.fTileMode));
90
91 SkShader::GradientInfo info;
92 checkRec.gradCheck(reporter, s, &info, SkShader::kLinear_GradientType);
93 REPORTER_ASSERT(reporter, !memcmp(info.fPoint, checkRec.fPoint, 2 * sizeof(SkPoint)));
94 }
95
radial_gradproc(skiatest::Reporter * reporter,const GradRec & buildRec,const GradRec & checkRec)96 static void radial_gradproc(skiatest::Reporter* reporter, const GradRec& buildRec,
97 const GradRec& checkRec) {
98 sk_sp<SkShader> s(SkGradientShader::MakeRadial(buildRec.fPoint[0], buildRec.fRadius[0],
99 buildRec.fColors, buildRec.fPos,
100 buildRec.fColorCount, buildRec.fTileMode));
101
102 SkShader::GradientInfo info;
103 checkRec.gradCheck(reporter, s, &info, SkShader::kRadial_GradientType);
104 REPORTER_ASSERT(reporter, info.fPoint[0] == checkRec.fPoint[0]);
105 REPORTER_ASSERT(reporter, info.fRadius[0] == checkRec.fRadius[0]);
106 }
107
sweep_gradproc(skiatest::Reporter * reporter,const GradRec & buildRec,const GradRec & checkRec)108 static void sweep_gradproc(skiatest::Reporter* reporter, const GradRec& buildRec,
109 const GradRec& checkRec) {
110 sk_sp<SkShader> s(SkGradientShader::MakeSweep(buildRec.fPoint[0].fX, buildRec.fPoint[0].fY,
111 buildRec.fColors, buildRec.fPos,
112 buildRec.fColorCount));
113
114 SkShader::GradientInfo info;
115 checkRec.gradCheck(reporter, s, &info, SkShader::kSweep_GradientType);
116 REPORTER_ASSERT(reporter, info.fPoint[0] == checkRec.fPoint[0]);
117 }
118
conical_gradproc(skiatest::Reporter * reporter,const GradRec & buildRec,const GradRec & checkRec)119 static void conical_gradproc(skiatest::Reporter* reporter, const GradRec& buildRec,
120 const GradRec& checkRec) {
121 sk_sp<SkShader> s(SkGradientShader::MakeTwoPointConical(buildRec.fPoint[0],
122 buildRec.fRadius[0],
123 buildRec.fPoint[1],
124 buildRec.fRadius[1],
125 buildRec.fColors,
126 buildRec.fPos,
127 buildRec.fColorCount,
128 buildRec.fTileMode));
129
130 SkShader::GradientInfo info;
131 checkRec.gradCheck(reporter, s, &info, SkShader::kConical_GradientType);
132 REPORTER_ASSERT(reporter, !memcmp(info.fPoint, checkRec.fPoint, 2 * sizeof(SkPoint)));
133 REPORTER_ASSERT(reporter, !memcmp(info.fRadius, checkRec.fRadius, 2 * sizeof(SkScalar)));
134 }
135
136 // Ensure that repeated color gradients behave like drawing a single color
TestConstantGradient(skiatest::Reporter *)137 static void TestConstantGradient(skiatest::Reporter*) {
138 const SkPoint pts[] = {
139 { 0, 0 },
140 { SkIntToScalar(10), 0 }
141 };
142 SkColor colors[] = { SK_ColorBLUE, SK_ColorBLUE };
143 const SkScalar pos[] = { 0, SK_Scalar1 };
144 SkPaint paint;
145 paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 2, SkTileMode::kClamp));
146 SkBitmap outBitmap;
147 outBitmap.allocN32Pixels(10, 1);
148 SkCanvas canvas(outBitmap);
149 canvas.drawPaint(paint);
150 for (int i = 0; i < 10; i++) {
151 // The following is commented out because it currently fails
152 // Related bug: https://code.google.com/p/skia/issues/detail?id=1098
153
154 // REPORTER_ASSERT(reporter, SK_ColorBLUE == outBitmap.getColor(i, 0));
155 }
156 }
157
158 typedef void (*GradProc)(skiatest::Reporter* reporter, const GradRec&, const GradRec&);
159
TestGradientShaders(skiatest::Reporter * reporter)160 static void TestGradientShaders(skiatest::Reporter* reporter) {
161 static const SkColor gColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
162 static const SkScalar gPos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
163 static const SkPoint gPts[] = {
164 { 0, 0 },
165 { SkIntToScalar(10), SkIntToScalar(20) }
166 };
167 static const SkScalar gRad[] = { SkIntToScalar(1), SkIntToScalar(2) };
168
169 GradRec rec;
170 rec.fColorCount = SK_ARRAY_COUNT(gColors);
171 rec.fColors = gColors;
172 rec.fPos = gPos;
173 rec.fPoint = gPts;
174 rec.fRadius = gRad;
175 rec.fTileMode = SkTileMode::kClamp;
176
177 static const GradProc gProcs[] = {
178 none_gradproc,
179 color_gradproc,
180 linear_gradproc,
181 radial_gradproc,
182 sweep_gradproc,
183 conical_gradproc,
184 };
185
186 for (size_t i = 0; i < SK_ARRAY_COUNT(gProcs); ++i) {
187 gProcs[i](reporter, rec, rec);
188 }
189 }
190
TestGradientOptimization(skiatest::Reporter * reporter)191 static void TestGradientOptimization(skiatest::Reporter* reporter) {
192 static const struct {
193 GradProc fProc;
194 bool fIsClampRestricted;
195 } gProcInfo[] = {
196 { linear_gradproc , false },
197 { radial_gradproc , false },
198 { sweep_gradproc , true }, // sweep is funky in that it always pretends to be kClamp.
199 { conical_gradproc, false },
200 };
201
202 static const SkColor gC_00[] = { 0xff000000, 0xff000000 };
203 static const SkColor gC_01[] = { 0xff000000, 0xffffffff };
204 static const SkColor gC_11[] = { 0xffffffff, 0xffffffff };
205 static const SkColor gC_001[] = { 0xff000000, 0xff000000, 0xffffffff };
206 static const SkColor gC_011[] = { 0xff000000, 0xffffffff, 0xffffffff };
207 static const SkColor gC_0011[] = { 0xff000000, 0xff000000, 0xffffffff, 0xffffffff };
208
209 static const SkScalar gP_01[] = { 0, 1 };
210 static const SkScalar gP_001[] = { 0, 0, 1 };
211 static const SkScalar gP_011[] = { 0, 1, 1 };
212 static const SkScalar gP_0x1[] = { 0, .5f, 1 };
213 static const SkScalar gP_0011[] = { 0, 0, 1, 1 };
214
215 static const SkPoint gPts[] = { {0, 0}, {1, 1} };
216 static const SkScalar gRadii[] = { 1, 2 };
217
218 static const struct {
219 const SkColor* fCol;
220 const SkScalar* fPos;
221 int fCount;
222
223 const SkColor* fExpectedCol;
224 const SkScalar* fExpectedPos;
225 int fExpectedCount;
226 bool fRequiresNonClamp;
227 } gTests[] = {
228 { gC_001, gP_001, 3, gC_01, gP_01, 2, false },
229 { gC_001, gP_011, 3, gC_00, gP_01, 2, true },
230 { gC_001, gP_0x1, 3, gC_001, gP_0x1, 3, false },
231 { gC_001, nullptr, 3, gC_001, gP_0x1, 3, false },
232
233 { gC_011, gP_001, 3, gC_11, gP_01, 2, true },
234 { gC_011, gP_011, 3, gC_01, gP_01, 2, false },
235 { gC_011, gP_0x1, 3, gC_011, gP_0x1, 3, false },
236 { gC_011, nullptr, 3, gC_011, gP_0x1, 3, false },
237
238 { gC_0011, gP_0011, 4, gC_0011, gP_0011, 4, false },
239 };
240
241 const SkTileMode modes[] = {
242 SkTileMode::kClamp, SkTileMode::kRepeat, SkTileMode::kMirror,
243 // TODO: add kDecal_TileMode when it is implemented
244 };
245 for (size_t i = 0; i < SK_ARRAY_COUNT(gProcInfo); ++i) {
246 for (auto mode : modes) {
247 if (gProcInfo[i].fIsClampRestricted && mode != SkTileMode::kClamp) {
248 continue;
249 }
250
251 for (size_t t = 0; t < SK_ARRAY_COUNT(gTests); ++t) {
252 GradRec rec;
253 rec.fColorCount = gTests[t].fCount;
254 rec.fColors = gTests[t].fCol;
255 rec.fPos = gTests[t].fPos;
256 rec.fTileMode = mode;
257 rec.fPoint = gPts;
258 rec.fRadius = gRadii;
259
260 GradRec expected = rec;
261 if (!gTests[t].fRequiresNonClamp || mode != SkTileMode::kClamp) {
262 expected.fColorCount = gTests[t].fExpectedCount;
263 expected.fColors = gTests[t].fExpectedCol;
264 expected.fPos = gTests[t].fExpectedPos;
265 }
266
267 gProcInfo[i].fProc(reporter, rec, expected);
268 }
269 }
270 }
271 }
272
test_nearly_vertical(skiatest::Reporter * reporter)273 static void test_nearly_vertical(skiatest::Reporter* reporter) {
274 auto surface(SkSurface::MakeRasterN32Premul(200, 200));
275
276 const SkPoint pts[] = {{ 100, 50 }, { 100.0001f, 50000 }};
277 const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
278 const SkScalar pos[] = { 0, 1 };
279 SkPaint paint;
280 paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 2, SkTileMode::kClamp));
281
282 surface->getCanvas()->drawPaint(paint);
283 }
284
test_vertical(skiatest::Reporter * reporter)285 static void test_vertical(skiatest::Reporter* reporter) {
286 auto surface(SkSurface::MakeRasterN32Premul(200, 200));
287
288 const SkPoint pts[] = {{ 100, 50 }, { 100, 50 }};
289 const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
290 const SkScalar pos[] = { 0, 1 };
291 SkPaint paint;
292 paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 2, SkTileMode::kClamp));
293
294 surface->getCanvas()->drawPaint(paint);
295 }
296
297 // A linear gradient interval can, due to numerical imprecision (likely in the divide)
298 // finish an interval with the final fx not landing outside of [p0...p1].
299 // The old code had an assert which this test triggered.
300 // We now explicitly clamp the resulting fx value.
test_linear_fuzz(skiatest::Reporter * reporter)301 static void test_linear_fuzz(skiatest::Reporter* reporter) {
302 auto surface(SkSurface::MakeRasterN32Premul(1300, 630));
303
304 const SkPoint pts[] = {{ 179.5f, -179.5f }, { 1074.5f, 715.5f }};
305 const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE };
306 const SkScalar pos[] = {0, 0.200000003f, 0.800000012f, 1 };
307
308 SkPaint paint;
309 paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 4, SkTileMode::kClamp));
310
311 SkRect r = {0, 83, 1254, 620};
312 surface->getCanvas()->drawRect(r, paint);
313 }
314
315 // https://bugs.chromium.org/p/skia/issues/detail?id=5023
316 // We should still shade pixels for which the radius is exactly 0.
test_two_point_conical_zero_radius(skiatest::Reporter * reporter)317 static void test_two_point_conical_zero_radius(skiatest::Reporter* reporter) {
318 auto surface(SkSurface::MakeRasterN32Premul(5, 5));
319 surface->getCanvas()->clear(SK_ColorRED);
320
321 const SkColor colors[] = { SK_ColorGREEN, SK_ColorBLUE };
322 SkPaint p;
323 p.setShader(SkGradientShader::MakeTwoPointConical(
324 SkPoint::Make(2.5f, 2.5f), 0,
325 SkPoint::Make(3.0f, 3.0f), 10,
326 colors, nullptr, SK_ARRAY_COUNT(colors), SkTileMode::kClamp));
327 surface->getCanvas()->drawPaint(p);
328
329 // r == 0 for the center pixel.
330 // verify that we draw it (no red bleed)
331 SkPMColor centerPMColor;
332 surface->readPixels(SkImageInfo::MakeN32Premul(1, 1), ¢erPMColor, sizeof(SkPMColor), 2, 2);
333 REPORTER_ASSERT(reporter, SkGetPackedR32(centerPMColor) == 0);
334 }
335
336 // http://crbug.com/599458
test_clamping_overflow(skiatest::Reporter *)337 static void test_clamping_overflow(skiatest::Reporter*) {
338 SkPaint p;
339 const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN };
340 const SkPoint pts1[] = { SkPoint::Make(1001, 1000001), SkPoint::Make(1000.99f, 1000000) };
341
342 p.setShader(SkGradientShader::MakeLinear(pts1, colors, nullptr, 2, SkTileMode::kClamp));
343
344 sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(50, 50));
345 surface->getCanvas()->scale(100, 100);
346 surface->getCanvas()->drawPaint(p);
347
348 const SkPoint pts2[] = { SkPoint::Make(10000.99f, 1000000), SkPoint::Make(10001, 1000001) };
349 p.setShader(SkGradientShader::MakeLinear(pts2, colors, nullptr, 2, SkTileMode::kClamp));
350 surface->getCanvas()->drawPaint(p);
351
352 // Passes if we don't trigger asserts.
353 }
354
355 // http://crbug.com/636194
test_degenerate_linear(skiatest::Reporter *)356 static void test_degenerate_linear(skiatest::Reporter*) {
357 SkPaint p;
358 const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN };
359 const SkPoint pts[] = {
360 SkPoint::Make(-46058024627067344430605278824628224.0f, 0),
361 SkPoint::Make(SK_ScalarMax, 0)
362 };
363
364 p.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp));
365 sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(50, 50));
366 surface->getCanvas()->drawPaint(p);
367
368 // Passes if we don't trigger asserts.
369 }
370
371 // "Interesting" fuzzer values.
test_linear_fuzzer(skiatest::Reporter *)372 static void test_linear_fuzzer(skiatest::Reporter*) {
373 static const SkColor gColors0[] = { 0x30303030, 0x30303030 };
374 static const SkColor gColors1[] = { 0x30303030, 0x30303030, 0x30303030 };
375
376 static const SkScalar gPos1[] = { 0, 0, 1 };
377
378 static const SkScalar gMatrix0[9] = {
379 6.40969056e-10f, 0 , 6.40969056e-10f,
380 0 , 4.42539023e-39f, 6.40969056e-10f,
381 0 , 0 , 1
382 };
383 static const SkScalar gMatrix1[9] = {
384 -2.75294113f , 6.40969056e-10f, 6.40969056e-10f,
385 6.40969056e-10f, 6.40969056e-10f, -3.32810161e+24f,
386 6.40969056e-10f, 6.40969056e-10f, 0
387 };
388 static const SkScalar gMatrix2[9] = {
389 7.93481258e+17f, 6.40969056e-10f, 6.40969056e-10f,
390 6.40969056e-10f, 6.40969056e-10f, 6.40969056e-10f,
391 6.40969056e-10f, 6.40969056e-10f, 0.688235283f
392 };
393 static const SkScalar gMatrix3[9] = {
394 1.89180674e+11f, 6.40969056e-10f, 6.40969056e-10f,
395 6.40969056e-10f, 6.40969056e-10f, 6.40969056e-10f,
396 6.40969056e-10f, 11276.0469f , 8.12524808e+20f
397 };
398
399 static const struct {
400 SkPoint fPts[2];
401 const SkColor* fColors;
402 const SkScalar* fPos;
403 int fCount;
404 SkTileMode fTileMode;
405 uint32_t fFlags;
406 const SkScalar* fLocalMatrix;
407 const SkScalar* fGlobalMatrix;
408 } gConfigs[] = {
409 {
410 {{0, -2.752941f}, {0, 0}},
411 gColors0,
412 nullptr,
413 SK_ARRAY_COUNT(gColors0),
414 SkTileMode::kClamp,
415 0,
416 gMatrix0,
417 nullptr
418 },
419 {
420 {{4.42539023e-39f, -4.42539023e-39f}, {9.78041162e-15f, 4.42539023e-39f}},
421 gColors1,
422 gPos1,
423 SK_ARRAY_COUNT(gColors1),
424 SkTileMode::kClamp,
425 0,
426 nullptr,
427 gMatrix1
428 },
429 {
430 {{4.42539023e-39f, 6.40969056e-10f}, {6.40969056e-10f, 1.49237238e-19f}},
431 gColors1,
432 gPos1,
433 SK_ARRAY_COUNT(gColors1),
434 SkTileMode::kClamp,
435 0,
436 nullptr,
437 gMatrix2
438 },
439 {
440 {{6.40969056e-10f, 6.40969056e-10f}, {6.40969056e-10f, -0.688235283f}},
441 gColors0,
442 nullptr,
443 SK_ARRAY_COUNT(gColors0),
444 SkTileMode::kClamp,
445 0,
446 gMatrix3,
447 nullptr
448 },
449 };
450
451 sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
452 SkColorSpace* colorSpaces[] = {
453 nullptr, // hits the legacy gradient impl
454 srgb.get(), // triggers 4f/raster-pipeline
455 };
456
457 SkPaint paint;
458
459 for (auto colorSpace : colorSpaces) {
460
461 sk_sp<SkSurface> surface = SkSurface::MakeRaster(SkImageInfo::Make(100, 100,
462 kN32_SkColorType,
463 kPremul_SkAlphaType,
464 sk_ref_sp(colorSpace)));
465 SkCanvas* canvas = surface->getCanvas();
466
467 for (const auto& config : gConfigs) {
468 SkAutoCanvasRestore acr(canvas, false);
469 SkTLazy<SkMatrix> localMatrix;
470 if (config.fLocalMatrix) {
471 localMatrix.init();
472 localMatrix.get()->set9(config.fLocalMatrix);
473 }
474
475 paint.setShader(SkGradientShader::MakeLinear(config.fPts,
476 config.fColors,
477 config.fPos,
478 config.fCount,
479 config.fTileMode,
480 config.fFlags,
481 localMatrix.getMaybeNull()));
482 if (config.fGlobalMatrix) {
483 SkMatrix m;
484 m.set9(config.fGlobalMatrix);
485 canvas->save();
486 canvas->concat(m);
487 }
488
489 canvas->drawPaint(paint);
490 }
491 }
492 }
493
test_sweep_fuzzer(skiatest::Reporter *)494 static void test_sweep_fuzzer(skiatest::Reporter*) {
495 static const SkColor gColors0[] = { 0x30303030, 0x30303030, 0x30303030 };
496 static const SkScalar gPos0[] = { -47919293023455565225163489280.0f, 0, 1 };
497 static const SkScalar gMatrix0[9] = {
498 1.12116716e-13f, 0 , 8.50489682e+16f,
499 4.1917041e-41f , 3.51369881e-23f, -2.54344271e-26f,
500 9.61111907e+17f, -3.35263808e-29f, -1.35659403e+14f
501 };
502 static const struct {
503 SkPoint fCenter;
504 const SkColor* fColors;
505 const SkScalar* fPos;
506 int fCount;
507 const SkScalar* fGlobalMatrix;
508 } gConfigs[] = {
509 {
510 { 0, 0 },
511 gColors0,
512 gPos0,
513 SK_ARRAY_COUNT(gColors0),
514 gMatrix0
515 },
516 };
517
518 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(100, 100);
519 SkCanvas* canvas = surface->getCanvas();
520 SkPaint paint;
521
522 for (const auto& config : gConfigs) {
523 paint.setShader(SkGradientShader::MakeSweep(config.fCenter.x(),
524 config.fCenter.y(),
525 config.fColors,
526 config.fPos,
527 config.fCount));
528
529 SkAutoCanvasRestore acr(canvas, false);
530 if (config.fGlobalMatrix) {
531 SkMatrix m;
532 m.set9(config.fGlobalMatrix);
533 canvas->save();
534 canvas->concat(m);
535 }
536 canvas->drawPaint(paint);
537 }
538 }
539
DEF_TEST(Gradient,reporter)540 DEF_TEST(Gradient, reporter) {
541 TestGradientShaders(reporter);
542 TestGradientOptimization(reporter);
543 TestConstantGradient(reporter);
544 test_big_grad(reporter);
545 test_nearly_vertical(reporter);
546 test_vertical(reporter);
547 test_linear_fuzz(reporter);
548 test_two_point_conical_zero_radius(reporter);
549 test_clamping_overflow(reporter);
550 test_degenerate_linear(reporter);
551 test_linear_fuzzer(reporter);
552 test_sweep_fuzzer(reporter);
553 }
554