Flutter Engine
The Flutter Engine
SkOpContour.h
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#ifndef SkOpContour_DEFINED
8#define SkOpContour_DEFINED
9
10#include "include/core/SkPath.h"
21
22class SkOpAngle;
23class SkOpCoincidence;
24class SkPathWriter;
25enum class SkOpRayDir;
26struct SkOpRayHit;
27
29public:
31 reset();
32 }
33
34 bool operator<(const SkOpContour& rh) const {
35 return fBounds.fTop == rh.fBounds.fTop
37 : fBounds.fTop < rh.fBounds.fTop;
38 }
39
40 void addConic(SkPoint pts[3], SkScalar weight) {
41 appendSegment().addConic(pts, weight, this);
42 }
43
44 void addCubic(SkPoint pts[4]) {
45 appendSegment().addCubic(pts, this);
46 }
47
49 SkASSERT(pts[0] != pts[1]);
50 return appendSegment().addLine(pts, this);
51 }
52
53 void addQuad(SkPoint pts[3]) {
54 appendSegment().addQuad(pts, this);
55 }
56
59 : &fHead;
60 result->setPrev(fTail);
61 if (fTail) {
63 }
64 fTail = result;
65 return *result;
66 }
67
68 const SkPathOpsBounds& bounds() const {
69 return fBounds;
70 }
71
72 void calcAngles() {
73 SkASSERT(fCount > 0);
74 SkOpSegment* segment = &fHead;
75 do {
76 segment->calcAngles();
77 } while ((segment = segment->next()));
78 }
79
80 void complete() {
81 setBounds();
82 }
83
84 int count() const {
85 return fCount;
86 }
87
88 int debugID() const {
89 return SkDEBUGRELEASE(fID, -1);
90 }
91
92 int debugIndent() const {
93 return SkDEBUGRELEASE(fDebugIndent, 0);
94 }
95
96 const SkOpAngle* debugAngle(int id) const {
97 return SkDEBUGRELEASE(this->globalState()->debugAngle(id), nullptr);
98 }
99
101 return this->globalState()->coincidence();
102 }
103
104#if DEBUG_COIN
105 void debugCheckHealth(SkPathOpsDebug::GlitchLog* ) const;
106#endif
107
108 SkOpContour* debugContour(int id) const {
109 return SkDEBUGRELEASE(this->globalState()->debugContour(id), nullptr);
110 }
111
112#if DEBUG_COIN
113 void debugMissingCoincidence(SkPathOpsDebug::GlitchLog* log) const;
114 void debugMoveMultiples(SkPathOpsDebug::GlitchLog* ) const;
115 void debugMoveNearby(SkPathOpsDebug::GlitchLog* log) const;
116#endif
117
118 const SkOpPtT* debugPtT(int id) const {
119 return SkDEBUGRELEASE(this->globalState()->debugPtT(id), nullptr);
120 }
121
122 const SkOpSegment* debugSegment(int id) const {
123 return SkDEBUGRELEASE(this->globalState()->debugSegment(id), nullptr);
124 }
125
126#if DEBUG_ACTIVE_SPANS
127 void debugShowActiveSpans(SkString* str) {
128 SkOpSegment* segment = &fHead;
129 do {
130 segment->debugShowActiveSpans(str);
131 } while ((segment = segment->next()));
132 }
133#endif
134
135 const SkOpSpanBase* debugSpan(int id) const {
136 return SkDEBUGRELEASE(this->globalState()->debugSpan(id), nullptr);
137 }
138
140 return fState;
141 }
142
143 void debugValidate() const {
144#if DEBUG_VALIDATE
145 const SkOpSegment* segment = &fHead;
146 const SkOpSegment* prior = nullptr;
147 do {
148 segment->debugValidate();
149 SkASSERT(segment->prev() == prior);
150 prior = segment;
151 } while ((segment = segment->next()));
152 SkASSERT(prior == fTail);
153#endif
154 }
155
156 bool done() const {
157 return fDone;
158 }
159
160 void dump() const;
161 void dumpAll() const;
162 void dumpAngles() const;
163 void dumpContours() const;
164 void dumpContoursAll() const;
165 void dumpContoursAngles() const;
166 void dumpContoursPts() const;
167 void dumpContoursPt(int segmentID) const;
168 void dumpContoursSegment(int segmentID) const;
169 void dumpContoursSpan(int segmentID) const;
170 void dumpContoursSpans() const;
171 void dumpPt(int ) const;
172 void dumpPts(const char* prefix = "seg") const;
173 void dumpPtsX(const char* prefix) const;
174 void dumpSegment(int ) const;
175 void dumpSegments(const char* prefix = "seg", SkPathOp op = (SkPathOp) -1) const;
176 void dumpSpan(int ) const;
177 void dumpSpans() const;
178
179 const SkPoint& end() const {
181 }
182
184
186 SkASSERT(fCount > 0);
187 return &fHead;
188 }
189
190 const SkOpSegment* first() const {
191 SkASSERT(fCount > 0);
192 return &fHead;
193 }
194
195 void indentDump() const {
196 SkDEBUGCODE(fDebugIndent += 2);
197 }
198
202 fXor = isXor;
203 SkDEBUGCODE(fID = globalState->nextContourID());
204 }
205
206 int isCcw() const {
207 return fCcw;
208 }
209
210 bool isXor() const {
211 return fXor;
212 }
213
215 SkOpSegment* segment = &fHead;
217 do {
218 next = segment->next();
219 segment->joinEnds(next ? next : &fHead);
220 } while ((segment = next));
221 }
222
223 void markAllDone() {
224 SkOpSegment* segment = &fHead;
225 do {
226 segment->markAllDone();
227 } while ((segment = segment->next()));
228 }
229
230 // Please keep this aligned with debugMissingCoincidence()
232 SkASSERT(fCount > 0);
233 SkOpSegment* segment = &fHead;
234 bool result = false;
235 do {
236 if (segment->missingCoincidence()) {
237 result = true;
238 }
239 segment = segment->next();
240 } while (segment);
241 return result;
242 }
243
245 SkASSERT(fCount > 0);
246 SkOpSegment* segment = &fHead;
247 do {
248 if (!segment->moveMultiples()) {
249 return false;
250 }
251 } while ((segment = segment->next()));
252 return true;
253 }
254
255 bool moveNearby() {
256 SkASSERT(fCount > 0);
257 SkOpSegment* segment = &fHead;
258 do {
259 if (!segment->moveNearby()) {
260 return false;
261 }
262 } while ((segment = segment->next()));
263 return true;
264 }
265
267 return fNext;
268 }
269
270 const SkOpContour* next() const {
271 return fNext;
272 }
273
274 bool operand() const {
275 return fOperand;
276 }
277
278 bool oppXor() const {
279 return fOppXor;
280 }
281
282 void outdentDump() const {
283 SkDEBUGCODE(fDebugIndent -= 2);
284 }
285
287
288 void reset() {
289 fTail = nullptr;
290 fNext = nullptr;
291 fCount = 0;
292 fDone = false;
295 SkDEBUGCODE(fDebugIndent = 0);
296 }
297
299 SkOpContour* next = this;
300 do {
301 if (!next->count()) {
302 continue;
303 }
304 next->fCcw = -1;
305 next->fReverse = false;
306 } while ((next = next->next()));
307 }
308
309 bool reversed() const {
310 return fReverse;
311 }
312
313 void setBounds() {
314 SkASSERT(fCount > 0);
315 const SkOpSegment* segment = &fHead;
316 fBounds = segment->bounds();
317 while ((segment = segment->next())) {
318 fBounds.add(segment->bounds());
319 }
320 }
321
322 void setCcw(int ccw) {
323 fCcw = ccw;
324 }
325
327 fState = state;
328 }
329
331// SkASSERT(!fNext == !!contour);
332 fNext = contour;
333 }
334
335 void setOperand(bool isOp) {
336 fOperand = isOp;
337 }
338
339 void setOppXor(bool isOppXor) {
340 fOppXor = isOppXor;
341 }
342
343 void setReverse() {
344 fReverse = true;
345 }
346
347 void setXor(bool isXor) {
348 fXor = isXor;
349 }
350
351 bool sortAngles() {
352 SkASSERT(fCount > 0);
353 SkOpSegment* segment = &fHead;
354 do {
355 FAIL_IF(!segment->sortAngles());
356 } while ((segment = segment->next()));
357 return true;
358 }
359
360 const SkPoint& start() const {
361 return fHead.pts()[0];
362 }
363
365 const SkOpSegment* segment = fTail;
366 do {
367 SkAssertResult(segment->addCurveTo(segment->tail(), segment->head(), path));
368 } while ((segment = segment->prev()));
369 }
370
372 const SkOpSegment* segment = &fHead;
373 do {
374 SkAssertResult(segment->addCurveTo(segment->head(), segment->tail(), path));
375 } while ((segment = segment->next()));
376 }
377
378 void toReversePath(SkPathWriter* path) const;
379 void toPath(SkPathWriter* path) const;
381
382protected:
388 int fCcw;
391 bool fDone; // set by find top segment
392 bool fOperand; // true for the second argument to a binary operator
393 bool fReverse; // true if contour should be reverse written to path (used only by fix winding)
394 bool fXor; // set if original path had even-odd fill
395 bool fOppXor; // set if opposite path had even-odd fill
396 SkDEBUGCODE(int fID;)
397 SkDEBUGCODE(mutable int fDebugIndent;)
398};
399
401public:
404 contour->setNext(nullptr);
405 SkOpContour* prev = this;
407 while ((next = prev->next())) {
408 prev = next;
409 }
410 prev->setNext(contour);
411 return contour;
412 }
413
415 SkOpContour* next = this;
416 do {
417 if (!next->count()) {
418 continue;
419 }
421 } while ((next = next->next()));
422 }
423
425 if (contour == this) {
426 SkASSERT(this->count() == 0);
427 return;
428 }
429 SkASSERT(contour->next() == nullptr);
430 SkOpContour* prev = this;
432 while ((next = prev->next()) != contour) {
433 SkASSERT(next);
434 prev = next;
435 }
436 SkASSERT(prev);
437 prev->setNext(nullptr);
438 }
439};
440
442public:
445 , fLastIsLine(false) {
446 }
447
448 void addConic(SkPoint pts[3], SkScalar weight);
449 void addCubic(SkPoint pts[4]);
450 void addCurve(SkPath::Verb verb, const SkPoint pts[4], SkScalar weight = 1);
451 void addLine(const SkPoint pts[2]);
452 void addQuad(SkPoint pts[3]);
453 void flush();
456protected:
460};
461
462#endif
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
static float prev(float f)
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SkDEBUGRELEASE(a, b)
#define FAIL_IF(cond)
int SkPathOpsVerbToPoints(SkPath::Verb verb)
SkOpRayDir
SkPathOp
Definition: SkPathOps.h:22
#define SK_ScalarMin
Definition: SkScalar.h:25
#define SK_ScalarMax
Definition: SkScalar.h:24
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
Definition: SkArenaAlloc.h:120
SkOpContour * fContour
Definition: SkOpContour.h:457
void addConic(SkPoint pts[3], SkScalar weight)
Definition: SkOpContour.cpp:46
void addCurve(SkPath::Verb verb, const SkPoint pts[4], SkScalar weight=1)
Definition: SkOpContour.cpp:56
void setContour(SkOpContour *contour)
Definition: SkOpContour.h:455
SkOpContourBuilder(SkOpContour *contour)
Definition: SkOpContour.h:443
SkPoint fLastLine[2]
Definition: SkOpContour.h:458
void addCubic(SkPoint pts[4])
Definition: SkOpContour.cpp:51
void addQuad(SkPoint pts[3])
Definition: SkOpContour.cpp:97
void addLine(const SkPoint pts[2])
Definition: SkOpContour.cpp:83
SkOpContour * contour()
Definition: SkOpContour.h:454
SkOpContour * appendContour()
Definition: SkOpContour.h:402
void joinAllSegments()
Definition: SkOpContour.h:414
void remove(SkOpContour *contour)
Definition: SkOpContour.h:424
SkOpGlobalState * fState
Definition: SkOpContour.h:383
const SkPathOpsBounds & bounds() const
Definition: SkOpContour.h:68
void joinSegments()
Definition: SkOpContour.h:214
int count() const
Definition: SkOpContour.h:84
void addCubic(SkPoint pts[4])
Definition: SkOpContour.h:44
void setXor(bool isXor)
Definition: SkOpContour.h:347
bool isXor() const
Definition: SkOpContour.h:210
void calcAngles()
Definition: SkOpContour.h:72
void setReverse()
Definition: SkOpContour.h:343
bool reversed() const
Definition: SkOpContour.h:309
void reset()
Definition: SkOpContour.h:288
void toReversePath(SkPathWriter *path) const
Definition: SkOpContour.cpp:25
SkOpGlobalState * globalState() const
Definition: SkOpContour.h:139
void setBounds()
Definition: SkOpContour.h:313
void dumpPt(int) const
SkOpContour * fNext
Definition: SkOpContour.h:386
SkOpSpan * undoneSpan()
Definition: SkOpContour.cpp:34
bool operand() const
Definition: SkOpContour.h:274
const SkOpSegment * debugSegment(int id) const
Definition: SkOpContour.h:122
void dumpAll() const
int isCcw() const
Definition: SkOpContour.h:206
const SkPoint & end() const
Definition: SkOpContour.h:179
void dumpAngles() const
bool moveNearby()
Definition: SkOpContour.h:255
bool missingCoincidence()
Definition: SkOpContour.h:231
void setOppXor(bool isOppXor)
Definition: SkOpContour.h:339
SkOpSegment & appendSegment()
Definition: SkOpContour.h:57
void init(SkOpGlobalState *globalState, bool operand, bool isXor)
Definition: SkOpContour.h:199
int debugIndent() const
Definition: SkOpContour.h:92
SkDEBUGCODE(int fID;) SkDEBUGCODE(mutable int fDebugIndent
void markAllDone()
Definition: SkOpContour.h:223
void dumpContoursAngles() const
const SkOpCoincidence * debugCoincidence() const
Definition: SkOpContour.h:100
bool operator<(const SkOpContour &rh) const
Definition: SkOpContour.h:34
const SkOpContour * next() const
Definition: SkOpContour.h:270
bool done() const
Definition: SkOpContour.h:156
const SkOpSpanBase * debugSpan(int id) const
Definition: SkOpContour.h:135
void dump() const
SkOpSegment * fTail
Definition: SkOpContour.h:385
SkOpSpan * findSortableTop(SkOpContour *)
SkOpContour * debugContour(int id) const
Definition: SkOpContour.h:108
SkOpSegment * first()
Definition: SkOpContour.h:185
void dumpContoursPts() const
void dumpSpan(int) const
int fFirstSorted
Definition: SkOpContour.h:390
void rayCheck(const SkOpRayHit &base, SkOpRayDir dir, SkOpRayHit **hits, SkArenaAlloc *)
void dumpContoursAll() const
void indentDump() const
Definition: SkOpContour.h:195
void toPartialForward(SkPathWriter *path) const
Definition: SkOpContour.h:371
void complete()
Definition: SkOpContour.h:80
void dumpContoursSpans() const
bool sortAngles()
Definition: SkOpContour.h:351
const SkOpSegment * first() const
Definition: SkOpContour.h:190
void dumpPts(const char *prefix="seg") const
void dumpSegments(const char *prefix="seg", SkPathOp op=(SkPathOp) -1) const
void dumpContours() const
void dumpSegment(int) const
void dumpSpans() const
void dumpContoursPt(int segmentID) const
void addQuad(SkPoint pts[3])
Definition: SkOpContour.h:53
void setCcw(int ccw)
Definition: SkOpContour.h:322
void outdentDump() const
Definition: SkOpContour.h:282
void addConic(SkPoint pts[3], SkScalar weight)
Definition: SkOpContour.h:40
bool oppXor() const
Definition: SkOpContour.h:278
int debugID() const
Definition: SkOpContour.h:88
SkOpContour * next()
Definition: SkOpContour.h:266
void toPath(SkPathWriter *path) const
Definition: SkOpContour.cpp:13
const SkOpAngle * debugAngle(int id) const
Definition: SkOpContour.h:96
SkOpSegment fHead
Definition: SkOpContour.h:384
void toPartialBackward(SkPathWriter *path) const
Definition: SkOpContour.h:364
SkOpSegment * addLine(SkPoint pts[2])
Definition: SkOpContour.h:48
void dumpPtsX(const char *prefix) const
void resetReverse()
Definition: SkOpContour.h:298
const SkPoint & start() const
Definition: SkOpContour.h:360
void dumpContoursSpan(int segmentID) const
void setNext(SkOpContour *contour)
Definition: SkOpContour.h:330
const SkOpPtT * debugPtT(int id) const
Definition: SkOpContour.h:118
void setGlobalState(SkOpGlobalState *state)
Definition: SkOpContour.h:326
void dumpContoursSegment(int segmentID) const
void debugValidate() const
Definition: SkOpContour.h:143
SkPathOpsBounds fBounds
Definition: SkOpContour.h:387
void setOperand(bool isOp)
Definition: SkOpContour.h:335
bool moveMultiples()
Definition: SkOpContour.h:244
SkArenaAlloc * allocator()
SkOpCoincidence * coincidence()
SkOpSegment * addConic(SkPoint pts[3], SkScalar weight, SkOpContour *parent)
Definition: SkOpSegment.h:55
void debugValidate() const
void joinEnds(SkOpSegment *start)
Definition: SkOpSegment.h:279
SkPath::Verb verb() const
Definition: SkOpSegment.h:419
SkOpSegment * addLine(SkPoint pts[2], SkOpContour *parent)
Definition: SkOpSegment.h:82
bool sortAngles()
const SkPathOpsBounds & bounds() const
Definition: SkOpSegment.h:109
bool moveMultiples()
const SkOpSegment * prev() const
Definition: SkOpSegment.h:319
const SkOpSpanBase * tail() const
Definition: SkOpSegment.h:398
void markAllDone()
bool moveNearby()
void calcAngles()
const SkOpSpan * head() const
Definition: SkOpSegment.h:234
bool addCurveTo(const SkOpSpanBase *start, const SkOpSpanBase *end, SkPathWriter *path) const
SkOpSegment * addCubic(SkPoint pts[4], SkOpContour *parent)
Definition: SkOpSegment.h:63
void setNext(SkOpSegment *next)
Definition: SkOpSegment.h:361
const SkPoint * pts() const
Definition: SkOpSegment.h:327
SkOpSegment * addQuad(SkPoint pts[3], SkOpContour *parent)
Definition: SkOpSegment.h:98
bool missingCoincidence()
SkOpSegment * next() const
Definition: SkOpSegment.h:304
float SkScalar
Definition: extension.cpp:12
AtkStateType state
GAsyncResult * result
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
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 Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition: switches.h:145
void add(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
void setLTRB(float left, float top, float right, float bottom)
Definition: SkRect.h:865
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15