blob: db42e4df26289a46e9cb77a39bcd7f29e60a465e [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
10class SkClipStack {
11public:
12 SkClipStack();
13 ~SkClipStack() {}
14
15 void reset();
16
17 int getSaveCount() const { return fSaveCount; }
18 void save();
19 void restore();
20
21 void clipDevRect(const SkIRect& ir,
22 SkRegion::Op op = SkRegion::kIntersect_Op) {
23 SkRect r;
24 r.set(ir);
25 this->clipDevRect(r, op);
26 }
27 void clipDevRect(const SkRect&, SkRegion::Op = SkRegion::kIntersect_Op);
28 void clipDevPath(const SkPath&, SkRegion::Op = SkRegion::kIntersect_Op);
29
30 class B2FIter {
31 public:
bsalomon@google.comd302f142011-03-03 13:54:13 +000032 /**
33 * Creates an uninitialized iterator. Must be reset()
34 */
35 B2FIter();
36
reed@google.com5c3d1472011-02-22 19:12:23 +000037 B2FIter(const SkClipStack& stack);
38
39 struct Clip {
40 const SkRect* fRect; // if non-null, this is a rect clip
41 const SkPath* fPath; // if non-null, this is a path clip
42 SkRegion::Op fOp;
43 };
44
45 /**
46 * Return the clip for this element in the iterator. If next() returns
47 * NULL, then the iterator is done. The type of clip is determined by
48 * the pointers fRect and fPath:
49 *
50 * fRect==NULL fPath!=NULL path clip
51 * fRect!=NULL fPath==NULL rect clip
52 * fRect==NULL fPath==NULL empty clip
53 */
54 const Clip* next();
55
bsalomon@google.comd302f142011-03-03 13:54:13 +000056 /**
57 * Restarts the iterator on a clip stack.
58 */
59 void reset(const SkClipStack& stack);
60
reed@google.com5c3d1472011-02-22 19:12:23 +000061 private:
62 Clip fClip;
63 SkDeque::F2BIter fIter;
64 };
65
66private:
67 friend class B2FIter;
68 struct Rec;
69
70 SkDeque fDeque;
71 int fSaveCount;
72};
73
74#endif
75