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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
| 9 | #include "include/core/SkCanvas.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 10 | #include "include/core/SkPaint.h" |
| 11 | #include "include/core/SkRect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkRegion.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 13 | #include "include/core/SkSize.h" |
| 14 | #include "include/core/SkString.h" |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 15 | |
| 16 | /** |
| 17 | * This is very similar to the RectGrid macrobench in Android. |
| 18 | */ |
| 19 | class DrawRegionGM : public skiagm::GM { |
| 20 | public: |
| 21 | DrawRegionGM() {} |
| 22 | |
| 23 | protected: |
| 24 | SkString onShortName() override { |
| 25 | return SkString("drawregion"); |
| 26 | } |
| 27 | |
| 28 | SkISize onISize() override { |
| 29 | return SkISize::Make(500, 500); |
| 30 | } |
| 31 | |
| 32 | bool runAsBench() const override { |
| 33 | return true; |
| 34 | } |
| 35 | |
| 36 | void onOnceBeforeDraw() override { |
| 37 | for (int x = 50; x < 250; x+=2) { |
| 38 | for (int y = 50; y < 250; y+=2) { |
Mike Reed | 92b3335 | 2019-08-24 19:39:13 -0400 | [diff] [blame] | 39 | fRegion.op({x, y, x + 1, y + 1}, SkRegion::kUnion_Op); |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | void onDraw(SkCanvas* canvas) override { |
msarett | febb224 | 2016-08-26 12:49:27 -0700 | [diff] [blame] | 45 | canvas->translate(10, 10); |
| 46 | |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 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: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 59 | using INHERITED = skiagm::GM; |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 60 | }; |
| 61 | DEF_GM( return new DrawRegionGM; ) |