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