Flutter Engine
The Flutter Engine
SkPathEffect.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
8
11#include "include/core/SkPath.h"
17
18#include <cstddef>
19#include <utility>
20
21class SkStrokeRec;
22struct SkDeserialProcs;
23struct SkRect;
24
25///////////////////////////////////////////////////////////////////////////////
26
28 const SkRect* bounds) const {
29 return this->filterPath(dst, src, rec, bounds, SkMatrix::I());
30}
31
33 const SkRect* bounds, const SkMatrix& ctm) const {
34 SkPath tmp, *tmpDst = dst;
35 if (dst == &src) {
36 tmpDst = &tmp;
37 }
38 if (as_PEB(this)->onFilterPath(tmpDst, src, rec, bounds, ctm)) {
39 if (dst == &src) {
40 *dst = tmp;
41 }
42 return true;
43 }
44 return false;
45}
46
48 const SkStrokeRec& rec, const SkMatrix& mx, const SkRect* rect) const {
49 return this->onAsPoints(results, src, rec, mx, rect);
50}
51
53 return as_PEB(this)->onAsADash(info);
54}
55
57 return as_PEB(this)->onNeedsCTM();
58}
59
60///////////////////////////////////////////////////////////////////////////////
61
62/** \class SkPairPathEffect
63
64 Common baseclass for Compose and Sum. This subclass manages two pathEffects,
65 including flattening them. It does nothing in filterPath, and is only useful
66 for managing the lifetimes of its two arguments.
67 */
69protected:
71 : fPE0(std::move(pe0)), fPE1(std::move(pe1))
72 {
73 SkASSERT(fPE0.get());
74 SkASSERT(fPE1.get());
75 }
76
77 void flatten(SkWriteBuffer& buffer) const override {
78 buffer.writeFlattenable(fPE0.get());
79 buffer.writeFlattenable(fPE1.get());
80 }
81
82 // these are visible to our subclasses
85
86private:
88};
89
90///////////////////////////////////////////////////////////////////////////////////////////////////
91
93public:
94 /** Construct a pathEffect whose effect is to apply first the inner pathEffect
95 and the the outer pathEffect (e.g. outer(inner(path)))
96 The reference counts for outer and inner are both incremented in the constructor,
97 and decremented in the destructor.
98 */
100 if (!outer) {
101 return inner;
102 }
103 if (!inner) {
104 return outer;
105 }
106 return sk_sp<SkPathEffect>(new SkComposePathEffect(outer, inner));
107 }
108
110 : INHERITED(std::move(outer), std::move(inner)) {}
111
113 const SkRect* cullRect, const SkMatrix& ctm) const override {
114 SkPath tmp;
115 const SkPath* ptr = &src;
116
117 if (fPE1->filterPath(&tmp, src, rec, cullRect, ctm)) {
118 ptr = &tmp;
119 }
120 return fPE0->filterPath(dst, *ptr, rec, cullRect, ctm);
121 }
122
124
125 bool computeFastBounds(SkRect* bounds) const override {
126 // inner (fPE1) is computed first, automatically updating bounds before computing outer.
129 }
130
131private:
132 // illegal
134 SkComposePathEffect& operator=(const SkComposePathEffect&);
135 friend class SkPathEffect;
136
138};
139
140sk_sp<SkFlattenable> SkComposePathEffect::CreateProc(SkReadBuffer& buffer) {
141 sk_sp<SkPathEffect> pe0(buffer.readPathEffect());
142 sk_sp<SkPathEffect> pe1(buffer.readPathEffect());
143 return SkComposePathEffect::Make(std::move(pe0), std::move(pe1));
144}
145
146///////////////////////////////////////////////////////////////////////////////
147
148/** \class SkSumPathEffect
149
150 This subclass of SkPathEffect applies two pathEffects, one after the other.
151 Its filterPath() returns true if either of the effects succeeded.
152 */
154public:
155 /** Construct a pathEffect whose effect is to apply two effects, in sequence.
156 (e.g. first(path) + second(path))
157 The reference counts for first and second are both incremented in the constructor,
158 and decremented in the destructor.
159 */
161 if (!first) {
162 return second;
163 }
164 if (!second) {
165 return first;
166 }
167 return sk_sp<SkPathEffect>(new SkSumPathEffect(first, second));
168 }
169
171 : INHERITED(std::move(first), std::move(second)) {}
172
174 const SkRect* cullRect, const SkMatrix& ctm) const override {
175 // always call both, even if the first one succeeds
176 bool filteredFirst = fPE0->filterPath(dst, src, rec, cullRect, ctm);
177 bool filteredSecond = fPE1->filterPath(dst, src, rec, cullRect, ctm);
178 return filteredFirst || filteredSecond;
179 }
180
182
183 bool computeFastBounds(SkRect* bounds) const override {
184 // Unlike Compose(), PE0 modifies the path first for Sum
187 }
188
189private:
190 // illegal
192 SkSumPathEffect& operator=(const SkSumPathEffect&);
193 friend class SkPathEffect;
194
196};
197
198sk_sp<SkFlattenable> SkSumPathEffect::CreateProc(SkReadBuffer& buffer) {
199 sk_sp<SkPathEffect> pe0(buffer.readPathEffect());
200 sk_sp<SkPathEffect> pe1(buffer.readPathEffect());
201 return SkSumPathEffect::Make(pe0, pe1);
202}
203
204///////////////////////////////////////////////////////////////////////////////////////////////////
205
207 return SkSumPathEffect::Make(std::move(first), std::move(second));
208}
209
211 sk_sp<SkPathEffect> inner) {
212 return SkComposePathEffect::Make(std::move(outer), std::move(inner));
213}
214
218}
219
221 const SkDeserialProcs* procs) {
222 return sk_sp<SkPathEffect>(static_cast<SkPathEffect*>(
224 kSkPathEffect_Type, data, size, procs).release()));
225}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SK_FLATTENABLE_HOOKS(type)
#define SK_REGISTER_FLATTENABLE(type)
static SkPathEffectBase * as_PEB(SkPathEffect *effect)
SkComposePathEffect(sk_sp< SkPathEffect > outer, sk_sp< SkPathEffect > inner)
static sk_sp< SkPathEffect > Make(sk_sp< SkPathEffect > outer, sk_sp< SkPathEffect > inner)
bool computeFastBounds(SkRect *bounds) const override
bool onFilterPath(SkPath *dst, const SkPath &src, SkStrokeRec *rec, const SkRect *cullRect, const SkMatrix &ctm) const override
static sk_sp< SkFlattenable > Deserialize(Type, const void *data, size_t length, const SkDeserialProcs *procs=nullptr)
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
sk_sp< SkPathEffect > fPE0
sk_sp< SkPathEffect > fPE1
SkPairPathEffect(sk_sp< SkPathEffect > pe0, sk_sp< SkPathEffect > pe1)
void flatten(SkWriteBuffer &buffer) const override
virtual bool onNeedsCTM() const
virtual bool computeFastBounds(SkRect *bounds) const =0
virtual DashType onAsADash(DashInfo *) const
bool asPoints(PointData *results, const SkPath &src, const SkStrokeRec &, const SkMatrix &, const SkRect *cullR) const
static void RegisterFlattenables()
virtual bool onAsPoints(PointData *, const SkPath &, const SkStrokeRec &, const SkMatrix &, const SkRect *) const
static sk_sp< SkPathEffect > MakeCompose(sk_sp< SkPathEffect > outer, sk_sp< SkPathEffect > inner)
static sk_sp< SkPathEffect > Deserialize(const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
DashType asADash(DashInfo *info) const
static sk_sp< SkPathEffect > MakeSum(sk_sp< SkPathEffect > first, sk_sp< SkPathEffect > second)
bool needsCTM() const
bool filterPath(SkPath *dst, const SkPath &src, SkStrokeRec *, const SkRect *cullR) const
Definition: SkPath.h:59
SkSumPathEffect(sk_sp< SkPathEffect > first, sk_sp< SkPathEffect > second)
bool computeFastBounds(SkRect *bounds) const override
static sk_sp< SkPathEffect > Make(sk_sp< SkPathEffect > first, sk_sp< SkPathEffect > second)
bool onFilterPath(SkPath *dst, const SkPath &src, SkStrokeRec *rec, const SkRect *cullRect, const SkMatrix &ctm) const override
T * get() const
Definition: SkRefCnt.h:303
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
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 to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
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
dst
Definition: cp.py:12
Definition: ref_ptr.h:256
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63