caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | #include "SkOpCoincidence.h" |
| 8 | #include "SkOpContour.h" |
| 9 | #include "SkOpSegment.h" |
| 10 | #include "SkPathWriter.h" |
| 11 | |
| 12 | bool SkOpPtT::alias() const { |
| 13 | return this->span()->ptT() != this; |
| 14 | } |
| 15 | |
caryclark | d434972 | 2015-07-23 12:40:22 -0700 | [diff] [blame] | 16 | bool SkOpPtT::collapsed(const SkOpPtT* check) const { |
| 17 | if (fPt != check->fPt) { |
| 18 | return false; |
| 19 | } |
| 20 | SkASSERT(this != check); |
| 21 | const SkOpSegment* segment = this->segment(); |
| 22 | SkASSERT(segment == check->segment()); |
| 23 | return segment->collapsed(); |
| 24 | } |
| 25 | |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 26 | bool SkOpPtT::contains(const SkOpPtT* check) const { |
| 27 | SkASSERT(this != check); |
| 28 | const SkOpPtT* ptT = this; |
| 29 | const SkOpPtT* stopPtT = ptT; |
| 30 | while ((ptT = ptT->next()) != stopPtT) { |
| 31 | if (ptT == check) { |
| 32 | return true; |
| 33 | } |
| 34 | } |
| 35 | return false; |
| 36 | } |
| 37 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 38 | bool SkOpPtT::contains(const SkOpSegment* segment, const SkPoint& pt) const { |
| 39 | SkASSERT(this->segment() != segment); |
| 40 | const SkOpPtT* ptT = this; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 41 | const SkOpPtT* stopPtT = ptT; |
| 42 | while ((ptT = ptT->next()) != stopPtT) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 43 | if (ptT->fPt == pt && ptT->segment() == segment) { |
| 44 | return true; |
| 45 | } |
| 46 | } |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | bool SkOpPtT::contains(const SkOpSegment* segment, double t) const { |
| 51 | const SkOpPtT* ptT = this; |
| 52 | const SkOpPtT* stopPtT = ptT; |
| 53 | while ((ptT = ptT->next()) != stopPtT) { |
| 54 | if (ptT->fT == t && ptT->segment() == segment) { |
| 55 | return true; |
| 56 | } |
| 57 | } |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | const SkOpPtT* SkOpPtT::contains(const SkOpSegment* check) const { |
| 62 | SkASSERT(this->segment() != check); |
| 63 | const SkOpPtT* ptT = this; |
| 64 | const SkOpPtT* stopPtT = ptT; |
| 65 | while ((ptT = ptT->next()) != stopPtT) { |
| 66 | if (ptT->segment() == check && !ptT->deleted()) { |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 67 | return ptT; |
| 68 | } |
| 69 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 70 | return nullptr; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 71 | } |
| 72 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 73 | SkOpContour* SkOpPtT::contour() const { |
| 74 | return segment()->contour(); |
| 75 | } |
| 76 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 77 | const SkOpPtT* SkOpPtT::find(const SkOpSegment* segment) const { |
| 78 | const SkOpPtT* ptT = this; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 79 | const SkOpPtT* stopPtT = ptT; |
| 80 | do { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 81 | if (ptT->segment() == segment && !ptT->deleted()) { |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 82 | return ptT; |
| 83 | } |
| 84 | ptT = ptT->fNext; |
| 85 | } while (stopPtT != ptT); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 86 | // SkASSERT(0); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 87 | return nullptr; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 88 | } |
| 89 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 90 | SkOpGlobalState* SkOpPtT::globalState() const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 91 | return contour()->globalState(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void SkOpPtT::init(SkOpSpanBase* span, double t, const SkPoint& pt, bool duplicate) { |
| 95 | fT = t; |
| 96 | fPt = pt; |
| 97 | fSpan = span; |
| 98 | fNext = this; |
| 99 | fDuplicatePt = duplicate; |
| 100 | fDeleted = false; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 101 | fCoincident = false; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 102 | SkDEBUGCODE(fID = span->globalState()->nextPtTID()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | bool SkOpPtT::onEnd() const { |
| 106 | const SkOpSpanBase* span = this->span(); |
| 107 | if (span->ptT() != this) { |
| 108 | return false; |
| 109 | } |
| 110 | const SkOpSegment* segment = this->segment(); |
| 111 | return span == segment->head() || span == segment->tail(); |
| 112 | } |
| 113 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 114 | bool SkOpPtT::ptAlreadySeen(const SkOpPtT* check) const { |
| 115 | while (this != check) { |
| 116 | if (this->fPt == check->fPt) { |
| 117 | return true; |
| 118 | } |
| 119 | check = check->fNext; |
| 120 | } |
| 121 | return false; |
| 122 | } |
| 123 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 124 | SkOpPtT* SkOpPtT::prev() { |
| 125 | SkOpPtT* result = this; |
| 126 | SkOpPtT* next = this; |
| 127 | while ((next = next->fNext) != this) { |
| 128 | result = next; |
| 129 | } |
| 130 | SkASSERT(result->fNext == this); |
| 131 | return result; |
| 132 | } |
| 133 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 134 | SkOpPtT* SkOpPtT::remove(const SkOpPtT* kept) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 135 | SkOpPtT* prev = this; |
| 136 | do { |
| 137 | SkOpPtT* next = prev->fNext; |
| 138 | if (next == this) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 139 | prev->removeNext(kept); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 140 | SkASSERT(prev->fNext != prev); |
| 141 | fDeleted = true; |
| 142 | return prev; |
| 143 | } |
| 144 | prev = next; |
| 145 | } while (prev != this); |
| 146 | SkASSERT(0); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 147 | return nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 148 | } |
| 149 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 150 | void SkOpPtT::removeNext(const SkOpPtT* kept) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 151 | SkASSERT(this->fNext); |
| 152 | SkOpPtT* next = this->fNext; |
| 153 | SkASSERT(this != next->fNext); |
| 154 | this->fNext = next->fNext; |
| 155 | SkOpSpanBase* span = next->span(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 156 | SkOpCoincidence* coincidence = span->globalState()->coincidence(); |
| 157 | if (coincidence) { |
| 158 | coincidence->fixUp(next, kept); |
| 159 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 160 | next->setDeleted(); |
| 161 | if (span->ptT() == next) { |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 162 | span->upCast()->release(kept); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
| 166 | const SkOpSegment* SkOpPtT::segment() const { |
| 167 | return span()->segment(); |
| 168 | } |
| 169 | |
| 170 | SkOpSegment* SkOpPtT::segment() { |
| 171 | return span()->segment(); |
| 172 | } |
| 173 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 174 | void SkOpPtT::setDeleted() { |
| 175 | SkASSERT(this->span()->debugDeleted() || this->span()->ptT() != this); |
caryclark | 1597628 | 2016-07-21 05:48:43 -0700 | [diff] [blame] | 176 | SkOPASSERT(!fDeleted); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 177 | fDeleted = true; |
| 178 | } |
| 179 | |
| 180 | // please keep this in sync with debugAddOppAndMerge |
| 181 | // If the added points envelop adjacent spans, merge them in. |
| 182 | void SkOpSpanBase::addOppAndMerge(SkOpSpanBase* opp) { |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame^] | 183 | SkOpPtT* oppPrev = this->ptT()->oppPrev(opp->ptT()); |
| 184 | if (oppPrev) { |
| 185 | this->ptT()->addOpp(opp->ptT(), oppPrev); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 186 | this->checkForCollapsedCoincidence(); |
| 187 | } |
| 188 | // compute bounds of points in span |
| 189 | SkPathOpsBounds bounds; |
| 190 | bounds.set(SK_ScalarMax, SK_ScalarMax, SK_ScalarMin, SK_ScalarMin); |
| 191 | const SkOpPtT* head = this->ptT(); |
| 192 | const SkOpPtT* nextPt = head; |
| 193 | do { |
| 194 | bounds.add(nextPt->fPt); |
| 195 | } while ((nextPt = nextPt->next()) != head); |
| 196 | if (!bounds.width() && !bounds.height()) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 197 | return; |
| 198 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 199 | this->mergeContained(bounds); |
| 200 | opp->mergeContained(bounds); |
| 201 | } |
| 202 | |
| 203 | // Please keep this in sync with debugMergeContained() |
| 204 | void SkOpSpanBase::mergeContained(const SkPathOpsBounds& bounds) { |
| 205 | // while adjacent spans' points are contained by the bounds, merge them |
| 206 | SkOpSpanBase* prev = this; |
| 207 | SkOpSegment* seg = this->segment(); |
| 208 | while ((prev = prev->prev()) && bounds.contains(prev->pt()) && !seg->ptsDisjoint(prev, this)) { |
| 209 | if (prev->prev()) { |
| 210 | this->merge(prev->upCast()); |
| 211 | prev = this; |
| 212 | } else if (this->final()) { |
| 213 | seg->clearAll(); |
| 214 | return; |
| 215 | } else { |
| 216 | prev->merge(this->upCast()); |
| 217 | } |
| 218 | } |
| 219 | SkOpSpanBase* current = this; |
| 220 | SkOpSpanBase* next = this; |
| 221 | while (next->upCastable() && (next = next->upCast()->next()) |
| 222 | && bounds.contains(next->pt()) && !seg->ptsDisjoint(this, next)) { |
| 223 | if (!current->prev() && next->final()) { |
| 224 | seg->clearAll(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 225 | return; |
| 226 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 227 | if (current->prev()) { |
| 228 | next->merge(current->upCast()); |
| 229 | current = next; |
| 230 | } else { |
| 231 | current->merge(next->upCast()); |
| 232 | // extra line in debug version |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 233 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 234 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 235 | #if DEBUG_COINCIDENCE |
| 236 | this->globalState()->coincidence()->debugValidate(); |
| 237 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | bool SkOpSpanBase::contains(const SkOpSpanBase* span) const { |
| 241 | const SkOpPtT* start = &fPtT; |
| 242 | const SkOpPtT* check = &span->fPtT; |
caryclark | ef4f32a | 2016-08-24 09:24:18 -0700 | [diff] [blame] | 243 | SkOPASSERT(start != check); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 244 | const SkOpPtT* walk = start; |
| 245 | while ((walk = walk->next()) != start) { |
| 246 | if (walk == check) { |
| 247 | return true; |
| 248 | } |
| 249 | } |
| 250 | return false; |
| 251 | } |
| 252 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 253 | const SkOpPtT* SkOpSpanBase::contains(const SkOpSegment* segment) const { |
| 254 | const SkOpPtT* start = &fPtT; |
| 255 | const SkOpPtT* walk = start; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 256 | while ((walk = walk->next()) != start) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 257 | if (walk->deleted()) { |
| 258 | continue; |
| 259 | } |
| 260 | if (walk->segment() == segment && walk->span()->ptT() == walk) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 261 | return walk; |
| 262 | } |
| 263 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 264 | return nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | bool SkOpSpanBase::containsCoinEnd(const SkOpSegment* segment) const { |
| 268 | SkASSERT(this->segment() != segment); |
| 269 | const SkOpSpanBase* next = this; |
| 270 | while ((next = next->fCoinEnd) != this) { |
| 271 | if (next->segment() == segment) { |
| 272 | return true; |
| 273 | } |
| 274 | } |
| 275 | return false; |
| 276 | } |
| 277 | |
| 278 | SkOpContour* SkOpSpanBase::contour() const { |
| 279 | return segment()->contour(); |
| 280 | } |
| 281 | |
| 282 | SkOpGlobalState* SkOpSpanBase::globalState() const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 283 | return contour()->globalState(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | void SkOpSpanBase::initBase(SkOpSegment* segment, SkOpSpan* prev, double t, const SkPoint& pt) { |
| 287 | fSegment = segment; |
| 288 | fPtT.init(this, t, pt, false); |
| 289 | fCoinEnd = this; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 290 | fFromAngle = nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 291 | fPrev = prev; |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 292 | fSpanAdds = 0; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 293 | fAligned = true; |
| 294 | fChased = false; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 295 | SkDEBUGCODE(fCount = 1); |
| 296 | SkDEBUGCODE(fID = globalState()->nextSpanID()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 297 | SkDEBUGCODE(fDeleted = false); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | // this pair of spans share a common t value or point; merge them and eliminate duplicates |
| 301 | // this does not compute the best t or pt value; this merely moves all data into a single list |
| 302 | void SkOpSpanBase::merge(SkOpSpan* span) { |
| 303 | SkOpPtT* spanPtT = span->ptT(); |
| 304 | SkASSERT(this->t() != spanPtT->fT); |
| 305 | SkASSERT(!zero_or_one(spanPtT->fT)); |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 306 | span->release(this->ptT()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 307 | if (this->contains(span)) { |
| 308 | return; // merge is already in the ptT loop |
| 309 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 310 | SkOpPtT* remainder = spanPtT->next(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 311 | this->ptT()->insert(spanPtT); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 312 | while (remainder != spanPtT) { |
| 313 | SkOpPtT* next = remainder->next(); |
| 314 | SkOpPtT* compare = spanPtT->next(); |
| 315 | while (compare != spanPtT) { |
| 316 | SkOpPtT* nextC = compare->next(); |
| 317 | if (nextC->span() == remainder->span() && nextC->fT == remainder->fT) { |
| 318 | goto tryNextRemainder; |
| 319 | } |
| 320 | compare = nextC; |
| 321 | } |
| 322 | spanPtT->insert(remainder); |
| 323 | tryNextRemainder: |
| 324 | remainder = next; |
| 325 | } |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 326 | fSpanAdds += span->fSpanAdds; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 327 | this->checkForCollapsedCoincidence(); |
| 328 | } |
| 329 | |
| 330 | // please keep in sync with debugCheckForCollapsedCoincidence() |
| 331 | void SkOpSpanBase::checkForCollapsedCoincidence() { |
| 332 | SkOpCoincidence* coins = this->globalState()->coincidence(); |
| 333 | if (coins->isEmpty()) { |
| 334 | return; |
| 335 | } |
| 336 | // the insert above may have put both ends of a coincident run in the same span |
| 337 | // for each coincident ptT in loop; see if its opposite in is also in the loop |
| 338 | // this implementation is the motivation for marking that a ptT is referenced by a coincident span |
| 339 | SkOpPtT* head = this->ptT(); |
| 340 | SkOpPtT* test = head; |
| 341 | do { |
| 342 | if (!test->coincident()) { |
| 343 | continue; |
| 344 | } |
| 345 | coins->markCollapsed(test); |
| 346 | } while ((test = test->next()) != head); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 347 | } |
| 348 | |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 349 | int SkOpSpan::computeWindSum() { |
| 350 | SkOpGlobalState* globals = this->globalState(); |
| 351 | SkOpContour* contourHead = globals->contourHead(); |
| 352 | int windTry = 0; |
| 353 | while (!this->sortableTop(contourHead) && ++windTry < SkOpGlobalState::kMaxWindingTries) { |
| 354 | ; |
| 355 | } |
| 356 | return this->windSum(); |
| 357 | } |
| 358 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 359 | bool SkOpSpan::containsCoincidence(const SkOpSegment* segment) const { |
| 360 | SkASSERT(this->segment() != segment); |
| 361 | const SkOpSpan* next = fCoincident; |
| 362 | do { |
| 363 | if (next->segment() == segment) { |
| 364 | return true; |
| 365 | } |
| 366 | } while ((next = next->fCoincident) != this); |
| 367 | return false; |
| 368 | } |
| 369 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 370 | void SkOpSpan::init(SkOpSegment* segment, SkOpSpan* prev, double t, const SkPoint& pt) { |
| 371 | SkASSERT(t != 1); |
| 372 | initBase(segment, prev, t, pt); |
| 373 | fCoincident = this; |
| 374 | fToAngle = nullptr; |
| 375 | fWindSum = fOppSum = SK_MinS32; |
| 376 | fWindValue = 1; |
| 377 | fOppValue = 0; |
| 378 | fTopTTry = 0; |
| 379 | fChased = fDone = false; |
| 380 | segment->bumpCount(); |
| 381 | fAlreadyAdded = false; |
| 382 | } |
| 383 | |
| 384 | // Please keep this in sync with debugInsertCoincidence() |
| 385 | bool SkOpSpan::insertCoincidence(const SkOpSegment* segment, bool flipped) { |
| 386 | if (this->containsCoincidence(segment)) { |
| 387 | return true; |
| 388 | } |
| 389 | SkOpPtT* next = &fPtT; |
| 390 | while ((next = next->next()) != &fPtT) { |
| 391 | if (next->segment() == segment) { |
caryclark | 1493b97 | 2016-07-19 11:29:14 -0700 | [diff] [blame] | 392 | SkOpSpan* span; |
| 393 | if (flipped) { |
| 394 | span = next->span()->prev(); |
| 395 | if (!span) { |
| 396 | return false; |
| 397 | } |
| 398 | } else { |
| 399 | SkOpSpanBase* base = next->span(); |
| 400 | if (!base->upCastable()) { |
| 401 | return false; |
| 402 | } |
| 403 | span = base->upCast(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 404 | } |
| 405 | this->insertCoincidence(span); |
| 406 | return true; |
| 407 | } |
| 408 | } |
| 409 | #if DEBUG_COINCIDENCE |
| 410 | SkASSERT(0); // FIXME? if we get here, the span is missing its opposite segment... |
| 411 | #endif |
| 412 | return true; |
| 413 | } |
| 414 | |
| 415 | void SkOpSpan::release(const SkOpPtT* kept) { |
| 416 | SkDEBUGCODE(fDeleted = true); |
| 417 | SkASSERT(kept->span() != this); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 418 | SkASSERT(!final()); |
| 419 | SkOpSpan* prev = this->prev(); |
| 420 | SkASSERT(prev); |
| 421 | SkOpSpanBase* next = this->next(); |
| 422 | SkASSERT(next); |
| 423 | prev->setNext(next); |
| 424 | next->setPrev(prev); |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 425 | this->segment()->release(this); |
caryclark | 218f21a | 2015-06-29 11:41:52 -0700 | [diff] [blame] | 426 | SkOpCoincidence* coincidence = this->globalState()->coincidence(); |
| 427 | if (coincidence) { |
| 428 | coincidence->fixUp(this->ptT(), kept); |
| 429 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 430 | this->ptT()->setDeleted(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 431 | SkOpPtT* stopPtT = this->ptT(); |
| 432 | SkOpPtT* testPtT = stopPtT; |
| 433 | const SkOpSpanBase* keptSpan = kept->span(); |
| 434 | do { |
| 435 | if (this == testPtT->span()) { |
| 436 | testPtT->setSpan(keptSpan); |
| 437 | } |
| 438 | } while ((testPtT = testPtT->next()) != stopPtT); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | void SkOpSpan::setOppSum(int oppSum) { |
| 442 | SkASSERT(!final()); |
| 443 | if (fOppSum != SK_MinS32 && fOppSum != oppSum) { |
| 444 | this->globalState()->setWindingFailed(); |
| 445 | return; |
| 446 | } |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 447 | SkASSERT(!DEBUG_LIMIT_WIND_SUM || SkTAbs(oppSum) <= DEBUG_LIMIT_WIND_SUM); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 448 | fOppSum = oppSum; |
| 449 | } |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 450 | |
| 451 | void SkOpSpan::setWindSum(int windSum) { |
| 452 | SkASSERT(!final()); |
| 453 | if (fWindSum != SK_MinS32 && fWindSum != windSum) { |
| 454 | this->globalState()->setWindingFailed(); |
| 455 | return; |
| 456 | } |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 457 | SkASSERT(!DEBUG_LIMIT_WIND_SUM || SkTAbs(windSum) <= DEBUG_LIMIT_WIND_SUM); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 458 | fWindSum = windSum; |
| 459 | } |