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