caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 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 | */ |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 7 | #include "PathOpsDebug.h" |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 8 | #include "PathOpsExtendedTest.h" |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 9 | #include "PathOpsThreadedCommon.h" |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 10 | #include "SkString.h" |
Cary Clark | 8af4c40 | 2018-08-08 23:22:37 -0400 | [diff] [blame] | 11 | #include <atomic> |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 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 | |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 20 | static int loopNo = 6; |
Cary Clark | 8af4c40 | 2018-08-08 23:22:37 -0400 | [diff] [blame] | 21 | static std::atomic<int> gRectsTestNo{0}; |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 22 | |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 23 | static void testPathOpsRectsMain(PathOpsThreadState* data) |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 24 | { |
| 25 | SkASSERT(data); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 26 | PathOpsThreadState& state = *data; |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 27 | SkString pathStr; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 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; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 35 | pathA.setFillType((SkPath::FillType) e); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 36 | pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB), |
| 37 | SkIntToScalar(state.fB), SkPath::kCW_Direction); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 38 | pathA.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD), |
| 39 | SkIntToScalar(state.fD), SkPath::kCW_Direction); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 40 | pathA.close(); |
| 41 | pathB.setFillType((SkPath::FillType) f); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 42 | pathB.addRect(SkIntToScalar(a), SkIntToScalar(a), SkIntToScalar(b), |
| 43 | SkIntToScalar(b), SkPath::kCW_Direction); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 44 | pathB.addRect(SkIntToScalar(c), SkIntToScalar(c), SkIntToScalar(d), |
| 45 | SkIntToScalar(d), SkPath::kCW_Direction); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 46 | pathB.close(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 47 | for (int op = 0 ; op <= kXOR_SkPathOp; ++op) { |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 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"); |
Mike Reed | ff80c2a | 2017-01-07 11:16:28 -0500 | [diff] [blame] | 70 | state.outputProgress(pathStr.c_str(), (SkPathOp) op); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 71 | } |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 72 | SkString testName; |
| 73 | testName.printf("thread_rects%d", ++gRectsTestNo); |
| 74 | if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) { |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 75 | if (state.fReporter->verbose()) { |
| 76 | ++loopNo; |
| 77 | goto skipToNext; |
| 78 | } |
| 79 | } |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 80 | if (PathOpsDebug::gCheckForDuplicateNames) return; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 81 | } |
| 82 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 83 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 84 | skipToNext: ; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 85 | } |
| 86 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 87 | } |
| 88 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 89 | } |
| 90 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 91 | DEF_TEST(PathOpsRectsThreaded, reporter) { |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 92 | initializeTests(reporter, "testOp"); |
| 93 | PathOpsThreadedTestRunner testRunner(reporter); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 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) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 98 | *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( |
| 99 | &testPathOpsRectsMain, a, b, c, d, &testRunner); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 100 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 101 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 102 | if (!reporter->allowExtendedTest()) goto finish; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 103 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 104 | } |
| 105 | finish: |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 106 | testRunner.render(); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 107 | } |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 108 | |
Cary Clark | 8af4c40 | 2018-08-08 23:22:37 -0400 | [diff] [blame] | 109 | static std::atomic<int> gFastTestNo{0}; |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 110 | |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 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; |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 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 | } |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 158 | SkString testName; |
| 159 | testName.printf("fast%d", ++gFastTestNo); |
| 160 | if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) { |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 161 | if (state.fReporter->verbose()) { |
| 162 | ++loopNo; |
| 163 | goto skipToNext; |
| 164 | } |
| 165 | } |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 166 | if (PathOpsDebug::gCheckForDuplicateNames) return; |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | } |
| 170 | skipToNext: ; |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 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 | } |