Make GrGLGradientEffect derive directly from GrGLEffect.

Review URL: https://codereview.appspot.com/6784053

git-svn-id: http://skia.googlecode.com/svn/branches/gpu_dev@6163 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2012-10-29 12:43:38 +00:00
parent ee2ef02d3d
commit f78df33efc
7 changed files with 281 additions and 253 deletions

View File

@ -682,7 +682,7 @@ GrGLGradientEffect::GrGLGradientEffect(const GrBackendEffectFactory& factory)
GrGLGradientEffect::~GrGLGradientEffect() { }
void GrGLGradientEffect::setupVariables(GrGLShaderBuilder* builder) {
void GrGLGradientEffect::emitYCoordUniform(GrGLShaderBuilder* builder) {
fFSYUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kFloat_GrSLType, "GradientYCoordFS");
}

View File

@ -271,17 +271,21 @@ private:
///////////////////////////////////////////////////////////////////////////////
// Base class for GL gradient effects
class GrGLGradientEffect : public GrGLLegacyEffect {
class GrGLGradientEffect : public GrGLEffect {
public:
GrGLGradientEffect(const GrBackendEffectFactory& factory);
virtual ~GrGLGradientEffect();
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
// emit code that gets a fragment's color from an expression for t; for now
// this always uses the texture, but for simpler cases we'll be able to lerp
protected:
// Emits the uniform used as the y-coord to texture samples in derived classes. Subclasses
// should call this method from their emitCode().
void emitYCoordUniform(GrGLShaderBuilder* builder);
// emit code that gets a fragment's color from an expression for t; for now this always uses the
// texture, but for simpler cases we'll be able to lerp. Subclasses should call this method from
// their emitCode().
void emitColorLookup(GrGLShaderBuilder* builder,
const char* gradientTValue,
const char* outputColor,
@ -289,11 +293,10 @@ public:
const GrGLShaderBuilder::TextureSampler&);
private:
GrScalar fCachedYCoord;
GrGLUniformManager::UniformHandle fFSYUni;
typedef GrGLLegacyEffect INHERITED;
typedef GrGLEffect INHERITED;
};
#endif

View File

@ -485,12 +485,14 @@ public:
virtual ~GrGLLinearGradient() { }
virtual void emitVS(GrGLShaderBuilder* builder,
const char* vertexCoords) SK_OVERRIDE { }
virtual void emitFS(GrGLShaderBuilder* builder,
virtual void emitCode(GrGLShaderBuilder*,
const GrEffect&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
static EffectKey GenKey(const GrEffect& s, const GrGLCaps& caps) { return 0; }
private:
@ -548,10 +550,14 @@ GrEffect* GrLinearGradient::TestCreate(SkRandom* random,
/////////////////////////////////////////////////////////////////////
void GrGLLinearGradient::emitFS(GrGLShaderBuilder* builder,
void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder,
const GrEffect&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
SkString t;
t.printf("%s.x", builder->defaultTexCoordsName());
this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplers[0]);

View File

@ -480,9 +480,10 @@ public:
const GrEffect&) : INHERITED (factory) { }
virtual ~GrGLRadialGradient() { }
virtual void emitVS(GrGLShaderBuilder* builder,
const char* vertexCoords) SK_OVERRIDE { }
virtual void emitFS(GrGLShaderBuilder* builder,
virtual void emitCode(GrGLShaderBuilder*,
const GrEffect&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
@ -547,10 +548,14 @@ GrEffect* GrRadialGradient::TestCreate(SkRandom* random,
/////////////////////////////////////////////////////////////////////
void GrGLRadialGradient::emitFS(GrGLShaderBuilder* builder,
void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder,
const GrEffect&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
SkString t;
t.printf("length(%s.xy)", builder->defaultTexCoordsName());
this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplers[0]);

View File

@ -389,9 +389,10 @@ public:
const GrEffect&) : INHERITED (factory) { }
virtual ~GrGLSweepGradient() { }
virtual void emitVS(GrGLShaderBuilder* builder,
const char* vertexCoords) SK_OVERRIDE { }
virtual void emitFS(GrGLShaderBuilder* builder,
virtual void emitCode(GrGLShaderBuilder*,
const GrEffect&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
@ -453,10 +454,14 @@ GrEffect* GrSweepGradient::TestCreate(SkRandom* random,
/////////////////////////////////////////////////////////////////////
void GrGLSweepGradient::emitFS(GrGLShaderBuilder* builder,
void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder,
const GrEffect&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
SkString t;
t.printf("atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5",
builder->defaultTexCoordsName(), builder->defaultTexCoordsName());

View File

@ -326,10 +326,10 @@ public:
const GrEffect&);
virtual ~GrGLConical2Gradient() { }
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
virtual void emitVS(GrGLShaderBuilder* builder,
const char* vertexCoords) SK_OVERRIDE;
virtual void emitFS(GrGLShaderBuilder* builder,
virtual void emitCode(GrGLShaderBuilder*,
const GrEffect&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
@ -465,8 +465,14 @@ GrGLConical2Gradient::GrGLConical2Gradient(
fIsDegenerate = data.isDegenerate();
}
void GrGLConical2Gradient::setupVariables(GrGLShaderBuilder* builder) {
INHERITED::setupVariables(builder);
void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
const GrEffect&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
// to work around Xoom bug. Doesn't seem to cause performance decrease
// in test apps, but need to keep an eye on it.
@ -481,10 +487,9 @@ void GrGLConical2Gradient::setupVariables(GrGLShaderBuilder* builder) {
builder->addVarying(kFloat_GrSLType, "Conical2BCoeff",
&fVSVaryingName, &fFSVaryingName);
}
}
void GrGLConical2Gradient::emitVS(GrGLShaderBuilder* builder,
const char* vertexCoords) {
// VS
{
SkString* code = &builder->fVSCode;
SkString p2; // distance between centers
SkString p3; // start radius
@ -503,10 +508,8 @@ void GrGLConical2Gradient::emitVS(GrGLShaderBuilder* builder,
}
}
void GrGLConical2Gradient::emitFS(GrGLShaderBuilder* builder,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
// FS
{
SkString* code = &builder->fFSCode;
SkString cName("c");
@ -625,6 +628,7 @@ void GrGLConical2Gradient::emitFS(GrGLShaderBuilder* builder,
code->appendf("\t}\n");
}
}
}
void GrGLConical2Gradient::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
INHERITED::setData(uman, stage);

View File

@ -361,10 +361,10 @@ public:
const GrEffect&);
virtual ~GrGLRadial2Gradient() { }
virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
virtual void emitVS(GrGLShaderBuilder* builder,
const char* vertexCoords) SK_OVERRIDE;
virtual void emitFS(GrGLShaderBuilder* builder,
virtual void emitCode(GrGLShaderBuilder*,
const GrEffect&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
@ -498,8 +498,15 @@ GrGLRadial2Gradient::GrGLRadial2Gradient(
fIsDegenerate = data.isDegenerate();
}
void GrGLRadial2Gradient::setupVariables(GrGLShaderBuilder* builder) {
INHERITED::setupVariables(builder);
void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
const GrEffect&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
// to work around Xoom bug. Doesn't seem to cause performance decrease
// in test apps, but need to keep an eye on it.
@ -514,10 +521,9 @@ void GrGLRadial2Gradient::setupVariables(GrGLShaderBuilder* builder) {
builder->addVarying(kFloat_GrSLType, "Radial2BCoeff",
&fVSVaryingName, &fFSVaryingName);
}
}
void GrGLRadial2Gradient::emitVS(GrGLShaderBuilder* builder,
const char* vertexCoords) {
// VS
{
SkString* code = &builder->fVSCode;
SkString p2;
SkString p3;
@ -534,10 +540,8 @@ void GrGLRadial2Gradient::emitVS(GrGLShaderBuilder* builder,
}
}
void GrGLRadial2Gradient::emitFS(GrGLShaderBuilder* builder,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
// FS
{
SkString* code = &builder->fFSCode;
SkString cName("c");
SkString ac4Name("ac4");
@ -600,6 +604,7 @@ void GrGLRadial2Gradient::emitFS(GrGLShaderBuilder* builder,
this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplers[0]);
}
}
void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
INHERITED::setData(uman, stage);