blob: e02ccf7686d4f18166aa3aad66f164772a5d784d [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:
Leandro Lovisolo24fa2112023-08-15 19:05:17 +000024 SkString getName() const override { return SkString("drawregion"); }
msarett44df6512016-08-25 13:54:30 -070025
Leandro Lovisolo8f023882023-08-15 21:13:52 +000026 SkISize getISize() override { return SkISize::Make(500, 500); }
msarett44df6512016-08-25 13:54:30 -070027
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) {
Mike Reed92b33352019-08-24 19:39:13 -040035 fRegion.op({x, y, x + 1, y + 1}, SkRegion::kUnion_Op);
msarett44df6512016-08-25 13:54:30 -070036 }
37 }
38 }
39
40 void onDraw(SkCanvas* canvas) override {
msarettfebb2242016-08-26 12:49:27 -070041 canvas->translate(10, 10);
42
msarett44df6512016-08-25 13:54:30 -070043 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
54private:
John Stiles7571f9e2020-09-02 22:42:33 -040055 using INHERITED = skiagm::GM;
msarett44df6512016-08-25 13:54:30 -070056};
57DEF_GM( return new DrawRegionGM; )