aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/drawregion.cpp
blob: a2633f9d9fc423f675025f6749efed2c8b5257f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "gm.h"
#include "SkCanvas.h"

/**
 *  This is very similar to the RectGrid macrobench in Android.
 */
class DrawRegionGM : public skiagm::GM {
public:
    DrawRegionGM() {}

protected:
    SkString onShortName() override {
        return SkString("drawregion");
    }

    SkISize onISize() override {
        return SkISize::Make(500, 500);
    }

    bool runAsBench() const override {
        return true;
    }

    void onOnceBeforeDraw() override {
        for (int x = 50; x < 250; x+=2) {
            for (int y = 50; y < 250; y+=2) {
                fRegion.op(x, y, x + 1, y + 1, SkRegion::kUnion_Op);
            }
        }
    }

    void onDraw(SkCanvas* canvas) override {
        canvas->translate(10, 10);

        SkPaint paint;
        paint.setStyle(SkPaint::kFill_Style);
        paint.setColor(0xFFFF00FF);
        canvas->drawRect(SkRect::MakeLTRB(50.0f, 50.0f, 250.0f, 250.0f), paint);

        paint.setColor(0xFF00FFFF);
        canvas->drawRegion(fRegion, paint);
    }

    SkRegion fRegion;

private:
    typedef skiagm::GM INHERITED;
};
DEF_GM( return new DrawRegionGM; )