Chromium Code Reviews| Index: include/gpu/GrTBackendEffectFactory.h |
| diff --git a/include/gpu/GrTBackendEffectFactory.h b/include/gpu/GrTBackendEffectFactory.h |
| index cd4c0a49e96a40aa16622606027717aad03784d1..32f17f667d15d25949bcf634d0c75eee1903ddda 100644 |
| --- a/include/gpu/GrTBackendEffectFactory.h |
| +++ b/include/gpu/GrTBackendEffectFactory.h |
| @@ -13,7 +13,26 @@ |
| #include "gl/GrGLProgramEffects.h" |
| /** |
| - * Implements GrBackendEffectFactory for a GrEffect subclass as a singleton. |
| + * 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() |
|
robertphillips
2014/07/11 17:24:58
readable
bsalomon
2014/07/11 17:52:56
Done.
|
| + * which returns a human-readble name for the effect. |
| */ |
| template <typename EffectClass> |
| class GrTBackendEffectFactory : public GrBackendEffectFactory { |
| @@ -21,35 +40,17 @@ class GrTBackendEffectFactory : public GrBackendEffectFactory { |
| public: |
| typedef typename EffectClass::GLEffect GLEffect; |
| - /** Returns a human-readable name that is accessible via GrEffect or |
| - GrGLEffect and is consistent between the two of them. |
| - */ |
| + /** Returns a human-readable name for the effect. Implemented using GLEffect::Name as described |
| + * in this class's comment. */ |
| virtual const char* name() const SK_OVERRIDE { return EffectClass::Name(); } |
| - /** 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, |
| + |
| + /** Implemented using GLEffect::GenKey as described in this class's comment. */ |
| + virtual void 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 |
| @@ -59,8 +60,7 @@ public: |
| 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,9 +72,7 @@ public: |
| } |
| protected: |
| - GrTBackendEffectFactory() { |
| - fEffectClassID = GenID(); |
| - } |
| + GrTBackendEffectFactory() {} |
| }; |
| #endif |