1 /*
2  * Copyright 2020 Google LLC
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 "gm/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkPaint.h"
11 #include "include/core/SkRect.h"
12 #include "include/effects/SkImageFilters.h"
13 
drawOne(SkCanvas * canvas,SkRect rect,float saveBorder,float sigma,SkColor c)14 static void drawOne(SkCanvas* canvas, SkRect rect, float saveBorder, float sigma, SkColor c) {
15     SkPaint sp;
16     sp.setImageFilter(SkImageFilters::Blur(sigma, sigma, SkTileMode::kClamp, nullptr));
17     SkPaint p;
18     p.setColor(c);
19     p.setAntiAlias(true);
20 
21     canvas->saveLayer(rect.makeOutset(saveBorder, saveBorder), &sp);
22     canvas->drawRect(rect, p);
23     canvas->restore();
24 }
25 
26 DEF_SIMPLE_GM(crbug_1156804, canvas, 250, 250) {
27     drawOne(canvas, SkRect::MakeXYWH( 64,  64, 25, 25),  1,  3, SK_ColorGREEN);
28     drawOne(canvas, SkRect::MakeXYWH(164,  64, 25, 25), 30,  3, SK_ColorGREEN);
29     // This one would draw incorrectly because the large sigma causes downscaling of the source
30     // and the one-pixel border would make the downscaled image not contain trans-black at the
31     // edges. Combined with the clamp mode on the blur filter it would "harden" the edge.
32     drawOne(canvas, SkRect::MakeXYWH( 64, 164, 25, 25),  1, 20, SK_ColorRED);
33     drawOne(canvas, SkRect::MakeXYWH(164, 164, 25, 25), 30, 20, SK_ColorGREEN);
34 }
35