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

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

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

Powered by Google App Engine
This is Rietveld 408576698