OLD | NEW |
---|---|
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() { | |
24 fCoordChangeMatrixSet = false; | |
25 fVertexAttribIndices[0] = -1; | |
26 fVertexAttribIndices[1] = -1; | |
27 } | |
jvanverth1
2013/07/15 13:20:02
You may want to make the default constructor priva
bsalomon
2013/07/15 13:24:53
Since we have other constructors, there is no auto
| |
28 | |
29 explicit GrEffectStage(const GrEffectRef* effectRef, int attrIndex0 = -1, in t attrIndex1 = -1) | 23 explicit GrEffectStage(const GrEffectRef* effectRef, int attrIndex0 = -1, in t attrIndex1 = -1) |
30 : fEffectRef(SkSafeRef(effectRef)) { | 24 : fEffectRef(SkRef(effectRef)) { |
31 fCoordChangeMatrixSet = false; | 25 fCoordChangeMatrixSet = false; |
32 fVertexAttribIndices[0] = attrIndex0; | 26 fVertexAttribIndices[0] = attrIndex0; |
33 fVertexAttribIndices[1] = attrIndex1; | 27 fVertexAttribIndices[1] = attrIndex1; |
34 } | 28 } |
35 | 29 |
36 GrEffectStage(const GrEffectStage& other) { | 30 GrEffectStage(const GrEffectStage& other) { |
37 *this = other; | 31 *this = other; |
38 } | 32 } |
39 | 33 |
34 class DeferredStage; | |
35 // This constructor balances DeferredStage::saveFrom(). | |
36 explicit GrEffectStage(const DeferredStage& deferredStage) { | |
37 deferredStage.restoreTo(this); | |
38 } | |
39 | |
40 GrEffectStage& operator= (const GrEffectStage& other) { | 40 GrEffectStage& operator= (const GrEffectStage& other) { |
41 fCoordChangeMatrixSet = other.fCoordChangeMatrixSet; | 41 fCoordChangeMatrixSet = other.fCoordChangeMatrixSet; |
42 if (other.fCoordChangeMatrixSet) { | 42 if (other.fCoordChangeMatrixSet) { |
43 fCoordChangeMatrix = other.fCoordChangeMatrix; | 43 fCoordChangeMatrix = other.fCoordChangeMatrix; |
44 } | 44 } |
45 fEffectRef.reset(SkSafeRef(other.fEffectRef.get())); | 45 fEffectRef.reset(SkRef(other.fEffectRef.get())); |
46 memcpy(fVertexAttribIndices, other.fVertexAttribIndices, sizeof(fVertexA ttribIndices)); | 46 memcpy(fVertexAttribIndices, other.fVertexAttribIndices, sizeof(fVertexA ttribIndices)); |
47 return *this; | 47 return *this; |
48 } | 48 } |
49 | 49 |
50 bool operator== (const GrEffectStage& other) const { | 50 bool operator== (const GrEffectStage& other) const { |
51 // first handle cases where one or the other has no effect | 51 GrAssert(NULL != fEffectRef.get()); |
52 if (NULL == fEffectRef.get()) { | 52 GrAssert(NULL != other.fEffectRef.get()); |
53 return NULL == other.fEffectRef.get(); | |
54 } else if (NULL == other.fEffectRef.get()) { | |
55 return false; | |
56 } | |
57 | 53 |
58 if (!(*this->getEffect())->isEqual(*other.getEffect())) { | 54 if (!(*this->getEffect())->isEqual(*other.getEffect())) { |
59 return false; | 55 return false; |
60 } | 56 } |
61 | 57 |
62 if (fCoordChangeMatrixSet != other.fCoordChangeMatrixSet) { | 58 if (fCoordChangeMatrixSet != other.fCoordChangeMatrixSet) { |
63 return false; | 59 return false; |
64 } | 60 } |
65 | 61 |
66 if (!fCoordChangeMatrixSet) { | 62 if (!fCoordChangeMatrixSet) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 * localCoordChange calls since the effect was installed. It is used when th en caller | 97 * localCoordChange calls since the effect was installed. It is used when th en caller |
102 * wants to temporarily change the source geometry coord system, draw someth ing, and then | 98 * wants to temporarily change the source geometry coord system, draw someth ing, and then |
103 * restore the previous coord system (e.g. temporarily draw in device coords ). | 99 * restore the previous coord system (e.g. temporarily draw in device coords ). |
104 */ | 100 */ |
105 void saveCoordChange(SavedCoordChange* savedCoordChange) const { | 101 void saveCoordChange(SavedCoordChange* savedCoordChange) const { |
106 savedCoordChange->fCoordChangeMatrixSet = fCoordChangeMatrixSet; | 102 savedCoordChange->fCoordChangeMatrixSet = fCoordChangeMatrixSet; |
107 if (fCoordChangeMatrixSet) { | 103 if (fCoordChangeMatrixSet) { |
108 savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix; | 104 savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix; |
109 } | 105 } |
110 GrAssert(NULL == savedCoordChange->fEffectRef.get()); | 106 GrAssert(NULL == savedCoordChange->fEffectRef.get()); |
111 GR_DEBUGCODE(GrSafeRef(fEffectRef.get());) | 107 GR_DEBUGCODE(SkRef(fEffectRef.get());) |
112 GR_DEBUGCODE(savedCoordChange->fEffectRef.reset(fEffectRef.get());) | 108 GR_DEBUGCODE(savedCoordChange->fEffectRef.reset(fEffectRef.get());) |
113 } | 109 } |
114 | 110 |
115 /** | 111 /** |
116 * This balances the saveCoordChange call. | 112 * This balances the saveCoordChange call. |
117 */ | 113 */ |
118 void restoreCoordChange(const SavedCoordChange& savedCoordChange) { | 114 void restoreCoordChange(const SavedCoordChange& savedCoordChange) { |
119 fCoordChangeMatrixSet = savedCoordChange.fCoordChangeMatrixSet; | 115 fCoordChangeMatrixSet = savedCoordChange.fCoordChangeMatrixSet; |
120 if (fCoordChangeMatrixSet) { | 116 if (fCoordChangeMatrixSet) { |
121 fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix; | 117 fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix; |
(...skipping 13 matching lines...) Expand all Loading... | |
135 } | 131 } |
136 | 132 |
137 ~DeferredStage() { | 133 ~DeferredStage() { |
138 if (NULL != fEffect) { | 134 if (NULL != fEffect) { |
139 fEffect->decDeferredRefCounts(); | 135 fEffect->decDeferredRefCounts(); |
140 } | 136 } |
141 } | 137 } |
142 | 138 |
143 void saveFrom(const GrEffectStage& stage) { | 139 void saveFrom(const GrEffectStage& stage) { |
144 GrAssert(!fInitialized); | 140 GrAssert(!fInitialized); |
145 if (NULL != stage.fEffectRef.get()) { | 141 GrAssert(NULL != stage.fEffectRef.get()); |
146 stage.fEffectRef->get()->incDeferredRefCounts(); | 142 stage.fEffectRef->get()->incDeferredRefCounts(); |
147 fEffect = stage.fEffectRef->get(); | 143 fEffect = stage.fEffectRef->get(); |
148 fCoordChangeMatrixSet = stage.fCoordChangeMatrixSet; | 144 fCoordChangeMatrixSet = stage.fCoordChangeMatrixSet; |
149 if (fCoordChangeMatrixSet) { | 145 if (fCoordChangeMatrixSet) { |
150 fCoordChangeMatrix = stage.fCoordChangeMatrix; | 146 fCoordChangeMatrix = stage.fCoordChangeMatrix; |
151 } | |
152 fVertexAttribIndices[0] = stage.fVertexAttribIndices[0]; | |
153 fVertexAttribIndices[1] = stage.fVertexAttribIndices[1]; | |
154 } | 147 } |
148 fVertexAttribIndices[0] = stage.fVertexAttribIndices[0]; | |
149 fVertexAttribIndices[1] = stage.fVertexAttribIndices[1]; | |
155 SkDEBUGCODE(fInitialized = true;) | 150 SkDEBUGCODE(fInitialized = true;) |
156 } | 151 } |
157 | 152 |
158 void restoreTo(GrEffectStage* stage) { | 153 void restoreTo(GrEffectStage* stage) const { |
159 GrAssert(fInitialized); | 154 GrAssert(fInitialized); |
160 if (NULL != fEffect) { | 155 stage->fEffectRef.reset(GrEffect::CreateEffectRef(fEffect)); |
161 stage->fEffectRef.reset(GrEffect::CreateEffectRef(fEffect)); | 156 stage->fCoordChangeMatrixSet = fCoordChangeMatrixSet; |
162 stage->fCoordChangeMatrixSet = fCoordChangeMatrixSet; | 157 if (fCoordChangeMatrixSet) { |
163 if (fCoordChangeMatrixSet) { | 158 stage->fCoordChangeMatrix = fCoordChangeMatrix; |
164 stage->fCoordChangeMatrix = fCoordChangeMatrix; | |
165 } | |
166 stage->fVertexAttribIndices[0] = fVertexAttribIndices[0]; | |
167 stage->fVertexAttribIndices[1] = fVertexAttribIndices[1]; | |
168 } else { | |
169 stage->fEffectRef.reset(NULL); | |
170 } | 159 } |
160 stage->fVertexAttribIndices[0] = fVertexAttribIndices[0]; | |
161 stage->fVertexAttribIndices[1] = fVertexAttribIndices[1]; | |
171 } | 162 } |
172 | 163 |
173 bool isEqual(const GrEffectStage& stage, bool ignoreCoordChange) const { | 164 bool isEqual(const GrEffectStage& stage, bool ignoreCoordChange) const { |
174 if (NULL == stage.fEffectRef.get()) { | 165 if (fVertexAttribIndices[0] != stage.fVertexAttribIndices[0] || |
175 return NULL == fEffect; | 166 fVertexAttribIndices[1] != stage.fVertexAttribIndices[1]) { |
176 } else if (NULL == fEffect) { | |
177 return false; | 167 return false; |
178 } | 168 } |
179 | 169 |
180 if (fVertexAttribIndices[0] != stage.fVertexAttribIndices[0] | |
181 || fVertexAttribIndices[1] != stage.fVertexAttribIndices[1]) { | |
182 return false; | |
183 } | |
184 | |
185 if (!(*stage.getEffect())->isEqual(*fEffect)) { | 170 if (!(*stage.getEffect())->isEqual(*fEffect)) { |
186 return false; | 171 return false; |
187 } | 172 } |
188 | 173 |
189 if (ignoreCoordChange) { | 174 if (ignoreCoordChange) { |
190 // ignore the coordinate change matrix since there are | 175 // ignore the coordinate change matrix since there are |
191 // explicit uv coordinates | 176 // explicit uv coordinates |
192 return true; | 177 return true; |
193 } | 178 } |
194 | 179 |
(...skipping 21 matching lines...) Expand all Loading... | |
216 * installed in the stage. | 201 * installed in the stage. |
217 */ | 202 */ |
218 const SkMatrix& getCoordChangeMatrix() const { | 203 const SkMatrix& getCoordChangeMatrix() const { |
219 if (fCoordChangeMatrixSet) { | 204 if (fCoordChangeMatrixSet) { |
220 return fCoordChangeMatrix; | 205 return fCoordChangeMatrix; |
221 } else { | 206 } else { |
222 return SkMatrix::I(); | 207 return SkMatrix::I(); |
223 } | 208 } |
224 } | 209 } |
225 | 210 |
226 void reset() { fEffectRef.reset(NULL); } | |
227 | |
228 const GrEffectRef* setEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) { | |
229 fEffectRef.reset(SkSafeRef(effect)); | |
230 fCoordChangeMatrixSet = false; | |
231 | |
232 fVertexAttribIndices[0] = attr0; | |
233 fVertexAttribIndices[1] = attr1; | |
234 | |
235 return effect; | |
236 } | |
237 | |
238 const GrEffectRef* getEffect() const { return fEffectRef.get(); } | 211 const GrEffectRef* getEffect() const { return fEffectRef.get(); } |
239 | 212 |
240 const int* getVertexAttribIndices() const { return fVertexAttribIndices; } | 213 const int* getVertexAttribIndices() const { return fVertexAttribIndices; } |
241 int getVertexAttribIndexCount() const { return fEffectRef->get()->numVertexA ttribs(); } | 214 int getVertexAttribIndexCount() const { return fEffectRef->get()->numVertexA ttribs(); } |
242 | 215 |
243 private: | 216 private: |
244 bool fCoordChangeMatrixSet; | 217 bool fCoordChangeMatrixSet; |
245 SkMatrix fCoordChangeMatrix; | 218 SkMatrix fCoordChangeMatrix; |
246 SkAutoTUnref<const GrEffectRef> fEffectRef; | 219 SkAutoTUnref<const GrEffectRef> fEffectRef; |
247 int fVertexAttribIndices[2]; | 220 int fVertexAttribIndices[2]; |
248 }; | 221 }; |
249 | 222 |
250 #endif | 223 #endif |
OLD | NEW |