commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | */ |
| 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" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkMatrix.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 12 | #include "include/core/SkPaint.h" |
| 13 | #include "include/core/SkPoint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/core/SkRRect.h" |
| 15 | #include "include/core/SkRect.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 16 | #include "include/core/SkScalar.h" |
| 17 | #include "include/core/SkShader.h" |
| 18 | #include "include/core/SkSize.h" |
| 19 | #include "include/core/SkString.h" |
| 20 | #include "include/core/SkTileMode.h" |
| 21 | #include "include/core/SkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 22 | #include "include/effects/SkGradientShader.h" |
| 23 | #include "include/private/SkTArray.h" |
| 24 | #include "include/utils/SkRandom.h" |
| 25 | #include "tools/ToolUtils.h" |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 26 | |
| 27 | namespace skiagm { |
| 28 | |
robertphillips | 05302f8 | 2015-09-29 11:24:07 -0700 | [diff] [blame] | 29 | static SkColor gen_color(SkRandom* rand) { |
| 30 | SkScalar hsv[3]; |
| 31 | hsv[0] = rand->nextRangeF(0.0f, 360.0f); |
| 32 | hsv[1] = rand->nextRangeF(0.75f, 1.0f); |
| 33 | hsv[2] = rand->nextRangeF(0.75f, 1.0f); |
| 34 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 35 | return ToolUtils::color_to_565(SkHSVToColor(hsv)); |
robertphillips | 05302f8 | 2015-09-29 11:24:07 -0700 | [diff] [blame] | 36 | } |
| 37 | |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 38 | class RoundRectGM : public GM { |
| 39 | public: |
| 40 | RoundRectGM() { |
| 41 | this->setBGColor(0xFF000000); |
| 42 | this->makePaints(); |
| 43 | this->makeMatrices(); |
| 44 | } |
| 45 | |
| 46 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 47 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 48 | SkString onShortName() override { |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 49 | return SkString("roundrects"); |
| 50 | } |
| 51 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 52 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 53 | return SkISize::Make(1200, 900); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void makePaints() { |
| 57 | { |
jvanverth | 250d00b | 2016-08-25 05:53:00 -0700 | [diff] [blame] | 58 | // no AA |
| 59 | SkPaint p; |
| 60 | fPaints.push_back(p); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | { |
jvanverth | 250d00b | 2016-08-25 05:53:00 -0700 | [diff] [blame] | 64 | // AA |
| 65 | SkPaint p; |
| 66 | p.setAntiAlias(true); |
| 67 | fPaints.push_back(p); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | { |
jvanverth | 250d00b | 2016-08-25 05:53:00 -0700 | [diff] [blame] | 71 | // AA with stroke style |
| 72 | SkPaint p; |
| 73 | p.setAntiAlias(true); |
| 74 | p.setStyle(SkPaint::kStroke_Style); |
| 75 | p.setStrokeWidth(SkIntToScalar(5)); |
| 76 | fPaints.push_back(p); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | { |
jvanverth | 250d00b | 2016-08-25 05:53:00 -0700 | [diff] [blame] | 80 | // AA with stroke style, width = 0 |
| 81 | SkPaint p; |
| 82 | p.setAntiAlias(true); |
| 83 | p.setStyle(SkPaint::kStroke_Style); |
| 84 | fPaints.push_back(p); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | { |
jvanverth | 250d00b | 2016-08-25 05:53:00 -0700 | [diff] [blame] | 88 | // AA with stroke and fill style |
| 89 | SkPaint p; |
| 90 | p.setAntiAlias(true); |
| 91 | p.setStyle(SkPaint::kStrokeAndFill_Style); |
| 92 | p.setStrokeWidth(SkIntToScalar(3)); |
| 93 | fPaints.push_back(p); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
| 97 | void makeMatrices() { |
| 98 | { |
jvanverth | 250d00b | 2016-08-25 05:53:00 -0700 | [diff] [blame] | 99 | SkMatrix m; |
| 100 | m.setIdentity(); |
| 101 | fMatrices.push_back(m); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | { |
jvanverth | 250d00b | 2016-08-25 05:53:00 -0700 | [diff] [blame] | 105 | SkMatrix m; |
| 106 | m.setScale(SkIntToScalar(3), SkIntToScalar(2)); |
| 107 | fMatrices.push_back(m); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | { |
jvanverth | 250d00b | 2016-08-25 05:53:00 -0700 | [diff] [blame] | 111 | SkMatrix m; |
| 112 | m.setScale(SkIntToScalar(2), SkIntToScalar(2)); |
| 113 | fMatrices.push_back(m); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | { |
jvanverth | 250d00b | 2016-08-25 05:53:00 -0700 | [diff] [blame] | 117 | SkMatrix m; |
| 118 | m.setScale(SkIntToScalar(1), SkIntToScalar(2)); |
| 119 | fMatrices.push_back(m); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | { |
jvanverth | 250d00b | 2016-08-25 05:53:00 -0700 | [diff] [blame] | 123 | SkMatrix m; |
| 124 | m.setScale(SkIntToScalar(4), SkIntToScalar(1)); |
| 125 | fMatrices.push_back(m); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | { |
jvanverth | 250d00b | 2016-08-25 05:53:00 -0700 | [diff] [blame] | 129 | SkMatrix m; |
| 130 | m.setRotate(SkIntToScalar(90)); |
| 131 | fMatrices.push_back(m); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | { |
jvanverth | 250d00b | 2016-08-25 05:53:00 -0700 | [diff] [blame] | 135 | SkMatrix m; |
| 136 | m.setSkew(SkIntToScalar(2), SkIntToScalar(3)); |
| 137 | fMatrices.push_back(m); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | { |
jvanverth | 250d00b | 2016-08-25 05:53:00 -0700 | [diff] [blame] | 141 | SkMatrix m; |
| 142 | m.setRotate(SkIntToScalar(60)); |
| 143 | fMatrices.push_back(m); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 147 | void onDraw(SkCanvas* canvas) override { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 148 | SkRandom rand(1); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 149 | canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1); |
robertphillips | 05302f8 | 2015-09-29 11:24:07 -0700 | [diff] [blame] | 150 | const SkRect rect = SkRect::MakeLTRB(-20, -30, 20, 30); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 151 | SkRRect circleRect; |
| 152 | circleRect.setRectXY(rect, 5, 5); |
| 153 | |
| 154 | const SkScalar kXStart = 60.0f; |
| 155 | const SkScalar kYStart = 80.0f; |
| 156 | const int kXStep = 150; |
| 157 | const int kYStep = 160; |
| 158 | int maxX = fMatrices.count(); |
| 159 | |
| 160 | SkPaint rectPaint; |
| 161 | rectPaint.setAntiAlias(true); |
| 162 | rectPaint.setStyle(SkPaint::kStroke_Style); |
| 163 | rectPaint.setStrokeWidth(SkIntToScalar(0)); |
Mike Klein | d46dce3 | 2018-08-16 10:17:03 -0400 | [diff] [blame] | 164 | rectPaint.setColor(SK_ColorLTGRAY); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 165 | |
| 166 | int testCount = 0; |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 167 | for (int i = 0; i < fPaints.count(); ++i) { |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 168 | for (int j = 0; j < fMatrices.count(); ++j) { |
| 169 | canvas->save(); |
| 170 | SkMatrix mat = fMatrices[j]; |
| 171 | // position the roundrect, and make it at off-integer coords. |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 172 | mat.postTranslate(kXStart + SK_Scalar1 * kXStep * (testCount % maxX) + |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 173 | SK_Scalar1 / 4, |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 174 | kYStart + SK_Scalar1 * kYStep * (testCount / maxX) + |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 175 | 3 * SK_Scalar1 / 4); |
| 176 | canvas->concat(mat); |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 177 | |
robertphillips | 05302f8 | 2015-09-29 11:24:07 -0700 | [diff] [blame] | 178 | SkColor color = gen_color(&rand); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 179 | fPaints[i].setColor(color); |
| 180 | |
| 181 | canvas->drawRect(rect, rectPaint); |
| 182 | canvas->drawRRect(circleRect, fPaints[i]); |
| 183 | |
| 184 | canvas->restore(); |
| 185 | |
| 186 | ++testCount; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | // special cases |
| 191 | |
| 192 | // non-scaled tall and skinny roundrect |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 193 | for (int i = 0; i < fPaints.count(); ++i) { |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 194 | SkRect rect = SkRect::MakeLTRB(-20, -60, 20, 60); |
| 195 | SkRRect ellipseRect; |
| 196 | ellipseRect.setRectXY(rect, 5, 10); |
| 197 | |
| 198 | canvas->save(); |
| 199 | // position the roundrect, and make it at off-integer coords. |
| 200 | canvas->translate(kXStart + SK_Scalar1 * kXStep * 2.55f + SK_Scalar1 / 4, |
| 201 | kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4); |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 202 | |
robertphillips | 05302f8 | 2015-09-29 11:24:07 -0700 | [diff] [blame] | 203 | SkColor color = gen_color(&rand); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 204 | fPaints[i].setColor(color); |
| 205 | |
| 206 | canvas->drawRect(rect, rectPaint); |
| 207 | canvas->drawRRect(ellipseRect, fPaints[i]); |
| 208 | canvas->restore(); |
| 209 | } |
| 210 | |
| 211 | // non-scaled wide and short roundrect |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 212 | for (int i = 0; i < fPaints.count(); ++i) { |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 213 | SkRect rect = SkRect::MakeLTRB(-80, -30, 80, 30); |
| 214 | SkRRect ellipseRect; |
| 215 | ellipseRect.setRectXY(rect, 20, 5); |
| 216 | |
| 217 | canvas->save(); |
| 218 | // position the roundrect, and make it at off-integer coords. |
| 219 | canvas->translate(kXStart + SK_Scalar1 * kXStep * 4 + SK_Scalar1 / 4, |
| 220 | kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4 + |
| 221 | SK_ScalarHalf * kYStep); |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 222 | |
robertphillips | 05302f8 | 2015-09-29 11:24:07 -0700 | [diff] [blame] | 223 | SkColor color = gen_color(&rand); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 224 | fPaints[i].setColor(color); |
| 225 | |
| 226 | canvas->drawRect(rect, rectPaint); |
| 227 | canvas->drawRRect(ellipseRect, fPaints[i]); |
| 228 | canvas->restore(); |
| 229 | } |
| 230 | |
| 231 | // super skinny roundrect |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 232 | for (int i = 0; i < fPaints.count(); ++i) { |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 233 | SkRect rect = SkRect::MakeLTRB(0, -60, 1, 60); |
| 234 | SkRRect circleRect; |
| 235 | circleRect.setRectXY(rect, 5, 5); |
| 236 | |
| 237 | canvas->save(); |
| 238 | // position the roundrect, and make it at off-integer coords. |
| 239 | canvas->translate(kXStart + SK_Scalar1 * kXStep * 3.25f + SK_Scalar1 / 4, |
| 240 | kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4); |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 241 | |
robertphillips | 05302f8 | 2015-09-29 11:24:07 -0700 | [diff] [blame] | 242 | SkColor color = gen_color(&rand); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 243 | fPaints[i].setColor(color); |
| 244 | |
| 245 | canvas->drawRRect(circleRect, fPaints[i]); |
| 246 | canvas->restore(); |
| 247 | } |
| 248 | |
| 249 | // super short roundrect |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 250 | for (int i = 0; i < fPaints.count(); ++i) { |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 251 | SkRect rect = SkRect::MakeLTRB(-80, -1, 80, 0); |
| 252 | SkRRect circleRect; |
| 253 | circleRect.setRectXY(rect, 5, 5); |
| 254 | |
| 255 | canvas->save(); |
| 256 | // position the roundrect, and make it at off-integer coords. |
| 257 | canvas->translate(kXStart + SK_Scalar1 * kXStep * 2.5f + SK_Scalar1 / 4, |
| 258 | kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4 + |
| 259 | SK_ScalarHalf * kYStep); |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 260 | |
robertphillips | 05302f8 | 2015-09-29 11:24:07 -0700 | [diff] [blame] | 261 | SkColor color = gen_color(&rand); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 262 | fPaints[i].setColor(color); |
| 263 | |
| 264 | canvas->drawRRect(circleRect, fPaints[i]); |
| 265 | canvas->restore(); |
| 266 | } |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 267 | |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 268 | // radial gradient |
| 269 | SkPoint center = SkPoint::Make(SkIntToScalar(0), SkIntToScalar(0)); |
| 270 | SkColor colors[] = { SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN }; |
| 271 | SkScalar pos[] = { 0, SK_ScalarHalf, SK_Scalar1 }; |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 272 | auto shader = SkGradientShader::MakeRadial(center, 20, colors, pos, SK_ARRAY_COUNT(colors), |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 273 | SkTileMode::kClamp); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 274 | |
| 275 | for (int i = 0; i < fPaints.count(); ++i) { |
| 276 | canvas->save(); |
| 277 | // position the path, and make it at off-integer coords. |
| 278 | canvas->translate(kXStart + SK_Scalar1 * kXStep * 0 + SK_Scalar1 / 4, |
| 279 | kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4 + |
| 280 | SK_ScalarHalf * kYStep); |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 281 | |
robertphillips | 05302f8 | 2015-09-29 11:24:07 -0700 | [diff] [blame] | 282 | SkColor color = gen_color(&rand); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 283 | fPaints[i].setColor(color); |
| 284 | fPaints[i].setShader(shader); |
| 285 | |
| 286 | canvas->drawRect(rect, rectPaint); |
| 287 | canvas->drawRRect(circleRect, fPaints[i]); |
| 288 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 289 | fPaints[i].setShader(nullptr); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 290 | |
| 291 | canvas->restore(); |
| 292 | } |
| 293 | |
| 294 | // strokes and radii |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 295 | { |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 296 | SkScalar radii[][2] = { |
| 297 | {10,10}, |
| 298 | {5,15}, |
| 299 | {5,15}, |
| 300 | {5,15} |
| 301 | }; |
| 302 | |
| 303 | SkScalar strokeWidths[] = { |
| 304 | 20, 10, 20, 40 |
| 305 | }; |
| 306 | |
| 307 | for (int i = 0; i < 4; ++i) { |
| 308 | SkRRect circleRect; |
| 309 | circleRect.setRectXY(rect, radii[i][0], radii[i][1]); |
| 310 | |
| 311 | canvas->save(); |
| 312 | // position the roundrect, and make it at off-integer coords. |
| 313 | canvas->translate(kXStart + SK_Scalar1 * kXStep * 5 + SK_Scalar1 / 4, |
| 314 | kYStart + SK_Scalar1 * kYStep * i + 3 * SK_Scalar1 / 4 + |
| 315 | SK_ScalarHalf * kYStep); |
skia.committer@gmail.com | e36a168 | 2013-04-23 07:01:29 +0000 | [diff] [blame] | 316 | |
robertphillips | 05302f8 | 2015-09-29 11:24:07 -0700 | [diff] [blame] | 317 | SkColor color = gen_color(&rand); |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 318 | |
| 319 | SkPaint p; |
| 320 | p.setAntiAlias(true); |
| 321 | p.setStyle(SkPaint::kStroke_Style); |
| 322 | p.setStrokeWidth(strokeWidths[i]); |
| 323 | p.setColor(color); |
| 324 | |
| 325 | canvas->drawRRect(circleRect, p); |
| 326 | canvas->restore(); |
| 327 | } |
| 328 | } |
| 329 | |
halcanary | 6950de6 | 2015-11-07 05:29:00 -0800 | [diff] [blame] | 330 | // test old entry point ( https://bug.skia.org/3786 ) |
robertphillips | 05302f8 | 2015-09-29 11:24:07 -0700 | [diff] [blame] | 331 | { |
| 332 | canvas->save(); |
| 333 | |
| 334 | canvas->translate(kXStart + SK_Scalar1 * kXStep * 5 + SK_Scalar1 / 4, |
| 335 | kYStart + SK_Scalar1 * kYStep * 4 + SK_Scalar1 / 4 + |
| 336 | SK_ScalarHalf * kYStep); |
| 337 | |
| 338 | const SkColor color = gen_color(&rand); |
| 339 | |
| 340 | SkPaint p; |
| 341 | p.setColor(color); |
| 342 | |
| 343 | const SkRect oooRect = { 20, 30, -20, -30 }; // intentionally out of order |
| 344 | canvas->drawRoundRect(oooRect, 10, 10, p); |
| 345 | |
| 346 | canvas->restore(); |
| 347 | } |
jvanverth | 250d00b | 2016-08-25 05:53:00 -0700 | [diff] [blame] | 348 | |
| 349 | // rrect with stroke > radius/2 |
| 350 | { |
| 351 | SkRect smallRect = { -30, -20, 30, 20 }; |
| 352 | SkRRect circleRect; |
| 353 | circleRect.setRectXY(smallRect, 5, 5); |
| 354 | |
| 355 | canvas->save(); |
| 356 | // position the roundrect, and make it at off-integer coords. |
| 357 | canvas->translate(kXStart + SK_Scalar1 * kXStep * 5 + SK_Scalar1 / 4, |
| 358 | kYStart - SK_Scalar1 * kYStep + 73 * SK_Scalar1 / 4 + |
| 359 | SK_ScalarHalf * kYStep); |
| 360 | |
| 361 | SkColor color = gen_color(&rand); |
| 362 | |
| 363 | SkPaint p; |
| 364 | p.setAntiAlias(true); |
| 365 | p.setStyle(SkPaint::kStroke_Style); |
| 366 | p.setStrokeWidth(25); |
| 367 | p.setColor(color); |
| 368 | |
| 369 | canvas->drawRRect(circleRect, p); |
| 370 | canvas->restore(); |
| 371 | } |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | private: |
| 375 | SkTArray<SkPaint> fPaints; |
| 376 | SkTArray<SkMatrix> fMatrices; |
| 377 | |
| 378 | typedef GM INHERITED; |
| 379 | }; |
| 380 | |
| 381 | ////////////////////////////////////////////////////////////////////////////// |
| 382 | |
Hal Canary | e964c18 | 2019-01-23 10:22:01 -0500 | [diff] [blame] | 383 | DEF_GM( return new RoundRectGM; ) |
commit-bot@chromium.org | a534b84 | 2013-04-22 18:05:19 +0000 | [diff] [blame] | 384 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 385 | } // namespace skiagm |