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 |
| 188 * kMaxVertexAttribs). This must only be called from the constructor because
GrEffects are |
| 189 * immutable. |
| 190 */ |
| 191 void addVertexAttrib(GrSLType type); |
| 192 |
177 GrEffect() : fEffectRef(NULL) {}; | 193 GrEffect() : fEffectRef(NULL) {}; |
178 | 194 |
179 /** This should be called by GrEffect subclass factories. See the comment on
AutoEffectUnref for | 195 /** This should be called by GrEffect subclass factories. See the comment on
AutoEffectUnref for |
180 an example factory function. */ | 196 an example factory function. */ |
181 static GrEffectRef* CreateEffectRef(GrEffect* effect) { | 197 static GrEffectRef* CreateEffectRef(GrEffect* effect) { |
182 if (NULL == effect->fEffectRef) { | 198 if (NULL == effect->fEffectRef) { |
183 effect->fEffectRef = SkNEW_ARGS(GrEffectRef, (effect)); | 199 effect->fEffectRef = SkNEW_ARGS(GrEffectRef, (effect)); |
184 } else { | 200 } else { |
185 effect->fEffectRef->ref(); | 201 effect->fEffectRef->ref(); |
186 } | 202 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 getFactory()).*/ | 255 getFactory()).*/ |
240 virtual bool onIsEqual(const GrEffect& other) const = 0; | 256 virtual bool onIsEqual(const GrEffect& other) const = 0; |
241 | 257 |
242 void EffectRefDestroyed() { fEffectRef = NULL; } | 258 void EffectRefDestroyed() { fEffectRef = NULL; } |
243 | 259 |
244 friend class GrEffectRef; // to call EffectRefDestroyed() | 260 friend class GrEffectRef; // to call EffectRefDestroyed() |
245 friend class GrEffectStage; // to rewrap GrEffect in GrEffectRef when restor
ing an effect-stage | 261 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 | 262 // from deferred state, to call isEqual on naked
GrEffects, and |
247 // to inc/dec deferred ref counts. | 263 // to inc/dec deferred ref counts. |
248 | 264 |
249 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; | 265 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; |
250 GrEffectRef* fEffectRef; | 266 SkSTArray<kMaxVertexAttribs, GrSLType, true> fVertexAttribTypes; |
| 267 GrEffectRef* fEffectRef; |
251 | 268 |
252 typedef GrRefCnt INHERITED; | 269 typedef GrRefCnt INHERITED; |
253 }; | 270 }; |
254 | 271 |
255 inline GrEffectRef::GrEffectRef(GrEffect* effect) { | 272 inline GrEffectRef::GrEffectRef(GrEffect* effect) { |
256 GrAssert(NULL != effect); | 273 GrAssert(NULL != effect); |
257 effect->ref(); | 274 effect->ref(); |
258 fEffect = effect; | 275 fEffect = effect; |
259 } | 276 } |
260 | 277 |
261 #endif | 278 #endif |
OLD | NEW |