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 | */ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 7 | #include "include/core/SkString.h" |
| 8 | #include "tests/PathOpsDebug.h" |
| 9 | #include "tests/PathOpsExtendedTest.h" |
| 10 | #include "tests/PathOpsThreadedCommon.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); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 26 | const SkPathFillType fts[] = { SkPathFillType::kWinding, SkPathFillType::kEvenOdd }; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 27 | PathOpsThreadState& state = *data; |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 28 | SkString pathStr; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 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) { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 33 | for (auto e : fts) { |
| 34 | for (auto f : fts) { |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 35 | SkPath pathA, pathB; |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 36 | pathA.setFillType((SkPathFillType) e); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 37 | pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB), |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 38 | SkIntToScalar(state.fB), SkPathDirection::kCW); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 39 | pathA.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD), |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 40 | SkIntToScalar(state.fD), SkPathDirection::kCW); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 41 | pathA.close(); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 42 | pathB.setFillType((SkPathFillType) f); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 43 | pathB.addRect(SkIntToScalar(a), SkIntToScalar(a), SkIntToScalar(b), |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 44 | SkIntToScalar(b), SkPathDirection::kCW); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 45 | pathB.addRect(SkIntToScalar(c), SkIntToScalar(c), SkIntToScalar(d), |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 46 | SkIntToScalar(d), SkPathDirection::kCW); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 47 | pathB.close(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 48 | for (int op = 0 ; op <= kXOR_SkPathOp; ++op) { |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 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;"); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 54 | pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n", |
| 55 | e == SkPathFillType::kWinding ? "Winding" : e == SkPathFillType::kEvenOdd |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 56 | ? "EvenOdd" : "?UNDEFINED"); |
| 57 | pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 58 | " SkPathDirection::kCW);\n", state.fA, state.fA, state.fB, state.fB); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 59 | pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 60 | " SkPathDirection::kCW);\n", state.fC, state.fC, state.fD, state.fD); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 61 | pathStr.appendf(" pathB.setFillType(SkPathFillType::k%s);\n", |
| 62 | f == SkPathFillType::kWinding ? "Winding" : f == SkPathFillType::kEvenOdd |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 63 | ? "EvenOdd" : "?UNDEFINED"); |
| 64 | pathStr.appendf(" pathB.addRect(%d, %d, %d, %d," |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 65 | " SkPathDirection::kCW);\n", a, a, b, b); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 66 | pathStr.appendf(" pathB.addRect(%d, %d, %d, %d," |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 67 | " SkPathDirection::kCW);\n", c, c, d, d); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 68 | pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n", |
| 69 | SkPathOpsDebug::OpStr((SkPathOp) op)); |
| 70 | pathStr.appendf("}\n\n"); |
Mike Reed | ff80c2a | 2017-01-07 11:16:28 -0500 | [diff] [blame] | 71 | state.outputProgress(pathStr.c_str(), (SkPathOp) op); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 72 | } |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 73 | SkString testName; |
| 74 | testName.printf("thread_rects%d", ++gRectsTestNo); |
| 75 | if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) { |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 76 | if (state.fReporter->verbose()) { |
| 77 | ++loopNo; |
| 78 | goto skipToNext; |
| 79 | } |
| 80 | } |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 81 | if (PathOpsDebug::gCheckForDuplicateNames) return; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 82 | } |
| 83 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 84 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 85 | skipToNext: ; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 86 | } |
| 87 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 88 | } |
| 89 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 90 | } |
| 91 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 92 | DEF_TEST(PathOpsRectsThreaded, reporter) { |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 93 | initializeTests(reporter, "testOp"); |
| 94 | PathOpsThreadedTestRunner testRunner(reporter); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 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) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 99 | *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( |
| 100 | &testPathOpsRectsMain, a, b, c, d, &testRunner); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 101 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 102 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 103 | if (!reporter->allowExtendedTest()) goto finish; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 104 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 105 | } |
| 106 | finish: |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 107 | testRunner.render(); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 108 | } |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 109 | |
Cary Clark | 8af4c40 | 2018-08-08 23:22:37 -0400 | [diff] [blame] | 110 | static std::atomic<int> gFastTestNo{0}; |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 111 | |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 112 | static void testPathOpsFastMain(PathOpsThreadState* data) |
| 113 | { |
| 114 | SkASSERT(data); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 115 | const SkPathFillType fts[] = { |
| 116 | SkPathFillType::kWinding, SkPathFillType::kEvenOdd, |
| 117 | SkPathFillType::kInverseWinding, SkPathFillType::kInverseEvenOdd |
| 118 | }; |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 119 | PathOpsThreadState& state = *data; |
| 120 | SkString pathStr; |
| 121 | int step = data->fReporter->allowExtendedTest() ? 2 : 5; |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 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) { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 126 | for (auto e : fts) { |
| 127 | for (auto f : fts) { |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 128 | SkPath pathA, pathB; |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 129 | pathA.setFillType(e); |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 130 | if (a) { |
| 131 | pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB) + c, |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 132 | SkIntToScalar(state.fB), SkPathDirection::kCW); |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 133 | } |
| 134 | pathA.close(); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 135 | pathB.setFillType(f); |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 136 | if (b) { |
| 137 | pathB.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD) + d, |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 138 | SkIntToScalar(state.fD), SkPathDirection::kCW); |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 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;"); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 148 | pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n", fillTypeStr[(int)e]); |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 149 | if (a) { |
| 150 | pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 151 | " SkPathDirection::kCW);\n", state.fA, state.fA, state.fB + c, state.fB); |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 152 | } |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 153 | pathStr.appendf(" path.setFillType(SkPathFillType::k%s);\n", fillTypeStr[(int)f]); |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 154 | if (b) { |
| 155 | pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 156 | " SkPathDirection::kCW);\n", state.fC, state.fC, state.fD + d, state.fD); |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 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 | } |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 163 | SkString testName; |
| 164 | testName.printf("fast%d", ++gFastTestNo); |
| 165 | if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, testName.c_str())) { |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 166 | if (state.fReporter->verbose()) { |
| 167 | ++loopNo; |
| 168 | goto skipToNext; |
| 169 | } |
| 170 | } |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 171 | if (PathOpsDebug::gCheckForDuplicateNames) return; |
Cary Clark | 1bb47df | 2018-06-18 08:53:00 -0400 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | } |
| 175 | skipToNext: ; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | |
| 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 | } |