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 #include "include/core/SkString.h"
8 #include "tests/PathOpsDebug.h"
9 #include "tests/PathOpsExtendedTest.h"
10 #include "tests/PathOpsThreadedCommon.h"
11 #include <atomic>
12
13 // four rects, of four sizes
14 // for 3 smaller sizes, tall, wide
15 // top upper mid lower bottom aligned (3 bits, 5 values)
16 // same with x (3 bits, 5 values)
17 // not included, square, tall, wide (2 bits)
18 // cw or ccw (1 bit)
19
20 static int loopNo = 6;
21 static std::atomic<int> gRectsTestNo{0};
22
testPathOpsRectsMain(PathOpsThreadState * data)23 static void testPathOpsRectsMain(PathOpsThreadState* data)
24 {
25 SkASSERT(data);
26 const SkPathFillType fts[] = { SkPathFillType::kWinding, SkPathFillType::kEvenOdd };
27 PathOpsThreadState& state = *data;
28 SkString pathStr;
29 for (int a = 0 ; a < 6; ++a) {
30 for (int b = a + 1 ; b < 7; ++b) {
31 for (int c = 0 ; c < 6; ++c) {
32 for (int d = c + 1 ; d < 7; ++d) {
33 for (auto e : fts) {
34 for (auto f : fts) {
35 SkPath pathA, pathB;
36 pathA.setFillType((SkPathFillType) e);
37 pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB),
38 SkIntToScalar(state.fB), SkPathDirection::kCW);
39 pathA.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD),
40 SkIntToScalar(state.fD), SkPathDirection::kCW);
41 pathA.close();
42 pathB.setFillType((SkPathFillType) f);
43 pathB.addRect(SkIntToScalar(a), SkIntToScalar(a), SkIntToScalar(b),
44 SkIntToScalar(b), SkPathDirection::kCW);
45 pathB.addRect(SkIntToScalar(c), SkIntToScalar(c), SkIntToScalar(d),
46 SkIntToScalar(d), SkPathDirection::kCW);
47 pathB.close();
48 for (int op = 0 ; op <= kXOR_SkPathOp; ++op) {
49 if (state.fReporter->verbose()) {
50 pathStr.printf(
51 "static void rects%d(skiatest::Reporter* reporter,"
52 "const char* filename) {\n", loopNo);
53 pathStr.appendf(" SkPath path, pathB;");
54 pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n",
55 e == SkPathFillType::kWinding ? "Winding" : e == SkPathFillType::kEvenOdd
56 ? "EvenOdd" : "?UNDEFINED");
57 pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
58 " SkPathDirection::kCW);\n", state.fA, state.fA, state.fB, state.fB);
59 pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
60 " SkPathDirection::kCW);\n", state.fC, state.fC, state.fD, state.fD);
61 pathStr.appendf(" pathB.setFillType(SkPathFillType::k%s);\n",
62 f == SkPathFillType::kWinding ? "Winding" : f == SkPathFillType::kEvenOdd
63 ? "EvenOdd" : "?UNDEFINED");
64 pathStr.appendf(" pathB.addRect(%d, %d, %d, %d,"
65 " SkPathDirection::kCW);\n", a, a, b, b);
66 pathStr.appendf(" pathB.addRect(%d, %d, %d, %d,"
67 " SkPathDirection::kCW);\n", c, c, d, d);
68 pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n",
69 SkPathOpsDebug::OpStr((SkPathOp) op));
70 pathStr.appendf("}\n\n");
71 state.outputProgress(pathStr.c_str(), (SkPathOp) op);
72 }
73 SkString testName;
74 testName.printf("thread_rects%d", ++gRectsTestNo);
75 if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
76 if (state.fReporter->verbose()) {
77 ++loopNo;
78 goto skipToNext;
79 }
80 }
81 if (PathOpsDebug::gCheckForDuplicateNames) return;
82 }
83 }
84 }
85 skipToNext: ;
86 }
87 }
88 }
89 }
90 }
91
DEF_TEST(PathOpsRectsThreaded,reporter)92 DEF_TEST(PathOpsRectsThreaded, reporter) {
93 initializeTests(reporter, "testOp");
94 PathOpsThreadedTestRunner testRunner(reporter);
95 for (int a = 0; a < 6; ++a) { // outermost
96 for (int b = a + 1; b < 7; ++b) {
97 for (int c = 0 ; c < 6; ++c) {
98 for (int d = c + 1; d < 7; ++d) {
99 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
100 &testPathOpsRectsMain, a, b, c, d, &testRunner);
101 }
102 }
103 if (!reporter->allowExtendedTest()) goto finish;
104 }
105 }
106 finish:
107 testRunner.render();
108 }
109
110 static std::atomic<int> gFastTestNo{0};
111
testPathOpsFastMain(PathOpsThreadState * data)112 static void testPathOpsFastMain(PathOpsThreadState* data)
113 {
114 SkASSERT(data);
115 const SkPathFillType fts[] = {
116 SkPathFillType::kWinding, SkPathFillType::kEvenOdd,
117 SkPathFillType::kInverseWinding, SkPathFillType::kInverseEvenOdd
118 };
119 PathOpsThreadState& state = *data;
120 SkString pathStr;
121 int step = data->fReporter->allowExtendedTest() ? 2 : 5;
122 for (bool a : { false, true } ) {
123 for (bool b : { false, true } ) {
124 for (int c = 0; c < 6; c += step) {
125 for (int d = 0; d < 6; d += step) {
126 for (auto e : fts) {
127 for (auto f : fts) {
128 SkPath pathA, pathB;
129 pathA.setFillType(e);
130 if (a) {
131 pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB) + c,
132 SkIntToScalar(state.fB), SkPathDirection::kCW);
133 }
134 pathA.close();
135 pathB.setFillType(f);
136 if (b) {
137 pathB.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD) + d,
138 SkIntToScalar(state.fD), SkPathDirection::kCW);
139 }
140 pathB.close();
141 const char* fillTypeStr[] = { "Winding", "EvenOdd", "InverseWinding", "InverseEvenOdd" };
142 for (int op = 0; op <= kXOR_SkPathOp; ++op) {
143 if (state.fReporter->verbose()) {
144 pathStr.printf(
145 "static void fast%d(skiatest::Reporter* reporter,"
146 "const char* filename) {\n", loopNo);
147 pathStr.appendf(" SkPath path, pathB;");
148 pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n", fillTypeStr[(int)e]);
149 if (a) {
150 pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
151 " SkPathDirection::kCW);\n", state.fA, state.fA, state.fB + c, state.fB);
152 }
153 pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n", fillTypeStr[(int)f]);
154 if (b) {
155 pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
156 " SkPathDirection::kCW);\n", state.fC, state.fC, state.fD + d, state.fD);
157 }
158 pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n",
159 SkPathOpsDebug::OpStr((SkPathOp) op));
160 pathStr.appendf("}\n\n");
161 state.outputProgress(pathStr.c_str(), (SkPathOp) op);
162 }
163 SkString testName;
164 testName.printf("fast%d", ++gFastTestNo);
165 if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
166 if (state.fReporter->verbose()) {
167 ++loopNo;
168 goto skipToNext;
169 }
170 }
171 if (PathOpsDebug::gCheckForDuplicateNames) return;
172 }
173 }
174 }
175 skipToNext: ;
176 }
177 }
178 }
179 }
180 }
181
DEF_TEST(PathOpsFastThreaded,reporter)182 DEF_TEST(PathOpsFastThreaded, reporter) {
183 initializeTests(reporter, "testOp");
184 PathOpsThreadedTestRunner testRunner(reporter);
185 int step = reporter->allowExtendedTest() ? 2 : 5;
186 for (int a = 0; a < 6; a += step) { // outermost
187 for (int b = a + 1; b < 7; b += step) {
188 for (int c = 0 ; c < 6; c += step) {
189 for (int d = c + 1; d < 7; d += step) {
190 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
191 &testPathOpsFastMain, a, b, c, d, &testRunner);
192 }
193 }
194 }
195 }
196 testRunner.render();
197 }
198