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 | |
| 33 | void clipDevRect(const SkIRect& ir, |
| 34 | SkRegion::Op op = SkRegion::kIntersect_Op) { |
| 35 | SkRect r; |
| 36 | r.set(ir); |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 37 | this->clipDevRect(r, op, false); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 38 | } |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 39 | void clipDevRect(const SkRect&, SkRegion::Op, bool doAA); |
| 40 | void clipDevPath(const SkPath&, SkRegion::Op, bool doAA); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 41 | |
| 42 | class B2FIter { |
| 43 | public: |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 44 | /** |
| 45 | * Creates an uninitialized iterator. Must be reset() |
| 46 | */ |
| 47 | B2FIter(); |
| 48 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 49 | B2FIter(const SkClipStack& stack); |
| 50 | |
| 51 | struct Clip { |
vandebo@chromium.org | e1bc274 | 2011-06-21 22:26:39 +0000 | [diff] [blame] | 52 | Clip() : fRect(NULL), fPath(NULL), fOp(SkRegion::kIntersect_Op) {} |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 53 | friend bool operator==(const Clip& a, const Clip& b); |
vandebo@chromium.org | 8887ede | 2011-05-25 01:27:52 +0000 | [diff] [blame] | 54 | friend bool operator!=(const Clip& a, const Clip& b); |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 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; |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 58 | bool fDoAA; |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 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 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 72 | /** |
| 73 | * Restarts the iterator on a clip stack. |
| 74 | */ |
| 75 | void reset(const SkClipStack& stack); |
| 76 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 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 | |