SkClipStack.h revision 05b6b4d746867a9fb02e14edfe1bf3685abeb813
1#ifndef SkClipStack_DEFINED
2#define SkClipStack_DEFINED
3
4#include "SkDeque.h"
5#include "SkRegion.h"
6
7struct SkRect;
8class 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:
32        /**
33         * Creates an uninitialized iterator. Must be reset()
34         */
35        B2FIter();
36
37        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
56        /**
57         * Restarts the iterator on a clip stack.
58         */
59        void reset(const SkClipStack& stack);
60
61    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
76