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; |
Mike Reed | 3e7af41 | 2019-11-26 03:34:16 +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," |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 70 | " SkPathDirection::kC%sW);\n", l, t, r, b, |
| 71 | aCW == SkPathDirection::kCCW ? "C" : ""); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 72 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 73 | } else { |
| 74 | aXAlign = 5; |
| 75 | aYAlign = 5; |
| 76 | } |
| 77 | if (bShape) { |
| 78 | switch (bShape) { |
| 79 | case 1: // square |
| 80 | l = bXAlign * 10; |
| 81 | r = l + 20; |
| 82 | t = bYAlign * 10; |
| 83 | b = l + 20; |
| 84 | break; |
| 85 | case 2: |
| 86 | l = bXAlign * 10; |
| 87 | r = l + 20; |
| 88 | t = 10; b = 40; |
| 89 | bYAlign = 5; |
| 90 | break; |
| 91 | case 3: |
| 92 | l = 10; r = 40; |
| 93 | t = bYAlign * 10; |
| 94 | b = l + 20; |
| 95 | bXAlign = 5; |
| 96 | break; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 97 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 98 | path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b), |
| 99 | bCW); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 100 | if (state.fReporter->verbose()) { |
| 101 | pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 102 | " SkPathDirection::kC%sW);\n", l, t, r, b, |
| 103 | bCW == SkPathDirection::kCCW ? "C" : ""); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 104 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 105 | } else { |
| 106 | bXAlign = 5; |
| 107 | bYAlign = 5; |
| 108 | } |
| 109 | if (cShape) { |
| 110 | switch (cShape) { |
| 111 | case 1: // square |
| 112 | l = cXAlign * 6; |
| 113 | r = l + 12; |
| 114 | t = cYAlign * 6; |
| 115 | b = l + 12; |
| 116 | break; |
| 117 | case 2: |
| 118 | l = cXAlign * 6; |
| 119 | r = l + 12; |
| 120 | t = 20; b = 30; |
| 121 | cYAlign = 5; |
| 122 | break; |
| 123 | case 3: |
| 124 | l = 20; r = 30; |
| 125 | t = cYAlign * 6; |
| 126 | b = l + 20; |
| 127 | cXAlign = 5; |
| 128 | break; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 129 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 130 | path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b), |
| 131 | cCW); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 132 | if (state.fReporter->verbose()) { |
| 133 | pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 134 | " SkPathDirection::kC%sW);\n", l, t, r, b, |
| 135 | cCW == SkPathDirection::kCCW ? "C" : ""); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 136 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 137 | } else { |
| 138 | cXAlign = 5; |
| 139 | cYAlign = 5; |
| 140 | } |
| 141 | if (dShape) { |
| 142 | switch (dShape) { |
| 143 | case 1: // square |
| 144 | l = dXAlign * 4; |
| 145 | r = l + 9; |
| 146 | t = dYAlign * 4; |
| 147 | b = l + 9; |
| 148 | break; |
| 149 | case 2: |
| 150 | l = dXAlign * 6; |
| 151 | r = l + 9; |
| 152 | t = 32; b = 36; |
| 153 | dYAlign = 5; |
| 154 | break; |
| 155 | case 3: |
| 156 | l = 32; r = 36; |
| 157 | t = dYAlign * 6; |
| 158 | b = l + 9; |
| 159 | dXAlign = 5; |
| 160 | break; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 161 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 162 | path.addRect(SkIntToScalar(l), SkIntToScalar(t), SkIntToScalar(r), SkIntToScalar(b), |
| 163 | dCW); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 164 | if (state.fReporter->verbose()) { |
| 165 | pathStr.appendf(" path.addRect(%d, %d, %d, %d," |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 166 | " SkPathDirection::kC%sW);\n", l, t, r, b, |
| 167 | dCW == SkPathDirection::kCCW ? "C" : ""); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 168 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 169 | } else { |
| 170 | dXAlign = 5; |
| 171 | dYAlign = 5; |
| 172 | } |
| 173 | path.close(); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 174 | if (state.fReporter->verbose()) { |
Mike Reed | 3e7af41 | 2019-11-26 03:34:16 +0000 | [diff] [blame^] | 175 | state.outputProgress(pathStr.c_str(), SkPath::kWinding_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, false, out, state, pathStr.c_str()); |
| 178 | if (state.fReporter->verbose()) { |
Mike Reed | 3e7af41 | 2019-11-26 03:34:16 +0000 | [diff] [blame^] | 179 | state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 180 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 181 | testSimplify(path, true, out, state, pathStr.c_str()); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 182 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 189 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 190 | } |
| 191 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 192 | DEF_TEST(PathOpsSimplifyRectsThreaded, reporter) { |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 193 | initializeTests(reporter, "testLine"); |
| 194 | PathOpsThreadedTestRunner testRunner(reporter); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 195 | for (int a = 0; a < 8; ++a) { // outermost |
| 196 | for (int b = a ; b < 8; ++b) { |
| 197 | for (int c = b ; c < 8; ++c) { |
| 198 | for (int d = c; d < 8; ++d) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 199 | *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( |
| 200 | &testSimplify4x4RectsMain, a, b, c, d, &testRunner); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 201 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 202 | if (!reporter->allowExtendedTest()) goto finish; |
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 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 205 | } |
| 206 | finish: |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 207 | testRunner.render(); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 208 | } |