aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/gpu/GrCustomStage.h13
-rw-r--r--include/gpu/GrProgramStageFactory.h13
-rw-r--r--src/gpu/effects/GrConvolutionEffect.cpp20
-rw-r--r--src/gpu/effects/GrConvolutionEffect.h5
-rw-r--r--src/gpu/gl/GrGLProgramStage.cpp4
-rw-r--r--src/gpu/gl/GrGLProgramStage.h14
6 files changed, 43 insertions, 26 deletions
diff --git a/include/gpu/GrCustomStage.h b/include/gpu/GrCustomStage.h
index fd844251d8..9db4244d05 100644
--- a/include/gpu/GrCustomStage.h
+++ b/include/gpu/GrCustomStage.h
@@ -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;
diff --git a/include/gpu/GrProgramStageFactory.h b/include/gpu/GrProgramStageFactory.h
index e5f05f74d5..1ce0393bb9 100644
--- a/include/gpu/GrProgramStageFactory.h
+++ b/include/gpu/GrProgramStageFactory.h
@@ -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;
diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp
index 563d1a4051..29d1573061 100644
--- a/src/gpu/effects/GrConvolutionEffect.cpp
+++ b/src/gpu/effects/GrConvolutionEffect.cpp
@@ -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();
}
diff --git a/src/gpu/effects/GrConvolutionEffect.h b/src/gpu/effects/GrConvolutionEffect.h
index 4fdddd9c5a..df164d51fb 100644
--- a/src/gpu/effects/GrConvolutionEffect.h
+++ b/src/gpu/effects/GrConvolutionEffect.h
@@ -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;
diff --git a/src/gpu/gl/GrGLProgramStage.cpp b/src/gpu/gl/GrGLProgramStage.cpp
index 28a711d419..1221631572 100644
--- a/src/gpu/gl/GrGLProgramStage.cpp
+++ b/src/gpu/gl/GrGLProgramStage.cpp
@@ -8,6 +8,10 @@
#include "GrGLSL.h"
#include "GrGLProgramStage.h"
+GrGLProgramStage::GrGLProgramStage(const GrProgramStageFactory& factory)
+ : fFactory(factory) {
+}
+
GrGLProgramStage::~GrGLProgramStage() {
}
diff --git a/src/gpu/gl/GrGLProgramStage.h b/src/gpu/gl/GrGLProgramStage.h
index 21416407aa..df7bdb8cac 100644
--- a/src/gpu/gl/GrGLProgramStage.h
+++ b/src/gpu/gl/GrGLProgramStage.h
@@ -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