blob: 5da53ae89434460e5f2ed1ab2a92440187265e43 [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"
reed@google.com5c3d1472011-02-22 19:12:23 +000017
reed@google.com5c3d1472011-02-22 19:12:23 +000018
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +000019// Because a single save/restore state can have multiple clips, this class
20// stores the stack depth (fSaveCount) and clips (fDeque) separately.
21// Each clip in fDeque stores the stack state to which it belongs
22// (i.e., the fSaveCount in force when it was added). Restores are thus
23// implemented by removing clips from fDeque that have an fSaveCount larger
24// then the freshly decremented count.
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000025class SK_API SkClipStack {
reed@google.com5c3d1472011-02-22 19:12:23 +000026public:
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000027 enum BoundsType {
28 // The bounding box contains all the pixels that can be written to
29 kNormal_BoundsType,
30 // The bounding box contains all the pixels that cannot be written to.
31 // The real bound extends out to infinity and all the pixels outside
32 // of the bound can be written to. Note that some of the pixels inside
33 // the bound may also be writeable but all pixels that cannot be
34 // written to are guaranteed to be inside.
35 kInsideOut_BoundsType
36 };
37
38 class Element {
39 public:
40 enum Type {
41 //!< This element makes the clip empty (regardless of previous elements).
42 kEmpty_Type,
43 //!< This element combines a rect with the current clip using a set operation
44 kRect_Type,
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000045 //!< This element combines a round-rect with the current clip using a set operation
46 kRRect_Type,
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000047 //!< This element combines a path with the current clip using a set operation
48 kPath_Type,
49 };
50
51 Element() {
52 this->initCommon(0, SkRegion::kReplace_Op, false);
53 this->setEmpty();
54 }
55
56 Element(const SkRect& rect, SkRegion::Op op, bool doAA) {
57 this->initRect(0, rect, op, doAA);
58 }
59
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000060 Element(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
61 this->initRRect(0, rrect, op, doAA);
62 }
63
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000064 Element(const SkPath& path, SkRegion::Op op, bool doAA) {
65 this->initPath(0, path, op, doAA);
66 }
67
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000068 bool operator== (const Element& element) const;
bsalomon@google.com8182fa02012-12-04 14:06:06 +000069 bool operator!= (const Element& element) const { return !(*this == element); }
70
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000071 //!< Call to get the type of the clip element.
72 Type getType() const { return fType; }
73
74 //!< Call if getType() is kPath to get the path.
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000075 const SkPath& getPath() const { SkASSERT(kPath_Type == fType); return fPath; }
76
77 //!< Call if getType() is kRRect to get the round-rect.
78 const SkRRect& getRRect() const { SkASSERT(kRRect_Type == fType); return fRRect; }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000079
80 //!< Call if getType() is kRect to get the rect.
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +000081 const SkRect& getRect() const {
82 SkASSERT(kRect_Type == fType && (fRRect.isRect() || fRRect.isEmpty()));
83 return fRRect.getBounds();
84 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000085
86 //!< Call if getType() is not kEmpty to get the set operation used to combine this element.
87 SkRegion::Op getOp() const { return fOp; }
88
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +000089 //!< Call to get the element as a path, regardless of its type.
90 void asPath(SkPath* path) const;
91
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +000092 /** If getType() is not kEmpty this indicates whether the clip shape should be anti-aliased
93 when it is rasterized. */
94 bool isAA() const { return fDoAA; }
95
bsalomon@google.comc6b3e482012-12-07 20:43:52 +000096 //!< Inverts the fill of the clip shape. Note that a kEmpty element remains kEmpty.
97 void invertShapeFillType();
98
99 //!< Sets the set operation represented by the element.
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000100 void setOp(SkRegion::Op op) { fOp = op; }
101
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000102 /** The GenID can be used by clip stack clients to cache representations of the clip. The
103 ID corresponds to the set of clip elements up to and including this element within the
104 stack not to the element itself. That is the same clip path in different stacks will
105 have a different ID since the elements produce different clip result in the context of
106 their stacks. */
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000107 int32_t getGenID() const { SkASSERT(kInvalidGenID != fGenID); return fGenID; }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000108
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000109 /**
110 * Gets the bounds of the clip element, either the rect or path bounds. (Whether the shape
111 * is inverse filled is not considered.)
112 */
113 const SkRect& getBounds() const {
114 static const SkRect kEmpty = { 0, 0, 0, 0 };
115 switch (fType) {
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000116 case kRect_Type: // fallthrough
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000117 case kRRect_Type:
118 return fRRect.getBounds();
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000119 case kPath_Type:
120 return fPath.getBounds();
121 case kEmpty_Type:
122 return kEmpty;
123 default:
124 SkDEBUGFAIL("Unexpected type.");
125 return kEmpty;
126 }
127 }
128
129 /**
130 * Conservatively checks whether the clip shape contains the rect param. (Whether the shape
131 * is inverse filled is not considered.)
132 */
133 bool contains(const SkRect& rect) const {
134 switch (fType) {
135 case kRect_Type:
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000136 return this->getRect().contains(rect);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000137 case kRRect_Type:
138 return fRRect.contains(rect);
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000139 case kPath_Type:
140 return fPath.conservativelyContainsRect(rect);
141 case kEmpty_Type:
142 return false;
143 default:
144 SkDEBUGFAIL("Unexpected type.");
145 return false;
146 }
147 }
148
149 /**
150 * Is the clip shape inverse filled.
151 */
152 bool isInverseFilled() const {
153 return kPath_Type == fType && fPath.isInverseFillType();
154 }
155
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000156 private:
157 friend class SkClipStack;
158
159 SkPath fPath;
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000160 SkRRect fRRect;
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000161 int fSaveCount; // save count of stack when this element was added.
162 SkRegion::Op fOp;
163 Type fType;
164 bool fDoAA;
165
166 /* fFiniteBoundType and fFiniteBound are used to incrementally update the clip stack's
167 bound. When fFiniteBoundType is kNormal_BoundsType, fFiniteBound represents the
168 conservative bounding box of the pixels that aren't clipped (i.e., any pixels that can be
169 drawn to are inside the bound). When fFiniteBoundType is kInsideOut_BoundsType (which
170 occurs when a clip is inverse filled), fFiniteBound represents the conservative bounding
171 box of the pixels that _are_ clipped (i.e., any pixels that cannot be drawn to are inside
172 the bound). When fFiniteBoundType is kInsideOut_BoundsType the actual bound is the
173 infinite plane. This behavior of fFiniteBoundType and fFiniteBound is required so that we
174 can capture the cancelling out of the extensions to infinity when two inverse filled
175 clips are Booleaned together. */
176 SkClipStack::BoundsType fFiniteBoundType;
177 SkRect fFiniteBound;
skia.committer@gmail.comc3d7d902012-11-30 02:01:24 +0000178
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000179 // When element is applied to the previous elements in the stack is the result known to be
180 // equivalent to a single rect intersection? IIOW, is the clip effectively a rectangle.
181 bool fIsIntersectionOfRects;
182
183 int fGenID;
184
185 Element(int saveCount) {
186 this->initCommon(saveCount, SkRegion::kReplace_Op, false);
187 this->setEmpty();
188 }
189
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000190 Element(int saveCount, const SkRRect& rrect, SkRegion::Op op, bool doAA) {
191 this->initRRect(saveCount, rrect, op, doAA);
192 }
193
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000194 Element(int saveCount, const SkRect& rect, SkRegion::Op op, bool doAA) {
195 this->initRect(saveCount, rect, op, doAA);
196 }
197
198 Element(int saveCount, const SkPath& path, SkRegion::Op op, bool doAA) {
199 this->initPath(saveCount, path, op, doAA);
200 }
201
202 void initCommon(int saveCount, SkRegion::Op op, bool doAA) {
203 fSaveCount = saveCount;
204 fOp = op;
205 fDoAA = doAA;
206 // A default of inside-out and empty bounds means the bounds are effectively void as it
207 // indicates that nothing is known to be outside the clip.
208 fFiniteBoundType = kInsideOut_BoundsType;
209 fFiniteBound.setEmpty();
210 fIsIntersectionOfRects = false;
211 fGenID = kInvalidGenID;
212 }
213
214 void initRect(int saveCount, const SkRect& rect, SkRegion::Op op, bool doAA) {
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000215 fRRect.setRect(rect);
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000216 fType = kRect_Type;
217 this->initCommon(saveCount, op, doAA);
218 }
219
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000220 void initRRect(int saveCount, const SkRRect& rrect, SkRegion::Op op, bool doAA) {
commit-bot@chromium.org032a52f2014-02-21 20:09:13 +0000221 SkRRect::Type type = rrect.getType();
222 fRRect = rrect;
223 if (SkRRect::kRect_Type == type || SkRRect::kEmpty_Type == type) {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000224 fType = kRect_Type;
225 } else {
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000226 fType = kRRect_Type;
227 }
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000228 this->initCommon(saveCount, op, doAA);
229 }
230
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000231 void initPath(int saveCount, const SkPath& path, SkRegion::Op op, bool doAA);
232
commit-bot@chromium.org9cb671a2014-02-16 14:45:45 +0000233 void setEmpty();
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000234
235 // All Element methods below are only used within SkClipStack.cpp
236 inline void checkEmpty() const;
bsalomon@google.com8a98e3b2012-11-29 21:05:13 +0000237 inline bool canBeIntersectedInPlace(int saveCount, SkRegion::Op op) const;
238 /* 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 +0000239 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 +0000240 anti-aliasing. */
241 bool rectRectIntersectAllowed(const SkRect& newR, bool newAA) const;
242 /** Determines possible finite bounds for the Element given the previous element of the
243 stack */
244 void updateBoundAndGenID(const Element* prior);
245 // The different combination of fill & inverse fill when combining bounding boxes
246 enum FillCombo {
247 kPrev_Cur_FillCombo,
248 kPrev_InvCur_FillCombo,
249 kInvPrev_Cur_FillCombo,
250 kInvPrev_InvCur_FillCombo
251 };
252 // per-set operation functions used by updateBoundAndGenID().
253 inline void combineBoundsDiff(FillCombo combination, const SkRect& prevFinite);
254 inline void combineBoundsXOR(int combination, const SkRect& prevFinite);
255 inline void combineBoundsUnion(int combination, const SkRect& prevFinite);
256 inline void combineBoundsIntersection(int combination, const SkRect& prevFinite);
257 inline void combineBoundsRevDiff(int combination, const SkRect& prevFinite);
258 };
259
reed@google.com5c3d1472011-02-22 19:12:23 +0000260 SkClipStack();
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000261 SkClipStack(const SkClipStack& b);
robertphillips@google.comcc6493b2012-07-26 18:39:13 +0000262 explicit SkClipStack(const SkRect& r);
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000263 explicit SkClipStack(const SkIRect& r);
vandebo@chromium.org610f7162012-03-14 18:34:15 +0000264 ~SkClipStack();
reed@google.com5c3d1472011-02-22 19:12:23 +0000265
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +0000266 SkClipStack& operator=(const SkClipStack& b);
267 bool operator==(const SkClipStack& b) const;
268 bool operator!=(const SkClipStack& b) const { return !(*this == b); }
269
reed@google.com5c3d1472011-02-22 19:12:23 +0000270 void reset();
271
272 int getSaveCount() const { return fSaveCount; }
273 void save();
274 void restore();
275
robertphillips@google.com607fe072012-07-24 13:54:00 +0000276 /**
277 * getBounds places the current finite bound in its first parameter. In its
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000278 * second, it indicates which kind of bound is being returned. If
robertphillips@google.com7b112892012-07-31 15:18:21 +0000279 * 'canvFiniteBound' is a normal bounding box then it encloses all writeable
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000280 * pixels. If 'canvFiniteBound' is an inside out bounding box then it
robertphillips@google.com607fe072012-07-24 13:54:00 +0000281 * encloses all the un-writeable pixels and the true/normal bound is the
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000282 * infinite plane. isIntersectionOfRects is an optional parameter
robertphillips@google.com7b112892012-07-31 15:18:21 +0000283 * that is true if 'canvFiniteBound' resulted from an intersection of rects.
robertphillips@google.com607fe072012-07-24 13:54:00 +0000284 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000285 void getBounds(SkRect* canvFiniteBound,
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000286 BoundsType* boundType,
287 bool* isIntersectionOfRects = NULL) const;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000288
bsalomon@google.com3ab43d52012-10-11 19:39:09 +0000289 /**
290 * Takes an input rect in device space and conservatively clips it to the
291 * clip-stack. If false is returned then the rect does not intersect the
292 * clip and is unmodified.
293 */
294 bool intersectRectWithClip(SkRect* devRect) const;
295
junov@chromium.org8cdf0f52012-12-12 17:58:15 +0000296 /**
297 * Returns true if the input rect in device space is entirely contained
298 * by the clip. A return value of false does not guarantee that the rect
299 * is not contained by the clip.
300 */
301 bool quickContains(const SkRect& devRect) const;
302
reed@google.com115d9312012-05-16 18:50:40 +0000303 void clipDevRect(const SkIRect& ir, SkRegion::Op op) {
reed@google.com5c3d1472011-02-22 19:12:23 +0000304 SkRect r;
305 r.set(ir);
reed@google.com00177082011-10-12 14:34:30 +0000306 this->clipDevRect(r, op, false);
reed@google.com5c3d1472011-02-22 19:12:23 +0000307 }
reed@google.com00177082011-10-12 14:34:30 +0000308 void clipDevRect(const SkRect&, SkRegion::Op, bool doAA);
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000309 void clipDevRRect(const SkRRect&, SkRegion::Op, bool doAA);
reed@google.com00177082011-10-12 14:34:30 +0000310 void clipDevPath(const SkPath&, SkRegion::Op, bool doAA);
reed@google.com0557d9e2012-08-16 15:59:59 +0000311 // An optimized version of clipDevRect(emptyRect, kIntersect, ...)
312 void clipEmpty();
reed@google.com5c3d1472011-02-22 19:12:23 +0000313
robertphillips@google.comcc6493b2012-07-26 18:39:13 +0000314 /**
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000315 * isWideOpen returns true if the clip state corresponds to the infinite
robertphillips@google.comcc6493b2012-07-26 18:39:13 +0000316 * plane (i.e., draws are not limited at all)
317 */
318 bool isWideOpen() const;
319
robertphillips@google.com46f93502012-08-07 15:38:08 +0000320 /**
robertphillips@google.com46f93502012-08-07 15:38:08 +0000321 * The generation ID has three reserved values to indicate special
bsalomon@google.come8ca6c62012-11-07 21:19:10 +0000322 * (potentially ignorable) cases
robertphillips@google.com46f93502012-08-07 15:38:08 +0000323 */
commit-bot@chromium.orgd3e58422013-11-05 15:03:08 +0000324 static const int32_t kInvalidGenID = 0; //!< Invalid id that is never returned by
325 //!< SkClipStack. Useful when caching clips
326 //!< based on GenID.
robertphillips@google.com46f93502012-08-07 15:38:08 +0000327 static const int32_t kEmptyGenID = 1; // no pixels writeable
328 static const int32_t kWideOpenGenID = 2; // all pixels writeable
329
robertphillips@google.com73e71022012-08-09 18:10:49 +0000330 int32_t getTopmostGenID() const;
331
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000332public:
333 class Iter {
reed@google.com5c3d1472011-02-22 19:12:23 +0000334 public:
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000335 enum IterStart {
robertphillips@google.com80214e22012-07-20 15:33:18 +0000336 kBottom_IterStart = SkDeque::Iter::kFront_IterStart,
337 kTop_IterStart = SkDeque::Iter::kBack_IterStart
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000338 };
339
bsalomon@google.comd302f142011-03-03 13:54:13 +0000340 /**
341 * Creates an uninitialized iterator. Must be reset()
342 */
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000343 Iter();
bsalomon@google.comd302f142011-03-03 13:54:13 +0000344
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000345 Iter(const SkClipStack& stack, IterStart startLoc);
reed@google.com5c3d1472011-02-22 19:12:23 +0000346
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000347 /**
348 * Return the clip element for this iterator. If next()/prev() returns NULL, then the
349 * iterator is done.
350 */
351 const Element* next();
352 const Element* prev();
reed@google.com5c3d1472011-02-22 19:12:23 +0000353
354 /**
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000355 * Moves the iterator to the topmost element with the specified RegionOp and returns that
356 * element. If no clip element with that op is found, the first element is returned.
reed@google.com5c3d1472011-02-22 19:12:23 +0000357 */
bsalomon@google.com8182fa02012-12-04 14:06:06 +0000358 const Element* skipToTopmost(SkRegion::Op op);
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000359
360 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000361 * Restarts the iterator on a clip stack.
362 */
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000363 void reset(const SkClipStack& stack, IterStart startLoc);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000364
reed@google.com5c3d1472011-02-22 19:12:23 +0000365 private:
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000366 const SkClipStack* fStack;
robertphillips@google.com5836b6d2012-07-18 12:06:15 +0000367 SkDeque::Iter fIter;
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000368 };
369
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000370 /**
robertphillips@google.com80214e22012-07-20 15:33:18 +0000371 * The B2TIter iterates from the bottom of the stack to the top.
372 * It inherits privately from Iter to prevent access to reverse iteration.
373 */
374 class B2TIter : private Iter {
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000375 public:
robertphillips@google.com80214e22012-07-20 15:33:18 +0000376 B2TIter() {}
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000377
378 /**
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000379 * Wrap Iter's 2 parameter ctor to force initialization to the
robertphillips@google.com80214e22012-07-20 15:33:18 +0000380 * beginning of the deque/bottom of the stack
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000381 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000382 B2TIter(const SkClipStack& stack)
robertphillips@google.com80214e22012-07-20 15:33:18 +0000383 : INHERITED(stack, kBottom_IterStart) {
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000384 }
385
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000386 using Iter::next;
387
388 /**
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000389 * Wrap Iter::reset to force initialization to the
robertphillips@google.com80214e22012-07-20 15:33:18 +0000390 * beginning of the deque/bottom of the stack
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000391 */
392 void reset(const SkClipStack& stack) {
robertphillips@google.com80214e22012-07-20 15:33:18 +0000393 this->INHERITED::reset(stack, kBottom_IterStart);
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000394 }
395
396 private:
397
398 typedef Iter INHERITED;
reed@google.com5c3d1472011-02-22 19:12:23 +0000399 };
400
robertphillips@google.com607fe072012-07-24 13:54:00 +0000401 /**
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000402 * GetConservativeBounds returns a conservative bound of the current clip.
403 * Since this could be the infinite plane (if inverse fills were involved) the
404 * maxWidth and maxHeight parameters can be used to limit the returned bound
robertphillips@google.com607fe072012-07-24 13:54:00 +0000405 * to the expected drawing area. Similarly, the offsetX and offsetY parameters
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000406 * allow the caller to offset the returned bound to account for translated
robertphillips@google.com607fe072012-07-24 13:54:00 +0000407 * drawing areas (i.e., those resulting from a saveLayer). For finite bounds,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000408 * the translation (+offsetX, +offsetY) is applied before the clamp to the
robertphillips@google.com607fe072012-07-24 13:54:00 +0000409 * maximum rectangle: [0,maxWidth) x [0,maxHeight).
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000410 * isIntersectionOfRects is an optional parameter that is true when
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000411 * 'devBounds' is the result of an intersection of rects. In this case
412 * 'devBounds' is the exact answer/clip.
robertphillips@google.com607fe072012-07-24 13:54:00 +0000413 */
414 void getConservativeBounds(int offsetX,
415 int offsetY,
416 int maxWidth,
417 int maxHeight,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000418 SkRect* devBounds,
robertphillips@google.com4c2a2f72012-07-24 22:07:50 +0000419 bool* isIntersectionOfRects = NULL) const;
robertphillips@google.com607fe072012-07-24 13:54:00 +0000420
reed@google.com5c3d1472011-02-22 19:12:23 +0000421private:
robertphillips@google.com52cb2c72012-07-16 18:52:29 +0000422 friend class Iter;
reed@google.com5c3d1472011-02-22 19:12:23 +0000423
424 SkDeque fDeque;
425 int fSaveCount;
robertphillips@google.com46f93502012-08-07 15:38:08 +0000426
427 // Generation ID for the clip stack. This is incremented for each
428 // clipDevRect and clipDevPath call. 0 is reserved to indicate an
429 // invalid ID.
430 static int32_t gGenID;
431
robertphillips@google.com46f93502012-08-07 15:38:08 +0000432 /**
commit-bot@chromium.orge5b2af92014-02-16 13:25:24 +0000433 * Helper for clipDevPath, etc.
434 */
435 void pushElement(const Element& element);
436
437 /**
commit-bot@chromium.org6fbe54c2013-06-11 11:01:48 +0000438 * Restore the stack back to the specified save count.
439 */
440 void restoreTo(int saveCount);
441
442 /**
robertphillips@google.com46f93502012-08-07 15:38:08 +0000443 * Return the next unique generation ID.
444 */
445 static int32_t GetNextGenID();
reed@google.com5c3d1472011-02-22 19:12:23 +0000446};
447
448#endif