blob: b94ae1924644738a1e43169c3359917b0f569685 [file] [log] [blame]
reed@google.com5c3d1472011-02-22 19:12:23 +00001#ifndef SkClipStack_DEFINED
2#define SkClipStack_DEFINED
3
4#include "SkDeque.h"
5#include "SkRegion.h"
6
bsalomon@google.com57788b52011-02-22 21:00:31 +00007struct SkRect;
reed@google.com5c3d1472011-02-22 19:12:23 +00008class SkPath;
9
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000010class SK_API SkClipStack {
reed@google.com5c3d1472011-02-22 19:12:23 +000011public:
12 SkClipStack();
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +000013 SkClipStack(const SkClipStack& b);
reed@google.com5c3d1472011-02-22 19:12:23 +000014 ~SkClipStack() {}
15
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +000016 SkClipStack& operator=(const SkClipStack& b);
17 bool operator==(const SkClipStack& b) const;
18 bool operator!=(const SkClipStack& b) const { return !(*this == b); }
19
reed@google.com5c3d1472011-02-22 19:12:23 +000020 void reset();
21
22 int getSaveCount() const { return fSaveCount; }
23 void save();
24 void restore();
25
26 void clipDevRect(const SkIRect& ir,
27 SkRegion::Op op = SkRegion::kIntersect_Op) {
28 SkRect r;
29 r.set(ir);
30 this->clipDevRect(r, op);
31 }
32 void clipDevRect(const SkRect&, SkRegion::Op = SkRegion::kIntersect_Op);
33 void clipDevPath(const SkPath&, SkRegion::Op = SkRegion::kIntersect_Op);
34
35 class B2FIter {
36 public:
bsalomon@google.comd302f142011-03-03 13:54:13 +000037 /**
38 * Creates an uninitialized iterator. Must be reset()
39 */
40 B2FIter();
41
reed@google.com5c3d1472011-02-22 19:12:23 +000042 B2FIter(const SkClipStack& stack);
43
44 struct Clip {
45 const SkRect* fRect; // if non-null, this is a rect clip
46 const SkPath* fPath; // if non-null, this is a path clip
47 SkRegion::Op fOp;
48 };
49
50 /**
51 * Return the clip for this element in the iterator. If next() returns
52 * NULL, then the iterator is done. The type of clip is determined by
53 * the pointers fRect and fPath:
54 *
55 * fRect==NULL fPath!=NULL path clip
56 * fRect!=NULL fPath==NULL rect clip
57 * fRect==NULL fPath==NULL empty clip
58 */
59 const Clip* next();
60
bsalomon@google.comd302f142011-03-03 13:54:13 +000061 /**
62 * Restarts the iterator on a clip stack.
63 */
64 void reset(const SkClipStack& stack);
65
reed@google.com5c3d1472011-02-22 19:12:23 +000066 private:
67 Clip fClip;
68 SkDeque::F2BIter fIter;
69 };
70
71private:
72 friend class B2FIter;
73 struct Rec;
74
75 SkDeque fDeque;
76 int fSaveCount;
77};
78
79#endif
80