More effect->processor cleanup
R=joshualitt@google.com Review URL: https://codereview.chromium.org/660563003
This commit is contained in:
parent
98b33ebe6f
commit
b762cb548b
@ -19,8 +19,8 @@ class GrGLCaps;
|
||||
class GrProcessor;
|
||||
|
||||
/**
|
||||
* Used by effects to build their keys. It incorporates each per-processor key into a larger shader
|
||||
* key.
|
||||
* Used by processors to build their keys. It incorporates each per-processor key into a larger shader
|
||||
* key.
|
||||
*/
|
||||
class GrProcessorKeyBuilder {
|
||||
public:
|
||||
@ -45,7 +45,7 @@ public:
|
||||
|
||||
private:
|
||||
SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key.
|
||||
int fCount; // number of uint32_ts added to fData by the effect.
|
||||
int fCount; // number of uint32_ts added to fData by the processor.
|
||||
};
|
||||
|
||||
/**
|
||||
@ -59,41 +59,42 @@ public:
|
||||
SkASSERT(0 == reinterpret_cast<intptr_t>(key) % sizeof(uint32_t));
|
||||
}
|
||||
|
||||
/** Gets the uint32_t values that the effect inserted into the key. */
|
||||
/** Gets the uint32_t values that the processor inserted into the key. */
|
||||
uint32_t get32(int index) const {
|
||||
SkASSERT(index >=0 && index < fCount);
|
||||
return fKey[index];
|
||||
}
|
||||
|
||||
/** Gets the number of uint32_t values that the effect inserted into the key. */
|
||||
/** Gets the number of uint32_t values that the processor inserted into the key. */
|
||||
int count32() const { return fCount; }
|
||||
|
||||
private:
|
||||
const uint32_t* fKey; // unowned ptr into the larger key.
|
||||
int fCount; // number of uint32_ts inserted by the effect into its key.
|
||||
int fCount; // number of uint32_ts inserted by the processor into its key.
|
||||
};
|
||||
|
||||
/**
|
||||
* Given a GrProcessor of a particular type, creates the corresponding graphics-backend-specific
|
||||
* effect object. It also tracks equivalence of shaders generated via a key. The factory for an
|
||||
* effect is accessed via GrProcessor::getFactory(). Each factory instance is assigned an ID at
|
||||
* processor object. It also tracks equivalence of shaders generated via a key. The factory for an
|
||||
* processor is accessed via GrProcessor::getFactory(). Each factory instance is assigned an ID at
|
||||
* construction. The ID of GrProcessor::getFactory() is used as a type identifier. Thus, a
|
||||
* GrProcessor subclass must always return the same object from getFactory() and that factory object
|
||||
* must be unique to the GrProcessor subclass (and unique from any further derived subclasses).
|
||||
*
|
||||
* Rather than subclassing this class themselves, it is recommended that GrProcessor authors use
|
||||
* the templated subclass GrTBackendEffectFactory by writing their getFactory() method as:
|
||||
* the templated subclass GrTBackendProcessorFactory by writing their getFactory() method as:
|
||||
*
|
||||
* const GrBackendEffectFactory& MyEffect::getFactory() const {
|
||||
* return GrTBackendEffectFactory<MyEffect>::getInstance();
|
||||
* const GrBackendProcessorFactory& MyProcessor::getFactory() const {
|
||||
* return GrTBackendProcessorFactory<MyProcessor>::getInstance();
|
||||
* }
|
||||
*
|
||||
* Using GrTBackendEffectFactory places a few constraints on the effect. See that class's comments.
|
||||
* Using GrTBackendProcessorFactory places a few constraints on the processor. See that class's
|
||||
* comments.
|
||||
*/
|
||||
class GrBackendProcessorFactory : SkNoncopyable {
|
||||
public:
|
||||
/**
|
||||
* Generates an effect's key. The key is based on the aspects of the GrProcessor object's
|
||||
* Generates an processor's key. The key is based on the aspects of the GrProcessor object's
|
||||
* configuration that affect GLSL code generation. Two GrProcessor instances that would cause
|
||||
* this->createGLInstance()->emitCode() to produce different code must produce different keys.
|
||||
*/
|
||||
@ -101,13 +102,13 @@ public:
|
||||
GrProcessorKeyBuilder*) const = 0;
|
||||
|
||||
/**
|
||||
* Produces a human-reable name for the effect.
|
||||
* Produces a human-reable name for the v.
|
||||
*/
|
||||
virtual const char* name() const = 0;
|
||||
|
||||
/**
|
||||
* A unique value for every instance of this factory. It is automatically incorporated into the
|
||||
* effect's key. This allows keys generated by getGLProcessorKey() to only be unique within a
|
||||
* processor's key. This allows keys generated by getGLProcessorKey() to only be unique within a
|
||||
* GrProcessor subclass and not necessarily across subclasses.
|
||||
*/
|
||||
uint32_t effectClassID() const { return fEffectClassID; }
|
||||
|
@ -153,15 +153,15 @@ public:
|
||||
|
||||
/** This object, besides creating back-end-specific helper objects, is used for run-time-type-
|
||||
identification. The factory should be an instance of templated class,
|
||||
GrTBackendEffectFactory. It is templated on the subclass of GrProcessor. The subclass must
|
||||
have a nested type (or typedef) named GLProcessor which will be the subclass of
|
||||
GrTBackendProcessorFactory. It is templated on the subclass of GrProcessor. The subclass
|
||||
must have a nested type (or typedef) named GLProcessor which will be the subclass of
|
||||
GrGLProcessor created by the factory.
|
||||
|
||||
Example:
|
||||
class MyCustomProcessor : public GrProcessor {
|
||||
...
|
||||
virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE {
|
||||
return GrTBackendEffectFactory<MyCustomProcessor>::getInstance();
|
||||
virtual const GrBackendProcessorFactory& getFactory() const SK_OVERRIDE {
|
||||
return GrTBackendProcessorFactory<MyCustomProcessor>::getInstance();
|
||||
}
|
||||
...
|
||||
};
|
||||
|
@ -11,49 +11,49 @@
|
||||
#include "GrBackendProcessorFactory.h"
|
||||
|
||||
/**
|
||||
* Implements GrBackendEffectFactory for a GrProcessor subclass as a singleton. This can be used by
|
||||
* most GrProcessor subclasses to implement the GrProcessor::getFactory() method:
|
||||
* Implements GrBackendProcessorFactory for a GrProcessor subclass as a singleton. This can be used
|
||||
* by most GrProcessor subclasses to implement the GrProcessor::getFactory() method:
|
||||
*
|
||||
* const GrBackendEffectFactory& MyEffect::getFactory() const {
|
||||
* return GrTBackendEffectFactory<MyEffect>::getInstance();
|
||||
* const GrBackendProcessorFactory& MyProcessor::getFactory() const {
|
||||
* return GrTBackendProcessorFactory<MyProcessor>::getInstance();
|
||||
* }
|
||||
*
|
||||
* Using this class requires that the GrProcessor subclass always produces the same GrGLProcessor
|
||||
* subclass. Additionally, it adds the following requirements to the GrProcessor and GrGLProcessor
|
||||
* subclasses:
|
||||
*
|
||||
* 1. The GrGLProcessor used by GrProcessor subclass MyEffect must be named or typedef'ed to
|
||||
* MyEffect::GLProcessor.
|
||||
* 2. MyEffect::GLProcessor must have a static function:
|
||||
* EffectKey GenKey(const GrProcessor, const GrGLCaps&)
|
||||
* 1. The GrGLProcessor used by GrProcessor subclass MyProcessor must be named or typedef'ed to
|
||||
* MyProcessor::GLProcessor.
|
||||
* 2. MyProcessor::GLProcessor must have a static function:
|
||||
void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder* b)
|
||||
* which generates a key that maps 1 to 1 with code variations emitted by
|
||||
* MyEffect::GLProcessor::emitCode().
|
||||
* 3. MyEffect must have a static function:
|
||||
* MyProcessor::GLProcessor::emitCode().
|
||||
* 3. MyProcessor must have a static function:
|
||||
* const char* Name()
|
||||
* which returns a human-readable name for the effect.
|
||||
* which returns a human-readable name for the processor.
|
||||
*/
|
||||
template <class ProcessorClass, class BackEnd, class ProcessorBase, class GLProcessorBase>
|
||||
class GrTBackendProcessorFactory : public BackEnd {
|
||||
public:
|
||||
typedef typename ProcessorClass::GLProcessor GLProcessor;
|
||||
|
||||
/** Returns a human-readable name for the effect. Implemented using GLProcessor::Name as
|
||||
/** Returns a human-readable name for the processor. Implemented using GLProcessor::Name as
|
||||
* described in this class's comment. */
|
||||
virtual const char* name() const SK_OVERRIDE { return ProcessorClass::Name(); }
|
||||
|
||||
|
||||
/** Implemented using GLProcessor::GenKey as described in this class's comment. */
|
||||
virtual void getGLProcessorKey(const GrProcessor& effect,
|
||||
virtual void getGLProcessorKey(const GrProcessor& processor,
|
||||
const GrGLCaps& caps,
|
||||
GrProcessorKeyBuilder* b) const SK_OVERRIDE {
|
||||
GLProcessor::GenKey(effect, caps, b);
|
||||
GLProcessor::GenKey(processor, caps, b);
|
||||
}
|
||||
|
||||
/** Returns a new instance of the appropriate *GL* implementation class
|
||||
for the given GrProcessor; caller is responsible for deleting
|
||||
the object. */
|
||||
virtual GLProcessorBase* createGLInstance(const ProcessorBase& effect) const SK_OVERRIDE {
|
||||
return SkNEW_ARGS(GLProcessor, (*this, effect));
|
||||
virtual GLProcessorBase* createGLInstance(const ProcessorBase& processor) const SK_OVERRIDE {
|
||||
return SkNEW_ARGS(GLProcessor, (*this, processor));
|
||||
}
|
||||
|
||||
/** This class is a singleton. This function returns the single instance. */
|
||||
@ -72,9 +72,9 @@ protected:
|
||||
};
|
||||
|
||||
/*
|
||||
* Every effect so far derives from one of the following subclasses of GrTBackendProcessorFactory.
|
||||
* All of this machinery is necessary to ensure that creatGLInstace is typesafe and does not
|
||||
* require any casting
|
||||
* Every processor so far derives from one of the following subclasses of
|
||||
* GrTBackendProcessorFactory. All of this machinery is necessary to ensure that creatGLInstace is
|
||||
* typesafe and does not require any casting.
|
||||
*/
|
||||
template <class ProcessorClass>
|
||||
class GrTBackendGeometryProcessorFactory
|
||||
|
@ -22,7 +22,7 @@
|
||||
that their GrGLProcessors would emit the same GLSL code.
|
||||
|
||||
The GrGLProcessor subclass must also have a constructor of the form:
|
||||
EffectSubclass::EffectSubclass(const GrBackendEffectFactory&, const GrProcessor&)
|
||||
EffectSubclass::EffectSubclass(const GrBackendProcessorFactory&, const GrProcessor&)
|
||||
|
||||
These objects are created by the factory object returned by the GrProcessor::getFactory().
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user