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