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