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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 int numTextures() const { return fTextureAccesses.count(); } | 146 int numTextures() const { return fTextureAccesses.count(); } |
147 | 147 |
148 /** Returns the access pattern for the texture at index. index must be valid
according to | 148 /** Returns the access pattern for the texture at index. index must be valid
according to |
149 numTextures(). */ | 149 numTextures(). */ |
150 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce
sses[index]; } | 150 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce
sses[index]; } |
151 | 151 |
152 /** Shortcut for textureAccess(index).texture(); */ | 152 /** Shortcut for textureAccess(index).texture(); */ |
153 GrTexture* texture(int index) const { return this->textureAccess(index).getT
exture(); } | 153 GrTexture* texture(int index) const { return this->textureAccess(index).getT
exture(); } |
154 | 154 |
155 /** Will this effect read the destination pixel value? */ | 155 /** Will this effect read the destination pixel value? */ |
156 bool willReadDst() const { return fWillReadDst; } | 156 bool willReadDstColor() const { return fWillReadDstColor; } |
| 157 |
| 158 /** Will this effect read the fragment position? */ |
| 159 bool willReadFragmentPosition() const { return fWillReadFragmentPosition; } |
157 | 160 |
158 int numVertexAttribs() const { return fVertexAttribTypes.count(); } | 161 int numVertexAttribs() const { return fVertexAttribTypes.count(); } |
159 | 162 |
160 GrSLType vertexAttribType(int index) const { return fVertexAttribTypes[index
]; } | 163 GrSLType vertexAttribType(int index) const { return fVertexAttribTypes[index
]; } |
161 | 164 |
162 static const int kMaxVertexAttribs = 2; | 165 static const int kMaxVertexAttribs = 2; |
163 | 166 |
164 /** Useful for effects that want to insert a texture matrix that is implied
by the texture | 167 /** Useful for effects that want to insert a texture matrix that is implied
by the texture |
165 dimensions */ | 168 dimensions */ |
166 static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) { | 169 static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 */ | 209 */ |
207 void addTextureAccess(const GrTextureAccess* textureAccess); | 210 void addTextureAccess(const GrTextureAccess* textureAccess); |
208 | 211 |
209 /** | 212 /** |
210 * Subclasses call this from their constructor to register vertex attributes
(at most | 213 * Subclasses call this from their constructor to register vertex attributes
(at most |
211 * kMaxVertexAttribs). This must only be called from the constructor because
GrEffects are | 214 * kMaxVertexAttribs). This must only be called from the constructor because
GrEffects are |
212 * immutable. | 215 * immutable. |
213 */ | 216 */ |
214 void addVertexAttrib(GrSLType type); | 217 void addVertexAttrib(GrSLType type); |
215 | 218 |
216 GrEffect() : fWillReadDst(false), fEffectRef(NULL) {} | 219 GrEffect() : fWillReadDstColor(false), fWillReadFragmentPosition(false), fEf
fectRef(NULL) {} |
217 | 220 |
218 /** This should be called by GrEffect subclass factories. See the comment on
AutoEffectUnref for | 221 /** This should be called by GrEffect subclass factories. See the comment on
AutoEffectUnref for |
219 an example factory function. */ | 222 an example factory function. */ |
220 static GrEffectRef* CreateEffectRef(GrEffect* effect) { | 223 static GrEffectRef* CreateEffectRef(GrEffect* effect) { |
221 if (NULL == effect->fEffectRef) { | 224 if (NULL == effect->fEffectRef) { |
222 effect->fEffectRef = SkNEW_ARGS(GrEffectRef, (effect)); | 225 effect->fEffectRef = SkNEW_ARGS(GrEffectRef, (effect)); |
223 } else { | 226 } else { |
224 effect->fEffectRef->ref(); | 227 effect->fEffectRef->ref(); |
225 } | 228 } |
226 return effect->fEffectRef; | 229 return effect->fEffectRef; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 template <typename T> | 265 template <typename T> |
263 static const T& CastEffect(const GrEffect& effectRef) { | 266 static const T& CastEffect(const GrEffect& effectRef) { |
264 return *static_cast<const T*>(&effectRef); | 267 return *static_cast<const T*>(&effectRef); |
265 } | 268 } |
266 | 269 |
267 /** | 270 /** |
268 * If the effect subclass will read the destination pixel value then it must
call this function | 271 * If the effect subclass will read the destination pixel value then it must
call this function |
269 * from its constructor. Otherwise, when its generated backend-specific effe
ct class attempts | 272 * from its constructor. Otherwise, when its generated backend-specific effe
ct class attempts |
270 * to generate code that reads the destination pixel it will fail. | 273 * to generate code that reads the destination pixel it will fail. |
271 */ | 274 */ |
272 void setWillReadDst() { fWillReadDst = true; } | 275 void setWillReadDstColor() { fWillReadDstColor = true; } |
| 276 |
| 277 /** |
| 278 * If the effect will generate a backend-specific effect that will read the
fragment position |
| 279 * in the FS then it must call this method from its constructor. Otherwise,
the request to |
| 280 * access the fragment position will be denied. |
| 281 */ |
| 282 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; } |
273 | 283 |
274 private: | 284 private: |
275 bool isEqual(const GrEffect& other) const { | 285 bool isEqual(const GrEffect& other) const { |
276 if (&this->getFactory() != &other.getFactory()) { | 286 if (&this->getFactory() != &other.getFactory()) { |
277 return false; | 287 return false; |
278 } | 288 } |
279 bool result = this->onIsEqual(other); | 289 bool result = this->onIsEqual(other); |
280 #if GR_DEBUG | 290 #if GR_DEBUG |
281 if (result) { | 291 if (result) { |
282 GrAssert(this->numTextures() == other.numTextures()); | 292 GrAssert(this->numTextures() == other.numTextures()); |
(...skipping 12 matching lines...) Expand all Loading... |
295 | 305 |
296 void EffectRefDestroyed() { fEffectRef = NULL; } | 306 void EffectRefDestroyed() { fEffectRef = NULL; } |
297 | 307 |
298 friend class GrEffectRef; // to call EffectRefDestroyed() | 308 friend class GrEffectRef; // to call EffectRefDestroyed() |
299 friend class GrEffectStage; // to rewrap GrEffect in GrEffectRef when restor
ing an effect-stage | 309 friend class GrEffectStage; // to rewrap GrEffect in GrEffectRef when restor
ing an effect-stage |
300 // from deferred state, to call isEqual on naked
GrEffects, and | 310 // from deferred state, to call isEqual on naked
GrEffects, and |
301 // to inc/dec deferred ref counts. | 311 // to inc/dec deferred ref counts. |
302 | 312 |
303 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; | 313 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; |
304 SkSTArray<kMaxVertexAttribs, GrSLType, true> fVertexAttribTypes; | 314 SkSTArray<kMaxVertexAttribs, GrSLType, true> fVertexAttribTypes; |
305 bool fWillReadDst; | 315 bool fWillReadDstColor; |
| 316 bool fWillReadFragmentPosition; |
306 GrEffectRef* fEffectRef; | 317 GrEffectRef* fEffectRef; |
307 | 318 |
308 typedef GrRefCnt INHERITED; | 319 typedef GrRefCnt INHERITED; |
309 }; | 320 }; |
310 | 321 |
311 inline GrEffectRef::GrEffectRef(GrEffect* effect) { | 322 inline GrEffectRef::GrEffectRef(GrEffect* effect) { |
312 GrAssert(NULL != effect); | 323 GrAssert(NULL != effect); |
313 effect->ref(); | 324 effect->ref(); |
314 fEffect = effect; | 325 fEffect = effect; |
315 } | 326 } |
316 | 327 |
317 /** | 328 /** |
318 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called | 329 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called |
319 * at global destruction time. NAME will be the name of the created GrEffectRef. | 330 * at global destruction time. NAME will be the name of the created GrEffectRef. |
320 */ | 331 */ |
321 #define GR_CREATE_STATIC_EFFECT(NAME, EFFECT_CLASS, ARGS)
\ | 332 #define GR_CREATE_STATIC_EFFECT(NAME, EFFECT_CLASS, ARGS)
\ |
322 enum {
\ | 333 enum {
\ |
323 k_##NAME##_EffectRefOffset = GR_CT_ALIGN_UP(sizeof(EFFECT_CLASS), 8),
\ | 334 k_##NAME##_EffectRefOffset = GR_CT_ALIGN_UP(sizeof(EFFECT_CLASS), 8),
\ |
324 k_##NAME##_StorageSize = k_##NAME##_EffectRefOffset + sizeof(GrEffectRef)
\ | 335 k_##NAME##_StorageSize = k_##NAME##_EffectRefOffset + sizeof(GrEffectRef)
\ |
325 };
\ | 336 };
\ |
326 static SkAlignedSStorage<k_##NAME##_StorageSize> g_##NAME##_Storage;
\ | 337 static SkAlignedSStorage<k_##NAME##_StorageSize> g_##NAME##_Storage;
\ |
327 static void* NAME##_RefLocation = (char*)g_##NAME##_Storage.get() + k_##NAME##_E
ffectRefOffset; \ | 338 static void* NAME##_RefLocation = (char*)g_##NAME##_Storage.get() + k_##NAME##_E
ffectRefOffset; \ |
328 static GrEffect* NAME##_Effect SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EF
FECT_CLASS, ARGS);\ | 339 static GrEffect* NAME##_Effect SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EF
FECT_CLASS, ARGS);\ |
329 static SkAutoTDestroy<GrEffect> NAME##_ad(NAME##_Effect);
\ | 340 static SkAutoTDestroy<GrEffect> NAME##_ad(NAME##_Effect);
\ |
330 static GrEffectRef* NAME(GrEffect::CreateStaticEffectRef(NAME##_RefLocation, NAM
E##_Effect)); \ | 341 static GrEffectRef* NAME(GrEffect::CreateStaticEffectRef(NAME##_RefLocation, NAM
E##_Effect)); \ |
331 static SkAutoTDestroy<GrEffectRef> NAME##_Ref_ad(NAME) | 342 static SkAutoTDestroy<GrEffectRef> NAME##_Ref_ad(NAME) |
332 | 343 |
333 | 344 |
334 #endif | 345 #endif |
OLD | NEW |