commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 13 | class DRRectGM : public skiagm::GM { |
| 14 | public: |
| 15 | DRRectGM() {} |
| 16 | |
| 17 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 18 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 19 | SkString onShortName() override { |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 20 | return SkString("drrect"); |
| 21 | } |
| 22 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 23 | SkISize onISize() override { |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 24 | return SkISize::Make(640, 480); |
| 25 | } |
| 26 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 27 | void onDraw(SkCanvas* canvas) override { |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 28 | 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.com | 25c7127 | 2014-02-21 03:02:02 +0000 | [diff] [blame] | 37 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 38 | 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 | |
| 66 | private: |
| 67 | typedef GM INHERITED; |
| 68 | }; |
| 69 | |
| 70 | DEF_GM( return new DRRectGM; ) |