schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +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 | |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 8 | #include "gm.h" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils.h" |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 10 | #include "SkCanvas.h" |
| 11 | #include "SkPaint.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 12 | #include "SkPath.h" |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 13 | #include "SkRandom.h" |
| 14 | |
halcanary | 6950de6 | 2015-11-07 05:29:00 -0800 | [diff] [blame] | 15 | // https://bug.skia.org/1316 shows that this cubic, when slightly clipped, creates big |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 16 | // (incorrect) changes to its control points. |
| 17 | class ClippedCubicGM : public skiagm::GM { |
| 18 | public: |
| 19 | ClippedCubicGM() {} |
skia.committer@gmail.com | 3e2345a | 2013-05-24 07:01:26 +0000 | [diff] [blame] | 20 | |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 21 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 22 | |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 23 | SkString onShortName() { |
reed@google.com | 03ca64b | 2013-05-23 19:39:15 +0000 | [diff] [blame] | 24 | return SkString("clippedcubic"); |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 25 | } |
skia.committer@gmail.com | 3e2345a | 2013-05-24 07:01:26 +0000 | [diff] [blame] | 26 | |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 27 | SkISize onISize() { return SkISize::Make(1240, 390); } |
skia.committer@gmail.com | 3e2345a | 2013-05-24 07:01:26 +0000 | [diff] [blame] | 28 | |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 29 | virtual void onDraw(SkCanvas* canvas) { |
| 30 | SkPath path; |
| 31 | path.moveTo(0, 0); |
| 32 | path.cubicTo(140, 150, 40, 10, 170, 150); |
skia.committer@gmail.com | 3e2345a | 2013-05-24 07:01:26 +0000 | [diff] [blame] | 33 | |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 34 | SkPaint paint; |
| 35 | SkRect bounds = path.getBounds(); |
skia.committer@gmail.com | 3e2345a | 2013-05-24 07:01:26 +0000 | [diff] [blame] | 36 | |
reed@google.com | 0f8990c | 2013-05-23 19:47:05 +0000 | [diff] [blame] | 37 | for (SkScalar dy = -1; dy <= 1; dy += 1) { |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 38 | canvas->save(); |
reed@google.com | 0f8990c | 2013-05-23 19:47:05 +0000 | [diff] [blame] | 39 | for (SkScalar dx = -1; dx <= 1; dx += 1) { |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 40 | canvas->save(); |
| 41 | canvas->clipRect(bounds); |
| 42 | canvas->translate(dx, dy); |
| 43 | canvas->drawPath(path, paint); |
| 44 | canvas->restore(); |
skia.committer@gmail.com | 3e2345a | 2013-05-24 07:01:26 +0000 | [diff] [blame] | 45 | |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 46 | canvas->translate(bounds.width(), 0); |
| 47 | } |
| 48 | canvas->restore(); |
| 49 | canvas->translate(0, bounds.height()); |
| 50 | } |
| 51 | } |
skia.committer@gmail.com | 3e2345a | 2013-05-24 07:01:26 +0000 | [diff] [blame] | 52 | |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 53 | private: |
| 54 | typedef skiagm::GM INHERITED; |
| 55 | }; |
| 56 | |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 57 | |
| 58 | class ClippedCubic2GM : public skiagm::GM { |
| 59 | public: |
| 60 | ClippedCubic2GM() {} |
| 61 | |
| 62 | protected: |
| 63 | |
caryclark | 02833bf | 2015-08-20 10:53:13 -0700 | [diff] [blame] | 64 | SkString onShortName() override { |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 65 | return SkString("clippedcubic2"); |
| 66 | } |
| 67 | |
caryclark | 02833bf | 2015-08-20 10:53:13 -0700 | [diff] [blame] | 68 | SkISize onISize() override { return SkISize::Make(1240, 390); } |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 69 | |
| 70 | void onDraw(SkCanvas* canvas) override { |
| 71 | canvas->save(); |
caryclark | 05424f7 | 2015-08-20 10:35:43 -0700 | [diff] [blame] | 72 | canvas->translate(-2, 120); |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 73 | drawOne(canvas, fPath, SkRect::MakeLTRB(0, 0, 80, 150)); |
| 74 | canvas->translate(0, 170); |
| 75 | drawOne(canvas, fPath, SkRect::MakeLTRB(0, 0, 80, 100)); |
| 76 | canvas->translate(0, 170); |
| 77 | drawOne(canvas, fPath, SkRect::MakeLTRB(0, 0, 30, 150)); |
| 78 | canvas->translate(0, 170); |
| 79 | drawOne(canvas, fPath, SkRect::MakeLTRB(0, 0, 10, 150)); |
| 80 | canvas->restore(); |
caryclark | 05424f7 | 2015-08-20 10:35:43 -0700 | [diff] [blame] | 81 | canvas->save(); |
| 82 | canvas->translate(20, -2); |
| 83 | drawOne(canvas, fFlipped, SkRect::MakeLTRB(0, 0, 150, 80)); |
| 84 | canvas->translate(170, 0); |
| 85 | drawOne(canvas, fFlipped, SkRect::MakeLTRB(0, 0, 100, 80)); |
| 86 | canvas->translate(170, 0); |
| 87 | drawOne(canvas, fFlipped, SkRect::MakeLTRB(0, 0, 150, 30)); |
| 88 | canvas->translate(170, 0); |
| 89 | drawOne(canvas, fFlipped, SkRect::MakeLTRB(0, 0, 150, 10)); |
| 90 | canvas->restore(); |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | void drawOne(SkCanvas* canvas, const SkPath& path, const SkRect& clip) { |
| 94 | SkPaint framePaint, fillPaint; |
| 95 | framePaint.setStyle(SkPaint::kStroke_Style); |
| 96 | canvas->drawRect(clip, framePaint); |
| 97 | canvas->drawPath(path, framePaint); |
| 98 | canvas->save(); |
| 99 | canvas->clipRect(clip); |
| 100 | canvas->drawPath(path, fillPaint); |
| 101 | canvas->restore(); |
| 102 | } |
| 103 | |
| 104 | void onOnceBeforeDraw() override { |
| 105 | fPath.moveTo(69.7030518991886f, 0); |
| 106 | fPath.cubicTo( 69.7030518991886f, 21.831149999999997f, |
| 107 | 58.08369508178456f, 43.66448333333333f, 34.8449814469765f, 65.5f); |
| 108 | fPath.cubicTo( 11.608591683531916f, 87.33115f, -0.010765133872116195f, 109.16448333333332f, |
| 109 | -0.013089005235602302f, 131); |
| 110 | fPath.close(); |
caryclark | 05424f7 | 2015-08-20 10:35:43 -0700 | [diff] [blame] | 111 | fFlipped = fPath; |
| 112 | SkMatrix matrix; |
| 113 | matrix.reset(); |
| 114 | matrix.setScaleX(0); |
| 115 | matrix.setScaleY(0); |
| 116 | matrix.setSkewX(1); |
| 117 | matrix.setSkewY(1); |
| 118 | fFlipped.transform(matrix); |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | SkPath fPath; |
caryclark | 05424f7 | 2015-08-20 10:35:43 -0700 | [diff] [blame] | 122 | SkPath fFlipped; |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 123 | private: |
| 124 | typedef skiagm::GM INHERITED; |
| 125 | }; |
| 126 | |
| 127 | |
reed@google.com | 27b90fa | 2013-03-08 18:44:01 +0000 | [diff] [blame] | 128 | class CubicPathGM : public skiagm::GM { |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 129 | public: |
| 130 | CubicPathGM() {} |
| 131 | |
| 132 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 133 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 134 | SkString onShortName() { |
| 135 | return SkString("cubicpath"); |
| 136 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 137 | |
reed@google.com | 27b90fa | 2013-03-08 18:44:01 +0000 | [diff] [blame] | 138 | SkISize onISize() { return SkISize::Make(1240, 390); } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 139 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 140 | void drawPath(SkPath& path,SkCanvas* canvas,SkColor color, |
| 141 | const SkRect& clip,SkPaint::Cap cap, SkPaint::Join join, |
| 142 | SkPaint::Style style, SkPath::FillType fill, |
| 143 | SkScalar strokeWidth) { |
| 144 | path.setFillType(fill); |
| 145 | SkPaint paint; |
| 146 | paint.setStrokeCap(cap); |
| 147 | paint.setStrokeWidth(strokeWidth); |
| 148 | paint.setStrokeJoin(join); |
| 149 | paint.setColor(color); |
| 150 | paint.setStyle(style); |
| 151 | canvas->save(); |
| 152 | canvas->clipRect(clip); |
| 153 | canvas->drawPath(path, paint); |
| 154 | canvas->restore(); |
| 155 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 156 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 157 | virtual void onDraw(SkCanvas* canvas) { |
| 158 | struct FillAndName { |
| 159 | SkPath::FillType fFill; |
| 160 | const char* fName; |
| 161 | }; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 162 | constexpr FillAndName gFills[] = { |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 163 | {SkPath::kWinding_FillType, "Winding"}, |
| 164 | {SkPath::kEvenOdd_FillType, "Even / Odd"}, |
| 165 | {SkPath::kInverseWinding_FillType, "Inverse Winding"}, |
| 166 | {SkPath::kInverseEvenOdd_FillType, "Inverse Even / Odd"}, |
| 167 | }; |
| 168 | struct StyleAndName { |
| 169 | SkPaint::Style fStyle; |
| 170 | const char* fName; |
| 171 | }; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 172 | constexpr StyleAndName gStyles[] = { |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 173 | {SkPaint::kFill_Style, "Fill"}, |
| 174 | {SkPaint::kStroke_Style, "Stroke"}, |
| 175 | {SkPaint::kStrokeAndFill_Style, "Stroke And Fill"}, |
| 176 | }; |
| 177 | struct CapAndName { |
| 178 | SkPaint::Cap fCap; |
| 179 | SkPaint::Join fJoin; |
| 180 | const char* fName; |
| 181 | }; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 182 | constexpr CapAndName gCaps[] = { |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 183 | {SkPaint::kButt_Cap, SkPaint::kBevel_Join, "Butt"}, |
| 184 | {SkPaint::kRound_Cap, SkPaint::kRound_Join, "Round"}, |
| 185 | {SkPaint::kSquare_Cap, SkPaint::kBevel_Join, "Square"} |
| 186 | }; |
| 187 | struct PathAndName { |
| 188 | SkPath fPath; |
| 189 | const char* fName; |
| 190 | }; |
| 191 | PathAndName path; |
| 192 | path.fPath.moveTo(25*SK_Scalar1, 10*SK_Scalar1); |
| 193 | path.fPath.cubicTo(40*SK_Scalar1, 20*SK_Scalar1, |
| 194 | 60*SK_Scalar1, 20*SK_Scalar1, |
| 195 | 75*SK_Scalar1, 10*SK_Scalar1); |
| 196 | path.fName = "moveTo-cubic"; |
| 197 | |
| 198 | SkPaint titlePaint; |
| 199 | titlePaint.setColor(SK_ColorBLACK); |
| 200 | titlePaint.setAntiAlias(true); |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 201 | sk_tool_utils::set_portable_typeface(&titlePaint); |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 202 | titlePaint.setTextSize(15 * SK_Scalar1); |
| 203 | const char title[] = "Cubic Drawn Into Rectangle Clips With " |
| 204 | "Indicated Style, Fill and Linecaps, with stroke width 10"; |
Cary Clark | 2a475ea | 2017-04-28 15:35:12 -0400 | [diff] [blame] | 205 | canvas->drawString(title, |
| 206 | 20 * SK_Scalar1, |
| 207 | 20 * SK_Scalar1, |
| 208 | titlePaint); |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 209 | |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 210 | SkRandom rand; |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 211 | SkRect rect = SkRect::MakeWH(100*SK_Scalar1, 30*SK_Scalar1); |
| 212 | canvas->save(); |
| 213 | canvas->translate(10 * SK_Scalar1, 30 * SK_Scalar1); |
| 214 | canvas->save(); |
| 215 | for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) { |
| 216 | if (0 < cap) { |
| 217 | canvas->translate((rect.width() + 40 * SK_Scalar1) * SK_ARRAY_COUNT(gStyles), 0); |
| 218 | } |
| 219 | canvas->save(); |
| 220 | for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) { |
| 221 | if (0 < fill) { |
| 222 | canvas->translate(0, rect.height() + 40 * SK_Scalar1); |
| 223 | } |
| 224 | canvas->save(); |
| 225 | for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) { |
| 226 | if (0 < style) { |
| 227 | canvas->translate(rect.width() + 40 * SK_Scalar1, 0); |
| 228 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 229 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 230 | SkColor color = 0xff007000; |
| 231 | this->drawPath(path.fPath, canvas, color, rect, |
| 232 | gCaps[cap].fCap, gCaps[cap].fJoin, gStyles[style].fStyle, |
| 233 | gFills[fill].fFill, SK_Scalar1*10); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 234 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 235 | SkPaint rectPaint; |
| 236 | rectPaint.setColor(SK_ColorBLACK); |
| 237 | rectPaint.setStyle(SkPaint::kStroke_Style); |
| 238 | rectPaint.setStrokeWidth(-1); |
| 239 | rectPaint.setAntiAlias(true); |
| 240 | canvas->drawRect(rect, rectPaint); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 241 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 242 | SkPaint labelPaint; |
| 243 | labelPaint.setColor(color); |
| 244 | labelPaint.setAntiAlias(true); |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 245 | sk_tool_utils::set_portable_typeface(&labelPaint); |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 246 | labelPaint.setTextSize(10 * SK_Scalar1); |
Cary Clark | 2a475ea | 2017-04-28 15:35:12 -0400 | [diff] [blame] | 247 | canvas->drawString(gStyles[style].fName, |
| 248 | 0, rect.height() + 12 * SK_Scalar1, |
| 249 | labelPaint); |
| 250 | canvas->drawString(gFills[fill].fName, |
| 251 | 0, rect.height() + 24 * SK_Scalar1, |
| 252 | labelPaint); |
| 253 | canvas->drawString(gCaps[cap].fName, |
| 254 | 0, rect.height() + 36 * SK_Scalar1, |
| 255 | labelPaint); |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 256 | } |
| 257 | canvas->restore(); |
| 258 | } |
| 259 | canvas->restore(); |
| 260 | } |
| 261 | canvas->restore(); |
| 262 | canvas->restore(); |
| 263 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 264 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 265 | private: |
reed@google.com | 27b90fa | 2013-03-08 18:44:01 +0000 | [diff] [blame] | 266 | typedef skiagm::GM INHERITED; |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 267 | }; |
| 268 | |
reed@google.com | 27b90fa | 2013-03-08 18:44:01 +0000 | [diff] [blame] | 269 | class CubicClosePathGM : public skiagm::GM { |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 270 | public: |
| 271 | CubicClosePathGM() {} |
| 272 | |
| 273 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 274 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 275 | SkString onShortName() { |
| 276 | return SkString("cubicclosepath"); |
| 277 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 278 | |
reed@google.com | 27b90fa | 2013-03-08 18:44:01 +0000 | [diff] [blame] | 279 | SkISize onISize() { return SkISize::Make(1240, 390); } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 280 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 281 | void drawPath(SkPath& path,SkCanvas* canvas,SkColor color, |
| 282 | const SkRect& clip,SkPaint::Cap cap, SkPaint::Join join, |
| 283 | SkPaint::Style style, SkPath::FillType fill, |
| 284 | SkScalar strokeWidth) { |
| 285 | path.setFillType(fill); |
| 286 | SkPaint paint; |
| 287 | paint.setStrokeCap(cap); |
| 288 | paint.setStrokeWidth(strokeWidth); |
| 289 | paint.setStrokeJoin(join); |
| 290 | paint.setColor(color); |
| 291 | paint.setStyle(style); |
| 292 | canvas->save(); |
| 293 | canvas->clipRect(clip); |
| 294 | canvas->drawPath(path, paint); |
| 295 | canvas->restore(); |
| 296 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 297 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 298 | virtual void onDraw(SkCanvas* canvas) { |
| 299 | struct FillAndName { |
| 300 | SkPath::FillType fFill; |
| 301 | const char* fName; |
| 302 | }; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 303 | constexpr FillAndName gFills[] = { |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 304 | {SkPath::kWinding_FillType, "Winding"}, |
| 305 | {SkPath::kEvenOdd_FillType, "Even / Odd"}, |
| 306 | {SkPath::kInverseWinding_FillType, "Inverse Winding"}, |
| 307 | {SkPath::kInverseEvenOdd_FillType, "Inverse Even / Odd"}, |
| 308 | }; |
| 309 | struct StyleAndName { |
| 310 | SkPaint::Style fStyle; |
| 311 | const char* fName; |
| 312 | }; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 313 | constexpr StyleAndName gStyles[] = { |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 314 | {SkPaint::kFill_Style, "Fill"}, |
| 315 | {SkPaint::kStroke_Style, "Stroke"}, |
| 316 | {SkPaint::kStrokeAndFill_Style, "Stroke And Fill"}, |
| 317 | }; |
| 318 | struct CapAndName { |
| 319 | SkPaint::Cap fCap; |
| 320 | SkPaint::Join fJoin; |
| 321 | const char* fName; |
| 322 | }; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 323 | constexpr CapAndName gCaps[] = { |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 324 | {SkPaint::kButt_Cap, SkPaint::kBevel_Join, "Butt"}, |
| 325 | {SkPaint::kRound_Cap, SkPaint::kRound_Join, "Round"}, |
| 326 | {SkPaint::kSquare_Cap, SkPaint::kBevel_Join, "Square"} |
| 327 | }; |
| 328 | struct PathAndName { |
| 329 | SkPath fPath; |
| 330 | const char* fName; |
| 331 | }; |
| 332 | PathAndName path; |
| 333 | path.fPath.moveTo(25*SK_Scalar1, 10*SK_Scalar1); |
| 334 | path.fPath.cubicTo(40*SK_Scalar1, 20*SK_Scalar1, |
| 335 | 60*SK_Scalar1, 20*SK_Scalar1, |
| 336 | 75*SK_Scalar1, 10*SK_Scalar1); |
| 337 | path.fPath.close(); |
| 338 | path.fName = "moveTo-cubic-close"; |
| 339 | |
| 340 | SkPaint titlePaint; |
| 341 | titlePaint.setColor(SK_ColorBLACK); |
| 342 | titlePaint.setAntiAlias(true); |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 343 | sk_tool_utils::set_portable_typeface(&titlePaint); |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 344 | titlePaint.setTextSize(15 * SK_Scalar1); |
| 345 | const char title[] = "Cubic Closed Drawn Into Rectangle Clips With " |
| 346 | "Indicated Style, Fill and Linecaps, with stroke width 10"; |
Cary Clark | 2a475ea | 2017-04-28 15:35:12 -0400 | [diff] [blame] | 347 | canvas->drawString(title, |
| 348 | 20 * SK_Scalar1, |
| 349 | 20 * SK_Scalar1, |
| 350 | titlePaint); |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 351 | |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 352 | SkRandom rand; |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 353 | SkRect rect = SkRect::MakeWH(100*SK_Scalar1, 30*SK_Scalar1); |
| 354 | canvas->save(); |
| 355 | canvas->translate(10 * SK_Scalar1, 30 * SK_Scalar1); |
| 356 | canvas->save(); |
| 357 | for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) { |
| 358 | if (0 < cap) { |
| 359 | canvas->translate((rect.width() + 40 * SK_Scalar1) * SK_ARRAY_COUNT(gStyles), 0); |
| 360 | } |
| 361 | canvas->save(); |
| 362 | for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) { |
| 363 | if (0 < fill) { |
| 364 | canvas->translate(0, rect.height() + 40 * SK_Scalar1); |
| 365 | } |
| 366 | canvas->save(); |
| 367 | for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) { |
| 368 | if (0 < style) { |
| 369 | canvas->translate(rect.width() + 40 * SK_Scalar1, 0); |
| 370 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 371 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 372 | SkColor color = 0xff007000; |
| 373 | this->drawPath(path.fPath, canvas, color, rect, |
| 374 | gCaps[cap].fCap, gCaps[cap].fJoin, gStyles[style].fStyle, |
| 375 | gFills[fill].fFill, SK_Scalar1*10); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 376 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 377 | SkPaint rectPaint; |
| 378 | rectPaint.setColor(SK_ColorBLACK); |
| 379 | rectPaint.setStyle(SkPaint::kStroke_Style); |
| 380 | rectPaint.setStrokeWidth(-1); |
| 381 | rectPaint.setAntiAlias(true); |
| 382 | canvas->drawRect(rect, rectPaint); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 383 | |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 384 | SkPaint labelPaint; |
| 385 | labelPaint.setColor(color); |
| 386 | labelPaint.setAntiAlias(true); |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 387 | sk_tool_utils::set_portable_typeface(&labelPaint); |
schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame] | 388 | labelPaint.setTextSize(10 * SK_Scalar1); |
Cary Clark | 2a475ea | 2017-04-28 15:35:12 -0400 | [diff] [blame] | 389 | canvas->drawString(gStyles[style].fName, |
| 390 | 0, rect.height() + 12 * SK_Scalar1, |
| 391 | labelPaint); |
| 392 | canvas->drawString(gFills[fill].fName, |
| 393 | 0, rect.height() + 24 * SK_Scalar1, |
| 394 | labelPaint); |
| 395 | canvas->drawString(gCaps[cap].fName, |
| 396 | 0, rect.height() + 36 * SK_Scalar1, |
| 397 | labelPaint); |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 398 | } |
| 399 | canvas->restore(); |
| 400 | } |
| 401 | canvas->restore(); |
| 402 | } |
| 403 | canvas->restore(); |
| 404 | canvas->restore(); |
| 405 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 406 | |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 407 | private: |
reed@google.com | 27b90fa | 2013-03-08 18:44:01 +0000 | [diff] [blame] | 408 | typedef skiagm::GM INHERITED; |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 409 | }; |
| 410 | |
caryclark | 4693a17 | 2016-04-06 08:54:06 -0700 | [diff] [blame] | 411 | DEF_SIMPLE_GM(bug5099, canvas, 50, 50) { |
| 412 | SkPaint p; |
| 413 | p.setColor(SK_ColorRED); |
| 414 | p.setAntiAlias(true); |
| 415 | p.setStyle(SkPaint::kStroke_Style); |
| 416 | p.setStrokeWidth(10); |
| 417 | |
| 418 | SkPath path; |
| 419 | path.moveTo(6, 27); |
| 420 | path.cubicTo(31.5f, 1.5f, 3.5f, 4.5f, 29, 29); |
| 421 | canvas->drawPath(path, p); |
| 422 | } |
| 423 | |
Cary Clark | d463198 | 2017-01-05 12:08:38 -0500 | [diff] [blame] | 424 | DEF_SIMPLE_GM(bug6083, canvas, 100, 50) { |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 425 | SkPaint p; |
| 426 | p.setColor(SK_ColorRED); |
| 427 | p.setAntiAlias(true); |
| 428 | p.setStyle(SkPaint::kStroke_Style); |
| 429 | p.setStrokeWidth(15); |
| 430 | canvas->translate(-500, -130); |
| 431 | SkPath path; |
| 432 | path.moveTo(500.988f, 155.200f); |
| 433 | path.lineTo(526.109f, 155.200f); |
| 434 | SkPoint p1 = { 526.109f, 155.200f }; |
| 435 | SkPoint p2 = { 525.968f, 212.968f }; |
| 436 | SkPoint p3 = { 526.109f, 241.840f }; |
| 437 | path.cubicTo(p1, p2, p3); |
| 438 | canvas->drawPath(path, p); |
| 439 | canvas->translate(50, 0); |
| 440 | path.reset(); |
| 441 | p2.set(525.968f, 213.172f); |
| 442 | path.moveTo(500.988f, 155.200f); |
| 443 | path.lineTo(526.109f, 155.200f); |
| 444 | path.cubicTo(p1, p2, p3); |
| 445 | canvas->drawPath(path, p); |
Cary Clark | d463198 | 2017-01-05 12:08:38 -0500 | [diff] [blame] | 446 | } |
| 447 | |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 448 | ////////////////////////////////////////////////////////////////////////////// |
| 449 | |
reed@google.com | 27b90fa | 2013-03-08 18:44:01 +0000 | [diff] [blame] | 450 | DEF_GM( return new CubicPathGM; ) |
| 451 | DEF_GM( return new CubicClosePathGM; ) |
reed@google.com | 22999c6 | 2013-05-23 19:30:48 +0000 | [diff] [blame] | 452 | DEF_GM( return new ClippedCubicGM; ) |
caryclark | 7d17340 | 2015-08-20 08:23:52 -0700 | [diff] [blame] | 453 | DEF_GM( return new ClippedCubic2GM; ) |