Flutter Engine
The Flutter Engine
PathEffectsSlide.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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
10#include "include/core/SkPath.h"
18#include "src/base/SkRandom.h"
19#include "src/base/SkUTF.h"
21#include "tools/viewer/Slide.h"
22
23#define CORNER_RADIUS 12
24
25static const int gXY[] = {
26 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4
27};
28
30 if (flags == 1) {
32 }
33
35 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1]));
36 for (unsigned i = 2; i < std::size(gXY); i += 2)
37 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1]));
38 path.close();
39 path.offset(SkIntToScalar(-6), 0);
40
42
43 if (flags == 2)
44 return outer;
45
47
48 return SkPathEffect::MakeCompose(outer, inner);
49}
50
53 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1]));
54 for (unsigned i = 2; i < std::size(gXY); i += 2) {
55 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1]));
56 }
57 path.close();
58 path.offset(SkIntToScalar(-6), 0);
59
60 auto outer = SkPath1DPathEffect::Make(
63
64 return SkPathEffect::MakeCompose(outer, inner);
65}
66
67///////////////////////////////////////////////////////////
68
70
71class PathEffectSlide : public Slide {
72 SkPath fPath;
73 SkPoint fClickPt;
74 SkScalar fPhase;
75
76public:
77 PathEffectSlide() : fPhase(0) { fName = "PathEffects"; }
78
79 void load(SkScalar w, SkScalar h) override {
80 SkRandom rand;
81 int steps = 20;
82 SkScalar dist = SkIntToScalar(400);
85
86 fPath.moveTo(x, y);
87 for (int i = 0; i < steps; i++) {
88 x += dist/steps;
89 SkScalar tmpY = y + SkIntToScalar(rand.nextS() % 25);
90 if (i == steps/2) {
91 fPath.moveTo(x, tmpY);
92 } else {
93 fPath.lineTo(x, tmpY);
94 }
95 }
96
97 {
99 oval.setLTRB(20, 30, 100, 60);
100 oval.offset(x, 0);
102 }
103
104 fClickPt.set(SkIntToScalar(200), SkIntToScalar(200));
105 }
106
107 void draw(SkCanvas* canvas) override {
108 canvas->clear(0xFFDDDDDD);
109
111
112 canvas->translate(0, 50);
113
114 paint.setColor(SK_ColorBLUE);
115 paint.setPathEffect(make_pe(2, fPhase));
116 canvas->drawPath(fPath, paint);
117
118 canvas->translate(0, 50);
119
120 paint.setARGB(0xFF, 0, 0xBB, 0);
121 paint.setPathEffect(make_pe(3, fPhase));
122 canvas->drawPath(fPath, paint);
123
124 canvas->translate(0, 50);
125
126 paint.setARGB(0xFF, 0, 0, 0);
127 paint.setPathEffect(make_warp_pe(fPhase));
128 canvas->drawPath(fPath, paint);
129 }
130
131 bool animate(double nanos) override {
132 fPhase = TimeUtils::Scaled(1e-9 * nanos, 40);
133 return true;
134 }
135};
136
137//////////////////////////////////////////////////////////////////////////////
138
139DEF_SLIDE( return new PathEffectSlide(); )
SkPath fPath
static sk_sp< SkPathEffect > make_pe(int flags, SkScalar phase)
static sk_sp< SkPathEffect > make_warp_pe(SkScalar phase)
static const int gXY[]
#define CORNER_RADIUS
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
#define SkIntToScalar(x)
Definition: SkScalar.h:57
#define DEF_SLIDE(code)
Definition: Slide.h:25
void load(SkScalar w, SkScalar h) override
bool animate(double nanos) override
void draw(SkCanvas *canvas) override
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
static sk_sp< SkPathEffect > Make(SkScalar radius)
static sk_sp< SkPathEffect > Make(const SkPath &path, SkScalar advance, SkScalar phase, Style)
static sk_sp< SkPathEffect > MakeCompose(sk_sp< SkPathEffect > outer, sk_sp< SkPathEffect > inner)
Definition: SkPath.h:59
SkPath & moveTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:688
SkPath & lineTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:728
SkPath & addRoundRect(const SkRect &rect, SkScalar rx, SkScalar ry, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:1093
int32_t nextS()
Definition: SkRandom.h:50
Definition: Slide.h:29
SkString fName
Definition: Slide.h:54
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
FlutterSemanticsFlag flags
double y
double x
SkRect oval
Definition: SkRecords.h:249
static float Scaled(float time, float speed, float period=0)
Definition: TimeUtils.h:27
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
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
SkScalar w
SkScalar h
void set(float x, float y)
Definition: SkPoint_impl.h:200
void offset(float dx, float dy)
Definition: SkRect.h:1016
void setLTRB(float left, float top, float right, float bottom)
Definition: SkRect.h:865