Flutter Engine
The Flutter Engine
circularclips.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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"
12#include "include/core/SkPath.h"
13#include "include/core/SkRect.h"
15#include "include/core/SkSize.h"
18
20 SkScalar fX1, fX2, fY, fR;
21 SkPath fCircle1, fCircle2;
22
23protected:
24 void onOnceBeforeDraw() override {
25 fX1 = 80;
26 fX2 = 120;
27 fY = 50;
28 fR = 40;
29
30 fCircle1 = SkPath::Circle(fX1, fY, fR, SkPathDirection::kCW);
31 fCircle2 = SkPath::Circle(fX2, fY, fR, SkPathDirection::kCW);
32 }
33
34
35 bool runAsBench() const override { return true; }
36
37 SkString getName() const override { return SkString("circular-clips"); }
38
39 SkISize getISize() override { return SkISize::Make(800, 200); }
40
41 void onDraw(SkCanvas* canvas) override {
42 const SkClipOp ops[] = {
45 };
46
47 SkRect rect = SkRect::MakeLTRB(fX1 - fR, fY - fR, fX2 + fR, fY + fR);
48
49 SkPaint fillPaint;
50
51 // Giant background circular clips (AA, non-inverted, replace/isect)
52 fillPaint.setColor(0x80808080);
53 canvas->save();
54 canvas->scale(10, 10);
55 canvas->translate(-((fX1 + fX2)/2 - fR), -(fY - 2*fR/3));
56 canvas->clipPath(fCircle1, true);
57 canvas->clipPath(fCircle2, true);
58
59 canvas->drawRect(rect, fillPaint);
60
61 canvas->restore();
62
63 fillPaint.setColor(0xFF000000);
64
65 for (size_t i = 0; i < 4; i++) {
66 fCircle1.toggleInverseFillType();
67 if (i % 2 == 0) {
68 fCircle2.toggleInverseFillType();
69 }
70
71 canvas->save();
72 for (size_t op = 0; op < std::size(ops); op++) {
73 canvas->save();
74
75 canvas->clipPath(fCircle1);
76 canvas->clipPath(fCircle2, ops[op]);
77
78 canvas->drawRect(rect, fillPaint);
79
80 canvas->restore();
81 canvas->translate(0, 2 * fY);
82 }
83 canvas->restore();
84 canvas->translate(fX1 + fX2, 0);
85 }
86 }
87
88private:
89 using INHERITED = skiagm::GM;
90};
91
92//////////////////////////////////////////////////////////////////////////////
93
94DEF_GM( return new CircularClipsGM; )
SkPathOp ops[]
SkClipOp
Definition: SkClipOp.h:13
SkISize getISize() override
bool runAsBench() const override
void onOnceBeforeDraw() override
void onDraw(SkCanvas *canvas) override
SkString getName() const override
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1456
int save()
Definition: SkCanvas.cpp:447
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void setColor(SkColor color)
Definition: SkPaint.cpp:119
Definition: SkPath.h:59
void toggleInverseFillType()
Definition: SkPath.h:249
static SkPath Circle(SkScalar center_x, SkScalar center_y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:3598
Definition: gm.h:110
float SkScalar
Definition: extension.cpp:12
#define DEF_GM(CODE)
Definition: gm.h:40
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646