reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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.h" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils.h" |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 10 | #include "SkCanvas.h" |
| 11 | #include "SkColorFilter.h" |
| 12 | #include "SkColorPriv.h" |
Cary Clark | 60aaeb2 | 2017-11-03 08:06:09 -0400 | [diff] [blame] | 13 | #include "SkImageFilterPriv.h" |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 14 | #include "SkShader.h" |
Mike Reed | 71f5a0b | 2018-10-25 16:12:39 -0400 | [diff] [blame] | 15 | #include "SkTextUtils.h" |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 16 | |
| 17 | #include "SkBlurImageFilter.h" |
senorblanco@chromium.org | 44888c6 | 2012-08-20 19:23:24 +0000 | [diff] [blame] | 18 | #include "SkColorFilterImageFilter.h" |
junov@chromium.org | f44fcdc | 2013-08-07 20:00:55 +0000 | [diff] [blame] | 19 | #include "SkDropShadowImageFilter.h" |
robertphillips | 4ba94e2 | 2016-04-04 12:07:47 -0700 | [diff] [blame] | 20 | #include "SkSpecialImage.h" |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 21 | |
| 22 | class FailImageFilter : public SkImageFilter { |
| 23 | public: |
robertphillips | 43c2ad4 | 2016-04-04 05:05:11 -0700 | [diff] [blame] | 24 | static sk_sp<SkImageFilter> Make() { |
| 25 | return sk_sp<SkImageFilter>(new FailImageFilter); |
| 26 | } |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 27 | |
Mike Klein | a3d4099 | 2018-10-20 07:54:41 -0400 | [diff] [blame] | 28 | SK_FLATTENABLE_HOOKS(FailImageFilter) |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 29 | protected: |
robertphillips | 43c2ad4 | 2016-04-04 05:05:11 -0700 | [diff] [blame] | 30 | FailImageFilter() : INHERITED(nullptr, 0, nullptr) {} |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 31 | |
robertphillips | 4ba94e2 | 2016-04-04 12:07:47 -0700 | [diff] [blame] | 32 | sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, |
| 33 | SkIPoint* offset) const override { |
| 34 | return nullptr; |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 35 | } |
Matt Sarett | 62745a8 | 2017-04-17 11:57:29 -0400 | [diff] [blame] | 36 | sk_sp<SkImageFilter> onMakeColorSpace(SkColorSpaceXformer*) const override { |
Brian Osman | f83cacb | 2018-08-03 16:13:13 -0400 | [diff] [blame] | 37 | return sk_ref_sp(this); |
Matt Sarett | 62745a8 | 2017-04-17 11:57:29 -0400 | [diff] [blame] | 38 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 39 | |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 40 | private: |
Mike Klein | 4fee323 | 2018-10-18 17:27:16 -0400 | [diff] [blame] | 41 | |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 42 | typedef SkImageFilter INHERITED; |
| 43 | }; |
| 44 | |
reed | 60c9b58 | 2016-04-03 09:11:13 -0700 | [diff] [blame] | 45 | sk_sp<SkFlattenable> FailImageFilter::CreateProc(SkReadBuffer& buffer) { |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 46 | SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0); |
robertphillips | 43c2ad4 | 2016-04-04 05:05:11 -0700 | [diff] [blame] | 47 | return FailImageFilter::Make(); |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 48 | } |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 49 | |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 50 | class IdentityImageFilter : public SkImageFilter { |
| 51 | public: |
robertphillips | 43c2ad4 | 2016-04-04 05:05:11 -0700 | [diff] [blame] | 52 | static sk_sp<SkImageFilter> Make(sk_sp<SkImageFilter> input) { |
| 53 | return sk_sp<SkImageFilter>(new IdentityImageFilter(std::move(input))); |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 54 | } |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 55 | |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 56 | |
Mike Klein | a3d4099 | 2018-10-20 07:54:41 -0400 | [diff] [blame] | 57 | SK_FLATTENABLE_HOOKS(IdentityImageFilter) |
robertphillips | 43c2ad4 | 2016-04-04 05:05:11 -0700 | [diff] [blame] | 58 | protected: |
robertphillips | 4ba94e2 | 2016-04-04 12:07:47 -0700 | [diff] [blame] | 59 | sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, |
| 60 | SkIPoint* offset) const override { |
commit-bot@chromium.org | f7efa50 | 2014-04-11 18:57:00 +0000 | [diff] [blame] | 61 | offset->set(0, 0); |
robertphillips | 4ba94e2 | 2016-04-04 12:07:47 -0700 | [diff] [blame] | 62 | return sk_ref_sp<SkSpecialImage>(source); |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 63 | } |
Matt Sarett | 62745a8 | 2017-04-17 11:57:29 -0400 | [diff] [blame] | 64 | sk_sp<SkImageFilter> onMakeColorSpace(SkColorSpaceXformer*) const override { |
| 65 | return sk_ref_sp(const_cast<IdentityImageFilter*>(this)); |
| 66 | } |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 67 | |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 68 | private: |
robertphillips | 43c2ad4 | 2016-04-04 05:05:11 -0700 | [diff] [blame] | 69 | IdentityImageFilter(sk_sp<SkImageFilter> input) : INHERITED(&input, 1, nullptr) {} |
| 70 | |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 71 | typedef SkImageFilter INHERITED; |
| 72 | }; |
| 73 | |
Mike Klein | a3d4099 | 2018-10-20 07:54:41 -0400 | [diff] [blame] | 74 | // Register these image filters as deserializable before main(). |
| 75 | namespace { |
| 76 | static struct Initializer { |
| 77 | Initializer() { |
Mike Klein | fa5f6ce | 2018-10-20 08:21:31 -0400 | [diff] [blame] | 78 | SK_REGISTER_FLATTENABLE(IdentityImageFilter); |
| 79 | SK_REGISTER_FLATTENABLE(FailImageFilter); |
Mike Klein | a3d4099 | 2018-10-20 07:54:41 -0400 | [diff] [blame] | 80 | } |
| 81 | } initializer; |
| 82 | } |
reed | 7daaaa4 | 2014-08-21 10:53:34 -0700 | [diff] [blame] | 83 | |
reed | 60c9b58 | 2016-04-03 09:11:13 -0700 | [diff] [blame] | 84 | sk_sp<SkFlattenable> IdentityImageFilter::CreateProc(SkReadBuffer& buffer) { |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 85 | SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
robertphillips | 43c2ad4 | 2016-04-04 05:05:11 -0700 | [diff] [blame] | 86 | return IdentityImageFilter::Make(common.getInput(0)); |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 87 | } |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 88 | |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 89 | /////////////////////////////////////////////////////////////////////////////// |
| 90 | |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 91 | static void draw_paint(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) { |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 92 | SkPaint paint; |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 93 | paint.setImageFilter(std::move(imf)); |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 94 | paint.setColor(SK_ColorGREEN); |
| 95 | canvas->save(); |
| 96 | canvas->clipRect(r); |
| 97 | canvas->drawPaint(paint); |
| 98 | canvas->restore(); |
| 99 | } |
| 100 | |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 101 | static void draw_line(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) { |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 102 | SkPaint paint; |
| 103 | paint.setColor(SK_ColorBLUE); |
| 104 | paint.setImageFilter(imf); |
| 105 | paint.setStrokeWidth(r.width()/10); |
| 106 | canvas->drawLine(r.fLeft, r.fTop, r.fRight, r.fBottom, paint); |
| 107 | } |
| 108 | |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 109 | static void draw_rect(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) { |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 110 | SkPaint paint; |
| 111 | paint.setColor(SK_ColorYELLOW); |
| 112 | paint.setImageFilter(imf); |
| 113 | SkRect rr(r); |
| 114 | rr.inset(r.width()/10, r.height()/10); |
| 115 | canvas->drawRect(rr, paint); |
| 116 | } |
| 117 | |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 118 | static void draw_path(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) { |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 119 | SkPaint paint; |
| 120 | paint.setColor(SK_ColorMAGENTA); |
| 121 | paint.setImageFilter(imf); |
| 122 | paint.setAntiAlias(true); |
| 123 | canvas->drawCircle(r.centerX(), r.centerY(), r.width()*2/5, paint); |
| 124 | } |
| 125 | |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 126 | static void draw_text(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) { |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 127 | SkPaint paint; |
| 128 | paint.setImageFilter(imf); |
| 129 | paint.setColor(SK_ColorCYAN); |
Mike Reed | dc5863c | 2018-12-23 23:19:14 -0500 | [diff] [blame] | 130 | SkFont font(sk_tool_utils::create_portable_typeface(), r.height()/2); |
| 131 | SkTextUtils::DrawString(canvas, "Text", r.centerX(), r.centerY(), font, paint, |
Mike Reed | 3a42ec0 | 2018-10-30 12:53:21 -0400 | [diff] [blame] | 132 | SkTextUtils::kCenter_Align); |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 133 | } |
| 134 | |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 135 | static void draw_bitmap(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) { |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 136 | SkPaint paint; |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 137 | paint.setImageFilter(std::move(imf)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 138 | |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 139 | SkIRect bounds; |
| 140 | r.roundOut(&bounds); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 141 | |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 142 | SkBitmap bm; |
reed@google.com | eb9a46c | 2014-01-25 16:46:20 +0000 | [diff] [blame] | 143 | bm.allocN32Pixels(bounds.width(), bounds.height()); |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 144 | bm.eraseColor(SK_ColorTRANSPARENT); |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 145 | SkCanvas c(bm); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 146 | draw_path(&c, r, nullptr); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 147 | |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 148 | canvas->drawBitmap(bm, 0, 0, &paint); |
| 149 | } |
| 150 | |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 151 | /////////////////////////////////////////////////////////////////////////////// |
| 152 | |
| 153 | class ImageFiltersBaseGM : public skiagm::GM { |
| 154 | public: |
| 155 | ImageFiltersBaseGM () {} |
| 156 | |
| 157 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 158 | SkString onShortName() override { |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 159 | return SkString("imagefiltersbase"); |
| 160 | } |
| 161 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 162 | SkISize onISize() override { return SkISize::Make(700, 500); } |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 163 | |
| 164 | void draw_frame(SkCanvas* canvas, const SkRect& r) { |
| 165 | SkPaint paint; |
| 166 | paint.setStyle(SkPaint::kStroke_Style); |
| 167 | paint.setColor(SK_ColorRED); |
| 168 | canvas->drawRect(r, paint); |
| 169 | } |
| 170 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 171 | void onDraw(SkCanvas* canvas) override { |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 172 | void (*drawProc[])(SkCanvas*, const SkRect&, sk_sp<SkImageFilter>) = { |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 173 | draw_paint, |
| 174 | draw_line, draw_rect, draw_path, draw_text, |
| 175 | draw_bitmap, |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 176 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 177 | |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 178 | auto cf = SkColorFilter::MakeModeFilter(SK_ColorRED, SkBlendMode::kSrcIn); |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 179 | sk_sp<SkImageFilter> filters[] = { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 180 | nullptr, |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 181 | IdentityImageFilter::Make(nullptr), |
| 182 | FailImageFilter::Make(), |
| 183 | SkColorFilterImageFilter::Make(std::move(cf), nullptr), |
Herb Derby | 4fafedd | 2017-12-18 15:06:29 -0500 | [diff] [blame] | 184 | // The strage 0.29 value tickles an edge case where crop rect calculates |
| 185 | // a small border, but the blur really needs no border. This tickels |
| 186 | // an msan uninitialized value bug. |
| 187 | SkBlurImageFilter::Make(12.0f, 0.29f, nullptr), |
robertphillips | c416912 | 2016-04-06 08:40:59 -0700 | [diff] [blame] | 188 | SkDropShadowImageFilter::Make( |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 189 | 10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLUE, |
robertphillips | c416912 | 2016-04-06 08:40:59 -0700 | [diff] [blame] | 190 | SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, |
| 191 | nullptr), |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 192 | }; |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 193 | |
| 194 | SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); |
| 195 | SkScalar MARGIN = SkIntToScalar(16); |
| 196 | SkScalar DX = r.width() + MARGIN; |
| 197 | SkScalar DY = r.height() + MARGIN; |
| 198 | |
| 199 | canvas->translate(MARGIN, MARGIN); |
| 200 | for (size_t i = 0; i < SK_ARRAY_COUNT(drawProc); ++i) { |
| 201 | canvas->save(); |
| 202 | for (size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) { |
| 203 | drawProc[i](canvas, r, filters[j]); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 204 | |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 205 | draw_frame(canvas, r); |
| 206 | canvas->translate(0, DY); |
| 207 | } |
| 208 | canvas->restore(); |
| 209 | canvas->translate(DX, 0); |
| 210 | } |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | private: |
| 214 | typedef GM INHERITED; |
| 215 | }; |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 216 | DEF_GM( return new ImageFiltersBaseGM; ) |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 217 | |
| 218 | /////////////////////////////////////////////////////////////////////////////// |
| 219 | |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 220 | /* |
| 221 | * Want to test combos of filter and LCD text, to be sure we disable LCD in the presence of |
| 222 | * a filter. |
| 223 | */ |
| 224 | class ImageFiltersTextBaseGM : public skiagm::GM { |
| 225 | SkString fSuffix; |
| 226 | public: |
| 227 | ImageFiltersTextBaseGM(const char suffix[]) : fSuffix(suffix) {} |
| 228 | |
| 229 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 230 | SkString onShortName() override { |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 231 | SkString name; |
| 232 | name.printf("%s_%s", "textfilter", fSuffix.c_str()); |
| 233 | return name; |
| 234 | } |
| 235 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 236 | SkISize onISize() override { return SkISize::Make(512, 342); } |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 237 | |
Hal Canary | 6ac0df8 | 2019-01-07 16:01:22 -0500 | [diff] [blame] | 238 | void drawWaterfall(SkCanvas* canvas, const SkPaint& paint) { |
| 239 | static const SkFont::Edging kEdgings[3] = { |
| 240 | SkFont::Edging::kAlias, |
| 241 | SkFont::Edging::kAntiAlias, |
| 242 | SkFont::Edging::kSubpixelAntiAlias, |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 243 | }; |
Hal Canary | 6ac0df8 | 2019-01-07 16:01:22 -0500 | [diff] [blame] | 244 | SkFont font(sk_tool_utils::create_portable_typeface(), 30); |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 245 | |
| 246 | SkAutoCanvasRestore acr(canvas, true); |
Hal Canary | 6ac0df8 | 2019-01-07 16:01:22 -0500 | [diff] [blame] | 247 | for (SkFont::Edging edging : kEdgings) { |
| 248 | font.setEdging(edging); |
| 249 | canvas->drawString("Hamburgefon", 0, 0, font, paint); |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 250 | canvas->translate(0, 40); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | virtual void installFilter(SkPaint* paint) = 0; |
| 255 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 256 | void onDraw(SkCanvas* canvas) override { |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 257 | SkPaint paint; |
| 258 | |
| 259 | canvas->translate(20, 40); |
| 260 | |
| 261 | for (int doSaveLayer = 0; doSaveLayer <= 1; ++doSaveLayer) { |
| 262 | SkAutoCanvasRestore acr(canvas, true); |
| 263 | for (int useFilter = 0; useFilter <= 1; ++useFilter) { |
| 264 | SkAutoCanvasRestore acr2(canvas, true); |
| 265 | |
| 266 | SkPaint paint; |
| 267 | if (useFilter) { |
| 268 | this->installFilter(&paint); |
| 269 | } |
| 270 | if (doSaveLayer) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 271 | canvas->saveLayer(nullptr, &paint); |
| 272 | paint.setImageFilter(nullptr); |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 273 | } |
| 274 | this->drawWaterfall(canvas, paint); |
| 275 | |
| 276 | acr2.restore(); |
| 277 | canvas->translate(250, 0); |
| 278 | } |
| 279 | acr.restore(); |
| 280 | canvas->translate(0, 200); |
| 281 | } |
| 282 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 283 | |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 284 | private: |
| 285 | typedef GM INHERITED; |
| 286 | }; |
| 287 | |
| 288 | class ImageFiltersText_IF : public ImageFiltersTextBaseGM { |
| 289 | public: |
| 290 | ImageFiltersText_IF() : ImageFiltersTextBaseGM("image") {} |
| 291 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 292 | void installFilter(SkPaint* paint) override { |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 293 | paint->setImageFilter(SkBlurImageFilter::Make(1.5f, 1.5f, nullptr)); |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 294 | } |
| 295 | }; |
| 296 | DEF_GM( return new ImageFiltersText_IF; ) |
| 297 | |
| 298 | class ImageFiltersText_CF : public ImageFiltersTextBaseGM { |
| 299 | public: |
| 300 | ImageFiltersText_CF() : ImageFiltersTextBaseGM("color") {} |
| 301 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 302 | void installFilter(SkPaint* paint) override { |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 303 | paint->setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkBlendMode::kSrcIn)); |
reed | 8dc0ccb | 2015-03-20 06:32:52 -0700 | [diff] [blame] | 304 | } |
| 305 | }; |
| 306 | DEF_GM( return new ImageFiltersText_CF; ) |