Remove RawIter usages from pathops
Change-Id: Ib988271088cb1459d026faeb497eeed793172928
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/287887
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Mike Reed <reed@google.com>
diff --git a/src/pathops/SkOpEdgeBuilder.cpp b/src/pathops/SkOpEdgeBuilder.cpp
index f8d73c3..757fa31 100644
--- a/src/pathops/SkOpEdgeBuilder.cpp
+++ b/src/pathops/SkOpEdgeBuilder.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
#include "src/core/SkGeometry.h"
+#include "src/core/SkPathPriv.h"
#include "src/pathops/SkOpEdgeBuilder.h"
#include "src/pathops/SkReduceOrder.h"
@@ -83,14 +84,11 @@
fUnparseable = true;
return 0;
}
- SkPath::RawIter iter(*fPath);
SkPoint curveStart;
SkPoint curve[4];
- SkPoint pts[4];
- SkPath::Verb verb;
bool lastCurve = false;
- do {
- verb = iter.next(pts);
+ for (auto [pathVerb, pts, w] : SkPathPriv::Iterate(*fPath)) {
+ auto verb = static_cast<SkPath::Verb>(pathVerb);
switch (verb) {
case SkPath::kMove_Verb:
if (!fAllowOpenContours && lastCurve) {
@@ -124,7 +122,7 @@
curve[1] = force_small_to_zero(pts[1]);
curve[2] = force_small_to_zero(pts[2]);
verb = SkReduceOrder::Quad(curve, curve);
- if (SkPath::kQuad_Verb == verb && 1 != iter.conicWeight()) {
+ if (SkPath::kQuad_Verb == verb && 1 != *w) {
verb = SkPath::kConic_Verb;
} else if (verb == SkPath::kMove_Verb) {
continue; // skip degenerate points
@@ -150,11 +148,11 @@
int ptCount = SkPathOpsVerbToPoints(verb);
fPathPts.append(ptCount, &curve[1]);
if (verb == SkPath::kConic_Verb) {
- *fWeights.append() = iter.conicWeight();
+ *fWeights.append() = *w;
}
curve[0] = curve[ptCount];
lastCurve = true;
- } while (verb != SkPath::kDone_Verb);
+ }
if (!fAllowOpenContours && lastCurve) {
closeContour(curve[0], curveStart);
}
diff --git a/src/pathops/SkPathOpsAsWinding.cpp b/src/pathops/SkPathOpsAsWinding.cpp
index abf6af7..763427f 100644
--- a/src/pathops/SkPathOpsAsWinding.cpp
+++ b/src/pathops/SkPathOpsAsWinding.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
#include "include/core/SkRect.h"
+#include "src/core/SkPathPriv.h"
#include "src/pathops/SkOpEdgeBuilder.h"
#include "src/pathops/SkPathOpsCommon.h"
#include <algorithm>
@@ -178,29 +179,25 @@
void contourBounds(vector<Contour>* containers) {
SkRect bounds;
bounds.setEmpty();
- SkPath::RawIter iter(fPath);
- SkPoint pts[4];
- SkPath::Verb verb;
int lastStart = 0;
int verbStart = 0;
- do {
- verb = iter.next(pts);
- if (SkPath::kMove_Verb == verb) {
+ for (auto [verb, pts, w] : SkPathPriv::Iterate(fPath)) {
+ if (SkPathVerb::kMove == verb) {
if (!bounds.isEmpty()) {
containers->emplace_back(bounds, lastStart, verbStart);
lastStart = verbStart;
}
- bounds.setBounds(&pts[kPtIndex[verb]], kPtCount[verb]);
+ bounds.setBounds(&pts[kPtIndex[SkPath::kMove_Verb]], kPtCount[SkPath::kMove_Verb]);
}
- if (SkPath::kLine_Verb <= verb && verb <= SkPath::kCubic_Verb) {
+ if (SkPathVerb::kLine <= verb && verb <= SkPathVerb::kCubic) {
SkRect verbBounds;
- verbBounds.setBounds(&pts[kPtIndex[verb]], kPtCount[verb]);
+ verbBounds.setBounds(&pts[kPtIndex[(int)verb]], kPtCount[(int)verb]);
bounds.joinPossiblyEmptyRect(verbBounds);
}
++verbStart;
- } while (SkPath::kDone_Verb != verb);
+ }
if (!bounds.isEmpty()) {
- containers->emplace_back(bounds, lastStart, verbStart);
+ containers->emplace_back(bounds, lastStart, ++verbStart);
}
}
@@ -325,38 +322,35 @@
}
void reverseMarkedContours(vector<Contour>& contours, SkPath* result) {
- SkPath::RawIter iter(fPath);
+ SkPathPriv::Iterate iterate(fPath);
+ auto iter = iterate.begin();
int verbCount = 0;
for (auto contour : contours) {
SkPath reverse;
SkPath* temp = contour.fReverse ? &reverse : result;
- do {
- SkPoint pts[4];
- switch (iter.next(pts)) {
- case SkPath::kMove_Verb:
+ for (; iter != iterate.end() && verbCount < contour.fVerbEnd; ++iter, ++verbCount) {
+ auto [verb, pts, w] = *iter;
+ switch (verb) {
+ case SkPathVerb::kMove:
temp->moveTo(pts[0]);
break;
- case SkPath::kLine_Verb:
+ case SkPathVerb::kLine:
temp->lineTo(pts[1]);
break;
- case SkPath::kQuad_Verb:
+ case SkPathVerb::kQuad:
temp->quadTo(pts[1], pts[2]);
break;
- case SkPath::kConic_Verb:
- temp->conicTo(pts[1], pts[2], iter.conicWeight());
+ case SkPathVerb::kConic:
+ temp->conicTo(pts[1], pts[2], *w);
break;
- case SkPath::kCubic_Verb:
+ case SkPathVerb::kCubic:
temp->cubicTo(pts[1], pts[2], pts[3]);
break;
- case SkPath::kClose_Verb:
+ case SkPathVerb::kClose:
temp->close();
break;
- case SkPath::kDone_Verb:
- break;
- default:
- SkASSERT(0);
}
- } while (++verbCount < contour.fVerbEnd);
+ }
if (contour.fReverse) {
result->reverseAddPath(reverse);
}
diff --git a/src/pathops/SkPathOpsDebug.cpp b/src/pathops/SkPathOpsDebug.cpp
index 8fc2ca8..a6555d1 100644
--- a/src/pathops/SkPathOpsDebug.cpp
+++ b/src/pathops/SkPathOpsDebug.cpp
@@ -9,6 +9,7 @@
#include "include/core/SkString.h"
#include "include/private/SkMutex.h"
#include "src/core/SkOSFile.h"
+#include "src/core/SkPathPriv.h"
#include "src/pathops/SkOpCoincidence.h"
#include "src/pathops/SkOpContour.h"
#include "src/pathops/SkPathOpsDebug.h"
@@ -2838,37 +2839,35 @@
}
}
-static void showPathContours(SkPath::RawIter& iter, const char* pathName) {
- uint8_t verb;
- SkPoint pts[4];
- while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
+static void showPathContours(const SkPath& path, const char* pathName) {
+ for (auto [verb, pts, w] : SkPathPriv::Iterate(path)) {
switch (verb) {
- case SkPath::kMove_Verb:
+ case SkPathVerb::kMove:
SkDebugf(" %s.moveTo(", pathName);
output_points(&pts[0], 1);
SkDebugf(");\n");
continue;
- case SkPath::kLine_Verb:
+ case SkPathVerb::kLine:
SkDebugf(" %s.lineTo(", pathName);
output_points(&pts[1], 1);
SkDebugf(");\n");
break;
- case SkPath::kQuad_Verb:
+ case SkPathVerb::kQuad:
SkDebugf(" %s.quadTo(", pathName);
output_points(&pts[1], 2);
SkDebugf(");\n");
break;
- case SkPath::kConic_Verb:
+ case SkPathVerb::kConic:
SkDebugf(" %s.conicTo(", pathName);
output_points(&pts[1], 2);
- SkDebugf(", %1.9gf);\n", iter.conicWeight());
+ SkDebugf(", %1.9gf);\n", *w);
break;
- case SkPath::kCubic_Verb:
+ case SkPathVerb::kCubic:
SkDebugf(" %s.cubicTo(", pathName);
output_points(&pts[1], 3);
SkDebugf(");\n");
break;
- case SkPath::kClose_Verb:
+ case SkPathVerb::kClose:
SkDebugf(" %s.close();\n", pathName);
break;
default:
@@ -2886,7 +2885,6 @@
};
void SkPathOpsDebug::ShowOnePath(const SkPath& path, const char* name, bool includeDeclaration) {
- SkPath::RawIter iter(path);
#define SUPPORT_RECT_CONTOUR_DETECTION 0
#if SUPPORT_RECT_CONTOUR_DETECTION
int rectCount = path.isRectContours() ? path.rectContours(nullptr, nullptr) : 0;
@@ -2911,8 +2909,7 @@
SkDebugf(" SkPath %s;\n", name);
}
SkDebugf(" %s.setFillType(SkPath::%s);\n", name, gFillTypeStr[(int)fillType]);
- iter.setPath(path);
- showPathContours(iter, name);
+ showPathContours(path, name);
}
#if DEBUG_DUMP_VERIFY
diff --git a/src/pathops/SkPathOpsTightBounds.cpp b/src/pathops/SkPathOpsTightBounds.cpp
index 4e2af89..d11b292 100644
--- a/src/pathops/SkPathOpsTightBounds.cpp
+++ b/src/pathops/SkPathOpsTightBounds.cpp
@@ -4,33 +4,30 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+#include "src/core/SkPathPriv.h"
#include "src/pathops/SkOpEdgeBuilder.h"
#include "src/pathops/SkPathOpsCommon.h"
bool TightBounds(const SkPath& path, SkRect* result) {
- SkPath::RawIter iter(path);
SkRect moveBounds = { SK_ScalarMax, SK_ScalarMax, SK_ScalarMin, SK_ScalarMin };
bool wellBehaved = true;
- SkPath::Verb verb;
- do {
- SkPoint pts[4];
- verb = iter.next(pts);
+ for (auto [verb, pts, w] : SkPathPriv::Iterate(path)) {
switch (verb) {
- case SkPath::kMove_Verb:
+ case SkPathVerb::kMove:
moveBounds.fLeft = std::min(moveBounds.fLeft, pts[0].fX);
moveBounds.fTop = std::min(moveBounds.fTop, pts[0].fY);
moveBounds.fRight = std::max(moveBounds.fRight, pts[0].fX);
moveBounds.fBottom = std::max(moveBounds.fBottom, pts[0].fY);
break;
- case SkPath::kQuad_Verb:
- case SkPath::kConic_Verb:
+ case SkPathVerb::kQuad:
+ case SkPathVerb::kConic:
if (!wellBehaved) {
break;
}
wellBehaved &= between(pts[0].fX, pts[1].fX, pts[2].fX);
wellBehaved &= between(pts[0].fY, pts[1].fY, pts[2].fY);
break;
- case SkPath::kCubic_Verb:
+ case SkPathVerb::kCubic:
if (!wellBehaved) {
break;
}
@@ -42,7 +39,7 @@
default:
break;
}
- } while (verb != SkPath::kDone_Verb);
+ }
if (wellBehaved) {
*result = path.getBounds();
return true;
diff --git a/tests/PathOpsExtendedTest.cpp b/tests/PathOpsExtendedTest.cpp
index 0439b86..2ceb5fa 100644
--- a/tests/PathOpsExtendedTest.cpp
+++ b/tests/PathOpsExtendedTest.cpp
@@ -13,6 +13,7 @@
#include "include/core/SkStream.h"
#include "include/private/SkMutex.h"
#include "include/utils/SkParsePath.h"
+#include "src/core/SkPathPriv.h"
#include "tests/PathOpsDebug.h"
#include "tests/PathOpsExtendedTest.h"
#include "tests/PathOpsThreadedCommon.h"
@@ -416,20 +417,13 @@
SkParsePath::ToSVGString(path, &svg);
fprintf(PathOpsDebug::gOut, " \"%s\": \"%s\",\n", pathName, svg.c_str());
} else {
- SkPath::RawIter iter(path);
- SkPath::Verb verb;
// MOVE, LINE, QUAD, CONIC, CUBIC, CLOSE
const int verbConst[] = { 0, 1, 2, 3, 4, 5 };
const int pointIndex[] = { 0, 1, 1, 1, 1, 0 };
const int pointCount[] = { 1, 2, 3, 3, 4, 0 };
fprintf(PathOpsDebug::gOut, " \"%s\": [", pathName);
bool first = true;
- do {
- SkPoint points[4];
- verb = iter.next(points);
- if (SkPath::kDone_Verb == verb) {
- break;
- }
+ for (auto [verb, points, w] : SkPathPriv::Iterate(path)) {
if (first) {
first = false;
} else {
@@ -441,11 +435,11 @@
fprintf(PathOpsDebug::gOut, ", \"0x%08x\", \"0x%08x\"",
SkFloat2Bits(points[i].fX), SkFloat2Bits(points[i].fY));
}
- if (SkPath::kConic_Verb == verb) {
- fprintf(PathOpsDebug::gOut, ", \"0x%08x\"", SkFloat2Bits(iter.conicWeight()));
+ if (SkPathVerb::kConic == verb) {
+ fprintf(PathOpsDebug::gOut, ", \"0x%08x\"", SkFloat2Bits(*w));
}
fprintf(PathOpsDebug::gOut, "]");
- } while (SkPath::kDone_Verb != verb);
+ }
fprintf(PathOpsDebug::gOut, "],\n");
}
fprintf(PathOpsDebug::gOut, " \"fillType%s\": \"k%s_FillType\"%s", fillTypeName,
diff --git a/tests/PathOpsTestCommon.cpp b/tests/PathOpsTestCommon.cpp
index 4d7ee1c..a8106d0 100644
--- a/tests/PathOpsTestCommon.cpp
+++ b/tests/PathOpsTestCommon.cpp
@@ -4,6 +4,7 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+#include "src/core/SkPathPriv.h"
#include "src/core/SkTSort.h"
#include "src/pathops/SkPathOpsBounds.h"
#include "src/pathops/SkPathOpsConic.h"
@@ -167,21 +168,18 @@
quadPath->reset();
SkDCubic cubic;
SkTArray<SkDQuad, true> quads;
- SkPath::RawIter iter(cubicPath);
- uint8_t verb;
- SkPoint pts[4];
- while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
+ for (auto [verb, pts, w] : SkPathPriv::Iterate(cubicPath)) {
switch (verb) {
- case SkPath::kMove_Verb:
+ case SkPathVerb::kMove:
quadPath->moveTo(pts[0].fX, pts[0].fY);
continue;
- case SkPath::kLine_Verb:
+ case SkPathVerb::kLine:
quadPath->lineTo(pts[1].fX, pts[1].fY);
break;
- case SkPath::kQuad_Verb:
+ case SkPathVerb::kQuad:
quadPath->quadTo(pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY);
break;
- case SkPath::kCubic_Verb:
+ case SkPathVerb::kCubic:
quads.reset();
cubic.set(pts);
CubicToQuads(cubic, cubic.calcPrecision(), quads);
@@ -193,7 +191,7 @@
quadPath->quadTo(qPts[0].fX, qPts[0].fY, qPts[1].fX, qPts[1].fY);
}
break;
- case SkPath::kClose_Verb:
+ case SkPathVerb::kClose:
quadPath->close();
break;
default:
@@ -206,21 +204,18 @@
void CubicPathToSimple(const SkPath& cubicPath, SkPath* simplePath) {
simplePath->reset();
SkDCubic cubic;
- SkPath::RawIter iter(cubicPath);
- uint8_t verb;
- SkPoint pts[4];
- while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
+ for (auto [verb, pts, w] : SkPathPriv::Iterate(cubicPath)) {
switch (verb) {
- case SkPath::kMove_Verb:
+ case SkPathVerb::kMove:
simplePath->moveTo(pts[0].fX, pts[0].fY);
continue;
- case SkPath::kLine_Verb:
+ case SkPathVerb::kLine:
simplePath->lineTo(pts[1].fX, pts[1].fY);
break;
- case SkPath::kQuad_Verb:
+ case SkPathVerb::kQuad:
simplePath->quadTo(pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY);
break;
- case SkPath::kCubic_Verb: {
+ case SkPathVerb::kCubic: {
cubic.set(pts);
double tInflects[2];
int inflections = cubic.findInflections(tInflects);
@@ -242,7 +237,7 @@
}
break;
}
- case SkPath::kClose_Verb:
+ case SkPathVerb::kClose:
simplePath->close();
break;
default: