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