Index: include/gpu/GrTBackendEffectFactory.h |
diff --git a/include/gpu/GrTBackendEffectFactory.h b/include/gpu/GrTBackendEffectFactory.h |
index 251e8c776877be577b0fa206ed616526fd81b1af..cd4c0a49e96a40aa16622606027717aad03784d1 100644 |
--- a/include/gpu/GrTBackendEffectFactory.h |
+++ b/include/gpu/GrTBackendEffectFactory.h |
@@ -13,26 +13,7 @@ |
#include "gl/GrGLProgramEffects.h" |
/** |
- * Implements GrBackendEffectFactory for a GrEffect subclass as a singleton. This can be used by |
- * most GrEffect subclasses to implement the GrEffect::getFactory() method: |
- * |
- * const GrBackendEffectFactory& MyEffect::getFactory() const { |
- * return GrTBackendEffectFactory<MyEffect>::getInstance(); |
- * } |
- * |
- * Using this class requires that the GrEffect subclass always produces the same GrGLEffect |
- * subclass. Additionally, It adds the following requirements to the GrEffect and GrGLEffect |
- * subclasses: |
- * |
- * 1. The GrGLEffect used by GrEffect subclass MyEffect must be named or typedef'ed to |
- * MyEffect::GLEffect. |
- * 2. MyEffect::GLEffect must have a static function: |
- * EffectKey GenKey(const GrDrawEffect, const GrGLCaps&) |
- * which generates a key that maps 1 to 1 with code variations emitted by |
- * MyEffect::GLEffect::emitCode(). |
- * 3. MyEffect must have a static function: |
- * const char* Name() |
- * which returns a human-readable name for the effect. |
+ * Implements GrBackendEffectFactory for a GrEffect subclass as a singleton. |
*/ |
template <typename EffectClass> |
class GrTBackendEffectFactory : public GrBackendEffectFactory { |
@@ -40,17 +21,35 @@ |
public: |
typedef typename EffectClass::GLEffect GLEffect; |
- /** Returns a human-readable name for the effect. Implemented using GLEffect::Name as described |
- * in this class's comment. */ |
+ /** Returns a human-readable name that is accessible via GrEffect or |
+ GrGLEffect and is consistent between the two of them. |
+ */ |
virtual const char* name() const SK_OVERRIDE { return EffectClass::Name(); } |
- |
- /** Implemented using GLEffect::GenKey as described in this class's comment. */ |
- virtual void getGLEffectKey(const GrDrawEffect& drawEffect, |
+ /** Generates an effect's key. This enables caching of generated shaders. Part of the |
+ id identifies the GrEffect subclass. The remainder is based on the aspects of the |
+ GrEffect object's configuration that affect GLSL code generation. If this fails |
+ then program generation should be aborted. Failure occurs if the effect uses more |
+ transforms, attributes, or textures than the key has space for. */ |
+ virtual bool getGLEffectKey(const GrDrawEffect& drawEffect, |
const GrGLCaps& caps, |
GrEffectKeyBuilder* b) const SK_OVERRIDE { |
+ SkASSERT(kIllegalEffectClassID != fEffectClassID); |
EffectKey effectKey = GLEffect::GenKey(drawEffect, caps); |
+ EffectKey textureKey = GrGLProgramEffects::GenTextureKey(drawEffect, caps); |
+ EffectKey transformKey = GrGLProgramEffects::GenTransformKey(drawEffect); |
+ EffectKey attribKey = GrGLProgramEffects::GenAttribKey(drawEffect); |
+ static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16); |
+ if ((textureKey | transformKey | attribKey | fEffectClassID) & kMetaKeyInvalidMask) { |
+ return false; |
+ } |
+ |
+ // effectKey must be first because it is what will be returned by |
+ // GrGLProgramDesc::EffectKeyProvider and passed to the GrGLEffect as its key. |
b->add32(effectKey); |
+ b->add32(textureKey << 16 | transformKey); |
+ b->add32(fEffectClassID << 16 | attribKey); |
+ return true; |
} |
/** Returns a new instance of the appropriate *GL* implementation class |
@@ -60,7 +59,8 @@ |
return SkNEW_ARGS(GLEffect, (*this, drawEffect)); |
} |
- /** This class is a singleton. This function returns the single instance. */ |
+ /** This class is a singleton. This function returns the single instance. |
+ */ |
static const GrBackendEffectFactory& getInstance() { |
static SkAlignedSTStorage<1, GrTBackendEffectFactory> gInstanceMem; |
static const GrTBackendEffectFactory* gInstance; |
@@ -72,7 +72,9 @@ |
} |
protected: |
- GrTBackendEffectFactory() {} |
+ GrTBackendEffectFactory() { |
+ fEffectClassID = GenID(); |
+ } |
}; |
#endif |