1 /*
2  * Copyright 2018 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 "gm/gm.h"
9 #include "include/core/SkBlendMode.h"
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkImage.h"
12 #include "include/core/SkImageFilter.h"
13 #include "include/core/SkImageInfo.h"
14 #include "include/core/SkPaint.h"
15 #include "include/core/SkRect.h"
16 #include "include/core/SkRefCnt.h"
17 #include "include/core/SkSurface.h"
18 #include "include/effects/SkImageFilters.h"
19 
20 DEF_SIMPLE_GM(crbug_905548, canvas, 100, 200) {
21     auto surface = canvas->makeSurface(SkImageInfo::MakeN32Premul(100, 100));
22     if (!surface) {
23         surface = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100));
24     }
25     surface->getCanvas()->clear(0);
26     surface->getCanvas()->drawCircle(50, 50, 45, SkPaint());
27     auto imageSource = SkImageFilters::Image(surface->makeImageSnapshot());
28 
29     auto blurred = SkImageFilters::Blur(15, 15, imageSource);
30     auto eroded = SkImageFilters::Erode(0, 0, blurred);
31     auto blended = SkImageFilters::Blend(SkBlendMode::kDstOut, eroded, imageSource, nullptr);
32 
33     SkPaint paint;
34     paint.setImageFilter(blended);
35     canvas->drawRect(SkRect::MakeWH(100, 100), paint);
36 
37     auto mult = SkImageFilters::Arithmetic(1, 0, 0, 0, false, eroded, imageSource, nullptr);
38     paint.setImageFilter(mult);
39     canvas->translate(0, 100);
40     canvas->drawRect(SkRect::MakeWH(100, 100), paint);
41 }
42