Mike Reed | 6e87eee | 2018-01-18 16:06:54 -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/SkBlurTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkCanvas.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 12 | #include "include/core/SkColor.h" |
| 13 | #include "include/core/SkCoverageMode.h" |
| 14 | #include "include/core/SkFont.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "include/core/SkImage.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 16 | #include "include/core/SkImageFilter.h" |
| 17 | #include "include/core/SkImageInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "include/core/SkMaskFilter.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 19 | #include "include/core/SkMatrix.h" |
| 20 | #include "include/core/SkPaint.h" |
| 21 | #include "include/core/SkPath.h" |
| 22 | #include "include/core/SkPicture.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "include/core/SkPictureRecorder.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 24 | #include "include/core/SkPoint.h" |
| 25 | #include "include/core/SkRect.h" |
| 26 | #include "include/core/SkRefCnt.h" |
| 27 | #include "include/core/SkScalar.h" |
| 28 | #include "include/core/SkShader.h" |
| 29 | #include "include/core/SkString.h" |
| 30 | #include "include/core/SkSurface.h" |
| 31 | #include "include/core/SkTileMode.h" |
| 32 | #include "include/core/SkTypes.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 33 | #include "include/effects/SkGradientShader.h" |
Michael Ludwig | 898bbfa | 2019-08-02 15:21:23 -0400 | [diff] [blame] | 34 | #include "include/effects/SkImageFilters.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 35 | #include "include/effects/SkShaderMaskFilter.h" |
| 36 | #include "include/utils/SkTextUtils.h" |
| 37 | #include "src/core/SkBlendModePriv.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 38 | #include "tools/Resources.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 39 | #include "tools/ToolUtils.h" |
Mike Reed | 6e87eee | 2018-01-18 16:06:54 -0500 | [diff] [blame] | 40 | |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 41 | #include <initializer_list> |
| 42 | |
Mike Reed | 6e87eee | 2018-01-18 16:06:54 -0500 | [diff] [blame] | 43 | static sk_sp<SkShader> make_shader(const SkRect& r) { |
| 44 | const SkPoint pts[] = { |
| 45 | { r.fLeft, r.fTop }, { r.fRight, r.fBottom }, |
| 46 | }; |
| 47 | const SkColor colors[] = { 0, SK_ColorWHITE }; |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 48 | return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kRepeat); |
Mike Reed | 6e87eee | 2018-01-18 16:06:54 -0500 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | DEF_SIMPLE_GM(shadermaskfilter_gradient, canvas, 512, 512) { |
| 52 | SkRect r = { 0, 0, 100, 150 }; |
| 53 | auto shader = make_shader(r); |
| 54 | auto mf = SkShaderMaskFilter::Make(shader); |
| 55 | |
| 56 | canvas->translate(20, 20); |
| 57 | canvas->scale(2, 2); |
| 58 | |
| 59 | SkPaint paint; |
| 60 | paint.setMaskFilter(mf); |
| 61 | paint.setColor(SK_ColorRED); |
Mike Reed | 28eaed2 | 2018-02-01 11:24:53 -0500 | [diff] [blame] | 62 | paint.setAntiAlias(true); |
Mike Reed | 6e87eee | 2018-01-18 16:06:54 -0500 | [diff] [blame] | 63 | canvas->drawOval(r, paint); |
| 64 | } |