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 #include "SkOpCoincidence.h" | 7 #include "SkOpCoincidence.h" |
8 #include "SkOpContour.h" | 8 #include "SkOpContour.h" |
9 #include "SkOpSegment.h" | 9 #include "SkOpSegment.h" |
10 #include "SkPathWriter.h" | 10 #include "SkPathWriter.h" |
11 | 11 |
12 bool SkOpPtT::alias() const { | 12 bool SkOpPtT::alias() const { |
13 return this->span()->ptT() != this; | 13 return this->span()->ptT() != this; |
14 } | 14 } |
15 | 15 |
16 SkOpContour* SkOpPtT::contour() const { | 16 SkOpContour* SkOpPtT::contour() const { |
17 return segment()->contour(); | 17 return segment()->contour(); |
18 } | 18 } |
19 | 19 |
20 SkOpDebugState* SkOpPtT::debugState() const { | 20 SkOpGlobalState* SkOpPtT::globalState() const { |
21 return PATH_OPS_DEBUG_RELEASE(contour()->debugState(), NULL); | 21 return PATH_OPS_DEBUG_RELEASE(contour()->globalState(), NULL); |
22 } | 22 } |
23 | 23 |
24 void SkOpPtT::init(SkOpSpanBase* span, double t, const SkPoint& pt, bool duplica
te) { | 24 void SkOpPtT::init(SkOpSpanBase* span, double t, const SkPoint& pt, bool duplica
te) { |
25 fT = t; | 25 fT = t; |
26 fPt = pt; | 26 fPt = pt; |
27 fSpan = span; | 27 fSpan = span; |
28 fNext = this; | 28 fNext = this; |
29 fDuplicatePt = duplicate; | 29 fDuplicatePt = duplicate; |
30 fDeleted = false; | 30 fDeleted = false; |
31 PATH_OPS_DEBUG_CODE(fID = ++span->debugState()->fPtTID); | 31 PATH_OPS_DEBUG_CODE(fID = ++span->globalState()->fPtTID); |
32 } | 32 } |
33 | 33 |
34 bool SkOpPtT::onEnd() const { | 34 bool SkOpPtT::onEnd() const { |
35 const SkOpSpanBase* span = this->span(); | 35 const SkOpSpanBase* span = this->span(); |
36 if (span->ptT() != this) { | 36 if (span->ptT() != this) { |
37 return false; | 37 return false; |
38 } | 38 } |
39 const SkOpSegment* segment = this->segment(); | 39 const SkOpSegment* segment = this->segment(); |
40 return span == segment->head() || span == segment->tail(); | 40 return span == segment->head() || span == segment->tail(); |
41 } | 41 } |
42 | 42 |
43 SkOpPtT* SkOpPtT::remove() { | 43 SkOpPtT* SkOpPtT::remove() { |
44 SkOpPtT* prev = this; | 44 SkOpPtT* prev = this; |
45 do { | 45 do { |
46 SkOpPtT* next = prev->fNext; | 46 SkOpPtT* next = prev->fNext; |
47 if (next == this) { | 47 if (next == this) { |
48 prev->removeNext(); | 48 prev->removeNext(this); |
49 fDeleted = true; | 49 fDeleted = true; |
50 return prev; | 50 return prev; |
51 } | 51 } |
52 prev = next; | 52 prev = next; |
53 } while (prev != this); | 53 } while (prev != this); |
54 SkASSERT(0); | 54 SkASSERT(0); |
55 return NULL; | 55 return NULL; |
56 } | 56 } |
57 | 57 |
58 void SkOpPtT::removeNext() { | 58 void SkOpPtT::removeNext(SkOpPtT* kept) { |
59 SkASSERT(this->fNext); | 59 SkASSERT(this->fNext); |
60 SkOpPtT* next = this->fNext; | 60 SkOpPtT* next = this->fNext; |
61 this->fNext = next->fNext; | 61 this->fNext = next->fNext; |
62 SkOpSpanBase* span = next->span(); | 62 SkOpSpanBase* span = next->span(); |
63 next->setDeleted(); | 63 next->setDeleted(); |
64 if (span->ptT() == next) { | 64 if (span->ptT() == next) { |
65 span->upCast()->detach(); | 65 span->upCast()->detach(kept); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 const SkOpSegment* SkOpPtT::segment() const { | 69 const SkOpSegment* SkOpPtT::segment() const { |
70 return span()->segment(); | 70 return span()->segment(); |
71 } | 71 } |
72 | 72 |
73 SkOpSegment* SkOpPtT::segment() { | 73 SkOpSegment* SkOpPtT::segment() { |
74 return span()->segment(); | 74 return span()->segment(); |
75 } | 75 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 SkOpPtT* test = ptT; | 192 SkOpPtT* test = ptT; |
193 do { | 193 do { |
194 SkOpPtT* prev = test; | 194 SkOpPtT* prev = test; |
195 if ((test = test->next()) == stopPtT) { | 195 if ((test = test->next()) == stopPtT) { |
196 break; | 196 break; |
197 } | 197 } |
198 if (span == test->span() && !span->segment()->ptsDisjoint(*ptT, *tes
t)) { | 198 if (span == test->span() && !span->segment()->ptsDisjoint(*ptT, *tes
t)) { |
199 // omit aliases that alignment makes redundant | 199 // omit aliases that alignment makes redundant |
200 if ((!ptT->alias() || test->alias()) && (ptT->onEnd() || !test->
onEnd())) { | 200 if ((!ptT->alias() || test->alias()) && (ptT->onEnd() || !test->
onEnd())) { |
201 SkASSERT(test->alias()); | 201 SkASSERT(test->alias()); |
202 prev->removeNext(); | 202 prev->removeNext(ptT); |
203 test = prev; | 203 test = prev; |
204 } else { | 204 } else { |
205 SkASSERT(ptT->alias()); | 205 SkASSERT(ptT->alias()); |
206 stopPtT = ptT = ptT->remove(); | 206 stopPtT = ptT = ptT->remove(); |
207 break; | 207 break; |
208 } | 208 } |
209 } | 209 } |
210 } while (true); | 210 } while (true); |
211 } while ((ptT = ptT->next()) != stopPtT); | 211 } while ((ptT = ptT->next()) != stopPtT); |
212 } | 212 } |
(...skipping 19 matching lines...) Expand all Loading... |
232 return true; | 232 return true; |
233 } | 233 } |
234 } | 234 } |
235 return false; | 235 return false; |
236 } | 236 } |
237 | 237 |
238 SkOpContour* SkOpSpanBase::contour() const { | 238 SkOpContour* SkOpSpanBase::contour() const { |
239 return segment()->contour(); | 239 return segment()->contour(); |
240 } | 240 } |
241 | 241 |
242 SkOpDebugState* SkOpSpanBase::debugState() const { | 242 SkOpGlobalState* SkOpSpanBase::globalState() const { |
243 return PATH_OPS_DEBUG_RELEASE(contour()->debugState(), NULL); | 243 return PATH_OPS_DEBUG_RELEASE(contour()->globalState(), NULL); |
244 } | 244 } |
245 | 245 |
246 void SkOpSpanBase::initBase(SkOpSegment* segment, SkOpSpan* prev, double t, cons
t SkPoint& pt) { | 246 void SkOpSpanBase::initBase(SkOpSegment* segment, SkOpSpan* prev, double t, cons
t SkPoint& pt) { |
247 fSegment = segment; | 247 fSegment = segment; |
248 fPtT.init(this, t, pt, false); | 248 fPtT.init(this, t, pt, false); |
249 fCoinEnd = this; | 249 fCoinEnd = this; |
250 fFromAngle = NULL; | 250 fFromAngle = NULL; |
251 fPrev = prev; | 251 fPrev = prev; |
252 fAligned = true; | 252 fAligned = true; |
253 fChased = false; | 253 fChased = false; |
254 PATH_OPS_DEBUG_CODE(fCount = 1); | 254 PATH_OPS_DEBUG_CODE(fCount = 1); |
255 PATH_OPS_DEBUG_CODE(fID = ++debugState()->fSpanID); | 255 PATH_OPS_DEBUG_CODE(fID = ++globalState()->fSpanID); |
256 } | 256 } |
257 | 257 |
258 // this pair of spans share a common t value or point; merge them and eliminate
duplicates | 258 // this pair of spans share a common t value or point; merge them and eliminate
duplicates |
259 // this does not compute the best t or pt value; this merely moves all data into
a single list | 259 // this does not compute the best t or pt value; this merely moves all data into
a single list |
260 void SkOpSpanBase::merge(SkOpSpan* span) { | 260 void SkOpSpanBase::merge(SkOpSpan* span) { |
261 SkOpPtT* spanPtT = span->ptT(); | 261 SkOpPtT* spanPtT = span->ptT(); |
262 SkASSERT(this->t() != spanPtT->fT); | 262 SkASSERT(this->t() != spanPtT->fT); |
263 SkASSERT(!zero_or_one(spanPtT->fT)); | 263 SkASSERT(!zero_or_one(spanPtT->fT)); |
264 span->detach(); | 264 span->detach(this->ptT()); |
265 SkOpPtT* remainder = spanPtT->next(); | 265 SkOpPtT* remainder = spanPtT->next(); |
266 ptT()->insert(spanPtT); | 266 ptT()->insert(spanPtT); |
267 while (remainder != spanPtT) { | 267 while (remainder != spanPtT) { |
268 SkOpPtT* next = remainder->next(); | 268 SkOpPtT* next = remainder->next(); |
269 SkOpPtT* compare = spanPtT->next(); | 269 SkOpPtT* compare = spanPtT->next(); |
270 while (compare != spanPtT) { | 270 while (compare != spanPtT) { |
271 SkOpPtT* nextC = compare->next(); | 271 SkOpPtT* nextC = compare->next(); |
272 if (nextC->span() == remainder->span() && nextC->fT == remainder->fT
) { | 272 if (nextC->span() == remainder->span() && nextC->fT == remainder->fT
) { |
273 goto tryNextRemainder; | 273 goto tryNextRemainder; |
274 } | 274 } |
(...skipping 22 matching lines...) Expand all Loading... |
297 SkASSERT(this->segment() != segment); | 297 SkASSERT(this->segment() != segment); |
298 const SkOpSpan* next = this; | 298 const SkOpSpan* next = this; |
299 while ((next = next->fCoincident) != this) { | 299 while ((next = next->fCoincident) != this) { |
300 if (next->segment() == segment) { | 300 if (next->segment() == segment) { |
301 return true; | 301 return true; |
302 } | 302 } |
303 } | 303 } |
304 return false; | 304 return false; |
305 } | 305 } |
306 | 306 |
307 void SkOpSpan::detach() { | 307 void SkOpSpan::detach(SkOpPtT* kept) { |
308 SkASSERT(!final()); | 308 SkASSERT(!final()); |
309 SkOpSpan* prev = this->prev(); | 309 SkOpSpan* prev = this->prev(); |
310 SkASSERT(prev); | 310 SkASSERT(prev); |
311 SkOpSpanBase* next = this->next(); | 311 SkOpSpanBase* next = this->next(); |
312 SkASSERT(next); | 312 SkASSERT(next); |
313 prev->setNext(next); | 313 prev->setNext(next); |
314 next->setPrev(prev); | 314 next->setPrev(prev); |
315 this->segment()->detach(this); | 315 this->segment()->detach(this); |
| 316 if (this->coincident()) { |
| 317 this->globalState()->fCoincidence->fixUp(this->ptT(), kept); |
| 318 } |
316 this->ptT()->setDeleted(); | 319 this->ptT()->setDeleted(); |
317 } | 320 } |
318 | 321 |
319 void SkOpSpan::init(SkOpSegment* segment, SkOpSpan* prev, double t, const SkPoin
t& pt) { | 322 void SkOpSpan::init(SkOpSegment* segment, SkOpSpan* prev, double t, const SkPoin
t& pt) { |
320 SkASSERT(t != 1); | 323 SkASSERT(t != 1); |
321 initBase(segment, prev, t, pt); | 324 initBase(segment, prev, t, pt); |
322 fCoincident = this; | 325 fCoincident = this; |
323 fToAngle = NULL; | 326 fToAngle = NULL; |
324 fWindSum = fOppSum = SK_MinS32; | 327 fWindSum = fOppSum = SK_MinS32; |
325 fWindValue = 1; | 328 fWindValue = 1; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 next->insertCoinEnd(oNext); | 496 next->insertCoinEnd(oNext); |
494 } | 497 } |
495 SkOpSpan* nextSpan = next->upCast(); | 498 SkOpSpan* nextSpan = next->upCast(); |
496 SkOpSpan* oNextSpan = oNext->upCast(); | 499 SkOpSpan* oNextSpan = oNext->upCast(); |
497 if (!nextSpan->containsCoincidence(oNextSpan)) { | 500 if (!nextSpan->containsCoincidence(oNextSpan)) { |
498 nextSpan->insertCoincidence(oNextSpan); | 501 nextSpan->insertCoincidence(oNextSpan); |
499 } | 502 } |
500 } while (true); | 503 } while (true); |
501 } while ((coin = coin->fNext)); | 504 } while ((coin = coin->fNext)); |
502 } | 505 } |
OLD | NEW |