senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | |
commit-bot@chromium.org | 4b681bc | 2013-09-13 12:40:02 +0000 | [diff] [blame] | 8 | #include "SkBitmap.h" |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 9 | #include "SkBlurImageFilter.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 10 | #include "SkCanvas.h" |
| 11 | #include "SkColorFilterImageFilter.h" |
| 12 | #include "SkColorMatrixFilter.h" |
ajuma | 5788faa | 2015-02-13 09:05:47 -0800 | [diff] [blame] | 13 | #include "SkComposeImageFilter.h" |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 14 | #include "SkDisplacementMapEffect.h" |
| 15 | #include "SkDropShadowImageFilter.h" |
senorblanco@chromium.org | 97f5fc6 | 2014-05-30 20:50:56 +0000 | [diff] [blame] | 16 | #include "SkFlattenableSerialization.h" |
senorblanco@chromium.org | 0a5c233 | 2014-04-29 15:20:39 +0000 | [diff] [blame] | 17 | #include "SkGradientShader.h" |
fmalita | 5598b63 | 2015-09-15 11:26:13 -0700 | [diff] [blame] | 18 | #include "SkImage.h" |
fmalita | cd56f81 | 2015-09-14 13:31:18 -0700 | [diff] [blame] | 19 | #include "SkImageSource.h" |
commit-bot@chromium.org | 4b681bc | 2013-09-13 12:40:02 +0000 | [diff] [blame] | 20 | #include "SkLightingImageFilter.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 21 | #include "SkMatrixConvolutionImageFilter.h" |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 22 | #include "SkMergeImageFilter.h" |
| 23 | #include "SkMorphologyImageFilter.h" |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 24 | #include "SkOffsetImageFilter.h" |
ajuma | 77b6ba3 | 2016-01-08 14:58:35 -0800 | [diff] [blame] | 25 | #include "SkPaintImageFilter.h" |
senorblanco | 8f3937d | 2014-10-29 12:36:32 -0700 | [diff] [blame] | 26 | #include "SkPerlinNoiseShader.h" |
senorblanco@chromium.org | 5251e2b | 2014-02-05 22:36:31 +0000 | [diff] [blame] | 27 | #include "SkPicture.h" |
senorblanco@chromium.org | 910702b | 2014-05-30 20:36:15 +0000 | [diff] [blame] | 28 | #include "SkPictureImageFilter.h" |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 29 | #include "SkPictureRecorder.h" |
robertphillips | 3d32d76 | 2015-07-13 13:16:44 -0700 | [diff] [blame] | 30 | #include "SkPoint3.h" |
halcanary | 97d2c0a | 2014-08-19 06:27:53 -0700 | [diff] [blame] | 31 | #include "SkReadBuffer.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 32 | #include "SkRect.h" |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 33 | #include "SkSpecialImage.h" |
| 34 | #include "SkSpecialSurface.h" |
fmalita | cd56f81 | 2015-09-14 13:31:18 -0700 | [diff] [blame] | 35 | #include "SkSurface.h" |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 36 | #include "SkTableColorFilter.h" |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 37 | #include "SkTileImageFilter.h" |
| 38 | #include "SkXfermodeImageFilter.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 39 | #include "Test.h" |
senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 40 | |
senorblanco@chromium.org | aba651c | 2014-02-03 22:22:16 +0000 | [diff] [blame] | 41 | #if SK_SUPPORT_GPU |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 42 | #include "GrContext.h" |
senorblanco@chromium.org | aba651c | 2014-02-03 22:22:16 +0000 | [diff] [blame] | 43 | #endif |
| 44 | |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 45 | static const int kBitmapSize = 4; |
commit-bot@chromium.org | 4b681bc | 2013-09-13 12:40:02 +0000 | [diff] [blame] | 46 | |
senorblanco@chromium.org | 5251e2b | 2014-02-05 22:36:31 +0000 | [diff] [blame] | 47 | namespace { |
| 48 | |
| 49 | class MatrixTestImageFilter : public SkImageFilter { |
| 50 | public: |
robertphillips | 43c2ad4 | 2016-04-04 05:05:11 -0700 | [diff] [blame] | 51 | static sk_sp<SkImageFilter> Make(skiatest::Reporter* reporter, |
| 52 | const SkMatrix& expectedMatrix) { |
| 53 | return sk_sp<SkImageFilter>(new MatrixTestImageFilter(reporter, expectedMatrix)); |
senorblanco@chromium.org | 5251e2b | 2014-02-05 22:36:31 +0000 | [diff] [blame] | 54 | } |
| 55 | |
robertphillips | f3f5bad | 2014-12-19 13:49:15 -0800 | [diff] [blame] | 56 | SK_TO_STRING_OVERRIDE() |
senorblanco@chromium.org | 5251e2b | 2014-02-05 22:36:31 +0000 | [diff] [blame] | 57 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(MatrixTestImageFilter) |
| 58 | |
| 59 | protected: |
robertphillips | 4ba94e2 | 2016-04-04 12:07:47 -0700 | [diff] [blame] | 60 | sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context& ctx, |
| 61 | SkIPoint* offset) const override { |
robertphillips | 43c2ad4 | 2016-04-04 05:05:11 -0700 | [diff] [blame] | 62 | REPORTER_ASSERT(fReporter, ctx.ctm() == fExpectedMatrix); |
robertphillips | 4ba94e2 | 2016-04-04 12:07:47 -0700 | [diff] [blame] | 63 | offset->fX = offset->fY = 0; |
| 64 | return sk_ref_sp<SkSpecialImage>(source); |
robertphillips | 43c2ad4 | 2016-04-04 05:05:11 -0700 | [diff] [blame] | 65 | } |
| 66 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 67 | void flatten(SkWriteBuffer& buffer) const override { |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 68 | this->INHERITED::flatten(buffer); |
senorblanco@chromium.org | 5251e2b | 2014-02-05 22:36:31 +0000 | [diff] [blame] | 69 | buffer.writeFunctionPtr(fReporter); |
| 70 | buffer.writeMatrix(fExpectedMatrix); |
| 71 | } |
| 72 | |
| 73 | private: |
robertphillips | 43c2ad4 | 2016-04-04 05:05:11 -0700 | [diff] [blame] | 74 | MatrixTestImageFilter(skiatest::Reporter* reporter, const SkMatrix& expectedMatrix) |
| 75 | : INHERITED(nullptr, 0, nullptr) |
| 76 | , fReporter(reporter) |
| 77 | , fExpectedMatrix(expectedMatrix) { |
| 78 | } |
| 79 | |
senorblanco@chromium.org | 5251e2b | 2014-02-05 22:36:31 +0000 | [diff] [blame] | 80 | skiatest::Reporter* fReporter; |
| 81 | SkMatrix fExpectedMatrix; |
mtklein | 3f3b3d0 | 2014-12-01 11:47:08 -0800 | [diff] [blame] | 82 | |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 83 | typedef SkImageFilter INHERITED; |
senorblanco@chromium.org | 5251e2b | 2014-02-05 22:36:31 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
senorblanco | 6a93fa1 | 2016-04-05 04:43:45 -0700 | [diff] [blame] | 86 | class FailImageFilter : public SkImageFilter { |
| 87 | public: |
robertphillips | 6b13473 | 2016-04-15 09:58:37 -0700 | [diff] [blame] | 88 | FailImageFilter() : SkImageFilter(nullptr, 0, nullptr) { } |
senorblanco | 6a93fa1 | 2016-04-05 04:43:45 -0700 | [diff] [blame] | 89 | |
| 90 | sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, |
| 91 | const Context& ctx, |
| 92 | SkIPoint* offset) const override { |
| 93 | return nullptr; |
| 94 | } |
| 95 | |
| 96 | SK_TO_STRING_OVERRIDE() |
| 97 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(FailImageFilter) |
| 98 | |
| 99 | private: |
| 100 | typedef SkImageFilter INHERITED; |
| 101 | }; |
| 102 | |
| 103 | sk_sp<SkFlattenable> FailImageFilter::CreateProc(SkReadBuffer& buffer) { |
| 104 | SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0); |
| 105 | return sk_sp<SkFlattenable>(new FailImageFilter()); |
| 106 | } |
| 107 | |
| 108 | #ifndef SK_IGNORE_TO_STRING |
| 109 | void FailImageFilter::toString(SkString* str) const { |
| 110 | str->appendf("FailImageFilter: ("); |
| 111 | str->append(")"); |
| 112 | } |
| 113 | #endif |
| 114 | |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 115 | void draw_gradient_circle(SkCanvas* canvas, int width, int height) { |
| 116 | SkScalar x = SkIntToScalar(width / 2); |
| 117 | SkScalar y = SkIntToScalar(height / 2); |
| 118 | SkScalar radius = SkMinScalar(x, y) * 0.8f; |
| 119 | canvas->clear(0x00000000); |
| 120 | SkColor colors[2]; |
| 121 | colors[0] = SK_ColorWHITE; |
| 122 | colors[1] = SK_ColorBLACK; |
| 123 | sk_sp<SkShader> shader( |
| 124 | SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2, |
| 125 | SkShader::kClamp_TileMode) |
| 126 | ); |
| 127 | SkPaint paint; |
| 128 | paint.setShader(shader); |
| 129 | canvas->drawCircle(x, y, radius, paint); |
| 130 | } |
| 131 | |
| 132 | SkBitmap make_gradient_circle(int width, int height) { |
| 133 | SkBitmap bitmap; |
| 134 | bitmap.allocN32Pixels(width, height); |
| 135 | SkCanvas canvas(bitmap); |
| 136 | draw_gradient_circle(&canvas, width, height); |
| 137 | return bitmap; |
| 138 | } |
| 139 | |
| 140 | class FilterList { |
| 141 | public: |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 142 | FilterList(sk_sp<SkImageFilter> input, const SkImageFilter::CropRect* cropRect = nullptr) { |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 143 | SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 144 | const SkScalar five = SkIntToScalar(5); |
| 145 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 146 | { |
| 147 | sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED, |
| 148 | SkXfermode::kSrcIn_Mode)); |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 149 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 150 | this->addFilter("color filter", |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 151 | SkColorFilterImageFilter::Make(std::move(cf), input, cropRect)); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 152 | } |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 153 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 154 | { |
| 155 | sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_circle(64, 64))); |
| 156 | sk_sp<SkImageFilter> gradientSource(SkImageSource::Make(std::move(gradientImage))); |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 157 | |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 158 | this->addFilter("displacement map", |
robertphillips | bfe11fc | 2016-04-15 07:17:36 -0700 | [diff] [blame] | 159 | SkDisplacementMapEffect::Make(SkDisplacementMapEffect::kR_ChannelSelectorType, |
| 160 | SkDisplacementMapEffect::kB_ChannelSelectorType, |
| 161 | 20.0f, |
| 162 | std::move(gradientSource), input, cropRect)); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 163 | } |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 164 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 165 | this->addFilter("blur", SkBlurImageFilter::Make(SK_Scalar1, |
| 166 | SK_Scalar1, |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 167 | input, |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 168 | cropRect)); |
robertphillips | c416912 | 2016-04-06 08:40:59 -0700 | [diff] [blame] | 169 | this->addFilter("drop shadow", SkDropShadowImageFilter::Make( |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 170 | SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_ColorGREEN, |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 171 | SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 172 | input, cropRect)); |
| 173 | this->addFilter("diffuse lighting", |
| 174 | SkLightingImageFilter::MakePointLitDiffuse(location, SK_ColorGREEN, 0, 0, |
| 175 | input, cropRect)); |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 176 | this->addFilter("specular lighting", |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 177 | SkLightingImageFilter::MakePointLitSpecular(location, SK_ColorGREEN, 0, 0, 0, |
| 178 | input, cropRect)); |
| 179 | { |
| 180 | SkScalar kernel[9] = { |
| 181 | SkIntToScalar(1), SkIntToScalar(1), SkIntToScalar(1), |
| 182 | SkIntToScalar(1), SkIntToScalar(-7), SkIntToScalar(1), |
| 183 | SkIntToScalar(1), SkIntToScalar(1), SkIntToScalar(1), |
| 184 | }; |
| 185 | const SkISize kernelSize = SkISize::Make(3, 3); |
| 186 | const SkScalar gain = SK_Scalar1, bias = 0; |
| 187 | |
| 188 | this->addFilter("matrix convolution", |
robertphillips | ef6a47b | 2016-04-08 08:01:20 -0700 | [diff] [blame] | 189 | SkMatrixConvolutionImageFilter::Make( |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 190 | kernelSize, kernel, gain, bias, SkIPoint::Make(1, 1), |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 191 | SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 192 | input, cropRect)); |
| 193 | } |
| 194 | |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 195 | this->addFilter("merge", SkMergeImageFilter::Make(input, input, |
robertphillips | 2238c9d | 2016-03-30 13:34:16 -0700 | [diff] [blame] | 196 | SkXfermode::kSrcOver_Mode, |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 197 | cropRect)); |
| 198 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 199 | { |
| 200 | SkPaint greenColorShaderPaint; |
| 201 | greenColorShaderPaint.setShader(SkShader::MakeColorShader(SK_ColorGREEN)); |
| 202 | |
| 203 | SkImageFilter::CropRect leftSideCropRect(SkRect::MakeXYWH(0, 0, 32, 64)); |
| 204 | sk_sp<SkImageFilter> paintFilterLeft(SkPaintImageFilter::Make(greenColorShaderPaint, |
| 205 | &leftSideCropRect)); |
| 206 | SkImageFilter::CropRect rightSideCropRect(SkRect::MakeXYWH(32, 0, 32, 64)); |
| 207 | sk_sp<SkImageFilter> paintFilterRight(SkPaintImageFilter::Make(greenColorShaderPaint, |
| 208 | &rightSideCropRect)); |
| 209 | |
| 210 | |
| 211 | this->addFilter("merge with disjoint inputs", SkMergeImageFilter::Make( |
robertphillips | 2238c9d | 2016-03-30 13:34:16 -0700 | [diff] [blame] | 212 | std::move(paintFilterLeft), std::move(paintFilterRight), |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 213 | SkXfermode::kSrcOver_Mode, cropRect)); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 214 | } |
| 215 | |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 216 | this->addFilter("offset", |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 217 | SkOffsetImageFilter::Make(SK_Scalar1, SK_Scalar1, input, |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 218 | cropRect)); |
| 219 | this->addFilter("dilate", SkDilateImageFilter::Make(3, 2, input, cropRect)); |
| 220 | this->addFilter("erode", SkErodeImageFilter::Make(2, 3, input, cropRect)); |
robertphillips | 534c270 | 2016-04-15 07:57:40 -0700 | [diff] [blame] | 221 | this->addFilter("tile", SkTileImageFilter::Make( |
| 222 | SkRect::MakeXYWH(0, 0, 50, 50), |
| 223 | cropRect ? cropRect->rect() : SkRect::MakeXYWH(0, 0, 100, 100), |
| 224 | input)); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 225 | |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 226 | if (!cropRect) { |
| 227 | SkMatrix matrix; |
| 228 | |
| 229 | matrix.setTranslate(SK_Scalar1, SK_Scalar1); |
| 230 | matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1); |
| 231 | |
| 232 | this->addFilter("matrix", |
| 233 | SkImageFilter::MakeMatrixFilter(matrix, kLow_SkFilterQuality, input)); |
| 234 | } |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 235 | { |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 236 | sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(five, five, input)); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 237 | |
| 238 | this->addFilter("blur and offset", SkOffsetImageFilter::Make(five, five, |
| 239 | std::move(blur), |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 240 | cropRect)); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 241 | } |
| 242 | { |
| 243 | SkRTreeFactory factory; |
| 244 | SkPictureRecorder recorder; |
| 245 | SkCanvas* recordingCanvas = recorder.beginRecording(64, 64, &factory, 0); |
| 246 | |
| 247 | SkPaint greenPaint; |
| 248 | greenPaint.setColor(SK_ColorGREEN); |
| 249 | recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 30, 20)), greenPaint); |
| 250 | sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
| 251 | sk_sp<SkImageFilter> pictureFilter(SkPictureImageFilter::Make(std::move(picture))); |
| 252 | |
| 253 | this->addFilter("picture and blur", SkBlurImageFilter::Make(five, five, |
| 254 | std::move(pictureFilter), |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 255 | cropRect)); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 256 | } |
| 257 | { |
| 258 | SkPaint paint; |
| 259 | paint.setShader(SkPerlinNoiseShader::MakeTurbulence(SK_Scalar1, SK_Scalar1, 1, 0)); |
| 260 | sk_sp<SkImageFilter> paintFilter(SkPaintImageFilter::Make(paint)); |
| 261 | |
| 262 | this->addFilter("paint and blur", SkBlurImageFilter::Make(five, five, |
| 263 | std::move(paintFilter), |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 264 | cropRect)); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 265 | } |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 266 | this->addFilter("xfermode", SkXfermodeImageFilter::Make( |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 267 | SkXfermode::Make(SkXfermode::kSrc_Mode), input, input, cropRect)); |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 268 | } |
| 269 | int count() const { return fFilters.count(); } |
| 270 | SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.get(); } |
| 271 | const char* getName(int index) const { return fFilters[index].fName; } |
| 272 | private: |
| 273 | struct Filter { |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 274 | Filter() : fName(nullptr) {} |
| 275 | Filter(const char* name, sk_sp<SkImageFilter> filter) |
| 276 | : fName(name) |
| 277 | , fFilter(std::move(filter)) { |
| 278 | } |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 279 | const char* fName; |
| 280 | sk_sp<SkImageFilter> fFilter; |
| 281 | }; |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 282 | void addFilter(const char* name, sk_sp<SkImageFilter> filter) { |
| 283 | fFilters.push_back(Filter(name, std::move(filter))); |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | SkTArray<Filter> fFilters; |
| 287 | }; |
| 288 | |
senorblanco@chromium.org | 5251e2b | 2014-02-05 22:36:31 +0000 | [diff] [blame] | 289 | } |
| 290 | |
reed | 60c9b58 | 2016-04-03 09:11:13 -0700 | [diff] [blame] | 291 | sk_sp<SkFlattenable> MatrixTestImageFilter::CreateProc(SkReadBuffer& buffer) { |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 292 | SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
| 293 | skiatest::Reporter* reporter = (skiatest::Reporter*)buffer.readFunctionPtr(); |
| 294 | SkMatrix matrix; |
| 295 | buffer.readMatrix(&matrix); |
robertphillips | 43c2ad4 | 2016-04-04 05:05:11 -0700 | [diff] [blame] | 296 | return MatrixTestImageFilter::Make(reporter, matrix); |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 297 | } |
| 298 | |
robertphillips | f3f5bad | 2014-12-19 13:49:15 -0800 | [diff] [blame] | 299 | #ifndef SK_IGNORE_TO_STRING |
| 300 | void MatrixTestImageFilter::toString(SkString* str) const { |
| 301 | str->appendf("MatrixTestImageFilter: ("); |
| 302 | str->append(")"); |
| 303 | } |
| 304 | #endif |
| 305 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 306 | static sk_sp<SkImage> make_small_image() { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 307 | auto surface(SkSurface::MakeRasterN32Premul(kBitmapSize, kBitmapSize)); |
fmalita | 5598b63 | 2015-09-15 11:26:13 -0700 | [diff] [blame] | 308 | SkCanvas* canvas = surface->getCanvas(); |
| 309 | canvas->clear(0x00000000); |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 310 | SkPaint darkPaint; |
| 311 | darkPaint.setColor(0xFF804020); |
| 312 | SkPaint lightPaint; |
| 313 | lightPaint.setColor(0xFF244484); |
| 314 | const int i = kBitmapSize / 4; |
| 315 | for (int y = 0; y < kBitmapSize; y += i) { |
| 316 | for (int x = 0; x < kBitmapSize; x += i) { |
fmalita | 5598b63 | 2015-09-15 11:26:13 -0700 | [diff] [blame] | 317 | canvas->save(); |
| 318 | canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 319 | canvas->drawRect(SkRect::MakeXYWH(0, 0, |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 320 | SkIntToScalar(i), |
| 321 | SkIntToScalar(i)), darkPaint); |
fmalita | 5598b63 | 2015-09-15 11:26:13 -0700 | [diff] [blame] | 322 | canvas->drawRect(SkRect::MakeXYWH(SkIntToScalar(i), |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 323 | 0, |
| 324 | SkIntToScalar(i), |
| 325 | SkIntToScalar(i)), lightPaint); |
fmalita | 5598b63 | 2015-09-15 11:26:13 -0700 | [diff] [blame] | 326 | canvas->drawRect(SkRect::MakeXYWH(0, |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 327 | SkIntToScalar(i), |
| 328 | SkIntToScalar(i), |
| 329 | SkIntToScalar(i)), lightPaint); |
fmalita | 5598b63 | 2015-09-15 11:26:13 -0700 | [diff] [blame] | 330 | canvas->drawRect(SkRect::MakeXYWH(SkIntToScalar(i), |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 331 | SkIntToScalar(i), |
| 332 | SkIntToScalar(i), |
| 333 | SkIntToScalar(i)), darkPaint); |
fmalita | 5598b63 | 2015-09-15 11:26:13 -0700 | [diff] [blame] | 334 | canvas->restore(); |
commit-bot@chromium.org | 4b681bc | 2013-09-13 12:40:02 +0000 | [diff] [blame] | 335 | } |
| 336 | } |
fmalita | 5598b63 | 2015-09-15 11:26:13 -0700 | [diff] [blame] | 337 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 338 | return surface->makeImageSnapshot(); |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 339 | } |
senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 340 | |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 341 | static sk_sp<SkImageFilter> make_scale(float amount, sk_sp<SkImageFilter> input) { |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 342 | SkScalar s = amount; |
| 343 | SkScalar matrix[20] = { s, 0, 0, 0, 0, |
| 344 | 0, s, 0, 0, 0, |
| 345 | 0, 0, s, 0, 0, |
| 346 | 0, 0, 0, s, 0 }; |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 347 | sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); |
| 348 | return SkColorFilterImageFilter::Make(std::move(filter), std::move(input)); |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 349 | } |
| 350 | |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 351 | static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input, |
| 352 | const SkImageFilter::CropRect* cropRect) { |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 353 | SkScalar matrix[20]; |
| 354 | memset(matrix, 0, 20 * sizeof(SkScalar)); |
| 355 | matrix[0] = matrix[5] = matrix[10] = 0.2126f; |
| 356 | matrix[1] = matrix[6] = matrix[11] = 0.7152f; |
| 357 | matrix[2] = matrix[7] = matrix[12] = 0.0722f; |
| 358 | matrix[18] = 1.0f; |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 359 | sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix)); |
| 360 | return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), cropRect); |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 361 | } |
| 362 | |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 363 | static sk_sp<SkImageFilter> make_blue(sk_sp<SkImageFilter> input, |
| 364 | const SkImageFilter::CropRect* cropRect) { |
| 365 | sk_sp<SkColorFilter> filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, |
| 366 | SkXfermode::kSrcIn_Mode)); |
| 367 | return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), cropRect); |
reed | cedc36f | 2015-03-08 04:42:52 -0700 | [diff] [blame] | 368 | } |
| 369 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 370 | static sk_sp<SkSpecialSurface> create_empty_special_surface(GrContext* context, int widthHeight) { |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 371 | if (context) { |
| 372 | GrSurfaceDesc desc; |
| 373 | desc.fConfig = kSkia8888_GrPixelConfig; |
| 374 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 375 | desc.fWidth = widthHeight; |
| 376 | desc.fHeight = widthHeight; |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 377 | return SkSpecialSurface::MakeRenderTarget(context, desc); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 378 | } else { |
| 379 | const SkImageInfo info = SkImageInfo::MakeN32(widthHeight, widthHeight, |
| 380 | kOpaque_SkAlphaType); |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 381 | return SkSpecialSurface::MakeRaster(info); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 382 | } |
senorblanco | bf680c3 | 2016-03-16 16:15:53 -0700 | [diff] [blame] | 383 | } |
| 384 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 385 | static sk_sp<SkSpecialImage> create_empty_special_image(GrContext* context, int widthHeight) { |
| 386 | sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, widthHeight)); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 387 | |
| 388 | SkASSERT(surf); |
| 389 | |
| 390 | SkCanvas* canvas = surf->getCanvas(); |
| 391 | SkASSERT(canvas); |
| 392 | |
| 393 | canvas->clear(0x0); |
| 394 | |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 395 | return surf->makeImageSnapshot(); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 399 | DEF_TEST(ImageFilter, reporter) { |
| 400 | { |
reed | cedc36f | 2015-03-08 04:42:52 -0700 | [diff] [blame] | 401 | // Check that two non-clipping color-matrice-filters concatenate into a single filter. |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 402 | sk_sp<SkImageFilter> halfBrightness(make_scale(0.5f, nullptr)); |
| 403 | sk_sp<SkImageFilter> quarterBrightness(make_scale(0.5f, std::move(halfBrightness))); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 404 | REPORTER_ASSERT(reporter, nullptr == quarterBrightness->getInput(0)); |
reed | cedc36f | 2015-03-08 04:42:52 -0700 | [diff] [blame] | 405 | SkColorFilter* cf; |
| 406 | REPORTER_ASSERT(reporter, quarterBrightness->asColorFilter(&cf)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 407 | REPORTER_ASSERT(reporter, cf->asColorMatrix(nullptr)); |
reed | cedc36f | 2015-03-08 04:42:52 -0700 | [diff] [blame] | 408 | cf->unref(); |
senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 409 | } |
| 410 | |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 411 | { |
reed | cedc36f | 2015-03-08 04:42:52 -0700 | [diff] [blame] | 412 | // Check that a clipping color-matrice-filter followed by a color-matrice-filters |
| 413 | // concatenates into a single filter, but not a matrixfilter (due to clamping). |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 414 | sk_sp<SkImageFilter> doubleBrightness(make_scale(2.0f, nullptr)); |
| 415 | sk_sp<SkImageFilter> halfBrightness(make_scale(0.5f, std::move(doubleBrightness))); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 416 | REPORTER_ASSERT(reporter, nullptr == halfBrightness->getInput(0)); |
reed | cedc36f | 2015-03-08 04:42:52 -0700 | [diff] [blame] | 417 | SkColorFilter* cf; |
| 418 | REPORTER_ASSERT(reporter, halfBrightness->asColorFilter(&cf)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 419 | REPORTER_ASSERT(reporter, !cf->asColorMatrix(nullptr)); |
reed | cedc36f | 2015-03-08 04:42:52 -0700 | [diff] [blame] | 420 | cf->unref(); |
senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 421 | } |
| 422 | |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 423 | { |
| 424 | // Check that a color filter image filter without a crop rect can be |
| 425 | // expressed as a color filter. |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 426 | sk_sp<SkImageFilter> gray(make_grayscale(nullptr, nullptr)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 427 | REPORTER_ASSERT(reporter, true == gray->asColorFilter(nullptr)); |
senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 428 | } |
mtklein | 2afbe23 | 2016-02-07 12:23:10 -0800 | [diff] [blame] | 429 | |
reed | cedc36f | 2015-03-08 04:42:52 -0700 | [diff] [blame] | 430 | { |
| 431 | // Check that a colorfilterimage filter without a crop rect but with an input |
| 432 | // that is another colorfilterimage can be expressed as a colorfilter (composed). |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 433 | sk_sp<SkImageFilter> mode(make_blue(nullptr, nullptr)); |
| 434 | sk_sp<SkImageFilter> gray(make_grayscale(std::move(mode), nullptr)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 435 | REPORTER_ASSERT(reporter, true == gray->asColorFilter(nullptr)); |
reed | cedc36f | 2015-03-08 04:42:52 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | { |
| 439 | // Test that if we exceed the limit of what ComposeColorFilter can combine, we still |
| 440 | // can build the DAG and won't assert if we call asColorFilter. |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 441 | sk_sp<SkImageFilter> filter(make_blue(nullptr, nullptr)); |
reed | cedc36f | 2015-03-08 04:42:52 -0700 | [diff] [blame] | 442 | const int kWayTooManyForComposeColorFilter = 100; |
| 443 | for (int i = 0; i < kWayTooManyForComposeColorFilter; ++i) { |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 444 | filter = make_blue(filter, nullptr); |
reed | cedc36f | 2015-03-08 04:42:52 -0700 | [diff] [blame] | 445 | // the first few of these will succeed, but after we hit the internal limit, |
| 446 | // it will then return false. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 447 | (void)filter->asColorFilter(nullptr); |
reed | cedc36f | 2015-03-08 04:42:52 -0700 | [diff] [blame] | 448 | } |
| 449 | } |
reed | 5c518a8 | 2015-03-05 14:47:29 -0800 | [diff] [blame] | 450 | |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 451 | { |
| 452 | // Check that a color filter image filter with a crop rect cannot |
| 453 | // be expressed as a color filter. |
| 454 | SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100)); |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 455 | sk_sp<SkImageFilter> grayWithCrop(make_grayscale(nullptr, &cropRect)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 456 | REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(nullptr)); |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | { |
senorblanco | 3df0501 | 2014-07-03 11:13:09 -0700 | [diff] [blame] | 460 | // Check that two non-commutative matrices are concatenated in |
| 461 | // the correct order. |
| 462 | SkScalar blueToRedMatrix[20] = { 0 }; |
| 463 | blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1; |
| 464 | SkScalar redToGreenMatrix[20] = { 0 }; |
| 465 | redToGreenMatrix[5] = redToGreenMatrix[18] = SK_Scalar1; |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 466 | sk_sp<SkColorFilter> blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix)); |
| 467 | sk_sp<SkImageFilter> filter1(SkColorFilterImageFilter::Make(std::move(blueToRed), |
| 468 | nullptr)); |
| 469 | sk_sp<SkColorFilter> redToGreen(SkColorFilter::MakeMatrixFilterRowMajor255(redToGreenMatrix)); |
| 470 | sk_sp<SkImageFilter> filter2(SkColorFilterImageFilter::Make(std::move(redToGreen), |
| 471 | std::move(filter1))); |
senorblanco | 3df0501 | 2014-07-03 11:13:09 -0700 | [diff] [blame] | 472 | |
| 473 | SkBitmap result; |
| 474 | result.allocN32Pixels(kBitmapSize, kBitmapSize); |
| 475 | |
| 476 | SkPaint paint; |
| 477 | paint.setColor(SK_ColorBLUE); |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 478 | paint.setImageFilter(std::move(filter2)); |
senorblanco | 3df0501 | 2014-07-03 11:13:09 -0700 | [diff] [blame] | 479 | SkCanvas canvas(result); |
| 480 | canvas.clear(0x0); |
| 481 | SkRect rect = SkRect::Make(SkIRect::MakeWH(kBitmapSize, kBitmapSize)); |
| 482 | canvas.drawRect(rect, paint); |
| 483 | uint32_t pixel = *result.getAddr32(0, 0); |
| 484 | // The result here should be green, since we have effectively shifted blue to green. |
| 485 | REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 486 | } |
| 487 | |
| 488 | { |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 489 | // Tests pass by not asserting |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 490 | sk_sp<SkImage> image(make_small_image()); |
fmalita | 5598b63 | 2015-09-15 11:26:13 -0700 | [diff] [blame] | 491 | SkBitmap result; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 492 | result.allocN32Pixels(kBitmapSize, kBitmapSize); |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 493 | |
senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 494 | { |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 495 | // This tests for : |
| 496 | // 1 ) location at (0,0,1) |
robertphillips | 3d32d76 | 2015-07-13 13:16:44 -0700 | [diff] [blame] | 497 | SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 498 | // 2 ) location and target at same value |
robertphillips | 3d32d76 | 2015-07-13 13:16:44 -0700 | [diff] [blame] | 499 | SkPoint3 target = SkPoint3::Make(location.fX, location.fY, location.fZ); |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 500 | // 3 ) large negative specular exponent value |
| 501 | SkScalar specularExponent = -1000; |
| 502 | |
robertphillips | 549c899 | 2016-04-01 09:28:51 -0700 | [diff] [blame] | 503 | sk_sp<SkImageFilter> bmSrc(SkImageSource::Make(std::move(image))); |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 504 | SkPaint paint; |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 505 | paint.setImageFilter(SkLightingImageFilter::MakeSpotLitSpecular( |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 506 | location, target, specularExponent, 180, |
| 507 | 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1, |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 508 | std::move(bmSrc))); |
tfarina@chromium.org | 9f9d582 | 2013-12-18 22:15:12 +0000 | [diff] [blame] | 509 | SkCanvas canvas(result); |
| 510 | SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize), |
| 511 | SkIntToScalar(kBitmapSize)); |
| 512 | canvas.drawRect(r, paint); |
senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 513 | } |
senorblanco@chromium.org | 194d775 | 2013-07-24 22:19:24 +0000 | [diff] [blame] | 514 | } |
senorblanco@chromium.org | aba651c | 2014-02-03 22:22:16 +0000 | [diff] [blame] | 515 | } |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 516 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 517 | static void test_crop_rects(skiatest::Reporter* reporter, |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 518 | GrContext* context) { |
senorblanco@chromium.org | aba651c | 2014-02-03 22:22:16 +0000 | [diff] [blame] | 519 | // Check that all filters offset to their absolute crop rect, |
| 520 | // unaffected by the input crop rect. |
| 521 | // Tests pass by not asserting. |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 522 | sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 100)); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 523 | SkASSERT(srcImg); |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 524 | |
senorblanco@chromium.org | aba651c | 2014-02-03 22:22:16 +0000 | [diff] [blame] | 525 | SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80)); |
| 526 | SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60)); |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 527 | sk_sp<SkImageFilter> input(make_grayscale(nullptr, &inputCropRect)); |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 528 | |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 529 | FilterList filters(input, &cropRect); |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 530 | |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 531 | for (int i = 0; i < filters.count(); ++i) { |
| 532 | SkImageFilter* filter = filters.getFilter(i); |
senorblanco@chromium.org | aba651c | 2014-02-03 22:22:16 +0000 | [diff] [blame] | 533 | SkIPoint offset; |
reed | 4e23cda | 2016-01-11 10:56:59 -0800 | [diff] [blame] | 534 | SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr); |
robertphillips | 2302de9 | 2016-03-24 07:26:32 -0700 | [diff] [blame] | 535 | sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offset)); |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 536 | REPORTER_ASSERT_MESSAGE(reporter, resultImg, filters.getName(i)); |
| 537 | REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, filters.getName(i)); |
senorblanco@chromium.org | aba651c | 2014-02-03 22:22:16 +0000 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 541 | static void test_negative_blur_sigma(skiatest::Reporter* reporter, |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 542 | GrContext* context) { |
senorblanco | 32673b9 | 2014-09-09 09:15:04 -0700 | [diff] [blame] | 543 | // Check that SkBlurImageFilter will accept a negative sigma, either in |
| 544 | // the given arguments or after CTM application. |
reed | 5ea95df | 2015-10-06 14:05:32 -0700 | [diff] [blame] | 545 | const int width = 32, height = 32; |
| 546 | const SkScalar five = SkIntToScalar(5); |
senorblanco | 32673b9 | 2014-09-09 09:15:04 -0700 | [diff] [blame] | 547 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 548 | sk_sp<SkImageFilter> positiveFilter(SkBlurImageFilter::Make(five, five, nullptr)); |
| 549 | sk_sp<SkImageFilter> negativeFilter(SkBlurImageFilter::Make(-five, five, nullptr)); |
senorblanco | 32673b9 | 2014-09-09 09:15:04 -0700 | [diff] [blame] | 550 | |
| 551 | SkBitmap gradient = make_gradient_circle(width, height); |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 552 | sk_sp<SkSpecialImage> imgSrc(SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(width, height), |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 553 | gradient)); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 554 | |
senorblanco | 32673b9 | 2014-09-09 09:15:04 -0700 | [diff] [blame] | 555 | SkIPoint offset; |
reed | 4e23cda | 2016-01-11 10:56:59 -0800 | [diff] [blame] | 556 | SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 557 | |
robertphillips | 2302de9 | 2016-03-24 07:26:32 -0700 | [diff] [blame] | 558 | sk_sp<SkSpecialImage> positiveResult1(positiveFilter->filterImage(imgSrc.get(), ctx, &offset)); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 559 | REPORTER_ASSERT(reporter, positiveResult1); |
| 560 | |
robertphillips | 2302de9 | 2016-03-24 07:26:32 -0700 | [diff] [blame] | 561 | sk_sp<SkSpecialImage> negativeResult1(negativeFilter->filterImage(imgSrc.get(), ctx, &offset)); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 562 | REPORTER_ASSERT(reporter, negativeResult1); |
| 563 | |
senorblanco | 32673b9 | 2014-09-09 09:15:04 -0700 | [diff] [blame] | 564 | SkMatrix negativeScale; |
| 565 | negativeScale.setScale(-SK_Scalar1, SK_Scalar1); |
reed | 4e23cda | 2016-01-11 10:56:59 -0800 | [diff] [blame] | 566 | SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeWH(32, 32), nullptr); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 567 | |
robertphillips | 2302de9 | 2016-03-24 07:26:32 -0700 | [diff] [blame] | 568 | sk_sp<SkSpecialImage> negativeResult2(positiveFilter->filterImage(imgSrc.get(), |
| 569 | negativeCTX, |
| 570 | &offset)); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 571 | REPORTER_ASSERT(reporter, negativeResult2); |
| 572 | |
robertphillips | 2302de9 | 2016-03-24 07:26:32 -0700 | [diff] [blame] | 573 | sk_sp<SkSpecialImage> positiveResult2(negativeFilter->filterImage(imgSrc.get(), |
| 574 | negativeCTX, |
| 575 | &offset)); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 576 | REPORTER_ASSERT(reporter, positiveResult2); |
| 577 | |
| 578 | |
| 579 | SkBitmap positiveResultBM1, positiveResultBM2; |
| 580 | SkBitmap negativeResultBM1, negativeResultBM2; |
| 581 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 582 | REPORTER_ASSERT(reporter, positiveResult1->getROPixels(&positiveResultBM1)); |
| 583 | REPORTER_ASSERT(reporter, positiveResult2->getROPixels(&positiveResultBM2)); |
| 584 | REPORTER_ASSERT(reporter, negativeResult1->getROPixels(&negativeResultBM1)); |
| 585 | REPORTER_ASSERT(reporter, negativeResult2->getROPixels(&negativeResultBM2)); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 586 | |
| 587 | SkAutoLockPixels lockP1(positiveResultBM1); |
| 588 | SkAutoLockPixels lockP2(positiveResultBM2); |
| 589 | SkAutoLockPixels lockN1(negativeResultBM1); |
| 590 | SkAutoLockPixels lockN2(negativeResultBM2); |
senorblanco | 32673b9 | 2014-09-09 09:15:04 -0700 | [diff] [blame] | 591 | for (int y = 0; y < height; y++) { |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 592 | int diffs = memcmp(positiveResultBM1.getAddr32(0, y), |
| 593 | negativeResultBM1.getAddr32(0, y), |
| 594 | positiveResultBM1.rowBytes()); |
senorblanco | 32673b9 | 2014-09-09 09:15:04 -0700 | [diff] [blame] | 595 | REPORTER_ASSERT(reporter, !diffs); |
| 596 | if (diffs) { |
| 597 | break; |
| 598 | } |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 599 | diffs = memcmp(positiveResultBM1.getAddr32(0, y), |
| 600 | negativeResultBM2.getAddr32(0, y), |
| 601 | positiveResultBM1.rowBytes()); |
senorblanco | 32673b9 | 2014-09-09 09:15:04 -0700 | [diff] [blame] | 602 | REPORTER_ASSERT(reporter, !diffs); |
| 603 | if (diffs) { |
| 604 | break; |
| 605 | } |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 606 | diffs = memcmp(positiveResultBM1.getAddr32(0, y), |
| 607 | positiveResultBM2.getAddr32(0, y), |
| 608 | positiveResultBM1.rowBytes()); |
senorblanco | 32673b9 | 2014-09-09 09:15:04 -0700 | [diff] [blame] | 609 | REPORTER_ASSERT(reporter, !diffs); |
| 610 | if (diffs) { |
| 611 | break; |
| 612 | } |
| 613 | } |
| 614 | } |
| 615 | |
senorblanco | 21a465d | 2016-04-11 11:58:39 -0700 | [diff] [blame] | 616 | DEF_TEST(ImageFilterNegativeBlurSigma, reporter) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 617 | test_negative_blur_sigma(reporter, nullptr); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | #if SK_SUPPORT_GPU |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 621 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterNegativeBlurSigma_Gpu, reporter, ctxInfo) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 622 | test_negative_blur_sigma(reporter, ctxInfo.fGrContext); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 623 | } |
| 624 | #endif |
| 625 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 626 | static void test_zero_blur_sigma(skiatest::Reporter* reporter, GrContext* context) { |
senorblanco | bf680c3 | 2016-03-16 16:15:53 -0700 | [diff] [blame] | 627 | // Check that SkBlurImageFilter with a zero sigma and a non-zero srcOffset works correctly. |
| 628 | SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(5, 0, 5, 10))); |
robertphillips | 51a315e | 2016-03-31 09:05:49 -0700 | [diff] [blame] | 629 | sk_sp<SkImageFilter> input(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRect)); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 630 | sk_sp<SkImageFilter> filter(SkBlurImageFilter::Make(0, 0, std::move(input), &cropRect)); |
senorblanco | bf680c3 | 2016-03-16 16:15:53 -0700 | [diff] [blame] | 631 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 632 | sk_sp<SkSpecialSurface> surf(create_empty_special_surface(context, 10)); |
senorblanco | bf680c3 | 2016-03-16 16:15:53 -0700 | [diff] [blame] | 633 | surf->getCanvas()->clear(SK_ColorGREEN); |
robertphillips | 37bd7c3 | 2016-03-17 14:31:39 -0700 | [diff] [blame] | 634 | sk_sp<SkSpecialImage> image(surf->makeImageSnapshot()); |
senorblanco | bf680c3 | 2016-03-16 16:15:53 -0700 | [diff] [blame] | 635 | |
| 636 | SkIPoint offset; |
| 637 | SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr); |
| 638 | |
robertphillips | 2302de9 | 2016-03-24 07:26:32 -0700 | [diff] [blame] | 639 | sk_sp<SkSpecialImage> result(filter->filterImage(image.get(), ctx, &offset)); |
senorblanco | bf680c3 | 2016-03-16 16:15:53 -0700 | [diff] [blame] | 640 | REPORTER_ASSERT(reporter, offset.fX == 5 && offset.fY == 0); |
| 641 | REPORTER_ASSERT(reporter, result); |
| 642 | REPORTER_ASSERT(reporter, result->width() == 5 && result->height() == 10); |
| 643 | |
| 644 | SkBitmap resultBM; |
| 645 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 646 | REPORTER_ASSERT(reporter, result->getROPixels(&resultBM)); |
senorblanco | bf680c3 | 2016-03-16 16:15:53 -0700 | [diff] [blame] | 647 | |
| 648 | SkAutoLockPixels lock(resultBM); |
| 649 | for (int y = 0; y < resultBM.height(); y++) { |
| 650 | for (int x = 0; x < resultBM.width(); x++) { |
| 651 | bool diff = *resultBM.getAddr32(x, y) != SK_ColorGREEN; |
| 652 | REPORTER_ASSERT(reporter, !diff); |
| 653 | if (diff) { |
| 654 | break; |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
senorblanco | 21a465d | 2016-04-11 11:58:39 -0700 | [diff] [blame] | 660 | DEF_TEST(ImageFilterZeroBlurSigma, reporter) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 661 | test_zero_blur_sigma(reporter, nullptr); |
senorblanco | bf680c3 | 2016-03-16 16:15:53 -0700 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | #if SK_SUPPORT_GPU |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 665 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterZeroBlurSigma_Gpu, reporter, ctxInfo) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 666 | test_zero_blur_sigma(reporter, ctxInfo.fGrContext); |
senorblanco | bf680c3 | 2016-03-16 16:15:53 -0700 | [diff] [blame] | 667 | } |
| 668 | #endif |
| 669 | |
senorblanco | 6a93fa1 | 2016-04-05 04:43:45 -0700 | [diff] [blame] | 670 | |
| 671 | // Tests that, even when an upstream filter has returned null (due to failure or clipping), a |
| 672 | // downstream filter that affects transparent black still does so even with a nullptr input. |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 673 | static void test_fail_affects_transparent_black(skiatest::Reporter* reporter, GrContext* context) { |
senorblanco | 6a93fa1 | 2016-04-05 04:43:45 -0700 | [diff] [blame] | 674 | sk_sp<FailImageFilter> failFilter(new FailImageFilter()); |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 675 | sk_sp<SkSpecialImage> source(create_empty_special_image(context, 5)); |
senorblanco | 6a93fa1 | 2016-04-05 04:43:45 -0700 | [diff] [blame] | 676 | SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 1, 1), nullptr); |
| 677 | sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode)); |
| 678 | SkASSERT(green->affectsTransparentBlack()); |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 679 | sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Make(std::move(green), |
| 680 | std::move(failFilter))); |
senorblanco | 6a93fa1 | 2016-04-05 04:43:45 -0700 | [diff] [blame] | 681 | SkIPoint offset; |
| 682 | sk_sp<SkSpecialImage> result(greenFilter->filterImage(source.get(), ctx, &offset)); |
| 683 | REPORTER_ASSERT(reporter, nullptr != result.get()); |
| 684 | if (result.get()) { |
| 685 | SkBitmap resultBM; |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 686 | REPORTER_ASSERT(reporter, result->getROPixels(&resultBM)); |
senorblanco | 6a93fa1 | 2016-04-05 04:43:45 -0700 | [diff] [blame] | 687 | SkAutoLockPixels lock(resultBM); |
| 688 | REPORTER_ASSERT(reporter, *resultBM.getAddr32(0, 0) == SK_ColorGREEN); |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | DEF_TEST(ImageFilterFailAffectsTransparentBlack, reporter) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 693 | test_fail_affects_transparent_black(reporter, nullptr); |
senorblanco | 6a93fa1 | 2016-04-05 04:43:45 -0700 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | #if SK_SUPPORT_GPU |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 697 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterFailAffectsTransparentBlack_Gpu, reporter, ctxInfo) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 698 | test_fail_affects_transparent_black(reporter, ctxInfo.fGrContext); |
senorblanco | 6a93fa1 | 2016-04-05 04:43:45 -0700 | [diff] [blame] | 699 | } |
| 700 | #endif |
| 701 | |
senorblanco@chromium.org | 0a5c233 | 2014-04-29 15:20:39 +0000 | [diff] [blame] | 702 | DEF_TEST(ImageFilterDrawTiled, reporter) { |
| 703 | // Check that all filters when drawn tiled (with subsequent clip rects) exactly |
| 704 | // match the same filters drawn with a single full-canvas bitmap draw. |
| 705 | // Tests pass by not asserting. |
| 706 | |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 707 | FilterList filters(nullptr); |
senorblanco@chromium.org | 0a5c233 | 2014-04-29 15:20:39 +0000 | [diff] [blame] | 708 | |
| 709 | SkBitmap untiledResult, tiledResult; |
reed | 5ea95df | 2015-10-06 14:05:32 -0700 | [diff] [blame] | 710 | const int width = 64, height = 64; |
senorblanco@chromium.org | 0a5c233 | 2014-04-29 15:20:39 +0000 | [diff] [blame] | 711 | untiledResult.allocN32Pixels(width, height); |
| 712 | tiledResult.allocN32Pixels(width, height); |
| 713 | SkCanvas tiledCanvas(tiledResult); |
| 714 | SkCanvas untiledCanvas(untiledResult); |
senorblanco@chromium.org | d4db657 | 2014-05-07 20:00:04 +0000 | [diff] [blame] | 715 | int tileSize = 8; |
senorblanco@chromium.org | 0a5c233 | 2014-04-29 15:20:39 +0000 | [diff] [blame] | 716 | |
senorblanco@chromium.org | d4db657 | 2014-05-07 20:00:04 +0000 | [diff] [blame] | 717 | for (int scale = 1; scale <= 2; ++scale) { |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 718 | for (int i = 0; i < filters.count(); ++i) { |
senorblanco@chromium.org | d4db657 | 2014-05-07 20:00:04 +0000 | [diff] [blame] | 719 | tiledCanvas.clear(0); |
| 720 | untiledCanvas.clear(0); |
| 721 | SkPaint paint; |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 722 | paint.setImageFilter(filters.getFilter(i)); |
senorblanco@chromium.org | d4db657 | 2014-05-07 20:00:04 +0000 | [diff] [blame] | 723 | paint.setTextSize(SkIntToScalar(height)); |
| 724 | paint.setColor(SK_ColorWHITE); |
| 725 | SkString str; |
| 726 | const char* text = "ABC"; |
| 727 | SkScalar ypos = SkIntToScalar(height); |
| 728 | untiledCanvas.save(); |
| 729 | untiledCanvas.scale(SkIntToScalar(scale), SkIntToScalar(scale)); |
| 730 | untiledCanvas.drawText(text, strlen(text), 0, ypos, paint); |
| 731 | untiledCanvas.restore(); |
| 732 | for (int y = 0; y < height; y += tileSize) { |
| 733 | for (int x = 0; x < width; x += tileSize) { |
| 734 | tiledCanvas.save(); |
| 735 | tiledCanvas.clipRect(SkRect::Make(SkIRect::MakeXYWH(x, y, tileSize, tileSize))); |
| 736 | tiledCanvas.scale(SkIntToScalar(scale), SkIntToScalar(scale)); |
| 737 | tiledCanvas.drawText(text, strlen(text), 0, ypos, paint); |
| 738 | tiledCanvas.restore(); |
| 739 | } |
senorblanco@chromium.org | 0a5c233 | 2014-04-29 15:20:39 +0000 | [diff] [blame] | 740 | } |
senorblanco@chromium.org | d4db657 | 2014-05-07 20:00:04 +0000 | [diff] [blame] | 741 | untiledCanvas.flush(); |
| 742 | tiledCanvas.flush(); |
| 743 | for (int y = 0; y < height; y++) { |
| 744 | int diffs = memcmp(untiledResult.getAddr32(0, y), tiledResult.getAddr32(0, y), untiledResult.rowBytes()); |
senorblanco | 297f7ce | 2016-03-23 13:44:26 -0700 | [diff] [blame] | 745 | REPORTER_ASSERT_MESSAGE(reporter, !diffs, filters.getName(i)); |
senorblanco@chromium.org | d4db657 | 2014-05-07 20:00:04 +0000 | [diff] [blame] | 746 | if (diffs) { |
| 747 | break; |
| 748 | } |
senorblanco@chromium.org | 0a5c233 | 2014-04-29 15:20:39 +0000 | [diff] [blame] | 749 | } |
| 750 | } |
| 751 | } |
senorblanco@chromium.org | 0a5c233 | 2014-04-29 15:20:39 +0000 | [diff] [blame] | 752 | } |
| 753 | |
mtklein | 3f3b3d0 | 2014-12-01 11:47:08 -0800 | [diff] [blame] | 754 | static void draw_saveLayer_picture(int width, int height, int tileSize, |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 755 | SkBBHFactory* factory, SkBitmap* result) { |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 756 | |
| 757 | SkMatrix matrix; |
| 758 | matrix.setTranslate(SkIntToScalar(50), 0); |
| 759 | |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 760 | sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode)); |
| 761 | sk_sp<SkImageFilter> cfif(SkColorFilterImageFilter::Make(std::move(cf), nullptr)); |
robertphillips | ae8c933 | 2016-04-05 15:09:00 -0700 | [diff] [blame] | 762 | sk_sp<SkImageFilter> imageFilter(SkImageFilter::MakeMatrixFilter(matrix, |
| 763 | kNone_SkFilterQuality, |
| 764 | std::move(cfif))); |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 765 | |
| 766 | SkPaint paint; |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 767 | paint.setImageFilter(std::move(imageFilter)); |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 768 | SkPictureRecorder recorder; |
| 769 | SkRect bounds = SkRect::Make(SkIRect::MakeXYWH(0, 0, 50, 50)); |
mtklein | 3f3b3d0 | 2014-12-01 11:47:08 -0800 | [diff] [blame] | 770 | SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(width), |
| 771 | SkIntToScalar(height), |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 772 | factory, 0); |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 773 | recordingCanvas->translate(-55, 0); |
| 774 | recordingCanvas->saveLayer(&bounds, &paint); |
| 775 | recordingCanvas->restore(); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 776 | sk_sp<SkPicture> picture1(recorder.finishRecordingAsPicture()); |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 777 | |
| 778 | result->allocN32Pixels(width, height); |
| 779 | SkCanvas canvas(*result); |
| 780 | canvas.clear(0); |
| 781 | canvas.clipRect(SkRect::Make(SkIRect::MakeWH(tileSize, tileSize))); |
| 782 | canvas.drawPicture(picture1.get()); |
| 783 | } |
| 784 | |
| 785 | DEF_TEST(ImageFilterDrawMatrixBBH, reporter) { |
| 786 | // Check that matrix filter when drawn tiled with BBH exactly |
| 787 | // matches the same thing drawn without BBH. |
| 788 | // Tests pass by not asserting. |
| 789 | |
| 790 | const int width = 200, height = 200; |
| 791 | const int tileSize = 100; |
| 792 | SkBitmap result1, result2; |
| 793 | SkRTreeFactory factory; |
| 794 | |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 795 | draw_saveLayer_picture(width, height, tileSize, &factory, &result1); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 796 | draw_saveLayer_picture(width, height, tileSize, nullptr, &result2); |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 797 | |
| 798 | for (int y = 0; y < height; y++) { |
| 799 | int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), result1.rowBytes()); |
| 800 | REPORTER_ASSERT(reporter, !diffs); |
| 801 | if (diffs) { |
| 802 | break; |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 807 | static sk_sp<SkImageFilter> make_blur(sk_sp<SkImageFilter> input) { |
| 808 | return SkBlurImageFilter::Make(SK_Scalar1, SK_Scalar1, std::move(input)); |
senorblanco | 1150a6d | 2014-08-25 12:46:58 -0700 | [diff] [blame] | 809 | } |
| 810 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 811 | static sk_sp<SkImageFilter> make_drop_shadow(sk_sp<SkImageFilter> input) { |
robertphillips | c416912 | 2016-04-06 08:40:59 -0700 | [diff] [blame] | 812 | return SkDropShadowImageFilter::Make( |
senorblanco | 1150a6d | 2014-08-25 12:46:58 -0700 | [diff] [blame] | 813 | SkIntToScalar(100), SkIntToScalar(100), |
| 814 | SkIntToScalar(10), SkIntToScalar(10), |
sugoi | 234f036 | 2014-10-23 13:59:52 -0700 | [diff] [blame] | 815 | SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, |
robertphillips | c416912 | 2016-04-06 08:40:59 -0700 | [diff] [blame] | 816 | std::move(input)); |
senorblanco | 1150a6d | 2014-08-25 12:46:58 -0700 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | DEF_TEST(ImageFilterBlurThenShadowBounds, reporter) { |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 820 | sk_sp<SkImageFilter> filter1(make_blur(nullptr)); |
| 821 | sk_sp<SkImageFilter> filter2(make_drop_shadow(std::move(filter1))); |
senorblanco | 1150a6d | 2014-08-25 12:46:58 -0700 | [diff] [blame] | 822 | |
| 823 | SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); |
| 824 | SkIRect expectedBounds = SkIRect::MakeXYWH(-133, -133, 236, 236); |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 825 | bounds = filter2->filterBounds(bounds, SkMatrix::I()); |
senorblanco | 1150a6d | 2014-08-25 12:46:58 -0700 | [diff] [blame] | 826 | |
| 827 | REPORTER_ASSERT(reporter, bounds == expectedBounds); |
| 828 | } |
| 829 | |
| 830 | DEF_TEST(ImageFilterShadowThenBlurBounds, reporter) { |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 831 | sk_sp<SkImageFilter> filter1(make_drop_shadow(nullptr)); |
| 832 | sk_sp<SkImageFilter> filter2(make_blur(std::move(filter1))); |
senorblanco | 1150a6d | 2014-08-25 12:46:58 -0700 | [diff] [blame] | 833 | |
| 834 | SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); |
| 835 | SkIRect expectedBounds = SkIRect::MakeXYWH(-133, -133, 236, 236); |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 836 | bounds = filter2->filterBounds(bounds, SkMatrix::I()); |
senorblanco | 1150a6d | 2014-08-25 12:46:58 -0700 | [diff] [blame] | 837 | |
| 838 | REPORTER_ASSERT(reporter, bounds == expectedBounds); |
| 839 | } |
| 840 | |
| 841 | DEF_TEST(ImageFilterDilateThenBlurBounds, reporter) { |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 842 | sk_sp<SkImageFilter> filter1(SkDilateImageFilter::Make(2, 2, nullptr)); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 843 | sk_sp<SkImageFilter> filter2(make_drop_shadow(std::move(filter1))); |
senorblanco | 1150a6d | 2014-08-25 12:46:58 -0700 | [diff] [blame] | 844 | |
| 845 | SkIRect bounds = SkIRect::MakeXYWH(0, 0, 100, 100); |
| 846 | SkIRect expectedBounds = SkIRect::MakeXYWH(-132, -132, 234, 234); |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 847 | bounds = filter2->filterBounds(bounds, SkMatrix::I()); |
senorblanco | 1150a6d | 2014-08-25 12:46:58 -0700 | [diff] [blame] | 848 | |
| 849 | REPORTER_ASSERT(reporter, bounds == expectedBounds); |
| 850 | } |
| 851 | |
ajuma | 5788faa | 2015-02-13 09:05:47 -0800 | [diff] [blame] | 852 | DEF_TEST(ImageFilterComposedBlurFastBounds, reporter) { |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 853 | sk_sp<SkImageFilter> filter1(make_blur(nullptr)); |
| 854 | sk_sp<SkImageFilter> filter2(make_blur(nullptr)); |
robertphillips | 491fb17 | 2016-03-30 12:32:58 -0700 | [diff] [blame] | 855 | sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(filter1), |
| 856 | std::move(filter2))); |
ajuma | 5788faa | 2015-02-13 09:05:47 -0800 | [diff] [blame] | 857 | |
| 858 | SkRect boundsSrc = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); |
| 859 | SkRect expectedBounds = SkRect::MakeXYWH( |
| 860 | SkIntToScalar(-6), SkIntToScalar(-6), SkIntToScalar(112), SkIntToScalar(112)); |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 861 | SkRect boundsDst = composedFilter->computeFastBounds(boundsSrc); |
ajuma | 5788faa | 2015-02-13 09:05:47 -0800 | [diff] [blame] | 862 | |
| 863 | REPORTER_ASSERT(reporter, boundsDst == expectedBounds); |
| 864 | } |
| 865 | |
jbroman | 0e3129d | 2016-03-17 12:24:23 -0700 | [diff] [blame] | 866 | DEF_TEST(ImageFilterUnionBounds, reporter) { |
robertphillips | 51a315e | 2016-03-31 09:05:49 -0700 | [diff] [blame] | 867 | sk_sp<SkImageFilter> offset(SkOffsetImageFilter::Make(50, 0, nullptr)); |
jbroman | 0e3129d | 2016-03-17 12:24:23 -0700 | [diff] [blame] | 868 | // Regardless of which order they appear in, the image filter bounds should |
| 869 | // be combined correctly. |
| 870 | { |
robertphillips | 8c0326d | 2016-04-05 12:48:34 -0700 | [diff] [blame] | 871 | sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, offset)); |
jbroman | 0e3129d | 2016-03-17 12:24:23 -0700 | [diff] [blame] | 872 | SkRect bounds = SkRect::MakeWH(100, 100); |
| 873 | // Intentionally aliasing here, as that's what the real callers do. |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 874 | bounds = composite->computeFastBounds(bounds); |
jbroman | 0e3129d | 2016-03-17 12:24:23 -0700 | [diff] [blame] | 875 | REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100)); |
| 876 | } |
| 877 | { |
reed | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 878 | sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, nullptr, |
robertphillips | 8c0326d | 2016-04-05 12:48:34 -0700 | [diff] [blame] | 879 | offset, nullptr)); |
jbroman | 0e3129d | 2016-03-17 12:24:23 -0700 | [diff] [blame] | 880 | SkRect bounds = SkRect::MakeWH(100, 100); |
| 881 | // Intentionally aliasing here, as that's what the real callers do. |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 882 | bounds = composite->computeFastBounds(bounds); |
jbroman | 0e3129d | 2016-03-17 12:24:23 -0700 | [diff] [blame] | 883 | REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100)); |
| 884 | } |
| 885 | } |
| 886 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 887 | static void test_imagefilter_merge_result_size(skiatest::Reporter* reporter, GrContext* context) { |
senorblanco | 4a24398 | 2015-11-25 07:06:55 -0800 | [diff] [blame] | 888 | SkBitmap greenBM; |
| 889 | greenBM.allocN32Pixels(20, 20); |
| 890 | greenBM.eraseColor(SK_ColorGREEN); |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 891 | sk_sp<SkImage> greenImage(SkImage::MakeFromBitmap(greenBM)); |
robertphillips | 549c899 | 2016-04-01 09:28:51 -0700 | [diff] [blame] | 892 | sk_sp<SkImageFilter> source(SkImageSource::Make(std::move(greenImage))); |
robertphillips | 2238c9d | 2016-03-30 13:34:16 -0700 | [diff] [blame] | 893 | sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(source, source)); |
senorblanco | 4a24398 | 2015-11-25 07:06:55 -0800 | [diff] [blame] | 894 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 895 | sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 1)); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 896 | |
reed | 4e23cda | 2016-01-11 10:56:59 -0800 | [diff] [blame] | 897 | SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr); |
senorblanco | 4a24398 | 2015-11-25 07:06:55 -0800 | [diff] [blame] | 898 | SkIPoint offset; |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 899 | |
robertphillips | 2302de9 | 2016-03-24 07:26:32 -0700 | [diff] [blame] | 900 | sk_sp<SkSpecialImage> resultImg(merge->filterImage(srcImg.get(), ctx, &offset)); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 901 | REPORTER_ASSERT(reporter, resultImg); |
| 902 | |
| 903 | REPORTER_ASSERT(reporter, resultImg->width() == 20 && resultImg->height() == 20); |
senorblanco | 4a24398 | 2015-11-25 07:06:55 -0800 | [diff] [blame] | 904 | } |
| 905 | |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 906 | DEF_TEST(ImageFilterMergeResultSize, reporter) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 907 | test_imagefilter_merge_result_size(reporter, nullptr); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | #if SK_SUPPORT_GPU |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 911 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImageFilterMergeResultSize_Gpu, reporter, ctxInfo) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 912 | test_imagefilter_merge_result_size(reporter, ctxInfo.fGrContext); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 913 | } |
| 914 | #endif |
| 915 | |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 916 | static void draw_blurred_rect(SkCanvas* canvas) { |
senorblanco | 837f532 | 2014-07-14 10:19:54 -0700 | [diff] [blame] | 917 | SkPaint filterPaint; |
| 918 | filterPaint.setColor(SK_ColorWHITE); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 919 | filterPaint.setImageFilter(SkBlurImageFilter::Make(SkIntToScalar(8), 0, nullptr)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 920 | canvas->saveLayer(nullptr, &filterPaint); |
senorblanco | 837f532 | 2014-07-14 10:19:54 -0700 | [diff] [blame] | 921 | SkPaint whitePaint; |
| 922 | whitePaint.setColor(SK_ColorWHITE); |
| 923 | canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); |
| 924 | canvas->restore(); |
| 925 | } |
| 926 | |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 927 | static void draw_picture_clipped(SkCanvas* canvas, const SkRect& clipRect, const SkPicture* picture) { |
senorblanco | 837f532 | 2014-07-14 10:19:54 -0700 | [diff] [blame] | 928 | canvas->save(); |
| 929 | canvas->clipRect(clipRect); |
| 930 | canvas->drawPicture(picture); |
| 931 | canvas->restore(); |
| 932 | } |
| 933 | |
| 934 | DEF_TEST(ImageFilterDrawTiledBlurRTree, reporter) { |
| 935 | // Check that the blur filter when recorded with RTree acceleration, |
| 936 | // and drawn tiled (with subsequent clip rects) exactly |
| 937 | // matches the same filter drawn with without RTree acceleration. |
| 938 | // This tests that the "bleed" from the blur into the otherwise-blank |
| 939 | // tiles is correctly rendered. |
| 940 | // Tests pass by not asserting. |
| 941 | |
| 942 | int width = 16, height = 8; |
| 943 | SkBitmap result1, result2; |
| 944 | result1.allocN32Pixels(width, height); |
| 945 | result2.allocN32Pixels(width, height); |
| 946 | SkCanvas canvas1(result1); |
| 947 | SkCanvas canvas2(result2); |
| 948 | int tileSize = 8; |
| 949 | |
| 950 | canvas1.clear(0); |
| 951 | canvas2.clear(0); |
| 952 | |
| 953 | SkRTreeFactory factory; |
| 954 | |
| 955 | SkPictureRecorder recorder1, recorder2; |
| 956 | // The only difference between these two pictures is that one has RTree aceleration. |
mtklein | 3f3b3d0 | 2014-12-01 11:47:08 -0800 | [diff] [blame] | 957 | SkCanvas* recordingCanvas1 = recorder1.beginRecording(SkIntToScalar(width), |
| 958 | SkIntToScalar(height), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 959 | nullptr, 0); |
mtklein | 3f3b3d0 | 2014-12-01 11:47:08 -0800 | [diff] [blame] | 960 | SkCanvas* recordingCanvas2 = recorder2.beginRecording(SkIntToScalar(width), |
| 961 | SkIntToScalar(height), |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 962 | &factory, 0); |
| 963 | draw_blurred_rect(recordingCanvas1); |
| 964 | draw_blurred_rect(recordingCanvas2); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 965 | sk_sp<SkPicture> picture1(recorder1.finishRecordingAsPicture()); |
| 966 | sk_sp<SkPicture> picture2(recorder2.finishRecordingAsPicture()); |
senorblanco | 837f532 | 2014-07-14 10:19:54 -0700 | [diff] [blame] | 967 | for (int y = 0; y < height; y += tileSize) { |
| 968 | for (int x = 0; x < width; x += tileSize) { |
| 969 | SkRect tileRect = SkRect::Make(SkIRect::MakeXYWH(x, y, tileSize, tileSize)); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 970 | draw_picture_clipped(&canvas1, tileRect, picture1.get()); |
| 971 | draw_picture_clipped(&canvas2, tileRect, picture2.get()); |
senorblanco | 837f532 | 2014-07-14 10:19:54 -0700 | [diff] [blame] | 972 | } |
| 973 | } |
| 974 | for (int y = 0; y < height; y++) { |
| 975 | int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), result1.rowBytes()); |
| 976 | REPORTER_ASSERT(reporter, !diffs); |
| 977 | if (diffs) { |
| 978 | break; |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | |
senorblanco@chromium.org | 9195743 | 2014-05-01 14:03:41 +0000 | [diff] [blame] | 983 | DEF_TEST(ImageFilterMatrixConvolution, reporter) { |
| 984 | // Check that a 1x3 filter does not cause a spurious assert. |
| 985 | SkScalar kernel[3] = { |
| 986 | SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
| 987 | }; |
| 988 | SkISize kernelSize = SkISize::Make(1, 3); |
| 989 | SkScalar gain = SK_Scalar1, bias = 0; |
| 990 | SkIPoint kernelOffset = SkIPoint::Make(0, 0); |
| 991 | |
robertphillips | ef6a47b | 2016-04-08 08:01:20 -0700 | [diff] [blame] | 992 | sk_sp<SkImageFilter> filter(SkMatrixConvolutionImageFilter::Make( |
| 993 | kernelSize, kernel, |
| 994 | gain, bias, kernelOffset, |
| 995 | SkMatrixConvolutionImageFilter::kRepeat_TileMode, |
| 996 | false, nullptr)); |
senorblanco@chromium.org | 9195743 | 2014-05-01 14:03:41 +0000 | [diff] [blame] | 997 | |
| 998 | SkBitmap result; |
| 999 | int width = 16, height = 16; |
| 1000 | result.allocN32Pixels(width, height); |
| 1001 | SkCanvas canvas(result); |
| 1002 | canvas.clear(0); |
| 1003 | |
| 1004 | SkPaint paint; |
robertphillips | ef6a47b | 2016-04-08 08:01:20 -0700 | [diff] [blame] | 1005 | paint.setImageFilter(std::move(filter)); |
senorblanco@chromium.org | 9195743 | 2014-05-01 14:03:41 +0000 | [diff] [blame] | 1006 | SkRect rect = SkRect::Make(SkIRect::MakeWH(width, height)); |
| 1007 | canvas.drawRect(rect, paint); |
| 1008 | } |
| 1009 | |
senorblanco@chromium.org | 8c7372b | 2014-05-02 19:13:11 +0000 | [diff] [blame] | 1010 | DEF_TEST(ImageFilterMatrixConvolutionBorder, reporter) { |
| 1011 | // Check that a filter with borders outside the target bounds |
| 1012 | // does not crash. |
| 1013 | SkScalar kernel[3] = { |
| 1014 | 0, 0, 0, |
| 1015 | }; |
| 1016 | SkISize kernelSize = SkISize::Make(3, 1); |
| 1017 | SkScalar gain = SK_Scalar1, bias = 0; |
| 1018 | SkIPoint kernelOffset = SkIPoint::Make(2, 0); |
| 1019 | |
robertphillips | ef6a47b | 2016-04-08 08:01:20 -0700 | [diff] [blame] | 1020 | sk_sp<SkImageFilter> filter(SkMatrixConvolutionImageFilter::Make( |
| 1021 | kernelSize, kernel, gain, bias, kernelOffset, |
| 1022 | SkMatrixConvolutionImageFilter::kClamp_TileMode, |
| 1023 | true, nullptr)); |
senorblanco@chromium.org | 8c7372b | 2014-05-02 19:13:11 +0000 | [diff] [blame] | 1024 | |
| 1025 | SkBitmap result; |
| 1026 | |
| 1027 | int width = 10, height = 10; |
| 1028 | result.allocN32Pixels(width, height); |
| 1029 | SkCanvas canvas(result); |
| 1030 | canvas.clear(0); |
| 1031 | |
| 1032 | SkPaint filterPaint; |
robertphillips | ef6a47b | 2016-04-08 08:01:20 -0700 | [diff] [blame] | 1033 | filterPaint.setImageFilter(std::move(filter)); |
senorblanco@chromium.org | 8c7372b | 2014-05-02 19:13:11 +0000 | [diff] [blame] | 1034 | SkRect bounds = SkRect::MakeWH(1, 10); |
| 1035 | SkRect rect = SkRect::Make(SkIRect::MakeWH(width, height)); |
| 1036 | SkPaint rectPaint; |
| 1037 | canvas.saveLayer(&bounds, &filterPaint); |
| 1038 | canvas.drawRect(rect, rectPaint); |
| 1039 | canvas.restore(); |
| 1040 | } |
| 1041 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1042 | static void test_big_kernel(skiatest::Reporter* reporter, GrContext* context) { |
robertphillips | dada4dd | 2016-04-13 04:54:36 -0700 | [diff] [blame] | 1043 | // Check that a kernel that is too big for the GPU still works |
| 1044 | SkScalar identityKernel[49] = { |
| 1045 | 0, 0, 0, 0, 0, 0, 0, |
| 1046 | 0, 0, 0, 0, 0, 0, 0, |
| 1047 | 0, 0, 0, 0, 0, 0, 0, |
| 1048 | 0, 0, 0, 1, 0, 0, 0, |
| 1049 | 0, 0, 0, 0, 0, 0, 0, |
| 1050 | 0, 0, 0, 0, 0, 0, 0, |
| 1051 | 0, 0, 0, 0, 0, 0, 0 |
| 1052 | }; |
| 1053 | SkISize kernelSize = SkISize::Make(7, 7); |
| 1054 | SkScalar gain = SK_Scalar1, bias = 0; |
| 1055 | SkIPoint kernelOffset = SkIPoint::Make(0, 0); |
| 1056 | |
| 1057 | sk_sp<SkImageFilter> filter(SkMatrixConvolutionImageFilter::Make( |
| 1058 | kernelSize, identityKernel, gain, bias, kernelOffset, |
| 1059 | SkMatrixConvolutionImageFilter::kClamp_TileMode, |
| 1060 | true, nullptr)); |
| 1061 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1062 | sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 100)); |
robertphillips | dada4dd | 2016-04-13 04:54:36 -0700 | [diff] [blame] | 1063 | SkASSERT(srcImg); |
| 1064 | |
| 1065 | SkIPoint offset; |
| 1066 | SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr); |
| 1067 | sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offset)); |
| 1068 | REPORTER_ASSERT(reporter, resultImg); |
| 1069 | REPORTER_ASSERT(reporter, SkToBool(context) == resultImg->isTextureBacked()); |
| 1070 | REPORTER_ASSERT(reporter, resultImg->width() == 100 && resultImg->height() == 100); |
| 1071 | REPORTER_ASSERT(reporter, offset.fX == 0 && offset.fY == 0); |
| 1072 | } |
| 1073 | |
| 1074 | DEF_TEST(ImageFilterMatrixConvolutionBigKernel, reporter) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1075 | test_big_kernel(reporter, nullptr); |
robertphillips | dada4dd | 2016-04-13 04:54:36 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | #if SK_SUPPORT_GPU |
| 1079 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ImageFilterMatrixConvolutionBigKernel_Gpu, |
| 1080 | reporter, ctxInfo) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1081 | test_big_kernel(reporter, ctxInfo.fGrContext); |
robertphillips | dada4dd | 2016-04-13 04:54:36 -0700 | [diff] [blame] | 1082 | } |
| 1083 | #endif |
| 1084 | |
senorblanco@chromium.org | aba651c | 2014-02-03 22:22:16 +0000 | [diff] [blame] | 1085 | DEF_TEST(ImageFilterCropRect, reporter) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1086 | test_crop_rects(reporter, nullptr); |
senorblanco@chromium.org | aba651c | 2014-02-03 22:22:16 +0000 | [diff] [blame] | 1087 | } |
| 1088 | |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1089 | #if SK_SUPPORT_GPU |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 1090 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCropRect_Gpu, reporter, ctxInfo) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1091 | test_crop_rects(reporter, ctxInfo.fGrContext); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1092 | } |
| 1093 | #endif |
| 1094 | |
tfarina | 9ea53f9 | 2014-06-24 06:50:39 -0700 | [diff] [blame] | 1095 | DEF_TEST(ImageFilterMatrix, reporter) { |
senorblanco@chromium.org | 5251e2b | 2014-02-05 22:36:31 +0000 | [diff] [blame] | 1096 | SkBitmap temp; |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 1097 | temp.allocN32Pixels(100, 100); |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 1098 | SkCanvas canvas(temp); |
senorblanco@chromium.org | 5251e2b | 2014-02-05 22:36:31 +0000 | [diff] [blame] | 1099 | canvas.scale(SkIntToScalar(2), SkIntToScalar(2)); |
| 1100 | |
| 1101 | SkMatrix expectedMatrix = canvas.getTotalMatrix(); |
| 1102 | |
commit-bot@chromium.org | 5fb2ce3 | 2014-04-17 23:35:06 +0000 | [diff] [blame] | 1103 | SkRTreeFactory factory; |
| 1104 | SkPictureRecorder recorder; |
| 1105 | SkCanvas* recordingCanvas = recorder.beginRecording(100, 100, &factory, 0); |
senorblanco@chromium.org | 5251e2b | 2014-02-05 22:36:31 +0000 | [diff] [blame] | 1106 | |
| 1107 | SkPaint paint; |
robertphillips | 43c2ad4 | 2016-04-04 05:05:11 -0700 | [diff] [blame] | 1108 | paint.setImageFilter(MatrixTestImageFilter::Make(reporter, expectedMatrix)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1109 | recordingCanvas->saveLayer(nullptr, &paint); |
senorblanco@chromium.org | 5251e2b | 2014-02-05 22:36:31 +0000 | [diff] [blame] | 1110 | SkPaint solidPaint; |
| 1111 | solidPaint.setColor(0xFFFFFFFF); |
| 1112 | recordingCanvas->save(); |
| 1113 | recordingCanvas->scale(SkIntToScalar(10), SkIntToScalar(10)); |
| 1114 | recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(100, 100)), solidPaint); |
| 1115 | recordingCanvas->restore(); // scale |
| 1116 | recordingCanvas->restore(); // saveLayer |
senorblanco@chromium.org | 5251e2b | 2014-02-05 22:36:31 +0000 | [diff] [blame] | 1117 | |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 1118 | canvas.drawPicture(recorder.finishRecordingAsPicture()); |
senorblanco@chromium.org | 5251e2b | 2014-02-05 22:36:31 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
senorblanco | 3d822c2 | 2014-07-30 14:49:31 -0700 | [diff] [blame] | 1121 | DEF_TEST(ImageFilterCrossProcessPictureImageFilter, reporter) { |
senorblanco@chromium.org | 97f5fc6 | 2014-05-30 20:50:56 +0000 | [diff] [blame] | 1122 | SkRTreeFactory factory; |
| 1123 | SkPictureRecorder recorder; |
| 1124 | SkCanvas* recordingCanvas = recorder.beginRecording(1, 1, &factory, 0); |
| 1125 | |
| 1126 | // Create an SkPicture which simply draws a green 1x1 rectangle. |
| 1127 | SkPaint greenPaint; |
| 1128 | greenPaint.setColor(SK_ColorGREEN); |
| 1129 | recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 1130 | sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
senorblanco@chromium.org | 97f5fc6 | 2014-05-30 20:50:56 +0000 | [diff] [blame] | 1131 | |
| 1132 | // Wrap that SkPicture in an SkPictureImageFilter. |
robertphillips | 5ff17b1 | 2016-03-28 13:13:42 -0700 | [diff] [blame] | 1133 | sk_sp<SkImageFilter> imageFilter(SkPictureImageFilter::Make(picture)); |
senorblanco@chromium.org | 97f5fc6 | 2014-05-30 20:50:56 +0000 | [diff] [blame] | 1134 | |
| 1135 | // Check that SkPictureImageFilter successfully serializes its contained |
| 1136 | // SkPicture when not in cross-process mode. |
| 1137 | SkPaint paint; |
robertphillips | 5ff17b1 | 2016-03-28 13:13:42 -0700 | [diff] [blame] | 1138 | paint.setImageFilter(imageFilter); |
senorblanco@chromium.org | 97f5fc6 | 2014-05-30 20:50:56 +0000 | [diff] [blame] | 1139 | SkPictureRecorder outerRecorder; |
| 1140 | SkCanvas* outerCanvas = outerRecorder.beginRecording(1, 1, &factory, 0); |
| 1141 | SkPaint redPaintWithFilter; |
| 1142 | redPaintWithFilter.setColor(SK_ColorRED); |
robertphillips | 5ff17b1 | 2016-03-28 13:13:42 -0700 | [diff] [blame] | 1143 | redPaintWithFilter.setImageFilter(imageFilter); |
senorblanco@chromium.org | 97f5fc6 | 2014-05-30 20:50:56 +0000 | [diff] [blame] | 1144 | outerCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), redPaintWithFilter); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 1145 | sk_sp<SkPicture> outerPicture(outerRecorder.finishRecordingAsPicture()); |
senorblanco@chromium.org | 97f5fc6 | 2014-05-30 20:50:56 +0000 | [diff] [blame] | 1146 | |
| 1147 | SkBitmap bitmap; |
| 1148 | bitmap.allocN32Pixels(1, 1); |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 1149 | SkCanvas canvas(bitmap); |
senorblanco@chromium.org | 97f5fc6 | 2014-05-30 20:50:56 +0000 | [diff] [blame] | 1150 | |
| 1151 | // The result here should be green, since the filter replaces the primitive's red interior. |
| 1152 | canvas.clear(0x0); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 1153 | canvas.drawPicture(outerPicture); |
senorblanco@chromium.org | 97f5fc6 | 2014-05-30 20:50:56 +0000 | [diff] [blame] | 1154 | uint32_t pixel = *bitmap.getAddr32(0, 0); |
| 1155 | REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 1156 | |
| 1157 | // Check that, for now, SkPictureImageFilter does not serialize or |
| 1158 | // deserialize its contained picture when the filter is serialized |
| 1159 | // cross-process. Do this by "laundering" it through SkValidatingReadBuffer. |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 1160 | sk_sp<SkData> data(SkValidatingSerializeFlattenable(imageFilter.get())); |
| 1161 | sk_sp<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable( |
mtklein | 3b37545 | 2016-04-04 14:57:19 -0700 | [diff] [blame] | 1162 | data->data(), data->size(), SkImageFilter::GetFlattenableType())); |
senorblanco@chromium.org | 97f5fc6 | 2014-05-30 20:50:56 +0000 | [diff] [blame] | 1163 | SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable.get()); |
| 1164 | |
| 1165 | redPaintWithFilter.setImageFilter(unflattenedFilter); |
| 1166 | SkPictureRecorder crossProcessRecorder; |
| 1167 | SkCanvas* crossProcessCanvas = crossProcessRecorder.beginRecording(1, 1, &factory, 0); |
| 1168 | crossProcessCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), redPaintWithFilter); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 1169 | sk_sp<SkPicture> crossProcessPicture(crossProcessRecorder.finishRecordingAsPicture()); |
senorblanco@chromium.org | 97f5fc6 | 2014-05-30 20:50:56 +0000 | [diff] [blame] | 1170 | |
| 1171 | canvas.clear(0x0); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 1172 | canvas.drawPicture(crossProcessPicture); |
senorblanco@chromium.org | 97f5fc6 | 2014-05-30 20:50:56 +0000 | [diff] [blame] | 1173 | pixel = *bitmap.getAddr32(0, 0); |
hendrikw | 446ee67 | 2015-06-16 09:28:37 -0700 | [diff] [blame] | 1174 | // If the security precautions are enabled, the result here should not be green, since the |
| 1175 | // filter draws nothing. |
mtklein | 2afbe23 | 2016-02-07 12:23:10 -0800 | [diff] [blame] | 1176 | REPORTER_ASSERT(reporter, SkPicture::PictureIOSecurityPrecautionsEnabled() |
hendrikw | 446ee67 | 2015-06-16 09:28:37 -0700 | [diff] [blame] | 1177 | ? pixel != SK_ColorGREEN : pixel == SK_ColorGREEN); |
senorblanco@chromium.org | 97f5fc6 | 2014-05-30 20:50:56 +0000 | [diff] [blame] | 1178 | } |
| 1179 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1180 | static void test_clipped_picture_imagefilter(skiatest::Reporter* reporter, GrContext* context) { |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 1181 | sk_sp<SkPicture> picture; |
senorblanco | 3d822c2 | 2014-07-30 14:49:31 -0700 | [diff] [blame] | 1182 | |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1183 | { |
| 1184 | SkRTreeFactory factory; |
| 1185 | SkPictureRecorder recorder; |
| 1186 | SkCanvas* recordingCanvas = recorder.beginRecording(1, 1, &factory, 0); |
| 1187 | |
| 1188 | // Create an SkPicture which simply draws a green 1x1 rectangle. |
| 1189 | SkPaint greenPaint; |
| 1190 | greenPaint.setColor(SK_ColorGREEN); |
| 1191 | recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 1192 | picture = recorder.finishRecordingAsPicture(); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1193 | } |
| 1194 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1195 | sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 2)); |
senorblanco | 3d822c2 | 2014-07-30 14:49:31 -0700 | [diff] [blame] | 1196 | |
robertphillips | 5ff17b1 | 2016-03-28 13:13:42 -0700 | [diff] [blame] | 1197 | sk_sp<SkImageFilter> imageFilter(SkPictureImageFilter::Make(picture)); |
senorblanco | 3d822c2 | 2014-07-30 14:49:31 -0700 | [diff] [blame] | 1198 | |
senorblanco | 3d822c2 | 2014-07-30 14:49:31 -0700 | [diff] [blame] | 1199 | SkIPoint offset; |
reed | 4e23cda | 2016-01-11 10:56:59 -0800 | [diff] [blame] | 1200 | SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nullptr); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1201 | |
robertphillips | 2302de9 | 2016-03-24 07:26:32 -0700 | [diff] [blame] | 1202 | sk_sp<SkSpecialImage> resultImage(imageFilter->filterImage(srcImg.get(), ctx, &offset)); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1203 | REPORTER_ASSERT(reporter, !resultImage); |
senorblanco | 3d822c2 | 2014-07-30 14:49:31 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1206 | DEF_TEST(ImageFilterClippedPictureImageFilter, reporter) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1207 | test_clipped_picture_imagefilter(reporter, nullptr); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | #if SK_SUPPORT_GPU |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 1211 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterClippedPictureImageFilter_Gpu, reporter, ctxInfo) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1212 | test_clipped_picture_imagefilter(reporter, ctxInfo.fGrContext); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1213 | } |
| 1214 | #endif |
| 1215 | |
tfarina | 9ea53f9 | 2014-06-24 06:50:39 -0700 | [diff] [blame] | 1216 | DEF_TEST(ImageFilterEmptySaveLayer, reporter) { |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 1217 | // Even when there's an empty saveLayer()/restore(), ensure that an image |
| 1218 | // filter or color filter which affects transparent black still draws. |
| 1219 | |
| 1220 | SkBitmap bitmap; |
| 1221 | bitmap.allocN32Pixels(10, 10); |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 1222 | SkCanvas canvas(bitmap); |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 1223 | |
| 1224 | SkRTreeFactory factory; |
| 1225 | SkPictureRecorder recorder; |
| 1226 | |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 1227 | sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, |
| 1228 | SkXfermode::kSrc_Mode)); |
| 1229 | sk_sp<SkImageFilter> imageFilter(SkColorFilterImageFilter::Make(green, nullptr)); |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 1230 | SkPaint imageFilterPaint; |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 1231 | imageFilterPaint.setImageFilter(std::move(imageFilter)); |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 1232 | SkPaint colorFilterPaint; |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 1233 | colorFilterPaint.setColorFilter(green); |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 1234 | |
| 1235 | SkRect bounds = SkRect::MakeWH(10, 10); |
| 1236 | |
| 1237 | SkCanvas* recordingCanvas = recorder.beginRecording(10, 10, &factory, 0); |
| 1238 | recordingCanvas->saveLayer(&bounds, &imageFilterPaint); |
| 1239 | recordingCanvas->restore(); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 1240 | sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 1241 | |
| 1242 | canvas.clear(0); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 1243 | canvas.drawPicture(picture); |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 1244 | uint32_t pixel = *bitmap.getAddr32(0, 0); |
| 1245 | REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 1246 | |
| 1247 | recordingCanvas = recorder.beginRecording(10, 10, &factory, 0); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1248 | recordingCanvas->saveLayer(nullptr, &imageFilterPaint); |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 1249 | recordingCanvas->restore(); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 1250 | sk_sp<SkPicture> picture2(recorder.finishRecordingAsPicture()); |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 1251 | |
| 1252 | canvas.clear(0); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 1253 | canvas.drawPicture(picture2); |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 1254 | pixel = *bitmap.getAddr32(0, 0); |
| 1255 | REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 1256 | |
| 1257 | recordingCanvas = recorder.beginRecording(10, 10, &factory, 0); |
| 1258 | recordingCanvas->saveLayer(&bounds, &colorFilterPaint); |
| 1259 | recordingCanvas->restore(); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 1260 | sk_sp<SkPicture> picture3(recorder.finishRecordingAsPicture()); |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 1261 | |
| 1262 | canvas.clear(0); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 1263 | canvas.drawPicture(picture3); |
senorblanco@chromium.org | 68250c8 | 2014-05-06 22:52:55 +0000 | [diff] [blame] | 1264 | pixel = *bitmap.getAddr32(0, 0); |
| 1265 | REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 1266 | } |
| 1267 | |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 1268 | static void test_huge_blur(SkCanvas* canvas, skiatest::Reporter* reporter) { |
senorblanco@chromium.org | 09843fd | 2014-03-24 20:50:59 +0000 | [diff] [blame] | 1269 | SkBitmap bitmap; |
| 1270 | bitmap.allocN32Pixels(100, 100); |
| 1271 | bitmap.eraseARGB(0, 0, 0, 0); |
| 1272 | |
| 1273 | // Check that a blur with an insane radius does not crash or assert. |
senorblanco@chromium.org | 09843fd | 2014-03-24 20:50:59 +0000 | [diff] [blame] | 1274 | SkPaint paint; |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 1275 | paint.setImageFilter(SkBlurImageFilter::Make(SkIntToScalar(1<<30), |
| 1276 | SkIntToScalar(1<<30), |
| 1277 | nullptr)); |
reed | da420b9 | 2015-12-16 08:38:15 -0800 | [diff] [blame] | 1278 | canvas->drawBitmap(bitmap, 0, 0, &paint); |
senorblanco@chromium.org | 09843fd | 2014-03-24 20:50:59 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | DEF_TEST(HugeBlurImageFilter, reporter) { |
| 1282 | SkBitmap temp; |
| 1283 | temp.allocN32Pixels(100, 100); |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 1284 | SkCanvas canvas(temp); |
| 1285 | test_huge_blur(&canvas, reporter); |
senorblanco@chromium.org | 09843fd | 2014-03-24 20:50:59 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
senorblanco | 21a465d | 2016-04-11 11:58:39 -0700 | [diff] [blame] | 1288 | DEF_TEST(ImageFilterMatrixConvolutionSanityTest, reporter) { |
senorblanco | 3a49520 | 2014-09-29 07:57:20 -0700 | [diff] [blame] | 1289 | SkScalar kernel[1] = { 0 }; |
| 1290 | SkScalar gain = SK_Scalar1, bias = 0; |
| 1291 | SkIPoint kernelOffset = SkIPoint::Make(1, 1); |
| 1292 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1293 | // Check that an enormous (non-allocatable) kernel gives a nullptr filter. |
robertphillips | ef6a47b | 2016-04-08 08:01:20 -0700 | [diff] [blame] | 1294 | sk_sp<SkImageFilter> conv(SkMatrixConvolutionImageFilter::Make( |
senorblanco | 3a49520 | 2014-09-29 07:57:20 -0700 | [diff] [blame] | 1295 | SkISize::Make(1<<30, 1<<30), |
| 1296 | kernel, |
| 1297 | gain, |
| 1298 | bias, |
| 1299 | kernelOffset, |
| 1300 | SkMatrixConvolutionImageFilter::kRepeat_TileMode, |
robertphillips | ef6a47b | 2016-04-08 08:01:20 -0700 | [diff] [blame] | 1301 | false, |
| 1302 | nullptr)); |
senorblanco | 3a49520 | 2014-09-29 07:57:20 -0700 | [diff] [blame] | 1303 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1304 | REPORTER_ASSERT(reporter, nullptr == conv.get()); |
senorblanco | 3a49520 | 2014-09-29 07:57:20 -0700 | [diff] [blame] | 1305 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1306 | // Check that a nullptr kernel gives a nullptr filter. |
robertphillips | ef6a47b | 2016-04-08 08:01:20 -0700 | [diff] [blame] | 1307 | conv = SkMatrixConvolutionImageFilter::Make( |
senorblanco | 3a49520 | 2014-09-29 07:57:20 -0700 | [diff] [blame] | 1308 | SkISize::Make(1, 1), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1309 | nullptr, |
senorblanco | 3a49520 | 2014-09-29 07:57:20 -0700 | [diff] [blame] | 1310 | gain, |
| 1311 | bias, |
| 1312 | kernelOffset, |
| 1313 | SkMatrixConvolutionImageFilter::kRepeat_TileMode, |
robertphillips | ef6a47b | 2016-04-08 08:01:20 -0700 | [diff] [blame] | 1314 | false, |
| 1315 | nullptr); |
senorblanco | 3a49520 | 2014-09-29 07:57:20 -0700 | [diff] [blame] | 1316 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1317 | REPORTER_ASSERT(reporter, nullptr == conv.get()); |
senorblanco | 3a49520 | 2014-09-29 07:57:20 -0700 | [diff] [blame] | 1318 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1319 | // Check that a kernel width < 1 gives a nullptr filter. |
robertphillips | ef6a47b | 2016-04-08 08:01:20 -0700 | [diff] [blame] | 1320 | conv = SkMatrixConvolutionImageFilter::Make( |
senorblanco | 3a49520 | 2014-09-29 07:57:20 -0700 | [diff] [blame] | 1321 | SkISize::Make(0, 1), |
| 1322 | kernel, |
| 1323 | gain, |
| 1324 | bias, |
| 1325 | kernelOffset, |
| 1326 | SkMatrixConvolutionImageFilter::kRepeat_TileMode, |
robertphillips | ef6a47b | 2016-04-08 08:01:20 -0700 | [diff] [blame] | 1327 | false, |
| 1328 | nullptr); |
senorblanco | 3a49520 | 2014-09-29 07:57:20 -0700 | [diff] [blame] | 1329 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1330 | REPORTER_ASSERT(reporter, nullptr == conv.get()); |
senorblanco | 3a49520 | 2014-09-29 07:57:20 -0700 | [diff] [blame] | 1331 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1332 | // Check that kernel height < 1 gives a nullptr filter. |
robertphillips | ef6a47b | 2016-04-08 08:01:20 -0700 | [diff] [blame] | 1333 | conv = SkMatrixConvolutionImageFilter::Make( |
senorblanco | 3a49520 | 2014-09-29 07:57:20 -0700 | [diff] [blame] | 1334 | SkISize::Make(1, -1), |
| 1335 | kernel, |
| 1336 | gain, |
| 1337 | bias, |
| 1338 | kernelOffset, |
| 1339 | SkMatrixConvolutionImageFilter::kRepeat_TileMode, |
robertphillips | ef6a47b | 2016-04-08 08:01:20 -0700 | [diff] [blame] | 1340 | false, |
| 1341 | nullptr); |
senorblanco | 3a49520 | 2014-09-29 07:57:20 -0700 | [diff] [blame] | 1342 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1343 | REPORTER_ASSERT(reporter, nullptr == conv.get()); |
senorblanco | 3a49520 | 2014-09-29 07:57:20 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 1346 | static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* reporter) { |
| 1347 | canvas->clear(0); |
senorblanco@chromium.org | ee845ae | 2014-04-01 19:15:23 +0000 | [diff] [blame] | 1348 | |
| 1349 | SkBitmap bitmap; |
| 1350 | bitmap.allocN32Pixels(1, 1); |
| 1351 | bitmap.eraseARGB(255, 255, 255, 255); |
| 1352 | |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 1353 | sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, |
| 1354 | SkXfermode::kSrcIn_Mode)); |
| 1355 | sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Make(green, nullptr)); |
senorblanco@chromium.org | ee845ae | 2014-04-01 19:15:23 +0000 | [diff] [blame] | 1356 | SkImageFilter::CropRect cropRect(SkRect::MakeEmpty()); |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 1357 | sk_sp<SkImageFilter> croppedOut(SkColorFilterImageFilter::Make(green, nullptr, &cropRect)); |
senorblanco@chromium.org | ee845ae | 2014-04-01 19:15:23 +0000 | [diff] [blame] | 1358 | |
| 1359 | // Check that an xfermode image filter whose input has been cropped out still draws the other |
| 1360 | // input. Also check that drawing with both inputs cropped out doesn't cause a GPU warning. |
robertphillips | 8c0326d | 2016-04-05 12:48:34 -0700 | [diff] [blame] | 1361 | sk_sp<SkXfermode> mode(SkXfermode::Make(SkXfermode::kSrcOver_Mode)); |
| 1362 | sk_sp<SkImageFilter> xfermodeNoFg(SkXfermodeImageFilter::Make(mode, greenFilter, |
| 1363 | croppedOut, nullptr)); |
| 1364 | sk_sp<SkImageFilter> xfermodeNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, |
| 1365 | greenFilter, nullptr)); |
| 1366 | sk_sp<SkImageFilter> xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, |
| 1367 | croppedOut, nullptr)); |
senorblanco@chromium.org | ee845ae | 2014-04-01 19:15:23 +0000 | [diff] [blame] | 1368 | |
| 1369 | SkPaint paint; |
robertphillips | 8c0326d | 2016-04-05 12:48:34 -0700 | [diff] [blame] | 1370 | paint.setImageFilter(std::move(xfermodeNoFg)); |
reed | da420b9 | 2015-12-16 08:38:15 -0800 | [diff] [blame] | 1371 | canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite |
senorblanco@chromium.org | ee845ae | 2014-04-01 19:15:23 +0000 | [diff] [blame] | 1372 | |
| 1373 | uint32_t pixel; |
kkinnunen | a9d9a39 | 2015-03-06 07:16:00 -0800 | [diff] [blame] | 1374 | SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul_SkAlphaType); |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 1375 | canvas->readPixels(info, &pixel, 4, 0, 0); |
senorblanco@chromium.org | ee845ae | 2014-04-01 19:15:23 +0000 | [diff] [blame] | 1376 | REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 1377 | |
robertphillips | 8c0326d | 2016-04-05 12:48:34 -0700 | [diff] [blame] | 1378 | paint.setImageFilter(std::move(xfermodeNoBg)); |
reed | da420b9 | 2015-12-16 08:38:15 -0800 | [diff] [blame] | 1379 | canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 1380 | canvas->readPixels(info, &pixel, 4, 0, 0); |
senorblanco@chromium.org | ee845ae | 2014-04-01 19:15:23 +0000 | [diff] [blame] | 1381 | REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 1382 | |
robertphillips | 8c0326d | 2016-04-05 12:48:34 -0700 | [diff] [blame] | 1383 | paint.setImageFilter(std::move(xfermodeNoFgNoBg)); |
reed | da420b9 | 2015-12-16 08:38:15 -0800 | [diff] [blame] | 1384 | canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 1385 | canvas->readPixels(info, &pixel, 4, 0, 0); |
senorblanco@chromium.org | ee845ae | 2014-04-01 19:15:23 +0000 | [diff] [blame] | 1386 | REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 1387 | } |
| 1388 | |
senorblanco@chromium.org | d5424a4 | 2014-04-02 19:20:05 +0000 | [diff] [blame] | 1389 | DEF_TEST(ImageFilterNestedSaveLayer, reporter) { |
| 1390 | SkBitmap temp; |
| 1391 | temp.allocN32Pixels(50, 50); |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 1392 | SkCanvas canvas(temp); |
senorblanco@chromium.org | d5424a4 | 2014-04-02 19:20:05 +0000 | [diff] [blame] | 1393 | canvas.clear(0x0); |
| 1394 | |
| 1395 | SkBitmap bitmap; |
| 1396 | bitmap.allocN32Pixels(10, 10); |
| 1397 | bitmap.eraseColor(SK_ColorGREEN); |
| 1398 | |
| 1399 | SkMatrix matrix; |
| 1400 | matrix.setScale(SkIntToScalar(2), SkIntToScalar(2)); |
| 1401 | matrix.postTranslate(SkIntToScalar(-20), SkIntToScalar(-20)); |
robertphillips | ae8c933 | 2016-04-05 15:09:00 -0700 | [diff] [blame] | 1402 | sk_sp<SkImageFilter> matrixFilter( |
| 1403 | SkImageFilter::MakeMatrixFilter(matrix, kLow_SkFilterQuality, nullptr)); |
senorblanco@chromium.org | d5424a4 | 2014-04-02 19:20:05 +0000 | [diff] [blame] | 1404 | |
| 1405 | // Test that saveLayer() with a filter nested inside another saveLayer() applies the |
| 1406 | // correct offset to the filter matrix. |
| 1407 | SkRect bounds1 = SkRect::MakeXYWH(10, 10, 30, 30); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1408 | canvas.saveLayer(&bounds1, nullptr); |
senorblanco@chromium.org | d5424a4 | 2014-04-02 19:20:05 +0000 | [diff] [blame] | 1409 | SkPaint filterPaint; |
robertphillips | ae8c933 | 2016-04-05 15:09:00 -0700 | [diff] [blame] | 1410 | filterPaint.setImageFilter(std::move(matrixFilter)); |
senorblanco@chromium.org | d5424a4 | 2014-04-02 19:20:05 +0000 | [diff] [blame] | 1411 | SkRect bounds2 = SkRect::MakeXYWH(20, 20, 10, 10); |
| 1412 | canvas.saveLayer(&bounds2, &filterPaint); |
| 1413 | SkPaint greenPaint; |
| 1414 | greenPaint.setColor(SK_ColorGREEN); |
| 1415 | canvas.drawRect(bounds2, greenPaint); |
| 1416 | canvas.restore(); |
| 1417 | canvas.restore(); |
| 1418 | SkPaint strokePaint; |
| 1419 | strokePaint.setStyle(SkPaint::kStroke_Style); |
| 1420 | strokePaint.setColor(SK_ColorRED); |
| 1421 | |
kkinnunen | a9d9a39 | 2015-03-06 07:16:00 -0800 | [diff] [blame] | 1422 | SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul_SkAlphaType); |
senorblanco@chromium.org | d5424a4 | 2014-04-02 19:20:05 +0000 | [diff] [blame] | 1423 | uint32_t pixel; |
| 1424 | canvas.readPixels(info, &pixel, 4, 25, 25); |
| 1425 | REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 1426 | |
| 1427 | // Test that drawSprite() with a filter nested inside a saveLayer() applies the |
| 1428 | // correct offset to the filter matrix. |
| 1429 | canvas.clear(0x0); |
| 1430 | canvas.readPixels(info, &pixel, 4, 25, 25); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1431 | canvas.saveLayer(&bounds1, nullptr); |
reed | da420b9 | 2015-12-16 08:38:15 -0800 | [diff] [blame] | 1432 | canvas.drawBitmap(bitmap, 20, 20, &filterPaint); // drawSprite |
senorblanco@chromium.org | d5424a4 | 2014-04-02 19:20:05 +0000 | [diff] [blame] | 1433 | canvas.restore(); |
| 1434 | |
| 1435 | canvas.readPixels(info, &pixel, 4, 25, 25); |
| 1436 | REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 1437 | } |
| 1438 | |
senorblanco@chromium.org | ee845ae | 2014-04-01 19:15:23 +0000 | [diff] [blame] | 1439 | DEF_TEST(XfermodeImageFilterCroppedInput, reporter) { |
| 1440 | SkBitmap temp; |
| 1441 | temp.allocN32Pixels(100, 100); |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 1442 | SkCanvas canvas(temp); |
| 1443 | test_xfermode_cropped_input(&canvas, reporter); |
senorblanco@chromium.org | ee845ae | 2014-04-01 19:15:23 +0000 | [diff] [blame] | 1444 | } |
senorblanco@chromium.org | 09843fd | 2014-03-24 20:50:59 +0000 | [diff] [blame] | 1445 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1446 | static void test_composed_imagefilter_offset(skiatest::Reporter* reporter, GrContext* context) { |
| 1447 | sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 100)); |
ajuma | 5788faa | 2015-02-13 09:05:47 -0800 | [diff] [blame] | 1448 | |
| 1449 | SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); |
robertphillips | 51a315e | 2016-03-31 09:05:49 -0700 | [diff] [blame] | 1450 | sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRect)); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 1451 | sk_sp<SkImageFilter> blurFilter(SkBlurImageFilter::Make(SK_Scalar1, SK_Scalar1, |
| 1452 | nullptr, &cropRect)); |
robertphillips | 491fb17 | 2016-03-30 12:32:58 -0700 | [diff] [blame] | 1453 | sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(blurFilter), |
| 1454 | std::move(offsetFilter))); |
ajuma | 5788faa | 2015-02-13 09:05:47 -0800 | [diff] [blame] | 1455 | SkIPoint offset; |
reed | 4e23cda | 2016-01-11 10:56:59 -0800 | [diff] [blame] | 1456 | SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1457 | |
robertphillips | 2302de9 | 2016-03-24 07:26:32 -0700 | [diff] [blame] | 1458 | sk_sp<SkSpecialImage> resultImg(composedFilter->filterImage(srcImg.get(), ctx, &offset)); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1459 | REPORTER_ASSERT(reporter, resultImg); |
ajuma | 5788faa | 2015-02-13 09:05:47 -0800 | [diff] [blame] | 1460 | REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); |
| 1461 | } |
| 1462 | |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1463 | DEF_TEST(ComposedImageFilterOffset, reporter) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1464 | test_composed_imagefilter_offset(reporter, nullptr); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | #if SK_SUPPORT_GPU |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 1468 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ComposedImageFilterOffset_Gpu, reporter, ctxInfo) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1469 | test_composed_imagefilter_offset(reporter, ctxInfo.fGrContext); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1470 | } |
| 1471 | #endif |
| 1472 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1473 | static void test_composed_imagefilter_bounds(skiatest::Reporter* reporter, GrContext* context) { |
jbroman | 17a6520 | 2016-03-21 08:38:58 -0700 | [diff] [blame] | 1474 | // The bounds passed to the inner filter must be filtered by the outer |
| 1475 | // filter, so that the inner filter produces the pixels that the outer |
| 1476 | // filter requires as input. This matters if the outer filter moves pixels. |
| 1477 | // Here, accounting for the outer offset is necessary so that the green |
| 1478 | // pixels of the picture are not clipped. |
| 1479 | |
| 1480 | SkPictureRecorder recorder; |
| 1481 | SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(200, 100)); |
| 1482 | recordingCanvas->clipRect(SkRect::MakeXYWH(100, 0, 100, 100)); |
| 1483 | recordingCanvas->clear(SK_ColorGREEN); |
robertphillips | 491fb17 | 2016-03-30 12:32:58 -0700 | [diff] [blame] | 1484 | sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
robertphillips | 5ff17b1 | 2016-03-28 13:13:42 -0700 | [diff] [blame] | 1485 | sk_sp<SkImageFilter> pictureFilter(SkPictureImageFilter::Make(picture)); |
jbroman | 17a6520 | 2016-03-21 08:38:58 -0700 | [diff] [blame] | 1486 | SkImageFilter::CropRect cropRect(SkRect::MakeWH(100, 100)); |
robertphillips | 51a315e | 2016-03-31 09:05:49 -0700 | [diff] [blame] | 1487 | sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(-100, 0, nullptr, &cropRect)); |
robertphillips | 491fb17 | 2016-03-30 12:32:58 -0700 | [diff] [blame] | 1488 | sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(offsetFilter), |
| 1489 | std::move(pictureFilter))); |
jbroman | 17a6520 | 2016-03-21 08:38:58 -0700 | [diff] [blame] | 1490 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1491 | sk_sp<SkSpecialImage> sourceImage(create_empty_special_image(context, 100)); |
jbroman | 17a6520 | 2016-03-21 08:38:58 -0700 | [diff] [blame] | 1492 | SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr); |
| 1493 | SkIPoint offset; |
| 1494 | sk_sp<SkSpecialImage> result(composedFilter->filterImage(sourceImage.get(), ctx, &offset)); |
| 1495 | REPORTER_ASSERT(reporter, offset.isZero()); |
| 1496 | REPORTER_ASSERT(reporter, result); |
| 1497 | REPORTER_ASSERT(reporter, result->subset().size() == SkISize::Make(100, 100)); |
| 1498 | |
| 1499 | SkBitmap resultBM; |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 1500 | REPORTER_ASSERT(reporter, result->getROPixels(&resultBM)); |
jbroman | 17a6520 | 2016-03-21 08:38:58 -0700 | [diff] [blame] | 1501 | SkAutoLockPixels lock(resultBM); |
| 1502 | REPORTER_ASSERT(reporter, resultBM.getColor(50, 50) == SK_ColorGREEN); |
| 1503 | } |
| 1504 | |
| 1505 | DEF_TEST(ComposedImageFilterBounds, reporter) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1506 | test_composed_imagefilter_bounds(reporter, nullptr); |
jbroman | 17a6520 | 2016-03-21 08:38:58 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | #if SK_SUPPORT_GPU |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 1510 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ComposedImageFilterBounds_Gpu, reporter, ctxInfo) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1511 | test_composed_imagefilter_bounds(reporter, ctxInfo.fGrContext); |
jbroman | 17a6520 | 2016-03-21 08:38:58 -0700 | [diff] [blame] | 1512 | } |
| 1513 | #endif |
| 1514 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1515 | static void test_partial_crop_rect(skiatest::Reporter* reporter, GrContext* context) { |
| 1516 | sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 100)); |
senorblanco | 24d2a7b | 2015-07-13 10:27:05 -0700 | [diff] [blame] | 1517 | |
| 1518 | SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), |
senorblanco | ed7cf27 | 2015-07-16 15:19:11 -0700 | [diff] [blame] | 1519 | SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::kHasHeight_CropEdge); |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 1520 | sk_sp<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); |
senorblanco | 24d2a7b | 2015-07-13 10:27:05 -0700 | [diff] [blame] | 1521 | SkIPoint offset; |
reed | 4e23cda | 2016-01-11 10:56:59 -0800 | [diff] [blame] | 1522 | SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1523 | |
robertphillips | 2302de9 | 2016-03-24 07:26:32 -0700 | [diff] [blame] | 1524 | sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offset)); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1525 | REPORTER_ASSERT(reporter, resultImg); |
| 1526 | |
senorblanco | 24d2a7b | 2015-07-13 10:27:05 -0700 | [diff] [blame] | 1527 | REPORTER_ASSERT(reporter, offset.fX == 0); |
| 1528 | REPORTER_ASSERT(reporter, offset.fY == 0); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1529 | REPORTER_ASSERT(reporter, resultImg->width() == 20); |
| 1530 | REPORTER_ASSERT(reporter, resultImg->height() == 30); |
senorblanco | 24d2a7b | 2015-07-13 10:27:05 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
senorblanco | 21a465d | 2016-04-11 11:58:39 -0700 | [diff] [blame] | 1533 | DEF_TEST(ImageFilterPartialCropRect, reporter) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1534 | test_partial_crop_rect(reporter, nullptr); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | #if SK_SUPPORT_GPU |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 1538 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterPartialCropRect_Gpu, reporter, ctxInfo) { |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1539 | test_partial_crop_rect(reporter, ctxInfo.fGrContext); |
robertphillips | 4418dba | 2016-03-07 12:45:14 -0800 | [diff] [blame] | 1540 | } |
| 1541 | #endif |
| 1542 | |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 1543 | DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { |
| 1544 | |
robertphillips | 12fa47d | 2016-04-08 16:28:09 -0700 | [diff] [blame] | 1545 | { |
| 1546 | SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); |
| 1547 | sk_sp<SkImageFilter> lighting(SkLightingImageFilter::MakePointLitDiffuse(location, |
| 1548 | SK_ColorGREEN, |
| 1549 | 0, 0, nullptr)); |
| 1550 | REPORTER_ASSERT(reporter, !lighting->canComputeFastBounds()); |
| 1551 | } |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 1552 | |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 1553 | { |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 1554 | sk_sp<SkImageFilter> gray(make_grayscale(nullptr, nullptr)); |
| 1555 | REPORTER_ASSERT(reporter, gray->canComputeFastBounds()); |
| 1556 | { |
| 1557 | SkColorFilter* grayCF; |
| 1558 | REPORTER_ASSERT(reporter, gray->asAColorFilter(&grayCF)); |
| 1559 | REPORTER_ASSERT(reporter, !grayCF->affectsTransparentBlack()); |
| 1560 | grayCF->unref(); |
| 1561 | } |
| 1562 | REPORTER_ASSERT(reporter, gray->canComputeFastBounds()); |
| 1563 | |
| 1564 | sk_sp<SkImageFilter> grayBlur(SkBlurImageFilter::Make(SK_Scalar1, SK_Scalar1, |
| 1565 | std::move(gray))); |
| 1566 | REPORTER_ASSERT(reporter, grayBlur->canComputeFastBounds()); |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 1567 | } |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 1568 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 1569 | { |
| 1570 | SkScalar greenMatrix[20] = { 0, 0, 0, 0, 0, |
| 1571 | 0, 0, 0, 0, 1, |
| 1572 | 0, 0, 0, 0, 0, |
| 1573 | 0, 0, 0, 0, 1 }; |
| 1574 | sk_sp<SkColorFilter> greenCF(SkColorFilter::MakeMatrixFilterRowMajor255(greenMatrix)); |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 1575 | sk_sp<SkImageFilter> green(SkColorFilterImageFilter::Make(greenCF, nullptr)); |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 1576 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 1577 | REPORTER_ASSERT(reporter, greenCF->affectsTransparentBlack()); |
| 1578 | REPORTER_ASSERT(reporter, !green->canComputeFastBounds()); |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 1579 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 1580 | sk_sp<SkImageFilter> greenBlur(SkBlurImageFilter::Make(SK_Scalar1, SK_Scalar1, |
| 1581 | std::move(green))); |
| 1582 | REPORTER_ASSERT(reporter, !greenBlur->canComputeFastBounds()); |
| 1583 | } |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 1584 | |
| 1585 | uint8_t allOne[256], identity[256]; |
| 1586 | for (int i = 0; i < 256; ++i) { |
| 1587 | identity[i] = i; |
| 1588 | allOne[i] = 255; |
| 1589 | } |
| 1590 | |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 1591 | sk_sp<SkColorFilter> identityCF(SkTableColorFilter::MakeARGB(identity, identity, |
| 1592 | identity, allOne)); |
| 1593 | sk_sp<SkImageFilter> identityFilter(SkColorFilterImageFilter::Make(identityCF, nullptr)); |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 1594 | REPORTER_ASSERT(reporter, !identityCF->affectsTransparentBlack()); |
| 1595 | REPORTER_ASSERT(reporter, identityFilter->canComputeFastBounds()); |
| 1596 | |
robertphillips | 5605b56 | 2016-04-05 11:50:42 -0700 | [diff] [blame] | 1597 | sk_sp<SkColorFilter> forceOpaqueCF(SkTableColorFilter::MakeARGB(allOne, identity, |
| 1598 | identity, identity)); |
| 1599 | sk_sp<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Make(forceOpaqueCF, nullptr)); |
senorblanco | 0abdf76 | 2015-08-20 11:10:41 -0700 | [diff] [blame] | 1600 | REPORTER_ASSERT(reporter, forceOpaqueCF->affectsTransparentBlack()); |
| 1601 | REPORTER_ASSERT(reporter, !forceOpaque->canComputeFastBounds()); |
| 1602 | } |
| 1603 | |
fmalita | cd56f81 | 2015-09-14 13:31:18 -0700 | [diff] [blame] | 1604 | // Verify that SkImageSource survives serialization |
| 1605 | DEF_TEST(ImageFilterImageSourceSerialization, reporter) { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1606 | auto surface(SkSurface::MakeRasterN32Premul(10, 10)); |
fmalita | cd56f81 | 2015-09-14 13:31:18 -0700 | [diff] [blame] | 1607 | surface->getCanvas()->clear(SK_ColorGREEN); |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 1608 | sk_sp<SkImage> image(surface->makeImageSnapshot()); |
robertphillips | 549c899 | 2016-04-01 09:28:51 -0700 | [diff] [blame] | 1609 | sk_sp<SkImageFilter> filter(SkImageSource::Make(std::move(image))); |
fmalita | cd56f81 | 2015-09-14 13:31:18 -0700 | [diff] [blame] | 1610 | |
robertphillips | 549c899 | 2016-04-01 09:28:51 -0700 | [diff] [blame] | 1611 | sk_sp<SkData> data(SkValidatingSerializeFlattenable(filter.get())); |
| 1612 | sk_sp<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable( |
mtklein | 3b37545 | 2016-04-04 14:57:19 -0700 | [diff] [blame] | 1613 | data->data(), data->size(), SkImageFilter::GetFlattenableType())); |
fmalita | cd56f81 | 2015-09-14 13:31:18 -0700 | [diff] [blame] | 1614 | SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable.get()); |
| 1615 | REPORTER_ASSERT(reporter, unflattenedFilter); |
| 1616 | |
| 1617 | SkBitmap bm; |
| 1618 | bm.allocN32Pixels(10, 10); |
fmalita | 23cb88c | 2015-09-15 06:56:23 -0700 | [diff] [blame] | 1619 | bm.eraseColor(SK_ColorBLUE); |
fmalita | cd56f81 | 2015-09-14 13:31:18 -0700 | [diff] [blame] | 1620 | SkPaint paint; |
| 1621 | paint.setColor(SK_ColorRED); |
| 1622 | paint.setImageFilter(unflattenedFilter); |
| 1623 | |
| 1624 | SkCanvas canvas(bm); |
| 1625 | canvas.drawRect(SkRect::MakeWH(10, 10), paint); |
| 1626 | REPORTER_ASSERT(reporter, *bm.getAddr32(0, 0) == SkPreMultiplyColor(SK_ColorGREEN)); |
| 1627 | } |
| 1628 | |
bsalomon | 45eefcf | 2016-01-05 08:39:28 -0800 | [diff] [blame] | 1629 | static void test_large_blur_input(skiatest::Reporter* reporter, SkCanvas* canvas) { |
| 1630 | SkBitmap largeBmp; |
| 1631 | int largeW = 5000; |
| 1632 | int largeH = 5000; |
| 1633 | #if SK_SUPPORT_GPU |
| 1634 | // If we're GPU-backed make the bitmap too large to be converted into a texture. |
| 1635 | if (GrContext* ctx = canvas->getGrContext()) { |
| 1636 | largeW = ctx->caps()->maxTextureSize() + 1; |
| 1637 | } |
| 1638 | #endif |
| 1639 | |
| 1640 | largeBmp.allocN32Pixels(largeW, largeH); |
mtklein | 2afbe23 | 2016-02-07 12:23:10 -0800 | [diff] [blame] | 1641 | largeBmp.eraseColor(0); |
bsalomon | 45eefcf | 2016-01-05 08:39:28 -0800 | [diff] [blame] | 1642 | if (!largeBmp.getPixels()) { |
| 1643 | ERRORF(reporter, "Failed to allocate large bmp."); |
| 1644 | return; |
| 1645 | } |
| 1646 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 1647 | sk_sp<SkImage> largeImage(SkImage::MakeFromBitmap(largeBmp)); |
bsalomon | 45eefcf | 2016-01-05 08:39:28 -0800 | [diff] [blame] | 1648 | if (!largeImage) { |
| 1649 | ERRORF(reporter, "Failed to create large image."); |
| 1650 | return; |
| 1651 | } |
| 1652 | |
robertphillips | 549c899 | 2016-04-01 09:28:51 -0700 | [diff] [blame] | 1653 | sk_sp<SkImageFilter> largeSource(SkImageSource::Make(std::move(largeImage))); |
bsalomon | 45eefcf | 2016-01-05 08:39:28 -0800 | [diff] [blame] | 1654 | if (!largeSource) { |
| 1655 | ERRORF(reporter, "Failed to create large SkImageSource."); |
| 1656 | return; |
| 1657 | } |
| 1658 | |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 1659 | sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(10.f, 10.f, std::move(largeSource))); |
bsalomon | 45eefcf | 2016-01-05 08:39:28 -0800 | [diff] [blame] | 1660 | if (!blur) { |
| 1661 | ERRORF(reporter, "Failed to create SkBlurImageFilter."); |
| 1662 | return; |
| 1663 | } |
| 1664 | |
| 1665 | SkPaint paint; |
robertphillips | 549c899 | 2016-04-01 09:28:51 -0700 | [diff] [blame] | 1666 | paint.setImageFilter(std::move(blur)); |
bsalomon | 45eefcf | 2016-01-05 08:39:28 -0800 | [diff] [blame] | 1667 | |
| 1668 | // This should not crash (http://crbug.com/570479). |
| 1669 | canvas->drawRect(SkRect::MakeIWH(largeW, largeH), paint); |
| 1670 | } |
| 1671 | |
senorblanco | 21a465d | 2016-04-11 11:58:39 -0700 | [diff] [blame] | 1672 | DEF_TEST(ImageFilterBlurLargeImage, reporter) { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1673 | auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100))); |
bsalomon | 45eefcf | 2016-01-05 08:39:28 -0800 | [diff] [blame] | 1674 | test_large_blur_input(reporter, surface->getCanvas()); |
| 1675 | } |
| 1676 | |
senorblanco@chromium.org | 58d1466 | 2014-02-03 22:36:39 +0000 | [diff] [blame] | 1677 | #if SK_SUPPORT_GPU |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 1678 | |
bsalomon | 68d9134 | 2016-04-12 09:59:58 -0700 | [diff] [blame] | 1679 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterHugeBlur_Gpu, reporter, ctxInfo) { |
robertphillips | efbffed | 2015-06-22 12:06:08 -0700 | [diff] [blame] | 1680 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1681 | sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, |
| 1682 | SkBudgeted::kNo, |
| 1683 | SkImageInfo::MakeN32Premul(100, 100))); |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 1684 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1685 | |
| 1686 | SkCanvas* canvas = surf->getCanvas(); |
| 1687 | |
| 1688 | test_huge_blur(canvas, reporter); |
senorblanco@chromium.org | 09843fd | 2014-03-24 20:50:59 +0000 | [diff] [blame] | 1689 | } |
senorblanco@chromium.org | ee845ae | 2014-04-01 19:15:23 +0000 | [diff] [blame] | 1690 | |
bsalomon | 758586c | 2016-04-06 14:02:39 -0700 | [diff] [blame] | 1691 | DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(XfermodeImageFilterCroppedInput_Gpu, reporter, ctxInfo) { |
robertphillips | efbffed | 2015-06-22 12:06:08 -0700 | [diff] [blame] | 1692 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1693 | sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, |
| 1694 | SkBudgeted::kNo, |
| 1695 | SkImageInfo::MakeN32Premul(1, 1))); |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 1696 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame^] | 1697 | |
| 1698 | SkCanvas* canvas = surf->getCanvas(); |
| 1699 | |
| 1700 | test_xfermode_cropped_input(canvas, reporter); |
senorblanco@chromium.org | ee845ae | 2014-04-01 19:15:23 +0000 | [diff] [blame] | 1701 | } |
senorblanco | 32673b9 | 2014-09-09 09:15:04 -0700 | [diff] [blame] | 1702 | |
senorblanco | 21a465d | 2016-04-11 11:58:39 -0700 | [diff] [blame] | 1703 | DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(ImageFilterBlurLargeImage_Gpu, reporter, ctxInfo) { |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 1704 | auto surface(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted::kYes, |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1705 | SkImageInfo::MakeN32Premul(100, 100))); |
bsalomon | 45eefcf | 2016-01-05 08:39:28 -0800 | [diff] [blame] | 1706 | test_large_blur_input(reporter, surface->getCanvas()); |
| 1707 | } |
senorblanco@chromium.org | 58d1466 | 2014-02-03 22:36:39 +0000 | [diff] [blame] | 1708 | #endif |