Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Side by Side Diff: include/gpu/GrClip.h

Issue 956083002: Revert of Pass clip to context (Closed) Base URL: https://skia.googlesource.com/skia.git@pass_down_rendertarget
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkRect.h ('k') | include/gpu/GrContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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, or a full c lipstack. 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(); 29 fOrigin.setZero();
30 } 30 }
31
32 GrClip(const SkIRect& rect) : fClipType(kIRect_ClipType) { 31 GrClip(const SkIRect& rect) : fClipType(kIRect_ClipType) {
33 fOrigin.setZero(); 32 fOrigin.setZero();
34 fClip.fIRect = rect; 33 fClip.fIRect = rect;
35 } 34 }
36
37 GrClip(const SkRect& rect) : fClipType(kRect_ClipType) {
38 fOrigin.setZero();
39 fClip.fRect = rect;
40 }
41
42 ~GrClip() { this->reset(); } 35 ~GrClip() { this->reset(); }
43 36
44 const GrClip& operator=(const GrClip& other) { 37 const GrClip& operator=(const GrClip& other) {
45 this->reset(); 38 this->reset();
46 fClipType = other.fClipType; 39 fClipType = other.fClipType;
47 switch (other.fClipType) { 40 switch (other.fClipType) {
41 default:
42 SkFAIL("Incomplete Switch\n");
48 case kWideOpen_ClipType: 43 case kWideOpen_ClipType:
49 fOrigin.setZero(); 44 fOrigin.setZero();
50 break; 45 break;
51 case kClipStack_ClipType: 46 case kClipStack_ClipType:
52 fClip.fStack = SkRef(other.clipStack()); 47 fClip.fStack = SkRef(other.clipStack());
53 fOrigin = other.origin(); 48 fOrigin = other.origin();
54 break; 49 break;
55 case kIRect_ClipType: 50 case kIRect_ClipType:
56 fClip.fIRect = other.irect(); 51 fClip.fIRect = other.irect();
57 fOrigin.setZero(); 52 fOrigin.setZero();
58 break; 53 break;
59 case kRect_ClipType:
60 fClip.fRect = other.rect();
61 fOrigin.setZero();
62 break;
63 } 54 }
64 return *this; 55 return *this;
65 } 56 }
66 57
67 bool operator==(const GrClip& other) const { 58 bool operator==(const GrClip& other) const {
68 if (this->clipType() != other.clipType()) { 59 if (this->clipType() != other.clipType()) {
69 return false; 60 return false;
70 } 61 }
71 62
72 switch (fClipType) { 63 switch (fClipType) {
64 default:
65 SkFAIL("Incomplete Switch\n");
66 return false;
73 case kWideOpen_ClipType: 67 case kWideOpen_ClipType:
74 return true; 68 return true;
75 case kClipStack_ClipType: 69 case kClipStack_ClipType:
76 if (this->origin() != other.origin()) { 70 if (this->origin() != other.origin()) {
77 return false; 71 return false;
78 } 72 }
79 73
80 if (this->clipStack() && other.clipStack()) { 74 if (this->clipStack() && other.clipStack()) {
81 return *this->clipStack() == *other.clipStack(); 75 return *this->clipStack() == *other.clipStack();
82 } else { 76 } else {
83 return this->clipStack() == other.clipStack(); 77 return this->clipStack() == other.clipStack();
84 } 78 }
85 break; 79 break;
86 case kIRect_ClipType: 80 case kIRect_ClipType:
87 return this->irect() == other.irect(); 81 return this->irect() == other.irect();
88 break; 82 break;
89 case kRect_ClipType:
90 return this->rect() == other.rect();
91 break;
92 } 83 }
93 } 84 }
94 85
95 bool operator!=(const GrClip& other) const { 86 bool operator!=(const GrClip& other) const {
96 return !(*this == other); 87 return !(*this == other);
97 } 88 }
98 89
99 const SkClipStack* clipStack() const { 90 const SkClipStack* clipStack() const {
100 SkASSERT(kClipStack_ClipType == fClipType); 91 SkASSERT(kClipStack_ClipType == fClipType);
101 return fClip.fStack; 92 return fClip.fStack;
(...skipping 13 matching lines...) Expand all
115 fOrigin.setZero(); 106 fOrigin.setZero();
116 } 107 }
117 } 108 }
118 } 109 }
119 110
120 const SkIRect& irect() const { 111 const SkIRect& irect() const {
121 SkASSERT(kIRect_ClipType == fClipType); 112 SkASSERT(kIRect_ClipType == fClipType);
122 return fClip.fIRect; 113 return fClip.fIRect;
123 } 114 }
124 115
125 const SkRect& rect() const {
126 SkASSERT(kRect_ClipType == fClipType);
127 return fClip.fRect;
128 }
129
130 void reset() { 116 void reset() {
131 if (kClipStack_ClipType == fClipType) { 117 if (kClipStack_ClipType == fClipType) {
132 fClip.fStack->unref(); 118 fClip.fStack->unref();
133 fClip.fStack = NULL; 119 fClip.fStack = NULL;
134 } 120 }
135 fClipType = kWideOpen_ClipType; 121 fClipType = kWideOpen_ClipType;
136 fOrigin.setZero(); 122 fOrigin.setZero();
137 } 123 }
138 124
139 // We support this for all cliptypes to simplify the logic a bit in clip mas k manager. 125 // We support this for all cliptypes to simplify the logic a bit in clip mas k manager.
140 // non clipstack clip types MUST have a (0,0) origin 126 // non clipstack clip types MUST have a (0,0) origin
141 const SkIPoint& origin() const { 127 const SkIPoint& origin() const {
142 SkASSERT(fClipType == kClipStack_ClipType || (fOrigin.fX == 0 && fOrigin .fY == 0)); 128 SkASSERT(fClipType == kClipStack_ClipType || (fOrigin.fX == 0 && fOrigin .fY == 0));
143 return fOrigin; 129 return fOrigin;
144 } 130 }
145 131
146 bool isWideOpen(const SkRect& rect) const { 132 bool isWideOpen(const SkRect& rect) const {
147 return (kWideOpen_ClipType == fClipType) || 133 return (kWideOpen_ClipType == fClipType) ||
148 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe n()) || 134 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe n()) ||
149 (kIRect_ClipType == fClipType && this->irect().contains(rect)) || 135 (kIRect_ClipType == fClipType && this->irect().contains(rect));
150 (kRect_ClipType == fClipType && this->rect().contains(rect));
151 } 136 }
152 137
153 bool isWideOpen(const SkIRect& rect) const { 138 bool isWideOpen(const SkIRect& rect) const {
154 return (kWideOpen_ClipType == fClipType) || 139 return (kWideOpen_ClipType == fClipType) ||
155 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe n()) || 140 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe n()) ||
156 (kIRect_ClipType == fClipType && this->irect().contains(rect)) || 141 (kIRect_ClipType == fClipType && this->irect().contains(rect));
157 (kRect_ClipType == fClipType && this->rect().contains(rect));
158 } 142 }
159 143
160 bool isWideOpen() const { 144 bool isWideOpen() const {
161 return (kWideOpen_ClipType == fClipType) || 145 return (kWideOpen_ClipType == fClipType) ||
162 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe n()); 146 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe n());
163 } 147 }
164 148
165 bool quickContains(const SkRect& rect) const {
166 return (kWideOpen_ClipType == fClipType) ||
167 (kClipStack_ClipType == fClipType && this->clipStack()->quickCont ains(rect)) ||
168 (kIRect_ClipType == fClipType && this->irect().contains(rect)) ||
169 (kRect_ClipType == fClipType && this->rect().contains(rect));
170 }
171
172 void getConservativeBounds(const GrSurface* surface, 149 void getConservativeBounds(const GrSurface* surface,
173 SkIRect* devResult, 150 SkIRect* devResult,
174 bool* isIntersectionOfRects = NULL) const { 151 bool* isIntersectionOfRects = NULL) const {
175 this->getConservativeBounds(surface->width(), surface->height(), 152 this->getConservativeBounds(surface->width(), surface->height(),
176 devResult, isIntersectionOfRects); 153 devResult, isIntersectionOfRects);
177 } 154 }
178 155
179 void getConservativeBounds(int width, int height, 156 void getConservativeBounds(int width, int height,
180 SkIRect* devResult, 157 SkIRect* devResult,
181 bool* isIntersectionOfRects = NULL) const; 158 bool* isIntersectionOfRects = NULL) const;
182 159
183 static const GrClip& WideOpen(); 160 static const GrClip& WideOpen();
184 161
185 enum ClipType { 162 enum ClipType {
186 kClipStack_ClipType, 163 kClipStack_ClipType,
187 kWideOpen_ClipType, 164 kWideOpen_ClipType,
188 kIRect_ClipType, 165 kIRect_ClipType,
189 kRect_ClipType,
190 }; 166 };
191 167
192 ClipType clipType() const { return fClipType; } 168 ClipType clipType() const { return fClipType; }
193 169
194 private: 170 private:
195 union Clip { 171 union Clip {
196 const SkClipStack* fStack; 172 const SkClipStack* fStack;
197 SkRect fRect;
198 SkIRect fIRect; 173 SkIRect fIRect;
199 } fClip; 174 } fClip;
200 175
201 SkIPoint fOrigin; 176 SkIPoint fOrigin;
202 ClipType fClipType; 177 ClipType fClipType;
203 }; 178 };
204 179
205 #endif 180 #endif
OLDNEW
« no previous file with comments | « include/core/SkRect.h ('k') | include/gpu/GrContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698