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