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