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" |
(...skipping 125 matching lines...) Loading... |
136 } | 136 } |
137 simple->close(); | 137 simple->close(); |
138 #if DEBUG_ACTIVE_SPANS | 138 #if DEBUG_ACTIVE_SPANS |
139 DebugShowActiveSpans(contourList); | 139 DebugShowActiveSpans(contourList); |
140 #endif | 140 #endif |
141 } | 141 } |
142 return closable; | 142 return closable; |
143 } | 143 } |
144 | 144 |
145 // FIXME : add this as a member of SkPath | 145 // FIXME : add this as a member of SkPath |
146 void Simplify(const SkPath& path, SkPath* result) { | 146 bool Simplify(const SkPath& path, SkPath* result) { |
147 #if DEBUG_SORT || DEBUG_SWAP_TOP | 147 #if DEBUG_SORT || DEBUG_SWAP_TOP |
148 gDebugSortCount = gDebugSortCountDefault; | 148 gDebugSortCount = gDebugSortCountDefault; |
149 #endif | 149 #endif |
150 // returns 1 for evenodd, -1 for winding, regardless of inverse-ness | 150 // returns 1 for evenodd, -1 for winding, regardless of inverse-ness |
151 result->reset(); | |
152 SkPath::FillType fillType = path.isInverseFillType() ? SkPath::kInverseEvenO
dd_FillType | 151 SkPath::FillType fillType = path.isInverseFillType() ? SkPath::kInverseEvenO
dd_FillType |
153 : SkPath::kEvenOdd_FillType; | 152 : SkPath::kEvenOdd_FillType; |
154 result->setFillType(fillType); | |
155 SkPathWriter simple(*result); | |
156 | 153 |
157 // turn path into list of segments | 154 // turn path into list of segments |
158 SkTArray<SkOpContour> contours; | 155 SkTArray<SkOpContour> contours; |
159 SkOpEdgeBuilder builder(path, contours); | 156 SkOpEdgeBuilder builder(path, contours); |
160 builder.finish(); | 157 if (!builder.finish()) { |
| 158 return false; |
| 159 } |
161 SkTDArray<SkOpContour*> contourList; | 160 SkTDArray<SkOpContour*> contourList; |
162 MakeContourList(contours, contourList, false, false); | 161 MakeContourList(contours, contourList, false, false); |
163 SkOpContour** currentPtr = contourList.begin(); | 162 SkOpContour** currentPtr = contourList.begin(); |
| 163 result->setFillType(fillType); |
| 164 result->reset(); |
164 if (!currentPtr) { | 165 if (!currentPtr) { |
165 return; | 166 return true; |
166 } | 167 } |
167 SkOpContour** listEnd = contourList.end(); | 168 SkOpContour** listEnd = contourList.end(); |
168 // find all intersections between segments | 169 // find all intersections between segments |
169 do { | 170 do { |
170 SkOpContour** nextPtr = currentPtr; | 171 SkOpContour** nextPtr = currentPtr; |
171 SkOpContour* current = *currentPtr++; | 172 SkOpContour* current = *currentPtr++; |
172 if (current->containsCubics()) { | 173 if (current->containsCubics()) { |
173 AddSelfIntersectTs(current); | 174 AddSelfIntersectTs(current); |
174 } | 175 } |
175 SkOpContour* next; | 176 SkOpContour* next; |
176 do { | 177 do { |
177 next = *nextPtr++; | 178 next = *nextPtr++; |
178 } while (AddIntersectTs(current, next) && nextPtr != listEnd); | 179 } while (AddIntersectTs(current, next) && nextPtr != listEnd); |
179 } while (currentPtr != listEnd); | 180 } while (currentPtr != listEnd); |
180 // eat through coincident edges | 181 // eat through coincident edges |
181 CoincidenceCheck(&contourList, 0); | 182 CoincidenceCheck(&contourList, 0); |
182 FixOtherTIndex(&contourList); | 183 FixOtherTIndex(&contourList); |
183 SortSegments(&contourList); | 184 SortSegments(&contourList); |
184 #if DEBUG_ACTIVE_SPANS | 185 #if DEBUG_ACTIVE_SPANS |
185 DebugShowActiveSpans(contourList); | 186 DebugShowActiveSpans(contourList); |
186 #endif | 187 #endif |
187 // construct closed contours | 188 // construct closed contours |
| 189 SkPathWriter simple(*result); |
188 if (builder.xorMask() == kWinding_PathOpsMask ? bridgeWinding(contourList, &
simple) | 190 if (builder.xorMask() == kWinding_PathOpsMask ? bridgeWinding(contourList, &
simple) |
189 : !bridgeXor(contourList, &simple)) | 191 : !bridgeXor(contourList, &simple)) |
190 { // if some edges could not be resolved, assemble remaining fragments | 192 { // if some edges could not be resolved, assemble remaining fragments |
191 SkPath temp; | 193 SkPath temp; |
192 temp.setFillType(fillType); | 194 temp.setFillType(fillType); |
193 SkPathWriter assembled(temp); | 195 SkPathWriter assembled(temp); |
194 Assemble(simple, &assembled); | 196 Assemble(simple, &assembled); |
195 *result = *assembled.nativePath(); | 197 *result = *assembled.nativePath(); |
| 198 result->setFillType(fillType); |
196 } | 199 } |
| 200 return true; |
197 } | 201 } |
OLD | NEW |