| 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: |
| 21 |
DrawRegionGM() {} |
| 22 |
|
| 23 |
protected: |
| 24 |
SkString getName() const override { return SkString("drawregion"); } |
| 25 |
|
| 26 |
SkISize getISize() override { return SkISize::Make(500, 500); } |
| 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 { |
| 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 |
using INHERITED = skiagm::GM; |
| 56 |
}; |
| 57 |
DEF_GM( return new DrawRegionGM; ) |