1ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org/*
2ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org * Copyright 2014 Google Inc.
3ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org *
4ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be
5ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org * found in the LICENSE file.
6ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org */
7ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
8ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org#include "gm.h"
9ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org#include "SkCanvas.h"
10ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org#include "SkRRect.h"
11ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org#include "SkPath.h"
12ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
13ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.orgclass DRRectGM : public skiagm::GM {
14ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.orgpublic:
15ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    DRRectGM() {}
16ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
17ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.orgprotected:
18a90c6803865766d28e92091f56f718f5e41fe80fcommit-bot@chromium.org
1936352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    SkString onShortName() override {
20ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        return SkString("drrect");
21ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    }
22ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
2336352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    SkISize onISize() override {
24ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        return SkISize::Make(640, 480);
25ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    }
26ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
2736352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    void onDraw(SkCanvas* canvas) override {
28ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        SkPaint paint;
29ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        paint.setAntiAlias(true);
30ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
31ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        SkRRect outers[4];
32ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        // like squares/circles, to exercise fast-cases in GPU
33ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        SkRect r = { 0, 0, 100, 100 };
34ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        SkVector radii[4] = {
35ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org            { 0, 0 }, { 30, 1 }, { 10, 40 }, { 40, 40 }
36ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        };
3725c7127c904aa6e03209220e8ecb7128d3595f11skia.committer@gmail.com
38ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        const SkScalar dx = r.width() + 16;
39ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        const SkScalar dy = r.height() + 16;
40ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
41ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        outers[0].setRect(r);
42ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        outers[1].setOval(r);
43ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        outers[2].setRectXY(r, 20, 20);
44ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        outers[3].setRectRadii(r, radii);
45ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
46ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        SkRRect inners[5];
47ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        r.inset(25, 25);
48ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
49ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        inners[0].setEmpty();
50ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        inners[1].setRect(r);
51ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        inners[2].setOval(r);
52ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        inners[3].setRectXY(r, 20, 20);
53ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        inners[4].setRectRadii(r, radii);
54ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
55ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        canvas->translate(16, 16);
56ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        for (size_t j = 0; j < SK_ARRAY_COUNT(inners); ++j) {
57ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org            for (size_t i = 0; i < SK_ARRAY_COUNT(outers); ++i) {
58ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org                canvas->save();
59ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org                canvas->translate(dx * j, dy * i);
60ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org                canvas->drawDRRect(outers[i], inners[j], paint);
61ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org                canvas->restore();
62ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org            }
63ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org        }
64ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    }
65ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
66ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.orgprivate:
67ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org    typedef GM INHERITED;
68ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org};
69ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org
70ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.orgDEF_GM( return new DRRectGM; )
71