Path ops formerly found the topmost unprocessed edge and determined its angle sort order to initialize the winding. This never worked correctly with cubics and was flaky with paths consisting mostly of vertical edges.
This replacement shoots axis-aligned rays through all intersecting edges to find the outermost one either horizontally or vertically. The resulting code is smaller and twice as fast.
To support this, most of the horizontal / vertical intersection code was rewritten and standardized, and old code supporting the top-directed winding was deleted.
Contours were pointed to by an SkTDArray. Instead, put them in a linked list, and designate the list head with its own class to ensure that methods that take lists of contours start at the top. This change removed a large percentage of memory allocations used by path ops.
TBR=reed@google.com
BUG=skia:3588
Review URL: https://codereview.chromium.org/1111333002
diff --git a/src/pathops/SkOpSpan.cpp b/src/pathops/SkOpSpan.cpp
index b75a692..9c9e07f 100755
--- a/src/pathops/SkOpSpan.cpp
+++ b/src/pathops/SkOpSpan.cpp
@@ -86,65 +86,6 @@
return span()->segment();
}
-// find the starting or ending span with an existing loop of angles
-// OPTIMIZE? remove the spans pointing to windValue==0 here or earlier?
-// FIXME? assert that only one other span has a valid windValue or oppValue
-bool SkOpSpanBase::addSimpleAngle(bool checkFrom, SkChunkAlloc* allocator) {
- SkOpAngle* angle;
- if (checkFrom) {
- if (!this->final()) {
- return false;
- }
- if (this->fromAngle()) {
- SkASSERT(this->fromAngle()->loopCount() == 2);
- return true;
- }
- angle = this->segment()->addEndSpan(allocator);
- } else {
- SkASSERT(this->t() == 0);
- SkOpSpan* span = this->upCast();
- if (span->toAngle()) {
- SkASSERT(span->toAngle()->loopCount() == 2);
- SkASSERT(!span->fromAngle());
- span->setFromAngle(span->toAngle()->next());
- return true;
- }
- angle = this->segment()->addStartSpan(allocator);
- }
- SkOpPtT* ptT = this->ptT();
- SkOpSpanBase* oSpanBase;
- SkOpSpan* oSpan;
- SkOpSegment* other;
- do {
- ptT = ptT->next();
- oSpanBase = ptT->span();
- oSpan = oSpanBase->upCastable();
- other = oSpanBase->segment();
- if (oSpan && oSpan->windValue()) {
- break;
- }
- if (oSpanBase->t() == 0) {
- continue;
- }
- SkOpSpan* oFromSpan = oSpanBase->prev();
- SkASSERT(oFromSpan->t() < 1);
- if (oFromSpan->windValue()) {
- break;
- }
- } while (ptT != this->ptT());
- SkOpAngle* oAngle;
- if (checkFrom) {
- oAngle = other->addStartSpan(allocator);
- SkASSERT(oSpan && !oSpan->final());
- SkASSERT(oAngle == oSpan->toAngle());
- } else {
- oAngle = other->addEndSpan(allocator);
- SkASSERT(oAngle == oSpanBase->fromAngle());
- }
- angle->insert(oAngle);
- return true;
-}
-
void SkOpSpanBase::align() {
if (this->fAligned) {
return;
@@ -308,11 +249,6 @@
fSpanAdds += span->fSpanAdds;
}
-void SkOpSpan::applyCoincidence(SkOpSpan* opp) {
- SkASSERT(!final());
- SkASSERT(0); // incomplete
-}
-
bool SkOpSpan::containsCoincidence(const SkOpSegment* segment) const {
SkASSERT(this->segment() != segment);
const SkOpSpan* next = fCoincident;
@@ -345,6 +281,7 @@
fWindSum = fOppSum = SK_MinS32;
fWindValue = 1;
fOppValue = 0;
+ fTopTTry = 0;
fChased = fDone = false;
segment->bumpCount();
}
@@ -358,3 +295,13 @@
SkASSERT(!DEBUG_LIMIT_WIND_SUM || abs(oppSum) <= DEBUG_LIMIT_WIND_SUM);
fOppSum = oppSum;
}
+
+void SkOpSpan::setWindSum(int windSum) {
+ SkASSERT(!final());
+ if (fWindSum != SK_MinS32 && fWindSum != windSum) {
+ this->globalState()->setWindingFailed();
+ return;
+ }
+ SkASSERT(!DEBUG_LIMIT_WIND_SUM || abs(windSum) <= DEBUG_LIMIT_WIND_SUM);
+ fWindSum = windSum;
+}