blob: 059ece25544a4f6c95178e0d3d7ee7704d48404e [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 */
Mike Kleinc0bd9f92019-04-23 12:05:21 -05007#include "include/core/SkString.h"
8#include "tests/PathOpsDebug.h"
9#include "tests/PathOpsExtendedTest.h"
10#include "tests/PathOpsThreadedCommon.h"
Cary Clark8af4c402018-08-08 23:22:37 -040011#include <atomic>
caryclark@google.com818b0cc2013-04-08 11:50:46 +000012
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
caryclark8f186432016-10-06 11:46:25 -070020static int loopNo = 6;
Cary Clark8af4c402018-08-08 23:22:37 -040021static std::atomic<int> gRectsTestNo{0};
caryclark8f186432016-10-06 11:46:25 -070022
caryclark@google.com66089e42013-04-10 15:55:37 +000023static void testPathOpsRectsMain(PathOpsThreadState* data)
caryclark@google.com818b0cc2013-04-08 11:50:46 +000024{
25 SkASSERT(data);
caryclark@google.com66089e42013-04-10 15:55:37 +000026 PathOpsThreadState& state = *data;
caryclark8f186432016-10-06 11:46:25 -070027 SkString pathStr;
caryclark@google.com66089e42013-04-10 15:55:37 +000028 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;
caryclark@google.com66089e42013-04-10 15:55:37 +000035 pathA.setFillType((SkPath::FillType) e);
caryclark@google.com66089e42013-04-10 15:55:37 +000036 pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB),
37 SkIntToScalar(state.fB), SkPath::kCW_Direction);
caryclark@google.com66089e42013-04-10 15:55:37 +000038 pathA.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD),
39 SkIntToScalar(state.fD), SkPath::kCW_Direction);
caryclark@google.com66089e42013-04-10 15:55:37 +000040 pathA.close();
41 pathB.setFillType((SkPath::FillType) f);
caryclark@google.com66089e42013-04-10 15:55:37 +000042 pathB.addRect(SkIntToScalar(a), SkIntToScalar(a), SkIntToScalar(b),
43 SkIntToScalar(b), SkPath::kCW_Direction);
caryclark@google.com66089e42013-04-10 15:55:37 +000044 pathB.addRect(SkIntToScalar(c), SkIntToScalar(c), SkIntToScalar(d),
45 SkIntToScalar(d), SkPath::kCW_Direction);
caryclark@google.com66089e42013-04-10 15:55:37 +000046 pathB.close();
caryclark54359292015-03-26 07:52:43 -070047 for (int op = 0 ; op <= kXOR_SkPathOp; ++op) {
caryclark8f186432016-10-06 11:46:25 -070048 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");
Mike Reedff80c2a2017-01-07 11:16:28 -050070 state.outputProgress(pathStr.c_str(), (SkPathOp) op);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000071 }
Cary Clark4533f3d2018-08-08 09:48:09 -040072 SkString testName;
73 testName.printf("thread_rects%d", ++gRectsTestNo);
74 if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
caryclark8f186432016-10-06 11:46:25 -070075 if (state.fReporter->verbose()) {
76 ++loopNo;
77 goto skipToNext;
78 }
79 }
Cary Clark4533f3d2018-08-08 09:48:09 -040080 if (PathOpsDebug::gCheckForDuplicateNames) return;
caryclark@google.com66089e42013-04-10 15:55:37 +000081 }
82 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000083 }
caryclark8f186432016-10-06 11:46:25 -070084skipToNext: ;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000085 }
86 }
caryclark@google.com66089e42013-04-10 15:55:37 +000087 }
88 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000089}
90
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000091DEF_TEST(PathOpsRectsThreaded, reporter) {
mtklein406654b2014-09-03 15:34:37 -070092 initializeTests(reporter, "testOp");
93 PathOpsThreadedTestRunner testRunner(reporter);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000094 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) {
halcanary385fe4d2015-08-26 13:07:48 -070098 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
99 &testPathOpsRectsMain, a, b, c, d, &testRunner);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000100 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000101 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000102 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000103 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000104 }
105finish:
caryclark@google.com66089e42013-04-10 15:55:37 +0000106 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000107}
Cary Clark1bb47df2018-06-18 08:53:00 -0400108
Cary Clark8af4c402018-08-08 23:22:37 -0400109static std::atomic<int> gFastTestNo{0};
Cary Clark4533f3d2018-08-08 09:48:09 -0400110
Cary Clark1bb47df2018-06-18 08:53:00 -0400111static void testPathOpsFastMain(PathOpsThreadState* data)
112{
113 SkASSERT(data);
114 PathOpsThreadState& state = *data;
115 SkString pathStr;
116 int step = data->fReporter->allowExtendedTest() ? 2 : 5;
Cary Clark1bb47df2018-06-18 08:53:00 -0400117 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 }
Cary Clark4533f3d2018-08-08 09:48:09 -0400158 SkString testName;
159 testName.printf("fast%d", ++gFastTestNo);
160 if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
Cary Clark1bb47df2018-06-18 08:53:00 -0400161 if (state.fReporter->verbose()) {
162 ++loopNo;
163 goto skipToNext;
164 }
165 }
Cary Clark4533f3d2018-08-08 09:48:09 -0400166 if (PathOpsDebug::gCheckForDuplicateNames) return;
Cary Clark1bb47df2018-06-18 08:53:00 -0400167 }
168 }
169 }
170skipToNext: ;
171 }
172 }
173 }
174 }
175}
176
177DEF_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}