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