caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +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 | |
| 8 | #include "PathOpsExtendedTest.h" |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 9 | #include "PathOpsThreadedCommon.h" |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 10 | #include "SkBitmap.h" |
| 11 | #include "SkCanvas.h" |
| 12 | #include "SkMatrix.h" |
mtklein | 1b24933 | 2015-07-07 12:21:21 -0700 | [diff] [blame] | 13 | #include "SkMutex.h" |
skia.committer@gmail.com | e02c5da | 2014-04-26 03:04:35 +0000 | [diff] [blame] | 14 | #include "SkPaint.h" |
Mike Reed | 267be7f | 2017-02-13 09:32:54 -0500 | [diff] [blame^] | 15 | #include "SkRegion.h" |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 16 | #include "SkStream.h" |
| 17 | |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 18 | #include <stdlib.h> |
| 19 | |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 20 | #ifdef SK_BUILD_FOR_MAC |
| 21 | #include <sys/sysctl.h> |
| 22 | #endif |
| 23 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 24 | bool OpDebug(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result |
| 25 | SkDEBUGPARAMS(bool skipAssert) |
| 26 | SkDEBUGPARAMS(const char* testName)); |
| 27 | |
| 28 | bool SimplifyDebug(const SkPath& one, SkPath* result |
| 29 | SkDEBUGPARAMS(bool skipAssert) |
| 30 | SkDEBUGPARAMS(const char* testName)); |
| 31 | |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 32 | static const char marker[] = |
| 33 | "</div>\n" |
| 34 | "\n" |
| 35 | "<script type=\"text/javascript\">\n" |
| 36 | "\n" |
| 37 | "var testDivs = [\n"; |
| 38 | |
| 39 | static const char* opStrs[] = { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 40 | "kDifference_SkPathOp", |
| 41 | "kIntersect_SkPathOp", |
| 42 | "kUnion_SkPathOp", |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 43 | "kXOR_PathOp", |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 44 | "kReverseDifference_SkPathOp", |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | static const char* opSuffixes[] = { |
| 48 | "d", |
| 49 | "i", |
| 50 | "u", |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 51 | "o", |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 52 | "r", |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
caryclark | d5b9173 | 2016-08-09 05:04:29 -0700 | [diff] [blame] | 55 | enum class ExpectSuccess { |
| 56 | kNo, |
| 57 | kYes, |
| 58 | kFlaky |
| 59 | }; |
| 60 | |
| 61 | enum class SkipAssert { |
| 62 | kNo, |
| 63 | kYes |
| 64 | }; |
| 65 | |
| 66 | enum class ExpectMatch { |
| 67 | kNo, |
| 68 | kYes, |
| 69 | kFlaky |
| 70 | }; |
| 71 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 72 | #if DEBUG_SHOW_TEST_NAME |
| 73 | static void showPathData(const SkPath& path) { |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 74 | SkPath::RawIter iter(path); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 75 | uint8_t verb; |
| 76 | SkPoint pts[4]; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 77 | SkPoint firstPt = {0, 0}, lastPt = {0, 0}; |
caryclark@google.com | fa2aeee | 2013-07-15 13:29:13 +0000 | [diff] [blame] | 78 | bool firstPtSet = false; |
| 79 | bool lastPtSet = true; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 80 | while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
| 81 | switch (verb) { |
| 82 | case SkPath::kMove_Verb: |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 83 | if (firstPtSet && lastPtSet && firstPt != lastPt) { |
| 84 | SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", lastPt.fX, lastPt.fY, |
| 85 | firstPt.fX, firstPt.fY); |
| 86 | lastPtSet = false; |
| 87 | } |
caryclark@google.com | fa2aeee | 2013-07-15 13:29:13 +0000 | [diff] [blame] | 88 | firstPt = pts[0]; |
| 89 | firstPtSet = true; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 90 | continue; |
| 91 | case SkPath::kLine_Verb: |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 92 | SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", pts[0].fX, pts[0].fY, |
| 93 | pts[1].fX, pts[1].fY); |
caryclark@google.com | fa2aeee | 2013-07-15 13:29:13 +0000 | [diff] [blame] | 94 | lastPt = pts[1]; |
| 95 | lastPtSet = true; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 96 | break; |
| 97 | case SkPath::kQuad_Verb: |
| 98 | SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 99 | pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY); |
caryclark@google.com | fa2aeee | 2013-07-15 13:29:13 +0000 | [diff] [blame] | 100 | lastPt = pts[2]; |
| 101 | lastPtSet = true; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 102 | break; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 103 | case SkPath::kConic_Verb: |
| 104 | SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}, //weight=%1.9g\n", |
| 105 | pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY, |
| 106 | iter.conicWeight()); |
| 107 | lastPt = pts[2]; |
| 108 | lastPtSet = true; |
| 109 | break; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 110 | case SkPath::kCubic_Verb: |
| 111 | SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 112 | pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY, |
| 113 | pts[3].fX, pts[3].fY); |
caryclark@google.com | fa2aeee | 2013-07-15 13:29:13 +0000 | [diff] [blame] | 114 | lastPt = pts[3]; |
| 115 | lastPtSet = true; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 116 | break; |
| 117 | case SkPath::kClose_Verb: |
caryclark@google.com | fa2aeee | 2013-07-15 13:29:13 +0000 | [diff] [blame] | 118 | if (firstPtSet && lastPtSet && firstPt != lastPt) { |
| 119 | SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", lastPt.fX, lastPt.fY, |
| 120 | firstPt.fX, firstPt.fY); |
| 121 | } |
| 122 | firstPtSet = lastPtSet = false; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 123 | break; |
| 124 | default: |
| 125 | SkDEBUGFAIL("bad verb"); |
| 126 | return; |
| 127 | } |
| 128 | } |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 129 | if (firstPtSet && lastPtSet && firstPt != lastPt) { |
| 130 | SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", lastPt.fX, lastPt.fY, |
| 131 | firstPt.fX, firstPt.fY); |
| 132 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 133 | } |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 134 | #endif |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 135 | |
| 136 | void showOp(const SkPathOp op) { |
| 137 | switch (op) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 138 | case kDifference_SkPathOp: |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 139 | SkDebugf("op difference\n"); |
| 140 | break; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 141 | case kIntersect_SkPathOp: |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 142 | SkDebugf("op intersect\n"); |
| 143 | break; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 144 | case kUnion_SkPathOp: |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 145 | SkDebugf("op union\n"); |
| 146 | break; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 147 | case kXOR_SkPathOp: |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 148 | SkDebugf("op xor\n"); |
| 149 | break; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 150 | case kReverseDifference_SkPathOp: |
caryclark@google.com | 6dc7df6 | 2013-04-25 11:51:54 +0000 | [diff] [blame] | 151 | SkDebugf("op reverse difference\n"); |
| 152 | break; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 153 | default: |
| 154 | SkASSERT(0); |
| 155 | } |
| 156 | } |
| 157 | |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 158 | #if DEBUG_SHOW_TEST_NAME |
caryclark@google.com | 0361032 | 2013-04-18 15:58:21 +0000 | [diff] [blame] | 159 | static char hexorator(int x) { |
| 160 | if (x < 10) { |
| 161 | return x + '0'; |
| 162 | } |
| 163 | x -= 10; |
| 164 | SkASSERT(x < 26); |
| 165 | return x + 'A'; |
| 166 | } |
| 167 | #endif |
| 168 | |
| 169 | void ShowTestName(PathOpsThreadState* state, int a, int b, int c, int d) { |
| 170 | #if DEBUG_SHOW_TEST_NAME |
| 171 | state->fSerialNo[0] = hexorator(state->fA); |
| 172 | state->fSerialNo[1] = hexorator(state->fB); |
| 173 | state->fSerialNo[2] = hexorator(state->fC); |
| 174 | state->fSerialNo[3] = hexorator(state->fD); |
| 175 | state->fSerialNo[4] = hexorator(a); |
| 176 | state->fSerialNo[5] = hexorator(b); |
| 177 | state->fSerialNo[6] = hexorator(c); |
| 178 | state->fSerialNo[7] = hexorator(d); |
| 179 | state->fSerialNo[8] = '\0'; |
| 180 | SkDebugf("%s\n", state->fSerialNo); |
| 181 | if (strcmp(state->fSerialNo, state->fKey) == 0) { |
| 182 | SkDebugf("%s\n", state->fPathStr); |
| 183 | } |
| 184 | #endif |
| 185 | } |
| 186 | |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 187 | const int bitWidth = 64; |
| 188 | const int bitHeight = 64; |
| 189 | |
| 190 | static void scaleMatrix(const SkPath& one, const SkPath& two, SkMatrix& scale) { |
| 191 | SkRect larger = one.getBounds(); |
| 192 | larger.join(two.getBounds()); |
| 193 | SkScalar largerWidth = larger.width(); |
| 194 | if (largerWidth < 4) { |
| 195 | largerWidth = 4; |
| 196 | } |
| 197 | SkScalar largerHeight = larger.height(); |
| 198 | if (largerHeight < 4) { |
| 199 | largerHeight = 4; |
| 200 | } |
| 201 | SkScalar hScale = (bitWidth - 2) / largerWidth; |
| 202 | SkScalar vScale = (bitHeight - 2) / largerHeight; |
| 203 | scale.reset(); |
| 204 | scale.preScale(hScale, vScale); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 205 | larger.fLeft *= hScale; |
| 206 | larger.fRight *= hScale; |
| 207 | larger.fTop *= vScale; |
| 208 | larger.fBottom *= vScale; |
| 209 | SkScalar dx = -16000 > larger.fLeft ? -16000 - larger.fLeft |
| 210 | : 16000 < larger.fRight ? 16000 - larger.fRight : 0; |
| 211 | SkScalar dy = -16000 > larger.fTop ? -16000 - larger.fTop |
| 212 | : 16000 < larger.fBottom ? 16000 - larger.fBottom : 0; |
| 213 | scale.postTranslate(dx, dy); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | static int pathsDrawTheSame(SkBitmap& bits, const SkPath& scaledOne, const SkPath& scaledTwo, |
| 217 | int& error2x2) { |
| 218 | if (bits.width() == 0) { |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 219 | bits.allocN32Pixels(bitWidth * 2, bitHeight); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 220 | } |
| 221 | SkCanvas canvas(bits); |
| 222 | canvas.drawColor(SK_ColorWHITE); |
| 223 | SkPaint paint; |
| 224 | canvas.save(); |
| 225 | const SkRect& bounds1 = scaledOne.getBounds(); |
| 226 | canvas.translate(-bounds1.fLeft + 1, -bounds1.fTop + 1); |
| 227 | canvas.drawPath(scaledOne, paint); |
| 228 | canvas.restore(); |
| 229 | canvas.save(); |
| 230 | canvas.translate(-bounds1.fLeft + 1 + bitWidth, -bounds1.fTop + 1); |
| 231 | canvas.drawPath(scaledTwo, paint); |
| 232 | canvas.restore(); |
| 233 | int errors2 = 0; |
| 234 | int errors = 0; |
| 235 | for (int y = 0; y < bitHeight - 1; ++y) { |
| 236 | uint32_t* addr1 = bits.getAddr32(0, y); |
| 237 | uint32_t* addr2 = bits.getAddr32(0, y + 1); |
| 238 | uint32_t* addr3 = bits.getAddr32(bitWidth, y); |
| 239 | uint32_t* addr4 = bits.getAddr32(bitWidth, y + 1); |
| 240 | for (int x = 0; x < bitWidth - 1; ++x) { |
| 241 | // count 2x2 blocks |
| 242 | bool err = addr1[x] != addr3[x]; |
| 243 | if (err) { |
| 244 | errors2 += addr1[x + 1] != addr3[x + 1] |
| 245 | && addr2[x] != addr4[x] && addr2[x + 1] != addr4[x + 1]; |
| 246 | errors++; |
| 247 | } |
| 248 | } |
| 249 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 250 | error2x2 = errors2; |
| 251 | return errors; |
| 252 | } |
| 253 | |
| 254 | static int pathsDrawTheSame(const SkPath& one, const SkPath& two, SkBitmap& bits, SkPath& scaledOne, |
| 255 | SkPath& scaledTwo, int& error2x2) { |
| 256 | SkMatrix scale; |
| 257 | scaleMatrix(one, two, scale); |
| 258 | one.transform(scale, &scaledOne); |
| 259 | two.transform(scale, &scaledTwo); |
| 260 | return pathsDrawTheSame(bits, scaledOne, scaledTwo, error2x2); |
| 261 | } |
| 262 | |
| 263 | bool drawAsciiPaths(const SkPath& one, const SkPath& two, bool drawPaths) { |
| 264 | if (!drawPaths) { |
| 265 | return true; |
| 266 | } |
| 267 | const SkRect& bounds1 = one.getBounds(); |
| 268 | const SkRect& bounds2 = two.getBounds(); |
| 269 | SkRect larger = bounds1; |
| 270 | larger.join(bounds2); |
| 271 | SkBitmap bits; |
| 272 | char out[256]; |
reed@google.com | e1ca705 | 2013-12-17 19:22:07 +0000 | [diff] [blame] | 273 | int bitWidth = SkScalarCeilToInt(larger.width()) + 2; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 274 | if (bitWidth * 2 + 1 >= (int) sizeof(out)) { |
| 275 | return false; |
| 276 | } |
reed@google.com | e1ca705 | 2013-12-17 19:22:07 +0000 | [diff] [blame] | 277 | int bitHeight = SkScalarCeilToInt(larger.height()) + 2; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 278 | if (bitHeight >= (int) sizeof(out)) { |
| 279 | return false; |
| 280 | } |
mike@reedtribe.org | deee496 | 2014-02-13 14:41:43 +0000 | [diff] [blame] | 281 | bits.allocN32Pixels(bitWidth * 2, bitHeight); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 282 | SkCanvas canvas(bits); |
| 283 | canvas.drawColor(SK_ColorWHITE); |
| 284 | SkPaint paint; |
| 285 | canvas.save(); |
| 286 | canvas.translate(-bounds1.fLeft + 1, -bounds1.fTop + 1); |
| 287 | canvas.drawPath(one, paint); |
| 288 | canvas.restore(); |
| 289 | canvas.save(); |
| 290 | canvas.translate(-bounds1.fLeft + 1 + bitWidth, -bounds1.fTop + 1); |
| 291 | canvas.drawPath(two, paint); |
| 292 | canvas.restore(); |
| 293 | for (int y = 0; y < bitHeight; ++y) { |
| 294 | uint32_t* addr1 = bits.getAddr32(0, y); |
| 295 | int x; |
| 296 | char* outPtr = out; |
| 297 | for (x = 0; x < bitWidth; ++x) { |
| 298 | *outPtr++ = addr1[x] == (uint32_t) -1 ? '_' : 'x'; |
| 299 | } |
| 300 | *outPtr++ = '|'; |
| 301 | for (x = bitWidth; x < bitWidth * 2; ++x) { |
| 302 | *outPtr++ = addr1[x] == (uint32_t) -1 ? '_' : 'x'; |
| 303 | } |
| 304 | *outPtr++ = '\0'; |
| 305 | SkDebugf("%s\n", out); |
| 306 | } |
| 307 | return true; |
| 308 | } |
| 309 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 310 | int comparePaths(skiatest::Reporter* reporter, const char* filename, const SkPath& one, |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 311 | const SkPath& two, SkBitmap& bitmap) { |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 312 | int errors2x2; |
| 313 | SkPath scaledOne, scaledTwo; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 314 | (void) pathsDrawTheSame(one, two, bitmap, scaledOne, scaledTwo, errors2x2); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 315 | if (errors2x2 == 0) { |
| 316 | return 0; |
| 317 | } |
| 318 | const int MAX_ERRORS = 9; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 319 | return errors2x2 > MAX_ERRORS ? errors2x2 : 0; |
| 320 | } |
| 321 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 322 | static SkTDArray<SkPathOp> gTestOp; |
| 323 | |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 324 | static void showPathOpPath(const char* testName, const SkPath& one, const SkPath& two, |
| 325 | const SkPath& a, const SkPath& b, const SkPath& scaledOne, const SkPath& scaledTwo, |
| 326 | const SkPathOp shapeOp, const SkMatrix& scale) { |
| 327 | SkASSERT((unsigned) shapeOp < SK_ARRAY_COUNT(opStrs)); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 328 | if (!testName) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 329 | testName = "xOp"; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 330 | } |
caryclark | 2bec26a | 2016-05-26 09:01:47 -0700 | [diff] [blame] | 331 | SkDebugf("static void %s_%s(skiatest::Reporter* reporter, const char* filename) {\n", |
| 332 | testName, opSuffixes[shapeOp]); |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 333 | *gTestOp.append() = shapeOp; |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 334 | SkDebugf(" SkPath path, pathB;\n"); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 335 | SkPathOpsDebug::ShowOnePath(a, "path", false); |
| 336 | SkPathOpsDebug::ShowOnePath(b, "pathB", false); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 337 | SkDebugf(" testPathOp(reporter, path, pathB, %s, filename);\n", opStrs[shapeOp]); |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 338 | SkDebugf("}\n"); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 339 | drawAsciiPaths(scaledOne, scaledTwo, true); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 340 | } |
| 341 | |
reed | 086eea9 | 2016-05-04 17:12:46 -0700 | [diff] [blame] | 342 | SK_DECLARE_STATIC_MUTEX(compareDebugOut3); |
caryclark | 38a017b | 2015-05-13 10:13:17 -0700 | [diff] [blame] | 343 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 344 | static int comparePaths(skiatest::Reporter* reporter, const char* testName, const SkPath& one, |
| 345 | const SkPath& scaledOne, const SkPath& two, const SkPath& scaledTwo, SkBitmap& bitmap, |
caryclark | 65f5531 | 2014-11-13 06:58:52 -0800 | [diff] [blame] | 346 | const SkPath& a, const SkPath& b, const SkPathOp shapeOp, const SkMatrix& scale, |
caryclark | d5b9173 | 2016-08-09 05:04:29 -0700 | [diff] [blame] | 347 | ExpectMatch expectMatch) { |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 348 | int errors2x2; |
caryclark | 65f5531 | 2014-11-13 06:58:52 -0800 | [diff] [blame] | 349 | const int MAX_ERRORS = 8; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 350 | (void) pathsDrawTheSame(bitmap, scaledOne, scaledTwo, errors2x2); |
caryclark | d5b9173 | 2016-08-09 05:04:29 -0700 | [diff] [blame] | 351 | if (ExpectMatch::kNo == expectMatch) { |
caryclark | 38a017b | 2015-05-13 10:13:17 -0700 | [diff] [blame] | 352 | if (errors2x2 < MAX_ERRORS) { |
caryclark | 65f5531 | 2014-11-13 06:58:52 -0800 | [diff] [blame] | 353 | REPORTER_ASSERT(reporter, 0); |
| 354 | } |
| 355 | return 0; |
| 356 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 357 | if (errors2x2 == 0) { |
| 358 | return 0; |
| 359 | } |
caryclark | d5b9173 | 2016-08-09 05:04:29 -0700 | [diff] [blame] | 360 | if (ExpectMatch::kYes == expectMatch && errors2x2 >= MAX_ERRORS) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 361 | SkAutoMutexAcquire autoM(compareDebugOut3); |
| 362 | showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp, scale); |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 363 | SkDebugf("\n/*"); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 364 | REPORTER_ASSERT(reporter, 0); |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 365 | SkDebugf(" */\n"); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 366 | } |
caryclark | 38a017b | 2015-05-13 10:13:17 -0700 | [diff] [blame] | 367 | return errors2x2 >= MAX_ERRORS ? errors2x2 : 0; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 368 | } |
| 369 | |
commit-bot@chromium.org | 409774e | 2013-10-02 16:15:44 +0000 | [diff] [blame] | 370 | // Default values for when reporter->verbose() is false. |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 371 | static int testNumber = 55; |
commit-bot@chromium.org | 409774e | 2013-10-02 16:15:44 +0000 | [diff] [blame] | 372 | static const char* testName = "pathOpTest"; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 373 | |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 374 | static void appendTestName(const char* nameSuffix, SkString& out) { |
| 375 | out.appendf("%s%d", testName, testNumber); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 376 | ++testNumber; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 377 | if (nameSuffix) { |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 378 | out.append(nameSuffix); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 382 | static void appendTest(const char* pathStr, const char* pathPrefix, const char* nameSuffix, |
| 383 | const char* testFunction, bool twoPaths, SkString& out) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 384 | #if 0 |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 385 | out.append("\n<div id=\""); |
| 386 | appendTestName(nameSuffix, out); |
| 387 | out.append("\">\n"); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 388 | if (pathPrefix) { |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 389 | out.append(pathPrefix); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 390 | } |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 391 | out.append(pathStr); |
| 392 | out.append("</div>\n\n"); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 393 | |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 394 | out.append(marker); |
| 395 | out.append(" "); |
| 396 | appendTestName(nameSuffix, out); |
| 397 | out.append(",\n\n\n"); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 398 | #endif |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 399 | out.append("static void "); |
| 400 | appendTestName(nameSuffix, out); |
| 401 | out.append("(skiatest::Reporter* reporter) {\n SkPath path"); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 402 | if (twoPaths) { |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 403 | out.append(", pathB"); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 404 | } |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 405 | out.append(";\n"); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 406 | if (pathPrefix) { |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 407 | out.append(pathPrefix); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 408 | } |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 409 | out.appendf("%s %s\n}\n\n", pathStr, testFunction); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 410 | #if 0 |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 411 | out.append("static void (*firstTest)() = "); |
| 412 | appendTestName(nameSuffix, out); |
| 413 | out.append(";\n\n"); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 414 | |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 415 | out.append("static struct {\n"); |
| 416 | out.append(" void (*fun)();\n"); |
| 417 | out.append(" const char* str;\n"); |
| 418 | out.append("} tests[] = {\n"); |
| 419 | out.append(" TEST("); |
| 420 | appendTestName(nameSuffix, out); |
| 421 | out.append("),\n"); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 422 | #endif |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 423 | } |
| 424 | |
reed | 086eea9 | 2016-05-04 17:12:46 -0700 | [diff] [blame] | 425 | SK_DECLARE_STATIC_MUTEX(simplifyDebugOut); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 426 | |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 427 | bool testSimplify(SkPath& path, bool useXor, SkPath& out, PathOpsThreadState& state, |
| 428 | const char* pathStr) { |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 429 | SkPath::FillType fillType = useXor ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType; |
| 430 | path.setFillType(fillType); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 431 | state.fReporter->bumpTestCount(); |
caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame] | 432 | if (!Simplify(path, &out)) { |
| 433 | SkDebugf("%s did not expect failure\n", __FUNCTION__); |
| 434 | REPORTER_ASSERT(state.fReporter, 0); |
| 435 | return false; |
| 436 | } |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 437 | if (!state.fReporter->verbose()) { |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 438 | return true; |
| 439 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 440 | int result = comparePaths(state.fReporter, nullptr, path, out, *state.fBitmap); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 441 | if (result) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 442 | SkAutoMutexAcquire autoM(simplifyDebugOut); |
Mike Reed | ff80c2a | 2017-01-07 11:16:28 -0500 | [diff] [blame] | 443 | SkString str; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 444 | const char* pathPrefix = nullptr; |
| 445 | const char* nameSuffix = nullptr; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 446 | if (fillType == SkPath::kEvenOdd_FillType) { |
| 447 | pathPrefix = " path.setFillType(SkPath::kEvenOdd_FillType);\n"; |
| 448 | nameSuffix = "x"; |
| 449 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 450 | const char testFunction[] = "testSimplify(reporter, path);"; |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 451 | appendTest(pathStr, pathPrefix, nameSuffix, testFunction, false, str); |
Mike Reed | ff80c2a | 2017-01-07 11:16:28 -0500 | [diff] [blame] | 452 | SkDebugf("%s", str.c_str()); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 453 | REPORTER_ASSERT(state.fReporter, 0); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 454 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 455 | state.fReporter->bumpTestCount(); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 456 | return result == 0; |
| 457 | } |
| 458 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 459 | static bool inner_simplify(skiatest::Reporter* reporter, const SkPath& path, const char* filename, |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 460 | ExpectSuccess expectSuccess, SkipAssert skipAssert, ExpectMatch expectMatch) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 461 | #if 0 && DEBUG_SHOW_TEST_NAME |
caryclark@google.com | 0361032 | 2013-04-18 15:58:21 +0000 | [diff] [blame] | 462 | showPathData(path); |
| 463 | #endif |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 464 | SkPath out; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 465 | if (!SimplifyDebug(path, &out SkDEBUGPARAMS(SkipAssert::kYes == skipAssert) |
| 466 | SkDEBUGPARAMS(testName))) { |
| 467 | if (ExpectSuccess::kYes == expectSuccess) { |
| 468 | SkDebugf("%s did not expect %s failure\n", __FUNCTION__, filename); |
| 469 | REPORTER_ASSERT(reporter, 0); |
| 470 | } |
caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame] | 471 | return false; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 472 | } else { |
| 473 | if (ExpectSuccess::kNo == expectSuccess) { |
| 474 | SkDebugf("%s %s unexpected success\n", __FUNCTION__, filename); |
| 475 | REPORTER_ASSERT(reporter, 0); |
| 476 | } |
caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame] | 477 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 478 | SkBitmap bitmap; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 479 | int errors = comparePaths(reporter, filename, path, out, bitmap); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 480 | if (ExpectMatch::kNo == expectMatch) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 481 | if (!errors) { |
| 482 | SkDebugf("%s failing test %s now succeeds\n", __FUNCTION__, filename); |
| 483 | REPORTER_ASSERT(reporter, 0); |
| 484 | return false; |
| 485 | } |
caryclark | d5b9173 | 2016-08-09 05:04:29 -0700 | [diff] [blame] | 486 | } else if (ExpectMatch::kYes == expectMatch && errors) { |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 487 | REPORTER_ASSERT(reporter, 0); |
| 488 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 489 | reporter->bumpTestCount(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 490 | return errors == 0; |
| 491 | } |
| 492 | |
| 493 | bool testSimplify(skiatest::Reporter* reporter, const SkPath& path, const char* filename) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 494 | return inner_simplify(reporter, path, filename, ExpectSuccess::kYes, SkipAssert::kNo, |
| 495 | ExpectMatch::kYes); |
| 496 | } |
| 497 | |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 498 | bool testSimplifyFuzz(skiatest::Reporter* reporter, const SkPath& path, const char* filename) { |
| 499 | return inner_simplify(reporter, path, filename, ExpectSuccess::kFlaky, SkipAssert::kYes, |
| 500 | ExpectMatch::kFlaky); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | bool testSimplifyCheck(skiatest::Reporter* reporter, const SkPath& path, const char* filename, |
| 504 | bool checkFail) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 505 | return inner_simplify(reporter, path, filename, checkFail ? |
| 506 | ExpectSuccess::kYes : ExpectSuccess::kNo, SkipAssert::kNo, ExpectMatch::kNo); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 507 | } |
| 508 | |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 509 | #if DEBUG_SHOW_TEST_NAME |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 510 | static void showName(const SkPath& a, const SkPath& b, const SkPathOp shapeOp) { |
| 511 | SkDebugf("\n"); |
| 512 | showPathData(a); |
| 513 | showOp(shapeOp); |
| 514 | showPathData(b); |
| 515 | } |
| 516 | #endif |
| 517 | |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 518 | static bool innerPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 519 | const SkPathOp shapeOp, const char* testName, ExpectSuccess expectSuccess, |
| 520 | SkipAssert skipAssert, ExpectMatch expectMatch) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 521 | #if 0 && DEBUG_SHOW_TEST_NAME |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 522 | showName(a, b, shapeOp); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 523 | #endif |
| 524 | SkPath out; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 525 | if (!OpDebug(a, b, shapeOp, &out SkDEBUGPARAMS(SkipAssert::kYes == skipAssert) |
caryclark | dae6b97 | 2016-06-08 04:28:19 -0700 | [diff] [blame] | 526 | SkDEBUGPARAMS(testName))) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 527 | if (ExpectSuccess::kYes == expectSuccess) { |
| 528 | SkDebugf("%s %s did not expect failure\n", __FUNCTION__, testName); |
caryclark | 3f0753d | 2016-06-28 09:23:57 -0700 | [diff] [blame] | 529 | REPORTER_ASSERT(reporter, 0); |
| 530 | } |
caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame] | 531 | return false; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 532 | } else { |
| 533 | if (ExpectSuccess::kNo == expectSuccess) { |
| 534 | SkDebugf("%s %s unexpected success\n", __FUNCTION__, testName); |
| 535 | REPORTER_ASSERT(reporter, 0); |
| 536 | } |
caryclark@google.com | 66560ca | 2013-04-26 19:51:16 +0000 | [diff] [blame] | 537 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 538 | if (!reporter->verbose()) { |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 539 | return true; |
| 540 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 541 | SkPath pathOut, scaledPathOut; |
| 542 | SkRegion rgnA, rgnB, openClip, rgnOut; |
| 543 | openClip.setRect(-16000, -16000, 16000, 16000); |
| 544 | rgnA.setPath(a, openClip); |
| 545 | rgnB.setPath(b, openClip); |
| 546 | rgnOut.op(rgnA, rgnB, (SkRegion::Op) shapeOp); |
| 547 | rgnOut.getBoundaryPath(&pathOut); |
| 548 | |
| 549 | SkMatrix scale; |
| 550 | scaleMatrix(a, b, scale); |
| 551 | SkRegion scaledRgnA, scaledRgnB, scaledRgnOut; |
| 552 | SkPath scaledA, scaledB; |
| 553 | scaledA.addPath(a, scale); |
| 554 | scaledA.setFillType(a.getFillType()); |
| 555 | scaledB.addPath(b, scale); |
| 556 | scaledB.setFillType(b.getFillType()); |
| 557 | scaledRgnA.setPath(scaledA, openClip); |
| 558 | scaledRgnB.setPath(scaledB, openClip); |
| 559 | scaledRgnOut.op(scaledRgnA, scaledRgnB, (SkRegion::Op) shapeOp); |
| 560 | scaledRgnOut.getBoundaryPath(&scaledPathOut); |
| 561 | SkBitmap bitmap; |
| 562 | SkPath scaledOut; |
| 563 | scaledOut.addPath(out, scale); |
| 564 | scaledOut.setFillType(out.getFillType()); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 565 | int result = comparePaths(reporter, testName, pathOut, scaledPathOut, out, scaledOut, bitmap, |
caryclark | d5b9173 | 2016-08-09 05:04:29 -0700 | [diff] [blame] | 566 | a, b, shapeOp, scale, expectMatch); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 567 | reporter->bumpTestCount(); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 568 | return result == 0; |
| 569 | } |
| 570 | |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 571 | bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, |
caryclark | 65f5531 | 2014-11-13 06:58:52 -0800 | [diff] [blame] | 572 | const SkPathOp shapeOp, const char* testName) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 573 | return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kYes, SkipAssert::kNo, |
| 574 | ExpectMatch::kYes); |
caryclark | 65f5531 | 2014-11-13 06:58:52 -0800 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | bool testPathOpCheck(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, |
| 578 | const SkPathOp shapeOp, const char* testName, bool checkFail) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 579 | return innerPathOp(reporter, a, b, shapeOp, testName, checkFail ? |
| 580 | ExpectSuccess::kYes : ExpectSuccess::kNo, SkipAssert::kNo, ExpectMatch::kNo); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 581 | } |
| 582 | |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 583 | bool testPathOpFuzz(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, |
caryclark | d5b9173 | 2016-08-09 05:04:29 -0700 | [diff] [blame] | 584 | const SkPathOp shapeOp, const char* testName) { |
| 585 | return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kFlaky, SkipAssert::kYes, |
| 586 | ExpectMatch::kFlaky); |
| 587 | } |
| 588 | |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 589 | bool testPathOpFail(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, |
| 590 | const SkPathOp shapeOp, const char* testName) { |
| 591 | #if DEBUG_SHOW_TEST_NAME |
| 592 | showName(a, b, shapeOp); |
| 593 | #endif |
| 594 | SkPath orig; |
| 595 | orig.lineTo(54, 43); |
| 596 | SkPath out = orig; |
| 597 | if (Op(a, b, shapeOp, &out) ) { |
| 598 | SkDebugf("%s test is expected to fail\n", __FUNCTION__); |
| 599 | REPORTER_ASSERT(reporter, 0); |
| 600 | return false; |
| 601 | } |
| 602 | SkASSERT(out == orig); |
| 603 | return true; |
| 604 | } |
| 605 | |
reed | 086eea9 | 2016-05-04 17:12:46 -0700 | [diff] [blame] | 606 | SK_DECLARE_STATIC_MUTEX(gMutex); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 607 | |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 608 | void initializeTests(skiatest::Reporter* reporter, const char* test) { |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 609 | if (reporter->verbose()) { |
| 610 | SkAutoMutexAcquire lock(gMutex); |
| 611 | testName = test; |
| 612 | size_t testNameSize = strlen(test); |
| 613 | SkFILEStream inFile("../../experimental/Intersection/op.htm"); |
| 614 | if (inFile.isValid()) { |
| 615 | SkTDArray<char> inData; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 616 | inData.setCount((int) inFile.getLength()); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 617 | size_t inLen = inData.count(); |
| 618 | inFile.read(inData.begin(), inLen); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 619 | inFile.setPath(nullptr); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 620 | char* insert = strstr(inData.begin(), marker); |
| 621 | if (insert) { |
| 622 | insert += sizeof(marker) - 1; |
| 623 | const char* numLoc = insert + 4 /* indent spaces */ + testNameSize - 1; |
| 624 | testNumber = atoi(numLoc) + 1; |
| 625 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 626 | } |
| 627 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 628 | } |
| 629 | |
Mike Reed | ff80c2a | 2017-01-07 11:16:28 -0500 | [diff] [blame] | 630 | void PathOpsThreadState::outputProgress(const char* pathStr, SkPath::FillType pathFillType) { |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 631 | const char testFunction[] = "testSimplify(path);"; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 632 | const char* pathPrefix = nullptr; |
| 633 | const char* nameSuffix = nullptr; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 634 | if (pathFillType == SkPath::kEvenOdd_FillType) { |
| 635 | pathPrefix = " path.setFillType(SkPath::kEvenOdd_FillType);\n"; |
| 636 | nameSuffix = "x"; |
| 637 | } |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 638 | appendTest(pathStr, pathPrefix, nameSuffix, testFunction, false, fPathStr); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Mike Reed | ff80c2a | 2017-01-07 11:16:28 -0500 | [diff] [blame] | 641 | void PathOpsThreadState::outputProgress(const char* pathStr, SkPathOp op) { |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 642 | const char testFunction[] = "testOp(path);"; |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 643 | SkASSERT((size_t) op < SK_ARRAY_COUNT(opSuffixes)); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 644 | const char* nameSuffix = opSuffixes[op]; |
Ben Wagner | 561c1b0 | 2017-01-09 15:54:34 -0500 | [diff] [blame] | 645 | appendTest(pathStr, nullptr, nameSuffix, testFunction, true, fPathStr); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | void RunTestSet(skiatest::Reporter* reporter, TestDesc tests[], size_t count, |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 649 | void (*firstTest)(skiatest::Reporter* , const char* filename), |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 650 | void (*skipTest)(skiatest::Reporter* , const char* filename), |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 651 | void (*stopTest)(skiatest::Reporter* , const char* filename), bool reverse) { |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 652 | size_t index; |
| 653 | if (firstTest) { |
| 654 | index = count - 1; |
| 655 | while (index > 0 && tests[index].fun != firstTest) { |
| 656 | --index; |
| 657 | } |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 658 | #if DEBUG_SHOW_TEST_NAME |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 659 | SkDebugf("\n<div id=\"%s\">\n", tests[index].str); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 660 | #endif |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 661 | (*tests[index].fun)(reporter, tests[index].str); |
| 662 | if (tests[index].fun == stopTest) { |
| 663 | return; |
| 664 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 665 | } |
| 666 | index = reverse ? count - 1 : 0; |
| 667 | size_t last = reverse ? 0 : count - 1; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 668 | bool foundSkip = !skipTest; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 669 | do { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 670 | if (tests[index].fun == skipTest) { |
| 671 | foundSkip = true; |
| 672 | } |
| 673 | if (foundSkip && tests[index].fun != firstTest) { |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 674 | #if DEBUG_SHOW_TEST_NAME |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 675 | SkDebugf("\n<div id=\"%s\">\n", tests[index].str); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 676 | #endif |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 677 | (*tests[index].fun)(reporter, tests[index].str); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 678 | } |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 679 | if (tests[index].fun == stopTest || index == last) { |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 680 | break; |
| 681 | } |
| 682 | index += reverse ? -1 : 1; |
| 683 | } while (true); |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 684 | #if DEBUG_SHOW_TEST_NAME |
| 685 | SkDebugf( |
| 686 | "\n" |
| 687 | "</div>\n" |
| 688 | "\n" |
| 689 | "<script type=\"text/javascript\">\n" |
| 690 | "\n" |
| 691 | "var testDivs = [\n" |
| 692 | ); |
| 693 | index = reverse ? count - 1 : 0; |
| 694 | last = reverse ? 0 : count - 1; |
| 695 | foundSkip = !skipTest; |
| 696 | do { |
| 697 | if (tests[index].fun == skipTest) { |
| 698 | foundSkip = true; |
| 699 | } |
| 700 | if (foundSkip && tests[index].fun != firstTest) { |
| 701 | SkDebugf(" %s,\n", tests[index].str); |
| 702 | } |
| 703 | if (tests[index].fun == stopTest || index == last) { |
| 704 | break; |
| 705 | } |
| 706 | index += reverse ? -1 : 1; |
| 707 | } while (true); |
| 708 | #endif |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 709 | } |