blob: fc96f031ccdcb55102d804cee5ec956ecfed4db4 [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"
12#include "SkRegion.h"
13
bsalomon@google.com57788b52011-02-22 21:00:31 +000014struct SkRect;
reed@google.com5c3d1472011-02-22 19:12:23 +000015class SkPath;
16
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000017class SK_API SkClipStack {
reed@google.com5c3d1472011-02-22 19:12:23 +000018public:
19 SkClipStack();
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +000020 SkClipStack(const SkClipStack& b);
reed@google.com5c3d1472011-02-22 19:12:23 +000021 ~SkClipStack() {}
22
vandebo@chromium.org1e1c36f2011-05-03 16:26:09 +000023 SkClipStack& operator=(const SkClipStack& b);
24 bool operator==(const SkClipStack& b) const;
25 bool operator!=(const SkClipStack& b) const { return !(*this == b); }
26
reed@google.com5c3d1472011-02-22 19:12:23 +000027 void reset();
28
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);
reed@google.com00177082011-10-12 14:34:30 +000037 this->clipDevRect(r, op, false);
reed@google.com5c3d1472011-02-22 19:12:23 +000038 }
reed@google.com00177082011-10-12 14:34:30 +000039 void clipDevRect(const SkRect&, SkRegion::Op, bool doAA);
40 void clipDevPath(const SkPath&, SkRegion::Op, bool doAA);
reed@google.com5c3d1472011-02-22 19:12:23 +000041
42 class B2FIter {
43 public:
bsalomon@google.comd302f142011-03-03 13:54:13 +000044 /**
45 * Creates an uninitialized iterator. Must be reset()
46 */
47 B2FIter();
48
reed@google.com5c3d1472011-02-22 19:12:23 +000049 B2FIter(const SkClipStack& stack);
50
51 struct Clip {
vandebo@chromium.orge1bc2742011-06-21 22:26:39 +000052 Clip() : fRect(NULL), fPath(NULL), fOp(SkRegion::kIntersect_Op) {}
vandebo@chromium.org9fbdf872011-05-09 07:55:58 +000053 friend bool operator==(const Clip& a, const Clip& b);
vandebo@chromium.org8887ede2011-05-25 01:27:52 +000054 friend bool operator!=(const Clip& a, const Clip& b);
reed@google.com5c3d1472011-02-22 19:12:23 +000055 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;
reed@google.com00177082011-10-12 14:34:30 +000058 bool fDoAA;
reed@google.com5c3d1472011-02-22 19:12:23 +000059 };
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
bsalomon@google.comd302f142011-03-03 13:54:13 +000072 /**
73 * Restarts the iterator on a clip stack.
74 */
75 void reset(const SkClipStack& stack);
76
reed@google.com5c3d1472011-02-22 19:12:23 +000077 private:
78 Clip fClip;
79 SkDeque::F2BIter fIter;
80 };
81
82private:
83 friend class B2FIter;
84 struct Rec;
85
86 SkDeque fDeque;
87 int fSaveCount;
88};
89
90#endif
91