| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #include "SkAddIntersections.h" | 7 #include "SkAddIntersections.h" |
| 8 #include "SkOpEdgeBuilder.h" | 8 #include "SkOpEdgeBuilder.h" |
| 9 #include "SkPathOpsCommon.h" | 9 #include "SkPathOpsCommon.h" |
| 10 #include "SkPathWriter.h" | 10 #include "SkPathWriter.h" |
| 11 | 11 |
| 12 static bool bridgeWinding(SkTArray<SkOpContour*, true>& contourList, SkPathWrite
r* simple) { | 12 static bool bridgeWinding(SkTArray<SkOpContour*, true>& contourList, SkPathWrite
r* simple) { |
| 13 bool firstContour = true; | 13 bool firstContour = true; |
| 14 bool unsortable = false; | 14 bool unsortable = false; |
| 15 bool topUnsortable = false; | 15 bool topUnsortable = false; |
| 16 SkPoint topLeft = {SK_ScalarMin, SK_ScalarMin}; | 16 SkPoint topLeft = {SK_ScalarMin, SK_ScalarMin}; |
| 17 do { | 17 do { |
| 18 int index, endIndex; | 18 int index, endIndex; |
| 19 bool topDone; | 19 bool topDone; |
| 20 SkOpSegment* current = FindSortableTop(contourList, &firstContour, &inde
x, &endIndex, | 20 SkOpSegment* current = FindSortableTop(contourList, SkOpAngle::kUnaryWin
ding, &firstContour, |
| 21 &topLeft, &topUnsortable, &topDone, false); | 21 &index, &endIndex, &topLeft, &topUnsortable, &topDone); |
| 22 if (!current) { | 22 if (!current) { |
| 23 if (topUnsortable || !topDone) { | 23 if (topUnsortable || !topDone) { |
| 24 topUnsortable = false; | 24 topUnsortable = false; |
| 25 SkASSERT(topLeft.fX != SK_ScalarMin && topLeft.fY != SK_ScalarMi
n); | 25 SkASSERT(topLeft.fX != SK_ScalarMin && topLeft.fY != SK_ScalarMi
n); |
| 26 topLeft.fX = topLeft.fY = SK_ScalarMin; | 26 topLeft.fX = topLeft.fY = SK_ScalarMin; |
| 27 continue; | 27 continue; |
| 28 } | 28 } |
| 29 break; | 29 break; |
| 30 } | 30 } |
| 31 SkTDArray<SkOpSpan*> chaseArray; | 31 SkTDArray<SkOpSpan*> chaseArray; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 #if DEBUG_ACTIVE_SPANS | 142 #if DEBUG_ACTIVE_SPANS |
| 143 DebugShowActiveSpans(contourList); | 143 DebugShowActiveSpans(contourList); |
| 144 #endif | 144 #endif |
| 145 } | 145 } |
| 146 return closable; | 146 return closable; |
| 147 } | 147 } |
| 148 | 148 |
| 149 // FIXME : add this as a member of SkPath | 149 // FIXME : add this as a member of SkPath |
| 150 bool Simplify(const SkPath& path, SkPath* result) { | 150 bool Simplify(const SkPath& path, SkPath* result) { |
| 151 #if DEBUG_SORT || DEBUG_SWAP_TOP | 151 #if DEBUG_SORT || DEBUG_SWAP_TOP |
| 152 gDebugSortCount = gDebugSortCountDefault; | 152 SkPathOpsDebug::gSortCount = SkPathOpsDebug::gSortCountDefault; |
| 153 #endif | 153 #endif |
| 154 // returns 1 for evenodd, -1 for winding, regardless of inverse-ness | 154 // returns 1 for evenodd, -1 for winding, regardless of inverse-ness |
| 155 SkPath::FillType fillType = path.isInverseFillType() ? SkPath::kInverseEvenO
dd_FillType | 155 SkPath::FillType fillType = path.isInverseFillType() ? SkPath::kInverseEvenO
dd_FillType |
| 156 : SkPath::kEvenOdd_FillType; | 156 : SkPath::kEvenOdd_FillType; |
| 157 | 157 |
| 158 // turn path into list of segments | 158 // turn path into list of segments |
| 159 SkTArray<SkOpContour> contours; | 159 SkTArray<SkOpContour> contours; |
| 160 SkOpEdgeBuilder builder(path, contours); | 160 SkOpEdgeBuilder builder(path, contours); |
| 161 if (!builder.finish()) { | 161 if (!builder.finish()) { |
| 162 return false; | 162 return false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 179 } | 179 } |
| 180 SkOpContour* next; | 180 SkOpContour* next; |
| 181 do { | 181 do { |
| 182 next = *nextPtr++; | 182 next = *nextPtr++; |
| 183 } while (AddIntersectTs(current, next) && nextPtr != listEnd); | 183 } while (AddIntersectTs(current, next) && nextPtr != listEnd); |
| 184 } while (currentPtr != listEnd); | 184 } while (currentPtr != listEnd); |
| 185 // eat through coincident edges | 185 // eat through coincident edges |
| 186 CoincidenceCheck(&contourList, 0); | 186 CoincidenceCheck(&contourList, 0); |
| 187 FixOtherTIndex(&contourList); | 187 FixOtherTIndex(&contourList); |
| 188 CheckEnds(&contourList); | 188 CheckEnds(&contourList); |
| 189 CheckTiny(&contourList); |
| 189 SortSegments(&contourList); | 190 SortSegments(&contourList); |
| 190 #if DEBUG_ACTIVE_SPANS || DEBUG_ACTIVE_SPANS_FIRST_ONLY | 191 #if DEBUG_ACTIVE_SPANS || DEBUG_ACTIVE_SPANS_FIRST_ONLY |
| 191 DebugShowActiveSpans(contourList); | 192 DebugShowActiveSpans(contourList); |
| 192 #endif | 193 #endif |
| 193 // construct closed contours | 194 // construct closed contours |
| 194 SkPathWriter simple(*result); | 195 SkPathWriter simple(*result); |
| 195 if (builder.xorMask() == kWinding_PathOpsMask ? bridgeWinding(contourList, &
simple) | 196 if (builder.xorMask() == kWinding_PathOpsMask ? bridgeWinding(contourList, &
simple) |
| 196 : !bridgeXor(contourList, &simple)) | 197 : !bridgeXor(contourList, &simple)) |
| 197 { // if some edges could not be resolved, assemble remaining fragments | 198 { // if some edges could not be resolved, assemble remaining fragments |
| 198 SkPath temp; | 199 SkPath temp; |
| 199 temp.setFillType(fillType); | 200 temp.setFillType(fillType); |
| 200 SkPathWriter assembled(temp); | 201 SkPathWriter assembled(temp); |
| 201 Assemble(simple, &assembled); | 202 Assemble(simple, &assembled); |
| 202 *result = *assembled.nativePath(); | 203 *result = *assembled.nativePath(); |
| 203 result->setFillType(fillType); | 204 result->setFillType(fillType); |
| 204 } | 205 } |
| 205 return true; | 206 return true; |
| 206 } | 207 } |
| OLD | NEW |