epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 8 | #ifndef SkClipStack_DEFINED |
| 9 | #define SkClipStack_DEFINED |
| 10 | |
| 11 | #include "SkDeque.h" |
| 12 | #include "SkRegion.h" |
| 13 | |
bsalomon@google.com | 57788b5 | 2011-02-22 21:00:31 +0000 | [diff] [blame] | 14 | struct SkRect; |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 15 | class SkPath; |
| 16 | |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 17 | class SK_API SkClipStack { |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 18 | public: |
| 19 | SkClipStack(); |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 20 | SkClipStack(const SkClipStack& b); |
vandebo@chromium.org | 610f716 | 2012-03-14 18:34:15 +0000 | [diff] [blame] | 21 | ~SkClipStack(); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 22 | |
vandebo@chromium.org | 1e1c36f | 2011-05-03 16:26:09 +0000 | [diff] [blame] | 23 | 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.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 27 | void reset(); |
| 28 | |
| 29 | int getSaveCount() const { return fSaveCount; } |
| 30 | void save(); |
| 31 | void restore(); |
| 32 | |
reed@google.com | 115d931 | 2012-05-16 18:50:40 +0000 | [diff] [blame] | 33 | void clipDevRect(const SkIRect& ir, SkRegion::Op op) { |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 34 | SkRect r; |
| 35 | r.set(ir); |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 36 | this->clipDevRect(r, op, false); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 37 | } |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 38 | void clipDevRect(const SkRect&, SkRegion::Op, bool doAA); |
| 39 | void clipDevPath(const SkPath&, SkRegion::Op, bool doAA); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 40 | |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 41 | private: |
| 42 | struct Rec; |
| 43 | |
| 44 | public: |
| 45 | class Iter { |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 46 | public: |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 47 | enum IterStart { |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame^] | 48 | kBottom_IterStart = SkDeque::Iter::kFront_IterStart, |
| 49 | kTop_IterStart = SkDeque::Iter::kBack_IterStart |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 52 | /** |
| 53 | * Creates an uninitialized iterator. Must be reset() |
| 54 | */ |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 55 | Iter(); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 56 | |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 57 | Iter(const SkClipStack& stack, IterStart startLoc); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 58 | |
| 59 | struct Clip { |
robertphillips@google.com | fa1d291 | 2012-04-16 14:49:14 +0000 | [diff] [blame] | 60 | Clip() : fRect(NULL), fPath(NULL), fOp(SkRegion::kIntersect_Op), |
| 61 | fDoAA(false) {} |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 62 | friend bool operator==(const Clip& a, const Clip& b); |
vandebo@chromium.org | 8887ede | 2011-05-25 01:27:52 +0000 | [diff] [blame] | 63 | friend bool operator!=(const Clip& a, const Clip& b); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 64 | const SkRect* fRect; // if non-null, this is a rect clip |
| 65 | const SkPath* fPath; // if non-null, this is a path clip |
| 66 | SkRegion::Op fOp; |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 67 | bool fDoAA; |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | /** |
| 71 | * Return the clip for this element in the iterator. If next() returns |
| 72 | * NULL, then the iterator is done. The type of clip is determined by |
| 73 | * the pointers fRect and fPath: |
| 74 | * |
| 75 | * fRect==NULL fPath!=NULL path clip |
| 76 | * fRect!=NULL fPath==NULL rect clip |
| 77 | * fRect==NULL fPath==NULL empty clip |
| 78 | */ |
| 79 | const Clip* next(); |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 80 | const Clip* prev(); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 81 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 82 | /** |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame^] | 83 | * Moves the iterator to the topmost clip with the specified RegionOp |
robertphillips@google.com | 5836b6d | 2012-07-18 12:06:15 +0000 | [diff] [blame] | 84 | * and returns that clip. If no clip with that op is found, |
| 85 | * returns NULL. |
| 86 | */ |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame^] | 87 | const Clip* skipToTopmost(SkRegion::Op op); |
robertphillips@google.com | 5836b6d | 2012-07-18 12:06:15 +0000 | [diff] [blame] | 88 | |
| 89 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 90 | * Restarts the iterator on a clip stack. |
| 91 | */ |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 92 | void reset(const SkClipStack& stack, IterStart startLoc); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 93 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 94 | private: |
robertphillips@google.com | 5836b6d | 2012-07-18 12:06:15 +0000 | [diff] [blame] | 95 | const SkClipStack* fStack; |
| 96 | Clip fClip; |
| 97 | SkDeque::Iter fIter; |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 98 | |
| 99 | /** |
| 100 | * updateClip updates fClip to the current state of fIter. It unifies |
| 101 | * functionality needed by both next() and prev(). |
| 102 | */ |
| 103 | const Clip* updateClip(const SkClipStack::Rec* rec); |
| 104 | }; |
| 105 | |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame^] | 106 | /** |
| 107 | * The B2TIter iterates from the bottom of the stack to the top. |
| 108 | * It inherits privately from Iter to prevent access to reverse iteration. |
| 109 | */ |
| 110 | class B2TIter : private Iter { |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 111 | public: |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame^] | 112 | B2TIter() {} |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * Wrap Iter's 2 parameter ctor to force initialization to the |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame^] | 116 | * beginning of the deque/bottom of the stack |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 117 | */ |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame^] | 118 | B2TIter(const SkClipStack& stack) |
| 119 | : INHERITED(stack, kBottom_IterStart) { |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | using Iter::Clip; |
| 123 | using Iter::next; |
| 124 | |
| 125 | /** |
| 126 | * Wrap Iter::reset to force initialization to the |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame^] | 127 | * beginning of the deque/bottom of the stack |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 128 | */ |
| 129 | void reset(const SkClipStack& stack) { |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame^] | 130 | this->INHERITED::reset(stack, kBottom_IterStart); |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | private: |
| 134 | |
| 135 | typedef Iter INHERITED; |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | private: |
robertphillips@google.com | 52cb2c7 | 2012-07-16 18:52:29 +0000 | [diff] [blame] | 139 | friend class Iter; |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 140 | |
| 141 | SkDeque fDeque; |
| 142 | int fSaveCount; |
| 143 | }; |
| 144 | |
| 145 | #endif |
| 146 | |