blob: 44a3c28cc68717b3eb0fdd16edd39fedb81b73b5 [file] [log] [blame]
msarett44df6512016-08-25 13:54:30 -07001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
9#include "include/core/SkCanvas.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040010#include "include/core/SkPaint.h"
11#include "include/core/SkRect.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkRegion.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040013#include "include/core/SkSize.h"
14#include "include/core/SkString.h"
msarett44df6512016-08-25 13:54:30 -070015
16/**
17 * This is very similar to the RectGrid macrobench in Android.
18 */
19class DrawRegionGM : public skiagm::GM {
20public:
21 DrawRegionGM() {}
22
23protected:
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 Reed92b33352019-08-24 19:39:13 -040039 fRegion.op({x, y, x + 1, y + 1}, SkRegion::kUnion_Op);
msarett44df6512016-08-25 13:54:30 -070040 }
41 }
42 }
43
44 void onDraw(SkCanvas* canvas) override {
msarettfebb2242016-08-26 12:49:27 -070045 canvas->translate(10, 10);
46
msarett44df6512016-08-25 13:54:30 -070047 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
58private:
John Stiles7571f9e2020-09-02 22:42:33 -040059 using INHERITED = skiagm::GM;
msarett44df6512016-08-25 13:54:30 -070060};
61DEF_GM( return new DrawRegionGM; )