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