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/SkAlphaType.h"
9 #include "include/core/SkBitmap.h"
10 #include "include/core/SkBlurTypes.h"
11 #include "include/core/SkCanvas.h"
12 #include "include/core/SkColor.h"
13 #include "include/core/SkColorPriv.h"
14 #include "include/core/SkColorType.h"
15 #include "include/core/SkImageInfo.h"
16 #include "include/core/SkMaskFilter.h"
17 #include "include/core/SkPaint.h"
18 #include "include/core/SkPath.h"
19 #include "include/core/SkPathUtils.h"
20 #include "include/core/SkPixmap.h"
21 #include "include/core/SkPoint.h"
22 #include "include/core/SkRRect.h"
23 #include "include/core/SkRect.h"
24 #include "include/core/SkRefCnt.h"
25 #include "include/core/SkScalar.h"
26 #include "include/core/SkSize.h"
27 #include "include/core/SkSurface.h"
28 #include "include/core/SkTypes.h"
29 #include "include/effects/SkPerlinNoiseShader.h"
30 #include "include/gpu/GpuTypes.h"
31 #include "include/gpu/ganesh/GrDirectContext.h"
32 #include "include/gpu/ganesh/SkSurfaceGanesh.h"
33 #include "include/private/base/SkTPin.h"
34 #include "src/base/SkFloatBits.h"
35 #include "src/base/SkMathPriv.h"
36 #include "src/core/SkBlurMask.h"
37 #include "src/core/SkMask.h"
38 #include "src/core/SkMaskFilterBase.h"
39 #include "src/effects/SkEmbossMaskFilter.h"
40 #include "src/gpu/ganesh/GrBlurUtils.h"
41 #include "tests/CtsEnforcement.h"
42 #include "tests/Test.h"
43 #include "tools/ToolUtils.h"
44
45 #include <math.h>
46 #include <string.h>
47 #include <array>
48 #include <cstddef>
49 #include <cstdint>
50 #include <initializer_list>
51
52 struct GrContextOptions;
53
54 #define WRITE_CSV 0
55
56 ///////////////////////////////////////////////////////////////////////////////
57
58 static const int outset = 100;
59 static const SkColor bgColor = SK_ColorWHITE;
60 static const int strokeWidth = 4;
61
create(SkBitmap * bm,const SkIRect & bound)62 static void create(SkBitmap* bm, const SkIRect& bound) {
63 bm->allocN32Pixels(bound.width(), bound.height());
64 }
65
drawBG(SkCanvas * canvas)66 static void drawBG(SkCanvas* canvas) {
67 canvas->drawColor(bgColor);
68 }
69
70
71 struct BlurTest {
72 void (*addPath)(SkPath*);
73 int viewLen;
74 SkIRect views[9];
75 };
76
77 //Path Draw Procs
78 //Beware that paths themselves my draw differently depending on the clip.
draw50x50Rect(SkPath * path)79 static void draw50x50Rect(SkPath* path) {
80 path->addRect(0, 0, SkIntToScalar(50), SkIntToScalar(50));
81 }
82
83 //Tests
84 static BlurTest tests[] = {
85 { draw50x50Rect, 3, {
86 //inner half of blur
87 { 0, 0, 50, 50 },
88 //blur, but no path.
89 { 50 + strokeWidth/2, 50 + strokeWidth/2, 100, 100 },
90 //just an edge
91 { 40, strokeWidth, 60, 50 - strokeWidth },
92 }},
93 };
94
95 /** Assumes that the ref draw was completely inside ref canvas --
96 implies that everything outside is "bgColor".
97 Checks that all overlap is the same and that all non-overlap on the
98 ref is "bgColor".
99 */
compare(const SkBitmap & ref,const SkIRect & iref,const SkBitmap & test,const SkIRect & itest)100 static bool compare(const SkBitmap& ref, const SkIRect& iref,
101 const SkBitmap& test, const SkIRect& itest)
102 {
103 const int xOff = itest.fLeft - iref.fLeft;
104 const int yOff = itest.fTop - iref.fTop;
105
106 for (int y = 0; y < test.height(); ++y) {
107 for (int x = 0; x < test.width(); ++x) {
108 SkColor testColor = test.getColor(x, y);
109 int refX = x + xOff;
110 int refY = y + yOff;
111 SkColor refColor;
112 if (refX >= 0 && refX < ref.width() &&
113 refY >= 0 && refY < ref.height())
114 {
115 refColor = ref.getColor(refX, refY);
116 } else {
117 refColor = bgColor;
118 }
119 if (refColor != testColor) {
120 return false;
121 }
122 }
123 }
124 return true;
125 }
126
DEF_TEST(BlurDrawing,reporter)127 DEF_TEST(BlurDrawing, reporter) {
128 SkPaint paint;
129 paint.setColor(SK_ColorGRAY);
130 paint.setStyle(SkPaint::kStroke_Style);
131 paint.setStrokeWidth(SkIntToScalar(strokeWidth));
132
133 SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5));
134 for (int style = 0; style <= kLastEnum_SkBlurStyle; ++style) {
135 SkBlurStyle blurStyle = static_cast<SkBlurStyle>(style);
136
137 for (bool respectCTM : { false, true }) {
138 paint.setMaskFilter(SkMaskFilter::MakeBlur(blurStyle, sigma, respectCTM));
139
140 for (size_t test = 0; test < std::size(tests); ++test) {
141 SkPath path;
142 tests[test].addPath(&path);
143 SkPath strokedPath;
144 skpathutils::FillPathWithPaint(path, paint, &strokedPath);
145 SkRect refBound = strokedPath.getBounds();
146 SkIRect iref;
147 refBound.roundOut(&iref);
148 iref.inset(-outset, -outset);
149 SkBitmap refBitmap;
150 create(&refBitmap, iref);
151
152 SkCanvas refCanvas(refBitmap);
153 refCanvas.translate(SkIntToScalar(-iref.fLeft),
154 SkIntToScalar(-iref.fTop));
155 drawBG(&refCanvas);
156 refCanvas.drawPath(path, paint);
157
158 for (int view = 0; view < tests[test].viewLen; ++view) {
159 SkIRect itest = tests[test].views[view];
160 SkBitmap testBitmap;
161 create(&testBitmap, itest);
162
163 SkCanvas testCanvas(testBitmap);
164 testCanvas.translate(SkIntToScalar(-itest.fLeft),
165 SkIntToScalar(-itest.fTop));
166 drawBG(&testCanvas);
167 testCanvas.drawPath(path, paint);
168
169 REPORTER_ASSERT(reporter,
170 compare(refBitmap, iref, testBitmap, itest));
171 }
172 }
173 }
174 }
175 }
176
177 ///////////////////////////////////////////////////////////////////////////////
178
179 // Use SkBlurMask::BlurGroundTruth to blur a 'width' x 'height' solid
180 // white rect. Return the right half of the middle row in 'result'.
ground_truth_2d(int width,int height,SkScalar sigma,int * result,int resultCount)181 static void ground_truth_2d(int width, int height,
182 SkScalar sigma,
183 int* result, int resultCount) {
184 SkMaskBuilder src, dst;
185
186 src.bounds().setWH(width, height);
187 src.format() = SkMask::kA8_Format;
188 src.rowBytes() = src.fBounds.width();
189 src.image() = SkMaskBuilder::AllocImage(src.computeTotalImageSize());
190
191 memset(src.image(), 0xff, src.computeTotalImageSize());
192
193 if (!SkBlurMask::BlurGroundTruth(sigma, &dst, src, kNormal_SkBlurStyle)) {
194 return;
195 }
196
197 int midX = dst.fBounds.x() + dst.fBounds.width()/2;
198 int midY = dst.fBounds.y() + dst.fBounds.height()/2;
199 uint8_t* bytes = dst.getAddr8(midX, midY);
200 int i;
201 for (i = 0; i < dst.fBounds.width()-(midX-dst.fBounds.fLeft); ++i) {
202 if (i < resultCount) {
203 result[i] = bytes[i];
204 }
205 }
206 for ( ; i < resultCount; ++i) {
207 result[i] = 0;
208 }
209
210 SkMaskBuilder::FreeImage(src.image());
211 SkMaskBuilder::FreeImage(dst.image());
212 }
213
214 // Implement a step function that is 255 between min and max; 0 elsewhere.
step(int x,SkScalar min,SkScalar max)215 static int step(int x, SkScalar min, SkScalar max) {
216 if (min < x && x < max) {
217 return 255;
218 }
219 return 0;
220 }
221
222 // Implement a Gaussian function with 0 mean and std.dev. of 'sigma'.
gaussian(int x,SkScalar sigma)223 static float gaussian(int x, SkScalar sigma) {
224 float k = SK_Scalar1/(sigma * sqrtf(2.0f*SK_ScalarPI));
225 float exponent = -(x * x) / (2 * sigma * sigma);
226 return k * expf(exponent);
227 }
228
229 // Perform a brute force convolution of a step function with a Gaussian.
230 // Return the right half in 'result'
brute_force_1d(SkScalar stepMin,SkScalar stepMax,SkScalar gaussianSigma,int * result,int resultCount)231 static void brute_force_1d(SkScalar stepMin, SkScalar stepMax,
232 SkScalar gaussianSigma,
233 int* result, int resultCount) {
234
235 int gaussianRange = SkScalarCeilToInt(10 * gaussianSigma);
236
237 for (int i = 0; i < resultCount; ++i) {
238 SkScalar sum = 0.0f;
239 for (int j = -gaussianRange; j < gaussianRange; ++j) {
240 sum += gaussian(j, gaussianSigma) * step(i-j, stepMin, stepMax);
241 }
242
243 result[i] = SkTPin(SkClampPos(int(sum + 0.5f)), 0, 255);
244 }
245 }
246
blur_path(SkCanvas * canvas,const SkPath & path,SkScalar gaussianSigma)247 static void blur_path(SkCanvas* canvas, const SkPath& path,
248 SkScalar gaussianSigma) {
249
250 SkScalar midX = path.getBounds().centerX();
251 SkScalar midY = path.getBounds().centerY();
252
253 canvas->translate(-midX, -midY);
254
255 SkPaint blurPaint;
256 blurPaint.setColor(SK_ColorWHITE);
257 blurPaint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, gaussianSigma));
258
259 canvas->drawColor(SK_ColorBLACK);
260 canvas->drawPath(path, blurPaint);
261 }
262
263 // Readback the blurred draw results from the canvas
readback(const SkBitmap & src,int * result,int resultCount)264 static void readback(const SkBitmap& src, int* result, int resultCount) {
265 SkBitmap readback;
266 readback.allocN32Pixels(resultCount, 30);
267 SkPixmap pm;
268 readback.peekPixels(&pm);
269 src.readPixels(pm, 0, 0);
270
271 const SkPMColor* pixels = pm.addr32(0, 15);
272
273 for (int i = 0; i < resultCount; ++i) {
274 result[i] = SkColorGetR(pixels[i]);
275 }
276 }
277
278 // Draw a blurred version of the provided path.
279 // Return the right half of the middle row in 'result'.
cpu_blur_path(const SkPath & path,SkScalar gaussianSigma,int * result,int resultCount)280 static void cpu_blur_path(const SkPath& path, SkScalar gaussianSigma,
281 int* result, int resultCount) {
282
283 SkBitmap bitmap;
284 bitmap.allocN32Pixels(resultCount, 30);
285 SkCanvas canvas(bitmap);
286
287 blur_path(&canvas, path, gaussianSigma);
288 readback(bitmap, result, resultCount);
289 }
290
291 #if WRITE_CSV
write_as_csv(const char * label,SkScalar scale,int * data,int count)292 static void write_as_csv(const char* label, SkScalar scale, int* data, int count) {
293 SkDebugf("%s_%.2f,", label, scale);
294 for (int i = 0; i < count-1; ++i) {
295 SkDebugf("%d,", data[i]);
296 }
297 SkDebugf("%d\n", data[count-1]);
298 }
299 #endif
300
match(int * first,int * second,int count,int tol)301 static bool match(int* first, int* second, int count, int tol) {
302 int delta;
303 for (int i = 0; i < count; ++i) {
304 delta = first[i] - second[i];
305 if (delta > tol || delta < -tol) {
306 return false;
307 }
308 }
309
310 return true;
311 }
312
313 // Test out the normal blur style with a wide range of sigmas
DEF_TEST(BlurSigmaRange,reporter)314 DEF_TEST(BlurSigmaRange, reporter) {
315 static const int kSize = 100;
316
317 // The geometry is offset a smidge to trigger:
318 // https://code.google.com/p/chromium/issues/detail?id=282418
319 SkPath rectPath;
320 rectPath.addRect(0.3f, 0.3f, 100.3f, 100.3f);
321
322 SkPoint polyPts[] = {
323 { 0.3f, 0.3f },
324 { 100.3f, 0.3f },
325 { 100.3f, 100.3f },
326 { 0.3f, 100.3f },
327 { 2.3f, 50.3f } // a little divet to throw off the rect special case
328 };
329 SkPath polyPath;
330 polyPath.addPoly(polyPts, std::size(polyPts), true);
331
332 int rectSpecialCaseResult[kSize];
333 int generalCaseResult[kSize];
334 int groundTruthResult[kSize];
335 int bruteForce1DResult[kSize];
336
337 SkScalar sigma = 10.0f;
338
339 for (int i = 0; i < 4; ++i, sigma /= 10) {
340
341 cpu_blur_path(rectPath, sigma, rectSpecialCaseResult, kSize);
342 cpu_blur_path(polyPath, sigma, generalCaseResult, kSize);
343
344 ground_truth_2d(100, 100, sigma, groundTruthResult, kSize);
345 brute_force_1d(-50.0f, 50.0f, sigma, bruteForce1DResult, kSize);
346
347 REPORTER_ASSERT(reporter, match(rectSpecialCaseResult, bruteForce1DResult, kSize, 5));
348 REPORTER_ASSERT(reporter, match(generalCaseResult, bruteForce1DResult, kSize, 15));
349 REPORTER_ASSERT(reporter, match(groundTruthResult, bruteForce1DResult, kSize, 1));
350
351 #if WRITE_CSV
352 write_as_csv("RectSpecialCase", sigma, rectSpecialCaseResult, kSize);
353 write_as_csv("GeneralCase", sigma, generalCaseResult, kSize);
354 write_as_csv("GPU", sigma, gpuResult, kSize);
355 write_as_csv("GroundTruth2D", sigma, groundTruthResult, kSize);
356 write_as_csv("BruteForce1D", sigma, bruteForce1DResult, kSize);
357 #endif
358 }
359 }
360
361 ///////////////////////////////////////////////////////////////////////////////////////////
362
DEF_TEST(BlurAsABlur,reporter)363 DEF_TEST(BlurAsABlur, reporter) {
364 const SkBlurStyle styles[] = {
365 kNormal_SkBlurStyle, kSolid_SkBlurStyle, kOuter_SkBlurStyle, kInner_SkBlurStyle
366 };
367 const SkScalar sigmas[] = {
368 // values <= 0 should not success for a blur
369 -1, 0, 0.5f, 2
370 };
371
372 // Test asABlur for SkBlurMaskFilter
373 //
374 for (size_t i = 0; i < std::size(styles); ++i) {
375 const SkBlurStyle style = styles[i];
376 for (size_t j = 0; j < std::size(sigmas); ++j) {
377 const SkScalar sigma = sigmas[j];
378 for (bool respectCTM : { false, true }) {
379 sk_sp<SkMaskFilter> mf(SkMaskFilter::MakeBlur(style, sigma, respectCTM));
380 if (nullptr == mf.get()) {
381 REPORTER_ASSERT(reporter, sigma <= 0);
382 } else {
383 REPORTER_ASSERT(reporter, sigma > 0);
384 SkMaskFilterBase::BlurRec rec;
385 bool success = as_MFB(mf)->asABlur(&rec);
386 if (respectCTM) {
387 REPORTER_ASSERT(reporter, success);
388 REPORTER_ASSERT(reporter, rec.fSigma == sigma);
389 REPORTER_ASSERT(reporter, rec.fStyle == style);
390 } else {
391 REPORTER_ASSERT(reporter, !success);
392 }
393
394 const SkRect src = {0, 0, 100, 100};
395 const auto dst = mf->approximateFilteredBounds(src);
396
397 // This is a very conservative test. With more knowledge, we could
398 // consider more stringent tests.
399 REPORTER_ASSERT(reporter, dst.contains(src));
400 }
401 }
402 }
403 }
404
405 // Test asABlur for SkEmbossMaskFilter -- should never succeed
406 //
407 {
408 SkEmbossMaskFilter::Light light = {
409 { 1, 1, 1 }, 0, 127, 127
410 };
411 for (size_t j = 0; j < std::size(sigmas); ++j) {
412 const SkScalar sigma = sigmas[j];
413 auto mf(SkEmbossMaskFilter::Make(sigma, light));
414 if (mf) {
415 SkMaskFilterBase::BlurRec rec;
416 bool success = as_MFB(mf)->asABlur(&rec);
417 REPORTER_ASSERT(reporter, !success);
418 }
419 }
420 }
421 }
422
423 // This exercises the problem discovered in crbug.com/570232. The return value from
424 // SkBlurMask::BoxBlur wasn't being checked in SkBlurMaskFilter.cpp::GrRRectBlurEffect::Create
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(SmallBoxBlurBug,reporter,ctxInfo,CtsEnforcement::kNever)425 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(SmallBoxBlurBug, reporter, ctxInfo, CtsEnforcement::kNever) {
426 SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
427 auto surface(SkSurfaces::RenderTarget(ctxInfo.directContext(), skgpu::Budgeted::kNo, info));
428 SkCanvas* canvas = surface->getCanvas();
429
430 SkRect r = SkRect::MakeXYWH(10, 10, 100, 100);
431 SkRRect rr = SkRRect::MakeRectXY(r, 10, 10);
432
433 SkPaint p;
434 p.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 0.01f));
435
436 canvas->drawRRect(rr, p);
437 }
438
DEF_TEST(BlurredRRectNinePatchComputation,reporter)439 DEF_TEST(BlurredRRectNinePatchComputation, reporter) {
440 const SkRect r = SkRect::MakeXYWH(10, 10, 100, 100);
441 static const SkScalar kBlurRad = 3.0f;
442
443 bool ninePatchable;
444 SkRRect rrectToDraw;
445 SkISize size;
446 SkScalar rectXs[GrBlurUtils::kBlurRRectMaxDivisions],
447 rectYs[GrBlurUtils::kBlurRRectMaxDivisions];
448 SkScalar texXs[GrBlurUtils::kBlurRRectMaxDivisions],
449 texYs[GrBlurUtils::kBlurRRectMaxDivisions];
450
451 // not nine-patchable
452 {
453 SkVector radii[4] = { { 100, 100 }, { 0, 0 }, { 100, 100 }, { 0, 0 } };
454
455 SkRRect rr;
456 rr.setRectRadii(r, radii);
457
458 ninePatchable = GrBlurUtils::ComputeBlurredRRectParams(rr, rr, kBlurRad, kBlurRad,
459 &rrectToDraw, &size,
460 rectXs, rectYs, texXs, texYs);
461 REPORTER_ASSERT(reporter, !ninePatchable);
462 }
463
464 // simple circular
465 {
466 static const SkScalar kCornerRad = 10.0f;
467 SkRRect rr;
468 rr.setRectXY(r, kCornerRad, kCornerRad);
469
470 ninePatchable = GrBlurUtils::ComputeBlurredRRectParams(rr, rr, kBlurRad, kBlurRad,
471 &rrectToDraw, &size,
472 rectXs, rectYs, texXs, texYs);
473
474 static const SkScalar kAns = 12.0f * kBlurRad + 2.0f * kCornerRad + 1.0f;
475 REPORTER_ASSERT(reporter, ninePatchable);
476 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fWidth), kAns));
477 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fHeight), kAns));
478 }
479
480 // simple elliptical
481 {
482 static const SkScalar kXCornerRad = 2.0f;
483 static const SkScalar kYCornerRad = 10.0f;
484 SkRRect rr;
485 rr.setRectXY(r, kXCornerRad, kYCornerRad);
486
487 ninePatchable = GrBlurUtils::ComputeBlurredRRectParams(rr, rr, kBlurRad, kBlurRad,
488 &rrectToDraw, &size,
489 rectXs, rectYs, texXs, texYs);
490
491 static const SkScalar kXAns = 12.0f * kBlurRad + 2.0f * kXCornerRad + 1.0f;
492 static const SkScalar kYAns = 12.0f * kBlurRad + 2.0f * kYCornerRad + 1.0f;
493
494 REPORTER_ASSERT(reporter, ninePatchable);
495 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fWidth), kXAns));
496 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fHeight), kYAns));
497 }
498 }
499
500 // https://crbugs.com/787712
DEF_TEST(EmbossPerlinCrash,reporter)501 DEF_TEST(EmbossPerlinCrash, reporter) {
502 SkPaint p;
503
504 static constexpr SkEmbossMaskFilter::Light light = {
505 { 1, 1, 1 }, 0, 127, 127
506 };
507 p.setMaskFilter(SkEmbossMaskFilter::Make(1, light));
508 p.setShader(SkShaders::MakeFractalNoise(1.0f, 1.0f, 2, 0.0f));
509
510 sk_sp<SkSurface> surface = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(100, 100));
511 surface->getCanvas()->drawPaint(p);
512 }
513
514 ///////////////////////////////////////////////////////////////////////////////////////////
515
DEF_TEST(BlurZeroSigma,reporter)516 DEF_TEST(BlurZeroSigma, reporter) {
517 auto surf = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(20, 20));
518 SkPaint paint;
519 paint.setAntiAlias(true);
520
521 const SkIRect ir = { 5, 5, 15, 15 };
522 const SkRect r = SkRect::Make(ir);
523
524 const SkScalar sigmas[] = { 0, SkBits2Float(1) };
525 // if sigma is zero (or nearly so), we need to draw correctly (unblurred) and not crash
526 // or assert.
527 for (auto sigma : sigmas) {
528 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma));
529 surf->getCanvas()->drawRect(r, paint);
530
531 ToolUtils::PixelIter iter(surf.get());
532 SkIPoint loc;
533 while (const SkPMColor* p = (const SkPMColor*)iter.next(&loc)) {
534 if (ir.contains(loc.fX, loc.fY)) {
535 // inside the rect we draw (opaque black)
536 REPORTER_ASSERT(reporter, *p == SkPackARGB32(0xFF, 0, 0, 0));
537 } else {
538 // outside the rect we didn't draw at all, no blurred edges
539 REPORTER_ASSERT(reporter, *p == 0);
540 }
541 }
542 }
543 }
544
545
546 ///////////////////////////////////////////////////////////////////////////////////////////
547
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(BlurMaskBiggerThanDest,reporter,ctxInfo,CtsEnforcement::kApiLevel_T)548 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(BlurMaskBiggerThanDest,
549 reporter,
550 ctxInfo,
551 CtsEnforcement::kApiLevel_T) {
552 auto context = ctxInfo.directContext();
553
554 SkImageInfo ii = SkImageInfo::Make(32, 32, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
555
556 sk_sp<SkSurface> dst(SkSurfaces::RenderTarget(context, skgpu::Budgeted::kNo, ii));
557 if (!dst) {
558 ERRORF(reporter, "Could not create surface for test.");
559 return;
560 }
561
562 SkPaint p;
563 p.setColor(SK_ColorRED);
564 p.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 3));
565
566 SkCanvas* canvas = dst->getCanvas();
567
568 canvas->clear(SK_ColorBLACK);
569 canvas->drawCircle(SkPoint::Make(16, 16), 8, p);
570
571 SkBitmap readback;
572 SkAssertResult(readback.tryAllocPixels(ii));
573
574 canvas->readPixels(readback, 0, 0);
575 REPORTER_ASSERT(reporter, SkColorGetR(readback.getColor(15, 15)) > 128);
576 REPORTER_ASSERT(reporter, SkColorGetG(readback.getColor(15, 15)) == 0);
577 REPORTER_ASSERT(reporter, SkColorGetB(readback.getColor(15, 15)) == 0);
578 REPORTER_ASSERT(reporter, readback.getColor(31, 31) == SK_ColorBLACK);
579 }
580
DEF_TEST(zero_blur,reporter)581 DEF_TEST(zero_blur, reporter) {
582 SkBitmap alpha, bitmap;
583
584 SkPaint paint;
585 paint.setMaskFilter(SkMaskFilter::MakeBlur(kOuter_SkBlurStyle, 3));
586 SkIPoint offset;
587 bitmap.extractAlpha(&alpha, &paint, nullptr, &offset);
588 }
589