Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SubsetPath.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 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
12#include "src/base/SkMathPriv.h"
13#include "src/core/SkPathPriv.h"
14#include "tests/SubsetPath.h"
15
17 : fPath(path)
18 , fSubset(1) {
19}
20
21int SubsetPath::range(int* end) const {
22 int leadingZero = SkCLZ(fSubset);
23 int parts = 1 << (31 - leadingZero);
24 int partIndex = fSubset - parts;
25 SkASSERT(partIndex >= 0);
26 int count = fSelected.size();
27 int start = count * partIndex / parts;
28 *end = count * (partIndex + 1) / parts;
29 return start;
30}
31
32bool SubsetPath::subset(bool testFailed, SkPath* sub) {
33 int start, end;
34 if (!testFailed) {
35 start = range(&end);
36 for (; start < end; ++start) {
37 fSelected[start] = true;
38 }
39 }
40 do {
41 do {
42 ++fSubset;
43 start = range(&end);
44 // SkDebugf("%d s=%d e=%d t=%d\n", fSubset, start, end, fTries);
45 if (end - start > 1) {
47 } else if (end - start == 1) {
48 if (--fTries <= 0) {
49 return false;
50 }
51 }
52 } while (start == end);
53 } while (!fSelected[start]);
54 for (; start < end; ++start) {
55 fSelected[start] = false;
56 }
57#if 1
58 SkDebugf("selected: ");
59 for (int index = 0; index < fSelected.size(); ++index) {
60 SkDebugf("%c", fSelected[index] ? 'x' : '-');
61 }
62#endif
63 *sub = getSubsetPath();
64 return true;
65}
66
68 : SubsetPath(path) {
69 bool foundCurve = false;
70 int contourCount = 0;
71 for (auto [verb, pts, w] : SkPathPriv::Iterate(fPath)) {
72 switch (verb) {
74 break;
79 foundCurve = true;
80 break;
82 ++contourCount;
83 foundCurve = false;
84 break;
85 default:
86 SkDEBUGFAIL("bad verb");
87 return;
88 }
89 }
90 contourCount += foundCurve;
91 for (int index = 0; index < contourCount; ++index) {
92 *fSelected.append() = true;
93 }
94 fTries = contourCount;
95}
96
100 if (!fSelected.size()) {
101 return result;
102 }
103 int contourCount = 0;
104 bool enabled = fSelected[0];
105 bool addMoveTo = true;
106 for (auto [verb, pts, w] : SkPathPriv::Iterate(fPath)) {
107 if (enabled && addMoveTo) {
108 result.moveTo(pts[0]);
109 addMoveTo = false;
110 }
111 switch (verb) {
113 break;
115 if (enabled) {
116 result.lineTo(pts[1]);
117 }
118 break;
120 if (enabled) {
121 result.quadTo(pts[1], pts[2]);
122 }
123 break;
125 if (enabled) {
126 result.conicTo(pts[1], pts[2], *w);
127 }
128 break;
130 if (enabled) {
131 result.cubicTo(pts[1], pts[2], pts[3]);
132 }
133 break;
135 if (enabled) {
136 result.close();
137 }
138 if (++contourCount >= fSelected.size()) {
139 break;
140 }
141 enabled = fSelected[contourCount];
142 addMoveTo = true;
143 continue;
144 default:
145 SkDEBUGFAIL("bad verb");
146 return result;
147 }
148 }
149 return result;
150}
151
153 : SubsetPath(path) {
154 int verbCount = 0;
155 for (auto [verb, pts, w] : SkPathPriv::Iterate(fPath)) {
156 switch (verb) {
158 break;
163 ++verbCount;
164 break;
166 break;
167 default:
168 SkDEBUGFAIL("bad verb");
169 return;
170 }
171 }
172 for (int index = 0; index < verbCount; ++index) {
173 *fSelected.append() = true;
174 }
175 fTries = verbCount;
176}
177
181 if (!fSelected.size()) {
182 return result;
183 }
184 int verbIndex = 0;
185 bool addMoveTo = true;
186 bool addLineTo = false;
187 for (auto [verb, pts, w] : SkPathPriv::Iterate(fPath)) {
188 bool enabled = SkPathVerb::kLine <= verb && verb <= SkPathVerb::kCubic
189 ? fSelected[verbIndex++] : false;
190 if (enabled) {
191 if (addMoveTo) {
192 result.moveTo(pts[0]);
193 addMoveTo = false;
194 } else if (addLineTo) {
195 result.lineTo(pts[0]);
196 addLineTo = false;
197 }
198 }
199 switch (verb) {
201 break;
203 if (enabled) {
204 result.lineTo(pts[1]);
205 }
206 break;
208 if (enabled) {
209 result.quadTo(pts[1], pts[2]);
210 }
211 break;
213 if (enabled) {
214 result.conicTo(pts[1], pts[2], *w);
215 }
216 break;
218 if (enabled) {
219 result.cubicTo(pts[1], pts[2], pts[3]);
220 }
221 break;
223 result.close();
224 addMoveTo = true;
225 addLineTo = false;
226 continue;
227 default:
228 SkDEBUGFAIL("bad verb");
229 return result;
230 }
231 addLineTo = !enabled;
232 }
233 return result;
234}
SkPath fPath
int count
#define SkDEBUGFAIL(message)
Definition SkAssert.h:118
#define SkASSERT(cond)
Definition SkAssert.h:116
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static int SkCLZ(uint32_t mask)
Definition SkMathPriv.h:186
@ kClose
SkPath::RawIter returns 0 points.
@ kCubic
SkPath::RawIter returns 4 points.
@ kConic
SkPath::RawIter returns 3 points + 1 weight.
@ kQuad
SkPath::RawIter returns 3 points.
@ kMove
SkPath::RawIter returns 1 point.
@ kLine
SkPath::RawIter returns 2 points.
SkPathFillType getFillType() const
Definition SkPath.h:230
void setFillType(SkPathFillType ft)
Definition SkPath.h:235
int size() const
Definition SkTDArray.h:138
T * append()
Definition SkTDArray.h:191
SkPath getSubsetPath() const override
SubsetContours(const SkPath &path)
SubsetPath(const SkPath &path)
SkTDArray< bool > fSelected
Definition SubsetPath.h:46
const SkPath & fPath
Definition SubsetPath.h:45
int range(int *end) const
bool subset(bool testFailed, SkPath *sub)
virtual SkPath getSubsetPath() const =0
SubsetVerbs(const SkPath &path)
SkPath getSubsetPath() const override
glong glong end
GAsyncResult * result
SkScalar w