Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: src/pathops/SkOpBuilder.cpp

Issue 1129193006: fix winding for path ops builder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix compile bug Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/pathops/SkOpContour.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 7
8 #include "SkMatrix.h" 8 #include "SkMatrix.h"
9 #include "SkOpEdgeBuilder.h"
9 #include "SkPath.h" 10 #include "SkPath.h"
10 #include "SkPathOps.h" 11 #include "SkPathOps.h"
12 #include "SkPathOpsCommon.h"
13
14 static bool one_contour(const SkPath& path) {
15 SkChunkAlloc allocator(256);
16 int verbCount = path.countVerbs();
17 uint8_t* verbs = (uint8_t*) allocator.alloc(sizeof(uint8_t) * verbCount,
18 SkChunkAlloc::kThrow_AllocFailType);
19 (void) path.getVerbs(verbs, verbCount);
20 for (int index = 1; index < verbCount; ++index) {
21 if (verbs[index] == SkPath::kMove_Verb) {
22 return false;
23 }
24 }
25 return true;
26 }
27
28 void FixWinding(SkPath* path) {
29 SkPath::FillType fillType = path->getFillType();
30 if (fillType == SkPath::kInverseEvenOdd_FillType) {
31 fillType = SkPath::kInverseWinding_FillType;
32 } else if (fillType == SkPath::kEvenOdd_FillType) {
33 fillType = SkPath::kWinding_FillType;
34 }
35 SkPath::Direction dir;
36 if (one_contour(*path) && path->cheapComputeDirection(&dir)) {
37 if (dir != SkPath::kCCW_Direction) {
38 SkPath temp;
39 temp.reverseAddPath(*path);
40 *path = temp;
41 }
42 path->setFillType(fillType);
43 return;
44 }
45 SkChunkAlloc allocator(4096);
46 SkOpContourHead contourHead;
47 SkOpGlobalState globalState(NULL, &contourHead);
48 SkOpEdgeBuilder builder(*path, &contourHead, &allocator, &globalState);
49 builder.finish(&allocator);
50 SkASSERT(contourHead.next());
51 contourHead.resetReverse();
52 bool writePath = false;
53 SkOpSpan* topSpan;
54 globalState.setPhase(SkOpGlobalState::kFixWinding);
55 while ((topSpan = FindSortableTop(&contourHead))) {
56 SkOpSegment* topSegment = topSpan->segment();
57 SkOpContour* topContour = topSegment->contour();
58 bool active = topSegment->activeWinding(topSpan, topSpan->next());
59 SkASSERT(topContour->isCcw() >= 0);
60 if (active != SkToBool(topContour->isCcw())) {
61 topContour->setReverse();
62 writePath = true;
63 }
64 topContour->markDone();
65 }
66 if (!writePath) {
67 path->setFillType(fillType);
68 return;
69 }
70 SkPath empty;
71 SkPathWriter woundPath(empty);
72 SkOpContour* test = &contourHead;
73 do {
74 if (test->reversed()) {
75 test->toReversePath(&woundPath);
76 } else {
77 test->toPath(&woundPath);
78 }
79 } while ((test = test->next()));
80 *path = *woundPath.nativePath();
81 path->setFillType(fillType);
82 }
11 83
12 void SkOpBuilder::add(const SkPath& path, SkPathOp op) { 84 void SkOpBuilder::add(const SkPath& path, SkPathOp op) {
13 if (0 == fOps.count() && op != kUnion_SkPathOp) { 85 if (0 == fOps.count() && op != kUnion_SkPathOp) {
14 fPathRefs.push_back() = SkPath(); 86 fPathRefs.push_back() = SkPath();
15 *fOps.append() = kUnion_SkPathOp; 87 *fOps.append() = kUnion_SkPathOp;
16 } 88 }
17 fPathRefs.push_back() = path; 89 fPathRefs.push_back() = path;
18 *fOps.append() = op; 90 *fOps.append() = op;
19 } 91 }
20 92
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 reset(); 147 reset();
76 return true; 148 return true;
77 } 149 }
78 SkPath sum; 150 SkPath sum;
79 for (int index = 0; index < count; ++index) { 151 for (int index = 0; index < count; ++index) {
80 if (!Simplify(fPathRefs[index], &fPathRefs[index])) { 152 if (!Simplify(fPathRefs[index], &fPathRefs[index])) {
81 reset(); 153 reset();
82 *result = original; 154 *result = original;
83 return false; 155 return false;
84 } 156 }
157 // convert the even odd result back to winding form before accumulating it
158 FixWinding(&fPathRefs[index]);
85 sum.addPath(fPathRefs[index]); 159 sum.addPath(fPathRefs[index]);
86 } 160 }
87 reset(); 161 reset();
88 sum.setFillType(SkPath::kEvenOdd_FillType);
89 bool success = Simplify(sum, result); 162 bool success = Simplify(sum, result);
90 if (!success) { 163 if (!success) {
91 *result = original; 164 *result = original;
92 } 165 }
93 return success; 166 return success;
94 } 167 }
OLDNEW
« no previous file with comments | « no previous file | src/pathops/SkOpContour.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698