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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkString.h" |
| 9 | #include "include/private/SkMacros.h" |
| 10 | #include "tests/PathOpsExtendedTest.h" |
| 11 | #include "tests/PathOpsThreadedCommon.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; |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 25 | SkPathDirection aCW = state.fA >> 2 ? SkPathDirection::kCCW : SkPathDirection::kCW; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 26 | int bShape = state.fB & 0x03; |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 27 | SkPathDirection bCW = state.fB >> 2 ? SkPathDirection::kCCW : SkPathDirection::kCW; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 28 | int cShape = state.fC & 0x03; |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 29 | SkPathDirection cCW = state.fC >> 2 ? SkPathDirection::kCCW : SkPathDirection::kCW; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 30 | int dShape = state.fD & 0x03; |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 31 | SkPathDirection dCW = state.fD >> 2 ? SkPathDirection::kCCW : SkPathDirection::kCW; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 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; |
robertphillips | 73add93 | 2016-04-07 09:01:20 -0700 | [diff] [blame] | 42 | int l SK_INIT_TO_AVOID_WARNING, t SK_INIT_TO_AVOID_WARNING, |
| 43 | 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] | 44 | if (aShape) { |
| 45 | switch (aShape) { |
| 46 | case 1: // square |
| 47 | l = 0; r = 60; |
| 48 | t = 0; b = 60; |
| 49 | aXAlign = 5; |
| 50 | aYAlign = 5; |
| 51 | break; |
| 52 | case 2: |
| 53 | l = aXAlign * 12; |
| 54 | r = l + 30; |
| 55 | t = 0; b = 60; |
| 56 | aYAlign = 5; |
| 57 | break; |
| 58 | case 3: |
| 59 | l = 0; r = 60; |
| 60 | t = aYAlign * 12; |
| 61 | b = l + 30; |
| 62 | aXAlign = 5; |
| 63 | break; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 64 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 65 | path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b), |
| 66 | aCW); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 67 | if (state.fReporter->verbose()) { |
| 68 | pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 69 | " SkPathDirection::kC%sW);\n", l, t, r, b, |
| 70 | aCW == SkPathDirection::kCCW ? "C" : ""); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 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," |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 101 | " SkPathDirection::kC%sW);\n", l, t, r, b, |
| 102 | bCW == SkPathDirection::kCCW ? "C" : ""); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 103 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 104 | } else { |
| 105 | bXAlign = 5; |
| 106 | bYAlign = 5; |
| 107 | } |
| 108 | if (cShape) { |
| 109 | switch (cShape) { |
| 110 | case 1: // square |
| 111 | l = cXAlign * 6; |
| 112 | r = l + 12; |
| 113 | t = cYAlign * 6; |
| 114 | b = l + 12; |
| 115 | break; |
| 116 | case 2: |
| 117 | l = cXAlign * 6; |
| 118 | r = l + 12; |
| 119 | t = 20; b = 30; |
| 120 | cYAlign = 5; |
| 121 | break; |
| 122 | case 3: |
| 123 | l = 20; r = 30; |
| 124 | t = cYAlign * 6; |
| 125 | b = l + 20; |
| 126 | cXAlign = 5; |
| 127 | break; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 128 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 129 | path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b), |
| 130 | cCW); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 131 | if (state.fReporter->verbose()) { |
| 132 | pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 133 | " SkPathDirection::kC%sW);\n", l, t, r, b, |
| 134 | cCW == SkPathDirection::kCCW ? "C" : ""); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 135 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 136 | } else { |
| 137 | cXAlign = 5; |
| 138 | cYAlign = 5; |
| 139 | } |
| 140 | if (dShape) { |
| 141 | switch (dShape) { |
| 142 | case 1: // square |
| 143 | l = dXAlign * 4; |
| 144 | r = l + 9; |
| 145 | t = dYAlign * 4; |
| 146 | b = l + 9; |
| 147 | break; |
| 148 | case 2: |
| 149 | l = dXAlign * 6; |
| 150 | r = l + 9; |
| 151 | t = 32; b = 36; |
| 152 | dYAlign = 5; |
| 153 | break; |
| 154 | case 3: |
| 155 | l = 32; r = 36; |
| 156 | t = dYAlign * 6; |
| 157 | b = l + 9; |
| 158 | dXAlign = 5; |
| 159 | break; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 160 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 161 | path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b), |
| 162 | dCW); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 163 | if (state.fReporter->verbose()) { |
| 164 | pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 165 | " SkPathDirection::kC%sW);\n", l, t, r, b, |
| 166 | dCW == SkPathDirection::kCCW ? "C" : ""); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 167 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 168 | } else { |
| 169 | dXAlign = 5; |
| 170 | dYAlign = 5; |
| 171 | } |
| 172 | path.close(); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 173 | if (state.fReporter->verbose()) { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 174 | state.outputProgress(pathStr.c_str(), SkPathFillType::kWinding); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 175 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 176 | testSimplify(path, false, out, state, pathStr.c_str()); |
| 177 | if (state.fReporter->verbose()) { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 178 | state.outputProgress(pathStr.c_str(), SkPathFillType::kEvenOdd); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 179 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 180 | testSimplify(path, true, out, state, pathStr.c_str()); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 181 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 188 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 189 | } |
| 190 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 191 | DEF_TEST(PathOpsSimplifyRectsThreaded, reporter) { |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 192 | initializeTests(reporter, "testLine"); |
| 193 | PathOpsThreadedTestRunner testRunner(reporter); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 194 | for (int a = 0; a < 8; ++a) { // outermost |
| 195 | for (int b = a ; b < 8; ++b) { |
| 196 | for (int c = b ; c < 8; ++c) { |
| 197 | for (int d = c; d < 8; ++d) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 198 | *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( |
| 199 | &testSimplify4x4RectsMain, a, b, c, d, &testRunner); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 200 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 201 | if (!reporter->allowExtendedTest()) goto finish; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 202 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 203 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 204 | } |
| 205 | finish: |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 206 | testRunner.render(); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 207 | } |