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