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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 69 } |
70 SkPath::RawIter iter(*fPath); | 70 SkPath::RawIter iter(*fPath); |
71 SkPoint pts[4]; | 71 SkPoint pts[4]; |
72 SkPath::Verb verb; | 72 SkPath::Verb verb; |
73 do { | 73 do { |
74 verb = iter.next(pts); | 74 verb = iter.next(pts); |
75 *fPathVerbs.append() = verb; | 75 *fPathVerbs.append() = verb; |
76 if (verb == SkPath::kMove_Verb) { | 76 if (verb == SkPath::kMove_Verb) { |
77 *fPathPts.append() = pts[0]; | 77 *fPathPts.append() = pts[0]; |
78 } else if (verb >= SkPath::kLine_Verb && verb <= SkPath::kCubic_Verb) { | 78 } else if (verb >= SkPath::kLine_Verb && verb <= SkPath::kCubic_Verb) { |
79 fPathPts.append(verb, &pts[1]); | 79 fPathPts.append(SkPathOpsVerbToPoints(verb), &pts[1]); |
80 } | 80 } |
81 } while (verb != SkPath::kDone_Verb); | 81 } while (verb != SkPath::kDone_Verb); |
82 return fPathVerbs.count() - 1; | 82 return fPathVerbs.count() - 1; |
83 } | 83 } |
84 | 84 |
85 bool SkOpEdgeBuilder::close() { | 85 bool SkOpEdgeBuilder::close() { |
86 if (fFinalCurveStart && fFinalCurveEnd && *fFinalCurveStart != *fFinalCurveE
nd) { | 86 if (fFinalCurveStart && fFinalCurveEnd && *fFinalCurveStart != *fFinalCurveE
nd) { |
87 *fReducePts.append() = *fFinalCurveStart; | 87 *fReducePts.append() = *fFinalCurveStart; |
88 *fReducePts.append() = *fFinalCurveEnd; | 88 *fReducePts.append() = *fFinalCurveEnd; |
89 const SkPoint* lineStart = fReducePts.end() - 2; | 89 const SkPoint* lineStart = fReducePts.end() - 2; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 if (lineStart.fX != lineEnd.fX || lineStart.fY != lineEnd.fY) { | 130 if (lineStart.fX != lineEnd.fX || lineStart.fY != lineEnd.fY) { |
131 fCurrentContour->addLine(&lineStart); | 131 fCurrentContour->addLine(&lineStart); |
132 } | 132 } |
133 } break; | 133 } break; |
134 case SkPath::kQuad_Verb: { | 134 case SkPath::kQuad_Verb: { |
135 const SkPoint* quadStart = &pointsPtr[-1]; | 135 const SkPoint* quadStart = &pointsPtr[-1]; |
136 reducedVerb = SkReduceOrder::Quad(quadStart, &fReducePts); | 136 reducedVerb = SkReduceOrder::Quad(quadStart, &fReducePts); |
137 if (reducedVerb == 0) { | 137 if (reducedVerb == 0) { |
138 break; // skip degenerate points | 138 break; // skip degenerate points |
139 } | 139 } |
140 if (reducedVerb == 1) { | 140 if (reducedVerb == SkPath::kLine_Verb) { |
141 const SkPoint* lineStart = fReducePts.end() - 2; | 141 const SkPoint* lineStart = fReducePts.end() - 2; |
142 *fExtra.append() = fCurrentContour->addLine(lineStart); | 142 *fExtra.append() = fCurrentContour->addLine(lineStart); |
143 break; | 143 break; |
144 } | 144 } |
145 fCurrentContour->addQuad(quadStart); | 145 fCurrentContour->addQuad(quadStart); |
146 } break; | 146 } break; |
147 case SkPath::kCubic_Verb: { | 147 case SkPath::kCubic_Verb: { |
148 const SkPoint* cubicStart = &pointsPtr[-1]; | 148 const SkPoint* cubicStart = &pointsPtr[-1]; |
149 reducedVerb = SkReduceOrder::Cubic(cubicStart, &fReducePts); | 149 reducedVerb = SkReduceOrder::Cubic(cubicStart, &fReducePts); |
150 if (reducedVerb == 0) { | 150 if (reducedVerb == 0) { |
151 break; // skip degenerate points | 151 break; // skip degenerate points |
152 } | 152 } |
153 if (reducedVerb == 1) { | 153 if (reducedVerb == SkPath::kLine_Verb) { |
154 const SkPoint* lineStart = fReducePts.end() - 2; | 154 const SkPoint* lineStart = fReducePts.end() - 2; |
155 *fExtra.append() = fCurrentContour->addLine(lineStart); | 155 *fExtra.append() = fCurrentContour->addLine(lineStart); |
156 break; | 156 break; |
157 } | 157 } |
158 if (reducedVerb == 2) { | 158 if (reducedVerb == SkPath::kQuad_Verb) { |
159 const SkPoint* quadStart = fReducePts.end() - 3; | 159 const SkPoint* quadStart = fReducePts.end() - 3; |
160 *fExtra.append() = fCurrentContour->addQuad(quadStart); | 160 *fExtra.append() = fCurrentContour->addQuad(quadStart); |
161 break; | 161 break; |
162 } | 162 } |
163 fCurrentContour->addCubic(cubicStart); | 163 fCurrentContour->addCubic(cubicStart); |
164 } break; | 164 } break; |
165 case SkPath::kClose_Verb: | 165 case SkPath::kClose_Verb: |
166 SkASSERT(fCurrentContour); | 166 SkASSERT(fCurrentContour); |
167 if (!close()) { | 167 if (!close()) { |
168 return false; | 168 return false; |
169 } | 169 } |
170 continue; | 170 continue; |
171 default: | 171 default: |
172 SkDEBUGFAIL("bad verb"); | 172 SkDEBUGFAIL("bad verb"); |
173 return false; | 173 return false; |
174 } | 174 } |
175 fFinalCurveStart = &pointsPtr[verb - 1]; | 175 fFinalCurveStart = &pointsPtr[SkPathOpsVerbToPoints(verb) - 1]; |
176 pointsPtr += verb; | 176 pointsPtr += SkPathOpsVerbToPoints(verb); |
177 SkASSERT(fCurrentContour); | 177 SkASSERT(fCurrentContour); |
178 } | 178 } |
179 if (fCurrentContour && !fAllowOpenContours && !close()) { | 179 if (fCurrentContour && !fAllowOpenContours && !close()) { |
180 return false; | 180 return false; |
181 } | 181 } |
182 return true; | 182 return true; |
183 } | 183 } |
OLD | NEW |