• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
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  */
8 #ifndef SkClipStack_DEFINED
9 #define SkClipStack_DEFINED
10 
11 #include "SkDeque.h"
12 #include "SkRegion.h"
13 
14 struct SkRect;
15 class SkPath;
16 
17 class SK_API SkClipStack {
18 public:
19     SkClipStack();
20     SkClipStack(const SkClipStack& b);
~SkClipStack()21     ~SkClipStack() {}
22 
23     SkClipStack& operator=(const SkClipStack& b);
24     bool operator==(const SkClipStack& b) const;
25     bool operator!=(const SkClipStack& b) const { return !(*this == b); }
26 
27     void reset();
28 
getSaveCount()29     int getSaveCount() const { return fSaveCount; }
30     void save();
31     void restore();
32 
33     void clipDevRect(const SkIRect& ir,
34                      SkRegion::Op op = SkRegion::kIntersect_Op) {
35         SkRect r;
36         r.set(ir);
37         this->clipDevRect(r, op, false);
38     }
39     void clipDevRect(const SkRect&, SkRegion::Op, bool doAA);
40     void clipDevPath(const SkPath&, SkRegion::Op, bool doAA);
41 
42     class B2FIter {
43     public:
44         /**
45          * Creates an uninitialized iterator. Must be reset()
46          */
47         B2FIter();
48 
49         B2FIter(const SkClipStack& stack);
50 
51         struct Clip {
ClipClip52             Clip() : fRect(NULL), fPath(NULL), fOp(SkRegion::kIntersect_Op) {}
53             friend bool operator==(const Clip& a, const Clip& b);
54             friend bool operator!=(const Clip& a, const Clip& b);
55             const SkRect*   fRect;  // if non-null, this is a rect clip
56             const SkPath*   fPath;  // if non-null, this is a path clip
57             SkRegion::Op    fOp;
58             bool            fDoAA;
59         };
60 
61         /**
62          *  Return the clip for this element in the iterator. If next() returns
63          *  NULL, then the iterator is done. The type of clip is determined by
64          *  the pointers fRect and fPath:
65          *
66          *  fRect==NULL  fPath!=NULL    path clip
67          *  fRect!=NULL  fPath==NULL    rect clip
68          *  fRect==NULL  fPath==NULL    empty clip
69          */
70         const Clip* next();
71 
72         /**
73          * Restarts the iterator on a clip stack.
74          */
75         void reset(const SkClipStack& stack);
76 
77     private:
78         Clip             fClip;
79         SkDeque::F2BIter fIter;
80     };
81 
82 private:
83     friend class B2FIter;
84     struct Rec;
85 
86     SkDeque fDeque;
87     int     fSaveCount;
88 };
89 
90 #endif
91 
92