• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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"
10 #include "SkRegion.h"
11 
12 /**
13  *  This is very similar to the RectGrid macrobench in Android.
14  */
15 class DrawRegionGM : public skiagm::GM {
16 public:
DrawRegionGM()17     DrawRegionGM() {}
18 
19 protected:
onShortName()20     SkString onShortName() override {
21         return SkString("drawregion");
22     }
23 
onISize()24     SkISize onISize() override {
25         return SkISize::Make(500, 500);
26     }
27 
runAsBench() const28     bool runAsBench() const override {
29         return true;
30     }
31 
onOnceBeforeDraw()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 
onDraw(SkCanvas * canvas)40     void onDraw(SkCanvas* canvas) override {
41         canvas->translate(10, 10);
42 
43         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 
54 private:
55     typedef skiagm::GM INHERITED;
56 };
57 DEF_GM( return new DrawRegionGM; )
58