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