2012-10-29 20:02:06 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2013-10-03 15:17:58 +00:00
|
|
|
#include "gl/GrGLProgramEffects.h"
|
2012-10-29 20:02:06 +00:00
|
|
|
|
|
|
|
/**
|
2014-07-17 14:55:11 +00:00
|
|
|
* 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:
|
2014-09-16 15:21:41 +00:00
|
|
|
* EffectKey GenKey(const GrEffect, const GrGLCaps&)
|
2014-07-17 14:55:11 +00:00
|
|
|
* 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.
|
2012-10-29 20:02:06 +00:00
|
|
|
*/
|
|
|
|
template <typename EffectClass>
|
|
|
|
class GrTBackendEffectFactory : public GrBackendEffectFactory {
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef typename EffectClass::GLEffect GLEffect;
|
|
|
|
|
2014-07-17 14:55:11 +00:00
|
|
|
/** Returns a human-readable name for the effect. Implemented using GLEffect::Name as described
|
|
|
|
* in this class's comment. */
|
2012-10-29 20:02:06 +00:00
|
|
|
virtual const char* name() const SK_OVERRIDE { return EffectClass::Name(); }
|
|
|
|
|
2014-07-17 14:55:11 +00:00
|
|
|
|
|
|
|
/** Implemented using GLEffect::GenKey as described in this class's comment. */
|
2014-09-16 15:21:41 +00:00
|
|
|
virtual void getGLEffectKey(const GrEffect& effect,
|
2014-07-11 17:01:02 +00:00
|
|
|
const GrGLCaps& caps,
|
|
|
|
GrEffectKeyBuilder* b) const SK_OVERRIDE {
|
2014-09-16 15:21:41 +00:00
|
|
|
GLEffect::GenKey(effect, caps, b);
|
2012-10-29 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns a new instance of the appropriate *GL* implementation class
|
|
|
|
for the given GrEffect; caller is responsible for deleting
|
|
|
|
the object. */
|
2014-09-16 15:21:41 +00:00
|
|
|
virtual GrGLEffect* createGLInstance(const GrEffect& effect) const SK_OVERRIDE {
|
|
|
|
return SkNEW_ARGS(GLEffect, (*this, effect));
|
2012-10-29 20:02:06 +00:00
|
|
|
}
|
|
|
|
|
2014-07-17 14:55:11 +00:00
|
|
|
/** This class is a singleton. This function returns the single instance. */
|
2012-10-29 20:02:06 +00:00
|
|
|
static const GrBackendEffectFactory& getInstance() {
|
|
|
|
static SkAlignedSTStorage<1, GrTBackendEffectFactory> gInstanceMem;
|
|
|
|
static const GrTBackendEffectFactory* gInstance;
|
|
|
|
if (!gInstance) {
|
|
|
|
gInstance = SkNEW_PLACEMENT(gInstanceMem.get(),
|
|
|
|
GrTBackendEffectFactory);
|
|
|
|
}
|
|
|
|
return *gInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-07-17 14:55:11 +00:00
|
|
|
GrTBackendEffectFactory() {}
|
2012-10-29 20:02:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|