reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkBitmap.h" |
| 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkImageInfo.h" |
| 12 | #include "include/core/SkMatrix.h" |
| 13 | #include "include/core/SkPaint.h" |
| 14 | #include "include/core/SkPath.h" |
| 15 | #include "include/core/SkPathEffect.h" |
| 16 | #include "include/core/SkPoint.h" |
| 17 | #include "include/core/SkRRect.h" |
| 18 | #include "include/core/SkRect.h" |
| 19 | #include "include/core/SkRefCnt.h" |
| 20 | #include "include/core/SkScalar.h" |
| 21 | #include "include/core/SkStrokeRec.h" |
| 22 | #include "include/core/SkSurface.h" |
| 23 | #include "include/core/SkTypes.h" |
| 24 | #include "include/effects/SkDashPathEffect.h" |
| 25 | #include "tests/Test.h" |
reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 26 | |
reed@google.com | f272e35 | 2013-08-26 21:27:03 +0000 | [diff] [blame] | 27 | // test that we can draw an aa-rect at coordinates > 32K (bigger than fixedpoint) |
| 28 | static void test_big_aa_rect(skiatest::Reporter* reporter) { |
| 29 | SkBitmap output; |
| 30 | SkPMColor pixel[1]; |
commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 31 | output.installPixels(SkImageInfo::MakeN32Premul(1, 1), pixel, 4); |
reed@google.com | f272e35 | 2013-08-26 21:27:03 +0000 | [diff] [blame] | 32 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 33 | auto surf = SkSurface::MakeRasterN32Premul(300, 33300); |
reed@google.com | f272e35 | 2013-08-26 21:27:03 +0000 | [diff] [blame] | 34 | SkCanvas* canvas = surf->getCanvas(); |
| 35 | |
| 36 | SkRect r = { 0, 33000, 300, 33300 }; |
| 37 | int x = SkScalarRoundToInt(r.left()); |
| 38 | int y = SkScalarRoundToInt(r.top()); |
| 39 | |
| 40 | // check that the pixel in question starts as transparent (by the surface) |
Mike Reed | f194219 | 2017-07-21 14:24:29 -0400 | [diff] [blame] | 41 | if (surf->readPixels(output, x, y)) { |
reed@google.com | f272e35 | 2013-08-26 21:27:03 +0000 | [diff] [blame] | 42 | REPORTER_ASSERT(reporter, 0 == pixel[0]); |
| 43 | } else { |
Brian Salomon | 1c80e99 | 2018-01-29 09:50:47 -0500 | [diff] [blame] | 44 | REPORTER_ASSERT(reporter, false, "readPixels failed"); |
reed@google.com | f272e35 | 2013-08-26 21:27:03 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | SkPaint paint; |
| 48 | paint.setAntiAlias(true); |
| 49 | paint.setColor(SK_ColorWHITE); |
| 50 | |
| 51 | canvas->drawRect(r, paint); |
| 52 | |
| 53 | // Now check that it is BLACK |
Mike Reed | f194219 | 2017-07-21 14:24:29 -0400 | [diff] [blame] | 54 | if (surf->readPixels(output, x, y)) { |
reed@google.com | f272e35 | 2013-08-26 21:27:03 +0000 | [diff] [blame] | 55 | // don't know what swizzling PMColor did, but white should always |
| 56 | // appear the same. |
| 57 | REPORTER_ASSERT(reporter, 0xFFFFFFFF == pixel[0]); |
| 58 | } else { |
Brian Salomon | 1c80e99 | 2018-01-29 09:50:47 -0500 | [diff] [blame] | 59 | REPORTER_ASSERT(reporter, false, "readPixels failed"); |
reed@google.com | f272e35 | 2013-08-26 21:27:03 +0000 | [diff] [blame] | 60 | } |
reed@google.com | f272e35 | 2013-08-26 21:27:03 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /////////////////////////////////////////////////////////////////////////////// |
| 64 | |
reed@google.com | b59ed51 | 2012-06-15 18:26:04 +0000 | [diff] [blame] | 65 | static void moveToH(SkPath* path, const uint32_t raw[]) { |
| 66 | const float* fptr = (const float*)raw; |
| 67 | path->moveTo(fptr[0], fptr[1]); |
| 68 | } |
| 69 | |
| 70 | static void cubicToH(SkPath* path, const uint32_t raw[]) { |
| 71 | const float* fptr = (const float*)raw; |
| 72 | path->cubicTo(fptr[0], fptr[1], fptr[2], fptr[3], fptr[4], fptr[5]); |
| 73 | } |
| 74 | |
| 75 | // This used to assert, because we performed a cast (int)(pt[0].fX * scale) to |
| 76 | // arrive at an int (SkFDot6) rather than calling sk_float_round2int. The assert |
| 77 | // was that the initial line-segment produced by the cubic was not monotonically |
| 78 | // going down (i.e. the initial DY was negative). By rounding the floats, we get |
| 79 | // the more proper result. |
| 80 | // |
| 81 | // http://code.google.com/p/chromium/issues/detail?id=131181 |
| 82 | // |
humper@google.com | 05af1af | 2013-01-07 16:47:43 +0000 | [diff] [blame] | 83 | |
| 84 | // we're not calling this test anymore; is that for a reason? |
| 85 | |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 86 | static void test_crbug131181() { |
reed@google.com | b59ed51 | 2012-06-15 18:26:04 +0000 | [diff] [blame] | 87 | /* |
| 88 | fX = 18.8943768, |
| 89 | fY = 129.121277 |
| 90 | }, { |
| 91 | fX = 18.8937435, |
| 92 | fY = 129.121689 |
| 93 | }, { |
| 94 | fX = 18.8950119, |
| 95 | fY = 129.120422 |
| 96 | }, { |
| 97 | fX = 18.5030727, |
| 98 | fY = 129.13121 |
| 99 | */ |
| 100 | uint32_t data[] = { |
| 101 | 0x419727af, 0x43011f0c, 0x41972663, 0x43011f27, |
| 102 | 0x419728fc, 0x43011ed4, 0x4194064b, 0x43012197 |
| 103 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 104 | |
reed@google.com | b59ed51 | 2012-06-15 18:26:04 +0000 | [diff] [blame] | 105 | SkPath path; |
| 106 | moveToH(&path, &data[0]); |
| 107 | cubicToH(&path, &data[2]); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 108 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 109 | auto surface(SkSurface::MakeRasterN32Premul(640, 480)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 110 | |
reed@google.com | b59ed51 | 2012-06-15 18:26:04 +0000 | [diff] [blame] | 111 | SkPaint paint; |
| 112 | paint.setAntiAlias(true); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 113 | surface->getCanvas()->drawPath(path, paint); |
reed@google.com | b59ed51 | 2012-06-15 18:26:04 +0000 | [diff] [blame] | 114 | } |
| 115 | |
reed@google.com | e2faf17 | 2012-08-06 19:01:34 +0000 | [diff] [blame] | 116 | // This used to assert in debug builds (and crash writing bad memory in release) |
| 117 | // because we overflowed an intermediate value (B coefficient) setting up our |
| 118 | // stepper for the quadratic. Now we bias that value by 1/2 so we don't overflow |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 119 | static void test_crbug_140803() { |
reed@google.com | e2faf17 | 2012-08-06 19:01:34 +0000 | [diff] [blame] | 120 | SkBitmap bm; |
commit-bot@chromium.org | fa9e5fa | 2014-02-13 22:00:04 +0000 | [diff] [blame] | 121 | bm.allocN32Pixels(2700, 30*1024); |
reed@google.com | e2faf17 | 2012-08-06 19:01:34 +0000 | [diff] [blame] | 122 | SkCanvas canvas(bm); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 123 | |
reed@google.com | e2faf17 | 2012-08-06 19:01:34 +0000 | [diff] [blame] | 124 | SkPaint paint; |
| 125 | paint.setAntiAlias(true); |
Mike Reed | b631742 | 2018-08-15 10:23:39 -0400 | [diff] [blame] | 126 | canvas.drawPath(SkPath().moveTo(2762, 20).quadTo(11, 21702, 10, 21706), paint); |
reed@google.com | e2faf17 | 2012-08-06 19:01:34 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Michael Ludwig | c7ffd5e | 2021-09-09 20:21:59 -0400 | [diff] [blame] | 129 | static void test_crbug_1239558(skiatest::Reporter* reporter) { |
| 130 | SkBitmap bm; |
| 131 | bm.allocN32Pixels(256, 256); |
| 132 | |
| 133 | SkCanvas canvas(bm); |
| 134 | canvas.clear(SK_ColorWHITE); |
| 135 | |
| 136 | // This creates a single cubic where the control points form an extremely skinny, vertical |
| 137 | // triangle contained within the x=0 column of pixels. Since it is convex (ignoring the leading |
| 138 | // moveTo's) it uses the convex aaa optimized edge walking algorithm after clipping the path to |
| 139 | // the device bounds. However, due to fixed-point math while walking these edges, the edge |
| 140 | // walking evaluates to coords that are very slightly less than 0 (i.e. 0.0012). Both the left |
| 141 | // and right edges would be out of bounds, but the edge walking is optimized to only clamp the |
| 142 | // left edge to the left bounds, and the right edge to the right bounds. After this clamping, |
| 143 | // the left and right edges are no longer sorted. This then led to incorrect behavior in various |
| 144 | // forms (described below). |
| 145 | SkPath path; |
| 146 | path.setFillType(SkPathFillType::kWinding); |
| 147 | path.moveTo(7.00649e-45f, 2.f); |
| 148 | path.moveTo(0.0160219f, 7.45063e-09f); |
| 149 | path.moveTo(192.263f, 8.40779e-44f); |
| 150 | path.moveTo(7.34684e-40f, 194.25f); |
| 151 | path.moveTo(2.3449e-38f, 6.01858e-36f); |
| 152 | path.moveTo(7.34684e-40f, 194.25f); |
| 153 | path.cubicTo(5.07266e-39f, 56.0488f, |
| 154 | 0.0119172f, 0.f, |
| 155 | 7.34684e-40f, 194.25f); |
| 156 | |
| 157 | SkPaint paint; |
| 158 | paint.setColor(SK_ColorRED); |
| 159 | paint.setAntiAlias(true); |
| 160 | // On debug builds, the inverted left/right edges led to a negative coverage that triggered an |
| 161 | // assert while converting to a uint8 alpha value. On release builds with UBSAN, it would |
| 162 | // detect a negative left shift when computing the pixel address and crash. On regular release |
| 163 | // builds it would write a saturate coverage value to pixels that wrapped around to the far edge |
| 164 | canvas.drawPath(path, paint); |
| 165 | |
| 166 | // UBSAN and debug builds would fail inside the drawPath() call above, but detect the incorrect |
| 167 | // memory access on release builds so that the test would fail. Given the path, it should only |
| 168 | // touch pixels with x=0 but the incorrect addressing would wrap to the right edge. |
| 169 | for (int y = 0; y < 256; ++y) { |
| 170 | if (bm.getColor(255, y) != SK_ColorWHITE) { |
| 171 | REPORTER_ASSERT(reporter, false, "drawPath modified incorrect pixels"); |
| 172 | break; |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
reed@google.com | 9d5f76a | 2012-05-01 14:49:28 +0000 | [diff] [blame] | 177 | // Need to exercise drawing an inverse-path whose bounds intersect the clip, |
| 178 | // but whose edges do not (since its a quad which draws only in the bottom half |
| 179 | // of its bounds). |
| 180 | // In the debug build, we used to assert in this case, until it was fixed. |
| 181 | // |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 182 | static void test_inversepathwithclip() { |
reed@google.com | 9d5f76a | 2012-05-01 14:49:28 +0000 | [diff] [blame] | 183 | SkPath path; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 184 | |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 185 | path.moveTo(0, 20); |
| 186 | path.quadTo(10, 10, 20, 20); |
reed@google.com | 9d5f76a | 2012-05-01 14:49:28 +0000 | [diff] [blame] | 187 | path.toggleInverseFillType(); |
| 188 | |
| 189 | SkPaint paint; |
| 190 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 191 | auto surface(SkSurface::MakeRasterN32Premul(640, 480)); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 192 | SkCanvas* canvas = surface->getCanvas(); |
| 193 | canvas->save(); |
| 194 | canvas->clipRect(SkRect::MakeWH(19, 11)); |
reed@google.com | 9d5f76a | 2012-05-01 14:49:28 +0000 | [diff] [blame] | 195 | |
| 196 | paint.setAntiAlias(false); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 197 | canvas->drawPath(path, paint); |
reed@google.com | 9d5f76a | 2012-05-01 14:49:28 +0000 | [diff] [blame] | 198 | paint.setAntiAlias(true); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 199 | canvas->drawPath(path, paint); |
reed@google.com | 9d5f76a | 2012-05-01 14:49:28 +0000 | [diff] [blame] | 200 | |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 201 | canvas->restore(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 202 | |
reed@google.com | 9d5f76a | 2012-05-01 14:49:28 +0000 | [diff] [blame] | 203 | // Now do the test again, with the path flipped, so we only draw in the |
| 204 | // top half of our bounds, and have the clip intersect our bounds at the |
| 205 | // bottom. |
| 206 | path.reset(); // preserves our filltype |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 207 | path.moveTo(0, 10); |
| 208 | path.quadTo(10, 20, 20, 10); |
| 209 | canvas->clipRect(SkRect::MakeXYWH(0, 19, 19, 11)); |
reed@google.com | 9d5f76a | 2012-05-01 14:49:28 +0000 | [diff] [blame] | 210 | |
| 211 | paint.setAntiAlias(false); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 212 | canvas->drawPath(path, paint); |
reed@google.com | 9d5f76a | 2012-05-01 14:49:28 +0000 | [diff] [blame] | 213 | paint.setAntiAlias(true); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 214 | canvas->drawPath(path, paint); |
reed@google.com | 9d5f76a | 2012-05-01 14:49:28 +0000 | [diff] [blame] | 215 | } |
| 216 | |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 217 | static void test_bug533() { |
mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 218 | /* |
| 219 | http://code.google.com/p/skia/issues/detail?id=533 |
| 220 | This particular test/bug only applies to the float case, where the |
| 221 | coordinates are very large. |
| 222 | */ |
| 223 | SkPath path; |
| 224 | path.moveTo(64, 3); |
| 225 | path.quadTo(-329936, -100000000, 1153, 330003); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 226 | |
mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 227 | SkPaint paint; |
| 228 | paint.setAntiAlias(true); |
| 229 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 230 | auto surface(SkSurface::MakeRasterN32Premul(640, 480)); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 231 | surface->getCanvas()->drawPath(path, paint); |
mike@reedtribe.org | 6093e65 | 2012-04-14 12:55:17 +0000 | [diff] [blame] | 232 | } |
| 233 | |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 234 | static void test_crbug_140642() { |
reed@google.com | d9ee348 | 2012-08-06 14:58:35 +0000 | [diff] [blame] | 235 | /* |
| 236 | * We used to see this construct, and due to rounding as we accumulated |
| 237 | * our length, the loop where we apply the phase would run off the end of |
| 238 | * the array, since it relied on just -= each interval value, which did not |
| 239 | * behave as "expected". Now the code explicitly checks for walking off the |
| 240 | * end of that array. |
| 241 | |
| 242 | * A different (better) fix might be to rewrite dashing to do all of its |
| 243 | * length/phase/measure math using double, but this may need to be |
| 244 | * coordinated with SkPathMeasure, to be consistent between the two. |
| 245 | |
| 246 | <path stroke="mintcream" stroke-dasharray="27734 35660 2157846850 247" |
| 247 | stroke-dashoffset="-248.135982067"> |
| 248 | */ |
| 249 | |
reed@google.com | d9ee348 | 2012-08-06 14:58:35 +0000 | [diff] [blame] | 250 | const SkScalar vals[] = { 27734, 35660, 2157846850.0f, 247 }; |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 251 | auto dontAssert = SkDashPathEffect::Make(vals, 4, -248.135982067f); |
reed@google.com | d9ee348 | 2012-08-06 14:58:35 +0000 | [diff] [blame] | 252 | } |
| 253 | |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 254 | static void test_crbug_124652() { |
reed@google.com | 1df888b | 2012-04-24 22:47:21 +0000 | [diff] [blame] | 255 | /* |
| 256 | http://code.google.com/p/chromium/issues/detail?id=124652 |
| 257 | This particular test/bug only applies to the float case, where |
| 258 | large values can "swamp" small ones. |
| 259 | */ |
| 260 | SkScalar intervals[2] = {837099584, 33450}; |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 261 | auto dontAssert = SkDashPathEffect::Make(intervals, 2, -10); |
reed@google.com | 1df888b | 2012-04-24 22:47:21 +0000 | [diff] [blame] | 262 | } |
| 263 | |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 264 | static void test_bigcubic() { |
reed@google.com | a90aa53 | 2012-04-16 16:27:09 +0000 | [diff] [blame] | 265 | SkPath path; |
| 266 | path.moveTo(64, 3); |
| 267 | path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 268 | |
reed@google.com | a90aa53 | 2012-04-16 16:27:09 +0000 | [diff] [blame] | 269 | SkPaint paint; |
| 270 | paint.setAntiAlias(true); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 271 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 272 | auto surface(SkSurface::MakeRasterN32Premul(640, 480)); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 273 | surface->getCanvas()->drawPath(path, paint); |
reed@google.com | a90aa53 | 2012-04-16 16:27:09 +0000 | [diff] [blame] | 274 | } |
| 275 | |
caryclark | 6df6115 | 2016-01-04 14:17:47 -0800 | [diff] [blame] | 276 | // asserts if halfway case is not handled |
| 277 | static void test_halfway() { |
| 278 | SkPaint paint; |
| 279 | SkPath path; |
| 280 | path.moveTo(16365.5f, 1394); |
| 281 | path.lineTo(16365.5f, 1387.5f); |
| 282 | path.quadTo(16365.5f, 1385.43f, 16367, 1383.96f); |
| 283 | path.quadTo(16368.4f, 1382.5f, 16370.5f, 1382.5f); |
| 284 | path.lineTo(16465.5f, 1382.5f); |
| 285 | path.quadTo(16467.6f, 1382.5f, 16469, 1383.96f); |
| 286 | path.quadTo(16470.5f, 1385.43f, 16470.5f, 1387.5f); |
| 287 | path.lineTo(16470.5f, 1394); |
| 288 | path.quadTo(16470.5f, 1396.07f, 16469, 1397.54f); |
| 289 | path.quadTo(16467.6f, 1399, 16465.5f, 1399); |
| 290 | path.lineTo(16370.5f, 1399); |
| 291 | path.quadTo(16368.4f, 1399, 16367, 1397.54f); |
| 292 | path.quadTo(16365.5f, 1396.07f, 16365.5f, 1394); |
| 293 | path.close(); |
| 294 | SkPath p2; |
| 295 | SkMatrix m; |
| 296 | m.reset(); |
| 297 | m.postTranslate(0.001f, 0.001f); |
| 298 | path.transform(m, &p2); |
| 299 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 300 | auto surface(SkSurface::MakeRasterN32Premul(640, 480)); |
caryclark | 6df6115 | 2016-01-04 14:17:47 -0800 | [diff] [blame] | 301 | SkCanvas* canvas = surface->getCanvas(); |
| 302 | canvas->translate(-16366, -1383); |
| 303 | canvas->drawPath(p2, paint); |
| 304 | |
| 305 | m.reset(); |
| 306 | m.postTranslate(-0.001f, -0.001f); |
| 307 | path.transform(m, &p2); |
| 308 | canvas->drawPath(p2, paint); |
| 309 | |
| 310 | m.reset(); |
| 311 | path.transform(m, &p2); |
| 312 | canvas->drawPath(p2, paint); |
| 313 | } |
| 314 | |
reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 315 | // we used to assert if the bounds of the device (clip) was larger than 32K |
| 316 | // even when the path itself was smaller. We just draw and hope in the debug |
| 317 | // version to not assert. |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 318 | static void test_giantaa() { |
reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 319 | const int W = 400; |
| 320 | const int H = 400; |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 321 | auto surface(SkSurface::MakeRasterN32Premul(33000, 10)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 322 | |
reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 323 | SkPaint paint; |
| 324 | paint.setAntiAlias(true); |
| 325 | SkPath path; |
| 326 | path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H)); |
reed | 3054be1 | 2014-12-10 07:24:28 -0800 | [diff] [blame] | 327 | surface->getCanvas()->drawPath(path, paint); |
reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 328 | } |
| 329 | |
fmalita@google.com | bfa0401 | 2012-12-12 22:13:58 +0000 | [diff] [blame] | 330 | // Extremely large path_length/dash_length ratios may cause infinite looping |
| 331 | // in SkDashPathEffect::filterPath() due to single precision rounding. |
| 332 | // The test is quite expensive, but it should get much faster after the fix |
| 333 | // for http://crbug.com/165432 goes in. |
| 334 | static void test_infinite_dash(skiatest::Reporter* reporter) { |
| 335 | SkPath path; |
| 336 | path.moveTo(0, 0); |
| 337 | path.lineTo(5000000, 0); |
| 338 | |
| 339 | SkScalar intervals[] = { 0.2f, 0.2f }; |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 340 | sk_sp<SkPathEffect> dash(SkDashPathEffect::Make(intervals, 2, 0)); |
fmalita@google.com | bfa0401 | 2012-12-12 22:13:58 +0000 | [diff] [blame] | 341 | |
| 342 | SkPath filteredPath; |
| 343 | SkPaint paint; |
| 344 | paint.setStyle(SkPaint::kStroke_Style); |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 345 | paint.setPathEffect(dash); |
fmalita@google.com | bfa0401 | 2012-12-12 22:13:58 +0000 | [diff] [blame] | 346 | |
| 347 | paint.getFillPath(path, &filteredPath); |
| 348 | // If we reach this, we passed. |
| 349 | REPORTER_ASSERT(reporter, true); |
| 350 | } |
| 351 | |
fmalita@google.com | 6b18d24 | 2012-12-17 16:27:34 +0000 | [diff] [blame] | 352 | // http://crbug.com/165432 |
| 353 | // Limit extreme dash path effects to avoid exhausting the system memory. |
| 354 | static void test_crbug_165432(skiatest::Reporter* reporter) { |
| 355 | SkPath path; |
| 356 | path.moveTo(0, 0); |
| 357 | path.lineTo(10000000, 0); |
| 358 | |
| 359 | SkScalar intervals[] = { 0.5f, 0.5f }; |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 360 | sk_sp<SkPathEffect> dash(SkDashPathEffect::Make(intervals, 2, 0)); |
fmalita@google.com | 6b18d24 | 2012-12-17 16:27:34 +0000 | [diff] [blame] | 361 | |
| 362 | SkPaint paint; |
| 363 | paint.setStyle(SkPaint::kStroke_Style); |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 364 | paint.setPathEffect(dash); |
fmalita@google.com | 6b18d24 | 2012-12-17 16:27:34 +0000 | [diff] [blame] | 365 | |
| 366 | SkPath filteredPath; |
| 367 | SkStrokeRec rec(paint); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 368 | REPORTER_ASSERT(reporter, !dash->filterPath(&filteredPath, path, &rec, nullptr)); |
fmalita@google.com | 6b18d24 | 2012-12-17 16:27:34 +0000 | [diff] [blame] | 369 | REPORTER_ASSERT(reporter, filteredPath.isEmpty()); |
| 370 | } |
| 371 | |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 372 | // http://crbug.com/472147 |
| 373 | // This is a simplified version from the bug. RRect radii not properly scaled. |
| 374 | static void test_crbug_472147_simple(skiatest::Reporter* reporter) { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 375 | auto surface(SkSurface::MakeRasterN32Premul(1000, 1000)); |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 376 | SkCanvas* canvas = surface->getCanvas(); |
| 377 | SkPaint p; |
| 378 | SkRect r = SkRect::MakeLTRB(-246.0f, 33.0f, 848.0f, 33554464.0f); |
| 379 | SkVector radii[4] = { |
| 380 | { 13.0f, 8.0f }, { 170.0f, 2.0 }, { 256.0f, 33554430.0f }, { 120.0f, 5.0f } |
| 381 | }; |
| 382 | SkRRect rr; |
| 383 | rr.setRectRadii(r, radii); |
| 384 | canvas->drawRRect(rr, p); |
| 385 | } |
| 386 | |
| 387 | // http://crbug.com/472147 |
| 388 | // RRect radii not properly scaled. |
| 389 | static void test_crbug_472147_actual(skiatest::Reporter* reporter) { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 390 | auto surface(SkSurface::MakeRasterN32Premul(1000, 1000)); |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 391 | SkCanvas* canvas = surface->getCanvas(); |
| 392 | SkPaint p; |
| 393 | SkRect r = SkRect::MakeLTRB(-246.0f, 33.0f, 848.0f, 33554464.0f); |
| 394 | SkVector radii[4] = { |
| 395 | { 13.0f, 8.0f }, { 170.0f, 2.0 }, { 256.0f, 33554430.0f }, { 120.0f, 5.0f } |
| 396 | }; |
| 397 | SkRRect rr; |
| 398 | rr.setRectRadii(r, radii); |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 399 | canvas->clipRRect(rr); |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 400 | |
| 401 | SkRect r2 = SkRect::MakeLTRB(0, 33, 1102, 33554464); |
| 402 | canvas->drawRect(r2, p); |
| 403 | } |
| 404 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 405 | DEF_TEST(DrawPath, reporter) { |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 406 | test_giantaa(); |
| 407 | test_bug533(); |
| 408 | test_bigcubic(); |
| 409 | test_crbug_124652(); |
| 410 | test_crbug_140642(); |
| 411 | test_crbug_140803(); |
| 412 | test_inversepathwithclip(); |
humper@google.com | 05af1af | 2013-01-07 16:47:43 +0000 | [diff] [blame] | 413 | // why? |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 414 | if (false) test_crbug131181(); |
fmalita@google.com | bfa0401 | 2012-12-12 22:13:58 +0000 | [diff] [blame] | 415 | test_infinite_dash(reporter); |
fmalita@google.com | 6b18d24 | 2012-12-17 16:27:34 +0000 | [diff] [blame] | 416 | test_crbug_165432(reporter); |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 417 | test_crbug_472147_simple(reporter); |
| 418 | test_crbug_472147_actual(reporter); |
Michael Ludwig | c7ffd5e | 2021-09-09 20:21:59 -0400 | [diff] [blame] | 419 | test_crbug_1239558(reporter); |
reed@google.com | 1c028bd | 2013-08-28 15:23:19 +0000 | [diff] [blame] | 420 | test_big_aa_rect(reporter); |
caryclark | 6df6115 | 2016-01-04 14:17:47 -0800 | [diff] [blame] | 421 | test_halfway(); |
reed@google.com | dceecc7 | 2012-02-23 19:20:19 +0000 | [diff] [blame] | 422 | } |