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