| 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 bool firstPass = true; | 16 bool firstPass = true; |
| 17 SkPoint lastTopLeft; | 17 SkPoint lastTopLeft; |
| 18 SkPoint topLeft = {SK_ScalarMin, SK_ScalarMin}; | 18 SkPoint topLeft = {SK_ScalarMin, SK_ScalarMin}; |
| 19 do { | 19 do { |
| 20 int index, endIndex; | 20 int index, endIndex; |
| 21 bool topDone; | 21 bool topDone; |
| 22 bool onlyVertical = false; |
| 22 lastTopLeft = topLeft; | 23 lastTopLeft = topLeft; |
| 23 SkOpSegment* current = FindSortableTop(contourList, SkOpAngle::kUnaryWin
ding, &firstContour, | 24 SkOpSegment* current = FindSortableTop(contourList, SkOpAngle::kUnaryWin
ding, &firstContour, |
| 24 &index, &endIndex, &topLeft, &topUnsortable, &topDone, firstPass
); | 25 &index, &endIndex, &topLeft, &topUnsortable, &topDone, &onlyVert
ical, firstPass); |
| 25 if (!current) { | 26 if (!current) { |
| 26 if ((!topUnsortable || firstPass) && !topDone) { | 27 if ((!topUnsortable || firstPass) && !topDone) { |
| 27 SkASSERT(topLeft.fX != SK_ScalarMin && topLeft.fY != SK_ScalarMi
n); | 28 SkASSERT(topLeft.fX != SK_ScalarMin && topLeft.fY != SK_ScalarMi
n); |
| 28 topLeft.fX = topLeft.fY = SK_ScalarMin; | 29 topLeft.fX = topLeft.fY = SK_ScalarMin; |
| 29 continue; | 30 continue; |
| 30 } | 31 } |
| 31 break; | 32 break; |
| 33 } else if (onlyVertical) { |
| 34 break; |
| 32 } | 35 } |
| 33 firstPass = !topUnsortable || lastTopLeft != topLeft; | 36 firstPass = !topUnsortable || lastTopLeft != topLeft; |
| 34 SkTDArray<SkOpSpan*> chaseArray; | 37 SkTDArray<SkOpSpan*> chase; |
| 35 do { | 38 do { |
| 36 if (current->activeWinding(index, endIndex)) { | 39 if (current->activeWinding(index, endIndex)) { |
| 37 do { | 40 do { |
| 38 if (!unsortable && current->done()) { | 41 if (!unsortable && current->done()) { |
| 39 if (simple->isEmpty()) { | 42 break; |
| 40 simple->init(); | |
| 41 break; | |
| 42 } | |
| 43 } | 43 } |
| 44 SkASSERT(unsortable || !current->done()); | 44 SkASSERT(unsortable || !current->done()); |
| 45 int nextStart = index; | 45 int nextStart = index; |
| 46 int nextEnd = endIndex; | 46 int nextEnd = endIndex; |
| 47 SkOpSegment* next = current->findNextWinding(&chaseArray, &n
extStart, &nextEnd, | 47 SkOpSegment* next = current->findNextWinding(&chase, &nextSt
art, &nextEnd, |
| 48 &unsortable); | 48 &unsortable); |
| 49 if (!next) { | 49 if (!next) { |
| 50 if (!unsortable && simple->hasMove() | 50 if (!unsortable && simple->hasMove() |
| 51 && current->verb() != SkPath::kLine_Verb | 51 && current->verb() != SkPath::kLine_Verb |
| 52 && !simple->isClosed()) { | 52 && !simple->isClosed()) { |
| 53 current->addCurveTo(index, endIndex, simple, true); | 53 current->addCurveTo(index, endIndex, simple, true); |
| 54 SkASSERT(simple->isClosed()); | 54 SkASSERT(simple->isClosed()); |
| 55 } | 55 } |
| 56 break; | 56 break; |
| 57 } | 57 } |
| 58 #if DEBUG_FLOW | 58 #if DEBUG_FLOW |
| 59 SkDebugf("%s current id=%d from=(%1.9g,%1.9g) to=(%1.9g,%1.9g)\n", _
_FUNCTION__, | 59 SkDebugf("%s current id=%d from=(%1.9g,%1.9g) to=(%1.9g,%1.9g)\n", _
_FUNCTION__, |
| 60 current->debugID(), current->xyAtT(index).fX, current->xyAtT
(index).fY, | 60 current->debugID(), current->xyAtT(index).fX, current->xyAtT
(index).fY, |
| 61 current->xyAtT(endIndex).fX, current->xyAtT(endIndex).fY); | 61 current->xyAtT(endIndex).fX, current->xyAtT(endIndex).fY); |
| 62 #endif | 62 #endif |
| 63 current->addCurveTo(index, endIndex, simple, true); | 63 current->addCurveTo(index, endIndex, simple, true); |
| 64 current = next; | 64 current = next; |
| 65 index = nextStart; | 65 index = nextStart; |
| 66 endIndex = nextEnd; | 66 endIndex = nextEnd; |
| 67 } while (!simple->isClosed() && (!unsortable | 67 } while (!simple->isClosed() && (!unsortable |
| 68 || !current->done(SkMin32(index, endIndex)))); | 68 || !current->done(SkMin32(index, endIndex)))); |
| 69 if (current->activeWinding(index, endIndex) && !simple->isClosed
()) { | 69 if (current->activeWinding(index, endIndex) && !simple->isClosed
()) { |
| 70 SkASSERT(unsortable || simple->isEmpty()); | 70 // SkASSERT(unsortable || simple->isEmpty()); |
| 71 int min = SkMin32(index, endIndex); | 71 int min = SkMin32(index, endIndex); |
| 72 if (!current->done(min)) { | 72 if (!current->done(min)) { |
| 73 current->addCurveTo(index, endIndex, simple, true); | 73 current->addCurveTo(index, endIndex, simple, true); |
| 74 current->markDoneUnary(min); | 74 current->markDoneUnary(min); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 simple->close(); | 77 simple->close(); |
| 78 } else { | 78 } else { |
| 79 SkOpSpan* last = current->markAndChaseDoneUnary(index, endIndex)
; | 79 SkOpSpan* last = current->markAndChaseDoneUnary(index, endIndex)
; |
| 80 if (last && !last->fChased && !last->fLoop) { | 80 if (last && !last->fChased && !last->fLoop) { |
| 81 last->fChased = true; | 81 last->fChased = true; |
| 82 SkASSERT(!SkPathOpsDebug::ChaseContains(chaseArray, last)); | 82 SkASSERT(!SkPathOpsDebug::ChaseContains(chase, last)); |
| 83 // assert that last isn't already in array | 83 // assert that last isn't already in array |
| 84 *chaseArray.append() = last; | 84 *chase.append() = last; |
| 85 #if DEBUG_WINDING |
| 86 SkDebugf("%s chase.append id=%d windSum=%d small=%d\n", __FU
NCTION__, |
| 87 last->fOther->span(last->fOtherIndex).fOther->debugI
D(), last->fWindSum, |
| 88 last->fSmall); |
| 89 #endif |
| 85 } | 90 } |
| 86 } | 91 } |
| 87 SkTDArray<SkOpSpan *>* chaseArrayPtr = &chaseArray; | 92 current = FindChase(&chase, &index, &endIndex); |
| 88 current = FindChase(chaseArrayPtr, &index, &endIndex); | |
| 89 #if DEBUG_ACTIVE_SPANS | 93 #if DEBUG_ACTIVE_SPANS |
| 90 DebugShowActiveSpans(contourList); | 94 DebugShowActiveSpans(contourList); |
| 91 #endif | 95 #endif |
| 92 if (!current) { | 96 if (!current) { |
| 93 break; | 97 break; |
| 94 } | 98 } |
| 95 } while (true); | 99 } while (true); |
| 96 } while (true); | 100 } while (true); |
| 97 return simple->someAssemblyRequired(); | 101 return simple->someAssemblyRequired(); |
| 98 } | 102 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 { // if some edges could not be resolved, assemble remaining fragments | 200 { // if some edges could not be resolved, assemble remaining fragments |
| 197 SkPath temp; | 201 SkPath temp; |
| 198 temp.setFillType(fillType); | 202 temp.setFillType(fillType); |
| 199 SkPathWriter assembled(temp); | 203 SkPathWriter assembled(temp); |
| 200 Assemble(simple, &assembled); | 204 Assemble(simple, &assembled); |
| 201 *result = *assembled.nativePath(); | 205 *result = *assembled.nativePath(); |
| 202 result->setFillType(fillType); | 206 result->setFillType(fillType); |
| 203 } | 207 } |
| 204 return true; | 208 return true; |
| 205 } | 209 } |
| OLD | NEW |