blob: 2406e8f4d23160a2612091936ca567e57c525492 [file] [log] [blame]
Brian Osmanc32aeb32018-12-03 11:17:51 -05001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#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 Kleinc0bd9f92019-04-23 12:05:21 -050017#include "include/core/SkSurface.h"
Michael Ludwig898bbfa2019-08-02 15:21:23 -040018#include "include/effects/SkImageFilters.h"
Brian Osmanc32aeb32018-12-03 11:17:51 -050019
20DEF_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 Ludwig898bbfa2019-08-02 15:21:23 -040027 auto imageSource = SkImageFilters::Image(surface->makeImageSnapshot());
Brian Osmanc32aeb32018-12-03 11:17:51 -050028
Michael Ludwig898bbfa2019-08-02 15:21:23 -040029 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 Osmanc32aeb32018-12-03 11:17:51 -050032
33 SkPaint paint;
34 paint.setImageFilter(blended);
35 canvas->drawRect(SkRect::MakeWH(100, 100), paint);
36
Michael Ludwig898bbfa2019-08-02 15:21:23 -040037 auto mult = SkImageFilters::Arithmetic(1, 0, 0, 0, false, eroded, imageSource, nullptr);
Brian Osmanc32aeb32018-12-03 11:17:51 -050038 paint.setImageFilter(mult);
39 canvas->translate(0, 100);
40 canvas->drawRect(SkRect::MakeWH(100, 100), paint);
41}