aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu/GrBackendEffectFactory.h
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-29 19:51:22 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-29 19:51:22 +0000
commit2eaaefd7e6a58339b3f93333f1e9cc92252cc303 (patch)
treef65a31a9b3bc70909ceb311ebad684c2bf445868 /include/gpu/GrBackendEffectFactory.h
parent484ee2a5fe47c204d9dda6acba54f9789d1cf69f (diff)
Pass GrCustomStage to key-generation functions and emitCode().
R=robertphillips@google.com Review URL: https://codereview.appspot.com/6819046 git-svn-id: http://skia.googlecode.com/svn/branches/gpu_dev@6182 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/gpu/GrBackendEffectFactory.h')
-rw-r--r--include/gpu/GrBackendEffectFactory.h70
1 files changed, 11 insertions, 59 deletions
diff --git a/include/gpu/GrBackendEffectFactory.h b/include/gpu/GrBackendEffectFactory.h
index 89562d5239..c496f5a13a 100644
--- a/include/gpu/GrBackendEffectFactory.h
+++ b/include/gpu/GrBackendEffectFactory.h
@@ -10,14 +10,21 @@
#include "GrTypes.h"
#include "SkTemplates.h"
+#include "SkThread_platform.h"
#include "GrNoncopyable.h"
-/** Given a GrEffect of a particular type, creates the corresponding
- graphics-backend-specific GrGLEffect. Also tracks equivalence
- of shaders generated via a key.
+/** Given a GrEffect of a particular type, creates the corresponding graphics-backend-specific
+ effect object. Also tracks equivalence of shaders generated via a key. Each factory instance
+ is assigned a generation ID at construction. The ID of the return of GrEffect::getFactory()
+ is used as a type identifier. Thus a GrEffect subclass must return a singleton from
+ getFactory(). GrEffect subclasses should use the derived class GrTBackendEffectFactory that is
+ templated on the GrEffect subclass as their factory object. It requires that the GrEffect
+ subclass has a nested class (or typedef) GLEffect which is its GL implementation and a subclass
+ of GrGLEffect.
*/
class GrEffect;
+class GrEffectStage;
class GrGLEffect;
class GrGLCaps;
@@ -35,7 +42,7 @@ public:
kTextureKeyBits = 6
};
- virtual EffectKey glEffectKey(const GrEffect&, const GrGLCaps&) const = 0;
+ virtual EffectKey glEffectKey(const GrEffectStage&, const GrGLCaps&) const = 0;
virtual GrGLEffect* createGLInstance(const GrEffect&) const = 0;
bool operator ==(const GrBackendEffectFactory& b) const {
@@ -71,59 +78,4 @@ private:
static int32_t fCurrEffectClassID;
};
-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 GrEffect& effect, const GrGLCaps& caps) const SK_OVERRIDE {
- GrAssert(kIllegalEffectClassID != fEffectClassID);
- EffectKey effectKey = GLEffect::GenKey(effect, caps);
- EffectKey textureKey = GLEffect::GenTextureKey(effect, 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