Brian Osman | c32aeb3 | 2018-12-03 11:17:51 -0500 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 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" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "include/core/SkSurface.h" |
Michael Ludwig | 898bbfa | 2019-08-02 15:21:23 -0400 | [diff] [blame] | 18 | #include "include/effects/SkImageFilters.h" |
Brian Osman | c32aeb3 | 2018-12-03 11:17:51 -0500 | [diff] [blame] | 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()); |
Michael Ludwig | 898bbfa | 2019-08-02 15:21:23 -0400 | [diff] [blame] | 27 | auto imageSource = SkImageFilters::Image(surface->makeImageSnapshot()); |
Brian Osman | c32aeb3 | 2018-12-03 11:17:51 -0500 | [diff] [blame] | 28 | |
Michael Ludwig | 898bbfa | 2019-08-02 15:21:23 -0400 | [diff] [blame] | 29 | auto blurred = SkImageFilters::Blur(15, 15, imageSource); |
| 30 | auto eroded = SkImageFilters::Erode(0, 0, blurred); |
| 31 | auto blended = SkImageFilters::Xfermode(SkBlendMode::kDstOut, eroded, imageSource, nullptr); |
Brian Osman | c32aeb3 | 2018-12-03 11:17:51 -0500 | [diff] [blame] | 32 | |
| 33 | SkPaint paint; |
| 34 | paint.setImageFilter(blended); |
| 35 | canvas->drawRect(SkRect::MakeWH(100, 100), paint); |
| 36 | |
Michael Ludwig | 898bbfa | 2019-08-02 15:21:23 -0400 | [diff] [blame] | 37 | auto mult = SkImageFilters::Arithmetic(1, 0, 0, 0, false, eroded, imageSource, nullptr); |
Brian Osman | c32aeb3 | 2018-12-03 11:17:51 -0500 | [diff] [blame] | 38 | paint.setImageFilter(mult); |
| 39 | canvas->translate(0, 100); |
| 40 | canvas->drawRect(SkRect::MakeWH(100, 100), paint); |
| 41 | } |