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