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 | */ |
Hal Canary | 50dbc09 | 2018-06-12 14:50:37 -0400 | [diff] [blame] | 7 | |
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" |
Hal Canary | 50dbc09 | 2018-06-12 14:50:37 -0400 | [diff] [blame] | 10 | #include "SkMacros.h" |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 11 | #include "SkString.h" |
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@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 20 | static void testSimplify4x4RectsMain(PathOpsThreadState* data) |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 21 | { |
| 22 | SkASSERT(data); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 23 | PathOpsThreadState& state = *data; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 24 | int aShape = state.fA & 0x03; |
| 25 | SkPath::Direction aCW = state.fA >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction; |
| 26 | int bShape = state.fB & 0x03; |
| 27 | SkPath::Direction bCW = state.fB >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction; |
| 28 | int cShape = state.fC & 0x03; |
| 29 | SkPath::Direction cCW = state.fC >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction; |
| 30 | int dShape = state.fD & 0x03; |
| 31 | SkPath::Direction dCW = state.fD >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction; |
| 32 | for (int aXAlign = 0; aXAlign < 5; ++aXAlign) { |
| 33 | for (int aYAlign = 0; aYAlign < 5; ++aYAlign) { |
| 34 | for (int bXAlign = 0; bXAlign < 5; ++bXAlign) { |
| 35 | for (int bYAlign = 0; bYAlign < 5; ++bYAlign) { |
| 36 | for (int cXAlign = 0; cXAlign < 5; ++cXAlign) { |
| 37 | for (int cYAlign = 0; cYAlign < 5; ++cYAlign) { |
| 38 | for (int dXAlign = 0; dXAlign < 5; ++dXAlign) { |
| 39 | for (int dYAlign = 0; dYAlign < 5; ++dYAlign) { |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 40 | SkString pathStr; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 41 | SkPath path, out; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 42 | path.setFillType(SkPath::kWinding_FillType); |
robertphillips | 73add93 | 2016-04-07 09:01:20 -0700 | [diff] [blame] | 43 | int l SK_INIT_TO_AVOID_WARNING, t SK_INIT_TO_AVOID_WARNING, |
| 44 | r SK_INIT_TO_AVOID_WARNING, b SK_INIT_TO_AVOID_WARNING; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 45 | if (aShape) { |
| 46 | switch (aShape) { |
| 47 | case 1: // square |
| 48 | l = 0; r = 60; |
| 49 | t = 0; b = 60; |
| 50 | aXAlign = 5; |
| 51 | aYAlign = 5; |
| 52 | break; |
| 53 | case 2: |
| 54 | l = aXAlign * 12; |
| 55 | r = l + 30; |
| 56 | t = 0; b = 60; |
| 57 | aYAlign = 5; |
| 58 | break; |
| 59 | case 3: |
| 60 | l = 0; r = 60; |
| 61 | t = aYAlign * 12; |
| 62 | b = l + 30; |
| 63 | aXAlign = 5; |
| 64 | break; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 65 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 66 | path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b), |
| 67 | aCW); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 68 | if (state.fReporter->verbose()) { |
| 69 | pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 70 | " SkPath::kC%sW_Direction);\n", l, t, r, b, aCW ? "C" : ""); |
| 71 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 72 | } else { |
| 73 | aXAlign = 5; |
| 74 | aYAlign = 5; |
| 75 | } |
| 76 | if (bShape) { |
| 77 | switch (bShape) { |
| 78 | case 1: // square |
| 79 | l = bXAlign * 10; |
| 80 | r = l + 20; |
| 81 | t = bYAlign * 10; |
| 82 | b = l + 20; |
| 83 | break; |
| 84 | case 2: |
| 85 | l = bXAlign * 10; |
| 86 | r = l + 20; |
| 87 | t = 10; b = 40; |
| 88 | bYAlign = 5; |
| 89 | break; |
| 90 | case 3: |
| 91 | l = 10; r = 40; |
| 92 | t = bYAlign * 10; |
| 93 | b = l + 20; |
| 94 | bXAlign = 5; |
| 95 | break; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 96 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 97 | path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b), |
| 98 | bCW); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 99 | if (state.fReporter->verbose()) { |
| 100 | pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 101 | " SkPath::kC%sW_Direction);\n", l, t, r, b, bCW ? "C" : ""); |
| 102 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 103 | } else { |
| 104 | bXAlign = 5; |
| 105 | bYAlign = 5; |
| 106 | } |
| 107 | if (cShape) { |
| 108 | switch (cShape) { |
| 109 | case 1: // square |
| 110 | l = cXAlign * 6; |
| 111 | r = l + 12; |
| 112 | t = cYAlign * 6; |
| 113 | b = l + 12; |
| 114 | break; |
| 115 | case 2: |
| 116 | l = cXAlign * 6; |
| 117 | r = l + 12; |
| 118 | t = 20; b = 30; |
| 119 | cYAlign = 5; |
| 120 | break; |
| 121 | case 3: |
| 122 | l = 20; r = 30; |
| 123 | t = cYAlign * 6; |
| 124 | b = l + 20; |
| 125 | cXAlign = 5; |
| 126 | break; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 127 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 128 | path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b), |
| 129 | cCW); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 130 | if (state.fReporter->verbose()) { |
| 131 | pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 132 | " SkPath::kC%sW_Direction);\n", l, t, r, b, cCW ? "C" : ""); |
| 133 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 134 | } else { |
| 135 | cXAlign = 5; |
| 136 | cYAlign = 5; |
| 137 | } |
| 138 | if (dShape) { |
| 139 | switch (dShape) { |
| 140 | case 1: // square |
| 141 | l = dXAlign * 4; |
| 142 | r = l + 9; |
| 143 | t = dYAlign * 4; |
| 144 | b = l + 9; |
| 145 | break; |
| 146 | case 2: |
| 147 | l = dXAlign * 6; |
| 148 | r = l + 9; |
| 149 | t = 32; b = 36; |
| 150 | dYAlign = 5; |
| 151 | break; |
| 152 | case 3: |
| 153 | l = 32; r = 36; |
| 154 | t = dYAlign * 6; |
| 155 | b = l + 9; |
| 156 | dXAlign = 5; |
| 157 | break; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 158 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 159 | path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b), |
| 160 | dCW); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 161 | if (state.fReporter->verbose()) { |
| 162 | pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 163 | " SkPath::kC%sW_Direction);\n", l, t, r, b, dCW ? "C" : ""); |
| 164 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 165 | } else { |
| 166 | dXAlign = 5; |
| 167 | dYAlign = 5; |
| 168 | } |
| 169 | path.close(); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 170 | if (state.fReporter->verbose()) { |
Mike Reed | ff80c2a | 2017-01-07 11:16:28 -0500 | [diff] [blame] | 171 | state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 172 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 173 | testSimplify(path, false, out, state, pathStr.c_str()); |
| 174 | if (state.fReporter->verbose()) { |
Mike Reed | ff80c2a | 2017-01-07 11:16:28 -0500 | [diff] [blame] | 175 | state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 176 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 177 | testSimplify(path, true, out, state, pathStr.c_str()); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 178 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 185 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 186 | } |
| 187 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 188 | DEF_TEST(PathOpsSimplifyRectsThreaded, reporter) { |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 189 | initializeTests(reporter, "testLine"); |
| 190 | PathOpsThreadedTestRunner testRunner(reporter); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 191 | for (int a = 0; a < 8; ++a) { // outermost |
| 192 | for (int b = a ; b < 8; ++b) { |
| 193 | for (int c = b ; c < 8; ++c) { |
| 194 | for (int d = c; d < 8; ++d) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 195 | *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( |
| 196 | &testSimplify4x4RectsMain, a, b, c, d, &testRunner); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 197 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 198 | if (!reporter->allowExtendedTest()) goto finish; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 199 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 200 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 201 | } |
| 202 | finish: |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 203 | testRunner.render(); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 204 | } |