More effect->processor cleanup

R=joshualitt@google.com

Review URL: https://codereview.chromium.org/660563003
This commit is contained in:
bsalomon 2014-10-15 11:25:21 -07:00 committed by Commit bot
parent 98b33ebe6f
commit b762cb548b
4 changed files with 40 additions and 39 deletions

View File

@ -19,8 +19,8 @@ class GrGLCaps;
class GrProcessor; class GrProcessor;
/** /**
* Used by effects to build their keys. It incorporates each per-processor key into a larger shader * Used by processors to build their keys. It incorporates each per-processor key into a larger shader
* key. * key.
*/ */
class GrProcessorKeyBuilder { class GrProcessorKeyBuilder {
public: public:
@ -45,7 +45,7 @@ public:
private: private:
SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key. 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)); 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 { uint32_t get32(int index) const {
SkASSERT(index >=0 && index < fCount); SkASSERT(index >=0 && index < fCount);
return fKey[index]; 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; } int count32() const { return fCount; }
private: private:
const uint32_t* fKey; // unowned ptr into the larger key. 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 * 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 * processor 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 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 * 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 * 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). * 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 * 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 { * const GrBackendProcessorFactory& MyProcessor::getFactory() const {
* return GrTBackendEffectFactory<MyEffect>::getInstance(); * 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 { class GrBackendProcessorFactory : SkNoncopyable {
public: 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 * configuration that affect GLSL code generation. Two GrProcessor instances that would cause
* this->createGLInstance()->emitCode() to produce different code must produce different keys. * this->createGLInstance()->emitCode() to produce different code must produce different keys.
*/ */
@ -101,13 +102,13 @@ public:
GrProcessorKeyBuilder*) const = 0; 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; virtual const char* name() const = 0;
/** /**
* A unique value for every instance of this factory. It is automatically incorporated into the * 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. * GrProcessor subclass and not necessarily across subclasses.
*/ */
uint32_t effectClassID() const { return fEffectClassID; } uint32_t effectClassID() const { return fEffectClassID; }

View File

@ -153,15 +153,15 @@ public:
/** This object, besides creating back-end-specific helper objects, is used for run-time-type- /** 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, identification. The factory should be an instance of templated class,
GrTBackendEffectFactory. It is templated on the subclass of GrProcessor. The subclass must GrTBackendProcessorFactory. It is templated on the subclass of GrProcessor. The subclass
have a nested type (or typedef) named GLProcessor which will be the subclass of must have a nested type (or typedef) named GLProcessor which will be the subclass of
GrGLProcessor created by the factory. GrGLProcessor created by the factory.
Example: Example:
class MyCustomProcessor : public GrProcessor { class MyCustomProcessor : public GrProcessor {
... ...
virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { virtual const GrBackendProcessorFactory& getFactory() const SK_OVERRIDE {
return GrTBackendEffectFactory<MyCustomProcessor>::getInstance(); return GrTBackendProcessorFactory<MyCustomProcessor>::getInstance();
} }
... ...
}; };

View File

@ -11,49 +11,49 @@
#include "GrBackendProcessorFactory.h" #include "GrBackendProcessorFactory.h"
/** /**
* Implements GrBackendEffectFactory for a GrProcessor subclass as a singleton. This can be used by * Implements GrBackendProcessorFactory for a GrProcessor subclass as a singleton. This can be used
* most GrProcessor subclasses to implement the GrProcessor::getFactory() method: * by most GrProcessor subclasses to implement the GrProcessor::getFactory() method:
* *
* const GrBackendEffectFactory& MyEffect::getFactory() const { * const GrBackendProcessorFactory& MyProcessor::getFactory() const {
* return GrTBackendEffectFactory<MyEffect>::getInstance(); * return GrTBackendProcessorFactory<MyProcessor>::getInstance();
* } * }
* *
* Using this class requires that the GrProcessor subclass always produces the same GrGLProcessor * 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 * subclass. Additionally, it adds the following requirements to the GrProcessor and GrGLProcessor
* subclasses: * subclasses:
* *
* 1. The GrGLProcessor used by GrProcessor subclass MyEffect must be named or typedef'ed to * 1. The GrGLProcessor used by GrProcessor subclass MyProcessor must be named or typedef'ed to
* MyEffect::GLProcessor. * MyProcessor::GLProcessor.
* 2. MyEffect::GLProcessor must have a static function: * 2. MyProcessor::GLProcessor must have a static function:
* EffectKey GenKey(const GrProcessor, const GrGLCaps&) void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBuilder* b)
* which generates a key that maps 1 to 1 with code variations emitted by * which generates a key that maps 1 to 1 with code variations emitted by
* MyEffect::GLProcessor::emitCode(). * MyProcessor::GLProcessor::emitCode().
* 3. MyEffect must have a static function: * 3. MyProcessor must have a static function:
* const char* Name() * 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> template <class ProcessorClass, class BackEnd, class ProcessorBase, class GLProcessorBase>
class GrTBackendProcessorFactory : public BackEnd { class GrTBackendProcessorFactory : public BackEnd {
public: public:
typedef typename ProcessorClass::GLProcessor GLProcessor; 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. */ * described in this class's comment. */
virtual const char* name() const SK_OVERRIDE { return ProcessorClass::Name(); } virtual const char* name() const SK_OVERRIDE { return ProcessorClass::Name(); }
/** Implemented using GLProcessor::GenKey as described in this class's comment. */ /** 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, const GrGLCaps& caps,
GrProcessorKeyBuilder* b) const SK_OVERRIDE { 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 /** Returns a new instance of the appropriate *GL* implementation class
for the given GrProcessor; caller is responsible for deleting for the given GrProcessor; caller is responsible for deleting
the object. */ the object. */
virtual GLProcessorBase* createGLInstance(const ProcessorBase& effect) const SK_OVERRIDE { virtual GLProcessorBase* createGLInstance(const ProcessorBase& processor) const SK_OVERRIDE {
return SkNEW_ARGS(GLProcessor, (*this, effect)); return SkNEW_ARGS(GLProcessor, (*this, processor));
} }
/** This class is a singleton. This function returns the single instance. */ /** 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. * Every processor so far derives from one of the following subclasses of
* All of this machinery is necessary to ensure that creatGLInstace is typesafe and does not * GrTBackendProcessorFactory. All of this machinery is necessary to ensure that creatGLInstace is
* require any casting * typesafe and does not require any casting.
*/ */
template <class ProcessorClass> template <class ProcessorClass>
class GrTBackendGeometryProcessorFactory class GrTBackendGeometryProcessorFactory

View File

@ -22,7 +22,7 @@
that their GrGLProcessors would emit the same GLSL code. that their GrGLProcessors would emit the same GLSL code.
The GrGLProcessor subclass must also have a constructor of the form: 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(). These objects are created by the factory object returned by the GrProcessor::getFactory().
*/ */