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