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