blob: 4f5f064c66e81a717c30c7e2ab8ccfa14aa0233d [file] [log] [blame]
Brian Salomona6069a12019-12-13 10:48:33 -05001/*
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
14static constexpr int kSize = 3*3*3*3*3;
15static constexpr int kTrans = 10;
16
17DEF_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}