OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "SkArithmeticMode.h" | 10 #include "SkArithmeticMode.h" |
11 #include "SkDevice.h" | 11 #include "SkDevice.h" |
12 #include "SkBlurImageFilter.h" | 12 #include "SkBlurImageFilter.h" |
13 #include "SkColorFilter.h" | 13 #include "SkColorFilter.h" |
14 #include "SkColorFilterImageFilter.h" | 14 #include "SkColorFilterImageFilter.h" |
15 #include "SkColorMatrixFilter.h" | 15 #include "SkColorMatrixFilter.h" |
16 #include "SkImage.h" | 16 #include "SkImage.h" |
17 #include "SkImageSource.h" | 17 #include "SkImageSource.h" |
| 18 #include "SkMatrixConvolutionImageFilter.h" |
18 #include "SkReadBuffer.h" | 19 #include "SkReadBuffer.h" |
19 #include "SkWriteBuffer.h" | 20 #include "SkWriteBuffer.h" |
20 #include "SkMergeImageFilter.h" | 21 #include "SkMergeImageFilter.h" |
21 #include "SkMorphologyImageFilter.h" | 22 #include "SkMorphologyImageFilter.h" |
22 #include "SkTestImageFilters.h" | 23 #include "SkTestImageFilters.h" |
23 #include "SkXfermodeImageFilter.h" | 24 #include "SkXfermodeImageFilter.h" |
24 | 25 |
25 // More closely models how Blink's OffsetFilter works as of 10/23/13. SkOffsetIm
ageFilter doesn't | 26 // More closely models how Blink's OffsetFilter works as of 10/23/13. SkOffsetIm
ageFilter doesn't |
26 // perform a draw and this one does. | 27 // perform a draw and this one does. |
27 class SimpleOffsetFilter : public SkImageFilter { | 28 class SimpleOffsetFilter : public SkImageFilter { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 class ImageFiltersGraphGM : public skiagm::GM { | 101 class ImageFiltersGraphGM : public skiagm::GM { |
101 public: | 102 public: |
102 ImageFiltersGraphGM() {} | 103 ImageFiltersGraphGM() {} |
103 | 104 |
104 protected: | 105 protected: |
105 | 106 |
106 SkString onShortName() override { | 107 SkString onShortName() override { |
107 return SkString("imagefiltersgraph"); | 108 return SkString("imagefiltersgraph"); |
108 } | 109 } |
109 | 110 |
110 SkISize onISize() override { return SkISize::Make(500, 150); } | 111 SkISize onISize() override { return SkISize::Make(600, 150); } |
111 | 112 |
112 void onOnceBeforeDraw() override { | 113 void onOnceBeforeDraw() override { |
113 fImage.reset(SkImage::NewFromBitmap( | 114 fImage.reset(SkImage::NewFromBitmap( |
114 sk_tool_utils::create_string_bitmap(100, 100, SK_ColorWHITE, 20, 70,
96, "e"))); | 115 sk_tool_utils::create_string_bitmap(100, 100, SK_ColorWHITE, 20, 70,
96, "e"))); |
115 } | 116 } |
116 | 117 |
117 void onDraw(SkCanvas* canvas) override { | 118 void onDraw(SkCanvas* canvas) override { |
118 canvas->clear(SK_ColorBLACK); | 119 canvas->clear(SK_ColorBLACK); |
119 { | 120 { |
120 SkAutoTUnref<SkImageFilter> bitmapSource(SkImageSource::Create(fImag
e)); | 121 SkAutoTUnref<SkImageFilter> bitmapSource(SkImageSource::Create(fImag
e)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), S
kIntToScalar(100))); | 176 SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), S
kIntToScalar(100))); |
176 SkAutoTUnref<SkImageFilter> blend( | 177 SkAutoTUnref<SkImageFilter> blend( |
177 SkXfermodeImageFilter::Create(mode, blur, nullptr, &cropRect)); | 178 SkXfermodeImageFilter::Create(mode, blur, nullptr, &cropRect)); |
178 | 179 |
179 SkPaint paint; | 180 SkPaint paint; |
180 paint.setImageFilter(blend); | 181 paint.setImageFilter(blend); |
181 DrawClippedImage(canvas, fImage, paint); | 182 DrawClippedImage(canvas, fImage, paint); |
182 canvas->translate(SkIntToScalar(100), 0); | 183 canvas->translate(SkIntToScalar(100), 0); |
183 } | 184 } |
184 { | 185 { |
| 186 // Dilate -> matrix convolution. |
| 187 // This tests that a filter using asFragmentProcessor (matrix |
| 188 // convolution) correctly handles a non-zero source offset |
| 189 // (supplied by the dilate). |
| 190 SkAutoTUnref<SkImageFilter> dilate(SkDilateImageFilter::Create(5, 5)
); |
| 191 |
| 192 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcIn_
Mode)); |
| 193 |
| 194 SkScalar kernel[9] = { |
| 195 SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1), |
| 196 SkIntToScalar(-1), SkIntToScalar( 7 ), SkIntToScalar(-1), |
| 197 SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1), |
| 198 }; |
| 199 SkISize kernelSize = SkISize::Make(3, 3); |
| 200 SkScalar gain = 1.0f, bias = SkIntToScalar(0); |
| 201 SkIPoint kernelOffset = SkIPoint::Make(1, 1); |
| 202 auto tileMode = SkMatrixConvolutionImageFilter::kClamp_TileMode; |
| 203 bool convolveAlpha = false; |
| 204 SkAutoTUnref<SkImageFilter> convolve( |
| 205 SkMatrixConvolutionImageFilter::Create(kernelSize, |
| 206 kernel, |
| 207 gain, |
| 208 bias, |
| 209 kernelOffset, |
| 210 tileMode, |
| 211 convolveAlpha, |
| 212 dilate)); |
| 213 |
| 214 SkPaint paint; |
| 215 paint.setImageFilter(convolve); |
| 216 DrawClippedImage(canvas, fImage, paint); |
| 217 canvas->translate(SkIntToScalar(100), 0); |
| 218 } |
| 219 { |
185 // Test that crop offsets are absolute, not relative to the parent's
crop rect. | 220 // Test that crop offsets are absolute, not relative to the parent's
crop rect. |
186 SkAutoTUnref<SkColorFilter> cf1(SkColorFilter::CreateModeFilter(SK_C
olorBLUE, | 221 SkAutoTUnref<SkColorFilter> cf1(SkColorFilter::CreateModeFilter(SK_C
olorBLUE, |
187 SkXf
ermode::kSrcIn_Mode)); | 222 SkXf
ermode::kSrcIn_Mode)); |
188 SkAutoTUnref<SkColorFilter> cf2(SkColorFilter::CreateModeFilter(SK_C
olorGREEN, | 223 SkAutoTUnref<SkColorFilter> cf2(SkColorFilter::CreateModeFilter(SK_C
olorGREEN, |
189 SkXf
ermode::kSrcIn_Mode)); | 224 SkXf
ermode::kSrcIn_Mode)); |
190 SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10)
, SkIntToScalar(10), | 225 SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10)
, SkIntToScalar(10), |
191 SkIntToScalar(80)
, SkIntToScalar(80))); | 226 SkIntToScalar(80)
, SkIntToScalar(80))); |
192 SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20)
, SkIntToScalar(20), | 227 SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20)
, SkIntToScalar(20), |
193 SkIntToScalar(60)
, SkIntToScalar(60))); | 228 SkIntToScalar(60)
, SkIntToScalar(60))); |
194 SkAutoTUnref<SkImageFilter> color1(SkColorFilterImageFilter::Create(
cf1, nullptr, &outerRect)); | 229 SkAutoTUnref<SkImageFilter> color1(SkColorFilterImageFilter::Create(
cf1, nullptr, &outerRect)); |
(...skipping 16 matching lines...) Expand all Loading... |
211 } | 246 } |
212 | 247 |
213 SkAutoTUnref<SkImage> fImage; | 248 SkAutoTUnref<SkImage> fImage; |
214 | 249 |
215 typedef GM INHERITED; | 250 typedef GM INHERITED; |
216 }; | 251 }; |
217 | 252 |
218 /////////////////////////////////////////////////////////////////////////////// | 253 /////////////////////////////////////////////////////////////////////////////// |
219 | 254 |
220 DEF_GM(return new ImageFiltersGraphGM;) | 255 DEF_GM(return new ImageFiltersGraphGM;) |
OLD | NEW |