| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 DebugShowActiveSpans(contourList); | 199 DebugShowActiveSpans(contourList); |
| 200 #endif | 200 #endif |
| 201 if (!current) { | 201 if (!current) { |
| 202 break; | 202 break; |
| 203 } | 203 } |
| 204 } while (true); | 204 } while (true); |
| 205 } while (true); | 205 } while (true); |
| 206 return simple->someAssemblyRequired(); | 206 return simple->someAssemblyRequired(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 // pretty picture: |
| 210 // https://docs.google.com/a/google.com/drawings/d/1sPV8rPfpEFXymBp3iSbDRWAycp1b
-7vD9JP2V-kn9Ss/edit?usp=sharing |
| 211 static const SkPathOp gOpInverse[kReverseDifference_PathOp + 1][2][2] = { |
| 212 // inside minuend outside minuend |
| 213 // inside subtrahend outside subtrahend inside subtrahend outsi
de subtrahend |
| 214 {{ kDifference_PathOp, kIntersect_PathOp }, { kUnion_PathOp, kReverseDiff
erence_PathOp }}, |
| 215 {{ kIntersect_PathOp, kDifference_PathOp }, { kReverseDifference_PathOp,
kUnion_PathOp }}, |
| 216 {{ kUnion_PathOp, kReverseDifference_PathOp }, { kDifference_PathOp, kInt
ersect_PathOp }}, |
| 217 {{ kXOR_PathOp, kXOR_PathOp }, { kXOR_PathOp,
kXOR_PathOp }}, |
| 218 {{ kReverseDifference_PathOp, kUnion_PathOp }, { kIntersect_PathOp, kDiff
erence_PathOp }}, |
| 219 }; |
| 220 |
| 221 static const bool gOutInverse[kReverseDifference_PathOp + 1][2][2] = { |
| 222 {{ false, false }, { true, false }}, // diff |
| 223 {{ false, false }, { false, true }}, // sect |
| 224 {{ false, true }, { true, true }}, // union |
| 225 {{ false, true }, { true, false }}, // xor |
| 226 {{ false, true }, { false, false }}, // rev diff |
| 227 }; |
| 228 |
| 209 void Op(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result) { | 229 void Op(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result) { |
| 230 op = gOpInverse[op][one.isInverseFillType()][two.isInverseFillType()]; |
| 231 result->reset(); |
| 232 SkPath::FillType fillType = gOutInverse[op][one.isInverseFillType()][two.isI
nverseFillType()] |
| 233 ? SkPath::kInverseEvenOdd_FillType : SkPath::kEvenOdd_FillType; |
| 234 result->setFillType(fillType); |
| 235 const SkPath* minuend = &one; |
| 236 const SkPath* subtrahend = &two; |
| 237 if (op == kReverseDifference_PathOp) { |
| 238 minuend = &two; |
| 239 subtrahend = &one; |
| 240 op = kDifference_PathOp; |
| 241 } |
| 210 #if DEBUG_SORT || DEBUG_SWAP_TOP | 242 #if DEBUG_SORT || DEBUG_SWAP_TOP |
| 211 gDebugSortCount = gDebugSortCountDefault; | 243 gDebugSortCount = gDebugSortCountDefault; |
| 212 #endif | 244 #endif |
| 213 result->reset(); | |
| 214 result->setFillType(SkPath::kEvenOdd_FillType); | |
| 215 // turn path into list of segments | 245 // turn path into list of segments |
| 216 SkTArray<SkOpContour> contours; | 246 SkTArray<SkOpContour> contours; |
| 217 // FIXME: add self-intersecting cubics' T values to segment | 247 // FIXME: add self-intersecting cubics' T values to segment |
| 218 SkOpEdgeBuilder builder(one, contours); | 248 SkOpEdgeBuilder builder(*minuend, contours); |
| 219 const int xorMask = builder.xorMask(); | 249 const int xorMask = builder.xorMask(); |
| 220 builder.addOperand(two); | 250 builder.addOperand(*subtrahend); |
| 221 builder.finish(); | 251 builder.finish(); |
| 222 const int xorOpMask = builder.xorMask(); | 252 const int xorOpMask = builder.xorMask(); |
| 223 SkTDArray<SkOpContour*> contourList; | 253 SkTDArray<SkOpContour*> contourList; |
| 224 MakeContourList(contours, contourList, xorMask == kEvenOdd_PathOpsMask, | 254 MakeContourList(contours, contourList, xorMask == kEvenOdd_PathOpsMask, |
| 225 xorOpMask == kEvenOdd_PathOpsMask); | 255 xorOpMask == kEvenOdd_PathOpsMask); |
| 226 SkOpContour** currentPtr = contourList.begin(); | 256 SkOpContour** currentPtr = contourList.begin(); |
| 227 if (!currentPtr) { | 257 if (!currentPtr) { |
| 228 return; | 258 return; |
| 229 } | 259 } |
| 230 SkOpContour** listEnd = contourList.end(); | 260 SkOpContour** listEnd = contourList.end(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 257 FixOtherTIndex(&contourList); | 287 FixOtherTIndex(&contourList); |
| 258 SortSegments(&contourList); | 288 SortSegments(&contourList); |
| 259 #if DEBUG_ACTIVE_SPANS | 289 #if DEBUG_ACTIVE_SPANS |
| 260 DebugShowActiveSpans(contourList); | 290 DebugShowActiveSpans(contourList); |
| 261 #endif | 291 #endif |
| 262 // construct closed contours | 292 // construct closed contours |
| 263 SkPathWriter wrapper(*result); | 293 SkPathWriter wrapper(*result); |
| 264 bridgeOp(contourList, op, xorMask, xorOpMask, &wrapper); | 294 bridgeOp(contourList, op, xorMask, xorOpMask, &wrapper); |
| 265 { // if some edges could not be resolved, assemble remaining fragments | 295 { // if some edges could not be resolved, assemble remaining fragments |
| 266 SkPath temp; | 296 SkPath temp; |
| 267 temp.setFillType(SkPath::kEvenOdd_FillType); | 297 temp.setFillType(fillType); |
| 268 SkPathWriter assembled(temp); | 298 SkPathWriter assembled(temp); |
| 269 Assemble(wrapper, &assembled); | 299 Assemble(wrapper, &assembled); |
| 270 *result = *assembled.nativePath(); | 300 *result = *assembled.nativePath(); |
| 271 } | 301 } |
| 272 } | 302 } |
| OLD | NEW |