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 |
11 #include "GrColor.h" | 11 #include "GrColor.h" |
12 #include "GrEffectUnitTest.h" | 12 #include "GrEffectUnitTest.h" |
13 #include "GrNoncopyable.h" | 13 #include "GrNoncopyable.h" |
14 #include "GrRefCnt.h" | 14 #include "GrRefCnt.h" |
15 #include "GrTexture.h" | 15 #include "GrTexture.h" |
16 #include "GrTextureAccess.h" | 16 #include "GrTextureAccess.h" |
17 #include "GrTypesPriv.h" | |
17 | 18 |
18 class GrBackendEffectFactory; | 19 class GrBackendEffectFactory; |
19 class GrContext; | 20 class GrContext; |
20 class GrEffect; | 21 class GrEffect; |
21 class SkString; | 22 class SkString; |
22 | 23 |
23 /** | 24 /** |
24 * A Wrapper class for GrEffect. Its ref-count will track owners that may use ef fects to enqueue | 25 * A Wrapper class for GrEffect. Its ref-count will track owners that may use ef fects to enqueue |
25 * new draw operations separately from ownership within a deferred drawing queue . When the | 26 * new draw operations separately from ownership within a deferred drawing queue . When the |
26 * GrEffectRef ref count reaches zero the scratch GrResources owned by the effec t can be recycled | 27 * GrEffectRef ref count reaches zero the scratch GrResources owned by the effec t can be recycled |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 | 130 |
130 int numTextures() const { return fTextureAccesses.count(); } | 131 int numTextures() const { return fTextureAccesses.count(); } |
131 | 132 |
132 /** Returns the access pattern for the texture at index. index must be valid according to | 133 /** Returns the access pattern for the texture at index. index must be valid according to |
133 numTextures(). */ | 134 numTextures(). */ |
134 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce sses[index]; } | 135 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce sses[index]; } |
135 | 136 |
136 /** Shortcut for textureAccess(index).texture(); */ | 137 /** Shortcut for textureAccess(index).texture(); */ |
137 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); } | 138 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); } |
138 | 139 |
140 | |
141 int numVertexAttribs() const { return fVertexAttribTypes.count(); } | |
142 | |
143 GrSLType vertexAttribType(int index) const { return fVertexAttribTypes[index ]; } | |
144 | |
145 | |
139 /** Useful for effects that want to insert a texture matrix that is implied by the texture | 146 /** Useful for effects that want to insert a texture matrix that is implied by the texture |
140 dimensions */ | 147 dimensions */ |
141 static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) { | 148 static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) { |
142 GrAssert(NULL != texture); | 149 GrAssert(NULL != texture); |
143 SkMatrix mat; | 150 SkMatrix mat; |
144 mat.setIDiv(texture->width(), texture->height()); | 151 mat.setIDiv(texture->width(), texture->height()); |
145 return mat; | 152 return mat; |
146 } | 153 } |
147 | 154 |
148 void* operator new(size_t size); | 155 void* operator new(size_t size); |
(...skipping 12 matching lines...) Expand all Loading... | |
161 void decDeferredRefCounts() const { | 168 void decDeferredRefCounts() const { |
162 int count = fTextureAccesses.count(); | 169 int count = fTextureAccesses.count(); |
163 for (int t = 0; t < count; ++t) { | 170 for (int t = 0; t < count; ++t) { |
164 fTextureAccesses[t]->getTexture()->decDeferredRefCount(); | 171 fTextureAccesses[t]->getTexture()->decDeferredRefCount(); |
165 } | 172 } |
166 this->unref(); | 173 this->unref(); |
167 } | 174 } |
168 | 175 |
169 protected: | 176 protected: |
170 /** | 177 /** |
171 * Subclasses call this from their constructor to register GrTextureAcceses. The effect subclass | 178 * Subclasses call this from their constructor to register GrTextureAccesses . The effect |
172 * manages the lifetime of the accesses (this function only stores a pointer ). This must only be | 179 * subclass manages the lifetime of the accesses (this function only stores a pointer). This |
173 * called from the constructor because GrEffects are supposed to be immutabl e. | 180 * must only be called from the constructor because GrEffects are immutable. |
174 */ | 181 */ |
175 void addTextureAccess(const GrTextureAccess* textureAccess); | 182 void addTextureAccess(const GrTextureAccess* textureAccess); |
176 | 183 |
184 /** | |
185 * Subclasses call this from their constructor to register vertex attributes . This must only be | |
bsalomon
2013/03/08 14:31:58
Should we document the current limitation here? (a
jvanverth1
2013/03/08 17:39:55
Done. Also created a constant GrEffect::kMaxVertex
| |
186 * called from the constructor because GrEffects are immutable. | |
187 */ | |
188 void addVertexAttrib(GrSLType type); | |
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, GrSLType, true> fVertexAttribTypes; | |
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 |