Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkOpContour.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*/
8
10
11#include <cstring>
12
14 if (!this->count()) {
15 return;
16 }
17 const SkOpSegment* segment = &fHead;
18 do {
19 SkAssertResult(segment->addCurveTo(segment->head(), segment->tail(), path));
20 } while ((segment = segment->next()));
21 path->finishContour();
22 path->assemble();
23}
24
26 const SkOpSegment* segment = fTail;
27 do {
28 SkAssertResult(segment->addCurveTo(segment->tail(), segment->head(), path));
29 } while ((segment = segment->prev()));
30 path->finishContour();
31 path->assemble();
32}
33
35 SkOpSegment* testSegment = &fHead;
36 do {
37 if (testSegment->done()) {
38 continue;
39 }
40 return testSegment->undoneSpan();
41 } while ((testSegment = testSegment->next()));
42 fDone = true;
43 return nullptr;
44}
45
47 this->flush();
48 fContour->addConic(pts, weight);
49}
50
52 this->flush();
53 fContour->addCubic(pts);
54}
55
57 if (SkPath::kLine_Verb == verb) {
58 this->addLine(pts);
59 return;
60 }
61 SkArenaAlloc* allocator = fContour->globalState()->allocator();
62 switch (verb) {
63 case SkPath::kQuad_Verb: {
64 SkPoint* ptStorage = allocator->makeArrayDefault<SkPoint>(3);
65 memcpy(ptStorage, pts, sizeof(SkPoint) * 3);
66 this->addQuad(ptStorage);
67 } break;
69 SkPoint* ptStorage = allocator->makeArrayDefault<SkPoint>(3);
70 memcpy(ptStorage, pts, sizeof(SkPoint) * 3);
71 this->addConic(ptStorage, weight);
72 } break;
74 SkPoint* ptStorage = allocator->makeArrayDefault<SkPoint>(4);
75 memcpy(ptStorage, pts, sizeof(SkPoint) * 4);
76 this->addCubic(ptStorage);
77 } break;
78 default:
79 SkASSERT(0);
80 }
81}
82
84 // if the previous line added is the exact opposite, eliminate both
85 if (fLastIsLine) {
86 if (fLastLine[0] == pts[1] && fLastLine[1] == pts[0]) {
87 fLastIsLine = false;
88 return;
89 } else {
90 flush();
91 }
92 }
93 memcpy(fLastLine, pts, sizeof(fLastLine));
94 fLastIsLine = true;
95}
96
98 this->flush();
99 fContour->addQuad(pts);
100}
101
103 if (!fLastIsLine)
104 return;
105 SkArenaAlloc* allocator = fContour->globalState()->allocator();
106 SkPoint* ptStorage = allocator->makeArrayDefault<SkPoint>(2);
107 memcpy(ptStorage, fLastLine, sizeof(fLastLine));
108 (void) fContour->addLine(ptStorage);
109 fLastIsLine = false;
110}
#define SkAssertResult(cond)
Definition SkAssert.h:123
#define SkASSERT(cond)
Definition SkAssert.h:116
T * makeArrayDefault(size_t count)
SkOpContour * fContour
void addConic(SkPoint pts[3], SkScalar weight)
void addCurve(SkPath::Verb verb, const SkPoint pts[4], SkScalar weight=1)
SkPoint fLastLine[2]
void addCubic(SkPoint pts[4])
void addQuad(SkPoint pts[3])
void addLine(const SkPoint pts[2])
int count() const
Definition SkOpContour.h:84
void addCubic(SkPoint pts[4])
Definition SkOpContour.h:44
void toReversePath(SkPathWriter *path) const
SkOpGlobalState * globalState() const
SkOpSpan * undoneSpan()
SkOpSegment * fTail
void addQuad(SkPoint pts[3])
Definition SkOpContour.h:53
void addConic(SkPoint pts[3], SkScalar weight)
Definition SkOpContour.h:40
void toPath(SkPathWriter *path) const
SkOpSegment fHead
SkOpSegment * addLine(SkPoint pts[2])
Definition SkOpContour.h:48
SkArenaAlloc * allocator()
bool done() const
const SkOpSegment * prev() const
const SkOpSpanBase * tail() const
SkOpSpan * undoneSpan()
const SkOpSpan * head() const
bool addCurveTo(const SkOpSpanBase *start, const SkOpSpanBase *end, SkPathWriter *path) const
SkOpSegment * next() const
@ kConic_Verb
Definition SkPath.h:1461
@ kCubic_Verb
Definition SkPath.h:1462
@ kQuad_Verb
Definition SkPath.h:1460
@ kLine_Verb
Definition SkPath.h:1459
float SkScalar
Definition extension.cpp:12