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