OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 GrEffect_DEFINED | 8 #ifndef GrEffect_DEFINED |
9 #define GrEffect_DEFINED | 9 #define GrEffect_DEFINED |
10 | 10 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 | 129 |
130 int numTextures() const { return fTextureAccesses.count(); } | 130 int numTextures() const { return fTextureAccesses.count(); } |
131 | 131 |
132 /** Returns the access pattern for the texture at index. index must be valid according to | 132 /** Returns the access pattern for the texture at index. index must be valid according to |
133 numTextures(). */ | 133 numTextures(). */ |
134 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce sses[index]; } | 134 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce sses[index]; } |
135 | 135 |
136 /** Shortcut for textureAccess(index).texture(); */ | 136 /** Shortcut for textureAccess(index).texture(); */ |
137 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); } | 137 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); } |
138 | 138 |
139 | |
140 int numVertexAttribs() const { return fVertexAttribNames.count(); } | |
141 | |
142 const char* vertexAttribName(int index) const { return fVertexAttribNames[in dex]; } | |
143 | |
144 | |
139 /** Useful for effects that want to insert a texture matrix that is implied by the texture | 145 /** Useful for effects that want to insert a texture matrix that is implied by the texture |
140 dimensions */ | 146 dimensions */ |
141 static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) { | 147 static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) { |
142 GrAssert(NULL != texture); | 148 GrAssert(NULL != texture); |
143 SkMatrix mat; | 149 SkMatrix mat; |
144 mat.setIDiv(texture->width(), texture->height()); | 150 mat.setIDiv(texture->width(), texture->height()); |
145 return mat; | 151 return mat; |
146 } | 152 } |
147 | 153 |
148 void* operator new(size_t size); | 154 void* operator new(size_t size); |
(...skipping 12 matching lines...) Expand all Loading... | |
161 void decDeferredRefCounts() const { | 167 void decDeferredRefCounts() const { |
162 int count = fTextureAccesses.count(); | 168 int count = fTextureAccesses.count(); |
163 for (int t = 0; t < count; ++t) { | 169 for (int t = 0; t < count; ++t) { |
164 fTextureAccesses[t]->getTexture()->decDeferredRefCount(); | 170 fTextureAccesses[t]->getTexture()->decDeferredRefCount(); |
165 } | 171 } |
166 this->unref(); | 172 this->unref(); |
167 } | 173 } |
168 | 174 |
169 protected: | 175 protected: |
170 /** | 176 /** |
171 * Subclasses call this from their constructor to register GrTextureAcceses. The effect subclass | 177 * Subclasses call this from their constructor to register GrTextureAccesses . The effect subclass |
172 * manages the lifetime of the accesses (this function only stores a pointer ). This must only be | 178 * manages the lifetime of the accesses (this function only stores a pointer ). This must only be |
173 * called from the constructor because GrEffects are supposed to be immutabl e. | 179 * called from the constructor because GrEffects are supposed to be immutabl e. |
174 */ | 180 */ |
175 void addTextureAccess(const GrTextureAccess* textureAccess); | 181 void addTextureAccess(const GrTextureAccess* textureAccess); |
176 | 182 |
robertphillips
2013/03/05 20:30:13
two over length lines here
jvanverth1
2013/03/07 15:21:54
Done.
| |
183 /** | |
184 * Subclasses call this from their constructor to register names to be bound as vertex attributes. | |
185 * The effect subclass manages the lifetime of the name (this function only stores a pointer). This | |
robertphillips
2013/03/05 20:30:13
remove "supposed to be"?
jvanverth1
2013/03/07 15:21:54
Done.
| |
186 * must only be called from the constructor because GrEffects are supposed t o be immutable. | |
187 */ | |
188 void addVertexAttribName(const char* attrName); | |
189 | |
177 GrEffect() : fEffectRef(NULL) {}; | 190 GrEffect() : fEffectRef(NULL) {}; |
178 | 191 |
179 /** This should be called by GrEffect subclass factories. See the comment on AutoEffectUnref for | 192 /** This should be called by GrEffect subclass factories. See the comment on AutoEffectUnref for |
180 an example factory function. */ | 193 an example factory function. */ |
181 static GrEffectRef* CreateEffectRef(GrEffect* effect) { | 194 static GrEffectRef* CreateEffectRef(GrEffect* effect) { |
182 if (NULL == effect->fEffectRef) { | 195 if (NULL == effect->fEffectRef) { |
183 effect->fEffectRef = SkNEW_ARGS(GrEffectRef, (effect)); | 196 effect->fEffectRef = SkNEW_ARGS(GrEffectRef, (effect)); |
184 } else { | 197 } else { |
185 effect->fEffectRef->ref(); | 198 effect->fEffectRef->ref(); |
186 } | 199 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 virtual bool onIsEqual(const GrEffect& other) const = 0; | 253 virtual bool onIsEqual(const GrEffect& other) const = 0; |
241 | 254 |
242 void EffectRefDestroyed() { fEffectRef = NULL; } | 255 void EffectRefDestroyed() { fEffectRef = NULL; } |
243 | 256 |
244 friend class GrEffectRef; // to call EffectRefDestroyed() | 257 friend class GrEffectRef; // to call EffectRefDestroyed() |
245 friend class GrEffectStage; // to rewrap GrEffect in GrEffectRef when restor ing an effect-stage | 258 friend class GrEffectStage; // to rewrap GrEffect in GrEffectRef when restor ing an effect-stage |
246 // from deferred state, to call isEqual on naked GrEffects, and | 259 // from deferred state, to call isEqual on naked GrEffects, and |
247 // to inc/dec deferred ref counts. | 260 // to inc/dec deferred ref counts. |
248 | 261 |
249 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; | 262 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; |
263 SkSTArray<2, const char*, true> fVertexAttribNames; | |
250 GrEffectRef* fEffectRef; | 264 GrEffectRef* fEffectRef; |
251 | 265 |
252 typedef GrRefCnt INHERITED; | 266 typedef GrRefCnt INHERITED; |
253 }; | 267 }; |
254 | 268 |
255 inline GrEffectRef::GrEffectRef(GrEffect* effect) { | 269 inline GrEffectRef::GrEffectRef(GrEffect* effect) { |
256 GrAssert(NULL != effect); | 270 GrAssert(NULL != effect); |
257 effect->ref(); | 271 effect->ref(); |
258 fEffect = effect; | 272 fEffect = effect; |
259 } | 273 } |
260 | 274 |
261 #endif | 275 #endif |
OLD | NEW |