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