epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | */ |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 7 | |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 8 | #include "SkBlurMask.h" |
reed@google.com | 2b75f42 | 2011-07-07 13:43:38 +0000 | [diff] [blame] | 9 | #include "SkBlurMaskFilter.h" |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 10 | #include "SkBlurDrawLooper.h" |
reed | fb8c1fc | 2015-08-04 18:44:56 -0700 | [diff] [blame] | 11 | #include "SkCanvas.h" |
mtklein | 7a1f45f | 2016-08-04 06:19:33 -0700 | [diff] [blame] | 12 | #include "SkColorFilter.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 13 | #include "SkEmbossMaskFilter.h" |
| 14 | #include "SkLayerDrawLooper.h" |
tomhudson@google.com | 889bd8b | 2011-09-27 17:38:17 +0000 | [diff] [blame] | 15 | #include "SkMath.h" |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 16 | #include "SkPaint.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 17 | #include "SkPath.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 18 | #include "Test.h" |
tfarina@chromium.org | 4ee16bf | 2014-01-10 22:08:27 +0000 | [diff] [blame] | 19 | |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 20 | #if SK_SUPPORT_GPU |
| 21 | #include "GrContextFactory.h" |
| 22 | #include "SkGpuDevice.h" |
| 23 | #endif |
| 24 | |
| 25 | #define WRITE_CSV 0 |
reed@google.com | 2b75f42 | 2011-07-07 13:43:38 +0000 | [diff] [blame] | 26 | |
| 27 | /////////////////////////////////////////////////////////////////////////////// |
| 28 | |
| 29 | #define ILLEGAL_MODE ((SkXfermode::Mode)-1) |
| 30 | |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 31 | static const int outset = 100; |
| 32 | static const SkColor bgColor = SK_ColorWHITE; |
| 33 | static const int strokeWidth = 4; |
| 34 | |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 35 | static void create(SkBitmap* bm, const SkIRect& bound) { |
| 36 | bm->allocN32Pixels(bound.width(), bound.height()); |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static void drawBG(SkCanvas* canvas) { |
| 40 | canvas->drawColor(bgColor); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | struct BlurTest { |
| 45 | void (*addPath)(SkPath*); |
| 46 | int viewLen; |
| 47 | SkIRect views[9]; |
| 48 | }; |
| 49 | |
| 50 | //Path Draw Procs |
| 51 | //Beware that paths themselves my draw differently depending on the clip. |
| 52 | static void draw50x50Rect(SkPath* path) { |
| 53 | path->addRect(0, 0, SkIntToScalar(50), SkIntToScalar(50)); |
| 54 | } |
| 55 | |
| 56 | //Tests |
| 57 | static BlurTest tests[] = { |
| 58 | { draw50x50Rect, 3, { |
| 59 | //inner half of blur |
| 60 | { 0, 0, 50, 50 }, |
| 61 | //blur, but no path. |
| 62 | { 50 + strokeWidth/2, 50 + strokeWidth/2, 100, 100 }, |
| 63 | //just an edge |
| 64 | { 40, strokeWidth, 60, 50 - strokeWidth }, |
| 65 | }}, |
| 66 | }; |
| 67 | |
| 68 | /** Assumes that the ref draw was completely inside ref canvas -- |
| 69 | implies that everything outside is "bgColor". |
| 70 | Checks that all overlap is the same and that all non-overlap on the |
| 71 | ref is "bgColor". |
| 72 | */ |
| 73 | static bool compare(const SkBitmap& ref, const SkIRect& iref, |
| 74 | const SkBitmap& test, const SkIRect& itest) |
| 75 | { |
| 76 | const int xOff = itest.fLeft - iref.fLeft; |
| 77 | const int yOff = itest.fTop - iref.fTop; |
| 78 | |
| 79 | SkAutoLockPixels alpRef(ref); |
| 80 | SkAutoLockPixels alpTest(test); |
| 81 | |
| 82 | for (int y = 0; y < test.height(); ++y) { |
| 83 | for (int x = 0; x < test.width(); ++x) { |
| 84 | SkColor testColor = test.getColor(x, y); |
| 85 | int refX = x + xOff; |
| 86 | int refY = y + yOff; |
| 87 | SkColor refColor; |
| 88 | if (refX >= 0 && refX < ref.width() && |
| 89 | refY >= 0 && refY < ref.height()) |
| 90 | { |
| 91 | refColor = ref.getColor(refX, refY); |
| 92 | } else { |
| 93 | refColor = bgColor; |
| 94 | } |
| 95 | if (refColor != testColor) { |
| 96 | return false; |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | return true; |
| 101 | } |
| 102 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 103 | DEF_TEST(BlurDrawing, reporter) { |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 104 | SkPaint paint; |
| 105 | paint.setColor(SK_ColorGRAY); |
| 106 | paint.setStyle(SkPaint::kStroke_Style); |
| 107 | paint.setStrokeWidth(SkIntToScalar(strokeWidth)); |
reed@google.com | 2b75f42 | 2011-07-07 13:43:38 +0000 | [diff] [blame] | 108 | |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 109 | SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)); |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 110 | for (int style = 0; style <= kLastEnum_SkBlurStyle; ++style) { |
| 111 | SkBlurStyle blurStyle = static_cast<SkBlurStyle>(style); |
reed@google.com | 2b75f42 | 2011-07-07 13:43:38 +0000 | [diff] [blame] | 112 | |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 113 | const uint32_t flagPermutations = SkBlurMaskFilter::kAll_BlurFlag; |
| 114 | for (uint32_t flags = 0; flags < flagPermutations; ++flags) { |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 115 | paint.setMaskFilter(SkBlurMaskFilter::Make(blurStyle, sigma, flags)); |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 116 | |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 117 | for (size_t test = 0; test < SK_ARRAY_COUNT(tests); ++test) { |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 118 | SkPath path; |
| 119 | tests[test].addPath(&path); |
bungeman@google.com | d16872c | 2011-09-02 15:46:17 +0000 | [diff] [blame] | 120 | SkPath strokedPath; |
| 121 | paint.getFillPath(path, &strokedPath); |
| 122 | SkRect refBound = strokedPath.getBounds(); |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 123 | SkIRect iref; |
| 124 | refBound.roundOut(&iref); |
bungeman@google.com | d16872c | 2011-09-02 15:46:17 +0000 | [diff] [blame] | 125 | iref.inset(-outset, -outset); |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 126 | SkBitmap refBitmap; |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 127 | create(&refBitmap, iref); |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 128 | |
| 129 | SkCanvas refCanvas(refBitmap); |
| 130 | refCanvas.translate(SkIntToScalar(-iref.fLeft), |
| 131 | SkIntToScalar(-iref.fTop)); |
| 132 | drawBG(&refCanvas); |
| 133 | refCanvas.drawPath(path, paint); |
| 134 | |
| 135 | for (int view = 0; view < tests[test].viewLen; ++view) { |
| 136 | SkIRect itest = tests[test].views[view]; |
| 137 | SkBitmap testBitmap; |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 138 | create(&testBitmap, itest); |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 139 | |
| 140 | SkCanvas testCanvas(testBitmap); |
| 141 | testCanvas.translate(SkIntToScalar(-itest.fLeft), |
| 142 | SkIntToScalar(-itest.fTop)); |
| 143 | drawBG(&testCanvas); |
| 144 | testCanvas.drawPath(path, paint); |
| 145 | |
| 146 | REPORTER_ASSERT(reporter, |
| 147 | compare(refBitmap, iref, testBitmap, itest)); |
| 148 | } |
| 149 | } |
| 150 | } |
reed@google.com | 2b75f42 | 2011-07-07 13:43:38 +0000 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 154 | /////////////////////////////////////////////////////////////////////////////// |
| 155 | |
| 156 | // Use SkBlurMask::BlurGroundTruth to blur a 'width' x 'height' solid |
| 157 | // white rect. Return the right half of the middle row in 'result'. |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 158 | static void ground_truth_2d(int width, int height, |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 159 | SkScalar sigma, |
| 160 | int* result, int resultCount) { |
| 161 | SkMask src, dst; |
| 162 | |
| 163 | src.fBounds.set(0, 0, width, height); |
| 164 | src.fFormat = SkMask::kA8_Format; |
| 165 | src.fRowBytes = src.fBounds.width(); |
| 166 | src.fImage = SkMask::AllocImage(src.computeTotalImageSize()); |
| 167 | |
| 168 | memset(src.fImage, 0xff, src.computeTotalImageSize()); |
| 169 | |
robertphillips | e80eb92 | 2015-12-17 11:33:12 -0800 | [diff] [blame] | 170 | if (!SkBlurMask::BlurGroundTruth(sigma, &dst, src, kNormal_SkBlurStyle)) { |
| 171 | return; |
| 172 | } |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 173 | |
| 174 | int midX = dst.fBounds.centerX(); |
| 175 | int midY = dst.fBounds.centerY(); |
| 176 | uint8_t* bytes = dst.getAddr8(midX, midY); |
| 177 | int i; |
| 178 | for (i = 0; i < dst.fBounds.width()-(midX-dst.fBounds.fLeft); ++i) { |
| 179 | if (i < resultCount) { |
| 180 | result[i] = bytes[i]; |
| 181 | } |
| 182 | } |
| 183 | for ( ; i < resultCount; ++i) { |
| 184 | result[i] = 0; |
| 185 | } |
robertphillips@google.com | 6d837aa | 2013-10-11 14:38:46 +0000 | [diff] [blame] | 186 | |
| 187 | SkMask::FreeImage(src.fImage); |
| 188 | SkMask::FreeImage(dst.fImage); |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | // Implement a step function that is 255 between min and max; 0 elsewhere. |
| 192 | static int step(int x, SkScalar min, SkScalar max) { |
| 193 | if (min < x && x < max) { |
| 194 | return 255; |
| 195 | } |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | // Implement a Gaussian function with 0 mean and std.dev. of 'sigma'. |
| 200 | static float gaussian(int x, SkScalar sigma) { |
robertphillips@google.com | b85564a | 2013-09-05 17:53:34 +0000 | [diff] [blame] | 201 | float k = SK_Scalar1/(sigma * sqrtf(2.0f*SK_ScalarPI)); |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 202 | float exponent = -(x * x) / (2 * sigma * sigma); |
robertphillips@google.com | b85564a | 2013-09-05 17:53:34 +0000 | [diff] [blame] | 203 | return k * expf(exponent); |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | // Perform a brute force convolution of a step function with a Gaussian. |
| 207 | // Return the right half in 'result' |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 208 | static void brute_force_1d(SkScalar stepMin, SkScalar stepMax, |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 209 | SkScalar gaussianSigma, |
| 210 | int* result, int resultCount) { |
| 211 | |
| 212 | int gaussianRange = SkScalarCeilToInt(10 * gaussianSigma); |
| 213 | |
| 214 | for (int i = 0; i < resultCount; ++i) { |
| 215 | SkScalar sum = 0.0f; |
| 216 | for (int j = -gaussianRange; j < gaussianRange; ++j) { |
| 217 | sum += gaussian(j, gaussianSigma) * step(i-j, stepMin, stepMax); |
| 218 | } |
| 219 | |
| 220 | result[i] = SkClampMax(SkClampPos(int(sum + 0.5f)), 255); |
| 221 | } |
| 222 | } |
| 223 | |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 224 | static void blur_path(SkCanvas* canvas, const SkPath& path, |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 225 | SkScalar gaussianSigma) { |
| 226 | |
| 227 | SkScalar midX = path.getBounds().centerX(); |
| 228 | SkScalar midY = path.getBounds().centerY(); |
| 229 | |
| 230 | canvas->translate(-midX, -midY); |
| 231 | |
| 232 | SkPaint blurPaint; |
| 233 | blurPaint.setColor(SK_ColorWHITE); |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 234 | blurPaint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, gaussianSigma, |
| 235 | SkBlurMaskFilter::kHighQuality_BlurFlag)); |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 236 | |
| 237 | canvas->drawColor(SK_ColorBLACK); |
| 238 | canvas->drawPath(path, blurPaint); |
| 239 | } |
| 240 | |
| 241 | // Readback the blurred draw results from the canvas |
| 242 | static void readback(SkCanvas* canvas, int* result, int resultCount) { |
| 243 | SkBitmap readback; |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 244 | readback.allocN32Pixels(resultCount, 30); |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 245 | |
| 246 | SkIRect readBackRect = { 0, 0, resultCount, 30 }; |
| 247 | |
| 248 | canvas->readPixels(readBackRect, &readback); |
| 249 | |
| 250 | readback.lockPixels(); |
| 251 | SkPMColor* pixels = (SkPMColor*) readback.getAddr32(0, 15); |
| 252 | |
| 253 | for (int i = 0; i < resultCount; ++i) { |
| 254 | result[i] = SkColorGetR(pixels[i]); |
| 255 | } |
| 256 | } |
| 257 | |
skia.committer@gmail.com | 6fc1b49 | 2013-09-06 07:01:45 +0000 | [diff] [blame] | 258 | // Draw a blurred version of the provided path. |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 259 | // Return the right half of the middle row in 'result'. |
| 260 | static void cpu_blur_path(const SkPath& path, SkScalar gaussianSigma, |
| 261 | int* result, int resultCount) { |
| 262 | |
| 263 | SkBitmap bitmap; |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 264 | bitmap.allocN32Pixels(resultCount, 30); |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 265 | SkCanvas canvas(bitmap); |
| 266 | |
| 267 | blur_path(&canvas, path, gaussianSigma); |
| 268 | readback(&canvas, result, resultCount); |
| 269 | } |
| 270 | |
| 271 | #if SK_SUPPORT_GPU |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 272 | #if 0 |
| 273 | // temporary disable; see below for explanation |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 274 | static bool gpu_blur_path(GrContext* context, const SkPath& path, |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 275 | SkScalar gaussianSigma, |
| 276 | int* result, int resultCount) { |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 277 | GrSurfaceDesc desc; |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 278 | desc.fConfig = kSkia8888_GrPixelConfig; |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 279 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 280 | desc.fWidth = resultCount; |
| 281 | desc.fHeight = 30; |
| 282 | desc.fSampleCnt = 0; |
| 283 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 284 | SkAutoTUnref<GrTexture> texture(grContext->createTexture(desc, false, nullptr, 0)); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 285 | SkAutoTUnref<SkGpuDevice> device(new SkGpuDevice (grContext, texture.get())); |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 286 | SkCanvas canvas(device.get()); |
| 287 | |
| 288 | blur_path(&canvas, path, gaussianSigma); |
| 289 | readback(&canvas, result, resultCount); |
robertphillips@google.com | cb3b615 | 2013-11-14 14:47:56 +0000 | [diff] [blame] | 290 | return true; |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 291 | } |
| 292 | #endif |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 293 | #endif |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 294 | |
| 295 | #if WRITE_CSV |
| 296 | static void write_as_csv(const char* label, SkScalar scale, int* data, int count) { |
| 297 | SkDebugf("%s_%.2f,", label, scale); |
| 298 | for (int i = 0; i < count-1; ++i) { |
| 299 | SkDebugf("%d,", data[i]); |
| 300 | } |
| 301 | SkDebugf("%d\n", data[count-1]); |
| 302 | } |
| 303 | #endif |
| 304 | |
| 305 | static bool match(int* first, int* second, int count, int tol) { |
| 306 | int delta; |
| 307 | for (int i = 0; i < count; ++i) { |
| 308 | delta = first[i] - second[i]; |
| 309 | if (delta > tol || delta < -tol) { |
| 310 | return false; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | return true; |
| 315 | } |
| 316 | |
| 317 | // Test out the normal blur style with a wide range of sigmas |
bsalomon | f2f1c17 | 2016-04-05 12:59:06 -0700 | [diff] [blame] | 318 | DEF_TEST(BlurSigmaRange, reporter) { |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 319 | static const int kSize = 100; |
| 320 | |
| 321 | // The geometry is offset a smidge to trigger: |
| 322 | // https://code.google.com/p/chromium/issues/detail?id=282418 |
| 323 | SkPath rectPath; |
| 324 | rectPath.addRect(0.3f, 0.3f, 100.3f, 100.3f); |
| 325 | |
| 326 | SkPoint polyPts[] = { |
| 327 | { 0.3f, 0.3f }, |
| 328 | { 100.3f, 0.3f }, |
| 329 | { 100.3f, 100.3f }, |
| 330 | { 0.3f, 100.3f }, |
| 331 | { 2.3f, 50.3f } // a little divet to throw off the rect special case |
| 332 | }; |
| 333 | SkPath polyPath; |
| 334 | polyPath.addPoly(polyPts, SK_ARRAY_COUNT(polyPts), true); |
| 335 | |
| 336 | int rectSpecialCaseResult[kSize]; |
| 337 | int generalCaseResult[kSize]; |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 338 | int groundTruthResult[kSize]; |
| 339 | int bruteForce1DResult[kSize]; |
| 340 | |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 341 | SkScalar sigma = 10.0f; |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 342 | |
| 343 | for (int i = 0; i < 4; ++i, sigma /= 10) { |
| 344 | |
| 345 | cpu_blur_path(rectPath, sigma, rectSpecialCaseResult, kSize); |
| 346 | cpu_blur_path(polyPath, sigma, generalCaseResult, kSize); |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 347 | |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 348 | ground_truth_2d(100, 100, sigma, groundTruthResult, kSize); |
| 349 | brute_force_1d(-50.0f, 50.0f, sigma, bruteForce1DResult, kSize); |
| 350 | |
| 351 | REPORTER_ASSERT(reporter, match(rectSpecialCaseResult, bruteForce1DResult, kSize, 5)); |
| 352 | REPORTER_ASSERT(reporter, match(generalCaseResult, bruteForce1DResult, kSize, 15)); |
| 353 | #if SK_SUPPORT_GPU |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 354 | #if 0 |
| 355 | int gpuResult[kSize]; |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 356 | bool haveGPUResult = gpu_blur_path(context, rectPath, sigma, gpuResult, kSize); |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 357 | // Disabling this test for now -- I don't think it's a legit comparison. |
| 358 | // Will continue to investigate this. |
robertphillips@google.com | cb3b615 | 2013-11-14 14:47:56 +0000 | [diff] [blame] | 359 | if (haveGPUResult) { |
| 360 | // 1 works everywhere but: Ubuntu13 & Nexus4 |
| 361 | REPORTER_ASSERT(reporter, match(gpuResult, bruteForce1DResult, kSize, 10)); |
| 362 | } |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 363 | #endif |
humper | 4a24cd8 | 2014-06-17 13:39:29 -0700 | [diff] [blame] | 364 | #endif |
robertphillips@google.com | 3dfa4cc | 2013-09-05 16:39:03 +0000 | [diff] [blame] | 365 | REPORTER_ASSERT(reporter, match(groundTruthResult, bruteForce1DResult, kSize, 1)); |
| 366 | |
| 367 | #if WRITE_CSV |
| 368 | write_as_csv("RectSpecialCase", sigma, rectSpecialCaseResult, kSize); |
| 369 | write_as_csv("GeneralCase", sigma, generalCaseResult, kSize); |
| 370 | #if SK_SUPPORT_GPU |
| 371 | write_as_csv("GPU", sigma, gpuResult, kSize); |
| 372 | #endif |
| 373 | write_as_csv("GroundTruth2D", sigma, groundTruthResult, kSize); |
| 374 | write_as_csv("BruteForce1D", sigma, bruteForce1DResult, kSize); |
| 375 | #endif |
| 376 | } |
| 377 | } |
| 378 | |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 379 | /////////////////////////////////////////////////////////////////////////////////////////// |
| 380 | |
| 381 | static SkBlurQuality blurMaskFilterFlags_as_quality(uint32_t blurMaskFilterFlags) { |
| 382 | return (blurMaskFilterFlags & SkBlurMaskFilter::kHighQuality_BlurFlag) ? |
| 383 | kHigh_SkBlurQuality : kLow_SkBlurQuality; |
| 384 | } |
| 385 | |
| 386 | static uint32_t blurMaskFilterFlags_to_blurDrawLooperFlags(uint32_t bmf) { |
| 387 | const struct { |
| 388 | uint32_t fBlurMaskFilterFlag; |
| 389 | uint32_t fBlurDrawLooperFlag; |
| 390 | } pairs[] = { |
| 391 | { SkBlurMaskFilter::kIgnoreTransform_BlurFlag, SkBlurDrawLooper::kIgnoreTransform_BlurFlag }, |
| 392 | { SkBlurMaskFilter::kHighQuality_BlurFlag, SkBlurDrawLooper::kHighQuality_BlurFlag }, |
| 393 | }; |
| 394 | |
| 395 | uint32_t bdl = 0; |
| 396 | for (size_t i = 0; i < SK_ARRAY_COUNT(pairs); ++i) { |
| 397 | if (bmf & pairs[i].fBlurMaskFilterFlag) { |
| 398 | bdl |= pairs[i].fBlurDrawLooperFlag; |
| 399 | } |
| 400 | } |
| 401 | return bdl; |
| 402 | } |
| 403 | |
| 404 | static void test_blurDrawLooper(skiatest::Reporter* reporter, SkScalar sigma, |
| 405 | SkBlurStyle style, uint32_t blurMaskFilterFlags) { |
| 406 | if (kNormal_SkBlurStyle != style) { |
| 407 | return; // blurdrawlooper only supports normal |
| 408 | } |
| 409 | |
| 410 | const SkColor color = 0xFF335577; |
| 411 | const SkScalar dx = 10; |
| 412 | const SkScalar dy = -5; |
| 413 | const SkBlurQuality quality = blurMaskFilterFlags_as_quality(blurMaskFilterFlags); |
| 414 | uint32_t flags = blurMaskFilterFlags_to_blurDrawLooperFlags(blurMaskFilterFlags); |
| 415 | |
reed | 7b380d0 | 2016-03-21 13:25:16 -0700 | [diff] [blame] | 416 | sk_sp<SkDrawLooper> lp(SkBlurDrawLooper::Make(color, sigma, dx, dy, flags)); |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 417 | |
| 418 | const bool expectSuccess = sigma > 0 && |
| 419 | 0 == (flags & SkBlurDrawLooper::kIgnoreTransform_BlurFlag); |
| 420 | |
reed | 7b380d0 | 2016-03-21 13:25:16 -0700 | [diff] [blame] | 421 | if (nullptr == lp) { |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 422 | REPORTER_ASSERT(reporter, sigma <= 0); |
| 423 | } else { |
| 424 | SkDrawLooper::BlurShadowRec rec; |
| 425 | bool success = lp->asABlurShadow(&rec); |
| 426 | REPORTER_ASSERT(reporter, success == expectSuccess); |
| 427 | if (success) { |
| 428 | REPORTER_ASSERT(reporter, rec.fSigma == sigma); |
| 429 | REPORTER_ASSERT(reporter, rec.fOffset.x() == dx); |
| 430 | REPORTER_ASSERT(reporter, rec.fOffset.y() == dy); |
| 431 | REPORTER_ASSERT(reporter, rec.fColor == color); |
| 432 | REPORTER_ASSERT(reporter, rec.fStyle == style); |
| 433 | REPORTER_ASSERT(reporter, rec.fQuality == quality); |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | |
reed | 7b380d0 | 2016-03-21 13:25:16 -0700 | [diff] [blame] | 438 | static void test_looper(skiatest::Reporter* reporter, sk_sp<SkDrawLooper> lp, SkScalar sigma, |
| 439 | SkBlurStyle style, SkBlurQuality quality, bool expectSuccess) { |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 440 | SkDrawLooper::BlurShadowRec rec; |
| 441 | bool success = lp->asABlurShadow(&rec); |
| 442 | REPORTER_ASSERT(reporter, success == expectSuccess); |
| 443 | if (success != expectSuccess) { |
| 444 | lp->asABlurShadow(&rec); |
| 445 | } |
| 446 | if (success) { |
| 447 | REPORTER_ASSERT(reporter, rec.fSigma == sigma); |
| 448 | REPORTER_ASSERT(reporter, rec.fStyle == style); |
| 449 | REPORTER_ASSERT(reporter, rec.fQuality == quality); |
| 450 | } |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | static void make_noop_layer(SkLayerDrawLooper::Builder* builder) { |
| 454 | SkLayerDrawLooper::LayerInfo info; |
| 455 | |
| 456 | info.fPaintBits = 0; |
| 457 | info.fColorMode = SkXfermode::kDst_Mode; |
| 458 | builder->addLayer(info); |
| 459 | } |
| 460 | |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 461 | static void make_blur_layer(SkLayerDrawLooper::Builder* builder, sk_sp<SkMaskFilter> mf) { |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 462 | SkLayerDrawLooper::LayerInfo info; |
| 463 | |
| 464 | info.fPaintBits = SkLayerDrawLooper::kMaskFilter_Bit; |
| 465 | info.fColorMode = SkXfermode::kSrc_Mode; |
| 466 | SkPaint* paint = builder->addLayer(info); |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 467 | paint->setMaskFilter(std::move(mf)); |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 468 | } |
| 469 | |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 470 | static void test_layerDrawLooper(skiatest::Reporter* reporter, sk_sp<SkMaskFilter> mf, |
| 471 | SkScalar sigma, SkBlurStyle style, SkBlurQuality quality, |
| 472 | bool expectSuccess) { |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 473 | |
| 474 | SkLayerDrawLooper::LayerInfo info; |
| 475 | SkLayerDrawLooper::Builder builder; |
| 476 | |
| 477 | // 1 layer is too few |
| 478 | make_noop_layer(&builder); |
reed | 7b380d0 | 2016-03-21 13:25:16 -0700 | [diff] [blame] | 479 | test_looper(reporter, builder.detach(), sigma, style, quality, false); |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 480 | |
| 481 | // 2 layers is good, but need blur |
| 482 | make_noop_layer(&builder); |
| 483 | make_noop_layer(&builder); |
reed | 7b380d0 | 2016-03-21 13:25:16 -0700 | [diff] [blame] | 484 | test_looper(reporter, builder.detach(), sigma, style, quality, false); |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 485 | |
| 486 | // 2 layers is just right |
| 487 | make_noop_layer(&builder); |
| 488 | make_blur_layer(&builder, mf); |
reed | 7b380d0 | 2016-03-21 13:25:16 -0700 | [diff] [blame] | 489 | test_looper(reporter, builder.detach(), sigma, style, quality, expectSuccess); |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 490 | |
| 491 | // 3 layers is too many |
| 492 | make_noop_layer(&builder); |
| 493 | make_blur_layer(&builder, mf); |
| 494 | make_noop_layer(&builder); |
reed | 7b380d0 | 2016-03-21 13:25:16 -0700 | [diff] [blame] | 495 | test_looper(reporter, builder.detach(), sigma, style, quality, false); |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 496 | } |
| 497 | |
kkinnunen | 1530283 | 2015-12-01 04:35:26 -0800 | [diff] [blame] | 498 | DEF_TEST(BlurAsABlur, reporter) { |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 499 | const SkBlurStyle styles[] = { |
| 500 | kNormal_SkBlurStyle, kSolid_SkBlurStyle, kOuter_SkBlurStyle, kInner_SkBlurStyle |
| 501 | }; |
| 502 | const SkScalar sigmas[] = { |
| 503 | // values <= 0 should not success for a blur |
| 504 | -1, 0, 0.5f, 2 |
| 505 | }; |
| 506 | |
| 507 | // Test asABlur for SkBlurMaskFilter |
| 508 | // |
| 509 | for (size_t i = 0; i < SK_ARRAY_COUNT(styles); ++i) { |
| 510 | const SkBlurStyle style = (SkBlurStyle)styles[i]; |
| 511 | for (size_t j = 0; j < SK_ARRAY_COUNT(sigmas); ++j) { |
| 512 | const SkScalar sigma = sigmas[j]; |
| 513 | for (int flags = 0; flags <= SkBlurMaskFilter::kAll_BlurFlag; ++flags) { |
| 514 | const SkBlurQuality quality = blurMaskFilterFlags_as_quality(flags); |
| 515 | |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 516 | sk_sp<SkMaskFilter> mf(SkBlurMaskFilter::Make(style, sigma, flags)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 517 | if (nullptr == mf.get()) { |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 518 | REPORTER_ASSERT(reporter, sigma <= 0); |
| 519 | } else { |
| 520 | REPORTER_ASSERT(reporter, sigma > 0); |
| 521 | SkMaskFilter::BlurRec rec; |
| 522 | bool success = mf->asABlur(&rec); |
| 523 | if (flags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag) { |
| 524 | REPORTER_ASSERT(reporter, !success); |
| 525 | } else { |
| 526 | REPORTER_ASSERT(reporter, success); |
| 527 | REPORTER_ASSERT(reporter, rec.fSigma == sigma); |
| 528 | REPORTER_ASSERT(reporter, rec.fStyle == style); |
| 529 | REPORTER_ASSERT(reporter, rec.fQuality == quality); |
| 530 | } |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 531 | test_layerDrawLooper(reporter, std::move(mf), sigma, style, quality, success); |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 532 | } |
| 533 | test_blurDrawLooper(reporter, sigma, style, flags); |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | // Test asABlur for SkEmbossMaskFilter -- should never succeed |
| 539 | // |
| 540 | { |
| 541 | SkEmbossMaskFilter::Light light = { |
| 542 | { 1, 1, 1 }, 0, 127, 127 |
| 543 | }; |
| 544 | for (size_t j = 0; j < SK_ARRAY_COUNT(sigmas); ++j) { |
| 545 | const SkScalar sigma = sigmas[j]; |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 546 | auto mf(SkEmbossMaskFilter::Make(sigma, light)); |
| 547 | if (mf) { |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 548 | SkMaskFilter::BlurRec rec; |
| 549 | bool success = mf->asABlur(&rec); |
| 550 | REPORTER_ASSERT(reporter, !success); |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | |
robertphillips | 4abb0c1 | 2016-01-04 11:20:25 -0800 | [diff] [blame] | 556 | #if SK_SUPPORT_GPU |
| 557 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 558 | // This exercises the problem discovered in crbug.com/570232. The return value from |
robertphillips | 4abb0c1 | 2016-01-04 11:20:25 -0800 | [diff] [blame] | 559 | // SkBlurMask::BoxBlur wasn't being checked in SkBlurMaskFilter.cpp::GrRRectBlurEffect::Create |
egdaniel | ab527a5 | 2016-06-28 08:07:26 -0700 | [diff] [blame] | 560 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SmallBoxBlurBug, reporter, ctxInfo) { |
robertphillips | 4abb0c1 | 2016-01-04 11:20:25 -0800 | [diff] [blame] | 561 | |
| 562 | SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128); |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 563 | auto surface(SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo, info)); |
robertphillips | 4abb0c1 | 2016-01-04 11:20:25 -0800 | [diff] [blame] | 564 | SkCanvas* canvas = surface->getCanvas(); |
| 565 | |
| 566 | SkRect r = SkRect::MakeXYWH(10, 10, 100, 100); |
| 567 | SkRRect rr = SkRRect::MakeRectXY(r, 10, 10); |
| 568 | |
| 569 | SkPaint p; |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 570 | p.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 0.01f)); |
robertphillips | 4abb0c1 | 2016-01-04 11:20:25 -0800 | [diff] [blame] | 571 | |
| 572 | canvas->drawRRect(rr, p); |
| 573 | } |
| 574 | |
| 575 | #endif |
| 576 | |
robertphillips | f5a83e8 | 2016-08-10 12:00:09 -0700 | [diff] [blame] | 577 | |
| 578 | DEF_TEST(BlurredRRectNinePatchComputation, reporter) { |
| 579 | const SkRect r = SkRect::MakeXYWH(10, 10, 100, 100); |
robertphillips | c4d2f90 | 2016-08-16 09:30:03 -0700 | [diff] [blame] | 580 | static const SkScalar kBlurRad = 3.0f; |
robertphillips | f5a83e8 | 2016-08-10 12:00:09 -0700 | [diff] [blame] | 581 | |
| 582 | bool ninePatchable; |
| 583 | SkRRect rrectToDraw; |
| 584 | SkISize size; |
robertphillips | c4d2f90 | 2016-08-16 09:30:03 -0700 | [diff] [blame] | 585 | SkScalar rectXs[SkBlurMaskFilter::kMaxDivisions], rectYs[SkBlurMaskFilter::kMaxDivisions]; |
| 586 | SkScalar texXs[SkBlurMaskFilter::kMaxDivisions], texYs[SkBlurMaskFilter::kMaxDivisions]; |
| 587 | int numX, numY; |
| 588 | uint32_t skipMask; |
robertphillips | f5a83e8 | 2016-08-10 12:00:09 -0700 | [diff] [blame] | 589 | |
| 590 | // not nine-patchable |
| 591 | { |
| 592 | SkVector radii[4] = { { 100, 100 }, { 0, 0 }, { 100, 100 }, { 0, 0 } }; |
| 593 | |
| 594 | SkRRect rr; |
| 595 | rr.setRectRadii(r, radii); |
| 596 | |
robertphillips | c4d2f90 | 2016-08-16 09:30:03 -0700 | [diff] [blame] | 597 | ninePatchable = SkBlurMaskFilter::ComputeBlurredRRectParams(rr, rr, SkRect::MakeEmpty(), |
| 598 | kBlurRad, kBlurRad, |
| 599 | &rrectToDraw, &size, |
| 600 | rectXs, rectYs, texXs, texYs, |
| 601 | &numX, &numY, &skipMask); |
robertphillips | f5a83e8 | 2016-08-10 12:00:09 -0700 | [diff] [blame] | 602 | REPORTER_ASSERT(reporter, !ninePatchable); |
| 603 | } |
| 604 | |
| 605 | // simple circular |
| 606 | { |
robertphillips | c4d2f90 | 2016-08-16 09:30:03 -0700 | [diff] [blame] | 607 | static const SkScalar kCornerRad = 10.0f; |
robertphillips | f5a83e8 | 2016-08-10 12:00:09 -0700 | [diff] [blame] | 608 | SkRRect rr; |
robertphillips | c4d2f90 | 2016-08-16 09:30:03 -0700 | [diff] [blame] | 609 | rr.setRectXY(r, kCornerRad, kCornerRad); |
robertphillips | f5a83e8 | 2016-08-10 12:00:09 -0700 | [diff] [blame] | 610 | |
robertphillips | c4d2f90 | 2016-08-16 09:30:03 -0700 | [diff] [blame] | 611 | ninePatchable = SkBlurMaskFilter::ComputeBlurredRRectParams(rr, rr, SkRect::MakeEmpty(), |
| 612 | kBlurRad, kBlurRad, |
| 613 | &rrectToDraw, &size, |
| 614 | rectXs, rectYs, texXs, texYs, |
| 615 | &numX, &numY, &skipMask); |
| 616 | |
| 617 | static const SkScalar kAns = 12.0f * kBlurRad + 2.0f * kCornerRad + 1.0f; |
robertphillips | f5a83e8 | 2016-08-10 12:00:09 -0700 | [diff] [blame] | 618 | REPORTER_ASSERT(reporter, ninePatchable); |
robertphillips | c4d2f90 | 2016-08-16 09:30:03 -0700 | [diff] [blame] | 619 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fWidth), kAns)); |
| 620 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fHeight), kAns)); |
| 621 | REPORTER_ASSERT(reporter, 4 == numX && 4 == numY); |
| 622 | REPORTER_ASSERT(reporter, !skipMask); |
robertphillips | f5a83e8 | 2016-08-10 12:00:09 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | // simple elliptical |
| 626 | { |
robertphillips | c4d2f90 | 2016-08-16 09:30:03 -0700 | [diff] [blame] | 627 | static const SkScalar kXCornerRad = 2.0f; |
| 628 | static const SkScalar kYCornerRad = 10.0f; |
robertphillips | f5a83e8 | 2016-08-10 12:00:09 -0700 | [diff] [blame] | 629 | SkRRect rr; |
robertphillips | c4d2f90 | 2016-08-16 09:30:03 -0700 | [diff] [blame] | 630 | rr.setRectXY(r, kXCornerRad, kYCornerRad); |
robertphillips | f5a83e8 | 2016-08-10 12:00:09 -0700 | [diff] [blame] | 631 | |
robertphillips | c4d2f90 | 2016-08-16 09:30:03 -0700 | [diff] [blame] | 632 | ninePatchable = SkBlurMaskFilter::ComputeBlurredRRectParams(rr, rr, SkRect::MakeEmpty(), |
| 633 | kBlurRad, kBlurRad, |
| 634 | &rrectToDraw, &size, |
| 635 | rectXs, rectYs, texXs, texYs, |
| 636 | &numX, &numY, &skipMask); |
| 637 | |
| 638 | static const SkScalar kXAns = 12.0f * kBlurRad + 2.0f * kXCornerRad + 1.0f; |
| 639 | static const SkScalar kYAns = 12.0f * kBlurRad + 2.0f * kYCornerRad + 1.0f; |
| 640 | |
robertphillips | f5a83e8 | 2016-08-10 12:00:09 -0700 | [diff] [blame] | 641 | REPORTER_ASSERT(reporter, ninePatchable); |
robertphillips | c4d2f90 | 2016-08-16 09:30:03 -0700 | [diff] [blame] | 642 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fWidth), kXAns)); |
| 643 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fHeight), kYAns)); |
| 644 | REPORTER_ASSERT(reporter, 4 == numX && 4 == numY); |
| 645 | REPORTER_ASSERT(reporter, !skipMask); |
| 646 | } |
| 647 | |
| 648 | // test-out occlusion |
| 649 | { |
| 650 | static const SkScalar kCornerRad = 10.0f; |
| 651 | SkRRect rr; |
| 652 | rr.setRectXY(r, kCornerRad, kCornerRad); |
| 653 | |
| 654 | // The rectXs & rectYs should be { 1, 29, 91, 119 }. Add two more points around each. |
| 655 | SkScalar testLocs[] = { |
| 656 | -18.0f, -9.0f, |
| 657 | 1.0f, |
| 658 | 9.0f, 18.0f, |
| 659 | 29.0f, |
| 660 | 39.0f, 49.0f, |
| 661 | 91.0f, |
| 662 | 109.0f, 118.0f, |
| 663 | 119.0f, |
| 664 | 139.0f, 149.0f |
| 665 | }; |
| 666 | |
| 667 | for (int minY = 0; minY < (int)SK_ARRAY_COUNT(testLocs); ++minY) { |
| 668 | for (int maxY = minY+1; maxY < (int)SK_ARRAY_COUNT(testLocs); ++maxY) { |
| 669 | for (int minX = 0; minX < (int)SK_ARRAY_COUNT(testLocs); ++minX) { |
| 670 | for (int maxX = minX+1; maxX < (int)SK_ARRAY_COUNT(testLocs); ++maxX) { |
| 671 | SkRect occluder = SkRect::MakeLTRB(testLocs[minX], testLocs[minY], |
| 672 | testLocs[maxX], testLocs[maxY]); |
| 673 | if (occluder.isEmpty()) { |
| 674 | continue; |
| 675 | } |
| 676 | |
| 677 | ninePatchable = SkBlurMaskFilter::ComputeBlurredRRectParams( |
| 678 | rr, rr, occluder, |
| 679 | kBlurRad, kBlurRad, |
| 680 | &rrectToDraw, &size, |
| 681 | rectXs, rectYs, texXs, texYs, |
| 682 | &numX, &numY, &skipMask); |
| 683 | |
| 684 | static const SkScalar kAns = 12.0f * kBlurRad + 2.0f * kCornerRad + 1.0f; |
| 685 | REPORTER_ASSERT(reporter, ninePatchable); |
| 686 | REPORTER_ASSERT(reporter, |
| 687 | SkScalarNearlyEqual(SkIntToScalar(size.fWidth), kAns)); |
| 688 | REPORTER_ASSERT(reporter, |
| 689 | SkScalarNearlyEqual(SkIntToScalar(size.fHeight), kAns)); |
| 690 | |
| 691 | int checkBit = 0x1; |
| 692 | for (int y = 0; y < numY-1; ++y) { |
| 693 | for (int x = 0; x < numX-1; ++x) { |
| 694 | SkRect cell = SkRect::MakeLTRB(rectXs[x], rectYs[y], |
| 695 | rectXs[x+1], rectYs[y+1]); |
| 696 | REPORTER_ASSERT(reporter, |
| 697 | SkToBool(skipMask & checkBit) == |
| 698 | (cell.isEmpty() || occluder.contains(cell))); |
| 699 | |
| 700 | REPORTER_ASSERT(reporter, texXs[x] >= 0 && |
| 701 | texXs[x] <= size.fWidth); |
| 702 | REPORTER_ASSERT(reporter, texYs[y] >= 0 && |
| 703 | texXs[y] <= size.fHeight); |
| 704 | |
| 705 | checkBit <<= 1; |
| 706 | } |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | } |
robertphillips | f5a83e8 | 2016-08-10 12:00:09 -0700 | [diff] [blame] | 711 | } |
robertphillips | c4d2f90 | 2016-08-16 09:30:03 -0700 | [diff] [blame] | 712 | |
| 713 | |
robertphillips | f5a83e8 | 2016-08-10 12:00:09 -0700 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | } |
| 717 | |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 718 | /////////////////////////////////////////////////////////////////////////////////////////// |