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 static const int kMaxVertexAttribs = 2; | |
146 | |
147 | |
139 /** Useful for effects that want to insert a texture matrix that is implied by the texture | 148 /** Useful for effects that want to insert a texture matrix that is implied by the texture |
140 dimensions */ | 149 dimensions */ |
141 static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) { | 150 static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) { |
142 GrAssert(NULL != texture); | 151 GrAssert(NULL != texture); |
143 SkMatrix mat; | 152 SkMatrix mat; |
144 mat.setIDiv(texture->width(), texture->height()); | 153 mat.setIDiv(texture->width(), texture->height()); |
145 return mat; | 154 return mat; |
146 } | 155 } |
147 | 156 |
148 void* operator new(size_t size); | 157 void* operator new(size_t size); |
(...skipping 12 matching lines...) Expand all Loading... | |
161 void decDeferredRefCounts() const { | 170 void decDeferredRefCounts() const { |
162 int count = fTextureAccesses.count(); | 171 int count = fTextureAccesses.count(); |
163 for (int t = 0; t < count; ++t) { | 172 for (int t = 0; t < count; ++t) { |
164 fTextureAccesses[t]->getTexture()->decDeferredRefCount(); | 173 fTextureAccesses[t]->getTexture()->decDeferredRefCount(); |
165 } | 174 } |
166 this->unref(); | 175 this->unref(); |
167 } | 176 } |
168 | 177 |
169 protected: | 178 protected: |
170 /** | 179 /** |
171 * Subclasses call this from their constructor to register GrTextureAcceses. The effect subclass | 180 * 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 | 181 * 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. | 182 * must only be called from the constructor because GrEffects are immutable. |
174 */ | 183 */ |
175 void addTextureAccess(const GrTextureAccess* textureAccess); | 184 void addTextureAccess(const GrTextureAccess* textureAccess); |
176 | 185 |
186 /** | |
187 * Subclasses call this from their constructor to register vertex attributes (at most 2). This | |
bsalomon
2013/03/08 18:27:20
(at most kMaxVertexAttribs) ?
| |
188 * must only be called from the constructor because GrEffects are immutable. | |
189 */ | |
190 void addVertexAttrib(GrSLType type); | |
191 | |
177 GrEffect() : fEffectRef(NULL) {}; | 192 GrEffect() : fEffectRef(NULL) {}; |
178 | 193 |
179 /** This should be called by GrEffect subclass factories. See the comment on AutoEffectUnref for | 194 /** This should be called by GrEffect subclass factories. See the comment on AutoEffectUnref for |
180 an example factory function. */ | 195 an example factory function. */ |
181 static GrEffectRef* CreateEffectRef(GrEffect* effect) { | 196 static GrEffectRef* CreateEffectRef(GrEffect* effect) { |
182 if (NULL == effect->fEffectRef) { | 197 if (NULL == effect->fEffectRef) { |
183 effect->fEffectRef = SkNEW_ARGS(GrEffectRef, (effect)); | 198 effect->fEffectRef = SkNEW_ARGS(GrEffectRef, (effect)); |
184 } else { | 199 } else { |
185 effect->fEffectRef->ref(); | 200 effect->fEffectRef->ref(); |
186 } | 201 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 getFactory()).*/ | 254 getFactory()).*/ |
240 virtual bool onIsEqual(const GrEffect& other) const = 0; | 255 virtual bool onIsEqual(const GrEffect& other) const = 0; |
241 | 256 |
242 void EffectRefDestroyed() { fEffectRef = NULL; } | 257 void EffectRefDestroyed() { fEffectRef = NULL; } |
243 | 258 |
244 friend class GrEffectRef; // to call EffectRefDestroyed() | 259 friend class GrEffectRef; // to call EffectRefDestroyed() |
245 friend class GrEffectStage; // to rewrap GrEffect in GrEffectRef when restor ing an effect-stage | 260 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 | 261 // from deferred state, to call isEqual on naked GrEffects, and |
247 // to inc/dec deferred ref counts. | 262 // to inc/dec deferred ref counts. |
248 | 263 |
249 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; | 264 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; |
250 GrEffectRef* fEffectRef; | 265 SkSTArray<kMaxVertexAttribs, GrSLType, true> fVertexAttribTypes; |
266 GrEffectRef* fEffectRef; | |
251 | 267 |
252 typedef GrRefCnt INHERITED; | 268 typedef GrRefCnt INHERITED; |
253 }; | 269 }; |
254 | 270 |
255 inline GrEffectRef::GrEffectRef(GrEffect* effect) { | 271 inline GrEffectRef::GrEffectRef(GrEffect* effect) { |
256 GrAssert(NULL != effect); | 272 GrAssert(NULL != effect); |
257 effect->ref(); | 273 effect->ref(); |
258 fEffect = effect; | 274 fEffect = effect; |
259 } | 275 } |
260 | 276 |
261 #endif | 277 #endif |
OLD | NEW |