blob: 857ba6392823abe6b6ec243da88f1f74fa121eb7 [file] [log] [blame]
caryclark@google.com818b0cc2013-04-08 11:50:46 +00001/*
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
Cary Clarkf3949122018-08-07 16:38:21 -04008#include "PathOpsDebug.h"
caryclark@google.com818b0cc2013-04-08 11:50:46 +00009#include "PathOpsExtendedTest.h"
caryclark@google.com66089e42013-04-10 15:55:37 +000010#include "PathOpsThreadedCommon.h"
caryclark@google.com818b0cc2013-04-08 11:50:46 +000011#include "SkBitmap.h"
12#include "SkCanvas.h"
13#include "SkMatrix.h"
mtklein1b249332015-07-07 12:21:21 -070014#include "SkMutex.h"
skia.committer@gmail.come02c5da2014-04-26 03:04:35 +000015#include "SkPaint.h"
Cary Clarkf3949122018-08-07 16:38:21 -040016#include "SkParsePath.h"
Mike Reed267be7f2017-02-13 09:32:54 -050017#include "SkRegion.h"
caryclark@google.com818b0cc2013-04-08 11:50:46 +000018#include "SkStream.h"
19
bungeman60e0fee2015-08-26 05:15:46 -070020#include <stdlib.h>
Cary Clark4533f3d2018-08-08 09:48:09 -040021#include <vector>
22#include <string>
23#include <algorithm>
24
25std::vector<std::string> gUniqueNames;
bungeman60e0fee2015-08-26 05:15:46 -070026
caryclark@google.com818b0cc2013-04-08 11:50:46 +000027#ifdef SK_BUILD_FOR_MAC
28#include <sys/sysctl.h>
29#endif
30
Cary Clark389c5572017-04-14 07:46:07 -040031// std::to_string isn't implemented on android
32#include <sstream>
33
34template <typename T>
35std::string std_to_string(T value)
36{
37 std::ostringstream os ;
38 os << value ;
39 return os.str() ;
40}
41
caryclark55888e42016-07-18 10:01:36 -070042bool OpDebug(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result
43 SkDEBUGPARAMS(bool skipAssert)
44 SkDEBUGPARAMS(const char* testName));
45
46bool SimplifyDebug(const SkPath& one, SkPath* result
47 SkDEBUGPARAMS(bool skipAssert)
48 SkDEBUGPARAMS(const char* testName));
49
caryclark@google.com818b0cc2013-04-08 11:50:46 +000050static const char marker[] =
51 "</div>\n"
52 "\n"
53 "<script type=\"text/javascript\">\n"
54 "\n"
55 "var testDivs = [\n";
56
57static const char* opStrs[] = {
caryclark54359292015-03-26 07:52:43 -070058 "kDifference_SkPathOp",
59 "kIntersect_SkPathOp",
60 "kUnion_SkPathOp",
caryclark55888e42016-07-18 10:01:36 -070061 "kXOR_PathOp",
caryclark54359292015-03-26 07:52:43 -070062 "kReverseDifference_SkPathOp",
caryclark@google.com818b0cc2013-04-08 11:50:46 +000063};
64
65static const char* opSuffixes[] = {
66 "d",
67 "i",
68 "u",
caryclark@google.com66089e42013-04-10 15:55:37 +000069 "o",
caryclark55888e42016-07-18 10:01:36 -070070 "r",
caryclark@google.com818b0cc2013-04-08 11:50:46 +000071};
72
caryclarkd5b91732016-08-09 05:04:29 -070073enum class ExpectSuccess {
74 kNo,
75 kYes,
76 kFlaky
77};
78
79enum class SkipAssert {
80 kNo,
81 kYes
82};
83
84enum class ExpectMatch {
85 kNo,
86 kYes,
87 kFlaky
88};
89
caryclark@google.comcffbcc32013-06-04 17:59:42 +000090#if DEBUG_SHOW_TEST_NAME
91static void showPathData(const SkPath& path) {
caryclark@google.com07e97fc2013-07-08 17:17:02 +000092 SkPath::RawIter iter(path);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000093 uint8_t verb;
94 SkPoint pts[4];
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000095 SkPoint firstPt = {0, 0}, lastPt = {0, 0};
caryclark@google.comfa2aeee2013-07-15 13:29:13 +000096 bool firstPtSet = false;
97 bool lastPtSet = true;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000098 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
99 switch (verb) {
100 case SkPath::kMove_Verb:
caryclarkdac1d172014-06-17 05:15:38 -0700101 if (firstPtSet && lastPtSet && firstPt != lastPt) {
102 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", lastPt.fX, lastPt.fY,
103 firstPt.fX, firstPt.fY);
104 lastPtSet = false;
105 }
caryclark@google.comfa2aeee2013-07-15 13:29:13 +0000106 firstPt = pts[0];
107 firstPtSet = true;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000108 continue;
109 case SkPath::kLine_Verb:
caryclark@google.com66089e42013-04-10 15:55:37 +0000110 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", pts[0].fX, pts[0].fY,
111 pts[1].fX, pts[1].fY);
caryclark@google.comfa2aeee2013-07-15 13:29:13 +0000112 lastPt = pts[1];
113 lastPtSet = true;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000114 break;
115 case SkPath::kQuad_Verb:
116 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n",
caryclark@google.com66089e42013-04-10 15:55:37 +0000117 pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY);
caryclark@google.comfa2aeee2013-07-15 13:29:13 +0000118 lastPt = pts[2];
119 lastPtSet = true;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000120 break;
caryclark54359292015-03-26 07:52:43 -0700121 case SkPath::kConic_Verb:
122 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}, //weight=%1.9g\n",
123 pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY,
124 iter.conicWeight());
125 lastPt = pts[2];
126 lastPtSet = true;
127 break;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000128 case SkPath::kCubic_Verb:
129 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n",
caryclark@google.com66089e42013-04-10 15:55:37 +0000130 pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY,
131 pts[3].fX, pts[3].fY);
caryclark@google.comfa2aeee2013-07-15 13:29:13 +0000132 lastPt = pts[3];
133 lastPtSet = true;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000134 break;
135 case SkPath::kClose_Verb:
caryclark@google.comfa2aeee2013-07-15 13:29:13 +0000136 if (firstPtSet && lastPtSet && firstPt != lastPt) {
137 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", lastPt.fX, lastPt.fY,
138 firstPt.fX, firstPt.fY);
139 }
140 firstPtSet = lastPtSet = false;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000141 break;
142 default:
143 SkDEBUGFAIL("bad verb");
144 return;
145 }
146 }
caryclarkdac1d172014-06-17 05:15:38 -0700147 if (firstPtSet && lastPtSet && firstPt != lastPt) {
148 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", lastPt.fX, lastPt.fY,
149 firstPt.fX, firstPt.fY);
150 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000151}
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000152#endif
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000153
154void showOp(const SkPathOp op) {
155 switch (op) {
caryclark54359292015-03-26 07:52:43 -0700156 case kDifference_SkPathOp:
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000157 SkDebugf("op difference\n");
158 break;
caryclark54359292015-03-26 07:52:43 -0700159 case kIntersect_SkPathOp:
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000160 SkDebugf("op intersect\n");
161 break;
caryclark54359292015-03-26 07:52:43 -0700162 case kUnion_SkPathOp:
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000163 SkDebugf("op union\n");
164 break;
caryclark54359292015-03-26 07:52:43 -0700165 case kXOR_SkPathOp:
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000166 SkDebugf("op xor\n");
167 break;
caryclark54359292015-03-26 07:52:43 -0700168 case kReverseDifference_SkPathOp:
caryclark@google.com6dc7df62013-04-25 11:51:54 +0000169 SkDebugf("op reverse difference\n");
170 break;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000171 default:
172 SkASSERT(0);
173 }
174}
175
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000176#if DEBUG_SHOW_TEST_NAME
caryclark@google.com03610322013-04-18 15:58:21 +0000177static char hexorator(int x) {
178 if (x < 10) {
179 return x + '0';
180 }
181 x -= 10;
182 SkASSERT(x < 26);
183 return x + 'A';
184}
185#endif
186
187void ShowTestName(PathOpsThreadState* state, int a, int b, int c, int d) {
188#if DEBUG_SHOW_TEST_NAME
189 state->fSerialNo[0] = hexorator(state->fA);
190 state->fSerialNo[1] = hexorator(state->fB);
191 state->fSerialNo[2] = hexorator(state->fC);
192 state->fSerialNo[3] = hexorator(state->fD);
193 state->fSerialNo[4] = hexorator(a);
194 state->fSerialNo[5] = hexorator(b);
195 state->fSerialNo[6] = hexorator(c);
196 state->fSerialNo[7] = hexorator(d);
197 state->fSerialNo[8] = '\0';
198 SkDebugf("%s\n", state->fSerialNo);
199 if (strcmp(state->fSerialNo, state->fKey) == 0) {
Cary Clark389c5572017-04-14 07:46:07 -0400200 SkDebugf("%s\n", state->fPathStr.c_str());
caryclark@google.com03610322013-04-18 15:58:21 +0000201 }
202#endif
203}
204
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000205const int bitWidth = 64;
206const int bitHeight = 64;
207
208static void scaleMatrix(const SkPath& one, const SkPath& two, SkMatrix& scale) {
209 SkRect larger = one.getBounds();
210 larger.join(two.getBounds());
211 SkScalar largerWidth = larger.width();
212 if (largerWidth < 4) {
213 largerWidth = 4;
214 }
215 SkScalar largerHeight = larger.height();
216 if (largerHeight < 4) {
217 largerHeight = 4;
218 }
219 SkScalar hScale = (bitWidth - 2) / largerWidth;
220 SkScalar vScale = (bitHeight - 2) / largerHeight;
221 scale.reset();
222 scale.preScale(hScale, vScale);
caryclark26ad22a2015-10-16 09:03:38 -0700223 larger.fLeft *= hScale;
224 larger.fRight *= hScale;
225 larger.fTop *= vScale;
226 larger.fBottom *= vScale;
227 SkScalar dx = -16000 > larger.fLeft ? -16000 - larger.fLeft
228 : 16000 < larger.fRight ? 16000 - larger.fRight : 0;
229 SkScalar dy = -16000 > larger.fTop ? -16000 - larger.fTop
230 : 16000 < larger.fBottom ? 16000 - larger.fBottom : 0;
231 scale.postTranslate(dx, dy);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000232}
233
234static int pathsDrawTheSame(SkBitmap& bits, const SkPath& scaledOne, const SkPath& scaledTwo,
235 int& error2x2) {
236 if (bits.width() == 0) {
mike@reedtribe.orgdeee4962014-02-13 14:41:43 +0000237 bits.allocN32Pixels(bitWidth * 2, bitHeight);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000238 }
239 SkCanvas canvas(bits);
240 canvas.drawColor(SK_ColorWHITE);
241 SkPaint paint;
242 canvas.save();
243 const SkRect& bounds1 = scaledOne.getBounds();
244 canvas.translate(-bounds1.fLeft + 1, -bounds1.fTop + 1);
245 canvas.drawPath(scaledOne, paint);
246 canvas.restore();
247 canvas.save();
248 canvas.translate(-bounds1.fLeft + 1 + bitWidth, -bounds1.fTop + 1);
249 canvas.drawPath(scaledTwo, paint);
250 canvas.restore();
251 int errors2 = 0;
252 int errors = 0;
253 for (int y = 0; y < bitHeight - 1; ++y) {
254 uint32_t* addr1 = bits.getAddr32(0, y);
255 uint32_t* addr2 = bits.getAddr32(0, y + 1);
256 uint32_t* addr3 = bits.getAddr32(bitWidth, y);
257 uint32_t* addr4 = bits.getAddr32(bitWidth, y + 1);
258 for (int x = 0; x < bitWidth - 1; ++x) {
259 // count 2x2 blocks
260 bool err = addr1[x] != addr3[x];
261 if (err) {
262 errors2 += addr1[x + 1] != addr3[x + 1]
263 && addr2[x] != addr4[x] && addr2[x + 1] != addr4[x + 1];
264 errors++;
265 }
266 }
267 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000268 error2x2 = errors2;
269 return errors;
270}
271
272static int pathsDrawTheSame(const SkPath& one, const SkPath& two, SkBitmap& bits, SkPath& scaledOne,
273 SkPath& scaledTwo, int& error2x2) {
274 SkMatrix scale;
275 scaleMatrix(one, two, scale);
276 one.transform(scale, &scaledOne);
277 two.transform(scale, &scaledTwo);
278 return pathsDrawTheSame(bits, scaledOne, scaledTwo, error2x2);
279}
280
281bool drawAsciiPaths(const SkPath& one, const SkPath& two, bool drawPaths) {
282 if (!drawPaths) {
283 return true;
284 }
285 const SkRect& bounds1 = one.getBounds();
286 const SkRect& bounds2 = two.getBounds();
287 SkRect larger = bounds1;
288 larger.join(bounds2);
289 SkBitmap bits;
290 char out[256];
reed@google.come1ca7052013-12-17 19:22:07 +0000291 int bitWidth = SkScalarCeilToInt(larger.width()) + 2;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000292 if (bitWidth * 2 + 1 >= (int) sizeof(out)) {
293 return false;
294 }
reed@google.come1ca7052013-12-17 19:22:07 +0000295 int bitHeight = SkScalarCeilToInt(larger.height()) + 2;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000296 if (bitHeight >= (int) sizeof(out)) {
297 return false;
298 }
mike@reedtribe.orgdeee4962014-02-13 14:41:43 +0000299 bits.allocN32Pixels(bitWidth * 2, bitHeight);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000300 SkCanvas canvas(bits);
301 canvas.drawColor(SK_ColorWHITE);
302 SkPaint paint;
303 canvas.save();
304 canvas.translate(-bounds1.fLeft + 1, -bounds1.fTop + 1);
305 canvas.drawPath(one, paint);
306 canvas.restore();
307 canvas.save();
308 canvas.translate(-bounds1.fLeft + 1 + bitWidth, -bounds1.fTop + 1);
309 canvas.drawPath(two, paint);
310 canvas.restore();
311 for (int y = 0; y < bitHeight; ++y) {
312 uint32_t* addr1 = bits.getAddr32(0, y);
313 int x;
314 char* outPtr = out;
315 for (x = 0; x < bitWidth; ++x) {
316 *outPtr++ = addr1[x] == (uint32_t) -1 ? '_' : 'x';
317 }
318 *outPtr++ = '|';
319 for (x = bitWidth; x < bitWidth * 2; ++x) {
320 *outPtr++ = addr1[x] == (uint32_t) -1 ? '_' : 'x';
321 }
322 *outPtr++ = '\0';
323 SkDebugf("%s\n", out);
324 }
325 return true;
326}
327
caryclark54359292015-03-26 07:52:43 -0700328int comparePaths(skiatest::Reporter* reporter, const char* filename, const SkPath& one,
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000329 const SkPath& two, SkBitmap& bitmap) {
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000330 int errors2x2;
331 SkPath scaledOne, scaledTwo;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000332 (void) pathsDrawTheSame(one, two, bitmap, scaledOne, scaledTwo, errors2x2);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000333 if (errors2x2 == 0) {
334 return 0;
335 }
336 const int MAX_ERRORS = 9;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000337 return errors2x2 > MAX_ERRORS ? errors2x2 : 0;
338}
339
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000340static SkTDArray<SkPathOp> gTestOp;
341
Cary Clark59d5a0e2017-01-23 14:38:52 +0000342static void showPathOpPath(const char* testName, const SkPath& one, const SkPath& two,
343 const SkPath& a, const SkPath& b, const SkPath& scaledOne, const SkPath& scaledTwo,
344 const SkPathOp shapeOp, const SkMatrix& scale) {
345 SkASSERT((unsigned) shapeOp < SK_ARRAY_COUNT(opStrs));
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000346 if (!testName) {
caryclark1049f122015-04-20 08:31:59 -0700347 testName = "xOp";
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000348 }
caryclark2bec26a2016-05-26 09:01:47 -0700349 SkDebugf("static void %s_%s(skiatest::Reporter* reporter, const char* filename) {\n",
350 testName, opSuffixes[shapeOp]);
Cary Clark59d5a0e2017-01-23 14:38:52 +0000351 *gTestOp.append() = shapeOp;
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000352 SkDebugf(" SkPath path, pathB;\n");
caryclark19eb3b22014-07-18 05:08:14 -0700353 SkPathOpsDebug::ShowOnePath(a, "path", false);
354 SkPathOpsDebug::ShowOnePath(b, "pathB", false);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000355 SkDebugf(" testPathOp(reporter, path, pathB, %s, filename);\n", opStrs[shapeOp]);
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000356 SkDebugf("}\n");
caryclark26ad22a2015-10-16 09:03:38 -0700357 drawAsciiPaths(scaledOne, scaledTwo, true);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000358}
359
reed086eea92016-05-04 17:12:46 -0700360SK_DECLARE_STATIC_MUTEX(compareDebugOut3);
caryclark38a017b2015-05-13 10:13:17 -0700361
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000362static int comparePaths(skiatest::Reporter* reporter, const char* testName, const SkPath& one,
363 const SkPath& scaledOne, const SkPath& two, const SkPath& scaledTwo, SkBitmap& bitmap,
caryclark65f55312014-11-13 06:58:52 -0800364 const SkPath& a, const SkPath& b, const SkPathOp shapeOp, const SkMatrix& scale,
caryclarkd5b91732016-08-09 05:04:29 -0700365 ExpectMatch expectMatch) {
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000366 int errors2x2;
caryclark65f55312014-11-13 06:58:52 -0800367 const int MAX_ERRORS = 8;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000368 (void) pathsDrawTheSame(bitmap, scaledOne, scaledTwo, errors2x2);
caryclarkd5b91732016-08-09 05:04:29 -0700369 if (ExpectMatch::kNo == expectMatch) {
caryclark38a017b2015-05-13 10:13:17 -0700370 if (errors2x2 < MAX_ERRORS) {
caryclark65f55312014-11-13 06:58:52 -0800371 REPORTER_ASSERT(reporter, 0);
372 }
373 return 0;
374 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000375 if (errors2x2 == 0) {
376 return 0;
377 }
caryclarkd5b91732016-08-09 05:04:29 -0700378 if (ExpectMatch::kYes == expectMatch && errors2x2 >= MAX_ERRORS) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000379 SkAutoMutexAcquire autoM(compareDebugOut3);
380 showPathOpPath(testName, one, two, a, b, scaledOne, scaledTwo, shapeOp, scale);
caryclarkaec25102015-04-29 08:28:30 -0700381 SkDebugf("\n/*");
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000382 REPORTER_ASSERT(reporter, 0);
caryclarkaec25102015-04-29 08:28:30 -0700383 SkDebugf(" */\n");
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000384 }
caryclark38a017b2015-05-13 10:13:17 -0700385 return errors2x2 >= MAX_ERRORS ? errors2x2 : 0;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000386}
387
commit-bot@chromium.org409774e2013-10-02 16:15:44 +0000388// Default values for when reporter->verbose() is false.
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000389static int testNumber = 55;
commit-bot@chromium.org409774e2013-10-02 16:15:44 +0000390static const char* testName = "pathOpTest";
caryclark@google.com66089e42013-04-10 15:55:37 +0000391
Cary Clark389c5572017-04-14 07:46:07 -0400392static void appendTestName(const char* nameSuffix, std::string& out) {
393 out += testName;
394 out += std_to_string(testNumber);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000395 ++testNumber;
caryclark@google.com66089e42013-04-10 15:55:37 +0000396 if (nameSuffix) {
Ben Wagner561c1b02017-01-09 15:54:34 -0500397 out.append(nameSuffix);
caryclark@google.com66089e42013-04-10 15:55:37 +0000398 }
399}
400
Ben Wagner561c1b02017-01-09 15:54:34 -0500401static void appendTest(const char* pathStr, const char* pathPrefix, const char* nameSuffix,
Cary Clark389c5572017-04-14 07:46:07 -0400402 const char* testFunction, bool twoPaths, std::string& out) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000403#if 0
Ben Wagner561c1b02017-01-09 15:54:34 -0500404 out.append("\n<div id=\"");
405 appendTestName(nameSuffix, out);
406 out.append("\">\n");
caryclark@google.com66089e42013-04-10 15:55:37 +0000407 if (pathPrefix) {
Ben Wagner561c1b02017-01-09 15:54:34 -0500408 out.append(pathPrefix);
caryclark@google.com66089e42013-04-10 15:55:37 +0000409 }
Ben Wagner561c1b02017-01-09 15:54:34 -0500410 out.append(pathStr);
411 out.append("</div>\n\n");
caryclark@google.com66089e42013-04-10 15:55:37 +0000412
Ben Wagner561c1b02017-01-09 15:54:34 -0500413 out.append(marker);
414 out.append(" ");
415 appendTestName(nameSuffix, out);
416 out.append(",\n\n\n");
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000417#endif
Ben Wagner561c1b02017-01-09 15:54:34 -0500418 out.append("static void ");
419 appendTestName(nameSuffix, out);
420 out.append("(skiatest::Reporter* reporter) {\n SkPath path");
caryclark@google.com66089e42013-04-10 15:55:37 +0000421 if (twoPaths) {
Ben Wagner561c1b02017-01-09 15:54:34 -0500422 out.append(", pathB");
caryclark@google.com66089e42013-04-10 15:55:37 +0000423 }
Ben Wagner561c1b02017-01-09 15:54:34 -0500424 out.append(";\n");
caryclark@google.com66089e42013-04-10 15:55:37 +0000425 if (pathPrefix) {
Ben Wagner561c1b02017-01-09 15:54:34 -0500426 out.append(pathPrefix);
caryclark@google.com66089e42013-04-10 15:55:37 +0000427 }
Cary Clark389c5572017-04-14 07:46:07 -0400428 out += pathStr;
429 out += " ";
430 out += testFunction;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000431#if 0
Ben Wagner561c1b02017-01-09 15:54:34 -0500432 out.append("static void (*firstTest)() = ");
433 appendTestName(nameSuffix, out);
434 out.append(";\n\n");
caryclark@google.com66089e42013-04-10 15:55:37 +0000435
Ben Wagner561c1b02017-01-09 15:54:34 -0500436 out.append("static struct {\n");
437 out.append(" void (*fun)();\n");
438 out.append(" const char* str;\n");
439 out.append("} tests[] = {\n");
440 out.append(" TEST(");
441 appendTestName(nameSuffix, out);
442 out.append("),\n");
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000443#endif
caryclark@google.com66089e42013-04-10 15:55:37 +0000444}
445
Cary Clarkda6289c2018-08-27 16:10:28 -0400446void markTestFlakyForPathKit() {
447 if (PathOpsDebug::gJson) {
448 SkASSERT(!PathOpsDebug::gMarkJsonFlaky);
449 PathOpsDebug::gMarkJsonFlaky = true;
450 }
451}
452
reed086eea92016-05-04 17:12:46 -0700453SK_DECLARE_STATIC_MUTEX(simplifyDebugOut);
caryclark54359292015-03-26 07:52:43 -0700454
caryclark@google.com66089e42013-04-10 15:55:37 +0000455bool testSimplify(SkPath& path, bool useXor, SkPath& out, PathOpsThreadState& state,
456 const char* pathStr) {
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000457 SkPath::FillType fillType = useXor ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType;
458 path.setFillType(fillType);
caryclark54359292015-03-26 07:52:43 -0700459 state.fReporter->bumpTestCount();
caryclark@google.com66560ca2013-04-26 19:51:16 +0000460 if (!Simplify(path, &out)) {
461 SkDebugf("%s did not expect failure\n", __FUNCTION__);
462 REPORTER_ASSERT(state.fReporter, 0);
463 return false;
464 }
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000465 if (!state.fReporter->verbose()) {
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000466 return true;
467 }
halcanary96fcdcc2015-08-27 07:41:13 -0700468 int result = comparePaths(state.fReporter, nullptr, path, out, *state.fBitmap);
caryclark54359292015-03-26 07:52:43 -0700469 if (result) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000470 SkAutoMutexAcquire autoM(simplifyDebugOut);
Cary Clark389c5572017-04-14 07:46:07 -0400471 std::string str;
halcanary96fcdcc2015-08-27 07:41:13 -0700472 const char* pathPrefix = nullptr;
473 const char* nameSuffix = nullptr;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000474 if (fillType == SkPath::kEvenOdd_FillType) {
475 pathPrefix = " path.setFillType(SkPath::kEvenOdd_FillType);\n";
476 nameSuffix = "x";
477 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000478 const char testFunction[] = "testSimplify(reporter, path);";
Ben Wagner561c1b02017-01-09 15:54:34 -0500479 appendTest(pathStr, pathPrefix, nameSuffix, testFunction, false, str);
Mike Reedff80c2a2017-01-07 11:16:28 -0500480 SkDebugf("%s", str.c_str());
caryclark@google.com66089e42013-04-10 15:55:37 +0000481 REPORTER_ASSERT(state.fReporter, 0);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000482 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000483 state.fReporter->bumpTestCount();
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000484 return result == 0;
485}
486
Cary Clark4533f3d2018-08-08 09:48:09 -0400487static void json_status(ExpectSuccess expectSuccess, ExpectMatch expectMatch, bool opSucceeded) {
488 fprintf(PathOpsDebug::gOut, " \"expectSuccess\": \"%s\",\n",
489 ExpectSuccess::kNo == expectSuccess ? "no" :
490 ExpectSuccess::kYes == expectSuccess ? "yes" : "flaky");
Cary Clarkda6289c2018-08-27 16:10:28 -0400491 if (PathOpsDebug::gMarkJsonFlaky) {
492 expectMatch = ExpectMatch::kFlaky;
493 PathOpsDebug::gMarkJsonFlaky = false;
494 }
Cary Clark4533f3d2018-08-08 09:48:09 -0400495 fprintf(PathOpsDebug::gOut, " \"expectMatch\": \"%s\",\n",
496 ExpectMatch::kNo == expectMatch ? "no" :
497 ExpectMatch::kYes == expectMatch ? "yes" : "flaky");
498 fprintf(PathOpsDebug::gOut, " \"succeeded\": %s,\n", opSucceeded ? "true" : "false");
499}
500
501static void json_path_out(const SkPath& path, const char* pathName, const char* fillTypeName,
502 bool lastField) {
503 char const * const gFillTypeStrs[] = {
504 "Winding",
505 "EvenOdd",
506 "InverseWinding",
507 "InverseEvenOdd",
508 };
Cary Clark9c9611f2018-08-08 13:17:25 -0400509 if (PathOpsDebug::gOutputSVG) {
510 SkString svg;
511 SkParsePath::ToSVGString(path, &svg);
512 fprintf(PathOpsDebug::gOut, " \"%s\": \"%s\",\n", pathName, svg.c_str());
513 } else {
514 SkPath::RawIter iter(path);
515 SkPath::Verb verb;
516 // MOVE, LINE, QUAD, CONIC, CUBIC, CLOSE
517 const int verbConst[] = { 0, 1, 2, 3, 4, 5 };
518 const int pointIndex[] = { 0, 1, 1, 1, 1, 0 };
519 const int pointCount[] = { 1, 2, 3, 3, 4, 0 };
520 fprintf(PathOpsDebug::gOut, " \"%s\": [", pathName);
521 bool first = true;
522 do {
523 SkPoint points[4];
524 verb = iter.next(points);
525 if (SkPath::kDone_Verb == verb) {
526 break;
527 }
528 if (first) {
529 first = false;
530 } else {
531 fprintf(PathOpsDebug::gOut, ",\n ");
532 }
533 int verbIndex = (int) verb;
534 fprintf(PathOpsDebug::gOut, "[%d", verbConst[verbIndex]);
535 for (int i = pointIndex[verbIndex]; i < pointCount[verbIndex]; ++i) {
536 fprintf(PathOpsDebug::gOut, ", \"0x%08x\", \"0x%08x\"",
537 SkFloat2Bits(points[i].fX), SkFloat2Bits(points[i].fY));
538 }
539 if (SkPath::kConic_Verb == verb) {
540 fprintf(PathOpsDebug::gOut, ", \"0x%08x\"", SkFloat2Bits(iter.conicWeight()));
541 }
542 fprintf(PathOpsDebug::gOut, "]");
543 } while (SkPath::kDone_Verb != verb);
544 fprintf(PathOpsDebug::gOut, "],\n");
545 }
Cary Clark4533f3d2018-08-08 09:48:09 -0400546 fprintf(PathOpsDebug::gOut, " \"fillType%s\": \"k%s_FillType\"%s", fillTypeName,
547 gFillTypeStrs[(int) path.getFillType()], lastField ? "\n}" : ",\n");
548}
549
550static bool check_for_duplicate_names(const char* testName) {
551 if (PathOpsDebug::gCheckForDuplicateNames) {
552 if (gUniqueNames.end() != std::find(gUniqueNames.begin(), gUniqueNames.end(),
553 std::string(testName))) {
554 SkDebugf(""); // convenience for setting breakpoints
555 }
556 gUniqueNames.push_back(std::string(testName));
557 return true;
558 }
559 return false;
560}
561
caryclark54359292015-03-26 07:52:43 -0700562static bool inner_simplify(skiatest::Reporter* reporter, const SkPath& path, const char* filename,
caryclark55888e42016-07-18 10:01:36 -0700563 ExpectSuccess expectSuccess, SkipAssert skipAssert, ExpectMatch expectMatch) {
caryclark54359292015-03-26 07:52:43 -0700564#if 0 && DEBUG_SHOW_TEST_NAME
caryclark@google.com03610322013-04-18 15:58:21 +0000565 showPathData(path);
566#endif
Cary Clark4533f3d2018-08-08 09:48:09 -0400567 if (PathOpsDebug::gJson) {
568 if (check_for_duplicate_names(filename)) {
569 return true;
570 }
571 if (!PathOpsDebug::gOutFirst) {
572 fprintf(PathOpsDebug::gOut, ",\n");
573 }
574 PathOpsDebug::gOutFirst = false;
575 fprintf(PathOpsDebug::gOut, "\"%s\": {\n", filename);
576 json_path_out(path, "path", "", false);
577 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000578 SkPath out;
caryclark55888e42016-07-18 10:01:36 -0700579 if (!SimplifyDebug(path, &out SkDEBUGPARAMS(SkipAssert::kYes == skipAssert)
580 SkDEBUGPARAMS(testName))) {
581 if (ExpectSuccess::kYes == expectSuccess) {
582 SkDebugf("%s did not expect %s failure\n", __FUNCTION__, filename);
583 REPORTER_ASSERT(reporter, 0);
584 }
Cary Clark4533f3d2018-08-08 09:48:09 -0400585 if (PathOpsDebug::gJson) {
586 json_status(expectSuccess, expectMatch, false);
587 fprintf(PathOpsDebug::gOut, " \"out\": \"\"\n}");
588 }
caryclark@google.com66560ca2013-04-26 19:51:16 +0000589 return false;
caryclark55888e42016-07-18 10:01:36 -0700590 } else {
591 if (ExpectSuccess::kNo == expectSuccess) {
592 SkDebugf("%s %s unexpected success\n", __FUNCTION__, filename);
593 REPORTER_ASSERT(reporter, 0);
594 }
Cary Clark4533f3d2018-08-08 09:48:09 -0400595 if (PathOpsDebug::gJson) {
596 json_status(expectSuccess, expectMatch, true);
597 json_path_out(out, "out", "Out", true);
598 }
caryclark@google.com66560ca2013-04-26 19:51:16 +0000599 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000600 SkBitmap bitmap;
caryclark54359292015-03-26 07:52:43 -0700601 int errors = comparePaths(reporter, filename, path, out, bitmap);
caryclark55888e42016-07-18 10:01:36 -0700602 if (ExpectMatch::kNo == expectMatch) {
caryclark54359292015-03-26 07:52:43 -0700603 if (!errors) {
604 SkDebugf("%s failing test %s now succeeds\n", __FUNCTION__, filename);
605 REPORTER_ASSERT(reporter, 0);
606 return false;
607 }
caryclarkd5b91732016-08-09 05:04:29 -0700608 } else if (ExpectMatch::kYes == expectMatch && errors) {
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000609 REPORTER_ASSERT(reporter, 0);
610 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000611 reporter->bumpTestCount();
caryclark54359292015-03-26 07:52:43 -0700612 return errors == 0;
613}
614
615bool testSimplify(skiatest::Reporter* reporter, const SkPath& path, const char* filename) {
caryclark55888e42016-07-18 10:01:36 -0700616 return inner_simplify(reporter, path, filename, ExpectSuccess::kYes, SkipAssert::kNo,
617 ExpectMatch::kYes);
618}
619
caryclark30b9fdd2016-08-31 14:36:29 -0700620bool testSimplifyFuzz(skiatest::Reporter* reporter, const SkPath& path, const char* filename) {
621 return inner_simplify(reporter, path, filename, ExpectSuccess::kFlaky, SkipAssert::kYes,
622 ExpectMatch::kFlaky);
caryclark54359292015-03-26 07:52:43 -0700623}
624
625bool testSimplifyCheck(skiatest::Reporter* reporter, const SkPath& path, const char* filename,
626 bool checkFail) {
caryclark55888e42016-07-18 10:01:36 -0700627 return inner_simplify(reporter, path, filename, checkFail ?
628 ExpectSuccess::kYes : ExpectSuccess::kNo, SkipAssert::kNo, ExpectMatch::kNo);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000629}
630
Cary Clark2587f412018-07-24 12:40:10 -0400631bool testSimplifyFail(skiatest::Reporter* reporter, const SkPath& path, const char* filename) {
632 return inner_simplify(reporter, path, filename,
633 ExpectSuccess::kNo, SkipAssert::kYes, ExpectMatch::kNo);
634}
635
caryclark@google.coma5e55922013-05-07 18:51:31 +0000636#if DEBUG_SHOW_TEST_NAME
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000637static void showName(const SkPath& a, const SkPath& b, const SkPathOp shapeOp) {
638 SkDebugf("\n");
639 showPathData(a);
640 showOp(shapeOp);
641 showPathData(b);
642}
643#endif
644
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000645static bool innerPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
caryclark55888e42016-07-18 10:01:36 -0700646 const SkPathOp shapeOp, const char* testName, ExpectSuccess expectSuccess,
647 SkipAssert skipAssert, ExpectMatch expectMatch) {
caryclark54359292015-03-26 07:52:43 -0700648#if 0 && DEBUG_SHOW_TEST_NAME
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000649 showName(a, b, shapeOp);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000650#endif
Cary Clarkf3949122018-08-07 16:38:21 -0400651 if (PathOpsDebug::gJson) {
Cary Clark4533f3d2018-08-08 09:48:09 -0400652 if (check_for_duplicate_names(testName)) {
653 return true;
654 }
Cary Clarkf3949122018-08-07 16:38:21 -0400655 if (!PathOpsDebug::gOutFirst) {
656 fprintf(PathOpsDebug::gOut, ",\n");
657 }
658 PathOpsDebug::gOutFirst = false;
659 fprintf(PathOpsDebug::gOut, "\"%s\": {\n", testName);
660 json_path_out(a, "p1", "1", false);
661 json_path_out(b, "p2", "2", false);
662 fprintf(PathOpsDebug::gOut, " \"op\": \"%s\",\n", opStrs[shapeOp]);
663 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000664 SkPath out;
caryclark55888e42016-07-18 10:01:36 -0700665 if (!OpDebug(a, b, shapeOp, &out SkDEBUGPARAMS(SkipAssert::kYes == skipAssert)
caryclarkdae6b972016-06-08 04:28:19 -0700666 SkDEBUGPARAMS(testName))) {
caryclark55888e42016-07-18 10:01:36 -0700667 if (ExpectSuccess::kYes == expectSuccess) {
668 SkDebugf("%s %s did not expect failure\n", __FUNCTION__, testName);
caryclark3f0753d2016-06-28 09:23:57 -0700669 REPORTER_ASSERT(reporter, 0);
670 }
Cary Clarkf3949122018-08-07 16:38:21 -0400671 if (PathOpsDebug::gJson) {
672 json_status(expectSuccess, expectMatch, false);
673 fprintf(PathOpsDebug::gOut, " \"out\": \"\"\n}");
674 }
caryclark@google.com66560ca2013-04-26 19:51:16 +0000675 return false;
caryclark55888e42016-07-18 10:01:36 -0700676 } else {
677 if (ExpectSuccess::kNo == expectSuccess) {
678 SkDebugf("%s %s unexpected success\n", __FUNCTION__, testName);
679 REPORTER_ASSERT(reporter, 0);
680 }
Cary Clarkf3949122018-08-07 16:38:21 -0400681 if (PathOpsDebug::gJson) {
682 json_status(expectSuccess, expectMatch, true);
683 json_path_out(out, "out", "Out", true);
684 }
caryclark@google.com66560ca2013-04-26 19:51:16 +0000685 }
caryclark54359292015-03-26 07:52:43 -0700686 if (!reporter->verbose()) {
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000687 return true;
688 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000689 SkPath pathOut, scaledPathOut;
690 SkRegion rgnA, rgnB, openClip, rgnOut;
691 openClip.setRect(-16000, -16000, 16000, 16000);
692 rgnA.setPath(a, openClip);
693 rgnB.setPath(b, openClip);
694 rgnOut.op(rgnA, rgnB, (SkRegion::Op) shapeOp);
695 rgnOut.getBoundaryPath(&pathOut);
696
697 SkMatrix scale;
698 scaleMatrix(a, b, scale);
699 SkRegion scaledRgnA, scaledRgnB, scaledRgnOut;
700 SkPath scaledA, scaledB;
701 scaledA.addPath(a, scale);
702 scaledA.setFillType(a.getFillType());
703 scaledB.addPath(b, scale);
704 scaledB.setFillType(b.getFillType());
705 scaledRgnA.setPath(scaledA, openClip);
706 scaledRgnB.setPath(scaledB, openClip);
707 scaledRgnOut.op(scaledRgnA, scaledRgnB, (SkRegion::Op) shapeOp);
708 scaledRgnOut.getBoundaryPath(&scaledPathOut);
709 SkBitmap bitmap;
710 SkPath scaledOut;
711 scaledOut.addPath(out, scale);
712 scaledOut.setFillType(out.getFillType());
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000713 int result = comparePaths(reporter, testName, pathOut, scaledPathOut, out, scaledOut, bitmap,
caryclarkd5b91732016-08-09 05:04:29 -0700714 a, b, shapeOp, scale, expectMatch);
caryclark@google.com66089e42013-04-10 15:55:37 +0000715 reporter->bumpTestCount();
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000716 return result == 0;
717}
718
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000719bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
caryclark65f55312014-11-13 06:58:52 -0800720 const SkPathOp shapeOp, const char* testName) {
caryclark55888e42016-07-18 10:01:36 -0700721 return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kYes, SkipAssert::kNo,
722 ExpectMatch::kYes);
caryclark65f55312014-11-13 06:58:52 -0800723}
724
725bool testPathOpCheck(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
726 const SkPathOp shapeOp, const char* testName, bool checkFail) {
caryclark55888e42016-07-18 10:01:36 -0700727 return innerPathOp(reporter, a, b, shapeOp, testName, checkFail ?
728 ExpectSuccess::kYes : ExpectSuccess::kNo, SkipAssert::kNo, ExpectMatch::kNo);
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000729}
730
caryclark30b9fdd2016-08-31 14:36:29 -0700731bool testPathOpFuzz(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
caryclarkd5b91732016-08-09 05:04:29 -0700732 const SkPathOp shapeOp, const char* testName) {
733 return innerPathOp(reporter, a, b, shapeOp, testName, ExpectSuccess::kFlaky, SkipAssert::kYes,
734 ExpectMatch::kFlaky);
735}
736
Cary Clark59d5a0e2017-01-23 14:38:52 +0000737bool testPathOpFail(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b,
738 const SkPathOp shapeOp, const char* testName) {
739#if DEBUG_SHOW_TEST_NAME
740 showName(a, b, shapeOp);
741#endif
742 SkPath orig;
743 orig.lineTo(54, 43);
744 SkPath out = orig;
745 if (Op(a, b, shapeOp, &out) ) {
746 SkDebugf("%s test is expected to fail\n", __FUNCTION__);
747 REPORTER_ASSERT(reporter, 0);
748 return false;
749 }
750 SkASSERT(out == orig);
751 return true;
752}
753
reed086eea92016-05-04 17:12:46 -0700754SK_DECLARE_STATIC_MUTEX(gMutex);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000755
mtklein406654b2014-09-03 15:34:37 -0700756void initializeTests(skiatest::Reporter* reporter, const char* test) {
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000757 if (reporter->verbose()) {
758 SkAutoMutexAcquire lock(gMutex);
759 testName = test;
760 size_t testNameSize = strlen(test);
761 SkFILEStream inFile("../../experimental/Intersection/op.htm");
762 if (inFile.isValid()) {
763 SkTDArray<char> inData;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000764 inData.setCount((int) inFile.getLength());
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000765 size_t inLen = inData.count();
766 inFile.read(inData.begin(), inLen);
Ben Wagner4d1955c2017-03-10 13:08:15 -0500767 inFile.close();
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000768 char* insert = strstr(inData.begin(), marker);
769 if (insert) {
770 insert += sizeof(marker) - 1;
771 const char* numLoc = insert + 4 /* indent spaces */ + testNameSize - 1;
772 testNumber = atoi(numLoc) + 1;
773 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000774 }
775 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000776}
777
Mike Reedff80c2a2017-01-07 11:16:28 -0500778void PathOpsThreadState::outputProgress(const char* pathStr, SkPath::FillType pathFillType) {
caryclark@google.com66089e42013-04-10 15:55:37 +0000779 const char testFunction[] = "testSimplify(path);";
halcanary96fcdcc2015-08-27 07:41:13 -0700780 const char* pathPrefix = nullptr;
781 const char* nameSuffix = nullptr;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000782 if (pathFillType == SkPath::kEvenOdd_FillType) {
783 pathPrefix = " path.setFillType(SkPath::kEvenOdd_FillType);\n";
784 nameSuffix = "x";
785 }
Ben Wagner561c1b02017-01-09 15:54:34 -0500786 appendTest(pathStr, pathPrefix, nameSuffix, testFunction, false, fPathStr);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000787}
788
Mike Reedff80c2a2017-01-07 11:16:28 -0500789void PathOpsThreadState::outputProgress(const char* pathStr, SkPathOp op) {
caryclark@google.com66089e42013-04-10 15:55:37 +0000790 const char testFunction[] = "testOp(path);";
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000791 SkASSERT((size_t) op < SK_ARRAY_COUNT(opSuffixes));
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000792 const char* nameSuffix = opSuffixes[op];
Ben Wagner561c1b02017-01-09 15:54:34 -0500793 appendTest(pathStr, nullptr, nameSuffix, testFunction, true, fPathStr);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000794}
795
796void RunTestSet(skiatest::Reporter* reporter, TestDesc tests[], size_t count,
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000797 void (*firstTest)(skiatest::Reporter* , const char* filename),
caryclark54359292015-03-26 07:52:43 -0700798 void (*skipTest)(skiatest::Reporter* , const char* filename),
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000799 void (*stopTest)(skiatest::Reporter* , const char* filename), bool reverse) {
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000800 size_t index;
801 if (firstTest) {
802 index = count - 1;
803 while (index > 0 && tests[index].fun != firstTest) {
804 --index;
805 }
caryclark@google.coma5e55922013-05-07 18:51:31 +0000806#if DEBUG_SHOW_TEST_NAME
caryclark54359292015-03-26 07:52:43 -0700807 SkDebugf("\n<div id=\"%s\">\n", tests[index].str);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000808#endif
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000809 (*tests[index].fun)(reporter, tests[index].str);
810 if (tests[index].fun == stopTest) {
811 return;
812 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000813 }
814 index = reverse ? count - 1 : 0;
815 size_t last = reverse ? 0 : count - 1;
caryclark54359292015-03-26 07:52:43 -0700816 bool foundSkip = !skipTest;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000817 do {
caryclark54359292015-03-26 07:52:43 -0700818 if (tests[index].fun == skipTest) {
819 foundSkip = true;
820 }
821 if (foundSkip && tests[index].fun != firstTest) {
caryclark@google.coma5e55922013-05-07 18:51:31 +0000822 #if DEBUG_SHOW_TEST_NAME
caryclark54359292015-03-26 07:52:43 -0700823 SkDebugf("\n<div id=\"%s\">\n", tests[index].str);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000824 #endif
caryclark30b9fdd2016-08-31 14:36:29 -0700825 (*tests[index].fun)(reporter, tests[index].str);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000826 }
caryclark03b03ca2015-04-23 09:13:37 -0700827 if (tests[index].fun == stopTest || index == last) {
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000828 break;
829 }
830 index += reverse ? -1 : 1;
831 } while (true);
caryclark03b03ca2015-04-23 09:13:37 -0700832#if DEBUG_SHOW_TEST_NAME
833 SkDebugf(
834 "\n"
835 "</div>\n"
836 "\n"
837 "<script type=\"text/javascript\">\n"
838 "\n"
839 "var testDivs = [\n"
840 );
841 index = reverse ? count - 1 : 0;
842 last = reverse ? 0 : count - 1;
843 foundSkip = !skipTest;
844 do {
845 if (tests[index].fun == skipTest) {
846 foundSkip = true;
847 }
848 if (foundSkip && tests[index].fun != firstTest) {
849 SkDebugf(" %s,\n", tests[index].str);
850 }
851 if (tests[index].fun == stopTest || index == last) {
852 break;
853 }
854 index += reverse ? -1 : 1;
855 } while (true);
856#endif
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000857}