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 "SkPath.h" | 9 #include "SkPath.h" |
10 #include "SkPathOps.h" | 10 #include "SkPathOps.h" |
11 | 11 |
12 void SkOpBuilder::add(const SkPath& path, SkPathOp op) { | 12 void SkOpBuilder::add(const SkPath& path, SkPathOp op) { |
13 if (0 == fOps.count() && op != kUnion_PathOp) { | 13 if (0 == fOps.count() && op != kUnion_SkPathOp) { |
14 fPathRefs.push_back() = SkPath(); | 14 fPathRefs.push_back() = SkPath(); |
15 *fOps.append() = kUnion_PathOp; | 15 *fOps.append() = kUnion_SkPathOp; |
16 } | 16 } |
17 fPathRefs.push_back() = path; | 17 fPathRefs.push_back() = path; |
18 *fOps.append() = op; | 18 *fOps.append() = op; |
19 } | 19 } |
20 | 20 |
21 void SkOpBuilder::reset() { | 21 void SkOpBuilder::reset() { |
22 fPathRefs.reset(); | 22 fPathRefs.reset(); |
23 fOps.reset(); | 23 fOps.reset(); |
24 } | 24 } |
25 | 25 |
26 /* OPTIMIZATION: Union doesn't need to be all-or-nothing. A run of three or more
convex | 26 /* OPTIMIZATION: Union doesn't need to be all-or-nothing. A run of three or more
convex |
27 paths with union ops could be locally resolved and still improve over doing t
he | 27 paths with union ops could be locally resolved and still improve over doing t
he |
28 ops one at a time. */ | 28 ops one at a time. */ |
29 bool SkOpBuilder::resolve(SkPath* result) { | 29 bool SkOpBuilder::resolve(SkPath* result) { |
30 int count = fOps.count(); | 30 int count = fOps.count(); |
31 bool allUnion = true; | 31 bool allUnion = true; |
32 SkPath::Direction firstDir; | 32 SkPath::Direction firstDir; |
33 for (int index = 0; index < count; ++index) { | 33 for (int index = 0; index < count; ++index) { |
34 SkPath* test = &fPathRefs[index]; | 34 SkPath* test = &fPathRefs[index]; |
35 if (kUnion_PathOp != fOps[index] || test->isInverseFillType()) { | 35 if (kUnion_SkPathOp != fOps[index] || test->isInverseFillType()) { |
36 allUnion = false; | 36 allUnion = false; |
37 break; | 37 break; |
38 } | 38 } |
39 // If all paths are convex, track direction, reversing as needed. | 39 // If all paths are convex, track direction, reversing as needed. |
40 if (test->isConvex()) { | 40 if (test->isConvex()) { |
41 SkPath::Direction dir; | 41 SkPath::Direction dir; |
42 if (!test->cheapComputeDirection(&dir)) { | 42 if (!test->cheapComputeDirection(&dir)) { |
43 allUnion = false; | 43 allUnion = false; |
44 break; | 44 break; |
45 } | 45 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 for (int index = 0; index < count; ++index) { | 77 for (int index = 0; index < count; ++index) { |
78 if (!Simplify(fPathRefs[index], &fPathRefs[index])) { | 78 if (!Simplify(fPathRefs[index], &fPathRefs[index])) { |
79 reset(); | 79 reset(); |
80 return false; | 80 return false; |
81 } | 81 } |
82 sum.addPath(fPathRefs[index]); | 82 sum.addPath(fPathRefs[index]); |
83 } | 83 } |
84 reset(); | 84 reset(); |
85 return Simplify(sum, result); | 85 return Simplify(sum, result); |
86 } | 86 } |
OLD | NEW |