Debian Codegraph @

gm/clip_sierpinski_region.cpp

raw
1 /*
2 * Copyright 2019 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
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkPaint.h"
12 #include "include/core/SkRegion.h"
13
14 static constexpr int kSize = 3*3*3*3*3;
15 static constexpr int kTrans = 10;
16
17 DEF_SIMPLE_GM(clip_sierpinski_region, canvas, 2*kTrans + kSize, 2*kTrans + kSize) {
18 SkRegion region;
19 static constexpr int kSteps = 4;
20 int n = 1;
21 SkScalar s = kSize/3.f;
22 for (int i = 0; i < kSteps; ++i, n*=3, s/=3.f) {
23 for (int x = 0; x < n; ++x) {
24 for (int y = 0; y < n; ++y) {
25 region.op(SkIRect::MakeXYWH((3*x + 1)*s, (3*y + 1)*s, s, s), SkRegion::kUnion_Op);
26 }
27 }
28 }
29 // Test that a save layer with an offset works as expected.
30 region.translate(kTrans, kTrans);
31 canvas->saveLayer(SkRect::MakeXYWH(kTrans, kTrans, 1000, 1000), nullptr);
32 // Make sure the clip call ignores the CTM.
33 canvas->rotate(25.f, 50.f, 50.f);
34 canvas->clipRegion(region);
35 SkPaint red;
36 red.setColor(SK_ColorRED);
37 canvas->drawPaint(red);
38 canvas->restore();
39 }