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

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: more cleanup 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(TODO), or a full clipstack.
bsalomon 2015/02/24 17:02:05 rm TODO?
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: 48 default:
42 SkFAIL("Incomplete Switch\n"); 49 SkFAIL("Incomplete Switch\n");
43 case kWideOpen_ClipType: 50 case kWideOpen_ClipType:
44 fOrigin.setZero(); 51 fOrigin.setZero();
45 break; 52 break;
46 case kClipStack_ClipType: 53 case kClipStack_ClipType:
47 fClip.fStack = SkRef(other.clipStack()); 54 fClip.fStack = SkRef(other.clipStack());
48 fOrigin = other.origin(); 55 fOrigin = other.origin();
49 break; 56 break;
50 case kIRect_ClipType: 57 case kIRect_ClipType:
51 fClip.fIRect = other.irect(); 58 fClip.fIRect = other.irect();
52 fOrigin.setZero(); 59 fOrigin.setZero();
53 break; 60 break;
61 case kRect_ClipType:
62 fClip.fRect = other.rect();
63 fOrigin.setZero();
64 break;
54 } 65 }
55 return *this; 66 return *this;
56 } 67 }
57 68
58 bool operator==(const GrClip& other) const { 69 bool operator==(const GrClip& other) const {
59 if (this->clipType() != other.clipType()) { 70 if (this->clipType() != other.clipType()) {
60 return false; 71 return false;
61 } 72 }
62 73
63 switch (fClipType) { 74 switch (fClipType) {
64 default: 75 default:
65 SkFAIL("Incomplete Switch\n"); 76 SkFAIL("Incomplete Switch\n");
66 return false; 77 return false;
67 case kWideOpen_ClipType: 78 case kWideOpen_ClipType:
68 return true; 79 return true;
69 case kClipStack_ClipType: 80 case kClipStack_ClipType:
70 if (this->origin() != other.origin()) { 81 if (this->origin() != other.origin()) {
71 return false; 82 return false;
72 } 83 }
73 84
74 if (this->clipStack() && other.clipStack()) { 85 if (this->clipStack() && other.clipStack()) {
75 return *this->clipStack() == *other.clipStack(); 86 return *this->clipStack() == *other.clipStack();
76 } else { 87 } else {
77 return this->clipStack() == other.clipStack(); 88 return this->clipStack() == other.clipStack();
78 } 89 }
79 break; 90 break;
80 case kIRect_ClipType: 91 case kIRect_ClipType:
81 return this->irect() == other.irect(); 92 return this->irect() == other.irect();
82 break; 93 break;
94 case kRect_ClipType:
95 return this->rect() == other.rect();
96 break;
83 } 97 }
84 } 98 }
85 99
86 bool operator!=(const GrClip& other) const { 100 bool operator!=(const GrClip& other) const {
87 return !(*this == other); 101 return !(*this == other);
88 } 102 }
89 103
90 const SkClipStack* clipStack() const { 104 const SkClipStack* clipStack() const {
91 SkASSERT(kClipStack_ClipType == fClipType); 105 SkASSERT(kClipStack_ClipType == fClipType);
92 return fClip.fStack; 106 return fClip.fStack;
(...skipping 12 matching lines...) Expand all
105 fOrigin.setZero(); 119 fOrigin.setZero();
106 } 120 }
107 } 121 }
108 } 122 }
109 123
110 const SkIRect& irect() const { 124 const SkIRect& irect() const {
111 SkASSERT(kIRect_ClipType == fClipType); 125 SkASSERT(kIRect_ClipType == fClipType);
112 return fClip.fIRect; 126 return fClip.fIRect;
113 } 127 }
114 128
129 const SkRect& rect() const {
130 SkASSERT(kRect_ClipType == fClipType);
131 return fClip.fRect;
132 }
133
115 void reset() { 134 void reset() {
116 if (kClipStack_ClipType == fClipType) { 135 if (kClipStack_ClipType == fClipType) {
117 fClip.fStack->unref(); 136 fClip.fStack->unref();
118 fClip.fStack = NULL; 137 fClip.fStack = NULL;
119 } 138 }
120 fClipType = kWideOpen_ClipType; 139 fClipType = kWideOpen_ClipType;
121 fOrigin.setZero(); 140 fOrigin.setZero();
122 } 141 }
123 142
124 // We support this for all cliptypes to simplify the logic a bit in clip mas k manager. 143 // 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 144 // non clipstack clip types MUST have a (0,0) origin
126 const SkIPoint& origin() const { 145 const SkIPoint& origin() const {
127 SkASSERT(fClipType == kClipStack_ClipType || (fOrigin.fX == 0 && fOrigin .fY == 0)); 146 SkASSERT(fClipType == kClipStack_ClipType || (fOrigin.fX == 0 && fOrigin .fY == 0));
128 return fOrigin; 147 return fOrigin;
129 } 148 }
130 149
131 bool isWideOpen(const SkRect& rect) const { 150 bool isWideOpen(const SkRect& rect) const {
132 return (kWideOpen_ClipType == fClipType) || 151 return (kWideOpen_ClipType == fClipType) ||
133 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe n()) || 152 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe n()) ||
134 (kIRect_ClipType == fClipType && this->irect().contains(rect)); 153 (kIRect_ClipType == fClipType && this->irect().contains(rect)) ||
154 (kRect_ClipType == fClipType && this->rect().contains(rect));
135 } 155 }
136 156
137 bool isWideOpen(const SkIRect& rect) const { 157 bool isWideOpen(const SkIRect& rect) const {
138 return (kWideOpen_ClipType == fClipType) || 158 return (kWideOpen_ClipType == fClipType) ||
139 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe n()) || 159 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe n()) ||
140 (kIRect_ClipType == fClipType && this->irect().contains(rect)); 160 (kIRect_ClipType == fClipType && this->irect().contains(rect)) ||
161 (kRect_ClipType == fClipType && this->rect().contains(rect));
141 } 162 }
142 163
143 bool isWideOpen() const { 164 bool isWideOpen() const {
144 return (kWideOpen_ClipType == fClipType) || 165 return (kWideOpen_ClipType == fClipType) ||
145 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe n()); 166 (kClipStack_ClipType == fClipType && this->clipStack()->isWideOpe n());
146 } 167 }
147 168
169 bool quickContains(const SkRect& rect) const {
170 return (kWideOpen_ClipType == fClipType) ||
171 (kClipStack_ClipType == fClipType && this->clipStack()->quickCont ains(rect)) ||
172 (kIRect_ClipType == fClipType && this->irect().contains(rect)) ||
173 (kRect_ClipType == fClipType && this->rect().contains(rect));
174 }
175
148 void getConservativeBounds(const GrSurface* surface, 176 void getConservativeBounds(const GrSurface* surface,
149 SkIRect* devResult, 177 SkIRect* devResult,
150 bool* isIntersectionOfRects = NULL) const { 178 bool* isIntersectionOfRects = NULL) const {
151 this->getConservativeBounds(surface->width(), surface->height(), 179 this->getConservativeBounds(surface->width(), surface->height(),
152 devResult, isIntersectionOfRects); 180 devResult, isIntersectionOfRects);
153 } 181 }
154 182
155 void getConservativeBounds(int width, int height, 183 void getConservativeBounds(int width, int height,
156 SkIRect* devResult, 184 SkIRect* devResult,
157 bool* isIntersectionOfRects = NULL) const; 185 bool* isIntersectionOfRects = NULL) const;
158 186
159 static const GrClip& WideOpen() { 187 static const GrClip& WideOpen() {
160 static GrClip clip; 188 static GrClip clip;
161 return clip; 189 return clip;
162 } 190 }
163 191
164 enum ClipType { 192 enum ClipType {
165 kClipStack_ClipType, 193 kClipStack_ClipType,
166 kWideOpen_ClipType, 194 kWideOpen_ClipType,
167 kIRect_ClipType, 195 kIRect_ClipType,
196 kRect_ClipType,
168 }; 197 };
169 198
170 ClipType clipType() const { return fClipType; } 199 ClipType clipType() const { return fClipType; }
171 200
172 private: 201 private:
173 union Clip { 202 union Clip {
174 const SkClipStack* fStack; 203 const SkClipStack* fStack;
204 SkRect fRect;
175 SkIRect fIRect; 205 SkIRect fIRect;
176 } fClip; 206 } fClip;
177 207
178 SkIPoint fOrigin; 208 SkIPoint fOrigin;
179 ClipType fClipType; 209 ClipType fClipType;
180 }; 210 };
181 211
182 #endif 212 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698