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