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 | #ifndef SkClipStack_DEFINED |
| 9 | #define SkClipStack_DEFINED |
| 10 | |
| 11 | #include "SkDeque.h" |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 12 | #include "SkPath.h" |
| 13 | #include "SkRect.h" |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 14 | #include "SkRegion.h" |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 15 | #include "SkTDArray.h" |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 16 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 17 | |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 18 | // Because a single save/restore state can have multiple clips, this class |
| 19 | // stores the stack depth (fSaveCount) and clips (fDeque) separately. |
| 20 | // Each clip in fDeque stores the stack state to which it belongs |
| 21 | // (i.e., the fSaveCount in force when it was added). Restores are thus |
| 22 | // implemented by removing clips from fDeque that have an fSaveCount larger |
| 23 | // then the freshly decremented count. |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 24 | class SK_API SkClipStack { |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 25 | public: |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 26 | enum BoundsType { |
| 27 | // The bounding box contains all the pixels that can be written to |
| 28 | kNormal_BoundsType, |
| 29 | // The bounding box contains all the pixels that cannot be written to. |
| 30 | // The real bound extends out to infinity and all the pixels outside |
| 31 | // of the bound can be written to. Note that some of the pixels inside |
| 32 | // the bound may also be writeable but all pixels that cannot be |
| 33 | // written to are guaranteed to be inside. |
| 34 | kInsideOut_BoundsType |
| 35 | }; |
| 36 | |
| 37 | class Element { |
| 38 | public: |
| 39 | enum Type { |
| 40 | //!< This element makes the clip empty (regardless of previous elements). |
| 41 | kEmpty_Type, |
| 42 | //!< This element combines a rect with the current clip using a set operation |
| 43 | kRect_Type, |
| 44 | //!< This element combines a path with the current clip using a set operation |
| 45 | kPath_Type, |
| 46 | }; |
| 47 | |
| 48 | Element() { |
| 49 | this->initCommon(0, SkRegion::kReplace_Op, false); |
| 50 | this->setEmpty(); |
| 51 | } |
| 52 | |
| 53 | Element(const SkRect& rect, SkRegion::Op op, bool doAA) { |
| 54 | this->initRect(0, rect, op, doAA); |
| 55 | } |
| 56 | |
| 57 | Element(const SkPath& path, SkRegion::Op op, bool doAA) { |
| 58 | this->initPath(0, path, op, doAA); |
| 59 | } |
| 60 | |
| 61 | //!< Call to get the type of the clip element. |
| 62 | Type getType() const { return fType; } |
| 63 | |
| 64 | //!< Call if getType() is kPath to get the path. |
| 65 | const SkPath& getPath() const { return fPath; } |
| 66 | |
| 67 | //!< Call if getType() is kRect to get the rect. |
| 68 | const SkRect& getRect() const { return fRect; } |
| 69 | |
| 70 | //!< Call if getType() is not kEmpty to get the set operation used to combine this element. |
| 71 | SkRegion::Op getOp() const { return fOp; } |
| 72 | |
| 73 | /** If getType() is not kEmpty this indicates whether the clip shape should be anti-aliased |
| 74 | when it is rasterized. */ |
| 75 | bool isAA() const { return fDoAA; } |
| 76 | |
| 77 | /** The GenID can be used by clip stack clients to cache representations of the clip. The |
| 78 | ID corresponds to the set of clip elements up to and including this element within the |
| 79 | stack not to the element itself. That is the same clip path in different stacks will |
| 80 | have a different ID since the elements produce different clip result in the context of |
| 81 | their stacks. */ |
| 82 | int32_t getGenID() const { return fGenID; } |
| 83 | |
| 84 | private: |
| 85 | friend class SkClipStack; |
| 86 | |
| 87 | SkPath fPath; |
| 88 | SkRect fRect; |
| 89 | int fSaveCount; // save count of stack when this element was added. |
| 90 | SkRegion::Op fOp; |
| 91 | Type fType; |
| 92 | bool fDoAA; |
| 93 | |
| 94 | /* fFiniteBoundType and fFiniteBound are used to incrementally update the clip stack's |
| 95 | bound. When fFiniteBoundType is kNormal_BoundsType, fFiniteBound represents the |
| 96 | conservative bounding box of the pixels that aren't clipped (i.e., any pixels that can be |
| 97 | drawn to are inside the bound). When fFiniteBoundType is kInsideOut_BoundsType (which |
| 98 | occurs when a clip is inverse filled), fFiniteBound represents the conservative bounding |
| 99 | box of the pixels that _are_ clipped (i.e., any pixels that cannot be drawn to are inside |
| 100 | the bound). When fFiniteBoundType is kInsideOut_BoundsType the actual bound is the |
| 101 | infinite plane. This behavior of fFiniteBoundType and fFiniteBound is required so that we |
| 102 | can capture the cancelling out of the extensions to infinity when two inverse filled |
| 103 | clips are Booleaned together. */ |
| 104 | SkClipStack::BoundsType fFiniteBoundType; |
| 105 | SkRect fFiniteBound; |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame^] | 106 | |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 107 | // When element is applied to the previous elements in the stack is the result known to be |
| 108 | // equivalent to a single rect intersection? IIOW, is the clip effectively a rectangle. |
| 109 | bool fIsIntersectionOfRects; |
| 110 | |
| 111 | int fGenID; |
| 112 | |
| 113 | Element(int saveCount) { |
| 114 | this->initCommon(saveCount, SkRegion::kReplace_Op, false); |
| 115 | this->setEmpty(); |
| 116 | } |
| 117 | |
| 118 | Element(int saveCount, const SkRect& rect, SkRegion::Op op, bool doAA) { |
| 119 | this->initRect(saveCount, rect, op, doAA); |
| 120 | } |
| 121 | |
| 122 | Element(int saveCount, const SkPath& path, SkRegion::Op op, bool doAA) { |
| 123 | this->initPath(saveCount, path, op, doAA); |
| 124 | } |
| 125 | |
| 126 | void initCommon(int saveCount, SkRegion::Op op, bool doAA) { |
| 127 | fSaveCount = saveCount; |
| 128 | fOp = op; |
| 129 | fDoAA = doAA; |
| 130 | // A default of inside-out and empty bounds means the bounds are effectively void as it |
| 131 | // indicates that nothing is known to be outside the clip. |
| 132 | fFiniteBoundType = kInsideOut_BoundsType; |
| 133 | fFiniteBound.setEmpty(); |
| 134 | fIsIntersectionOfRects = false; |
| 135 | fGenID = kInvalidGenID; |
| 136 | } |
| 137 | |
| 138 | void initRect(int saveCount, const SkRect& rect, SkRegion::Op op, bool doAA) { |
| 139 | fRect = rect; |
| 140 | fType = kRect_Type; |
| 141 | this->initCommon(saveCount, op, doAA); |
| 142 | } |
| 143 | |
| 144 | void initPath(int saveCount, const SkPath& path, SkRegion::Op op, bool doAA) { |
| 145 | fPath = path; |
| 146 | fType = kPath_Type; |
| 147 | this->initCommon(saveCount, op, doAA); |
| 148 | } |
| 149 | |
| 150 | void setEmpty() { |
| 151 | fType = kEmpty_Type; |
| 152 | fFiniteBound.setEmpty(); |
| 153 | fFiniteBoundType = kNormal_BoundsType; |
| 154 | fIsIntersectionOfRects = false; |
| 155 | fRect.setEmpty(); |
| 156 | fPath.reset(); |
| 157 | fGenID = kEmptyGenID; |
| 158 | } |
| 159 | |
| 160 | // All Element methods below are only used within SkClipStack.cpp |
| 161 | inline void checkEmpty() const; |
| 162 | inline bool operator==(const Element& b) const; |
| 163 | inline bool operator!=(const Element& b) const; |
| 164 | inline bool canBeIntersectedInPlace(int saveCount, SkRegion::Op op) const; |
| 165 | /* This method checks to see if two rect clips can be safely merged into one. The issue here |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame^] | 166 | is that to be strictly correct all the edges of the resulting rect must have the same |
bsalomon@google.com | 8a98e3b | 2012-11-29 21:05:13 +0000 | [diff] [blame] | 167 | anti-aliasing. */ |
| 168 | bool rectRectIntersectAllowed(const SkRect& newR, bool newAA) const; |
| 169 | /** Determines possible finite bounds for the Element given the previous element of the |
| 170 | stack */ |
| 171 | void updateBoundAndGenID(const Element* prior); |
| 172 | // The different combination of fill & inverse fill when combining bounding boxes |
| 173 | enum FillCombo { |
| 174 | kPrev_Cur_FillCombo, |
| 175 | kPrev_InvCur_FillCombo, |
| 176 | kInvPrev_Cur_FillCombo, |
| 177 | kInvPrev_InvCur_FillCombo |
| 178 | }; |
| 179 | // per-set operation functions used by updateBoundAndGenID(). |
| 180 | inline void combineBoundsDiff(FillCombo combination, const SkRect& prevFinite); |
| 181 | inline void combineBoundsXOR(int combination, const SkRect& prevFinite); |
| 182 | inline void combineBoundsUnion(int combination, const SkRect& prevFinite); |
| 183 | inline void combineBoundsIntersection(int combination, const SkRect& prevFinite); |
| 184 | inline void combineBoundsRevDiff(int combination, const SkRect& prevFinite); |
| 185 | }; |
| 186 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 187 | SkClipStack(); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 188 | SkClipStack(const SkClipStack& b); |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 189 | explicit SkClipStack(const SkRect& r); |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 190 | explicit SkClipStack(const SkIRect& r); |
vandebo@chromium.org | 610f716 | 2012-03-14 18:34:15 +0000 | [diff] [blame] | 191 | ~SkClipStack(); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 192 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 193 | SkClipStack& operator=(const SkClipStack& b); |
| 194 | bool operator==(const SkClipStack& b) const; |
| 195 | bool operator!=(const SkClipStack& b) const { return !(*this == b); } |
| 196 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 197 | void reset(); |
| 198 | |
| 199 | int getSaveCount() const { return fSaveCount; } |
| 200 | void save(); |
| 201 | void restore(); |
| 202 | |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 203 | /** |
| 204 | * getBounds places the current finite bound in its first parameter. In its |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 205 | * second, it indicates which kind of bound is being returned. If |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 206 | * 'canvFiniteBound' is a normal bounding box then it encloses all writeable |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 207 | * pixels. If 'canvFiniteBound' is an inside out bounding box then it |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 208 | * encloses all the un-writeable pixels and the true/normal bound is the |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 209 | * infinite plane. isIntersectionOfRects is an optional parameter |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 210 | * that is true if 'canvFiniteBound' resulted from an intersection of rects. |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 211 | */ |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 212 | void getBounds(SkRect* canvFiniteBound, |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 213 | BoundsType* boundType, |
| 214 | bool* isIntersectionOfRects = NULL) const; |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 215 | |
bsalomon@google.com | 3ab43d5 | 2012-10-11 19:39:09 +0000 | [diff] [blame] | 216 | /** |
| 217 | * Takes an input rect in device space and conservatively clips it to the |
| 218 | * clip-stack. If false is returned then the rect does not intersect the |
| 219 | * clip and is unmodified. |
| 220 | */ |
| 221 | bool intersectRectWithClip(SkRect* devRect) const; |
| 222 | |
reed@google.com | 115d931 | 2012-05-16 18:50:40 +0000 | [diff] [blame] | 223 | void clipDevRect(const SkIRect& ir, SkRegion::Op op) { |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 224 | SkRect r; |
| 225 | r.set(ir); |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 226 | this->clipDevRect(r, op, false); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 227 | } |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 228 | void clipDevRect(const SkRect&, SkRegion::Op, bool doAA); |
| 229 | void clipDevPath(const SkPath&, SkRegion::Op, bool doAA); |
reed@google.com | 0557d9e | 2012-08-16 15:59:59 +0000 | [diff] [blame] | 230 | // An optimized version of clipDevRect(emptyRect, kIntersect, ...) |
| 231 | void clipEmpty(); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 232 | |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 233 | /** |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 234 | * isWideOpen returns true if the clip state corresponds to the infinite |
robertphillips@google.com | cc6493b | 2012-07-26 18:39:13 +0000 | [diff] [blame] | 235 | * plane (i.e., draws are not limited at all) |
| 236 | */ |
| 237 | bool isWideOpen() const; |
| 238 | |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 239 | /** |
| 240 | * Add a callback function that will be called whenever a clip state |
| 241 | * is no longer viable. This will occur whenever restore |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 242 | * is called or when a clipDevRect or clipDevPath call updates the |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 243 | * clip within an existing save/restore state. Each clip state is |
| 244 | * represented by a unique generation ID. |
| 245 | */ |
| 246 | typedef void (*PFPurgeClipCB)(int genID, void* data); |
| 247 | void addPurgeClipCallback(PFPurgeClipCB callback, void* data) const; |
| 248 | |
| 249 | /** |
| 250 | * Remove a callback added earlier via addPurgeClipCallback |
| 251 | */ |
| 252 | void removePurgeClipCallback(PFPurgeClipCB callback, void* data) const; |
| 253 | |
| 254 | /** |
| 255 | * The generation ID has three reserved values to indicate special |
bsalomon@google.com | e8ca6c6 | 2012-11-07 21:19:10 +0000 | [diff] [blame] | 256 | * (potentially ignorable) cases |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 257 | */ |
| 258 | static const int32_t kInvalidGenID = 0; |
| 259 | static const int32_t kEmptyGenID = 1; // no pixels writeable |
| 260 | static const int32_t kWideOpenGenID = 2; // all pixels writeable |
| 261 | |
robertphillips@google.com | 73e7102 | 2012-08-09 18:10:49 +0000 | [diff] [blame] | 262 | int32_t getTopmostGenID() const; |
| 263 | |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 264 | public: |
| 265 | class Iter { |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 266 | public: |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 267 | enum IterStart { |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 268 | kBottom_IterStart = SkDeque::Iter::kFront_IterStart, |
| 269 | kTop_IterStart = SkDeque::Iter::kBack_IterStart |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 270 | }; |
| 271 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 272 | /** |
| 273 | * Creates an uninitialized iterator. Must be reset() |
| 274 | */ |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 275 | Iter(); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 276 | |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 277 | Iter(const SkClipStack& stack, IterStart startLoc); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 278 | |
| 279 | struct Clip { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 280 | Clip() : fRect(NULL), fPath(NULL), fOp(SkRegion::kIntersect_Op), |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 281 | fDoAA(false), fGenID(kInvalidGenID) {} |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 282 | friend bool operator==(const Clip& a, const Clip& b); |
vandebo@chromium.org | 8887ede | 2011-05-25 01:27:52 +0000 | [diff] [blame] | 283 | friend bool operator!=(const Clip& a, const Clip& b); |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 284 | /** |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 285 | * Gets the bounds of the clip element, either the rect or path bounds. (Whether the |
| 286 | * shape is inverse filled is not considered) |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 287 | */ |
| 288 | const SkRect& getBounds() const; |
| 289 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 290 | /** |
| 291 | * Conservatively checks whether the clip shape (rect/path) contains the rect param. |
| 292 | * (Whether the shape is inverse filled is not considered) |
| 293 | */ |
| 294 | bool contains(const SkRect&) const; |
| 295 | |
| 296 | /** |
| 297 | * Is the clip shape inverse filled. |
| 298 | */ |
| 299 | bool isInverseFilled() const; |
| 300 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 301 | const SkRect* fRect; // if non-null, this is a rect clip |
| 302 | const SkPath* fPath; // if non-null, this is a path clip |
| 303 | SkRegion::Op fOp; |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 304 | bool fDoAA; |
robertphillips@google.com | 73e7102 | 2012-08-09 18:10:49 +0000 | [diff] [blame] | 305 | int32_t fGenID; |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 306 | }; |
| 307 | |
| 308 | /** |
| 309 | * Return the clip for this element in the iterator. If next() returns |
| 310 | * NULL, then the iterator is done. The type of clip is determined by |
| 311 | * the pointers fRect and fPath: |
| 312 | * |
| 313 | * fRect==NULL fPath!=NULL path clip |
| 314 | * fRect!=NULL fPath==NULL rect clip |
| 315 | * fRect==NULL fPath==NULL empty clip |
| 316 | */ |
| 317 | const Clip* next(); |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 318 | const Clip* prev(); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 319 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 320 | /** |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 321 | * Moves the iterator to the topmost clip with the specified RegionOp |
| 322 | * and returns that clip. If no clip with that op is found, |
robertphillips@google.com | 5836b6d | 2012-07-18 12:06:15 +0000 | [diff] [blame] | 323 | * returns NULL. |
| 324 | */ |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 325 | const Clip* skipToTopmost(SkRegion::Op op); |
robertphillips@google.com | 5836b6d | 2012-07-18 12:06:15 +0000 | [diff] [blame] | 326 | |
| 327 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 328 | * Restarts the iterator on a clip stack. |
| 329 | */ |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 330 | void reset(const SkClipStack& stack, IterStart startLoc); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 331 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 332 | private: |
robertphillips@google.com | 5836b6d | 2012-07-18 12:06:15 +0000 | [diff] [blame] | 333 | const SkClipStack* fStack; |
| 334 | Clip fClip; |
| 335 | SkDeque::Iter fIter; |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 336 | /** |
| 337 | * updateClip updates fClip to the current state of fIter. It unifies |
| 338 | * functionality needed by both next() and prev(). |
| 339 | */ |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 340 | const Clip* updateClip(const SkClipStack::Element* element); |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 341 | }; |
| 342 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 343 | /** |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 344 | * The B2TIter iterates from the bottom of the stack to the top. |
| 345 | * It inherits privately from Iter to prevent access to reverse iteration. |
| 346 | */ |
| 347 | class B2TIter : private Iter { |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 348 | public: |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 349 | B2TIter() {} |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 350 | |
| 351 | /** |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 352 | * Wrap Iter's 2 parameter ctor to force initialization to the |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 353 | * beginning of the deque/bottom of the stack |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 354 | */ |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 355 | B2TIter(const SkClipStack& stack) |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 356 | : INHERITED(stack, kBottom_IterStart) { |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | using Iter::Clip; |
| 360 | using Iter::next; |
| 361 | |
| 362 | /** |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 363 | * Wrap Iter::reset to force initialization to the |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 364 | * beginning of the deque/bottom of the stack |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 365 | */ |
| 366 | void reset(const SkClipStack& stack) { |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 367 | this->INHERITED::reset(stack, kBottom_IterStart); |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | private: |
| 371 | |
| 372 | typedef Iter INHERITED; |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 373 | }; |
| 374 | |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 375 | /** |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 376 | * GetConservativeBounds returns a conservative bound of the current clip. |
| 377 | * Since this could be the infinite plane (if inverse fills were involved) the |
| 378 | * maxWidth and maxHeight parameters can be used to limit the returned bound |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 379 | * to the expected drawing area. Similarly, the offsetX and offsetY parameters |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 380 | * allow the caller to offset the returned bound to account for translated |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 381 | * drawing areas (i.e., those resulting from a saveLayer). For finite bounds, |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 382 | * the translation (+offsetX, +offsetY) is applied before the clamp to the |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 383 | * maximum rectangle: [0,maxWidth) x [0,maxHeight). |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 384 | * isIntersectionOfRects is an optional parameter that is true when |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 385 | * 'devBounds' is the result of an intersection of rects. In this case |
| 386 | * 'devBounds' is the exact answer/clip. |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 387 | */ |
| 388 | void getConservativeBounds(int offsetX, |
| 389 | int offsetY, |
| 390 | int maxWidth, |
| 391 | int maxHeight, |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 392 | SkRect* devBounds, |
robertphillips@google.com | 4c2a2f7 | 2012-07-24 22:07:50 +0000 | [diff] [blame] | 393 | bool* isIntersectionOfRects = NULL) const; |
robertphillips@google.com | 607fe07 | 2012-07-24 13:54:00 +0000 | [diff] [blame] | 394 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 395 | private: |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 396 | friend class Iter; |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 397 | |
| 398 | SkDeque fDeque; |
| 399 | int fSaveCount; |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 400 | |
| 401 | // Generation ID for the clip stack. This is incremented for each |
| 402 | // clipDevRect and clipDevPath call. 0 is reserved to indicate an |
| 403 | // invalid ID. |
| 404 | static int32_t gGenID; |
| 405 | |
| 406 | struct ClipCallbackData { |
| 407 | PFPurgeClipCB fCallback; |
| 408 | void* fData; |
| 409 | |
| 410 | friend bool operator==(const ClipCallbackData& a, |
| 411 | const ClipCallbackData& b) { |
| 412 | return a.fCallback == b.fCallback && a.fData == b.fData; |
| 413 | } |
| 414 | }; |
| 415 | |
| 416 | mutable SkTDArray<ClipCallbackData> fCallbackData; |
| 417 | |
| 418 | /** |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 419 | * Invoke all the purge callbacks passing in element's generation ID. |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 420 | */ |
bsalomon@google.com | 9128edc | 2012-11-29 18:58:19 +0000 | [diff] [blame] | 421 | void purgeClip(Element* element); |
robertphillips@google.com | 46f9350 | 2012-08-07 15:38:08 +0000 | [diff] [blame] | 422 | |
| 423 | /** |
| 424 | * Return the next unique generation ID. |
| 425 | */ |
| 426 | static int32_t GetNextGenID(); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 427 | }; |
| 428 | |
| 429 | #endif |
| 430 | |