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 "SkOpEdgeBuilder.h" | 7 #include "SkOpEdgeBuilder.h" |
8 #include "SkReduceOrder.h" | 8 #include "SkReduceOrder.h" |
9 | 9 |
10 void SkOpEdgeBuilder::init() { | 10 void SkOpEdgeBuilder::init() { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 ++cIndex; | 46 ++cIndex; |
47 continue; | 47 continue; |
48 } | 48 } |
49 fCurrentContour = &fContours[cIndex]; | 49 fCurrentContour = &fContours[cIndex]; |
50 rIndex += fCurrentContour->updateSegment(offset - 1, | 50 rIndex += fCurrentContour->updateSegment(offset - 1, |
51 &fReducePts[rIndex]); | 51 &fReducePts[rIndex]); |
52 } | 52 } |
53 fExtra.reset(); // we're done with this | 53 fExtra.reset(); // we're done with this |
54 } | 54 } |
55 | 55 |
56 // FIXME:remove once we can access path pts directly | 56 // Note that copying the points here avoids copying the resulting path later. |
| 57 // To allow Op() to take one of the input paths as an output parameter, either t
he source data |
| 58 // must be copied (as implemented below) or the result must be copied. |
| 59 // OPTIMIZATION: This copies both sets of input points every time. If the input
data was read |
| 60 // directly, the output path would only need to be copied if it was also one of
the input paths. |
57 int SkOpEdgeBuilder::preFetch() { | 61 int SkOpEdgeBuilder::preFetch() { |
58 SkPath::RawIter iter(*fPath); // FIXME: access path directly when allowed | 62 SkPath::RawIter iter(*fPath); |
59 SkPoint pts[4]; | 63 SkPoint pts[4]; |
60 SkPath::Verb verb; | 64 SkPath::Verb verb; |
61 do { | 65 do { |
62 verb = iter.next(pts); | 66 verb = iter.next(pts); |
63 *fPathVerbs.append() = verb; | 67 *fPathVerbs.append() = verb; |
64 if (verb == SkPath::kMove_Verb) { | 68 if (verb == SkPath::kMove_Verb) { |
65 *fPathPts.append() = pts[0]; | 69 *fPathPts.append() = pts[0]; |
66 } else if (verb >= SkPath::kLine_Verb && verb <= SkPath::kCubic_Verb) { | 70 } else if (verb >= SkPath::kLine_Verb && verb <= SkPath::kCubic_Verb) { |
67 fPathPts.append(verb, &pts[1]); | 71 fPathPts.append(verb, &pts[1]); |
68 } | 72 } |
69 } while (verb != SkPath::kDone_Verb); | 73 } while (verb != SkPath::kDone_Verb); |
70 return fPathVerbs.count() - 1; | 74 return fPathVerbs.count() - 1; |
71 } | 75 } |
72 | 76 |
73 void SkOpEdgeBuilder::walk() { | 77 void SkOpEdgeBuilder::walk() { |
74 SkPath::Verb reducedVerb; | 78 SkPath::Verb reducedVerb; |
75 uint8_t* verbPtr = fPathVerbs.begin(); | 79 uint8_t* verbPtr = fPathVerbs.begin(); |
76 uint8_t* endOfFirstHalf = &verbPtr[fSecondHalf]; | 80 uint8_t* endOfFirstHalf = &verbPtr[fSecondHalf]; |
77 const SkPoint* pointsPtr = fPathPts.begin(); | 81 const SkPoint* pointsPtr = fPathPts.begin(); |
78 const SkPoint* finalCurveStart = NULL; | 82 const SkPoint* finalCurveStart = NULL; |
79 const SkPoint* finalCurveEnd = NULL; | 83 const SkPoint* finalCurveEnd = NULL; |
80 SkPath::Verb verb; | 84 SkPath::Verb verb; |
81 while ((verb = (SkPath::Verb) *verbPtr++) != SkPath::kDone_Verb) { | 85 while ((verb = (SkPath::Verb) *verbPtr) != SkPath::kDone_Verb) { |
| 86 if (verbPtr == endOfFirstHalf) { |
| 87 fOperand = true; |
| 88 } |
| 89 verbPtr++; |
82 switch (verb) { | 90 switch (verb) { |
83 case SkPath::kMove_Verb: | 91 case SkPath::kMove_Verb: |
84 complete(); | 92 complete(); |
85 if (!fCurrentContour) { | 93 if (!fCurrentContour) { |
86 fCurrentContour = fContours.push_back_n(1); | 94 fCurrentContour = fContours.push_back_n(1); |
87 fCurrentContour->setOperand(fOperand); | 95 fCurrentContour->setOperand(fOperand); |
88 fCurrentContour->setXor(fXorMask[fOperand] == kEvenOdd_PathO
psMask); | 96 fCurrentContour->setXor(fXorMask[fOperand] == kEvenOdd_PathO
psMask); |
89 *fExtra.append() = -1; // start new contour | 97 *fExtra.append() = -1; // start new contour |
90 } | 98 } |
91 finalCurveEnd = pointsPtr++; | 99 finalCurveEnd = pointsPtr++; |
92 goto nextVerb; | 100 continue; |
93 case SkPath::kLine_Verb: | 101 case SkPath::kLine_Verb: |
94 // skip degenerate points | 102 // skip degenerate points |
95 if (pointsPtr[-1].fX != pointsPtr[0].fX || pointsPtr[-1].fY != p
ointsPtr[0].fY) { | 103 if (pointsPtr[-1].fX != pointsPtr[0].fX || pointsPtr[-1].fY != p
ointsPtr[0].fY) { |
96 fCurrentContour->addLine(&pointsPtr[-1]); | 104 fCurrentContour->addLine(&pointsPtr[-1]); |
97 } | 105 } |
98 break; | 106 break; |
99 case SkPath::kQuad_Verb: | 107 case SkPath::kQuad_Verb: |
100 reducedVerb = SkReduceOrder::Quad(&pointsPtr[-1], &fReducePts); | 108 reducedVerb = SkReduceOrder::Quad(&pointsPtr[-1], &fReducePts); |
101 if (reducedVerb == 0) { | 109 if (reducedVerb == 0) { |
102 break; // skip degenerate points | 110 break; // skip degenerate points |
(...skipping 22 matching lines...) Expand all Loading... |
125 break; | 133 break; |
126 case SkPath::kClose_Verb: | 134 case SkPath::kClose_Verb: |
127 SkASSERT(fCurrentContour); | 135 SkASSERT(fCurrentContour); |
128 if (finalCurveStart && finalCurveEnd | 136 if (finalCurveStart && finalCurveEnd |
129 && *finalCurveStart != *finalCurveEnd) { | 137 && *finalCurveStart != *finalCurveEnd) { |
130 *fReducePts.append() = *finalCurveStart; | 138 *fReducePts.append() = *finalCurveStart; |
131 *fReducePts.append() = *finalCurveEnd; | 139 *fReducePts.append() = *finalCurveEnd; |
132 *fExtra.append() = fCurrentContour->addLine(fReducePts.end()
- 2); | 140 *fExtra.append() = fCurrentContour->addLine(fReducePts.end()
- 2); |
133 } | 141 } |
134 complete(); | 142 complete(); |
135 goto nextVerb; | 143 continue; |
136 default: | 144 default: |
137 SkDEBUGFAIL("bad verb"); | 145 SkDEBUGFAIL("bad verb"); |
138 return; | 146 return; |
139 } | 147 } |
140 finalCurveStart = &pointsPtr[verb - 1]; | 148 finalCurveStart = &pointsPtr[verb - 1]; |
141 pointsPtr += verb; | 149 pointsPtr += verb; |
142 SkASSERT(fCurrentContour); | 150 SkASSERT(fCurrentContour); |
143 nextVerb: | |
144 if (verbPtr == endOfFirstHalf) { | |
145 fOperand = true; | |
146 } | |
147 } | 151 } |
148 } | 152 } |
OLD | NEW |