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