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