OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrClip_DEFINED | 8 #ifndef GrClip_DEFINED |
9 #define GrClip_DEFINED | 9 #define GrClip_DEFINED |
10 | 10 |
11 #include "SkClipStack.h" | 11 #include "SkClipStack.h" |
12 #include "GrSurface.h" | 12 #include "GrSurface.h" |
13 | 13 |
14 struct SkIRect; | 14 struct SkIRect; |
15 | 15 |
16 /** | 16 /** |
17 * GrClip encapsulates the information required to construct the clip | 17 * GrClip encapsulates the information required to construct the clip |
18 * masks. 'A GrClip is either wide open, just an IRect, just a Rect(TODO), or a
full clipstack. | 18 * masks. 'A GrClip is either wide open, just an IRect, just a Rect(TODO), or a
full clipstack. |
19 * If the clip is a clipstack than the origin is used to translate the stack wit
h | 19 * If the clip is a clipstack than the origin is used to translate the stack wit
h |
20 * respect to device coordinates. This allows us to use a clip stack that is | 20 * respect to device coordinates. This allows us to use a clip stack that is |
21 * specified for a root device with a layer device that is restricted to a subse
t | 21 * specified for a root device with a layer device that is restricted to a subse
t |
22 * of the original canvas. For other clip types the origin will always be (0,0). | 22 * of the original canvas. For other clip types the origin will always be (0,0). |
23 * | 23 * |
24 * NOTE: GrClip *must* point to a const clipstack | 24 * NOTE: GrClip *must* point to a const clipstack |
25 */ | 25 */ |
26 class GrClip : SkNoncopyable { | 26 class GrClip : SkNoncopyable { |
27 public: | 27 public: |
28 GrClip() : fClipType(kWideOpen_ClipType) {} | 28 GrClip() : fClipType(kWideOpen_ClipType) { |
| 29 fOrigin.setZero(); |
| 30 } |
29 GrClip(const SkIRect& rect) : fClipType(kIRect_ClipType) { | 31 GrClip(const SkIRect& rect) : fClipType(kIRect_ClipType) { |
| 32 fOrigin.setZero(); |
30 fClip.fIRect = rect; | 33 fClip.fIRect = rect; |
31 } | 34 } |
32 ~GrClip() { this->reset(); } | 35 ~GrClip() { this->reset(); } |
33 | 36 |
34 const GrClip& operator=(const GrClip& other) { | 37 const GrClip& operator=(const GrClip& other) { |
35 this->reset(); | 38 this->reset(); |
36 fClipType = other.fClipType; | 39 fClipType = other.fClipType; |
37 switch (other.fClipType) { | 40 switch (other.fClipType) { |
38 default: | 41 default: |
39 SkFAIL("Incomplete Switch\n"); | 42 SkFAIL("Incomplete Switch\n"); |
40 case kWideOpen_ClipType: | 43 case kWideOpen_ClipType: |
| 44 fOrigin.setZero(); |
41 break; | 45 break; |
42 case kClipStack_ClipType: | 46 case kClipStack_ClipType: |
43 fClip.fClipStack.fStack = SkRef(other.clipStack()); | 47 fClip.fStack = SkRef(other.clipStack()); |
44 fClip.fClipStack.fOrigin = other.origin(); | 48 fOrigin = other.origin(); |
45 break; | 49 break; |
46 case kIRect_ClipType: | 50 case kIRect_ClipType: |
47 fClip.fIRect = other.irect(); | 51 fClip.fIRect = other.irect(); |
| 52 fOrigin.setZero(); |
48 break; | 53 break; |
49 } | 54 } |
50 return *this; | 55 return *this; |
51 } | 56 } |
52 | 57 |
53 bool operator==(const GrClip& other) const { | 58 bool operator==(const GrClip& other) const { |
54 if (this->clipType() != other.clipType()) { | 59 if (this->clipType() != other.clipType()) { |
55 return false; | 60 return false; |
56 } | 61 } |
57 | 62 |
(...skipping 19 matching lines...) Expand all Loading... |
77 break; | 82 break; |
78 } | 83 } |
79 } | 84 } |
80 | 85 |
81 bool operator!=(const GrClip& other) const { | 86 bool operator!=(const GrClip& other) const { |
82 return !(*this == other); | 87 return !(*this == other); |
83 } | 88 } |
84 | 89 |
85 const SkClipStack* clipStack() const { | 90 const SkClipStack* clipStack() const { |
86 SkASSERT(kClipStack_ClipType == fClipType); | 91 SkASSERT(kClipStack_ClipType == fClipType); |
87 return fClip.fClipStack.fStack; | 92 return fClip.fStack; |
88 } | 93 } |
89 | 94 |
90 void setClipStack(const SkClipStack* clipStack, const SkIPoint* origin = NUL
L) { | 95 void setClipStack(const SkClipStack* clipStack, const SkIPoint* origin = NUL
L) { |
91 if (clipStack->isWideOpen()) { | 96 if (clipStack->isWideOpen()) { |
92 fClipType = kWideOpen_ClipType; | 97 fClipType = kWideOpen_ClipType; |
| 98 fOrigin.setZero(); |
93 } else { | 99 } else { |
94 fClipType = kClipStack_ClipType; | 100 fClipType = kClipStack_ClipType; |
95 fClip.fClipStack.fStack = SkRef(clipStack); | 101 fClip.fStack = SkRef(clipStack); |
96 if (origin) { | 102 if (origin) { |
97 fClip.fClipStack.fOrigin = *origin; | 103 fOrigin = *origin; |
98 } else { | 104 } else { |
99 fClip.fClipStack.fOrigin.setZero(); | 105 fOrigin.setZero(); |
100 } | 106 } |
101 } | 107 } |
102 } | 108 } |
103 | 109 |
104 const SkIRect& irect() const { | 110 const SkIRect& irect() const { |
105 SkASSERT(kIRect_ClipType == fClipType); | 111 SkASSERT(kIRect_ClipType == fClipType); |
106 return fClip.fIRect; | 112 return fClip.fIRect; |
107 } | 113 } |
108 | 114 |
109 void reset() { | 115 void reset() { |
110 if (kClipStack_ClipType == fClipType) { | 116 if (kClipStack_ClipType == fClipType) { |
111 fClip.fClipStack.fStack->unref(); | 117 fClip.fStack->unref(); |
112 fClip.fClipStack.fStack = NULL; | 118 fClip.fStack = NULL; |
113 } | 119 } |
114 fClipType = kWideOpen_ClipType; | 120 fClipType = kWideOpen_ClipType; |
| 121 fOrigin.setZero(); |
115 } | 122 } |
116 | 123 |
| 124 // We support this for all cliptypes to simplify the logic a bit in clip mas
k manager. |
| 125 // non clipstack clip types MUST have a (0,0) origin |
117 const SkIPoint& origin() const { | 126 const SkIPoint& origin() const { |
118 SkASSERT(kClipStack_ClipType == fClipType); | 127 SkASSERT(fClipType == kClipStack_ClipType || (fOrigin.fX == 0 && fOrigin
.fY == 0)); |
119 return fClip.fClipStack.fOrigin; | 128 return fOrigin; |
120 } | 129 } |
121 | 130 |
122 bool isWideOpen(const SkRect& rect) const { | 131 bool isWideOpen(const SkRect& rect) const { |
123 return (kWideOpen_ClipType == fClipType) || | 132 return (kWideOpen_ClipType == fClipType) || |
124 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe
n()) || | 133 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe
n()) || |
125 (kIRect_ClipType == fClipType && this->irect().contains(rect)); | 134 (kIRect_ClipType == fClipType && this->irect().contains(rect)); |
126 } | 135 } |
127 | 136 |
128 bool isWideOpen(const SkIRect& rect) const { | 137 bool isWideOpen(const SkIRect& rect) const { |
129 return (kWideOpen_ClipType == fClipType) || | 138 return (kWideOpen_ClipType == fClipType) || |
(...skipping 22 matching lines...) Expand all Loading... |
152 enum ClipType { | 161 enum ClipType { |
153 kClipStack_ClipType, | 162 kClipStack_ClipType, |
154 kWideOpen_ClipType, | 163 kWideOpen_ClipType, |
155 kIRect_ClipType, | 164 kIRect_ClipType, |
156 }; | 165 }; |
157 | 166 |
158 ClipType clipType() const { return fClipType; } | 167 ClipType clipType() const { return fClipType; } |
159 | 168 |
160 private: | 169 private: |
161 union Clip { | 170 union Clip { |
162 struct ClipStack { | 171 const SkClipStack* fStack; |
163 const SkClipStack* fStack; | |
164 SkIPoint fOrigin; | |
165 } fClipStack; | |
166 SkIRect fIRect; | 172 SkIRect fIRect; |
167 } fClip; | 173 } fClip; |
168 | 174 |
| 175 SkIPoint fOrigin; |
169 ClipType fClipType; | 176 ClipType fClipType; |
170 }; | 177 }; |
171 | 178 |
172 #endif | 179 #endif |
OLD | NEW |