Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Unified Diff: src/pathops/SkPathOpsSimplify.cpp

Issue 1029993002: Revert of pathops version two (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pathops/SkPathOpsRect.cpp ('k') | src/pathops/SkPathOpsTCubicSect.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pathops/SkPathOpsSimplify.cpp
diff --git a/src/pathops/SkPathOpsSimplify.cpp b/src/pathops/SkPathOpsSimplify.cpp
index 7a234ecb01ecb61a751b49368ca6391b90aac61f..57090ac4238bd658cf8bdc60c4cbee8113679ad4 100644
--- a/src/pathops/SkPathOpsSimplify.cpp
+++ b/src/pathops/SkPathOpsSimplify.cpp
@@ -5,13 +5,11 @@
* found in the LICENSE file.
*/
#include "SkAddIntersections.h"
-#include "SkOpCoincidence.h"
#include "SkOpEdgeBuilder.h"
#include "SkPathOpsCommon.h"
#include "SkPathWriter.h"
-static bool bridgeWinding(SkTDArray<SkOpContour* >& contourList, SkPathWriter* simple,
- SkChunkAlloc* allocator) {
+static bool bridgeWinding(SkTArray<SkOpContour*, true>& contourList, SkPathWriter* simple) {
bool firstContour = true;
bool unsortable = false;
bool topUnsortable = false;
@@ -19,24 +17,15 @@
SkPoint lastTopLeft;
SkPoint topLeft = {SK_ScalarMin, SK_ScalarMin};
do {
- SkOpSpanBase* start;
- SkOpSpanBase* end;
+ int index, endIndex;
bool topDone;
bool onlyVertical = false;
lastTopLeft = topLeft;
- SkOpSegment* current = FindSortableTop(contourList, firstPass, SkOpAngle::kUnaryWinding,
- &firstContour, &start, &end, &topLeft, &topUnsortable, &topDone, &onlyVertical,
- allocator);
+ SkOpSegment* current = FindSortableTop(contourList, SkOpAngle::kUnaryWinding, &firstContour,
+ &index, &endIndex, &topLeft, &topUnsortable, &topDone, &onlyVertical, firstPass);
if (!current) {
if ((!topUnsortable || firstPass) && !topDone) {
SkASSERT(topLeft.fX != SK_ScalarMin && topLeft.fY != SK_ScalarMin);
- if (lastTopLeft.fX == SK_ScalarMin && lastTopLeft.fY == SK_ScalarMin) {
- if (firstPass) {
- firstPass = false;
- } else {
- break;
- }
- }
topLeft.fX = topLeft.fY = SK_ScalarMin;
continue;
}
@@ -45,66 +34,62 @@
break;
}
firstPass = !topUnsortable || lastTopLeft != topLeft;
- SkTDArray<SkOpSpanBase*> chase;
+ SkTDArray<SkOpSpan*> chase;
do {
- if (current->activeWinding(start, end)) {
+ if (current->activeWinding(index, endIndex)) {
do {
if (!unsortable && current->done()) {
break;
}
SkASSERT(unsortable || !current->done());
- SkOpSpanBase* nextStart = start;
- SkOpSpanBase* nextEnd = end;
+ int nextStart = index;
+ int nextEnd = endIndex;
SkOpSegment* next = current->findNextWinding(&chase, &nextStart, &nextEnd,
&unsortable);
if (!next) {
if (!unsortable && simple->hasMove()
&& current->verb() != SkPath::kLine_Verb
&& !simple->isClosed()) {
- current->addCurveTo(start, end, simple, true);
- #if DEBUG_ACTIVE_SPANS
- if (!simple->isClosed()) {
- DebugShowActiveSpans(contourList);
- }
- #endif
+ current->addCurveTo(index, endIndex, simple, true);
+ SkASSERT(simple->isClosed());
}
break;
}
#if DEBUG_FLOW
SkDebugf("%s current id=%d from=(%1.9g,%1.9g) to=(%1.9g,%1.9g)\n", __FUNCTION__,
- current->debugID(), start->pt().fX, start->pt().fY,
- end->pt().fX, end->pt().fY);
+ current->debugID(), current->xyAtT(index).fX, current->xyAtT(index).fY,
+ current->xyAtT(endIndex).fX, current->xyAtT(endIndex).fY);
#endif
- current->addCurveTo(start, end, simple, true);
+ current->addCurveTo(index, endIndex, simple, true);
current = next;
- start = nextStart;
- end = nextEnd;
- } while (!simple->isClosed() && (!unsortable || !start->starter(end)->done()));
- if (current->activeWinding(start, end) && !simple->isClosed()) {
- SkOpSpan* spanStart = start->starter(end);
- if (!spanStart->done()) {
- current->addCurveTo(start, end, simple, true);
- current->markDone(spanStart);
+ index = nextStart;
+ endIndex = nextEnd;
+ } while (!simple->isClosed() && (!unsortable
+ || !current->done(SkMin32(index, endIndex))));
+ if (current->activeWinding(index, endIndex) && !simple->isClosed()) {
+// SkASSERT(unsortable || simple->isEmpty());
+ int min = SkMin32(index, endIndex);
+ if (!current->done(min)) {
+ current->addCurveTo(index, endIndex, simple, true);
+ current->markDoneUnary(min);
}
}
simple->close();
} else {
- SkOpSpanBase* last = current->markAndChaseDone(start, end);
- if (last && !last->chased()) {
- last->setChased(true);
+ SkOpSpan* last = current->markAndChaseDoneUnary(index, endIndex);
+ if (last && !last->fChased && !last->fLoop) {
+ last->fChased = true;
SkASSERT(!SkPathOpsDebug::ChaseContains(chase, last));
// assert that last isn't already in array
*chase.append() = last;
#if DEBUG_WINDING
- SkDebugf("%s chase.append id=%d", __FUNCTION__, last->segment()->debugID());
- if (!last->final()) {
- SkDebugf(" windSum=%d", last->upCast()->windSum());
- }
- SkDebugf("\n");
+ SkDebugf("%s chase.append id=%d windSum=%d small=%d\n", __FUNCTION__,
+ last->fOther->span(last->fOtherIndex).fOther->debugID(), last->fWindSum,
+ last->fSmall);
#endif
}
}
- current = FindChase(&chase, &start, &end);
+ current = FindChase(&chase, &index, &endIndex);
#if DEBUG_ACTIVE_SPANS
DebugShowActiveSpans(contourList);
#endif
@@ -117,11 +102,9 @@
}
// returns true if all edges were processed
-static bool bridgeXor(SkTDArray<SkOpContour* >& contourList, SkPathWriter* simple,
- SkChunkAlloc* allocator) {
+static bool bridgeXor(SkTArray<SkOpContour*, true>& contourList, SkPathWriter* simple) {
SkOpSegment* current;
- SkOpSpanBase* start;
- SkOpSpanBase* end;
+ int start, end;
bool unsortable = false;
bool closable = true;
while ((current = FindUndone(contourList, &start, &end))) {
@@ -132,38 +115,34 @@
}
#endif
SkASSERT(unsortable || !current->done());
- SkOpSpanBase* nextStart = start;
- SkOpSpanBase* nextEnd = end;
+ int nextStart = start;
+ int nextEnd = end;
SkOpSegment* next = current->findNextXor(&nextStart, &nextEnd, &unsortable);
if (!next) {
if (!unsortable && simple->hasMove()
&& current->verb() != SkPath::kLine_Verb
&& !simple->isClosed()) {
current->addCurveTo(start, end, simple, true);
- #if DEBUG_ACTIVE_SPANS
- if (!simple->isClosed()) {
- DebugShowActiveSpans(contourList);
- }
- #endif
+ SkASSERT(simple->isClosed());
}
break;
}
#if DEBUG_FLOW
SkDebugf("%s current id=%d from=(%1.9g,%1.9g) to=(%1.9g,%1.9g)\n", __FUNCTION__,
- current->debugID(), start->pt().fX, start->pt().fY,
- end->pt().fX, end->pt().fY);
+ current->debugID(), current->xyAtT(start).fX, current->xyAtT(start).fY,
+ current->xyAtT(end).fX, current->xyAtT(end).fY);
#endif
current->addCurveTo(start, end, simple, true);
current = next;
start = nextStart;
end = nextEnd;
- } while (!simple->isClosed() && (!unsortable || !start->starter(end)->done()));
+ } while (!simple->isClosed() && (!unsortable || !current->done(SkMin32(start, end))));
if (!simple->isClosed()) {
SkASSERT(unsortable);
- SkOpSpan* spanStart = start->starter(end);
- if (!spanStart->done()) {
+ int min = SkMin32(start, end);
+ if (!current->done(min)) {
current->addCurveTo(start, end, simple, true);
- current->markDone(spanStart);
+ current->markDone(min, 1);
}
closable = false;
}
@@ -177,68 +156,52 @@
// FIXME : add this as a member of SkPath
bool Simplify(const SkPath& path, SkPath* result) {
+#if DEBUG_SORT || DEBUG_SWAP_TOP
+ SkPathOpsDebug::gSortCount = SkPathOpsDebug::gSortCountDefault;
+#endif
// returns 1 for evenodd, -1 for winding, regardless of inverse-ness
SkPath::FillType fillType = path.isInverseFillType() ? SkPath::kInverseEvenOdd_FillType
: SkPath::kEvenOdd_FillType;
- if (path.isConvex()) {
- if (result != &path) {
- *result = path;
- }
- result->setFillType(fillType);
- return true;
- }
+
// turn path into list of segments
- SkOpCoincidence coincidence;
- SkOpContour contour;
- SkOpGlobalState globalState(&coincidence PATH_OPS_DEBUG_PARAMS(&contour));
-#if DEBUG_SORT || DEBUG_SWAP_TOP
- SkPathOpsDebug::gSortCount = SkPathOpsDebug::gSortCountDefault;
-#endif
- SkChunkAlloc allocator(4096); // FIXME: constant-ize, tune
- SkOpEdgeBuilder builder(path, &contour, &allocator, &globalState);
- if (!builder.finish(&allocator)) {
+ SkTArray<SkOpContour> contours;
+ SkOpEdgeBuilder builder(path, contours);
+ if (!builder.finish()) {
return false;
}
-#if !FORCE_RELEASE
- contour.dumpSegments((SkPathOp) -1);
-#endif
+ SkTArray<SkOpContour*, true> contourList;
+ MakeContourList(contours, contourList, false, false);
+ SkOpContour** currentPtr = contourList.begin();
result->reset();
result->setFillType(fillType);
- SkTDArray<SkOpContour* > contourList;
- MakeContourList(&contour, contourList, false, false);
- SkOpContour** currentPtr = contourList.begin();
if (!currentPtr) {
return true;
}
- if ((*currentPtr)->count() == 0) {
- SkASSERT((*currentPtr)->next() == NULL);
- return true;
- }
- SkOpContour** listEnd2 = contourList.end();
+ SkOpContour** listEnd = contourList.end();
// find all intersections between segments
do {
SkOpContour** nextPtr = currentPtr;
SkOpContour* current = *currentPtr++;
+ if (current->containsCubics()) {
+ AddSelfIntersectTs(current);
+ }
SkOpContour* next;
do {
next = *nextPtr++;
- } while (AddIntersectTs(current, next, &coincidence, &allocator) && nextPtr != listEnd2);
- } while (currentPtr != listEnd2);
-#if DEBUG_VALIDATE
- globalState.setPhase(SkOpGlobalState::kWalking);
-#endif
- if (!HandleCoincidence(&contourList, &coincidence, &allocator, &globalState)) {
+ } while (AddIntersectTs(current, next) && nextPtr != listEnd);
+ } while (currentPtr != listEnd);
+ if (!HandleCoincidence(&contourList, 0)) {
return false;
}
// construct closed contours
- SkPathWriter wrapper(*result);
- if (builder.xorMask() == kWinding_PathOpsMask ? bridgeWinding(contourList, &wrapper, &allocator)
- : !bridgeXor(contourList, &wrapper, &allocator))
+ SkPathWriter simple(*result);
+ if (builder.xorMask() == kWinding_PathOpsMask ? bridgeWinding(contourList, &simple)
+ : !bridgeXor(contourList, &simple))
{ // if some edges could not be resolved, assemble remaining fragments
SkPath temp;
temp.setFillType(fillType);
SkPathWriter assembled(temp);
- Assemble(wrapper, &assembled);
+ Assemble(simple, &assembled);
*result = *assembled.nativePath();
result->setFillType(fillType);
}
« no previous file with comments | « src/pathops/SkPathOpsRect.cpp ('k') | src/pathops/SkPathOpsTCubicSect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698