Tunnel name requests through factory, forcing custom effect and custom prog stage to use same impl
Review URL: http://codereview.appspot.com/6220061/ git-svn-id: http://skia.googlecode.com/svn/trunk@4019 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
469d0dd944
commit
289efe014a
@ -15,7 +15,10 @@
|
||||
class GrContext;
|
||||
|
||||
/** Provides custom vertex shader, fragment shader, uniform data for a
|
||||
particular stage of the Ganesh shading pipeline. */
|
||||
particular stage of the Ganesh shading pipeline.
|
||||
Subclasses must have a function that produces a human-readable name:
|
||||
static const char* Name();
|
||||
*/
|
||||
class GrCustomStage : public GrRefCnt {
|
||||
|
||||
public:
|
||||
@ -24,10 +27,6 @@ public:
|
||||
GrCustomStage();
|
||||
virtual ~GrCustomStage();
|
||||
|
||||
/** Human-meaningful string to identify this effect; may be embedded
|
||||
in generated shader code. */
|
||||
virtual const char* name() const = 0;
|
||||
|
||||
/** If given an input texture that is/is not opaque, is this
|
||||
stage guaranteed to produce an opaque output? */
|
||||
virtual bool isOpaque(bool inputTextureIsOpaque) const;
|
||||
@ -60,6 +59,10 @@ public:
|
||||
of the stageKey produced by the GrProgramStageFactory. */
|
||||
virtual bool isEqual(const GrCustomStage *) const = 0;
|
||||
|
||||
/** Human-meaningful string to identify this effect; may be embedded
|
||||
in generated shader code. */
|
||||
const char* name() const { return this->getFactory().name(); }
|
||||
|
||||
private:
|
||||
|
||||
typedef GrRefCnt INHERITED;
|
||||
|
@ -37,6 +37,8 @@ public:
|
||||
return !(*this == b);
|
||||
}
|
||||
|
||||
virtual const char* name() const = 0;
|
||||
|
||||
protected:
|
||||
enum {
|
||||
kIllegalStageClassID = 0,
|
||||
@ -66,7 +68,12 @@ class GrTProgramStageFactory : public GrProgramStageFactory {
|
||||
|
||||
public:
|
||||
typedef typename StageClass::GLProgramStage GLProgramStage;
|
||||
|
||||
|
||||
/** Returns a human-readable name that is accessible via GrCustomStage or
|
||||
GrGLProgramStage and is consistent between the two of them.
|
||||
*/
|
||||
virtual const char* name() const SK_OVERRIDE { return StageClass::Name(); }
|
||||
|
||||
/** Returns an value that idenitifes the shader code generated by
|
||||
a GrCustomStage. This enables caching of generated shaders. Part of the
|
||||
id identifies the GrCustomShader subclass. The remainder is based
|
||||
@ -88,9 +95,11 @@ public:
|
||||
the object. */
|
||||
virtual GLProgramStage* createGLInstance(
|
||||
const GrCustomStage* stage) const SK_OVERRIDE {
|
||||
return new GLProgramStage(stage);
|
||||
return new GLProgramStage(*this, stage);
|
||||
}
|
||||
|
||||
/** This class is a singleton. This function returns the single instance.
|
||||
*/
|
||||
static const GrProgramStageFactory& getInstance() {
|
||||
static SkAlignedSTStorage<1, GrTProgramStageFactory> gInstanceMem;
|
||||
static const GrTProgramStageFactory* gInstance;
|
||||
|
@ -17,8 +17,8 @@ class GrGLConvolutionEffect : public GrGLProgramStage {
|
||||
|
||||
public:
|
||||
|
||||
GrGLConvolutionEffect(const GrCustomStage* stage);
|
||||
virtual const char* name() const SK_OVERRIDE;
|
||||
GrGLConvolutionEffect(const GrProgramStageFactory& factory,
|
||||
const GrCustomStage* stage);
|
||||
virtual void setupVSUnis(VarArray* vsUnis, int stage) SK_OVERRIDE;
|
||||
virtual void setupFSUnis(VarArray* fsUnis, int stage) SK_OVERRIDE;
|
||||
virtual void emitVS(GrStringBuilder* code,
|
||||
@ -49,18 +49,17 @@ private:
|
||||
typedef GrGLProgramStage INHERITED;
|
||||
};
|
||||
|
||||
GrGLConvolutionEffect::GrGLConvolutionEffect(const GrCustomStage* data)
|
||||
: fKernelVar(NULL)
|
||||
GrGLConvolutionEffect::GrGLConvolutionEffect(
|
||||
const GrProgramStageFactory& factory,
|
||||
const GrCustomStage* data)
|
||||
: GrGLProgramStage(factory)
|
||||
, fKernelVar(NULL)
|
||||
, fImageIncrementVar(NULL)
|
||||
, fKernelLocation(0)
|
||||
, fImageIncrementLocation(0) {
|
||||
fKernelWidth = static_cast<const GrConvolutionEffect*>(data)->width();
|
||||
}
|
||||
|
||||
const char* GrGLConvolutionEffect::name() const {
|
||||
return GrConvolutionEffect::Name();
|
||||
}
|
||||
|
||||
void GrGLConvolutionEffect::setupVSUnis(VarArray* vsUnis,
|
||||
int stage) {
|
||||
fImageIncrementVar = &vsUnis->push_back();
|
||||
@ -188,11 +187,6 @@ GrConvolutionEffect::~GrConvolutionEffect() {
|
||||
|
||||
}
|
||||
|
||||
const char* GrConvolutionEffect::name() const {
|
||||
return Name();
|
||||
}
|
||||
|
||||
|
||||
const GrProgramStageFactory& GrConvolutionEffect::getFactory() const {
|
||||
return GrTProgramStageFactory<GrConvolutionEffect>::getInstance();
|
||||
}
|
||||
|
@ -24,12 +24,11 @@ public:
|
||||
unsigned int width() const { return fKernelWidth; }
|
||||
const float* kernel() const { return fKernel; }
|
||||
GrSamplerState::FilterDirection direction() const { return fDirection; }
|
||||
|
||||
|
||||
static const char* Name() { return "Convolution"; }
|
||||
|
||||
typedef GrGLConvolutionEffect GLProgramStage;
|
||||
|
||||
virtual const char* name() const SK_OVERRIDE;
|
||||
|
||||
virtual const GrProgramStageFactory& getFactory() const SK_OVERRIDE;
|
||||
virtual bool isEqual(const GrCustomStage *) const SK_OVERRIDE;
|
||||
|
||||
|
@ -8,6 +8,10 @@
|
||||
#include "GrGLSL.h"
|
||||
#include "GrGLProgramStage.h"
|
||||
|
||||
GrGLProgramStage::GrGLProgramStage(const GrProgramStageFactory& factory)
|
||||
: fFactory(factory) {
|
||||
}
|
||||
|
||||
GrGLProgramStage::~GrGLProgramStage() {
|
||||
}
|
||||
|
||||
|
@ -39,10 +39,10 @@ public:
|
||||
};
|
||||
|
||||
typedef GrTAllocator<GrGLShaderVar> VarArray;
|
||||
|
||||
virtual ~GrGLProgramStage();
|
||||
|
||||
virtual const char* name() const = 0;
|
||||
GrGLProgramStage(const GrProgramStageFactory&);
|
||||
|
||||
virtual ~GrGLProgramStage();
|
||||
|
||||
/** Creates any uniform variables the vertex shader requires
|
||||
and appends them to vsUnis;
|
||||
@ -107,6 +107,12 @@ public:
|
||||
updates the name of the sample coordinates. */
|
||||
void emitTextureSetup(GrGLShaderBuilder* segments);
|
||||
|
||||
/** Human-meaningful string to identify this effect; may be embedded
|
||||
in generated shader code. Because the implementation is delegated to
|
||||
the factory, the name will be the same as that of the generating
|
||||
GrCustomStage. */
|
||||
const char* name() const { return fFactory.name(); }
|
||||
|
||||
protected:
|
||||
|
||||
/** Convenience function for subclasses to write texture2D() or
|
||||
@ -116,6 +122,8 @@ protected:
|
||||
const char* coordName);
|
||||
|
||||
SamplerMode fSamplerMode;
|
||||
|
||||
const GrProgramStageFactory& fFactory;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user