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

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

Issue 16952006: Replace fixed-size array of effect stages in GrDrawState with two appendable arrays, one for color,… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix comments Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « include/gpu/GrContext.h ('k') | src/gpu/GrAAConvexPathRenderer.cpp » ('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 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 10
11 #ifndef GrEffectStage_DEFINED 11 #ifndef GrEffectStage_DEFINED
12 #define GrEffectStage_DEFINED 12 #define GrEffectStage_DEFINED
13 13
14 #include "GrBackendEffectFactory.h" 14 #include "GrBackendEffectFactory.h"
15 #include "GrEffect.h" 15 #include "GrEffect.h"
16 #include "SkMatrix.h" 16 #include "SkMatrix.h"
17 #include "GrTypes.h" 17 #include "GrTypes.h"
18 18
19 #include "SkShader.h" 19 #include "SkShader.h"
20 20
21 class GrEffectStage { 21 class GrEffectStage {
22 public: 22 public:
23 GrEffectStage() 23 GrEffectStage() {
24 : fEffectRef (NULL) { 24 fCoordChangeMatrixSet = false;
25 GR_DEBUGCODE(fSavedCoordChangeCnt = 0;) 25 fVertexAttribIndices[0] = -1;
26 fVertexAttribIndices[1] = -1;
26 } 27 }
27 28
28 ~GrEffectStage() { 29 explicit GrEffectStage(const GrEffectRef* effectRef, int attrIndex0 = -1, in t attrIndex1 = -1)
29 GrSafeUnref(fEffectRef); 30 : fEffectRef(SkSafeRef(effectRef)) {
30 GrAssert(0 == fSavedCoordChangeCnt); 31 fCoordChangeMatrixSet = false;
32 fVertexAttribIndices[0] = attrIndex0;
33 fVertexAttribIndices[1] = attrIndex1;
31 } 34 }
32 35
33 bool operator ==(const GrEffectStage& other) const { 36 GrEffectStage(const GrEffectStage& other) {
37 *this = other;
38 }
39
40 GrEffectStage& operator= (const GrEffectStage& other) {
41 fCoordChangeMatrixSet = other.fCoordChangeMatrixSet;
42 if (other.fCoordChangeMatrixSet) {
43 fCoordChangeMatrix = other.fCoordChangeMatrix;
44 }
45 fEffectRef.reset(SkSafeRef(other.fEffectRef.get()));
46 memcpy(fVertexAttribIndices, other.fVertexAttribIndices, sizeof(fVertexA ttribIndices));
47 return *this;
48 }
49
50 bool operator== (const GrEffectStage& other) const {
34 // first handle cases where one or the other has no effect 51 // first handle cases where one or the other has no effect
35 if (NULL == fEffectRef) { 52 if (NULL == fEffectRef.get()) {
36 return NULL == other.fEffectRef; 53 return NULL == other.fEffectRef.get();
37 } else if (NULL == other.fEffectRef) { 54 } else if (NULL == other.fEffectRef.get()) {
38 return false; 55 return false;
39 } 56 }
40 57
41 if (!(*this->getEffect())->isEqual(*other.getEffect())) { 58 if (!(*this->getEffect())->isEqual(*other.getEffect())) {
42 return false; 59 return false;
43 } 60 }
44 61
45 if (fCoordChangeMatrixSet != other.fCoordChangeMatrixSet) { 62 if (fCoordChangeMatrixSet != other.fCoordChangeMatrixSet) {
46 return false; 63 return false;
47 } 64 }
48 65
49 if (!fCoordChangeMatrixSet) { 66 if (!fCoordChangeMatrixSet) {
50 return true; 67 return true;
51 } 68 }
52 69
53 return fCoordChangeMatrix == other.fCoordChangeMatrix; 70 return fCoordChangeMatrix == other.fCoordChangeMatrix;
54 } 71 }
55 72
56 bool operator!= (const GrEffectStage& s) const { return !(*this == s); } 73 bool operator!= (const GrEffectStage& s) const { return !(*this == s); }
57 74
58 GrEffectStage& operator= (const GrEffectStage& other) {
59 GrSafeAssign(fEffectRef, other.fEffectRef);
60 fCoordChangeMatrixSet = other.fCoordChangeMatrixSet;
61 if (NULL != fEffectRef && fCoordChangeMatrixSet) {
62 fCoordChangeMatrix = other.fCoordChangeMatrix;
63 }
64 return *this;
65 }
66
67 /** 75 /**
68 * This is called when the coordinate system in which the geometry is specif ied will change. 76 * This is called when the coordinate system in which the geometry is specif ied will change.
69 * 77 *
70 * @param matrix The transformation from the old coord system in which ge ometry is specified 78 * @param matrix The transformation from the old coord system in which ge ometry is specified
71 * to the new one from which it will actually be drawn. 79 * to the new one from which it will actually be drawn.
72 */ 80 */
73 void localCoordChange(const SkMatrix& matrix) { 81 void localCoordChange(const SkMatrix& matrix) {
74 if (fCoordChangeMatrixSet) { 82 if (fCoordChangeMatrixSet) {
75 fCoordChangeMatrix.preConcat(matrix); 83 fCoordChangeMatrix.preConcat(matrix);
76 } else { 84 } else {
(...skipping 16 matching lines...) Expand all
93 * localCoordChange calls since the effect was installed. It is used when th en caller 101 * localCoordChange calls since the effect was installed. It is used when th en caller
94 * wants to temporarily change the source geometry coord system, draw someth ing, and then 102 * wants to temporarily change the source geometry coord system, draw someth ing, and then
95 * restore the previous coord system (e.g. temporarily draw in device coords ). 103 * restore the previous coord system (e.g. temporarily draw in device coords ).
96 */ 104 */
97 void saveCoordChange(SavedCoordChange* savedCoordChange) const { 105 void saveCoordChange(SavedCoordChange* savedCoordChange) const {
98 savedCoordChange->fCoordChangeMatrixSet = fCoordChangeMatrixSet; 106 savedCoordChange->fCoordChangeMatrixSet = fCoordChangeMatrixSet;
99 if (fCoordChangeMatrixSet) { 107 if (fCoordChangeMatrixSet) {
100 savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix; 108 savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix;
101 } 109 }
102 GrAssert(NULL == savedCoordChange->fEffectRef.get()); 110 GrAssert(NULL == savedCoordChange->fEffectRef.get());
103 GR_DEBUGCODE(GrSafeRef(fEffectRef);) 111 GR_DEBUGCODE(GrSafeRef(fEffectRef.get());)
104 GR_DEBUGCODE(savedCoordChange->fEffectRef.reset(fEffectRef);) 112 GR_DEBUGCODE(savedCoordChange->fEffectRef.reset(fEffectRef.get());)
105 GR_DEBUGCODE(++fSavedCoordChangeCnt);
106 } 113 }
107 114
108 /** 115 /**
109 * This balances the saveCoordChange call. 116 * This balances the saveCoordChange call.
110 */ 117 */
111 void restoreCoordChange(const SavedCoordChange& savedCoordChange) { 118 void restoreCoordChange(const SavedCoordChange& savedCoordChange) {
112 fCoordChangeMatrixSet = savedCoordChange.fCoordChangeMatrixSet; 119 fCoordChangeMatrixSet = savedCoordChange.fCoordChangeMatrixSet;
113 if (fCoordChangeMatrixSet) { 120 if (fCoordChangeMatrixSet) {
114 fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix; 121 fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix;
115 } 122 }
116 GrAssert(savedCoordChange.fEffectRef.get() == fEffectRef); 123 GrAssert(savedCoordChange.fEffectRef.get() == fEffectRef);
117 GR_DEBUGCODE(--fSavedCoordChangeCnt);
118 GR_DEBUGCODE(savedCoordChange.fEffectRef.reset(NULL);) 124 GR_DEBUGCODE(savedCoordChange.fEffectRef.reset(NULL);)
119 } 125 }
120 126
121 /** 127 /**
122 * Used when storing a deferred GrDrawState. The DeferredStage allows resour ces owned by its 128 * Used when storing a deferred GrDrawState. The DeferredStage allows resour ces owned by its
123 * GrEffect to be recycled through the cache. 129 * GrEffect to be recycled through the cache.
124 */ 130 */
125 class DeferredStage { 131 class DeferredStage {
126 public: 132 public:
127 DeferredStage() : fEffect(NULL) { 133 DeferredStage() : fEffect(NULL) {
128 SkDEBUGCODE(fInitialized = false;) 134 SkDEBUGCODE(fInitialized = false;)
129 } 135 }
130 136
131 ~DeferredStage() { 137 ~DeferredStage() {
132 if (NULL != fEffect) { 138 if (NULL != fEffect) {
133 fEffect->decDeferredRefCounts(); 139 fEffect->decDeferredRefCounts();
134 } 140 }
135 } 141 }
136 142
137 void saveFrom(const GrEffectStage& stage) { 143 void saveFrom(const GrEffectStage& stage) {
138 GrAssert(!fInitialized); 144 GrAssert(!fInitialized);
139 if (NULL != stage.fEffectRef) { 145 if (NULL != stage.fEffectRef.get()) {
140 stage.fEffectRef->get()->incDeferredRefCounts(); 146 stage.fEffectRef->get()->incDeferredRefCounts();
141 fEffect = stage.fEffectRef->get(); 147 fEffect = stage.fEffectRef->get();
142 fCoordChangeMatrixSet = stage.fCoordChangeMatrixSet; 148 fCoordChangeMatrixSet = stage.fCoordChangeMatrixSet;
143 if (fCoordChangeMatrixSet) { 149 if (fCoordChangeMatrixSet) {
144 fCoordChangeMatrix = stage.fCoordChangeMatrix; 150 fCoordChangeMatrix = stage.fCoordChangeMatrix;
145 } 151 }
146 fVertexAttribIndices[0] = stage.fVertexAttribIndices[0]; 152 fVertexAttribIndices[0] = stage.fVertexAttribIndices[0];
147 fVertexAttribIndices[1] = stage.fVertexAttribIndices[1]; 153 fVertexAttribIndices[1] = stage.fVertexAttribIndices[1];
148 } 154 }
149 SkDEBUGCODE(fInitialized = true;) 155 SkDEBUGCODE(fInitialized = true;)
150 } 156 }
151 157
152 void restoreTo(GrEffectStage* stage) { 158 void restoreTo(GrEffectStage* stage) {
153 GrAssert(fInitialized); 159 GrAssert(fInitialized);
154 const GrEffectRef* oldEffectRef = stage->fEffectRef;
155 if (NULL != fEffect) { 160 if (NULL != fEffect) {
156 stage->fEffectRef = GrEffect::CreateEffectRef(fEffect); 161 stage->fEffectRef.reset(GrEffect::CreateEffectRef(fEffect));
157 stage->fCoordChangeMatrixSet = fCoordChangeMatrixSet; 162 stage->fCoordChangeMatrixSet = fCoordChangeMatrixSet;
158 if (fCoordChangeMatrixSet) { 163 if (fCoordChangeMatrixSet) {
159 stage->fCoordChangeMatrix = fCoordChangeMatrix; 164 stage->fCoordChangeMatrix = fCoordChangeMatrix;
160 } 165 }
161 stage->fVertexAttribIndices[0] = fVertexAttribIndices[0]; 166 stage->fVertexAttribIndices[0] = fVertexAttribIndices[0];
162 stage->fVertexAttribIndices[1] = fVertexAttribIndices[1]; 167 stage->fVertexAttribIndices[1] = fVertexAttribIndices[1];
163 } else { 168 } else {
164 stage->fEffectRef = NULL; 169 stage->fEffectRef.reset(NULL);
165 } 170 }
166 SkSafeUnref(oldEffectRef);
167 } 171 }
168 172
169 bool isEqual(const GrEffectStage& stage, bool ignoreCoordChange) const { 173 bool isEqual(const GrEffectStage& stage, bool ignoreCoordChange) const {
170 if (NULL == stage.fEffectRef) { 174 if (NULL == stage.fEffectRef.get()) {
171 return NULL == fEffect; 175 return NULL == fEffect;
172 } else if (NULL == fEffect) { 176 } else if (NULL == fEffect) {
173 return false; 177 return false;
174 } 178 }
175 179
176 if (fVertexAttribIndices[0] != stage.fVertexAttribIndices[0] 180 if (fVertexAttribIndices[0] != stage.fVertexAttribIndices[0]
177 || fVertexAttribIndices[1] != stage.fVertexAttribIndices[1]) { 181 || fVertexAttribIndices[1] != stage.fVertexAttribIndices[1]) {
178 return false; 182 return false;
179 } 183 }
180 184
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 * installed in the stage. 216 * installed in the stage.
213 */ 217 */
214 const SkMatrix& getCoordChangeMatrix() const { 218 const SkMatrix& getCoordChangeMatrix() const {
215 if (fCoordChangeMatrixSet) { 219 if (fCoordChangeMatrixSet) {
216 return fCoordChangeMatrix; 220 return fCoordChangeMatrix;
217 } else { 221 } else {
218 return SkMatrix::I(); 222 return SkMatrix::I();
219 } 223 }
220 } 224 }
221 225
222 void reset() { 226 void reset() { fEffectRef.reset(NULL); }
223 GrSafeSetNull(fEffectRef);
224 }
225 227
226 const GrEffectRef* setEffect(const GrEffectRef* EffectRef) { 228 const GrEffectRef* setEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) {
227 GrAssert(0 == fSavedCoordChangeCnt); 229 fEffectRef.reset(SkSafeRef(effect));
228 GrSafeAssign(fEffectRef, EffectRef);
229 fCoordChangeMatrixSet = false;
230
231 fVertexAttribIndices[0] = -1;
232 fVertexAttribIndices[1] = -1;
233
234 return EffectRef;
235 }
236
237 const GrEffectRef* setEffect(const GrEffectRef* EffectRef, int attr0, int at tr1 = -1) {
238 GrAssert(0 == fSavedCoordChangeCnt);
239 GrSafeAssign(fEffectRef, EffectRef);
240 fCoordChangeMatrixSet = false; 230 fCoordChangeMatrixSet = false;
241 231
242 fVertexAttribIndices[0] = attr0; 232 fVertexAttribIndices[0] = attr0;
243 fVertexAttribIndices[1] = attr1; 233 fVertexAttribIndices[1] = attr1;
244 234
245 return EffectRef; 235 return effect;
246 } 236 }
247 237
248 const GrEffectRef* getEffect() const { return fEffectRef; } 238 const GrEffectRef* getEffect() const { return fEffectRef.get(); }
249 239
250 const int* getVertexAttribIndices() const { return fVertexAttribIndices; } 240 const int* getVertexAttribIndices() const { return fVertexAttribIndices; }
251 int getVertexAttribIndexCount() const { return fEffectRef->get()->numVertexA ttribs(); } 241 int getVertexAttribIndexCount() const { return fEffectRef->get()->numVertexA ttribs(); }
252 242
253 private: 243 private:
254 bool fCoordChangeMatrixSet; 244 bool fCoordChangeMatrixSet;
255 SkMatrix fCoordChangeMatrix; 245 SkMatrix fCoordChangeMatrix;
256 const GrEffectRef* fEffectRef; 246 SkAutoTUnref<const GrEffectRef> fEffectRef;
257 int fVertexAttribIndices[2]; 247 int fVertexAttribIndices[2];
258
259 GR_DEBUGCODE(mutable int fSavedCoordChangeCnt;)
260 }; 248 };
261 249
262 #endif 250 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrContext.h ('k') | src/gpu/GrAAConvexPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698