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