blob: b3809e024c120decc0cdcbb3aa00fe156c1ed614 [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);
Mike Reed7d34dc72019-11-26 12:17:17 -050026 const SkPathFillType fts[] = { SkPathFillType::kWinding, SkPathFillType::kEvenOdd };
caryclark@google.com66089e42013-04-10 15:55:37 +000027 PathOpsThreadState& state = *data;
caryclark8f186432016-10-06 11:46:25 -070028 SkString pathStr;
caryclark@google.com66089e42013-04-10 15:55:37 +000029 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) {
Mike Reed7d34dc72019-11-26 12:17:17 -050033 for (auto e : fts) {
34 for (auto f : fts) {
caryclark@google.com66089e42013-04-10 15:55:37 +000035 SkPath pathA, pathB;
Mike Reed7d34dc72019-11-26 12:17:17 -050036 pathA.setFillType((SkPathFillType) e);
caryclark@google.com66089e42013-04-10 15:55:37 +000037 pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB),
Mike Reed30bc5272019-11-22 18:34:02 +000038 SkIntToScalar(state.fB), SkPathDirection::kCW);
caryclark@google.com66089e42013-04-10 15:55:37 +000039 pathA.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD),
Mike Reed30bc5272019-11-22 18:34:02 +000040 SkIntToScalar(state.fD), SkPathDirection::kCW);
caryclark@google.com66089e42013-04-10 15:55:37 +000041 pathA.close();
Mike Reed7d34dc72019-11-26 12:17:17 -050042 pathB.setFillType((SkPathFillType) f);
caryclark@google.com66089e42013-04-10 15:55:37 +000043 pathB.addRect(SkIntToScalar(a), SkIntToScalar(a), SkIntToScalar(b),
Mike Reed30bc5272019-11-22 18:34:02 +000044 SkIntToScalar(b), SkPathDirection::kCW);
caryclark@google.com66089e42013-04-10 15:55:37 +000045 pathB.addRect(SkIntToScalar(c), SkIntToScalar(c), SkIntToScalar(d),
Mike Reed30bc5272019-11-22 18:34:02 +000046 SkIntToScalar(d), SkPathDirection::kCW);
caryclark@google.com66089e42013-04-10 15:55:37 +000047 pathB.close();
caryclark54359292015-03-26 07:52:43 -070048 for (int op = 0 ; op <= kXOR_SkPathOp; ++op) {
caryclark8f186432016-10-06 11:46:25 -070049 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;");
Mike Reed7d34dc72019-11-26 12:17:17 -050054 pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n",
55 e == SkPathFillType::kWinding ? "Winding" : e == SkPathFillType::kEvenOdd
caryclark8f186432016-10-06 11:46:25 -070056 ? "EvenOdd" : "?UNDEFINED");
57 pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
Mike Reed30bc5272019-11-22 18:34:02 +000058 " SkPathDirection::kCW);\n", state.fA, state.fA, state.fB, state.fB);
caryclark8f186432016-10-06 11:46:25 -070059 pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
Mike Reed30bc5272019-11-22 18:34:02 +000060 " SkPathDirection::kCW);\n", state.fC, state.fC, state.fD, state.fD);
Mike Reed7d34dc72019-11-26 12:17:17 -050061 pathStr.appendf(" pathB.setFillType(SkPathFillType::k%s);\n",
62 f == SkPathFillType::kWinding ? "Winding" : f == SkPathFillType::kEvenOdd
caryclark8f186432016-10-06 11:46:25 -070063 ? "EvenOdd" : "?UNDEFINED");
64 pathStr.appendf(" pathB.addRect(%d, %d, %d, %d,"
Mike Reed30bc5272019-11-22 18:34:02 +000065 " SkPathDirection::kCW);\n", a, a, b, b);
caryclark8f186432016-10-06 11:46:25 -070066 pathStr.appendf(" pathB.addRect(%d, %d, %d, %d,"
Mike Reed30bc5272019-11-22 18:34:02 +000067 " SkPathDirection::kCW);\n", c, c, d, d);
caryclark8f186432016-10-06 11:46:25 -070068 pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n",
69 SkPathOpsDebug::OpStr((SkPathOp) op));
70 pathStr.appendf("}\n\n");
Mike Reedff80c2a2017-01-07 11:16:28 -050071 state.outputProgress(pathStr.c_str(), (SkPathOp) op);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000072 }
Cary Clark4533f3d2018-08-08 09:48:09 -040073 SkString testName;
74 testName.printf("thread_rects%d", ++gRectsTestNo);
75 if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
caryclark8f186432016-10-06 11:46:25 -070076 if (state.fReporter->verbose()) {
77 ++loopNo;
78 goto skipToNext;
79 }
80 }
Cary Clark4533f3d2018-08-08 09:48:09 -040081 if (PathOpsDebug::gCheckForDuplicateNames) return;
caryclark@google.com66089e42013-04-10 15:55:37 +000082 }
83 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000084 }
caryclark8f186432016-10-06 11:46:25 -070085skipToNext: ;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000086 }
87 }
caryclark@google.com66089e42013-04-10 15:55:37 +000088 }
89 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000090}
91
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000092DEF_TEST(PathOpsRectsThreaded, reporter) {
mtklein406654b2014-09-03 15:34:37 -070093 initializeTests(reporter, "testOp");
94 PathOpsThreadedTestRunner testRunner(reporter);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000095 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) {
halcanary385fe4d2015-08-26 13:07:48 -070099 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
100 &testPathOpsRectsMain, a, b, c, d, &testRunner);
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000101 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000102 }
caryclark@google.com66089e42013-04-10 15:55:37 +0000103 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000104 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000105 }
106finish:
caryclark@google.com66089e42013-04-10 15:55:37 +0000107 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000108}
Cary Clark1bb47df2018-06-18 08:53:00 -0400109
Cary Clark8af4c402018-08-08 23:22:37 -0400110static std::atomic<int> gFastTestNo{0};
Cary Clark4533f3d2018-08-08 09:48:09 -0400111
Cary Clark1bb47df2018-06-18 08:53:00 -0400112static void testPathOpsFastMain(PathOpsThreadState* data)
113{
114 SkASSERT(data);
Mike Reed7d34dc72019-11-26 12:17:17 -0500115 const SkPathFillType fts[] = {
116 SkPathFillType::kWinding, SkPathFillType::kEvenOdd,
117 SkPathFillType::kInverseWinding, SkPathFillType::kInverseEvenOdd
118 };
Cary Clark1bb47df2018-06-18 08:53:00 -0400119 PathOpsThreadState& state = *data;
120 SkString pathStr;
121 int step = data->fReporter->allowExtendedTest() ? 2 : 5;
Cary Clark1bb47df2018-06-18 08:53:00 -0400122 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) {
Mike Reed7d34dc72019-11-26 12:17:17 -0500126 for (auto e : fts) {
127 for (auto f : fts) {
Cary Clark1bb47df2018-06-18 08:53:00 -0400128 SkPath pathA, pathB;
Mike Reed7d34dc72019-11-26 12:17:17 -0500129 pathA.setFillType(e);
Cary Clark1bb47df2018-06-18 08:53:00 -0400130 if (a) {
131 pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB) + c,
Mike Reed30bc5272019-11-22 18:34:02 +0000132 SkIntToScalar(state.fB), SkPathDirection::kCW);
Cary Clark1bb47df2018-06-18 08:53:00 -0400133 }
134 pathA.close();
Mike Reed7d34dc72019-11-26 12:17:17 -0500135 pathB.setFillType(f);
Cary Clark1bb47df2018-06-18 08:53:00 -0400136 if (b) {
137 pathB.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD) + d,
Mike Reed30bc5272019-11-22 18:34:02 +0000138 SkIntToScalar(state.fD), SkPathDirection::kCW);
Cary Clark1bb47df2018-06-18 08:53:00 -0400139 }
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;");
Mike Reed7d34dc72019-11-26 12:17:17 -0500148 pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n", fillTypeStr[(int)e]);
Cary Clark1bb47df2018-06-18 08:53:00 -0400149 if (a) {
150 pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
Mike Reed30bc5272019-11-22 18:34:02 +0000151 " SkPathDirection::kCW);\n", state.fA, state.fA, state.fB + c, state.fB);
Cary Clark1bb47df2018-06-18 08:53:00 -0400152 }
Mike Reed7d34dc72019-11-26 12:17:17 -0500153 pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n", fillTypeStr[(int)f]);
Cary Clark1bb47df2018-06-18 08:53:00 -0400154 if (b) {
155 pathStr.appendf(" path.addRect(%d, %d, %d, %d,"
Mike Reed30bc5272019-11-22 18:34:02 +0000156 " SkPathDirection::kCW);\n", state.fC, state.fC, state.fD + d, state.fD);
Cary Clark1bb47df2018-06-18 08:53:00 -0400157 }
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 }
Cary Clark4533f3d2018-08-08 09:48:09 -0400163 SkString testName;
164 testName.printf("fast%d", ++gFastTestNo);
165 if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) {
Cary Clark1bb47df2018-06-18 08:53:00 -0400166 if (state.fReporter->verbose()) {
167 ++loopNo;
168 goto skipToNext;
169 }
170 }
Cary Clark4533f3d2018-08-08 09:48:09 -0400171 if (PathOpsDebug::gCheckForDuplicateNames) return;
Cary Clark1bb47df2018-06-18 08:53:00 -0400172 }
173 }
174 }
175skipToNext: ;
176 }
177 }
178 }
179 }
180}
181
182DEF_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}