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