Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 957189b

Browse files
csmartdalton86Skia Commit-Bot
authored andcommitted
Remove RawIter usages from pathops
Change-Id: Ib988271088cb1459d026faeb497eeed793172928 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/287887 Commit-Queue: Chris Dalton <[email protected]> Reviewed-by: Mike Reed <[email protected]>
1 parent c66cd98 commit 957189b

File tree

6 files changed

+63
-88
lines changed

6 files changed

+63
-88
lines changed

src/pathops/SkOpEdgeBuilder.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* found in the LICENSE file.
66
*/
77
#include "src/core/SkGeometry.h"
8+
#include "src/core/SkPathPriv.h"
89
#include "src/pathops/SkOpEdgeBuilder.h"
910
#include "src/pathops/SkReduceOrder.h"
1011

@@ -83,14 +84,11 @@ int SkOpEdgeBuilder::preFetch() {
8384
fUnparseable = true;
8485
return 0;
8586
}
86-
SkPath::RawIter iter(*fPath);
8787
SkPoint curveStart;
8888
SkPoint curve[4];
89-
SkPoint pts[4];
90-
SkPath::Verb verb;
9189
bool lastCurve = false;
92-
do {
93-
verb = iter.next(pts);
90+
for (auto [pathVerb, pts, w] : SkPathPriv::Iterate(*fPath)) {
91+
auto verb = static_cast<SkPath::Verb>(pathVerb);
9492
switch (verb) {
9593
case SkPath::kMove_Verb:
9694
if (!fAllowOpenContours && lastCurve) {
@@ -124,7 +122,7 @@ int SkOpEdgeBuilder::preFetch() {
124122
curve[1] = force_small_to_zero(pts[1]);
125123
curve[2] = force_small_to_zero(pts[2]);
126124
verb = SkReduceOrder::Quad(curve, curve);
127-
if (SkPath::kQuad_Verb == verb && 1 != iter.conicWeight()) {
125+
if (SkPath::kQuad_Verb == verb && 1 != *w) {
128126
verb = SkPath::kConic_Verb;
129127
} else if (verb == SkPath::kMove_Verb) {
130128
continue; // skip degenerate points
@@ -150,11 +148,11 @@ int SkOpEdgeBuilder::preFetch() {
150148
int ptCount = SkPathOpsVerbToPoints(verb);
151149
fPathPts.append(ptCount, &curve[1]);
152150
if (verb == SkPath::kConic_Verb) {
153-
*fWeights.append() = iter.conicWeight();
151+
*fWeights.append() = *w;
154152
}
155153
curve[0] = curve[ptCount];
156154
lastCurve = true;
157-
} while (verb != SkPath::kDone_Verb);
155+
}
158156
if (!fAllowOpenContours && lastCurve) {
159157
closeContour(curve[0], curveStart);
160158
}

src/pathops/SkPathOpsAsWinding.cpp

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* found in the LICENSE file.
66
*/
77
#include "include/core/SkRect.h"
8+
#include "src/core/SkPathPriv.h"
89
#include "src/pathops/SkOpEdgeBuilder.h"
910
#include "src/pathops/SkPathOpsCommon.h"
1011
#include <algorithm>
@@ -178,29 +179,25 @@ class OpAsWinding {
178179
void contourBounds(vector<Contour>* containers) {
179180
SkRect bounds;
180181
bounds.setEmpty();
181-
SkPath::RawIter iter(fPath);
182-
SkPoint pts[4];
183-
SkPath::Verb verb;
184182
int lastStart = 0;
185183
int verbStart = 0;
186-
do {
187-
verb = iter.next(pts);
188-
if (SkPath::kMove_Verb == verb) {
184+
for (auto [verb, pts, w] : SkPathPriv::Iterate(fPath)) {
185+
if (SkPathVerb::kMove == verb) {
189186
if (!bounds.isEmpty()) {
190187
containers->emplace_back(bounds, lastStart, verbStart);
191188
lastStart = verbStart;
192189
}
193-
bounds.setBounds(&pts[kPtIndex[verb]], kPtCount[verb]);
190+
bounds.setBounds(&pts[kPtIndex[SkPath::kMove_Verb]], kPtCount[SkPath::kMove_Verb]);
194191
}
195-
if (SkPath::kLine_Verb <= verb && verb <= SkPath::kCubic_Verb) {
192+
if (SkPathVerb::kLine <= verb && verb <= SkPathVerb::kCubic) {
196193
SkRect verbBounds;
197-
verbBounds.setBounds(&pts[kPtIndex[verb]], kPtCount[verb]);
194+
verbBounds.setBounds(&pts[kPtIndex[(int)verb]], kPtCount[(int)verb]);
198195
bounds.joinPossiblyEmptyRect(verbBounds);
199196
}
200197
++verbStart;
201-
} while (SkPath::kDone_Verb != verb);
198+
}
202199
if (!bounds.isEmpty()) {
203-
containers->emplace_back(bounds, lastStart, verbStart);
200+
containers->emplace_back(bounds, lastStart, ++verbStart);
204201
}
205202
}
206203

@@ -325,38 +322,35 @@ class OpAsWinding {
325322
}
326323

327324
void reverseMarkedContours(vector<Contour>& contours, SkPath* result) {
328-
SkPath::RawIter iter(fPath);
325+
SkPathPriv::Iterate iterate(fPath);
326+
auto iter = iterate.begin();
329327
int verbCount = 0;
330328
for (auto contour : contours) {
331329
SkPath reverse;
332330
SkPath* temp = contour.fReverse ? &reverse : result;
333-
do {
334-
SkPoint pts[4];
335-
switch (iter.next(pts)) {
336-
case SkPath::kMove_Verb:
331+
for (; iter != iterate.end() && verbCount < contour.fVerbEnd; ++iter, ++verbCount) {
332+
auto [verb, pts, w] = *iter;
333+
switch (verb) {
334+
case SkPathVerb::kMove:
337335
temp->moveTo(pts[0]);
338336
break;
339-
case SkPath::kLine_Verb:
337+
case SkPathVerb::kLine:
340338
temp->lineTo(pts[1]);
341339
break;
342-
case SkPath::kQuad_Verb:
340+
case SkPathVerb::kQuad:
343341
temp->quadTo(pts[1], pts[2]);
344342
break;
345-
case SkPath::kConic_Verb:
346-
temp->conicTo(pts[1], pts[2], iter.conicWeight());
343+
case SkPathVerb::kConic:
344+
temp->conicTo(pts[1], pts[2], *w);
347345
break;
348-
case SkPath::kCubic_Verb:
346+
case SkPathVerb::kCubic:
349347
temp->cubicTo(pts[1], pts[2], pts[3]);
350348
break;
351-
case SkPath::kClose_Verb:
349+
case SkPathVerb::kClose:
352350
temp->close();
353351
break;
354-
case SkPath::kDone_Verb:
355-
break;
356-
default:
357-
SkASSERT(0);
358352
}
359-
} while (++verbCount < contour.fVerbEnd);
353+
}
360354
if (contour.fReverse) {
361355
result->reverseAddPath(reverse);
362356
}

src/pathops/SkPathOpsDebug.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "include/core/SkString.h"
1010
#include "include/private/SkMutex.h"
1111
#include "src/core/SkOSFile.h"
12+
#include "src/core/SkPathPriv.h"
1213
#include "src/pathops/SkOpCoincidence.h"
1314
#include "src/pathops/SkOpContour.h"
1415
#include "src/pathops/SkPathOpsDebug.h"
@@ -2838,37 +2839,35 @@ static void output_points(const SkPoint* pts, int count) {
28382839
}
28392840
}
28402841

2841-
static void showPathContours(SkPath::RawIter& iter, const char* pathName) {
2842-
uint8_t verb;
2843-
SkPoint pts[4];
2844-
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
2842+
static void showPathContours(const SkPath& path, const char* pathName) {
2843+
for (auto [verb, pts, w] : SkPathPriv::Iterate(path)) {
28452844
switch (verb) {
2846-
case SkPath::kMove_Verb:
2845+
case SkPathVerb::kMove:
28472846
SkDebugf(" %s.moveTo(", pathName);
28482847
output_points(&pts[0], 1);
28492848
SkDebugf(");\n");
28502849
continue;
2851-
case SkPath::kLine_Verb:
2850+
case SkPathVerb::kLine:
28522851
SkDebugf(" %s.lineTo(", pathName);
28532852
output_points(&pts[1], 1);
28542853
SkDebugf(");\n");
28552854
break;
2856-
case SkPath::kQuad_Verb:
2855+
case SkPathVerb::kQuad:
28572856
SkDebugf(" %s.quadTo(", pathName);
28582857
output_points(&pts[1], 2);
28592858
SkDebugf(");\n");
28602859
break;
2861-
case SkPath::kConic_Verb:
2860+
case SkPathVerb::kConic:
28622861
SkDebugf(" %s.conicTo(", pathName);
28632862
output_points(&pts[1], 2);
2864-
SkDebugf(", %1.9gf);\n", iter.conicWeight());
2863+
SkDebugf(", %1.9gf);\n", *w);
28652864
break;
2866-
case SkPath::kCubic_Verb:
2865+
case SkPathVerb::kCubic:
28672866
SkDebugf(" %s.cubicTo(", pathName);
28682867
output_points(&pts[1], 3);
28692868
SkDebugf(");\n");
28702869
break;
2871-
case SkPath::kClose_Verb:
2870+
case SkPathVerb::kClose:
28722871
SkDebugf(" %s.close();\n", pathName);
28732872
break;
28742873
default:
@@ -2886,7 +2885,6 @@ static const char* gFillTypeStr[] = {
28862885
};
28872886

28882887
void SkPathOpsDebug::ShowOnePath(const SkPath& path, const char* name, bool includeDeclaration) {
2889-
SkPath::RawIter iter(path);
28902888
#define SUPPORT_RECT_CONTOUR_DETECTION 0
28912889
#if SUPPORT_RECT_CONTOUR_DETECTION
28922890
int rectCount = path.isRectContours() ? path.rectContours(nullptr, nullptr) : 0;
@@ -2911,8 +2909,7 @@ void SkPathOpsDebug::ShowOnePath(const SkPath& path, const char* name, bool incl
29112909
SkDebugf(" SkPath %s;\n", name);
29122910
}
29132911
SkDebugf(" %s.setFillType(SkPath::%s);\n", name, gFillTypeStr[(int)fillType]);
2914-
iter.setPath(path);
2915-
showPathContours(iter, name);
2912+
showPathContours(path, name);
29162913
}
29172914

29182915
#if DEBUG_DUMP_VERIFY

src/pathops/SkPathOpsTightBounds.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,30 @@
44
* Use of this source code is governed by a BSD-style license that can be
55
* found in the LICENSE file.
66
*/
7+
#include "src/core/SkPathPriv.h"
78
#include "src/pathops/SkOpEdgeBuilder.h"
89
#include "src/pathops/SkPathOpsCommon.h"
910

1011
bool TightBounds(const SkPath& path, SkRect* result) {
11-
SkPath::RawIter iter(path);
1212
SkRect moveBounds = { SK_ScalarMax, SK_ScalarMax, SK_ScalarMin, SK_ScalarMin };
1313
bool wellBehaved = true;
14-
SkPath::Verb verb;
15-
do {
16-
SkPoint pts[4];
17-
verb = iter.next(pts);
14+
for (auto [verb, pts, w] : SkPathPriv::Iterate(path)) {
1815
switch (verb) {
19-
case SkPath::kMove_Verb:
16+
case SkPathVerb::kMove:
2017
moveBounds.fLeft = std::min(moveBounds.fLeft, pts[0].fX);
2118
moveBounds.fTop = std::min(moveBounds.fTop, pts[0].fY);
2219
moveBounds.fRight = std::max(moveBounds.fRight, pts[0].fX);
2320
moveBounds.fBottom = std::max(moveBounds.fBottom, pts[0].fY);
2421
break;
25-
case SkPath::kQuad_Verb:
26-
case SkPath::kConic_Verb:
22+
case SkPathVerb::kQuad:
23+
case SkPathVerb::kConic:
2724
if (!wellBehaved) {
2825
break;
2926
}
3027
wellBehaved &= between(pts[0].fX, pts[1].fX, pts[2].fX);
3128
wellBehaved &= between(pts[0].fY, pts[1].fY, pts[2].fY);
3229
break;
33-
case SkPath::kCubic_Verb:
30+
case SkPathVerb::kCubic:
3431
if (!wellBehaved) {
3532
break;
3633
}
@@ -42,7 +39,7 @@ bool TightBounds(const SkPath& path, SkRect* result) {
4239
default:
4340
break;
4441
}
45-
} while (verb != SkPath::kDone_Verb);
42+
}
4643
if (wellBehaved) {
4744
*result = path.getBounds();
4845
return true;

tests/PathOpsExtendedTest.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "include/core/SkStream.h"
1414
#include "include/private/SkMutex.h"
1515
#include "include/utils/SkParsePath.h"
16+
#include "src/core/SkPathPriv.h"
1617
#include "tests/PathOpsDebug.h"
1718
#include "tests/PathOpsExtendedTest.h"
1819
#include "tests/PathOpsThreadedCommon.h"
@@ -416,20 +417,13 @@ static void json_path_out(const SkPath& path, const char* pathName, const char*
416417
SkParsePath::ToSVGString(path, &svg);
417418
fprintf(PathOpsDebug::gOut, " \"%s\": \"%s\",\n", pathName, svg.c_str());
418419
} else {
419-
SkPath::RawIter iter(path);
420-
SkPath::Verb verb;
421420
// MOVE, LINE, QUAD, CONIC, CUBIC, CLOSE
422421
const int verbConst[] = { 0, 1, 2, 3, 4, 5 };
423422
const int pointIndex[] = { 0, 1, 1, 1, 1, 0 };
424423
const int pointCount[] = { 1, 2, 3, 3, 4, 0 };
425424
fprintf(PathOpsDebug::gOut, " \"%s\": [", pathName);
426425
bool first = true;
427-
do {
428-
SkPoint points[4];
429-
verb = iter.next(points);
430-
if (SkPath::kDone_Verb == verb) {
431-
break;
432-
}
426+
for (auto [verb, points, w] : SkPathPriv::Iterate(path)) {
433427
if (first) {
434428
first = false;
435429
} else {
@@ -441,11 +435,11 @@ static void json_path_out(const SkPath& path, const char* pathName, const char*
441435
fprintf(PathOpsDebug::gOut, ", \"0x%08x\", \"0x%08x\"",
442436
SkFloat2Bits(points[i].fX), SkFloat2Bits(points[i].fY));
443437
}
444-
if (SkPath::kConic_Verb == verb) {
445-
fprintf(PathOpsDebug::gOut, ", \"0x%08x\"", SkFloat2Bits(iter.conicWeight()));
438+
if (SkPathVerb::kConic == verb) {
439+
fprintf(PathOpsDebug::gOut, ", \"0x%08x\"", SkFloat2Bits(*w));
446440
}
447441
fprintf(PathOpsDebug::gOut, "]");
448-
} while (SkPath::kDone_Verb != verb);
442+
}
449443
fprintf(PathOpsDebug::gOut, "],\n");
450444
}
451445
fprintf(PathOpsDebug::gOut, " \"fillType%s\": \"k%s_FillType\"%s", fillTypeName,

tests/PathOpsTestCommon.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Use of this source code is governed by a BSD-style license that can be
55
* found in the LICENSE file.
66
*/
7+
#include "src/core/SkPathPriv.h"
78
#include "src/core/SkTSort.h"
89
#include "src/pathops/SkPathOpsBounds.h"
910
#include "src/pathops/SkPathOpsConic.h"
@@ -167,21 +168,18 @@ void CubicPathToQuads(const SkPath& cubicPath, SkPath* quadPath) {
167168
quadPath->reset();
168169
SkDCubic cubic;
169170
SkTArray<SkDQuad, true> quads;
170-
SkPath::RawIter iter(cubicPath);
171-
uint8_t verb;
172-
SkPoint pts[4];
173-
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
171+
for (auto [verb, pts, w] : SkPathPriv::Iterate(cubicPath)) {
174172
switch (verb) {
175-
case SkPath::kMove_Verb:
173+
case SkPathVerb::kMove:
176174
quadPath->moveTo(pts[0].fX, pts[0].fY);
177175
continue;
178-
case SkPath::kLine_Verb:
176+
case SkPathVerb::kLine:
179177
quadPath->lineTo(pts[1].fX, pts[1].fY);
180178
break;
181-
case SkPath::kQuad_Verb:
179+
case SkPathVerb::kQuad:
182180
quadPath->quadTo(pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY);
183181
break;
184-
case SkPath::kCubic_Verb:
182+
case SkPathVerb::kCubic:
185183
quads.reset();
186184
cubic.set(pts);
187185
CubicToQuads(cubic, cubic.calcPrecision(), quads);
@@ -193,7 +191,7 @@ void CubicPathToQuads(const SkPath& cubicPath, SkPath* quadPath) {
193191
quadPath->quadTo(qPts[0].fX, qPts[0].fY, qPts[1].fX, qPts[1].fY);
194192
}
195193
break;
196-
case SkPath::kClose_Verb:
194+
case SkPathVerb::kClose:
197195
quadPath->close();
198196
break;
199197
default:
@@ -206,21 +204,18 @@ void CubicPathToQuads(const SkPath& cubicPath, SkPath* quadPath) {
206204
void CubicPathToSimple(const SkPath& cubicPath, SkPath* simplePath) {
207205
simplePath->reset();
208206
SkDCubic cubic;
209-
SkPath::RawIter iter(cubicPath);
210-
uint8_t verb;
211-
SkPoint pts[4];
212-
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
207+
for (auto [verb, pts, w] : SkPathPriv::Iterate(cubicPath)) {
213208
switch (verb) {
214-
case SkPath::kMove_Verb:
209+
case SkPathVerb::kMove:
215210
simplePath->moveTo(pts[0].fX, pts[0].fY);
216211
continue;
217-
case SkPath::kLine_Verb:
212+
case SkPathVerb::kLine:
218213
simplePath->lineTo(pts[1].fX, pts[1].fY);
219214
break;
220-
case SkPath::kQuad_Verb:
215+
case SkPathVerb::kQuad:
221216
simplePath->quadTo(pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY);
222217
break;
223-
case SkPath::kCubic_Verb: {
218+
case SkPathVerb::kCubic: {
224219
cubic.set(pts);
225220
double tInflects[2];
226221
int inflections = cubic.findInflections(tInflects);
@@ -242,7 +237,7 @@ void CubicPathToSimple(const SkPath& cubicPath, SkPath* simplePath) {
242237
}
243238
break;
244239
}
245-
case SkPath::kClose_Verb:
240+
case SkPathVerb::kClose:
246241
simplePath->close();
247242
break;
248243
default:

0 commit comments

Comments
 (0)