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

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

Issue 1037953004: add conics to path ops (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix linux build Created 5 years, 8 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
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 "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_SkPathOp) { 13 if (0 == fOps.count() && op != kUnion_SkPathOp) {
14 fPathRefs.push_back() = SkPath(); 14 fPathRefs.push_back() = SkPath();
15 *fOps.append() = kUnion_SkPathOp; 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 SkPath original = *result;
30 int count = fOps.count(); 31 int count = fOps.count();
31 bool allUnion = true; 32 bool allUnion = true;
32 SkPath::Direction firstDir; 33 SkPath::Direction firstDir;
33 for (int index = 0; index < count; ++index) { 34 for (int index = 0; index < count; ++index) {
34 SkPath* test = &fPathRefs[index]; 35 SkPath* test = &fPathRefs[index];
35 if (kUnion_SkPathOp != fOps[index] || test->isInverseFillType()) { 36 if (kUnion_SkPathOp != fOps[index] || test->isInverseFillType()) {
36 allUnion = false; 37 allUnion = false;
37 break; 38 break;
38 } 39 }
39 // If all paths are convex, track direction, reversing as needed. 40 // If all paths are convex, track direction, reversing as needed.
(...skipping 20 matching lines...) Expand all
60 allUnion = false; 61 allUnion = false;
61 break; 62 break;
62 } 63 }
63 } 64 }
64 } 65 }
65 if (!allUnion) { 66 if (!allUnion) {
66 *result = fPathRefs[0]; 67 *result = fPathRefs[0];
67 for (int index = 1; index < count; ++index) { 68 for (int index = 1; index < count; ++index) {
68 if (!Op(*result, fPathRefs[index], fOps[index], result)) { 69 if (!Op(*result, fPathRefs[index], fOps[index], result)) {
69 reset(); 70 reset();
71 *result = original;
70 return false; 72 return false;
71 } 73 }
72 } 74 }
73 reset(); 75 reset();
74 return true; 76 return true;
75 } 77 }
76 SkPath sum; 78 SkPath sum;
77 for (int index = 0; index < count; ++index) { 79 for (int index = 0; index < count; ++index) {
78 if (!Simplify(fPathRefs[index], &fPathRefs[index])) { 80 if (!Simplify(fPathRefs[index], &fPathRefs[index])) {
79 reset(); 81 reset();
82 *result = original;
80 return false; 83 return false;
81 } 84 }
82 sum.addPath(fPathRefs[index]); 85 sum.addPath(fPathRefs[index]);
83 } 86 }
84 reset(); 87 reset();
85 return Simplify(sum, result); 88 bool success = Simplify(sum, result);
89 if (!success) {
90 *result = original;
91 }
92 return success;
86 } 93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698