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