OLD | NEW |
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 "SkOpEdgeBuilder.h" |
10 #include "SkPath.h" | 10 #include "SkPathPriv.h" |
11 #include "SkPathOps.h" | 11 #include "SkPathOps.h" |
12 #include "SkPathOpsCommon.h" | 12 #include "SkPathOpsCommon.h" |
13 | 13 |
14 static bool one_contour(const SkPath& path) { | 14 static bool one_contour(const SkPath& path) { |
15 SkChunkAlloc allocator(256); | 15 SkChunkAlloc allocator(256); |
16 int verbCount = path.countVerbs(); | 16 int verbCount = path.countVerbs(); |
17 uint8_t* verbs = (uint8_t*) allocator.alloc(sizeof(uint8_t) * verbCount, | 17 uint8_t* verbs = (uint8_t*) allocator.alloc(sizeof(uint8_t) * verbCount, |
18 SkChunkAlloc::kThrow_AllocFailType); | 18 SkChunkAlloc::kThrow_AllocFailType); |
19 (void) path.getVerbs(verbs, verbCount); | 19 (void) path.getVerbs(verbs, verbCount); |
20 for (int index = 1; index < verbCount; ++index) { | 20 for (int index = 1; index < verbCount; ++index) { |
21 if (verbs[index] == SkPath::kMove_Verb) { | 21 if (verbs[index] == SkPath::kMove_Verb) { |
22 return false; | 22 return false; |
23 } | 23 } |
24 } | 24 } |
25 return true; | 25 return true; |
26 } | 26 } |
27 | 27 |
28 void FixWinding(SkPath* path) { | 28 void FixWinding(SkPath* path) { |
29 SkPath::FillType fillType = path->getFillType(); | 29 SkPath::FillType fillType = path->getFillType(); |
30 if (fillType == SkPath::kInverseEvenOdd_FillType) { | 30 if (fillType == SkPath::kInverseEvenOdd_FillType) { |
31 fillType = SkPath::kInverseWinding_FillType; | 31 fillType = SkPath::kInverseWinding_FillType; |
32 } else if (fillType == SkPath::kEvenOdd_FillType) { | 32 } else if (fillType == SkPath::kEvenOdd_FillType) { |
33 fillType = SkPath::kWinding_FillType; | 33 fillType = SkPath::kWinding_FillType; |
34 } | 34 } |
35 SkPath::Direction dir; | 35 SkPathPriv::FirstDirection dir; |
36 if (one_contour(*path) && path->cheapComputeDirection(&dir)) { | 36 if (one_contour(*path) && SkPathPriv::CheapComputeFirstDirection(*path, &dir
)) { |
37 if (dir != SkPath::kCCW_Direction) { | 37 if (dir != SkPathPriv::kCCW_FirstDirection) { |
38 SkPath temp; | 38 SkPath temp; |
39 temp.reverseAddPath(*path); | 39 temp.reverseAddPath(*path); |
40 *path = temp; | 40 *path = temp; |
41 } | 41 } |
42 path->setFillType(fillType); | 42 path->setFillType(fillType); |
43 return; | 43 return; |
44 } | 44 } |
45 SkChunkAlloc allocator(4096); | 45 SkChunkAlloc allocator(4096); |
46 SkOpContourHead contourHead; | 46 SkOpContourHead contourHead; |
47 SkOpGlobalState globalState(NULL, &contourHead); | 47 SkOpGlobalState globalState(NULL, &contourHead); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 fOps.reset(); | 99 fOps.reset(); |
100 } | 100 } |
101 | 101 |
102 /* OPTIMIZATION: Union doesn't need to be all-or-nothing. A run of three or more
convex | 102 /* OPTIMIZATION: Union doesn't need to be all-or-nothing. A run of three or more
convex |
103 paths with union ops could be locally resolved and still improve over doing t
he | 103 paths with union ops could be locally resolved and still improve over doing t
he |
104 ops one at a time. */ | 104 ops one at a time. */ |
105 bool SkOpBuilder::resolve(SkPath* result) { | 105 bool SkOpBuilder::resolve(SkPath* result) { |
106 SkPath original = *result; | 106 SkPath original = *result; |
107 int count = fOps.count(); | 107 int count = fOps.count(); |
108 bool allUnion = true; | 108 bool allUnion = true; |
109 SkPath::Direction firstDir; | 109 SkPathPriv::FirstDirection firstDir; |
110 for (int index = 0; index < count; ++index) { | 110 for (int index = 0; index < count; ++index) { |
111 SkPath* test = &fPathRefs[index]; | 111 SkPath* test = &fPathRefs[index]; |
112 if (kUnion_SkPathOp != fOps[index] || test->isInverseFillType()) { | 112 if (kUnion_SkPathOp != fOps[index] || test->isInverseFillType()) { |
113 allUnion = false; | 113 allUnion = false; |
114 break; | 114 break; |
115 } | 115 } |
116 // If all paths are convex, track direction, reversing as needed. | 116 // If all paths are convex, track direction, reversing as needed. |
117 if (test->isConvex()) { | 117 if (test->isConvex()) { |
118 SkPath::Direction dir; | 118 SkPathPriv::FirstDirection dir; |
119 if (!test->cheapComputeDirection(&dir)) { | 119 if (!SkPathPriv::CheapComputeFirstDirection(*test, &dir)) { |
120 allUnion = false; | 120 allUnion = false; |
121 break; | 121 break; |
122 } | 122 } |
123 if (index == 0) { | 123 if (index == 0) { |
124 firstDir = dir; | 124 firstDir = dir; |
125 } else if (firstDir != dir) { | 125 } else if (firstDir != dir) { |
126 SkPath temp; | 126 SkPath temp; |
127 temp.reverseAddPath(*test); | 127 temp.reverseAddPath(*test); |
128 *test = temp; | 128 *test = temp; |
129 } | 129 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 FixWinding(&fPathRefs[index]); | 162 FixWinding(&fPathRefs[index]); |
163 sum.addPath(fPathRefs[index]); | 163 sum.addPath(fPathRefs[index]); |
164 } | 164 } |
165 reset(); | 165 reset(); |
166 bool success = Simplify(sum, result); | 166 bool success = Simplify(sum, result); |
167 if (!success) { | 167 if (!success) { |
168 *result = original; | 168 *result = original; |
169 } | 169 } |
170 return success; | 170 return success; |
171 } | 171 } |
OLD | NEW |