reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2010 Google Inc. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #ifndef GrClip_DEFINED |
| 19 | #define GrClip_DEFINED |
| 20 | |
| 21 | #include "GrClipIterator.h" |
| 22 | #include "GrRect.h" |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 23 | #include "GrPath.h" |
| 24 | #include "GrTArray.h" |
| 25 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 26 | |
| 27 | class GrClip { |
| 28 | public: |
| 29 | GrClip(); |
| 30 | GrClip(const GrClip& src); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 31 | GrClip(GrClipIterator* iter, const GrRect* bounds = NULL); |
| 32 | GrClip(const GrIRect& rect); |
| 33 | GrClip(const GrRect& rect); |
| 34 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 35 | ~GrClip(); |
| 36 | |
| 37 | GrClip& operator=(const GrClip& src); |
| 38 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 39 | bool hasBounds() const { return fBoundsValid; } |
| 40 | |
| 41 | const GrRect& getBounds() const { return fBounds; } |
| 42 | |
| 43 | int getElementCount() const { return fList.count(); } |
| 44 | |
| 45 | GrClipType getElementType(int i) const { return fList[i].fType; } |
| 46 | |
| 47 | const GrPath& getPath(int i) const { |
| 48 | GrAssert(kPath_ClipType == fList[i].fType); |
| 49 | return fList[i].fPath; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 50 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 51 | |
| 52 | GrPathFill getPathFill(int i) const { |
| 53 | GrAssert(kPath_ClipType == fList[i].fType); |
| 54 | return fList[i].fPathFill; |
| 55 | } |
| 56 | |
| 57 | const GrRect& getRect(int i) const { |
| 58 | GrAssert(kRect_ClipType == fList[i].fType); |
| 59 | return fList[i].fRect; |
| 60 | } |
| 61 | |
| 62 | const GrSetOp getOp(int i) const { return fList[i].fOp; } |
| 63 | |
| 64 | bool isRect() const { |
| 65 | if (1 == fList.count() && kRect_ClipType == fList[0].fType) { |
| 66 | GrAssert(fBoundsValid); |
| 67 | GrAssert(fBounds == fList[0].fRect); |
| 68 | return true; |
| 69 | } else { |
| 70 | return false; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | bool isEmpty() const { return 0 == fList.count(); } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 75 | |
| 76 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 77 | * Resets this clip to be empty |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 78 | */ |
| 79 | void setEmpty(); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 80 | void setFromIterator(GrClipIterator* iter, const GrRect* bounds = NULL); |
| 81 | void setFromRect(const GrRect& rect); |
| 82 | void setFromIRect(const GrIRect& rect); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 83 | |
| 84 | friend bool operator==(const GrClip& a, const GrClip& b) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 85 | if (a.fList.count() != b.fList.count()) { |
| 86 | return false; |
| 87 | } |
| 88 | int count = a.fList.count(); |
| 89 | for (int i = 0; i < count; ++i) { |
| 90 | if (a.fList[i] != b.fList[i]) { |
| 91 | return false; |
| 92 | } |
| 93 | } |
| 94 | return true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 95 | } |
| 96 | friend bool operator!=(const GrClip& a, const GrClip& b) { |
| 97 | return !(a == b); |
| 98 | } |
| 99 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 100 | private: |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 101 | struct Element { |
| 102 | GrClipType fType; |
| 103 | GrRect fRect; |
| 104 | GrPath fPath; |
| 105 | GrPathFill fPathFill; |
| 106 | GrSetOp fOp; |
| 107 | bool operator ==(const Element& e) const { |
| 108 | if (e.fType != fType || e.fOp != fOp) { |
| 109 | return false; |
| 110 | } |
| 111 | switch (fType) { |
| 112 | case kRect_ClipType: |
| 113 | return fRect == e.fRect; |
| 114 | break; |
| 115 | case kPath_ClipType: |
| 116 | return fPath == e.fPath; |
| 117 | default: |
| 118 | GrCrash("Unknown clip element type."); |
| 119 | return false; // suppress warning |
| 120 | } |
| 121 | } |
| 122 | bool operator !=(const Element& e) const { return !(*this == e); } |
| 123 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 124 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 125 | GrRect fBounds; |
| 126 | bool fBoundsValid; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 127 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 128 | enum { |
| 129 | kPreAllocElements = 4, |
| 130 | }; |
| 131 | uint8_t fListMemory[sizeof(Element) * kPreAllocElements]; |
| 132 | GrTArray<Element> fList; |
| 133 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 134 | #endif |
| 135 | |