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