1 /*
2 * Copyright 2015 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 #include "PathOpsDebug.h"
8 #include "PathOpsExtendedTest.h"
9 #include "PathOpsThreadedCommon.h"
10 #include "SkString.h"
11
12 #include <atomic>
13
14 static int loopNo = 4;
15 static std::atomic<int> gCirclesTestNo{0};
16
testOpCirclesMain(PathOpsThreadState * data)17 static void testOpCirclesMain(PathOpsThreadState* data) {
18 SkASSERT(data);
19 PathOpsThreadState& state = *data;
20 SkString pathStr;
21 for (int a = 0 ; a < 6; ++a) {
22 for (int b = a + 1 ; b < 7; ++b) {
23 for (int c = 0 ; c < 6; ++c) {
24 for (int d = c + 1 ; d < 7; ++d) {
25 for (int e = SkPath::kWinding_FillType ; e <= SkPath::kEvenOdd_FillType; ++e) {
26 for (int f = SkPath::kWinding_FillType ; f <= SkPath::kEvenOdd_FillType; ++f) {
27 SkPath pathA, pathB;
28 pathA.setFillType((SkPath::FillType) e);
29 pathA.addCircle(SkIntToScalar(state.fA), SkIntToScalar(state.fB), SkIntToScalar(state.fC),
30 state.fD ? SkPath::kCW_Direction : SkPath::kCCW_Direction);
31 pathB.setFillType((SkPath::FillType) f);
32 pathB.addCircle(SkIntToScalar(a), SkIntToScalar(b), SkIntToScalar(c),
33 d ? SkPath::kCW_Direction : SkPath::kCCW_Direction);
34 for (int op = 0 ; op <= kXOR_SkPathOp; ++op) {
35 if (state.fReporter->verbose()) {
36 pathStr.printf("static void circlesOp%d(skiatest::Reporter* reporter,"
37 " const char* filename) {\n", loopNo);
38 pathStr.appendf(" SkPath path, pathB;\n");
39 pathStr.appendf(" path.setFillType(SkPath::k%s_FillType);\n",
40 e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType
41 ? "EvenOdd" : "?UNDEFINED");
42 pathStr.appendf(" path.addCircle(%d, %d, %d, %s);\n", state.fA, state.fB,
43 state.fC, state.fD ? "SkPath::kCW_Direction" : "SkPath::kCCW_Direction");
44 pathStr.appendf(" pathB.setFillType(SkPath::k%s_FillType);\n",
45 f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType
46 ? "EvenOdd" : "?UNDEFINED");
47 pathStr.appendf(" pathB.addCircle(%d, %d, %d, %s);\n", a, b,
48 c, d ? "SkPath::kCW_Direction" : "SkPath::kCCW_Direction");
49 pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n",
50 SkPathOpsDebug::OpStr((SkPathOp) op));
51 pathStr.appendf("}\n");
52 state.outputProgress(pathStr.c_str(), (SkPathOp) op);
53 }
54 SkString testName;
55 testName.printf("thread_circles%d", ++gCirclesTestNo);
56 if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
57 if (state.fReporter->verbose()) {
58 ++loopNo;
59 goto skipToNext;
60 }
61 }
62 if (PathOpsDebug::gCheckForDuplicateNames) return;
63 }
64 }
65 }
66 skipToNext: ;
67 }
68 }
69 }
70 }
71 }
72
DEF_TEST(PathOpsOpCircleThreaded,reporter)73 DEF_TEST(PathOpsOpCircleThreaded, reporter) {
74 initializeTests(reporter, "circleOp");
75 PathOpsThreadedTestRunner testRunner(reporter);
76 for (int a = 0; a < 6; ++a) { // outermost
77 for (int b = a + 1; b < 7; ++b) {
78 for (int c = 0 ; c < 6; ++c) {
79 for (int d = 0; d < 2; ++d) {
80 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
81 &testOpCirclesMain, a, b, c, d, &testRunner);
82 }
83 }
84 if (!reporter->allowExtendedTest()) goto finish;
85 }
86 }
87 finish:
88 testRunner.render();
89 }
90