| 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 "SkOpCoincidence.h" | 8 #include "SkOpCoincidence.h" |
| 9 #include "SkOpEdgeBuilder.h" | 9 #include "SkOpEdgeBuilder.h" |
| 10 #include "SkPathOpsCommon.h" | 10 #include "SkPathOpsCommon.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 fprintf(file, " testPathOp(reporter, path1, path2, (SkPathOp) %d, filenam
e);\n", op); | 257 fprintf(file, " testPathOp(reporter, path1, path2, (SkPathOp) %d, filenam
e);\n", op); |
| 258 fprintf(file, "}\n"); | 258 fprintf(file, "}\n"); |
| 259 fclose(file); | 259 fclose(file); |
| 260 } | 260 } |
| 261 #endif | 261 #endif |
| 262 | 262 |
| 263 bool Op(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result) { | 263 bool Op(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result) { |
| 264 SkChunkAlloc allocator(4096); // FIXME: add a constant expression here, tun
e | 264 SkChunkAlloc allocator(4096); // FIXME: add a constant expression here, tun
e |
| 265 SkOpContour contour; | 265 SkOpContour contour; |
| 266 SkOpCoincidence coincidence; | 266 SkOpCoincidence coincidence; |
| 267 SkOpGlobalState globalState(&coincidence PATH_OPS_DEBUG_PARAMS(&contour)); | 267 SkOpGlobalState globalState(&coincidence SkDEBUGPARAMS(&contour)); |
| 268 #if DEBUGGING_PATHOPS_FROM_HOST | 268 #if DEBUGGING_PATHOPS_FROM_HOST |
| 269 dump_op(one, two, op); | 269 dump_op(one, two, op); |
| 270 #endif | 270 #endif |
| 271 #if 0 && DEBUG_SHOW_TEST_NAME | 271 #if 0 && DEBUG_SHOW_TEST_NAME |
| 272 char* debugName = DEBUG_FILENAME_STRING; | 272 char* debugName = DEBUG_FILENAME_STRING; |
| 273 if (debugName && debugName[0]) { | 273 if (debugName && debugName[0]) { |
| 274 SkPathOpsDebug::BumpTestName(debugName); | 274 SkPathOpsDebug::BumpTestName(debugName); |
| 275 SkPathOpsDebug::ShowPath(one, two, op, debugName); | 275 SkPathOpsDebug::ShowPath(one, two, op, debugName); |
| 276 } | 276 } |
| 277 #endif | 277 #endif |
| (...skipping 17 matching lines...) Expand all Loading... |
| 295 } | 295 } |
| 296 const int xorMask = builder.xorMask(); | 296 const int xorMask = builder.xorMask(); |
| 297 builder.addOperand(*subtrahend); | 297 builder.addOperand(*subtrahend); |
| 298 if (!builder.finish(&allocator)) { | 298 if (!builder.finish(&allocator)) { |
| 299 return false; | 299 return false; |
| 300 } | 300 } |
| 301 #if !FORCE_RELEASE | 301 #if !FORCE_RELEASE |
| 302 contour.dumpSegments(op); | 302 contour.dumpSegments(op); |
| 303 #endif | 303 #endif |
| 304 | 304 |
| 305 result->reset(); | |
| 306 result->setFillType(fillType); | |
| 307 const int xorOpMask = builder.xorMask(); | 305 const int xorOpMask = builder.xorMask(); |
| 308 SkTDArray<SkOpContour* > contourList; | 306 SkTDArray<SkOpContour* > contourList; |
| 309 MakeContourList(&contour, contourList, xorMask == kEvenOdd_PathOpsMask, | 307 MakeContourList(&contour, contourList, xorMask == kEvenOdd_PathOpsMask, |
| 310 xorOpMask == kEvenOdd_PathOpsMask); | 308 xorOpMask == kEvenOdd_PathOpsMask); |
| 311 SkOpContour** currentPtr = contourList.begin(); | 309 SkOpContour** currentPtr = contourList.begin(); |
| 312 if (!currentPtr) { | 310 if (!currentPtr) { |
| 311 result->reset(); |
| 312 result->setFillType(fillType); |
| 313 return true; | 313 return true; |
| 314 } | 314 } |
| 315 if ((*currentPtr)->count() == 0) { | 315 if ((*currentPtr)->count() == 0) { |
| 316 SkASSERT((*currentPtr)->next() == NULL); | 316 SkASSERT((*currentPtr)->next() == NULL); |
| 317 result->reset(); |
| 318 result->setFillType(fillType); |
| 317 return true; | 319 return true; |
| 318 } | 320 } |
| 319 SkOpContour** listEnd = contourList.end(); | 321 SkOpContour** listEnd = contourList.end(); |
| 320 // find all intersections between segments | 322 // find all intersections between segments |
| 321 do { | 323 do { |
| 322 SkOpContour** nextPtr = currentPtr; | 324 SkOpContour** nextPtr = currentPtr; |
| 323 SkOpContour* current = *currentPtr++; | 325 SkOpContour* current = *currentPtr++; |
| 324 SkOpContour* next; | 326 SkOpContour* next; |
| 325 do { | 327 do { |
| 326 next = *nextPtr++; | 328 next = *nextPtr++; |
| 327 } while (AddIntersectTs(current, next, &coincidence, &allocator) && next
Ptr != listEnd); | 329 } while (AddIntersectTs(current, next, &coincidence, &allocator) && next
Ptr != listEnd); |
| 328 } while (currentPtr != listEnd); | 330 } while (currentPtr != listEnd); |
| 329 #if DEBUG_VALIDATE | 331 #if DEBUG_VALIDATE |
| 330 globalState.setPhase(SkOpGlobalState::kWalking); | 332 globalState.setPhase(SkOpGlobalState::kWalking); |
| 331 #endif | 333 #endif |
| 332 // eat through coincident edges | 334 // eat through coincident edges |
| 333 if (!HandleCoincidence(&contourList, &coincidence, &allocator, &globalState)
) { | 335 if (!HandleCoincidence(&contourList, &coincidence, &allocator, &globalState)
) { |
| 334 return false; | 336 return false; |
| 335 } | 337 } |
| 336 // construct closed contours | 338 // construct closed contours |
| 339 result->reset(); |
| 340 result->setFillType(fillType); |
| 337 SkPathWriter wrapper(*result); | 341 SkPathWriter wrapper(*result); |
| 338 bridgeOp(contourList, op, xorMask, xorOpMask, &wrapper, &allocator); | 342 bridgeOp(contourList, op, xorMask, xorOpMask, &wrapper, &allocator); |
| 339 { // if some edges could not be resolved, assemble remaining fragments | 343 { // if some edges could not be resolved, assemble remaining fragments |
| 340 SkPath temp; | 344 SkPath temp; |
| 341 temp.setFillType(fillType); | 345 temp.setFillType(fillType); |
| 342 SkPathWriter assembled(temp); | 346 SkPathWriter assembled(temp); |
| 343 Assemble(wrapper, &assembled); | 347 Assemble(wrapper, &assembled); |
| 344 *result = *assembled.nativePath(); | 348 *result = *assembled.nativePath(); |
| 345 result->setFillType(fillType); | 349 result->setFillType(fillType); |
| 346 } | 350 } |
| 347 return true; | 351 return true; |
| 348 } | 352 } |
| OLD | NEW |