Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
clip_sierpinski_region.cpp
Go to the documentation of this file.
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
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;
37 canvas->drawPaint(red);
38 canvas->restore();
39}
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
void setColor(SkColor color)
Definition SkPaint.cpp:119
void translate(int dx, int dy)
Definition SkRegion.h:349
@ kUnion_Op
target unioned with operand
Definition SkRegion.h:369
bool op(const SkIRect &rect, Op op)
Definition SkRegion.h:384
static constexpr int kTrans
static constexpr int kSize
float SkScalar
Definition extension.cpp:12
struct MyStruct s
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
Definition gm.h:50
double y
double x
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition SkRect.h:104
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659