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