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: |
| 18 | virtual SkString onShortName() SK_OVERRIDE { |
| 19 | return SkString("drrect"); |
| 20 | } |
| 21 | |
| 22 | virtual SkISize onISize() SK_OVERRIDE { |
| 23 | return SkISize::Make(640, 480); |
| 24 | } |
| 25 | |
| 26 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 27 | SkPaint paint; |
| 28 | paint.setAntiAlias(true); |
| 29 | |
| 30 | SkRRect outers[4]; |
| 31 | // like squares/circles, to exercise fast-cases in GPU |
| 32 | SkRect r = { 0, 0, 100, 100 }; |
| 33 | SkVector radii[4] = { |
| 34 | { 0, 0 }, { 30, 1 }, { 10, 40 }, { 40, 40 } |
| 35 | }; |
| 36 | |
| 37 | const SkScalar dx = r.width() + 16; |
| 38 | const SkScalar dy = r.height() + 16; |
| 39 | |
| 40 | outers[0].setRect(r); |
| 41 | outers[1].setOval(r); |
| 42 | outers[2].setRectXY(r, 20, 20); |
| 43 | outers[3].setRectRadii(r, radii); |
| 44 | |
| 45 | SkRRect inners[5]; |
| 46 | r.inset(25, 25); |
| 47 | |
| 48 | inners[0].setEmpty(); |
| 49 | inners[1].setRect(r); |
| 50 | inners[2].setOval(r); |
| 51 | inners[3].setRectXY(r, 20, 20); |
| 52 | inners[4].setRectRadii(r, radii); |
| 53 | |
| 54 | canvas->translate(16, 16); |
| 55 | for (size_t j = 0; j < SK_ARRAY_COUNT(inners); ++j) { |
| 56 | for (size_t i = 0; i < SK_ARRAY_COUNT(outers); ++i) { |
| 57 | canvas->save(); |
| 58 | canvas->translate(dx * j, dy * i); |
| 59 | canvas->drawDRRect(outers[i], inners[j], paint); |
| 60 | canvas->restore(); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | private: |
| 66 | typedef GM INHERITED; |
| 67 | }; |
| 68 | |
| 69 | DEF_GM( return new DRRectGM; ) |