diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-29 20:02:06 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-10-29 20:02:06 +0000 |
commit | 56315b979b4a10e3f722f63d6e042e217712c6c0 (patch) | |
tree | 4c93e741d037a23578e6e1155c9c5ae3cbc3e610 /include | |
parent | 2eaaefd7e6a58339b3f93333f1e9cc92252cc303 (diff) |
Add file accidentally omitted from r6182.
git-svn-id: http://skia.googlecode.com/svn/branches/gpu_dev@6186 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r-- | include/gpu/GrTBackendEffectFactory.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/include/gpu/GrTBackendEffectFactory.h b/include/gpu/GrTBackendEffectFactory.h new file mode 100644 index 0000000000..52dbc64dd8 --- /dev/null +++ b/include/gpu/GrTBackendEffectFactory.h @@ -0,0 +1,73 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrTBackendEffectFactory_DEFINED +#define GrTBackendEffectFactory_DEFINED + +#include "GrBackendEffectFactory.h" +#include "GrEffectStage.h" + +/** + * Implements GrBackendEffectFactory for a GrEffect subclass as a singleton. + */ +template <typename EffectClass> +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. + */ + virtual const char* name() const SK_OVERRIDE { return EffectClass::Name(); } + + /** Returns a value that identifies the GLSL shader code generated by + a GrEffect. 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. */ + virtual EffectKey glEffectKey(const GrEffectStage& stage, + const GrGLCaps& caps) const SK_OVERRIDE { + GrAssert(kIllegalEffectClassID != fEffectClassID); + EffectKey effectKey = GLEffect::GenKey(stage, caps); + EffectKey textureKey = GLEffect::GenTextureKey(*stage.getEffect(), caps); +#if GR_DEBUG + static const EffectKey kIllegalIDMask = (uint16_t) (~((1U << kEffectKeyBits) - 1)); + GrAssert(!(kIllegalIDMask & effectKey)); + + static const EffectKey kIllegalTextureKeyMask = (uint16_t) (~((1U << kTextureKeyBits) - 1)); + GrAssert(!(kIllegalTextureKeyMask & textureKey)); +#endif + return fEffectClassID | (textureKey << kEffectKeyBits) | effectKey; + } + + /** Returns a new instance of the appropriate *GL* implementation class + for the given GrEffect; caller is responsible for deleting + the object. */ + virtual GLEffect* createGLInstance(const GrEffect& effect) const SK_OVERRIDE { + return SkNEW_ARGS(GLEffect, (*this, effect)); + } + + /** This class is a singleton. This function returns the single instance. + */ + static const GrBackendEffectFactory& getInstance() { + static SkAlignedSTStorage<1, GrTBackendEffectFactory> gInstanceMem; + static const GrTBackendEffectFactory* gInstance; + if (!gInstance) { + gInstance = SkNEW_PLACEMENT(gInstanceMem.get(), + GrTBackendEffectFactory); + } + return *gInstance; + } + +protected: + GrTBackendEffectFactory() { + fEffectClassID = GenID() << (kEffectKeyBits + kTextureKeyBits) ; + } +}; + +#endif |