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