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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 }; | 219 }; |
220 | 220 |
221 static const bool gOutInverse[kReverseDifference_PathOp + 1][2][2] = { | 221 static const bool gOutInverse[kReverseDifference_PathOp + 1][2][2] = { |
222 {{ false, false }, { true, false }}, // diff | 222 {{ false, false }, { true, false }}, // diff |
223 {{ false, false }, { false, true }}, // sect | 223 {{ false, false }, { false, true }}, // sect |
224 {{ false, true }, { true, true }}, // union | 224 {{ false, true }, { true, true }}, // union |
225 {{ false, true }, { true, false }}, // xor | 225 {{ false, true }, { true, false }}, // xor |
226 {{ false, true }, { false, false }}, // rev diff | 226 {{ false, true }, { false, false }}, // rev diff |
227 }; | 227 }; |
228 | 228 |
229 void Op(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result) { | 229 bool Op(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result) { |
230 op = gOpInverse[op][one.isInverseFillType()][two.isInverseFillType()]; | 230 op = gOpInverse[op][one.isInverseFillType()][two.isInverseFillType()]; |
231 SkPath::FillType fillType = gOutInverse[op][one.isInverseFillType()][two.isI
nverseFillType()] | 231 SkPath::FillType fillType = gOutInverse[op][one.isInverseFillType()][two.isI
nverseFillType()] |
232 ? SkPath::kInverseEvenOdd_FillType : SkPath::kEvenOdd_FillType; | 232 ? SkPath::kInverseEvenOdd_FillType : SkPath::kEvenOdd_FillType; |
233 const SkPath* minuend = &one; | 233 const SkPath* minuend = &one; |
234 const SkPath* subtrahend = &two; | 234 const SkPath* subtrahend = &two; |
235 if (op == kReverseDifference_PathOp) { | 235 if (op == kReverseDifference_PathOp) { |
236 minuend = &two; | 236 minuend = &two; |
237 subtrahend = &one; | 237 subtrahend = &one; |
238 op = kDifference_PathOp; | 238 op = kDifference_PathOp; |
239 } | 239 } |
240 #if DEBUG_SORT || DEBUG_SWAP_TOP | 240 #if DEBUG_SORT || DEBUG_SWAP_TOP |
241 gDebugSortCount = gDebugSortCountDefault; | 241 gDebugSortCount = gDebugSortCountDefault; |
242 #endif | 242 #endif |
243 // turn path into list of segments | 243 // turn path into list of segments |
244 SkTArray<SkOpContour> contours; | 244 SkTArray<SkOpContour> contours; |
245 // FIXME: add self-intersecting cubics' T values to segment | 245 // FIXME: add self-intersecting cubics' T values to segment |
246 SkOpEdgeBuilder builder(*minuend, contours); | 246 SkOpEdgeBuilder builder(*minuend, contours); |
247 const int xorMask = builder.xorMask(); | 247 const int xorMask = builder.xorMask(); |
248 builder.addOperand(*subtrahend); | 248 builder.addOperand(*subtrahend); |
249 builder.finish(); | 249 if (!builder.finish()) { |
| 250 return false; |
| 251 } |
250 result->reset(); | 252 result->reset(); |
251 result->setFillType(fillType); | 253 result->setFillType(fillType); |
252 const int xorOpMask = builder.xorMask(); | 254 const int xorOpMask = builder.xorMask(); |
253 SkTDArray<SkOpContour*> contourList; | 255 SkTDArray<SkOpContour*> contourList; |
254 MakeContourList(contours, contourList, xorMask == kEvenOdd_PathOpsMask, | 256 MakeContourList(contours, contourList, xorMask == kEvenOdd_PathOpsMask, |
255 xorOpMask == kEvenOdd_PathOpsMask); | 257 xorOpMask == kEvenOdd_PathOpsMask); |
256 SkOpContour** currentPtr = contourList.begin(); | 258 SkOpContour** currentPtr = contourList.begin(); |
257 if (!currentPtr) { | 259 if (!currentPtr) { |
258 return; | 260 return true; |
259 } | 261 } |
260 SkOpContour** listEnd = contourList.end(); | 262 SkOpContour** listEnd = contourList.end(); |
261 // find all intersections between segments | 263 // find all intersections between segments |
262 do { | 264 do { |
263 SkOpContour** nextPtr = currentPtr; | 265 SkOpContour** nextPtr = currentPtr; |
264 SkOpContour* current = *currentPtr++; | 266 SkOpContour* current = *currentPtr++; |
265 if (current->containsCubics()) { | 267 if (current->containsCubics()) { |
266 AddSelfIntersectTs(current); | 268 AddSelfIntersectTs(current); |
267 } | 269 } |
268 SkOpContour* next; | 270 SkOpContour* next; |
(...skipping 22 matching lines...) Expand all Loading... |
291 #endif | 293 #endif |
292 // construct closed contours | 294 // construct closed contours |
293 SkPathWriter wrapper(*result); | 295 SkPathWriter wrapper(*result); |
294 bridgeOp(contourList, op, xorMask, xorOpMask, &wrapper); | 296 bridgeOp(contourList, op, xorMask, xorOpMask, &wrapper); |
295 { // if some edges could not be resolved, assemble remaining fragments | 297 { // if some edges could not be resolved, assemble remaining fragments |
296 SkPath temp; | 298 SkPath temp; |
297 temp.setFillType(fillType); | 299 temp.setFillType(fillType); |
298 SkPathWriter assembled(temp); | 300 SkPathWriter assembled(temp); |
299 Assemble(wrapper, &assembled); | 301 Assemble(wrapper, &assembled); |
300 *result = *assembled.nativePath(); | 302 *result = *assembled.nativePath(); |
| 303 result->setFillType(fillType); |
301 } | 304 } |
| 305 return true; |
302 } | 306 } |
OLD | NEW |