| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 SkASSERT(topLeft.fX != SK_ScalarMin && topLeft.fY != SK_ScalarMi
n); | 142 SkASSERT(topLeft.fX != SK_ScalarMin && topLeft.fY != SK_ScalarMi
n); |
| 143 topLeft.fX = topLeft.fY = SK_ScalarMin; | 143 topLeft.fX = topLeft.fY = SK_ScalarMin; |
| 144 continue; | 144 continue; |
| 145 } | 145 } |
| 146 break; | 146 break; |
| 147 } | 147 } |
| 148 SkTDArray<SkOpSpan*> chaseArray; | 148 SkTDArray<SkOpSpan*> chaseArray; |
| 149 do { | 149 do { |
| 150 if (current->activeOp(index, endIndex, xorMask, xorOpMask, op)) { | 150 if (current->activeOp(index, endIndex, xorMask, xorOpMask, op)) { |
| 151 do { | 151 do { |
| 152 if (!unsortable && current->done()) { |
| 152 #if DEBUG_ACTIVE_SPANS | 153 #if DEBUG_ACTIVE_SPANS |
| 153 if (!unsortable && current->done()) { | |
| 154 DebugShowActiveSpans(contourList); | 154 DebugShowActiveSpans(contourList); |
| 155 #endif |
| 156 if (simple->isEmpty()) { |
| 157 // SkDebugf("%s discard empty fragment\n", __FUNCTION
__); |
| 158 simple->init(); |
| 159 break; |
| 160 } |
| 155 } | 161 } |
| 156 #endif | |
| 157 SkASSERT(unsortable || !current->done()); | 162 SkASSERT(unsortable || !current->done()); |
| 158 int nextStart = index; | 163 int nextStart = index; |
| 159 int nextEnd = endIndex; | 164 int nextEnd = endIndex; |
| 160 SkOpSegment* next = current->findNextOp(&chaseArray, &nextSt
art, &nextEnd, | 165 SkOpSegment* next = current->findNextOp(&chaseArray, &nextSt
art, &nextEnd, |
| 161 &unsortable, op, xorMask, xorOpMask); | 166 &unsortable, op, xorMask, xorOpMask); |
| 162 if (!next) { | 167 if (!next) { |
| 163 if (!unsortable && simple->hasMove() | 168 if (!unsortable && simple->hasMove() |
| 164 && current->verb() != SkPath::kLine_Verb | 169 && current->verb() != SkPath::kLine_Verb |
| 165 && !simple->isClosed()) { | 170 && !simple->isClosed()) { |
| 166 current->addCurveTo(index, endIndex, simple, true); | 171 current->addCurveTo(index, endIndex, simple, true); |
| 167 SkASSERT(simple->isClosed()); | 172 SkASSERT(simple->isClosed()); |
| 168 } | 173 } |
| 169 break; | 174 break; |
| 170 } | 175 } |
| 171 #if DEBUG_FLOW | 176 #if DEBUG_FLOW |
| 172 SkDebugf("%s current id=%d from=(%1.9g,%1.9g) to=(%1.9g,%1.9g)\n", _
_FUNCTION__, | 177 SkDebugf("%s current id=%d from=(%1.9g,%1.9g) to=(%1.9g,%1.9g)\n", _
_FUNCTION__, |
| 173 current->debugID(), current->xyAtT(index).fX, current->xyAtT
(index).fY, | 178 current->debugID(), current->xyAtT(index).fX, current->xyAtT
(index).fY, |
| 174 current->xyAtT(endIndex).fX, current->xyAtT(endIndex).fY); | 179 current->xyAtT(endIndex).fX, current->xyAtT(endIndex).fY); |
| 175 #endif | 180 #endif |
| 176 current->addCurveTo(index, endIndex, simple, true); | 181 current->addCurveTo(index, endIndex, simple, true); |
| 177 current = next; | 182 current = next; |
| 178 index = nextStart; | 183 index = nextStart; |
| 179 endIndex = nextEnd; | 184 endIndex = nextEnd; |
| 180 } while (!simple->isClosed() && ((!unsortable) | 185 } while (!simple->isClosed() && (!unsortable |
| 181 || !current->done(SkMin32(index, endIndex)))); | 186 || !current->done(SkMin32(index, endIndex)))); |
| 182 if (current->activeWinding(index, endIndex) && !simple->isClosed
()) { | 187 if (current->activeWinding(index, endIndex) && !simple->isClosed
()) { |
| 183 SkASSERT(unsortable); | 188 SkASSERT(unsortable || simple->isEmpty()); |
| 184 int min = SkMin32(index, endIndex); | 189 int min = SkMin32(index, endIndex); |
| 185 if (!current->done(min)) { | 190 if (!current->done(min)) { |
| 186 current->addCurveTo(index, endIndex, simple, true); | 191 current->addCurveTo(index, endIndex, simple, true); |
| 187 current->markDoneBinary(min); | 192 current->markDoneBinary(min); |
| 188 } | 193 } |
| 189 } | 194 } |
| 190 simple->close(); | 195 simple->close(); |
| 191 } else { | 196 } else { |
| 192 SkOpSpan* last = current->markAndChaseDoneBinary(index, endIndex
); | 197 SkOpSpan* last = current->markAndChaseDoneBinary(index, endIndex
); |
| 193 if (last && !last->fLoop) { | 198 if (last && !last->fLoop) { |
| 194 *chaseArray.append() = last; | 199 *chaseArray.append() = last; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 220 | 225 |
| 221 static const bool gOutInverse[kReverseDifference_PathOp + 1][2][2] = { | 226 static const bool gOutInverse[kReverseDifference_PathOp + 1][2][2] = { |
| 222 {{ false, false }, { true, false }}, // diff | 227 {{ false, false }, { true, false }}, // diff |
| 223 {{ false, false }, { false, true }}, // sect | 228 {{ false, false }, { false, true }}, // sect |
| 224 {{ false, true }, { true, true }}, // union | 229 {{ false, true }, { true, true }}, // union |
| 225 {{ false, true }, { true, false }}, // xor | 230 {{ false, true }, { true, false }}, // xor |
| 226 {{ false, true }, { false, false }}, // rev diff | 231 {{ false, true }, { false, false }}, // rev diff |
| 227 }; | 232 }; |
| 228 | 233 |
| 229 bool Op(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result) { | 234 bool Op(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result) { |
| 235 #if DEBUG_SHOW_PATH |
| 236 ShowPath(one, "path"); |
| 237 ShowPath(two, "pathB"); |
| 238 ShowOp(op, "path", "pathB"); |
| 239 #endif |
| 230 op = gOpInverse[op][one.isInverseFillType()][two.isInverseFillType()]; | 240 op = gOpInverse[op][one.isInverseFillType()][two.isInverseFillType()]; |
| 231 SkPath::FillType fillType = gOutInverse[op][one.isInverseFillType()][two.isI
nverseFillType()] | 241 SkPath::FillType fillType = gOutInverse[op][one.isInverseFillType()][two.isI
nverseFillType()] |
| 232 ? SkPath::kInverseEvenOdd_FillType : SkPath::kEvenOdd_FillType; | 242 ? SkPath::kInverseEvenOdd_FillType : SkPath::kEvenOdd_FillType; |
| 233 const SkPath* minuend = &one; | 243 const SkPath* minuend = &one; |
| 234 const SkPath* subtrahend = &two; | 244 const SkPath* subtrahend = &two; |
| 235 if (op == kReverseDifference_PathOp) { | 245 if (op == kReverseDifference_PathOp) { |
| 236 minuend = &two; | 246 minuend = &two; |
| 237 subtrahend = &one; | 247 subtrahend = &one; |
| 238 op = kDifference_PathOp; | 248 op = kDifference_PathOp; |
| 239 } | 249 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 } | 291 } |
| 282 #if DEBUG_SHOW_WINDING | 292 #if DEBUG_SHOW_WINDING |
| 283 SkOpContour::debugShowWindingValues(contourList); | 293 SkOpContour::debugShowWindingValues(contourList); |
| 284 #endif | 294 #endif |
| 285 CoincidenceCheck(&contourList, total); | 295 CoincidenceCheck(&contourList, total); |
| 286 #if DEBUG_SHOW_WINDING | 296 #if DEBUG_SHOW_WINDING |
| 287 SkOpContour::debugShowWindingValues(contourList); | 297 SkOpContour::debugShowWindingValues(contourList); |
| 288 #endif | 298 #endif |
| 289 FixOtherTIndex(&contourList); | 299 FixOtherTIndex(&contourList); |
| 290 SortSegments(&contourList); | 300 SortSegments(&contourList); |
| 291 #if DEBUG_ACTIVE_SPANS | 301 #if DEBUG_ACTIVE_SPANS || DEBUG_ACTIVE_SPANS_FIRST_ONLY |
| 292 DebugShowActiveSpans(contourList); | 302 DebugShowActiveSpans(contourList); |
| 293 #endif | 303 #endif |
| 294 // construct closed contours | 304 // construct closed contours |
| 295 SkPathWriter wrapper(*result); | 305 SkPathWriter wrapper(*result); |
| 296 bridgeOp(contourList, op, xorMask, xorOpMask, &wrapper); | 306 bridgeOp(contourList, op, xorMask, xorOpMask, &wrapper); |
| 297 { // if some edges could not be resolved, assemble remaining fragments | 307 { // if some edges could not be resolved, assemble remaining fragments |
| 298 SkPath temp; | 308 SkPath temp; |
| 299 temp.setFillType(fillType); | 309 temp.setFillType(fillType); |
| 300 SkPathWriter assembled(temp); | 310 SkPathWriter assembled(temp); |
| 301 Assemble(wrapper, &assembled); | 311 Assemble(wrapper, &assembled); |
| 302 *result = *assembled.nativePath(); | 312 *result = *assembled.nativePath(); |
| 303 result->setFillType(fillType); | 313 result->setFillType(fillType); |
| 304 } | 314 } |
| 305 return true; | 315 return true; |
| 306 } | 316 } |
| OLD | NEW |