epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 8 | #include "SkClipStack.h" |
| 9 | #include "SkPath.h" |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 10 | #include "SkThread.h" |
| 11 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 12 | #include <new> |
| 13 | |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 14 | |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 15 | // 0-2 are reserved for invalid, empty & wide-open |
bsalomon@google.com | edb26fd | 2012-11-28 14:42:41 +0000 | [diff] [blame] | 16 | static const int32_t kFirstUnreservedGenID = 3; |
| 17 | int32_t SkClipStack::gGenID = kFirstUnreservedGenID; |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 18 | |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 19 | bool SkClipStack::Element::operator== (const Element& element) const { |
| 20 | if (this == &element) { |
| 21 | return true; |
| 22 | } |
| 23 | if (fOp != element.fOp || |
| 24 | fType != element.fType || |
| 25 | fDoAA != element.fDoAA || |
| 26 | fSaveCount != element.fSaveCount) { |
| 27 | return false; |
| 28 | } |
| 29 | switch (fType) { |
| 30 | case kPath_Type: |
| 31 | return fPath == element.fPath; |
| 32 | case kRRect_Type: |
| 33 | return fRRect == element.fRRect; |
| 34 | case kRect_Type: |
| 35 | return fRect == element.fRect; |
| 36 | case kEmpty_Type: |
| 37 | return true; |
| 38 | default: |
| 39 | SkDEBUGFAIL("Unexpected type."); |
| 40 | return false; |
| 41 | } |
| 42 | } |
| 43 | |
bsalomon@google.com | c6b3e48 | 2012-12-07 20:43:52 +0000 | [diff] [blame] | 44 | void SkClipStack::Element::invertShapeFillType() { |
| 45 | switch (fType) { |
| 46 | case kRect_Type: |
| 47 | fPath.reset(); |
| 48 | fPath.addRect(fRect); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 49 | fPath.setFillType(SkPath::kInverseEvenOdd_FillType); |
| 50 | fType = kPath_Type; |
| 51 | break; |
| 52 | case kRRect_Type: |
| 53 | fPath.reset(); |
| 54 | fPath.addRRect(fRRect); |
| 55 | fPath.setFillType(SkPath::kInverseEvenOdd_FillType); |
bsalomon@google.com | c6b3e48 | 2012-12-07 20:43:52 +0000 | [diff] [blame] | 56 | fType = kPath_Type; |
| 57 | break; |
| 58 | case kPath_Type: |
| 59 | fPath.toggleInverseFillType(); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 60 | break; |
bsalomon@google.com | c6b3e48 | 2012-12-07 20:43:52 +0000 | [diff] [blame] | 61 | case kEmpty_Type: |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 62 | // Should this set to an empty, inverse filled path? |
| 63 | break; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | void SkClipStack::Element::initPath(int saveCount, const SkPath& path, SkRegion::Op op, |
| 68 | bool doAA) { |
| 69 | if (!path.isInverseFillType()) { |
| 70 | if (SkPath::kNone_PathAsRect != path.asRect()) { |
| 71 | this->initRect(saveCount, path.getBounds(), op, doAA); |
| 72 | return; |
| 73 | } |
| 74 | SkRect ovalRect; |
| 75 | if (path.isOval(&ovalRect)) { |
| 76 | SkRRect rrect; |
| 77 | rrect.setOval(ovalRect); |
| 78 | this->initRRect(saveCount, rrect, op, doAA); |
| 79 | return; |
| 80 | } |
| 81 | } |
| 82 | fPath = path; |
| 83 | fType = kPath_Type; |
| 84 | this->initCommon(saveCount, op, doAA); |
| 85 | } |
| 86 | |
| 87 | void SkClipStack::Element::asPath(SkPath* path) const { |
| 88 | switch (fType) { |
| 89 | case kEmpty_Type: |
| 90 | path->reset(); |
| 91 | break; |
| 92 | case kRect_Type: |
| 93 | path->reset(); |
| 94 | path->addRect(fRect); |
| 95 | break; |
| 96 | case kRRect_Type: |
| 97 | path->reset(); |
| 98 | path->addRRect(fRRect); |
| 99 | break; |
| 100 | case kPath_Type: |
| 101 | *path = fPath; |
bsalomon@google.com | c6b3e48 | 2012-12-07 20:43:52 +0000 | [diff] [blame] | 102 | break; |
| 103 | } |
| 104 | } |
| 105 | |
commit-bot@chromium.org | 9cb671a | 2014-02-16 14:45:45 +0000 | [diff] [blame^] | 106 | void SkClipStack::Element::setEmpty() { |
| 107 | fType = kEmpty_Type; |
| 108 | fFiniteBound.setEmpty(); |
| 109 | fFiniteBoundType = kNormal_BoundsType; |
| 110 | fIsIntersectionOfRects = false; |
| 111 | fRect.setEmpty(); |
| 112 | fRRect.setEmpty(); |
| 113 | fPath.reset(); |
| 114 | fGenID = kEmptyGenID; |
| 115 | SkDEBUGCODE(this->checkEmpty();) |
| 116 | } |
| 117 | |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 118 | void SkClipStack::Element::checkEmpty() const { |
| 119 | SkASSERT(fFiniteBound.isEmpty()); |
| 120 | SkASSERT(kNormal_BoundsType == fFiniteBoundType); |
| 121 | SkASSERT(!fIsIntersectionOfRects); |
| 122 | SkASSERT(kEmptyGenID == fGenID); |
| 123 | SkASSERT(fPath.isEmpty()); |
| 124 | } |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 125 | |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 126 | bool SkClipStack::Element::canBeIntersectedInPlace(int saveCount, SkRegion::Op op) const { |
| 127 | if (kEmpty_Type == fType && |
| 128 | (SkRegion::kDifference_Op == op || SkRegion::kIntersect_Op == op)) { |
| 129 | return true; |
| 130 | } |
| 131 | // Only clips within the same save/restore frame (as captured by |
| 132 | // the save count) can be merged |
| 133 | return fSaveCount == saveCount && |
| 134 | SkRegion::kIntersect_Op == op && |
| 135 | (SkRegion::kIntersect_Op == fOp || SkRegion::kReplace_Op == fOp); |
| 136 | } |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 137 | |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 138 | bool SkClipStack::Element::rectRectIntersectAllowed(const SkRect& newR, bool newAA) const { |
| 139 | SkASSERT(kRect_Type == fType); |
| 140 | |
| 141 | if (fDoAA == newAA) { |
| 142 | // if the AA setting is the same there is no issue |
| 143 | return true; |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 144 | } |
| 145 | |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 146 | if (!SkRect::Intersects(fRect, newR)) { |
| 147 | // The calling code will correctly set the result to the empty clip |
| 148 | return true; |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 149 | } |
| 150 | |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 151 | if (fRect.contains(newR)) { |
| 152 | // if the new rect carves out a portion of the old one there is no |
| 153 | // issue |
| 154 | return true; |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 155 | } |
| 156 | |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 157 | // So either the two overlap in some complex manner or newR contains oldR. |
| 158 | // In the first, case the edges will require different AA. In the second, |
| 159 | // the AA setting that would be carried forward is incorrect (e.g., oldR |
| 160 | // is AA while newR is BW but since newR contains oldR, oldR will be |
| 161 | // drawn BW) since the new AA setting will predominate. |
| 162 | return false; |
| 163 | } |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 164 | |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 165 | // a mirror of combineBoundsRevDiff |
| 166 | void SkClipStack::Element::combineBoundsDiff(FillCombo combination, const SkRect& prevFinite) { |
| 167 | switch (combination) { |
| 168 | case kInvPrev_InvCur_FillCombo: |
| 169 | // In this case the only pixels that can remain set |
| 170 | // are inside the current clip rect since the extensions |
| 171 | // to infinity of both clips cancel out and whatever |
| 172 | // is outside of the current clip is removed |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 173 | fFiniteBoundType = kNormal_BoundsType; |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 174 | break; |
| 175 | case kInvPrev_Cur_FillCombo: |
| 176 | // In this case the current op is finite so the only pixels |
| 177 | // that aren't set are whatever isn't set in the previous |
| 178 | // clip and whatever this clip carves out |
| 179 | fFiniteBound.join(prevFinite); |
| 180 | fFiniteBoundType = kInsideOut_BoundsType; |
| 181 | break; |
| 182 | case kPrev_InvCur_FillCombo: |
| 183 | // In this case everything outside of this clip's bound |
| 184 | // is erased, so the only pixels that can remain set |
| 185 | // occur w/in the intersection of the two finite bounds |
| 186 | if (!fFiniteBound.intersect(prevFinite)) { |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 187 | this->setEmpty(); |
| 188 | } else { |
| 189 | fFiniteBoundType = kNormal_BoundsType; |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 190 | } |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 191 | break; |
| 192 | case kPrev_Cur_FillCombo: |
| 193 | // The most conservative result bound is that of the |
| 194 | // prior clip. This could be wildly incorrect if the |
| 195 | // second clip either exactly matches the first clip |
| 196 | // (which should yield the empty set) or reduces the |
| 197 | // size of the prior bound (e.g., if the second clip |
| 198 | // exactly matched the bottom half of the prior clip). |
| 199 | // We ignore these two possibilities. |
| 200 | fFiniteBound = prevFinite; |
| 201 | break; |
| 202 | default: |
| 203 | SkDEBUGFAIL("SkClipStack::Element::combineBoundsDiff Invalid fill combination"); |
| 204 | break; |
| 205 | } |
| 206 | } |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 207 | |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 208 | void SkClipStack::Element::combineBoundsXOR(int combination, const SkRect& prevFinite) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 209 | |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 210 | switch (combination) { |
| 211 | case kInvPrev_Cur_FillCombo: // fall through |
| 212 | case kPrev_InvCur_FillCombo: |
| 213 | // With only one of the clips inverted the result will always |
| 214 | // extend to infinity. The only pixels that may be un-writeable |
| 215 | // lie within the union of the two finite bounds |
| 216 | fFiniteBound.join(prevFinite); |
| 217 | fFiniteBoundType = kInsideOut_BoundsType; |
| 218 | break; |
| 219 | case kInvPrev_InvCur_FillCombo: |
| 220 | // The only pixels that can survive are within the |
| 221 | // union of the two bounding boxes since the extensions |
| 222 | // to infinity of both clips cancel out |
| 223 | // fall through! |
| 224 | case kPrev_Cur_FillCombo: |
| 225 | // The most conservative bound for xor is the |
| 226 | // union of the two bounds. If the two clips exactly overlapped |
| 227 | // the xor could yield the empty set. Similarly the xor |
| 228 | // could reduce the size of the original clip's bound (e.g., |
| 229 | // if the second clip exactly matched the bottom half of the |
| 230 | // first clip). We ignore these two cases. |
| 231 | fFiniteBound.join(prevFinite); |
| 232 | fFiniteBoundType = kNormal_BoundsType; |
| 233 | break; |
| 234 | default: |
| 235 | SkDEBUGFAIL("SkClipStack::Element::combineBoundsXOR Invalid fill combination"); |
| 236 | break; |
| 237 | } |
| 238 | } |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 239 | |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 240 | // a mirror of combineBoundsIntersection |
| 241 | void SkClipStack::Element::combineBoundsUnion(int combination, const SkRect& prevFinite) { |
| 242 | |
| 243 | switch (combination) { |
| 244 | case kInvPrev_InvCur_FillCombo: |
| 245 | if (!fFiniteBound.intersect(prevFinite)) { |
| 246 | fFiniteBound.setEmpty(); |
| 247 | fGenID = kWideOpenGenID; |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 248 | } |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 249 | fFiniteBoundType = kInsideOut_BoundsType; |
| 250 | break; |
| 251 | case kInvPrev_Cur_FillCombo: |
| 252 | // The only pixels that won't be drawable are inside |
| 253 | // the prior clip's finite bound |
| 254 | fFiniteBound = prevFinite; |
| 255 | fFiniteBoundType = kInsideOut_BoundsType; |
| 256 | break; |
| 257 | case kPrev_InvCur_FillCombo: |
| 258 | // The only pixels that won't be drawable are inside |
| 259 | // this clip's finite bound |
| 260 | break; |
| 261 | case kPrev_Cur_FillCombo: |
| 262 | fFiniteBound.join(prevFinite); |
| 263 | break; |
| 264 | default: |
| 265 | SkDEBUGFAIL("SkClipStack::Element::combineBoundsUnion Invalid fill combination"); |
| 266 | break; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | // a mirror of combineBoundsUnion |
| 271 | void SkClipStack::Element::combineBoundsIntersection(int combination, const SkRect& prevFinite) { |
| 272 | |
| 273 | switch (combination) { |
| 274 | case kInvPrev_InvCur_FillCombo: |
| 275 | // The only pixels that aren't writable in this case |
| 276 | // occur in the union of the two finite bounds |
| 277 | fFiniteBound.join(prevFinite); |
| 278 | fFiniteBoundType = kInsideOut_BoundsType; |
| 279 | break; |
| 280 | case kInvPrev_Cur_FillCombo: |
| 281 | // In this case the only pixels that will remain writeable |
| 282 | // are within the current clip |
| 283 | break; |
| 284 | case kPrev_InvCur_FillCombo: |
| 285 | // In this case the only pixels that will remain writeable |
| 286 | // are with the previous clip |
| 287 | fFiniteBound = prevFinite; |
| 288 | fFiniteBoundType = kNormal_BoundsType; |
| 289 | break; |
| 290 | case kPrev_Cur_FillCombo: |
| 291 | if (!fFiniteBound.intersect(prevFinite)) { |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 292 | this->setEmpty(); |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 293 | } |
| 294 | break; |
| 295 | default: |
| 296 | SkDEBUGFAIL("SkClipStack::Element::combineBoundsIntersection Invalid fill combination"); |
| 297 | break; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | // a mirror of combineBoundsDiff |
| 302 | void SkClipStack::Element::combineBoundsRevDiff(int combination, const SkRect& prevFinite) { |
| 303 | |
| 304 | switch (combination) { |
| 305 | case kInvPrev_InvCur_FillCombo: |
| 306 | // The only pixels that can survive are in the |
| 307 | // previous bound since the extensions to infinity in |
| 308 | // both clips cancel out |
| 309 | fFiniteBound = prevFinite; |
| 310 | fFiniteBoundType = kNormal_BoundsType; |
| 311 | break; |
| 312 | case kInvPrev_Cur_FillCombo: |
| 313 | if (!fFiniteBound.intersect(prevFinite)) { |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 314 | this->setEmpty(); |
| 315 | } else { |
| 316 | fFiniteBoundType = kNormal_BoundsType; |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 317 | } |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 318 | break; |
| 319 | case kPrev_InvCur_FillCombo: |
| 320 | fFiniteBound.join(prevFinite); |
| 321 | fFiniteBoundType = kInsideOut_BoundsType; |
| 322 | break; |
| 323 | case kPrev_Cur_FillCombo: |
| 324 | // Fall through - as with the kDifference_Op case, the |
| 325 | // most conservative result bound is the bound of the |
| 326 | // current clip. The prior clip could reduce the size of this |
| 327 | // bound (as in the kDifference_Op case) but we are ignoring |
| 328 | // those cases. |
| 329 | break; |
| 330 | default: |
| 331 | SkDEBUGFAIL("SkClipStack::Element::combineBoundsRevDiff Invalid fill combination"); |
| 332 | break; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | void SkClipStack::Element::updateBoundAndGenID(const Element* prior) { |
| 337 | // We set this first here but we may overwrite it later if we determine that the clip is |
| 338 | // either wide-open or empty. |
| 339 | fGenID = GetNextGenID(); |
| 340 | |
| 341 | // First, optimistically update the current Element's bound information |
| 342 | // with the current clip's bound |
| 343 | fIsIntersectionOfRects = false; |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 344 | switch (fType) { |
| 345 | case kRect_Type: |
| 346 | fFiniteBound = fRect; |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 347 | fFiniteBoundType = kNormal_BoundsType; |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 348 | |
| 349 | if (SkRegion::kReplace_Op == fOp || |
| 350 | (SkRegion::kIntersect_Op == fOp && NULL == prior) || |
| 351 | (SkRegion::kIntersect_Op == fOp && prior->fIsIntersectionOfRects && |
| 352 | prior->rectRectIntersectAllowed(fRect, fDoAA))) { |
| 353 | fIsIntersectionOfRects = true; |
| 354 | } |
| 355 | break; |
| 356 | case kRRect_Type: |
| 357 | fFiniteBound = fRRect.getBounds(); |
| 358 | fFiniteBoundType = kNormal_BoundsType; |
| 359 | break; |
| 360 | case kPath_Type: |
| 361 | fFiniteBound = fPath.getBounds(); |
| 362 | |
| 363 | if (fPath.isInverseFillType()) { |
| 364 | fFiniteBoundType = kInsideOut_BoundsType; |
| 365 | } else { |
| 366 | fFiniteBoundType = kNormal_BoundsType; |
| 367 | } |
| 368 | break; |
| 369 | case kEmpty_Type: |
| 370 | SkDEBUGFAIL("We shouldn't get here with an empty element."); |
| 371 | break; |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 372 | } |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 373 | |
| 374 | if (!fDoAA) { |
| 375 | // Here we mimic a non-anti-aliased scanline system. If there is |
| 376 | // no anti-aliasing we can integerize the bounding box to exclude |
| 377 | // fractional parts that won't be rendered. |
| 378 | // Note: the left edge is handled slightly differently below. We |
| 379 | // are a bit more generous in the rounding since we don't want to |
| 380 | // risk missing the left pixels when fLeft is very close to .5 |
reed@google.com | e1ca705 | 2013-12-17 19:22:07 +0000 | [diff] [blame] | 381 | fFiniteBound.set(SkScalarFloorToScalar(fFiniteBound.fLeft+0.45f), |
| 382 | SkScalarRoundToScalar(fFiniteBound.fTop), |
| 383 | SkScalarRoundToScalar(fFiniteBound.fRight), |
| 384 | SkScalarRoundToScalar(fFiniteBound.fBottom)); |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | // Now determine the previous Element's bound information taking into |
| 388 | // account that there may be no previous clip |
| 389 | SkRect prevFinite; |
| 390 | SkClipStack::BoundsType prevType; |
| 391 | |
| 392 | if (NULL == prior) { |
| 393 | // no prior clip means the entire plane is writable |
| 394 | prevFinite.setEmpty(); // there are no pixels that cannot be drawn to |
| 395 | prevType = kInsideOut_BoundsType; |
| 396 | } else { |
| 397 | prevFinite = prior->fFiniteBound; |
| 398 | prevType = prior->fFiniteBoundType; |
| 399 | } |
| 400 | |
| 401 | FillCombo combination = kPrev_Cur_FillCombo; |
| 402 | if (kInsideOut_BoundsType == fFiniteBoundType) { |
| 403 | combination = (FillCombo) (combination | 0x01); |
| 404 | } |
| 405 | if (kInsideOut_BoundsType == prevType) { |
| 406 | combination = (FillCombo) (combination | 0x02); |
| 407 | } |
| 408 | |
| 409 | SkASSERT(kInvPrev_InvCur_FillCombo == combination || |
| 410 | kInvPrev_Cur_FillCombo == combination || |
| 411 | kPrev_InvCur_FillCombo == combination || |
| 412 | kPrev_Cur_FillCombo == combination); |
| 413 | |
| 414 | // Now integrate with clip with the prior clips |
| 415 | switch (fOp) { |
| 416 | case SkRegion::kDifference_Op: |
| 417 | this->combineBoundsDiff(combination, prevFinite); |
| 418 | break; |
| 419 | case SkRegion::kXOR_Op: |
| 420 | this->combineBoundsXOR(combination, prevFinite); |
| 421 | break; |
| 422 | case SkRegion::kUnion_Op: |
| 423 | this->combineBoundsUnion(combination, prevFinite); |
| 424 | break; |
| 425 | case SkRegion::kIntersect_Op: |
| 426 | this->combineBoundsIntersection(combination, prevFinite); |
| 427 | break; |
| 428 | case SkRegion::kReverseDifference_Op: |
| 429 | this->combineBoundsRevDiff(combination, prevFinite); |
| 430 | break; |
| 431 | case SkRegion::kReplace_Op: |
| 432 | // Replace just ignores everything prior |
| 433 | // The current clip's bound information is already filled in |
| 434 | // so nothing to do |
| 435 | break; |
| 436 | default: |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 437 | SkDebugf("SkRegion::Op error\n"); |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 438 | SkASSERT(0); |
| 439 | break; |
| 440 | } |
| 441 | } |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 442 | |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 443 | // This constant determines how many Element's are allocated together as a block in |
robertphillips@google.com | f9a9084 | 2012-08-17 14:25:43 +0000 | [diff] [blame] | 444 | // the deque. As such it needs to balance allocating too much memory vs. |
| 445 | // incurring allocation/deallocation thrashing. It should roughly correspond to |
| 446 | // the deepest save/restore stack we expect to see. |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 447 | static const int kDefaultElementAllocCnt = 8; |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 448 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 449 | SkClipStack::SkClipStack() |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 450 | : fDeque(sizeof(Element), kDefaultElementAllocCnt) |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 451 | , fSaveCount(0) { |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 452 | } |
| 453 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 454 | SkClipStack::SkClipStack(const SkClipStack& b) |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 455 | : fDeque(sizeof(Element), kDefaultElementAllocCnt) { |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 456 | *this = b; |
| 457 | } |
| 458 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 459 | SkClipStack::SkClipStack(const SkRect& r) |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 460 | : fDeque(sizeof(Element), kDefaultElementAllocCnt) |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 461 | , fSaveCount(0) { |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 462 | if (!r.isEmpty()) { |
| 463 | this->clipDevRect(r, SkRegion::kReplace_Op, false); |
| 464 | } |
| 465 | } |
| 466 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 467 | SkClipStack::SkClipStack(const SkIRect& r) |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 468 | : fDeque(sizeof(Element), kDefaultElementAllocCnt) |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 469 | , fSaveCount(0) { |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 470 | if (!r.isEmpty()) { |
| 471 | SkRect temp; |
| 472 | temp.set(r); |
| 473 | this->clipDevRect(temp, SkRegion::kReplace_Op, false); |
| 474 | } |
| 475 | } |
| 476 | |
vandebo@chromium.org | 610f716 | 2012-03-14 18:34:15 +0000 | [diff] [blame] | 477 | SkClipStack::~SkClipStack() { |
| 478 | reset(); |
| 479 | } |
| 480 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 481 | SkClipStack& SkClipStack::operator=(const SkClipStack& b) { |
| 482 | if (this == &b) { |
| 483 | return *this; |
| 484 | } |
| 485 | reset(); |
| 486 | |
| 487 | fSaveCount = b.fSaveCount; |
| 488 | SkDeque::F2BIter recIter(b.fDeque); |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 489 | for (const Element* element = (const Element*)recIter.next(); |
| 490 | element != NULL; |
| 491 | element = (const Element*)recIter.next()) { |
| 492 | new (fDeque.push_back()) Element(*element); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | return *this; |
| 496 | } |
| 497 | |
| 498 | bool SkClipStack::operator==(const SkClipStack& b) const { |
commit-bot@chromium.org | 86b39f3 | 2014-01-06 16:54:20 +0000 | [diff] [blame] | 499 | if (this->getTopmostGenID() == b.getTopmostGenID()) { |
| 500 | return true; |
| 501 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 502 | if (fSaveCount != b.fSaveCount || |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 503 | fDeque.count() != b.fDeque.count()) { |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 504 | return false; |
| 505 | } |
| 506 | SkDeque::F2BIter myIter(fDeque); |
| 507 | SkDeque::F2BIter bIter(b.fDeque); |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 508 | const Element* myElement = (const Element*)myIter.next(); |
| 509 | const Element* bElement = (const Element*)bIter.next(); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 510 | |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 511 | while (myElement != NULL && bElement != NULL) { |
| 512 | if (*myElement != *bElement) { |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 513 | return false; |
| 514 | } |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 515 | myElement = (const Element*)myIter.next(); |
| 516 | bElement = (const Element*)bIter.next(); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 517 | } |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 518 | return myElement == NULL && bElement == NULL; |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 519 | } |
| 520 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 521 | void SkClipStack::reset() { |
vandebo@chromium.org | 610f716 | 2012-03-14 18:34:15 +0000 | [diff] [blame] | 522 | // We used a placement new for each object in fDeque, so we're responsible |
| 523 | // for calling the destructor on each of them as well. |
| 524 | while (!fDeque.empty()) { |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 525 | Element* element = (Element*)fDeque.back(); |
| 526 | element->~Element(); |
vandebo@chromium.org | 610f716 | 2012-03-14 18:34:15 +0000 | [diff] [blame] | 527 | fDeque.pop_back(); |
| 528 | } |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 529 | |
| 530 | fSaveCount = 0; |
| 531 | } |
| 532 | |
| 533 | void SkClipStack::save() { |
| 534 | fSaveCount += 1; |
| 535 | } |
| 536 | |
| 537 | void SkClipStack::restore() { |
| 538 | fSaveCount -= 1; |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 539 | restoreTo(fSaveCount); |
| 540 | } |
| 541 | |
| 542 | void SkClipStack::restoreTo(int saveCount) { |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 543 | while (!fDeque.empty()) { |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 544 | Element* element = (Element*)fDeque.back(); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 545 | if (element->fSaveCount <= saveCount) { |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 546 | break; |
| 547 | } |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 548 | element->~Element(); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 549 | fDeque.pop_back(); |
| 550 | } |
| 551 | } |
| 552 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 553 | void SkClipStack::getBounds(SkRect* canvFiniteBound, |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 554 | BoundsType* boundType, |
| 555 | bool* isIntersectionOfRects) const { |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 556 | SkASSERT(NULL != canvFiniteBound && NULL != boundType); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 557 | |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 558 | Element* element = (Element*)fDeque.back(); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 559 | |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 560 | if (NULL == element) { |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 561 | // the clip is wide open - the infinite plane w/ no pixels un-writeable |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 562 | canvFiniteBound->setEmpty(); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 563 | *boundType = kInsideOut_BoundsType; |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 564 | if (NULL != isIntersectionOfRects) { |
| 565 | *isIntersectionOfRects = false; |
| 566 | } |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 567 | return; |
| 568 | } |
| 569 | |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 570 | *canvFiniteBound = element->fFiniteBound; |
| 571 | *boundType = element->fFiniteBoundType; |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 572 | if (NULL != isIntersectionOfRects) { |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 573 | *isIntersectionOfRects = element->fIsIntersectionOfRects; |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 574 | } |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 575 | } |
| 576 | |
bsalomon@google.com | 3ab43d5 | 2012-10-11 19:39:09 +0000 | [diff] [blame] | 577 | bool SkClipStack::intersectRectWithClip(SkRect* rect) const { |
| 578 | SkASSERT(NULL != rect); |
| 579 | |
| 580 | SkRect bounds; |
| 581 | SkClipStack::BoundsType bt; |
| 582 | this->getBounds(&bounds, &bt); |
| 583 | if (bt == SkClipStack::kInsideOut_BoundsType) { |
| 584 | if (bounds.contains(*rect)) { |
| 585 | return false; |
| 586 | } else { |
| 587 | // If rect's x values are both within bound's x range we |
| 588 | // could clip here. Same for y. But we don't bother to check. |
| 589 | return true; |
| 590 | } |
skia.committer@gmail.com | 5b6f916 | 2012-10-12 02:01:15 +0000 | [diff] [blame] | 591 | } else { |
bsalomon@google.com | 3ab43d5 | 2012-10-11 19:39:09 +0000 | [diff] [blame] | 592 | return rect->intersect(bounds); |
| 593 | } |
| 594 | } |
| 595 | |
junov@chromium.org | 8cdf0f5 | 2012-12-12 17:58:15 +0000 | [diff] [blame] | 596 | bool SkClipStack::quickContains(const SkRect& rect) const { |
| 597 | |
| 598 | Iter iter(*this, Iter::kTop_IterStart); |
| 599 | const Element* element = iter.prev(); |
| 600 | while (element != NULL) { |
| 601 | if (SkRegion::kIntersect_Op != element->getOp() && SkRegion::kReplace_Op != element->getOp()) |
| 602 | return false; |
| 603 | if (element->isInverseFilled()) { |
| 604 | // Part of 'rect' could be trimmed off by the inverse-filled clip element |
| 605 | if (SkRect::Intersects(element->getBounds(), rect)) { |
| 606 | return false; |
| 607 | } |
| 608 | } else { |
| 609 | if (!element->contains(rect)) { |
| 610 | return false; |
| 611 | } |
| 612 | } |
| 613 | if (SkRegion::kReplace_Op == element->getOp()) { |
| 614 | break; |
| 615 | } |
| 616 | element = iter.prev(); |
| 617 | } |
| 618 | return true; |
| 619 | } |
| 620 | |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 621 | void SkClipStack::pushElement(const Element& element) { |
robertphillips@google.com | 63ae1cf | 2012-08-17 13:53:05 +0000 | [diff] [blame] | 622 | // Use reverse iterator instead of back because Rect path may need previous |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 623 | SkDeque::Iter iter(fDeque, SkDeque::Iter::kBack_IterStart); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 624 | Element* prior = (Element*) iter.prev(); |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 625 | |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 626 | if (NULL != prior) { |
| 627 | if (prior->canBeIntersectedInPlace(fSaveCount, element.getOp())) { |
| 628 | switch (prior->fType) { |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 629 | case Element::kEmpty_Type: |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 630 | SkDEBUGCODE(prior->checkEmpty();) |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 631 | return; |
| 632 | case Element::kRect_Type: |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 633 | if (Element::kRect_Type == element.getType()) { |
| 634 | if (prior->rectRectIntersectAllowed(element.getRect(), element.isAA())) { |
| 635 | if (!prior->fRect.intersect(element.getRect())) { |
| 636 | prior->setEmpty(); |
| 637 | return; |
| 638 | } |
| 639 | |
| 640 | prior->fDoAA = element.isAA(); |
| 641 | Element* priorPrior = (Element*) iter.prev(); |
| 642 | prior->updateBoundAndGenID(priorPrior); |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 643 | return; |
| 644 | } |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 645 | break; |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 646 | } |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 647 | // fallthrough |
| 648 | default: |
| 649 | if (!SkRect::Intersects(prior->getBounds(), element.getBounds())) { |
| 650 | prior->setEmpty(); |
robertphillips@google.com | 08eacc1 | 2012-08-02 12:49:00 +0000 | [diff] [blame] | 651 | return; |
| 652 | } |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 653 | break; |
| 654 | } |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 655 | } else if (SkRegion::kReplace_Op == element.getOp()) { |
commit-bot@chromium.org | 6fbe54c | 2013-06-11 11:01:48 +0000 | [diff] [blame] | 656 | this->restoreTo(fSaveCount - 1); |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 657 | prior = (Element*) fDeque.back(); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 658 | } |
| 659 | } |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 660 | Element* newElement = SkNEW_PLACEMENT_ARGS(fDeque.push_back(), Element, (element)); |
| 661 | newElement->updateBoundAndGenID(prior); |
| 662 | } |
| 663 | |
| 664 | void SkClipStack::clipDevRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { |
| 665 | Element element(fSaveCount, rrect, op, doAA); |
| 666 | this->pushElement(element); |
| 667 | } |
| 668 | |
| 669 | void SkClipStack::clipDevRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
| 670 | Element element(fSaveCount, rect, op, doAA); |
| 671 | this->pushElement(element); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 672 | } |
| 673 | |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 674 | void SkClipStack::clipDevPath(const SkPath& path, SkRegion::Op op, bool doAA) { |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 675 | Element element(fSaveCount, path, op, doAA); |
| 676 | this->pushElement(element); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 677 | } |
| 678 | |
reed@google.com | 0557d9e | 2012-08-16 15:59:59 +0000 | [diff] [blame] | 679 | void SkClipStack::clipEmpty() { |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 680 | Element* element = (Element*) fDeque.back(); |
robertphillips@google.com | 63ae1cf | 2012-08-17 13:53:05 +0000 | [diff] [blame] | 681 | |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 682 | if (element && element->canBeIntersectedInPlace(fSaveCount, SkRegion::kIntersect_Op)) { |
commit-bot@chromium.org | e5b2af9 | 2014-02-16 13:25:24 +0000 | [diff] [blame] | 683 | element->setEmpty(); |
reed@google.com | 0557d9e | 2012-08-16 15:59:59 +0000 | [diff] [blame] | 684 | } |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 685 | new (fDeque.push_back()) Element(fSaveCount); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 686 | |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 687 | ((Element*)fDeque.back())->fGenID = kEmptyGenID; |
reed@google.com | 0557d9e | 2012-08-16 15:59:59 +0000 | [diff] [blame] | 688 | } |
| 689 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 690 | bool SkClipStack::isWideOpen() const { |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 691 | return this->getTopmostGenID() == kWideOpenGenID; |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 692 | } |
| 693 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 694 | /////////////////////////////////////////////////////////////////////////////// |
| 695 | |
robertphillips@google.com | 5836b6d | 2012-07-18 12:06:15 +0000 | [diff] [blame] | 696 | SkClipStack::Iter::Iter() : fStack(NULL) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 697 | } |
| 698 | |
robertphillips@google.com | 5836b6d | 2012-07-18 12:06:15 +0000 | [diff] [blame] | 699 | SkClipStack::Iter::Iter(const SkClipStack& stack, IterStart startLoc) |
| 700 | : fStack(&stack) { |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 701 | this->reset(stack, startLoc); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 702 | } |
| 703 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 704 | const SkClipStack::Element* SkClipStack::Iter::next() { |
| 705 | return (const SkClipStack::Element*)fIter.next(); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 706 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 707 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 708 | const SkClipStack::Element* SkClipStack::Iter::prev() { |
| 709 | return (const SkClipStack::Element*)fIter.prev(); |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 710 | } |
| 711 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 712 | const SkClipStack::Element* SkClipStack::Iter::skipToTopmost(SkRegion::Op op) { |
robertphillips@google.com | 5836b6d | 2012-07-18 12:06:15 +0000 | [diff] [blame] | 713 | |
| 714 | if (NULL == fStack) { |
| 715 | return NULL; |
| 716 | } |
| 717 | |
| 718 | fIter.reset(fStack->fDeque, SkDeque::Iter::kBack_IterStart); |
| 719 | |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 720 | const SkClipStack::Element* element = NULL; |
robertphillips@google.com | 5836b6d | 2012-07-18 12:06:15 +0000 | [diff] [blame] | 721 | |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 722 | for (element = (const SkClipStack::Element*) fIter.prev(); |
| 723 | NULL != element; |
| 724 | element = (const SkClipStack::Element*) fIter.prev()) { |
robertphillips@google.com | 5836b6d | 2012-07-18 12:06:15 +0000 | [diff] [blame] | 725 | |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 726 | if (op == element->fOp) { |
robertphillips@google.com | 5836b6d | 2012-07-18 12:06:15 +0000 | [diff] [blame] | 727 | // The Deque's iterator is actually one pace ahead of the |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 728 | // returned value. So while "element" is the element we want to |
robertphillips@google.com | 5836b6d | 2012-07-18 12:06:15 +0000 | [diff] [blame] | 729 | // return, the iterator is actually pointing at (and will |
| 730 | // return on the next "next" or "prev" call) the element |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 731 | // in front of it in the deque. Bump the iterator forward a |
robertphillips@google.com | 5836b6d | 2012-07-18 12:06:15 +0000 | [diff] [blame] | 732 | // step so we get the expected result. |
| 733 | if (NULL == fIter.next()) { |
| 734 | // The reverse iterator has run off the front of the deque |
| 735 | // (i.e., the "op" clip is the first clip) and can't |
| 736 | // recover. Reset the iterator to start at the front. |
| 737 | fIter.reset(fStack->fDeque, SkDeque::Iter::kFront_IterStart); |
| 738 | } |
| 739 | break; |
| 740 | } |
| 741 | } |
| 742 | |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 743 | if (NULL == element) { |
robertphillips@google.com | 5836b6d | 2012-07-18 12:06:15 +0000 | [diff] [blame] | 744 | // There were no "op" clips |
| 745 | fIter.reset(fStack->fDeque, SkDeque::Iter::kFront_IterStart); |
| 746 | } |
| 747 | |
| 748 | return this->next(); |
| 749 | } |
| 750 | |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 751 | void SkClipStack::Iter::reset(const SkClipStack& stack, IterStart startLoc) { |
robertphillips@google.com | a6f11c4 | 2012-07-23 17:39:44 +0000 | [diff] [blame] | 752 | fStack = &stack; |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 753 | fIter.reset(stack.fDeque, static_cast<SkDeque::Iter::IterStart>(startLoc)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 754 | } |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 755 | |
| 756 | // helper method |
| 757 | void SkClipStack::getConservativeBounds(int offsetX, |
| 758 | int offsetY, |
| 759 | int maxWidth, |
| 760 | int maxHeight, |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 761 | SkRect* devBounds, |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 762 | bool* isIntersectionOfRects) const { |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 763 | SkASSERT(NULL != devBounds); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 764 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 765 | devBounds->setLTRB(0, 0, |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 766 | SkIntToScalar(maxWidth), SkIntToScalar(maxHeight)); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 767 | |
| 768 | SkRect temp; |
| 769 | SkClipStack::BoundsType boundType; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 770 | |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 771 | // temp starts off in canvas space here |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 772 | this->getBounds(&temp, &boundType, isIntersectionOfRects); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 773 | if (SkClipStack::kInsideOut_BoundsType == boundType) { |
| 774 | return; |
| 775 | } |
| 776 | |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 777 | // but is converted to device space here |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 778 | temp.offset(SkIntToScalar(offsetX), SkIntToScalar(offsetY)); |
| 779 | |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 780 | if (!devBounds->intersect(temp)) { |
| 781 | devBounds->setEmpty(); |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 782 | } |
| 783 | } |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 784 | |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 785 | int32_t SkClipStack::GetNextGenID() { |
bsalomon@google.com | edb26fd | 2012-11-28 14:42:41 +0000 | [diff] [blame] | 786 | // TODO: handle overflow. |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 787 | return sk_atomic_inc(&gGenID); |
| 788 | } |
robertphillips@google.com | 73e7102 | 2012-08-09 18:10:49 +0000 | [diff] [blame] | 789 | |
| 790 | int32_t SkClipStack::getTopmostGenID() const { |
robertphillips@google.com | 73e7102 | 2012-08-09 18:10:49 +0000 | [diff] [blame] | 791 | if (fDeque.empty()) { |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 792 | return kWideOpenGenID; |
robertphillips@google.com | 73e7102 | 2012-08-09 18:10:49 +0000 | [diff] [blame] | 793 | } |
| 794 | |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame] | 795 | const Element* back = static_cast<const Element*>(fDeque.back()); |
| 796 | if (kInsideOut_BoundsType == back->fFiniteBoundType && back->fFiniteBound.isEmpty()) { |
| 797 | return kWideOpenGenID; |
| 798 | } |
| 799 | |
| 800 | return back->getGenID(); |
robertphillips@google.com | 73e7102 | 2012-08-09 18:10:49 +0000 | [diff] [blame] | 801 | } |