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