blob: 028d5515606815c82de9d3c232edf8d97eb23e85 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.com5c3d1472011-02-22 19:12:23 +00008#ifndef SkClipStack_DEFINED
9#define SkClipStack_DEFINED
10
11#include "SkDeque.h"
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000012#include "SkPath.h"
13#include "SkRect.h"
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000014#include "SkRRect.h"
reed@google.com5c3d1472011-02-22 19:12:23 +000015#include "SkRegion.h"
robertphillips@google.com46f93502012-08-07 15:38:08 +000016#include "SkTDArray.h"
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +000017#include "SkTLazy.h"
reed@google.com5c3d1472011-02-22 19:12:23 +000018
reed@google.com5c3d1472011-02-22 19:12:23 +000019
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +000020// Because a single save/restore state can have multiple clips, this class
21// stores the stack depth (fSaveCount) and clips (fDeque) separately.
22// Each clip in fDeque stores the stack state to which it belongs
23// (i.e., the fSaveCount in force when it was added). Restores are thus
24// implemented by removing clips from fDeque that have an fSaveCount larger
25// then the freshly decremented count.
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000026class SK_API SkClipStack {
reed@google.com5c3d1472011-02-22 19:12:23 +000027public:
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000028 enum BoundsType {
29 // The bounding box contains all the pixels that can be written to
30 kNormal_BoundsType,
31 // The bounding box contains all the pixels that cannot be written to.
32 // The real bound extends out to infinity and all the pixels outside
33 // of the bound can be written to. Note that some of the pixels inside
34 // the bound may also be writeable but all pixels that cannot be
35 // written to are guaranteed to be inside.
36 kInsideOut_BoundsType
37 };
38
39 class Element {
40 public:
41 enum Type {
42 //!< This element makes the clip empty (regardless of previous elements).
43 kEmpty_Type,
44 //!< This element combines a rect with the current clip using a set operation
45 kRect_Type,
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000046 //!< This element combines a round-rect with the current clip using a set operation
47 kRRect_Type,
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000048 //!< This element combines a path with the current clip using a set operation
49 kPath_Type,
50 };
51
52 Element() {
53 this->initCommon(0, SkRegion::kReplace_Op, false);
54 this->setEmpty();
55 }
56
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +000057 Element(const Element&);
58
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000059 Element(const SkRect& rect, SkRegion::Op op, bool doAA) {
60 this->initRect(0, rect, op, doAA);
61 }
62
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000063 Element(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
64 this->initRRect(0, rrect, op, doAA);
65 }
66
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000067 Element(const SkPath& path, SkRegion::Op op, bool doAA) {
68 this->initPath(0, path, op, doAA);
69 }
70
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000071 bool operator== (const Element& element) const;
bsalomon@google.com8182fa02012-12-04 14:06:06 +000072 bool operator!= (const Element& element) const { return !(*this == element); }
73
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000074 //!< Call to get the type of the clip element.
75 Type getType() const { return fType; }
76
77 //!< Call if getType() is kPath to get the path.
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +000078 const SkPath& getPath() const { SkASSERT(kPath_Type == fType); return *fPath.get(); }
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000079
80 //!< Call if getType() is kRRect to get the round-rect.
81 const SkRRect& getRRect() const { SkASSERT(kRRect_Type == fType); return fRRect; }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000082
83 //!< Call if getType() is kRect to get the rect.
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +000084 const SkRect& getRect() const {
85 SkASSERT(kRect_Type == fType && (fRRect.isRect() || fRRect.isEmpty()));
86 return fRRect.getBounds();
87 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000088
89 //!< Call if getType() is not kEmpty to get the set operation used to combine this element.
90 SkRegion::Op getOp() const { return fOp; }
91
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000092 //!< Call to get the element as a path, regardless of its type.
93 void asPath(SkPath* path) const;
94
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000095 /** If getType() is not kEmpty this indicates whether the clip shape should be anti-aliased
96 when it is rasterized. */
97 bool isAA() const { return fDoAA; }
98
bsalomon@google.comc6b3e482012-12-07 20:43:52 +000099 //!< Inverts the fill of the clip shape. Note that a kEmpty element remains kEmpty.
100 void invertShapeFillType();
101
102 //!< Sets the set operation represented by the element.
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000103 void setOp(SkRegion::Op op) { fOp = op; }
104
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000105 /** The GenID can be used by clip stack clients to cache representations of the clip. The
106 ID corresponds to the set of clip elements up to and including this element within the
107 stack not to the element itself. That is the same clip path in different stacks will
108 have a different ID since the elements produce different clip result in the context of
109 their stacks. */
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000110 int32_t getGenID() const { SkASSERT(kInvalidGenID != fGenID); return fGenID; }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000111
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000112 /**
113 * Gets the bounds of the clip element, either the rect or path bounds. (Whether the shape
114 * is inverse filled is not considered.)
115 */
116 const SkRect& getBounds() const {
117 static const SkRect kEmpty = { 0, 0, 0, 0 };
118 switch (fType) {
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000119 case kRect_Type: // fallthrough
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000120 case kRRect_Type:
121 return fRRect.getBounds();
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000122 case kPath_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000123 return fPath.get()->getBounds();
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000124 case kEmpty_Type:
125 return kEmpty;
126 default:
127 SkDEBUGFAIL("Unexpected type.");
128 return kEmpty;
129 }
130 }
131
132 /**
133 * Conservatively checks whether the clip shape contains the rect param. (Whether the shape
134 * is inverse filled is not considered.)
135 */
136 bool contains(const SkRect& rect) const {
137 switch (fType) {
138 case kRect_Type:
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000139 return this->getRect().contains(rect);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000140 case kRRect_Type:
141 return fRRect.contains(rect);
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000142 case kPath_Type:
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000143 return fPath.get()->conservativelyContainsRect(rect);
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000144 case kEmpty_Type:
145 return false;
146 default:
147 SkDEBUGFAIL("Unexpected type.");
148 return false;
149 }
150 }
151
152 /**
153 * Is the clip shape inverse filled.
154 */
155 bool isInverseFilled() const {
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000156 return kPath_Type == fType && fPath.get()->isInverseFillType();
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000157 }
158
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000159 private:
160 friend class SkClipStack;
161
commit-bot@chromium.org6f954b92014-02-27 17:39:46 +0000162 SkTLazy<SkPath> fPath;
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000163 SkRRect fRRect;
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000164 int fSaveCount; // save count of stack when this element was added.
165 SkRegion::Op fOp;
166 Type fType;
167 bool fDoAA;
168
169 /* fFiniteBoundType and fFiniteBound are used to incrementally update the clip stack's
170 bound. When fFiniteBoundType is kNormal_BoundsType, fFiniteBound represents the
171 conservative bounding box of the pixels that aren't clipped (i.e., any pixels that can be
172 drawn to are inside the bound). When fFiniteBoundType is kInsideOut_BoundsType (which
173 occurs when a clip is inverse filled), fFiniteBound represents the conservative bounding
174 box of the pixels that _are_ clipped (i.e., any pixels that cannot be drawn to are inside
175 the bound). When fFiniteBoundType is kInsideOut_BoundsType the actual bound is the
176 infinite plane. This behavior of fFiniteBoundType and fFiniteBound is required so that we
177 can capture the cancelling out of the extensions to infinity when two inverse filled
178 clips are Booleaned together. */
179 SkClipStack::BoundsType fFiniteBoundType;
180 SkRect fFiniteBound;
skia.committer@gmail.comc3d7d902012-11-30 02:01:24 +0000181
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000182 // When element is applied to the previous elements in the stack is the result known to be
183 // equivalent to a single rect intersection? IIOW, is the clip effectively a rectangle.
184 bool fIsIntersectionOfRects;
185
186 int fGenID;
187
188 Element(int saveCount) {
189 this->initCommon(saveCount, SkRegion::kReplace_Op, false);
190 this->setEmpty();
191 }
192
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000193 Element(int saveCount, const SkRRect& rrect, SkRegion::Op op, bool doAA) {
194 this->initRRect(saveCount, rrect, op, doAA);
195 }
196
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000197 Element(int saveCount, const SkRect& rect, SkRegion::Op op, bool doAA) {
198 this->initRect(saveCount, rect, op, doAA);
199 }
200
201 Element(int saveCount, const SkPath& path, SkRegion::Op op, bool doAA) {
202 this->initPath(saveCount, path, op, doAA);
203 }
204
205 void initCommon(int saveCount, SkRegion::Op op, bool doAA) {
206 fSaveCount = saveCount;
207 fOp = op;
208 fDoAA = doAA;
209 // A default of inside-out and empty bounds means the bounds are effectively void as it
210 // indicates that nothing is known to be outside the clip.
211 fFiniteBoundType = kInsideOut_BoundsType;
212 fFiniteBound.setEmpty();
213 fIsIntersectionOfRects = false;
214 fGenID = kInvalidGenID;
215 }
216
217 void initRect(int saveCount, const SkRect& rect, SkRegion::Op op, bool doAA) {
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000218 fRRect.setRect(rect);
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000219 fType = kRect_Type;
220 this->initCommon(saveCount, op, doAA);
221 }
222
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000223 void initRRect(int saveCount, const SkRRect& rrect, SkRegion::Op op, bool doAA) {
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000224 SkRRect::Type type = rrect.getType();
225 fRRect = rrect;
226 if (SkRRect::kRect_Type == type || SkRRect::kEmpty_Type == type) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000227 fType = kRect_Type;
228 } else {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000229 fType = kRRect_Type;
230 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000231 this->initCommon(saveCount, op, doAA);
232 }
233
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000234 void initPath(int saveCount, const SkPath& path, SkRegion::Op op, bool doAA);
235
commit-bot@chromium.org9cb671a2014-02-16 14:45:45 +0000236 void setEmpty();
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000237
238 // All Element methods below are only used within SkClipStack.cpp
239 inline void checkEmpty() const;
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000240 inline bool canBeIntersectedInPlace(int saveCount, SkRegion::Op op) const;
241 /* This method checks to see if two rect clips can be safely merged into one. The issue here
skia.committer@gmail.comc3d7d902012-11-30 02:01:24 +0000242 is that to be strictly correct all the edges of the resulting rect must have the same
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000243 anti-aliasing. */
244 bool rectRectIntersectAllowed(const SkRect& newR, bool newAA) const;
245 /** Determines possible finite bounds for the Element given the previous element of the
246 stack */
247 void updateBoundAndGenID(const Element* prior);
248 // The different combination of fill & inverse fill when combining bounding boxes
249 enum FillCombo {
250 kPrev_Cur_FillCombo,
251 kPrev_InvCur_FillCombo,
252 kInvPrev_Cur_FillCombo,
253 kInvPrev_InvCur_FillCombo
254 };
255 // per-set operation functions used by updateBoundAndGenID().
256 inline void combineBoundsDiff(FillCombo combination, const SkRect& prevFinite);
257 inline void combineBoundsXOR(int combination, const SkRect& prevFinite);
258 inline void combineBoundsUnion(int combination, const SkRect& prevFinite);
259 inline void combineBoundsIntersection(int combination, const SkRect& prevFinite);
260 inline void combineBoundsRevDiff(int combination, const SkRect& prevFinite);
261 };
262
reed@google.com5c3d1472011-02-22 19:12:23 +0000263 SkClipStack();
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000264 SkClipStack(const SkClipStack& b);
robertphillips@google.comcc6493b2012-07-26 18:39:13 +0000265 explicit SkClipStack(const SkRect& r);
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000266 explicit SkClipStack(const SkIRect& r);
vandebo@chromium.org610f7162012-03-14 18:34:15 +0000267 ~SkClipStack();
reed@google.com5c3d1472011-02-22 19:12:23 +0000268
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000269 SkClipStack& operator=(const SkClipStack& b);
270 bool operator==(const SkClipStack& b) const;
271 bool operator!=(const SkClipStack& b) const { return !(*this == b); }
272
reed@google.com5c3d1472011-02-22 19:12:23 +0000273 void reset();
274
275 int getSaveCount() const { return fSaveCount; }
276 void save();
277 void restore();
278
robertphillips@google.com607fe072012-07-24 13:54:00 +0000279 /**
280 * getBounds places the current finite bound in its first parameter. In its
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000281 * second, it indicates which kind of bound is being returned. If
robertphillips@google.com7b112892012-07-31 15:18:21 +0000282 * 'canvFiniteBound' is a normal bounding box then it encloses all writeable
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000283 * pixels. If 'canvFiniteBound' is an inside out bounding box then it
robertphillips@google.com607fe072012-07-24 13:54:00 +0000284 * encloses all the un-writeable pixels and the true/normal bound is the
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000285 * infinite plane. isIntersectionOfRects is an optional parameter
robertphillips@google.com7b112892012-07-31 15:18:21 +0000286 * that is true if 'canvFiniteBound' resulted from an intersection of rects.
robertphillips@google.com607fe072012-07-24 13:54:00 +0000287 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000288 void getBounds(SkRect* canvFiniteBound,
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000289 BoundsType* boundType,
290 bool* isIntersectionOfRects = NULL) const;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000291
bsalomon@google.com3ab43d52012-10-11 19:39:09 +0000292 /**
293 * Takes an input rect in device space and conservatively clips it to the
294 * clip-stack. If false is returned then the rect does not intersect the
295 * clip and is unmodified.
296 */
297 bool intersectRectWithClip(SkRect* devRect) const;
298
junov@chromium.org8cdf0f52012-12-12 17:58:15 +0000299 /**
300 * Returns true if the input rect in device space is entirely contained
301 * by the clip. A return value of false does not guarantee that the rect
302 * is not contained by the clip.
303 */
304 bool quickContains(const SkRect& devRect) const;
305
reed@google.com115d9312012-05-16 18:50:40 +0000306 void clipDevRect(const SkIRect& ir, SkRegion::Op op) {
reed@google.com5c3d1472011-02-22 19:12:23 +0000307 SkRect r;
308 r.set(ir);
reed@google.com00177082011-10-12 14:34:30 +0000309 this->clipDevRect(r, op, false);
reed@google.com5c3d1472011-02-22 19:12:23 +0000310 }
reed@google.com00177082011-10-12 14:34:30 +0000311 void clipDevRect(const SkRect&, SkRegion::Op, bool doAA);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000312 void clipDevRRect(const SkRRect&, SkRegion::Op, bool doAA);
reed@google.com00177082011-10-12 14:34:30 +0000313 void clipDevPath(const SkPath&, SkRegion::Op, bool doAA);
reed@google.com0557d9e2012-08-16 15:59:59 +0000314 // An optimized version of clipDevRect(emptyRect, kIntersect, ...)
315 void clipEmpty();
reed@google.com5c3d1472011-02-22 19:12:23 +0000316
robertphillips@google.comcc6493b2012-07-26 18:39:13 +0000317 /**
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000318 * isWideOpen returns true if the clip state corresponds to the infinite
robertphillips@google.comcc6493b2012-07-26 18:39:13 +0000319 * plane (i.e., draws are not limited at all)
320 */
321 bool isWideOpen() const;
322
robertphillips@google.com46f93502012-08-07 15:38:08 +0000323 /**
robertphillips@google.com46f93502012-08-07 15:38:08 +0000324 * The generation ID has three reserved values to indicate special
bsalomon@google.come8ca6c62012-11-07 21:19:10 +0000325 * (potentially ignorable) cases
robertphillips@google.com46f93502012-08-07 15:38:08 +0000326 */
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000327 static const int32_t kInvalidGenID = 0; //!< Invalid id that is never returned by
328 //!< SkClipStack. Useful when caching clips
329 //!< based on GenID.
robertphillips@google.com46f93502012-08-07 15:38:08 +0000330 static const int32_t kEmptyGenID = 1; // no pixels writeable
331 static const int32_t kWideOpenGenID = 2; // all pixels writeable
332
robertphillips@google.com73e71022012-08-09 18:10:49 +0000333 int32_t getTopmostGenID() const;
334
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000335public:
336 class Iter {
reed@google.com5c3d1472011-02-22 19:12:23 +0000337 public:
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000338 enum IterStart {
robertphillips@google.com80214e22012-07-20 15:33:18 +0000339 kBottom_IterStart = SkDeque::Iter::kFront_IterStart,
340 kTop_IterStart = SkDeque::Iter::kBack_IterStart
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000341 };
342
bsalomon@google.comd302f142011-03-03 13:54:13 +0000343 /**
344 * Creates an uninitialized iterator. Must be reset()
345 */
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000346 Iter();
bsalomon@google.comd302f142011-03-03 13:54:13 +0000347
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000348 Iter(const SkClipStack& stack, IterStart startLoc);
reed@google.com5c3d1472011-02-22 19:12:23 +0000349
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000350 /**
351 * Return the clip element for this iterator. If next()/prev() returns NULL, then the
352 * iterator is done.
353 */
354 const Element* next();
355 const Element* prev();
reed@google.com5c3d1472011-02-22 19:12:23 +0000356
357 /**
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000358 * Moves the iterator to the topmost element with the specified RegionOp and returns that
359 * element. If no clip element with that op is found, the first element is returned.
reed@google.com5c3d1472011-02-22 19:12:23 +0000360 */
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000361 const Element* skipToTopmost(SkRegion::Op op);
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000362
363 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000364 * Restarts the iterator on a clip stack.
365 */
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000366 void reset(const SkClipStack& stack, IterStart startLoc);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000367
reed@google.com5c3d1472011-02-22 19:12:23 +0000368 private:
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000369 const SkClipStack* fStack;
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000370 SkDeque::Iter fIter;
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000371 };
372
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000373 /**
robertphillips@google.com80214e22012-07-20 15:33:18 +0000374 * The B2TIter iterates from the bottom of the stack to the top.
375 * It inherits privately from Iter to prevent access to reverse iteration.
376 */
377 class B2TIter : private Iter {
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000378 public:
robertphillips@google.com80214e22012-07-20 15:33:18 +0000379 B2TIter() {}
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000380
381 /**
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000382 * Wrap Iter's 2 parameter ctor to force initialization to the
robertphillips@google.com80214e22012-07-20 15:33:18 +0000383 * beginning of the deque/bottom of the stack
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000384 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000385 B2TIter(const SkClipStack& stack)
robertphillips@google.com80214e22012-07-20 15:33:18 +0000386 : INHERITED(stack, kBottom_IterStart) {
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000387 }
388
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000389 using Iter::next;
390
391 /**
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000392 * Wrap Iter::reset to force initialization to the
robertphillips@google.com80214e22012-07-20 15:33:18 +0000393 * beginning of the deque/bottom of the stack
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000394 */
395 void reset(const SkClipStack& stack) {
robertphillips@google.com80214e22012-07-20 15:33:18 +0000396 this->INHERITED::reset(stack, kBottom_IterStart);
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000397 }
398
399 private:
400
401 typedef Iter INHERITED;
reed@google.com5c3d1472011-02-22 19:12:23 +0000402 };
403
robertphillips@google.com607fe072012-07-24 13:54:00 +0000404 /**
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000405 * GetConservativeBounds returns a conservative bound of the current clip.
406 * Since this could be the infinite plane (if inverse fills were involved) the
407 * maxWidth and maxHeight parameters can be used to limit the returned bound
robertphillips@google.com607fe072012-07-24 13:54:00 +0000408 * to the expected drawing area. Similarly, the offsetX and offsetY parameters
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000409 * allow the caller to offset the returned bound to account for translated
robertphillips@google.com607fe072012-07-24 13:54:00 +0000410 * drawing areas (i.e., those resulting from a saveLayer). For finite bounds,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000411 * the translation (+offsetX, +offsetY) is applied before the clamp to the
robertphillips@google.com607fe072012-07-24 13:54:00 +0000412 * maximum rectangle: [0,maxWidth) x [0,maxHeight).
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000413 * isIntersectionOfRects is an optional parameter that is true when
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000414 * 'devBounds' is the result of an intersection of rects. In this case
415 * 'devBounds' is the exact answer/clip.
robertphillips@google.com607fe072012-07-24 13:54:00 +0000416 */
417 void getConservativeBounds(int offsetX,
418 int offsetY,
419 int maxWidth,
420 int maxHeight,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000421 SkRect* devBounds,
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000422 bool* isIntersectionOfRects = NULL) const;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000423
reed@google.com5c3d1472011-02-22 19:12:23 +0000424private:
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000425 friend class Iter;
reed@google.com5c3d1472011-02-22 19:12:23 +0000426
427 SkDeque fDeque;
428 int fSaveCount;
robertphillips@google.com46f93502012-08-07 15:38:08 +0000429
430 // Generation ID for the clip stack. This is incremented for each
431 // clipDevRect and clipDevPath call. 0 is reserved to indicate an
432 // invalid ID.
433 static int32_t gGenID;
434
robertphillips@google.com46f93502012-08-07 15:38:08 +0000435 /**
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000436 * Helper for clipDevPath, etc.
437 */
438 void pushElement(const Element& element);
439
440 /**
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000441 * Restore the stack back to the specified save count.
442 */
443 void restoreTo(int saveCount);
444
445 /**
robertphillips@google.com46f93502012-08-07 15:38:08 +0000446 * Return the next unique generation ID.
447 */
448 static int32_t GetNextGenID();
reed@google.com5c3d1472011-02-22 19:12:23 +0000449};
450
451#endif