blob: e3d3e6e9abf8c4f071fb41d0017e21ca1df01818 [file] [log] [blame]
commit-bot@chromium.orged9806f2014-02-21 02:32:36 +00001/*
2 * Copyright 2014 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 "SkCanvas.h"
10#include "SkRRect.h"
11#include "SkPath.h"
12
13class DRRectGM : public skiagm::GM {
14public:
15 DRRectGM() {}
16
17protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000018
mtklein36352bf2015-03-25 18:17:31 -070019 SkString onShortName() override {
commit-bot@chromium.orged9806f2014-02-21 02:32:36 +000020 return SkString("drrect");
21 }
22
mtklein36352bf2015-03-25 18:17:31 -070023 SkISize onISize() override {
commit-bot@chromium.orged9806f2014-02-21 02:32:36 +000024 return SkISize::Make(640, 480);
25 }
26
mtklein36352bf2015-03-25 18:17:31 -070027 void onDraw(SkCanvas* canvas) override {
commit-bot@chromium.orged9806f2014-02-21 02:32:36 +000028 SkPaint paint;
29 paint.setAntiAlias(true);
30
31 SkRRect outers[4];
32 // like squares/circles, to exercise fast-cases in GPU
33 SkRect r = { 0, 0, 100, 100 };
34 SkVector radii[4] = {
35 { 0, 0 }, { 30, 1 }, { 10, 40 }, { 40, 40 }
36 };
skia.committer@gmail.com25c71272014-02-21 03:02:02 +000037
commit-bot@chromium.orged9806f2014-02-21 02:32:36 +000038 const SkScalar dx = r.width() + 16;
39 const SkScalar dy = r.height() + 16;
40
41 outers[0].setRect(r);
42 outers[1].setOval(r);
43 outers[2].setRectXY(r, 20, 20);
44 outers[3].setRectRadii(r, radii);
45
46 SkRRect inners[5];
47 r.inset(25, 25);
48
49 inners[0].setEmpty();
50 inners[1].setRect(r);
51 inners[2].setOval(r);
52 inners[3].setRectXY(r, 20, 20);
53 inners[4].setRectRadii(r, radii);
54
55 canvas->translate(16, 16);
56 for (size_t j = 0; j < SK_ARRAY_COUNT(inners); ++j) {
57 for (size_t i = 0; i < SK_ARRAY_COUNT(outers); ++i) {
58 canvas->save();
59 canvas->translate(dx * j, dy * i);
60 canvas->drawDRRect(outers[i], inners[j], paint);
61 canvas->restore();
62 }
63 }
64 }
65
66private:
67 typedef GM INHERITED;
68};
69
70DEF_GM( return new DRRectGM; )