blob: 0990dcfc104f6ce7bc1938ee74a3e5fd27f74d10 [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);
37 this->clipDevRect(r, op);
38 }
39 void clipDevRect(const SkRect&, SkRegion::Op = SkRegion::kIntersect_Op);
40 void clipDevPath(const SkPath&, SkRegion::Op = SkRegion::kIntersect_Op);
41
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;
58 };
59
60 /**
61 * Return the clip for this element in the iterator. If next() returns
62 * NULL, then the iterator is done. The type of clip is determined by
63 * the pointers fRect and fPath:
64 *
65 * fRect==NULL fPath!=NULL path clip
66 * fRect!=NULL fPath==NULL rect clip
67 * fRect==NULL fPath==NULL empty clip
68 */
69 const Clip* next();
70
bsalomon@google.comd302f142011-03-03 13:54:13 +000071 /**
72 * Restarts the iterator on a clip stack.
73 */
74 void reset(const SkClipStack& stack);
75
reed@google.com5c3d1472011-02-22 19:12:23 +000076 private:
77 Clip fClip;
78 SkDeque::F2BIter fIter;
79 };
80
81private:
82 friend class B2FIter;
83 struct Rec;
84
85 SkDeque fDeque;
86 int fSaveCount;
87};
88
89#endif
90