From 929f29a5c1bffa7f7c1b5a376351d0762b8ac561 Mon Sep 17 00:00:00 2001 From: bsalomon Date: Thu, 17 Jul 2014 07:55:11 -0700 Subject: Makes GrGLProgramDesc's key store the lengths as well as offsets of the effect keys. Makes it possible to use GrBackendEffectFactories other than GrTBEF by moving meta-key generation out of GrTBEF. Cleans up docs around GrBackendEffectFactory. Committed: https://skia.googlesource.com/skia/+/c0ea398aff8254e31152cbb94c9ab6150428e252 R=robertphillips@google.com, jvanverth@google.com Author: bsalomon@google.com Review URL: https://codereview.chromium.org/379113004 --- include/gpu/GrTBackendEffectFactory.h | 56 +++++++++++++++++------------------ 1 file changed, 27 insertions(+), 29 deletions(-) (limited to 'include/gpu/GrTBackendEffectFactory.h') diff --git a/include/gpu/GrTBackendEffectFactory.h b/include/gpu/GrTBackendEffectFactory.h index cd4c0a49e9..251e8c7768 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::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. */ template 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 -- cgit v1.2.3