• 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/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkPaint.h"
11 #include "include/core/SkRect.h"
12 #include "include/core/SkRegion.h"
13 #include "include/core/SkSize.h"
14 #include "include/core/SkString.h"
15 
16 /**
17  *  This is very similar to the RectGrid macrobench in Android.
18  */
19 class DrawRegionGM : public skiagm::GM {
20 public:
DrawRegionGM()21     DrawRegionGM() {}
22 
23 protected:
onShortName()24     SkString onShortName() override {
25         return SkString("drawregion");
26     }
27 
onISize()28     SkISize onISize() override {
29         return SkISize::Make(500, 500);
30     }
31 
runAsBench() const32     bool runAsBench() const override {
33         return true;
34     }
35 
onOnceBeforeDraw()36     void onOnceBeforeDraw() override {
37         for (int x = 50; x < 250; x+=2) {
38             for (int y = 50; y < 250; y+=2) {
39                 fRegion.op({x, y, x + 1, y + 1}, SkRegion::kUnion_Op);
40             }
41         }
42     }
43 
onDraw(SkCanvas * canvas)44     void onDraw(SkCanvas* canvas) override {
45         canvas->translate(10, 10);
46 
47         SkPaint paint;
48         paint.setStyle(SkPaint::kFill_Style);
49         paint.setColor(0xFFFF00FF);
50         canvas->drawRect(SkRect::MakeLTRB(50.0f, 50.0f, 250.0f, 250.0f), paint);
51 
52         paint.setColor(0xFF00FFFF);
53         canvas->drawRegion(fRegion, paint);
54     }
55 
56     SkRegion fRegion;
57 
58 private:
59     using INHERITED = skiagm::GM;
60 };
61 DEF_GM( return new DrawRegionGM; )
62