blob: 2230f091905d250aebc6be51081be38688ed321c [file] [log] [blame]
msarett44df6512016-08-25 13:54:30 -07001/*
2 * Copyright 2016 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"
Mike Reed267be7f2017-02-13 09:32:54 -050010#include "SkRegion.h"
msarett44df6512016-08-25 13:54:30 -070011
12/**
13 * This is very similar to the RectGrid macrobench in Android.
14 */
15class DrawRegionGM : public skiagm::GM {
16public:
17 DrawRegionGM() {}
18
19protected:
20 SkString onShortName() override {
21 return SkString("drawregion");
22 }
23
24 SkISize onISize() override {
25 return SkISize::Make(500, 500);
26 }
27
28 bool runAsBench() const override {
29 return true;
30 }
31
32 void onOnceBeforeDraw() override {
33 for (int x = 50; x < 250; x+=2) {
34 for (int y = 50; y < 250; y+=2) {
35 fRegion.op(x, y, x + 1, y + 1, SkRegion::kUnion_Op);
36 }
37 }
38 }
39
40 void onDraw(SkCanvas* canvas) override {
msarettfebb2242016-08-26 12:49:27 -070041 canvas->translate(10, 10);
42
msarett44df6512016-08-25 13:54:30 -070043 SkPaint paint;
44 paint.setStyle(SkPaint::kFill_Style);
45 paint.setColor(0xFFFF00FF);
46 canvas->drawRect(SkRect::MakeLTRB(50.0f, 50.0f, 250.0f, 250.0f), paint);
47
48 paint.setColor(0xFF00FFFF);
49 canvas->drawRegion(fRegion, paint);
50 }
51
52 SkRegion fRegion;
53
54private:
55 typedef skiagm::GM INHERITED;
56};
57DEF_GM( return new DrawRegionGM; )