epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | */ |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkPaint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkPath.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 13 | #include "include/core/SkRect.h" |
| 14 | #include "include/core/SkScalar.h" |
| 15 | #include "include/core/SkSize.h" |
| 16 | #include "include/core/SkString.h" |
| 17 | #include "include/core/SkTypes.h" |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 18 | |
| 19 | typedef SkScalar (*MakePathProc)(SkPath*); |
| 20 | |
| 21 | static SkScalar make_frame(SkPath* path) { |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 22 | SkRect r = { SkIntToScalar(10), SkIntToScalar(10), |
| 23 | SkIntToScalar(630), SkIntToScalar(470) }; |
Mike Reed | 4241f5e | 2019-09-14 19:13:23 +0000 | [diff] [blame] | 24 | path->addRoundRect(r, SkIntToScalar(15), SkIntToScalar(15)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 25 | |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 26 | SkPaint paint; |
| 27 | paint.setStyle(SkPaint::kStroke_Style); |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 28 | paint.setStrokeWidth(SkIntToScalar(5)); |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 29 | paint.getFillPath(*path, path); |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 30 | return SkIntToScalar(15); |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | static SkScalar make_triangle(SkPath* path) { |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 34 | constexpr int gCoord[] = { |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 35 | 10, 20, 15, 5, 30, 30 |
| 36 | }; |
| 37 | path->moveTo(SkIntToScalar(gCoord[0]), SkIntToScalar(gCoord[1])); |
| 38 | path->lineTo(SkIntToScalar(gCoord[2]), SkIntToScalar(gCoord[3])); |
| 39 | path->lineTo(SkIntToScalar(gCoord[4]), SkIntToScalar(gCoord[5])); |
| 40 | path->close(); |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 41 | path->offset(SkIntToScalar(10), SkIntToScalar(0)); |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 42 | return SkIntToScalar(30); |
| 43 | } |
| 44 | |
| 45 | static SkScalar make_rect(SkPath* path) { |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 46 | SkRect r = { SkIntToScalar(10), SkIntToScalar(10), |
| 47 | SkIntToScalar(30), SkIntToScalar(30) }; |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 48 | path->addRect(r); |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 49 | path->offset(SkIntToScalar(10), SkIntToScalar(0)); |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 50 | return SkIntToScalar(30); |
| 51 | } |
| 52 | |
| 53 | static SkScalar make_oval(SkPath* path) { |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 54 | SkRect r = { SkIntToScalar(10), SkIntToScalar(10), |
| 55 | SkIntToScalar(30), SkIntToScalar(30) }; |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 56 | path->addOval(r); |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 57 | path->offset(SkIntToScalar(10), SkIntToScalar(0)); |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 58 | return SkIntToScalar(30); |
| 59 | } |
| 60 | |
Jim Van Verth | ecdb686 | 2016-12-13 18:17:47 -0500 | [diff] [blame] | 61 | static SkScalar make_sawtooth(SkPath* path, int teeth) { |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 62 | SkScalar x = SkIntToScalar(20); |
| 63 | SkScalar y = SkIntToScalar(20); |
| 64 | const SkScalar x0 = x; |
Jim Van Verth | ecdb686 | 2016-12-13 18:17:47 -0500 | [diff] [blame] | 65 | const SkScalar dx = SkIntToScalar(5); |
| 66 | const SkScalar dy = SkIntToScalar(10); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 67 | |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 68 | path->moveTo(x, y); |
Jim Van Verth | ecdb686 | 2016-12-13 18:17:47 -0500 | [diff] [blame] | 69 | for (int i = 0; i < teeth; i++) { |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 70 | x += dx; |
| 71 | path->lineTo(x, y - dy); |
| 72 | x += dx; |
| 73 | path->lineTo(x, y + dy); |
| 74 | } |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 75 | path->lineTo(x, y + (2 * dy)); |
| 76 | path->lineTo(x0, y + (2 * dy)); |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 77 | path->close(); |
| 78 | return SkIntToScalar(30); |
| 79 | } |
| 80 | |
Jim Van Verth | ecdb686 | 2016-12-13 18:17:47 -0500 | [diff] [blame] | 81 | static SkScalar make_sawtooth_3(SkPath* path) { return make_sawtooth(path, 3); } |
| 82 | static SkScalar make_sawtooth_32(SkPath* path) { return make_sawtooth(path, 32); } |
| 83 | |
| 84 | static SkScalar make_house(SkPath* path) { |
| 85 | path->moveTo(21, 23); |
| 86 | path->lineTo(21, 11.534f); |
| 87 | path->lineTo(22.327f, 12.741f); |
| 88 | path->lineTo(23.673f, 11.261f); |
| 89 | path->lineTo(12, 0.648f); |
| 90 | path->lineTo(8, 4.285f); |
| 91 | path->lineTo(8, 2); |
| 92 | path->lineTo(4, 2); |
| 93 | path->lineTo(4, 7.921f); |
| 94 | path->lineTo(0.327f, 11.26f); |
| 95 | path->lineTo(1.673f, 12.74f); |
| 96 | path->lineTo(3, 11.534f); |
| 97 | path->lineTo(3, 23); |
| 98 | path->lineTo(11, 23); |
| 99 | path->lineTo(11, 18); |
| 100 | path->lineTo(13, 18); |
| 101 | path->lineTo(13, 23); |
| 102 | path->lineTo(21, 23); |
| 103 | path->close(); |
| 104 | path->lineTo(9, 16); |
| 105 | path->lineTo(9, 21); |
| 106 | path->lineTo(5, 21); |
| 107 | path->lineTo(5, 9.715f); |
| 108 | path->lineTo(12, 3.351f); |
| 109 | path->lineTo(19, 9.715f); |
| 110 | path->lineTo(19, 21); |
| 111 | path->lineTo(15, 21); |
| 112 | path->lineTo(15, 16); |
| 113 | path->lineTo(9, 16); |
| 114 | path->close(); |
| 115 | path->offset(20, 0); |
| 116 | return SkIntToScalar(30); |
| 117 | } |
| 118 | |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 119 | static SkScalar make_star(SkPath* path, int n) { |
| 120 | const SkScalar c = SkIntToScalar(45); |
| 121 | const SkScalar r = SkIntToScalar(20); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 122 | |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 123 | SkScalar rad = -SK_ScalarPI / 2; |
| 124 | const SkScalar drad = (n >> 1) * SK_ScalarPI * 2 / n; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 125 | |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 126 | path->moveTo(c, c - r); |
| 127 | for (int i = 1; i < n; i++) { |
| 128 | rad += drad; |
Brian Osman | 4428f2c | 2019-04-02 10:59:28 -0400 | [diff] [blame] | 129 | path->lineTo(c + SkScalarCos(rad) * r, c + SkScalarSin(rad) * r); |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 130 | } |
| 131 | path->close(); |
| 132 | return r * 2 * 6 / 5; |
| 133 | } |
| 134 | |
| 135 | static SkScalar make_star_5(SkPath* path) { return make_star(path, 5); } |
| 136 | static SkScalar make_star_13(SkPath* path) { return make_star(path, 13); } |
| 137 | |
vandebo@chromium.org | 683001c | 2012-05-09 17:17:51 +0000 | [diff] [blame] | 138 | // We don't expect any output from this path. |
| 139 | static SkScalar make_line(SkPath* path) { |
| 140 | path->moveTo(SkIntToScalar(30), SkIntToScalar(30)); |
| 141 | path->lineTo(SkIntToScalar(120), SkIntToScalar(40)); |
| 142 | path->close(); |
| 143 | path->moveTo(SkIntToScalar(150), SkIntToScalar(30)); |
| 144 | path->lineTo(SkIntToScalar(150), SkIntToScalar(30)); |
| 145 | path->lineTo(SkIntToScalar(300), SkIntToScalar(40)); |
| 146 | path->close(); |
| 147 | return SkIntToScalar(40); |
| 148 | } |
| 149 | |
Jim Van Verth | f9e678d | 2017-02-15 15:46:52 -0500 | [diff] [blame] | 150 | static void make_info(SkPath* path) { |
Jim Van Verth | 7704754 | 2017-01-11 14:17:00 -0500 | [diff] [blame] | 151 | path->moveTo(24, 4); |
| 152 | path->cubicTo(12.94999980926514f, |
| 153 | 4, |
| 154 | 4, |
| 155 | 12.94999980926514f, |
| 156 | 4, |
| 157 | 24); |
| 158 | path->cubicTo(4, |
| 159 | 35.04999923706055f, |
| 160 | 12.94999980926514f, |
| 161 | 44, |
| 162 | 24, |
| 163 | 44); |
| 164 | path->cubicTo(35.04999923706055f, |
| 165 | 44, |
| 166 | 44, |
| 167 | 35.04999923706055f, |
| 168 | 44, |
| 169 | 24); |
| 170 | path->cubicTo(44, |
| 171 | 12.95000076293945f, |
| 172 | 35.04999923706055f, |
| 173 | 4, |
| 174 | 24, |
| 175 | 4); |
| 176 | path->close(); |
| 177 | path->moveTo(26, 34); |
| 178 | path->lineTo(22, 34); |
| 179 | path->lineTo(22, 22); |
| 180 | path->lineTo(26, 22); |
| 181 | path->lineTo(26, 34); |
| 182 | path->close(); |
| 183 | path->moveTo(26, 18); |
| 184 | path->lineTo(22, 18); |
| 185 | path->lineTo(22, 14); |
| 186 | path->lineTo(26, 14); |
| 187 | path->lineTo(26, 18); |
| 188 | path->close(); |
Jim Van Verth | f9e678d | 2017-02-15 15:46:52 -0500 | [diff] [blame] | 189 | } |
Jim Van Verth | 7704754 | 2017-01-11 14:17:00 -0500 | [diff] [blame] | 190 | |
Jim Van Verth | f9e678d | 2017-02-15 15:46:52 -0500 | [diff] [blame] | 191 | static void make_accessibility(SkPath* path) { |
| 192 | path->moveTo(12, 2); |
| 193 | path->cubicTo(13.10000038146973f, |
| 194 | 2, |
| 195 | 14, |
| 196 | 2.900000095367432f, |
| 197 | 14, |
| 198 | 4); |
| 199 | path->cubicTo(14, |
| 200 | 5.099999904632568f, |
| 201 | 13.10000038146973f, |
| 202 | 6, |
| 203 | 12, |
| 204 | 6); |
| 205 | path->cubicTo(10.89999961853027f, |
| 206 | 6, |
| 207 | 10, |
| 208 | 5.099999904632568f, |
| 209 | 10, |
| 210 | 4); |
| 211 | path->cubicTo(10, |
| 212 | 2.900000095367432f, |
| 213 | 10.89999961853027f, |
| 214 | 2, |
| 215 | 12, |
| 216 | 2); |
| 217 | path->close(); |
| 218 | path->moveTo(21, 9); |
| 219 | path->lineTo(15, 9); |
| 220 | path->lineTo(15, 22); |
| 221 | path->lineTo(13, 22); |
| 222 | path->lineTo(13, 16); |
| 223 | path->lineTo(11, 16); |
| 224 | path->lineTo(11, 22); |
| 225 | path->lineTo(9, 22); |
| 226 | path->lineTo(9, 9); |
| 227 | path->lineTo(3, 9); |
| 228 | path->lineTo(3, 7); |
| 229 | path->lineTo(21, 7); |
| 230 | path->lineTo(21, 9); |
| 231 | path->close(); |
Jim Van Verth | 7704754 | 2017-01-11 14:17:00 -0500 | [diff] [blame] | 232 | } |
| 233 | |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 234 | // test case for http://crbug.com/695196 |
| 235 | static void make_visualizer(SkPath* path) { |
| 236 | path->moveTo(1.9520f, 2.0000f); |
| 237 | path->conicTo(1.5573f, 1.9992f, 1.2782f, 2.2782f, 0.9235f); |
| 238 | path->conicTo(0.9992f, 2.5573f, 1.0000f, 2.9520f, 0.9235f); |
| 239 | path->lineTo(1.0000f, 5.4300f); |
| 240 | path->lineTo(17.0000f, 5.4300f); |
| 241 | path->lineTo(17.0000f, 2.9520f); |
| 242 | path->conicTo(17.0008f, 2.5573f, 16.7218f, 2.2782f, 0.9235f); |
| 243 | path->conicTo(16.4427f, 1.9992f, 16.0480f, 2.0000f, 0.9235f); |
| 244 | path->lineTo(1.9520f, 2.0000f); |
| 245 | path->close(); |
| 246 | path->moveTo(2.7140f, 3.1430f); |
| 247 | path->conicTo(3.0547f, 3.1287f, 3.2292f, 3.4216f, 0.8590f); |
| 248 | path->conicTo(3.4038f, 3.7145f, 3.2292f, 4.0074f, 0.8590f); |
| 249 | path->conicTo(3.0547f, 4.3003f, 2.7140f, 4.2860f, 0.8590f); |
| 250 | path->conicTo(2.1659f, 4.2631f, 2.1659f, 3.7145f, 0.7217f); |
| 251 | path->conicTo(2.1659f, 3.1659f, 2.7140f, 3.1430f, 0.7217f); |
| 252 | path->lineTo(2.7140f, 3.1430f); |
| 253 | path->close(); |
| 254 | path->moveTo(5.0000f, 3.1430f); |
| 255 | path->conicTo(5.3407f, 3.1287f, 5.5152f, 3.4216f, 0.8590f); |
| 256 | path->conicTo(5.6898f, 3.7145f, 5.5152f, 4.0074f, 0.8590f); |
| 257 | path->conicTo(5.3407f, 4.3003f, 5.0000f, 4.2860f, 0.8590f); |
| 258 | path->conicTo(4.4519f, 4.2631f, 4.4519f, 3.7145f, 0.7217f); |
| 259 | path->conicTo(4.4519f, 3.1659f, 5.0000f, 3.1430f, 0.7217f); |
| 260 | path->lineTo(5.0000f, 3.1430f); |
| 261 | path->close(); |
| 262 | path->moveTo(7.2860f, 3.1430f); |
| 263 | path->conicTo(7.6267f, 3.1287f, 7.8012f, 3.4216f, 0.8590f); |
| 264 | path->conicTo(7.9758f, 3.7145f, 7.8012f, 4.0074f, 0.8590f); |
| 265 | path->conicTo(7.6267f, 4.3003f, 7.2860f, 4.2860f, 0.8590f); |
| 266 | path->conicTo(6.7379f, 4.2631f, 6.7379f, 3.7145f, 0.7217f); |
| 267 | path->conicTo(6.7379f, 3.1659f, 7.2860f, 3.1430f, 0.7217f); |
| 268 | path->close(); |
| 269 | path->moveTo(1.0000f, 6.1900f); |
| 270 | path->lineTo(1.0000f, 14.3810f); |
| 271 | path->conicTo(0.9992f, 14.7757f, 1.2782f, 15.0548f, 0.9235f); |
| 272 | path->conicTo(1.5573f, 15.3338f, 1.9520f, 15.3330f, 0.9235f); |
| 273 | path->lineTo(16.0480f, 15.3330f); |
| 274 | path->conicTo(16.4427f, 15.3338f, 16.7218f, 15.0548f, 0.9235f); |
| 275 | path->conicTo(17.0008f, 14.7757f, 17.0000f, 14.3810f, 0.9235f); |
| 276 | path->lineTo(17.0000f, 6.1910f); |
| 277 | path->lineTo(1.0000f, 6.1910f); |
| 278 | path->lineTo(1.0000f, 6.1900f); |
| 279 | path->close(); |
| 280 | } |
| 281 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 282 | constexpr MakePathProc gProcs[] = { |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 283 | make_frame, |
| 284 | make_triangle, |
| 285 | make_rect, |
| 286 | make_oval, |
Jim Van Verth | ecdb686 | 2016-12-13 18:17:47 -0500 | [diff] [blame] | 287 | make_sawtooth_32, |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 288 | make_star_5, |
vandebo@chromium.org | 683001c | 2012-05-09 17:17:51 +0000 | [diff] [blame] | 289 | make_star_13, |
| 290 | make_line, |
Jim Van Verth | ecdb686 | 2016-12-13 18:17:47 -0500 | [diff] [blame] | 291 | make_house, |
| 292 | make_sawtooth_3, |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 293 | }; |
| 294 | |
| 295 | #define N SK_ARRAY_COUNT(gProcs) |
| 296 | |
reed@google.com | 5ee6491 | 2012-06-11 17:30:33 +0000 | [diff] [blame] | 297 | class PathFillGM : public skiagm::GM { |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 298 | SkPath fPath[N]; |
| 299 | SkScalar fDY[N]; |
Jim Van Verth | 7704754 | 2017-01-11 14:17:00 -0500 | [diff] [blame] | 300 | SkPath fInfoPath; |
Jim Van Verth | f9e678d | 2017-02-15 15:46:52 -0500 | [diff] [blame] | 301 | SkPath fAccessibilityPath; |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 302 | SkPath fVisualizerPath; |
caryclark | 88c748a | 2015-02-18 10:56:00 -0800 | [diff] [blame] | 303 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 304 | void onOnceBeforeDraw() override { |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 305 | for (size_t i = 0; i < N; i++) { |
| 306 | fDY[i] = gProcs[i](&fPath[i]); |
| 307 | } |
Jim Van Verth | 7704754 | 2017-01-11 14:17:00 -0500 | [diff] [blame] | 308 | |
Jim Van Verth | f9e678d | 2017-02-15 15:46:52 -0500 | [diff] [blame] | 309 | make_info(&fInfoPath); |
| 310 | make_accessibility(&fAccessibilityPath); |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 311 | make_visualizer(&fVisualizerPath); |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 312 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 313 | |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 314 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 315 | SkString onShortName() override { |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 316 | return SkString("pathfill"); |
| 317 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 318 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 319 | SkISize onISize() override { |
reed@google.com | 5ee6491 | 2012-06-11 17:30:33 +0000 | [diff] [blame] | 320 | return SkISize::Make(640, 480); |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 321 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 322 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 323 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 324 | SkPaint paint; |
| 325 | paint.setAntiAlias(true); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 326 | |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 327 | for (size_t i = 0; i < N; i++) { |
| 328 | canvas->drawPath(fPath[i], paint); |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame] | 329 | canvas->translate(SkIntToScalar(0), fDY[i]); |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 330 | } |
Jim Van Verth | 7704754 | 2017-01-11 14:17:00 -0500 | [diff] [blame] | 331 | |
Jim Van Verth | f9e678d | 2017-02-15 15:46:52 -0500 | [diff] [blame] | 332 | canvas->save(); |
Jim Van Verth | 7704754 | 2017-01-11 14:17:00 -0500 | [diff] [blame] | 333 | canvas->scale(0.300000011920929f, 0.300000011920929f); |
| 334 | canvas->translate(50, 50); |
| 335 | canvas->drawPath(fInfoPath, paint); |
Jim Van Verth | f9e678d | 2017-02-15 15:46:52 -0500 | [diff] [blame] | 336 | canvas->restore(); |
| 337 | |
| 338 | canvas->scale(2, 2); |
| 339 | canvas->translate(5, 15); |
| 340 | canvas->drawPath(fAccessibilityPath, paint); |
Jim Van Verth | 33632d8 | 2017-02-28 10:24:39 -0500 | [diff] [blame] | 341 | |
| 342 | canvas->scale(0.5f, 0.5f); |
| 343 | canvas->translate(5, 50); |
| 344 | canvas->drawPath(fVisualizerPath, paint); |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 345 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 346 | |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 347 | private: |
reed@google.com | 5ee6491 | 2012-06-11 17:30:33 +0000 | [diff] [blame] | 348 | typedef skiagm::GM INHERITED; |
| 349 | }; |
| 350 | |
| 351 | // test inverse-fill w/ a clip that completely excludes the geometry |
| 352 | class PathInverseFillGM : public skiagm::GM { |
| 353 | SkPath fPath[N]; |
| 354 | SkScalar fDY[N]; |
caryclark | 88c748a | 2015-02-18 10:56:00 -0800 | [diff] [blame] | 355 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 356 | void onOnceBeforeDraw() override { |
reed@google.com | 5ee6491 | 2012-06-11 17:30:33 +0000 | [diff] [blame] | 357 | for (size_t i = 0; i < N; i++) { |
| 358 | fDY[i] = gProcs[i](&fPath[i]); |
| 359 | } |
| 360 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 361 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 362 | SkString onShortName() override { |
reed@google.com | 5ee6491 | 2012-06-11 17:30:33 +0000 | [diff] [blame] | 363 | return SkString("pathinvfill"); |
| 364 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 365 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 366 | SkISize onISize() override { |
reed@google.com | 5ee6491 | 2012-06-11 17:30:33 +0000 | [diff] [blame] | 367 | return SkISize::Make(450, 220); |
| 368 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 369 | |
reed@google.com | 5ee6491 | 2012-06-11 17:30:33 +0000 | [diff] [blame] | 370 | static void show(SkCanvas* canvas, const SkPath& path, const SkPaint& paint, |
| 371 | const SkRect* clip, SkScalar top, const SkScalar bottom) { |
| 372 | canvas->save(); |
| 373 | if (clip) { |
| 374 | SkRect r = *clip; |
| 375 | r.fTop = top; |
| 376 | r.fBottom = bottom; |
| 377 | canvas->clipRect(r); |
| 378 | } |
| 379 | canvas->drawPath(path, paint); |
| 380 | canvas->restore(); |
| 381 | } |
| 382 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 383 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | 5ee6491 | 2012-06-11 17:30:33 +0000 | [diff] [blame] | 384 | SkPath path; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 385 | |
reed@google.com | 5ee6491 | 2012-06-11 17:30:33 +0000 | [diff] [blame] | 386 | path.addCircle(SkIntToScalar(50), SkIntToScalar(50), SkIntToScalar(40)); |
| 387 | path.toggleInverseFillType(); |
| 388 | |
| 389 | SkRect clipR = { 0, 0, SkIntToScalar(100), SkIntToScalar(200) }; |
| 390 | |
| 391 | canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); |
| 392 | |
| 393 | for (int doclip = 0; doclip <= 1; ++doclip) { |
| 394 | for (int aa = 0; aa <= 1; ++aa) { |
| 395 | SkPaint paint; |
| 396 | paint.setAntiAlias(SkToBool(aa)); |
| 397 | |
| 398 | canvas->save(); |
| 399 | canvas->clipRect(clipR); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 400 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 401 | const SkRect* clipPtr = doclip ? &clipR : nullptr; |
reed@google.com | 5ee6491 | 2012-06-11 17:30:33 +0000 | [diff] [blame] | 402 | |
| 403 | show(canvas, path, paint, clipPtr, clipR.fTop, clipR.centerY()); |
| 404 | show(canvas, path, paint, clipPtr, clipR.centerY(), clipR.fBottom); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 405 | |
reed@google.com | 5ee6491 | 2012-06-11 17:30:33 +0000 | [diff] [blame] | 406 | canvas->restore(); |
| 407 | canvas->translate(SkIntToScalar(110), 0); |
| 408 | } |
| 409 | } |
| 410 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 411 | |
reed@google.com | 5ee6491 | 2012-06-11 17:30:33 +0000 | [diff] [blame] | 412 | private: |
| 413 | typedef skiagm::GM INHERITED; |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 414 | }; |
| 415 | |
caryclark | e3e8c72 | 2016-03-01 09:42:03 -0800 | [diff] [blame] | 416 | DEF_SIMPLE_GM(rotatedcubicpath, canvas, 200, 200) { |
| 417 | SkPaint p; |
| 418 | p.setAntiAlias(true); |
| 419 | p.setStyle(SkPaint::kFill_Style); |
| 420 | |
| 421 | canvas->translate(50, 50); |
| 422 | SkPath path; |
| 423 | path.moveTo(48,-23); |
| 424 | path.cubicTo(48,-29.5, 6,-30, 6,-30); |
| 425 | path.cubicTo(6,-30, 2,0, 2,0); |
| 426 | path.cubicTo(2,0, 44,-21.5, 48,-23); |
| 427 | path.close(); |
| 428 | |
| 429 | p.setColor(SK_ColorBLUE); |
| 430 | canvas->drawPath(path, p); |
| 431 | |
| 432 | // Rotated path, which is not antialiased on GPU |
| 433 | p.setColor(SK_ColorRED); |
| 434 | canvas->rotate(90); |
| 435 | canvas->drawPath(path, p); |
| 436 | } |
| 437 | |
reed@google.com | c280700 | 2011-04-11 13:57:04 +0000 | [diff] [blame] | 438 | /////////////////////////////////////////////////////////////////////////////// |
| 439 | |
scroggo | 96f16e8 | 2015-12-10 13:31:59 -0800 | [diff] [blame] | 440 | DEF_GM( return new PathFillGM; ) |
| 441 | DEF_GM( return new PathInverseFillGM; ) |
Cary Clark | 8540e11 | 2018-04-11 14:30:27 -0400 | [diff] [blame] | 442 | |
Cary Clark | 4eb6f7a | 2018-04-17 13:34:37 -0400 | [diff] [blame] | 443 | DEF_SIMPLE_GM(bug7792, canvas, 800, 800) { |
Cary Clark | 8540e11 | 2018-04-11 14:30:27 -0400 | [diff] [blame] | 444 | // from skbug.com/7792 bug description |
| 445 | SkPaint p; |
| 446 | SkPath path; |
| 447 | path.moveTo(10, 10); |
| 448 | path.moveTo(75, 75); |
| 449 | path.lineTo(150, 75); |
| 450 | path.lineTo(150, 150); |
| 451 | path.lineTo(75, 150); |
| 452 | canvas->drawPath(path, p); |
Cary Clark | d422847 | 2018-04-13 07:07:04 -0400 | [diff] [blame] | 453 | // from skbug.com/7792#c3 |
Cary Clark | 8540e11 | 2018-04-11 14:30:27 -0400 | [diff] [blame] | 454 | canvas->translate(200, 0); |
| 455 | path.reset(); |
| 456 | path.moveTo(75, 50); |
| 457 | path.moveTo(100, 75); |
| 458 | path.lineTo(150, 75); |
| 459 | path.lineTo(150, 150); |
| 460 | path.lineTo(75, 150); |
| 461 | path.lineTo(75, 50); |
| 462 | path.close(); |
| 463 | canvas->drawPath(path, p); |
Cary Clark | d422847 | 2018-04-13 07:07:04 -0400 | [diff] [blame] | 464 | // from skbug.com/7792#c9 |
Cary Clark | 8540e11 | 2018-04-11 14:30:27 -0400 | [diff] [blame] | 465 | canvas->translate(200, 0); |
| 466 | path.reset(); |
| 467 | path.moveTo(10, 10); |
| 468 | path.moveTo(75, 75); |
| 469 | path.lineTo(150, 75); |
| 470 | path.lineTo(150, 150); |
| 471 | path.lineTo(75, 150); |
| 472 | path.close(); |
| 473 | canvas->drawPath(path, p); |
Cary Clark | d422847 | 2018-04-13 07:07:04 -0400 | [diff] [blame] | 474 | // from skbug.com/7792#c11 |
Cary Clark | 8540e11 | 2018-04-11 14:30:27 -0400 | [diff] [blame] | 475 | canvas->translate(-200 * 2, 200); |
| 476 | path.reset(); |
| 477 | path.moveTo(75, 150); |
| 478 | path.lineTo(75, 75); |
| 479 | path.lineTo(150, 75); |
| 480 | path.lineTo(150, 150); |
| 481 | path.lineTo(75, 150); |
| 482 | path.moveTo(75, 150); |
| 483 | canvas->drawPath(path, p); |
Cary Clark | d422847 | 2018-04-13 07:07:04 -0400 | [diff] [blame] | 484 | // from skbug.com/7792#c14 |
Cary Clark | 8540e11 | 2018-04-11 14:30:27 -0400 | [diff] [blame] | 485 | canvas->translate(200, 0); |
| 486 | path.reset(); |
| 487 | path.moveTo(250, 75); |
| 488 | path.moveTo(250, 75); |
| 489 | path.moveTo(250, 75); |
| 490 | path.moveTo(100, 75); |
| 491 | path.lineTo(150, 75); |
| 492 | path.lineTo(150, 150); |
| 493 | path.lineTo(75, 150); |
| 494 | path.lineTo(75, 75); |
| 495 | path.close(); |
| 496 | path.lineTo(0, 0); |
| 497 | path.close(); |
| 498 | canvas->drawPath(path, p); |
Cary Clark | d422847 | 2018-04-13 07:07:04 -0400 | [diff] [blame] | 499 | // from skbug.com/7792#c15 |
Cary Clark | 8540e11 | 2018-04-11 14:30:27 -0400 | [diff] [blame] | 500 | canvas->translate(200, 0); |
| 501 | path.reset(); |
| 502 | path.moveTo(75, 75); |
| 503 | path.lineTo(150, 75); |
| 504 | path.lineTo(150, 150); |
| 505 | path.lineTo(75, 150); |
| 506 | path.moveTo(250, 75); |
| 507 | canvas->drawPath(path, p); |
Cary Clark | d422847 | 2018-04-13 07:07:04 -0400 | [diff] [blame] | 508 | // from skbug.com/7792#c17 |
Cary Clark | 31608c0 | 2018-04-12 10:29:46 -0400 | [diff] [blame] | 509 | canvas->translate(-200 * 2, 200); |
| 510 | path.reset(); |
| 511 | path.moveTo(75, 10); |
| 512 | path.moveTo(75, 75); |
| 513 | path.lineTo(150, 75); |
| 514 | path.lineTo(150, 150); |
| 515 | path.lineTo(75, 150); |
| 516 | path.lineTo(75, 10); |
| 517 | path.close(); |
| 518 | canvas->drawPath(path, p); |
Cary Clark | d422847 | 2018-04-13 07:07:04 -0400 | [diff] [blame] | 519 | // from skbug.com/7792#c19 |
Cary Clark | 88ba971 | 2018-04-12 14:00:24 -0400 | [diff] [blame] | 520 | canvas->translate(200, 0); |
| 521 | path.reset(); |
| 522 | path.moveTo(75, 75); |
| 523 | path.lineTo(75, 75); |
| 524 | path.lineTo(75, 75); |
| 525 | path.lineTo(75, 75); |
| 526 | path.lineTo(150, 75); |
| 527 | path.lineTo(150, 150); |
| 528 | path.lineTo(75, 150); |
| 529 | path.close(); |
| 530 | path.moveTo(10, 10); |
| 531 | path.lineTo(30, 10); |
| 532 | path.lineTo(10, 30); |
| 533 | canvas->drawPath(path, p); |
Cary Clark | d422847 | 2018-04-13 07:07:04 -0400 | [diff] [blame] | 534 | // from skbug.com/7792#c23 |
| 535 | canvas->translate(200, 0); |
| 536 | path.reset(); |
| 537 | path.moveTo(75, 75); |
| 538 | path.lineTo(75, 75); |
| 539 | path.moveTo(75, 75); |
| 540 | path.lineTo(75, 75); |
| 541 | path.lineTo(150, 75); |
| 542 | path.lineTo(150, 150); |
| 543 | path.lineTo(75, 150); |
| 544 | path.close(); |
| 545 | canvas->drawPath(path, p); |
Cary Clark | 48c464a | 2018-04-16 12:06:07 -0400 | [diff] [blame] | 546 | // from skbug.com/7792#c29 |
| 547 | canvas->translate(-200 * 2, 200); |
| 548 | path.reset(); |
| 549 | path.moveTo(75, 75); |
| 550 | path.lineTo(150, 75); |
| 551 | path.lineTo(150, 150); |
| 552 | path.lineTo(75, 150); |
| 553 | path.lineTo(75, 250); |
| 554 | path.moveTo(75, 75); |
| 555 | path.close(); |
| 556 | canvas->drawPath(path, p); |
Cary Clark | a765156 | 2018-04-17 09:30:14 -0400 | [diff] [blame] | 557 | // from skbug.com/7792#c31 |
| 558 | canvas->translate(200, 0); |
| 559 | path.reset(); |
| 560 | path.moveTo(75, 75); |
| 561 | path.lineTo(150, 75); |
| 562 | path.lineTo(150, 150); |
| 563 | path.lineTo(75, 150); |
| 564 | path.lineTo(75, 10); |
| 565 | path.moveTo(75, 75); |
| 566 | path.close(); |
| 567 | canvas->drawPath(path, p); |
Cary Clark | 1cd6098 | 2018-04-17 11:53:34 -0400 | [diff] [blame] | 568 | // from skbug.com/7792#c36 |
| 569 | canvas->translate(200, 0); |
| 570 | path.reset(); |
| 571 | path.moveTo(75, 75); |
| 572 | path.lineTo(150, 75); |
| 573 | path.lineTo(150, 150); |
| 574 | path.lineTo(10, 150); |
| 575 | path.moveTo(75, 75); |
| 576 | path.lineTo(75, 75); |
| 577 | canvas->drawPath(path, p); |
Cary Clark | 4eb6f7a | 2018-04-17 13:34:37 -0400 | [diff] [blame] | 578 | // from skbug.com/7792#c39 |
| 579 | canvas->translate(200, -200 * 3); |
| 580 | path.reset(); |
| 581 | path.moveTo(150, 75); |
| 582 | path.lineTo(150, 150); |
| 583 | path.lineTo(75, 150); |
| 584 | path.lineTo(75, 100); |
| 585 | canvas->drawPath(path, p); |
Cary Clark | b120e92 | 2018-04-18 12:25:08 -0400 | [diff] [blame] | 586 | // from zero_length_paths_aa |
| 587 | canvas->translate(0, 200); |
| 588 | path.reset(); |
| 589 | path.moveTo(150, 100); |
| 590 | path.lineTo(150, 100); |
| 591 | path.lineTo(150, 150); |
| 592 | path.lineTo(75, 150); |
| 593 | path.lineTo(75, 100); |
| 594 | path.lineTo(75, 75); |
| 595 | path.lineTo(150, 75); |
| 596 | path.close(); |
| 597 | canvas->drawPath(path, p); |
Cary Clark | dbc59ba | 2018-04-19 07:37:29 -0400 | [diff] [blame] | 598 | // from skbug.com/7792#c41 |
| 599 | canvas->translate(0, 200); |
| 600 | path.reset(); |
| 601 | path.moveTo(75, 75); |
| 602 | path.lineTo(150, 75); |
| 603 | path.lineTo(150, 150); |
| 604 | path.lineTo(140, 150); |
| 605 | path.lineTo(140, 75); |
| 606 | path.moveTo(75, 75); |
| 607 | path.close(); |
| 608 | canvas->drawPath(path, p); |
| 609 | // from skbug.com/7792#c53 |
| 610 | canvas->translate(0, 200); |
| 611 | path.reset(); |
| 612 | path.moveTo(75, 75); |
| 613 | path.lineTo(150, 75); |
| 614 | path.lineTo(150, 150); |
| 615 | path.lineTo(140, 150); |
| 616 | path.lineTo(140, 75); |
| 617 | path.moveTo(75, 75); |
| 618 | path.close(); |
| 619 | canvas->drawPath(path, p); |
Cary Clark | 8540e11 | 2018-04-11 14:30:27 -0400 | [diff] [blame] | 620 | } |
Mike Reed | 1ae3e75 | 2020-04-26 17:20:22 -0400 | [diff] [blame] | 621 | |
| 622 | #include "include/core/SkSurface.h" |
| 623 | |
| 624 | DEF_SIMPLE_GM(path_stroke_clip_crbug1070835, canvas, 25, 50) { |
| 625 | SkCanvas* orig = canvas; |
| 626 | auto surf = SkSurface::MakeRasterN32Premul(25, 25); |
| 627 | canvas = surf->getCanvas(); |
| 628 | |
| 629 | SkPaint p; |
| 630 | p.setColor(SK_ColorRED); |
| 631 | p.setAntiAlias(true); |
| 632 | p.setStyle(SkPaint::kStroke_Style); |
| 633 | p.setStrokeWidth(2); |
| 634 | |
| 635 | canvas->scale(4.16666651f/2, 4.16666651f/2); |
| 636 | |
| 637 | SkPath path; |
| 638 | |
| 639 | SkPoint pts[] = { |
| 640 | {11, 12}, |
| 641 | {11, 18.0751324f}, |
| 642 | {6.07513189f, 23}, |
| 643 | {-4.80825292E-7f, 23}, |
| 644 | {-6.07513332f, 23}, |
| 645 | {-11, 18.0751324f}, |
| 646 | {-11, 11.999999f}, |
| 647 | {-10.999999f, 5.92486763f}, |
| 648 | {-6.07513189f, 1}, |
| 649 | {1.31173692E-7f, 1}, |
| 650 | {6.07513141f, 1}, |
| 651 | {10.9999981f, 5.92486572f}, |
| 652 | {11, 11.9999971f}, |
| 653 | }; |
| 654 | path.moveTo(pts[0]).cubicTo(pts[1], pts[2], pts[3]) |
| 655 | .cubicTo(pts[4], pts[5], pts[6]) |
| 656 | .cubicTo(pts[7], pts[8], pts[9]) |
| 657 | .cubicTo(pts[10],pts[11],pts[12]); |
| 658 | |
| 659 | canvas->drawPath(path, p); |
| 660 | |
| 661 | surf->draw(orig, 0, 0, nullptr); |
| 662 | } |
Mike Reed | 3c411f5 | 2020-04-28 15:17:48 -0400 | [diff] [blame^] | 663 | |
| 664 | DEF_SIMPLE_GM(path_arcto_skbug_9077, canvas, 200, 200) { |
| 665 | SkPaint p; |
| 666 | p.setColor(SK_ColorRED); |
| 667 | p.setAntiAlias(true); |
| 668 | p.setStyle(SkPaint::kStroke_Style); |
| 669 | p.setStrokeWidth(2); |
| 670 | |
| 671 | SkPath path; |
| 672 | SkPoint pts[] = { {20, 20}, {100, 20}, {100, 60}, {130, 150}, {180, 160} }; |
| 673 | SkScalar radius = 60; |
| 674 | path.moveTo(pts[0]); |
| 675 | path.lineTo(pts[1]); |
| 676 | path.lineTo(pts[2]); |
| 677 | path.close(); |
| 678 | path.arcTo(pts[3], pts[4], radius); |
| 679 | canvas->drawPath(path, p); |
| 680 | } |