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 "SkGeometry.h" | 7 #include "SkGeometry.h" |
8 #include "SkOpEdgeBuilder.h" | 8 #include "SkOpEdgeBuilder.h" |
9 #include "SkReduceOrder.h" | 9 #include "SkReduceOrder.h" |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 int SkOpEdgeBuilder::count() const { | 29 int SkOpEdgeBuilder::count() const { |
30 SkOpContour* contour = fContoursHead; | 30 SkOpContour* contour = fContoursHead; |
31 int count = 0; | 31 int count = 0; |
32 while (contour) { | 32 while (contour) { |
33 count += contour->count() > 0; | 33 count += contour->count() > 0; |
34 contour = contour->next(); | 34 contour = contour->next(); |
35 } | 35 } |
36 return count; | 36 return count; |
37 } | 37 } |
38 | 38 |
39 bool SkOpEdgeBuilder::finish(SkChunkAlloc* allocator) { | 39 bool SkOpEdgeBuilder::finish() { |
40 fOperand = false; | 40 fOperand = false; |
41 if (fUnparseable || !walk(allocator)) { | 41 if (fUnparseable || !walk()) { |
42 return false; | 42 return false; |
43 } | 43 } |
44 complete(); | 44 complete(); |
45 if (fCurrentContour && !fCurrentContour->count()) { | 45 if (fCurrentContour && !fCurrentContour->count()) { |
46 fContoursHead->remove(fCurrentContour); | 46 fContoursHead->remove(fCurrentContour); |
47 } | 47 } |
48 return true; | 48 return true; |
49 } | 49 } |
50 | 50 |
51 void SkOpEdgeBuilder::closeContour(const SkPoint& curveEnd, const SkPoint& curve
Start) { | 51 void SkOpEdgeBuilder::closeContour(const SkPoint& curveEnd, const SkPoint& curve
Start) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 155 } |
156 *fPathVerbs.append() = SkPath::kDone_Verb; | 156 *fPathVerbs.append() = SkPath::kDone_Verb; |
157 return fPathVerbs.count() - 1; | 157 return fPathVerbs.count() - 1; |
158 } | 158 } |
159 | 159 |
160 bool SkOpEdgeBuilder::close() { | 160 bool SkOpEdgeBuilder::close() { |
161 complete(); | 161 complete(); |
162 return true; | 162 return true; |
163 } | 163 } |
164 | 164 |
165 bool SkOpEdgeBuilder::walk(SkChunkAlloc* allocator) { | 165 bool SkOpEdgeBuilder::walk() { |
166 uint8_t* verbPtr = fPathVerbs.begin(); | 166 uint8_t* verbPtr = fPathVerbs.begin(); |
167 uint8_t* endOfFirstHalf = &verbPtr[fSecondHalf]; | 167 uint8_t* endOfFirstHalf = &verbPtr[fSecondHalf]; |
168 SkPoint* pointsPtr = fPathPts.begin() - 1; | 168 SkPoint* pointsPtr = fPathPts.begin() - 1; |
169 SkScalar* weightPtr = fWeights.begin(); | 169 SkScalar* weightPtr = fWeights.begin(); |
170 SkPath::Verb verb; | 170 SkPath::Verb verb; |
171 while ((verb = (SkPath::Verb) *verbPtr) != SkPath::kDone_Verb) { | 171 while ((verb = (SkPath::Verb) *verbPtr) != SkPath::kDone_Verb) { |
172 if (verbPtr == endOfFirstHalf) { | 172 if (verbPtr == endOfFirstHalf) { |
173 fOperand = true; | 173 fOperand = true; |
174 } | 174 } |
175 verbPtr++; | 175 verbPtr++; |
176 switch (verb) { | 176 switch (verb) { |
177 case SkPath::kMove_Verb: | 177 case SkPath::kMove_Verb: |
178 if (fCurrentContour && fCurrentContour->count()) { | 178 if (fCurrentContour && fCurrentContour->count()) { |
179 if (fAllowOpenContours) { | 179 if (fAllowOpenContours) { |
180 complete(); | 180 complete(); |
181 } else if (!close()) { | 181 } else if (!close()) { |
182 return false; | 182 return false; |
183 } | 183 } |
184 } | 184 } |
185 if (!fCurrentContour) { | 185 if (!fCurrentContour) { |
186 fCurrentContour = fContoursHead->appendContour(allocator); | 186 fCurrentContour = fContoursHead->appendContour(); |
187 } | 187 } |
188 fCurrentContour->init(fGlobalState, fOperand, | 188 fCurrentContour->init(fGlobalState, fOperand, |
189 fXorMask[fOperand] == kEvenOdd_PathOpsMask); | 189 fXorMask[fOperand] == kEvenOdd_PathOpsMask); |
190 pointsPtr += 1; | 190 pointsPtr += 1; |
191 continue; | 191 continue; |
192 case SkPath::kLine_Verb: | 192 case SkPath::kLine_Verb: |
193 fCurrentContour->addLine(pointsPtr, fAllocator); | 193 fCurrentContour->addLine(pointsPtr); |
194 break; | 194 break; |
195 case SkPath::kQuad_Verb: | 195 case SkPath::kQuad_Verb: |
196 fCurrentContour->addQuad(pointsPtr, fAllocator); | 196 fCurrentContour->addQuad(pointsPtr); |
197 break; | 197 break; |
198 case SkPath::kConic_Verb: | 198 case SkPath::kConic_Verb: |
199 fCurrentContour->addConic(pointsPtr, *weightPtr++, fAllocator); | 199 fCurrentContour->addConic(pointsPtr, *weightPtr++); |
200 break; | 200 break; |
201 case SkPath::kCubic_Verb: { | 201 case SkPath::kCubic_Verb: { |
202 // Split complex cubics (such as self-intersecting curves or | 202 // Split complex cubics (such as self-intersecting curves or |
203 // ones with difficult curvature) in two before proceeding. | 203 // ones with difficult curvature) in two before proceeding. |
204 // This can be required for intersection to succeed. | 204 // This can be required for intersection to succeed. |
205 SkScalar splitT; | 205 SkScalar splitT; |
206 if (SkDCubic::ComplexBreak(pointsPtr, &splitT)) { | 206 if (SkDCubic::ComplexBreak(pointsPtr, &splitT)) { |
207 SkPoint cubicPair[7]; | 207 SkPoint cubicPair[7]; |
208 SkChopCubicAt(pointsPtr, cubicPair, splitT); | 208 SkChopCubicAt(pointsPtr, cubicPair, splitT); |
209 if (!SkScalarsAreFinite(&cubicPair[0].fX, SK_ARRAY_COUNT(cub
icPair) * 2)) { | 209 if (!SkScalarsAreFinite(&cubicPair[0].fX, SK_ARRAY_COUNT(cub
icPair) * 2)) { |
210 return false; | 210 return false; |
211 } | 211 } |
212 SkPoint cStorage[2][4]; | 212 SkPoint cStorage[2][4]; |
213 SkPath::Verb v1 = SkReduceOrder::Cubic(&cubicPair[0], cStora
ge[0]); | 213 SkPath::Verb v1 = SkReduceOrder::Cubic(&cubicPair[0], cStora
ge[0]); |
214 SkPath::Verb v2 = SkReduceOrder::Cubic(&cubicPair[3], cStora
ge[1]); | 214 SkPath::Verb v2 = SkReduceOrder::Cubic(&cubicPair[3], cStora
ge[1]); |
215 if (v1 != SkPath::kMove_Verb && v2 != SkPath::kMove_Verb) { | 215 if (v1 != SkPath::kMove_Verb && v2 != SkPath::kMove_Verb) { |
216 SkPoint* curve1 = v1 == SkPath::kCubic_Verb ? &cubicPair
[0] : cStorage[0]; | 216 SkPoint* curve1 = v1 == SkPath::kCubic_Verb ? &cubicPair
[0] : cStorage[0]; |
217 SkPoint* curve2 = v2 == SkPath::kCubic_Verb ? &cubicPair
[3] : cStorage[1]; | 217 SkPoint* curve2 = v2 == SkPath::kCubic_Verb ? &cubicPair
[3] : cStorage[1]; |
218 for (int index = 0; index < SkPathOpsVerbToPoints(v1); +
+index) { | 218 for (int index = 0; index < SkPathOpsVerbToPoints(v1); +
+index) { |
219 force_small_to_zero(&curve1[index]); | 219 force_small_to_zero(&curve1[index]); |
220 } | 220 } |
221 for (int index = 0; index < SkPathOpsVerbToPoints(v2); +
+index) { | 221 for (int index = 0; index < SkPathOpsVerbToPoints(v2); +
+index) { |
222 force_small_to_zero(&curve2[index]); | 222 force_small_to_zero(&curve2[index]); |
223 } | 223 } |
224 fCurrentContour->addCurve(v1, curve1, fAllocator); | 224 fCurrentContour->addCurve(v1, curve1); |
225 fCurrentContour->addCurve(v2, curve2, fAllocator); | 225 fCurrentContour->addCurve(v2, curve2); |
226 } else { | 226 } else { |
227 fCurrentContour->addCubic(pointsPtr, fAllocator); | 227 fCurrentContour->addCubic(pointsPtr); |
228 } | 228 } |
229 } else { | 229 } else { |
230 fCurrentContour->addCubic(pointsPtr, fAllocator); | 230 fCurrentContour->addCubic(pointsPtr); |
231 } | 231 } |
232 } break; | 232 } break; |
233 case SkPath::kClose_Verb: | 233 case SkPath::kClose_Verb: |
234 SkASSERT(fCurrentContour); | 234 SkASSERT(fCurrentContour); |
235 if (!close()) { | 235 if (!close()) { |
236 return false; | 236 return false; |
237 } | 237 } |
238 continue; | 238 continue; |
239 default: | 239 default: |
240 SkDEBUGFAIL("bad verb"); | 240 SkDEBUGFAIL("bad verb"); |
241 return false; | 241 return false; |
242 } | 242 } |
243 SkASSERT(fCurrentContour); | 243 SkASSERT(fCurrentContour); |
244 fCurrentContour->debugValidate(); | 244 fCurrentContour->debugValidate(); |
245 pointsPtr += SkPathOpsVerbToPoints(verb); | 245 pointsPtr += SkPathOpsVerbToPoints(verb); |
246 } | 246 } |
247 if (fCurrentContour && fCurrentContour->count() &&!fAllowOpenContours && !clo
se()) { | 247 if (fCurrentContour && fCurrentContour->count() &&!fAllowOpenContours && !clo
se()) { |
248 return false; | 248 return false; |
249 } | 249 } |
250 return true; | 250 return true; |
251 } | 251 } |
OLD | NEW |