Combine the emit functions in GrGLProgramStage.

R=robertphillips@google.com
Review URL: https://codereview.appspot.com/6741064

git-svn-id: http://skia.googlecode.com/svn/trunk@6057 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2012-10-23 17:30:45 +00:00
Родитель 158618ec62
Коммит 374e75956e
15 изменённых файлов: 100 добавлений и 76 удалений

Просмотреть файл

@ -110,7 +110,7 @@ bool SkBlendImageFilter::onFilterImage(Proxy* proxy,
///////////////////////////////////////////////////////////////////////////////
#if SK_SUPPORT_GPU
class GrGLBlendEffect : public GrGLProgramStage {
class GrGLBlendEffect : public GrGLLegacyProgramStage {
public:
GrGLBlendEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage);
@ -127,7 +127,7 @@ public:
static inline StageKey GenKey(const GrCustomStage& s, const GrGLCaps&);
private:
typedef GrGLProgramStage INHERITED;
typedef GrGLLegacyProgramStage INHERITED;
SkBlendImageFilter::Mode fMode;
};
@ -235,7 +235,7 @@ const GrProgramStageFactory& GrBlendEffect::getFactory() const {
GrGLBlendEffect::GrGLBlendEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage)
: GrGLProgramStage(factory),
: INHERITED(factory),
fMode(static_cast<const GrBlendEffect&>(stage).mode()) {
}

Просмотреть файл

@ -339,14 +339,14 @@ public:
GR_DECLARE_CUSTOM_STAGE_TEST;
class GLProgramStage : public GrGLProgramStage {
class GLProgramStage : public GrGLLegacyProgramStage {
public:
// this class always generates the same code.
static StageKey GenKey(const GrCustomStage& s, const GrGLCaps&) { return 0; }
GLProgramStage(const GrProgramStageFactory& factory,
const GrCustomStage& stage)
: GrGLProgramStage(factory)
: INHERITED(factory)
, fMatrixHandle(GrGLUniformManager::kInvalidUniformHandle)
, fVectorHandle(GrGLUniformManager::kInvalidUniformHandle) {
}
@ -408,6 +408,8 @@ public:
private:
SkColorMatrix fMatrix;
typedef GrGLLegacyProgramStage INHERITED;
};
GR_DEFINE_CUSTOM_STAGE_TEST(ColorMatrixEffect);

Просмотреть файл

@ -939,7 +939,7 @@ SkLight* create_random_light(SkRandom* random) {
}
class GrGLLightingEffect : public GrGLProgramStage {
class GrGLLightingEffect : public GrGLLegacyProgramStage {
public:
GrGLLightingEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage);
@ -960,7 +960,7 @@ public:
virtual void setData(const GrGLUniformManager&, const GrCustomStage&) SK_OVERRIDE;
private:
typedef GrGLProgramStage INHERITED;
typedef GrGLLegacyProgramStage INHERITED;
UniformHandle fImageIncrementUni;
UniformHandle fSurfaceScaleUni;
@ -1055,7 +1055,7 @@ GrCustomStage* GrDiffuseLightingEffect::TestCreate(SkRandom* random,
GrGLLightingEffect::GrGLLightingEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage)
: GrGLProgramStage(factory)
: INHERITED(factory)
, fImageIncrementUni(kInvalidUniformHandle)
, fSurfaceScaleUni(kInvalidUniformHandle) {
const GrLightingEffect& m = static_cast<const GrLightingEffect&>(stage);

Просмотреть файл

@ -72,7 +72,7 @@ private:
// For brevity
typedef GrGLUniformManager::UniformHandle UniformHandle;
class GrGLMagnifierEffect : public GrGLProgramStage {
class GrGLMagnifierEffect : public GrGLLegacyProgramStage {
public:
GrGLMagnifierEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage);
@ -96,12 +96,12 @@ private:
UniformHandle fZoomVar;
UniformHandle fInsetVar;
typedef GrGLProgramStage INHERITED;
typedef GrGLLegacyProgramStage INHERITED;
};
GrGLMagnifierEffect::GrGLMagnifierEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage)
: GrGLProgramStage(factory)
: INHERITED(factory)
, fOffsetVar(GrGLUniformManager::kInvalidUniformHandle)
, fZoomVar(GrGLUniformManager::kInvalidUniformHandle)
, fInsetVar(GrGLUniformManager::kInvalidUniformHandle) {

Просмотреть файл

@ -279,7 +279,7 @@ private:
typedef GrSingleTextureEffect INHERITED;
};
class GrGLMatrixConvolutionEffect : public GrGLProgramStage {
class GrGLMatrixConvolutionEffect : public GrGLLegacyProgramStage {
public:
GrGLMatrixConvolutionEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage);
@ -307,11 +307,13 @@ private:
UniformHandle fTargetUni;
UniformHandle fGainUni;
UniformHandle fBiasUni;
typedef GrGLLegacyProgramStage INHERITED;
};
GrGLMatrixConvolutionEffect::GrGLMatrixConvolutionEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage)
: GrGLProgramStage(factory)
: INHERITED(factory)
, fKernelUni(GrGLUniformManager::kInvalidUniformHandle)
, fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle)
, fTargetUni(GrGLUniformManager::kInvalidUniformHandle)

Просмотреть файл

@ -266,7 +266,7 @@ private:
///////////////////////////////////////////////////////////////////////////////
class GrGLMorphologyEffect : public GrGLProgramStage {
class GrGLMorphologyEffect : public GrGLLegacyProgramStage {
public:
GrGLMorphologyEffect (const GrProgramStageFactory& factory,
const GrCustomStage& stage);
@ -290,12 +290,12 @@ private:
GrMorphologyEffect::MorphologyType fType;
GrGLUniformManager::UniformHandle fImageIncrementUni;
typedef GrGLProgramStage INHERITED;
typedef GrGLLegacyProgramStage INHERITED;
};
GrGLMorphologyEffect::GrGLMorphologyEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage)
: GrGLProgramStage(factory)
: INHERITED(factory)
, fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle) {
const GrMorphologyEffect& m = static_cast<const GrMorphologyEffect&>(stage);
fRadius = m.radius();

Просмотреть файл

@ -244,7 +244,7 @@ private:
typedef GrCustomStage INHERITED;
};
class GLColorTableEffect : public GrGLProgramStage {
class GLColorTableEffect : public GrGLLegacyProgramStage {
public:
GLColorTableEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage);
@ -263,7 +263,7 @@ public:
private:
typedef GrGLProgramStage INHERITED;
typedef GrGLLegacyProgramStage INHERITED;
};
GLColorTableEffect::GLColorTableEffect(

Просмотреть файл

@ -271,7 +271,7 @@ private:
///////////////////////////////////////////////////////////////////////////////
// Base class for GL gradient custom stages
class GrGLGradientStage : public GrGLProgramStage {
class GrGLGradientStage : public GrGLLegacyProgramStage {
public:
GrGLGradientStage(const GrProgramStageFactory& factory);
@ -293,7 +293,7 @@ private:
GrScalar fCachedYCoord;
GrGLUniformManager::UniformHandle fFSYUni;
typedef GrGLProgramStage INHERITED;
typedef GrGLLegacyProgramStage INHERITED;
};
#endif

Просмотреть файл

@ -8,7 +8,7 @@
#include "GrConfigConversionEffect.h"
#include "gl/GrGLProgramStage.h"
class GrGLConfigConversionEffect : public GrGLProgramStage {
class GrGLConfigConversionEffect : public GrGLLegacyProgramStage {
public:
GrGLConfigConversionEffect(const GrProgramStageFactory& factory,
const GrCustomStage& s) : INHERITED (factory) {
@ -67,7 +67,7 @@ private:
bool fSwapRedAndBlue;
GrConfigConversionEffect::PMConversion fPMConversion;
typedef GrGLProgramStage INHERITED;
typedef GrGLLegacyProgramStage INHERITED;
};

Просмотреть файл

@ -15,7 +15,7 @@
typedef GrGLUniformManager::UniformHandle UniformHandle;
static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidUniformHandle;
class GrGLConvolutionEffect : public GrGLProgramStage {
class GrGLConvolutionEffect : public GrGLLegacyProgramStage {
public:
GrGLConvolutionEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage);
@ -39,12 +39,12 @@ private:
UniformHandle fKernelUni;
UniformHandle fImageIncrementUni;
typedef GrGLProgramStage INHERITED;
typedef GrGLLegacyProgramStage INHERITED;
};
GrGLConvolutionEffect::GrGLConvolutionEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage)
: GrGLProgramStage(factory)
: INHERITED(factory)
, fKernelUni(kInvalidUniformHandle)
, fImageIncrementUni(kInvalidUniformHandle) {
const GrConvolutionEffect& c =

Просмотреть файл

@ -12,7 +12,7 @@
#include "GrProgramStageFactory.h"
#include "GrTexture.h"
class GrGLSingleTextureEffect : public GrGLProgramStage {
class GrGLSingleTextureEffect : public GrGLLegacyProgramStage {
public:
GrGLSingleTextureEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage) : INHERITED (factory) { }
@ -32,7 +32,7 @@ public:
private:
typedef GrGLProgramStage INHERITED;
typedef GrGLLegacyProgramStage INHERITED;
};
///////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -9,7 +9,7 @@
#include "gl/GrGLProgramStage.h"
#include "GrProgramStageFactory.h"
class GrGLTextureDomainEffect : public GrGLProgramStage {
class GrGLTextureDomainEffect : public GrGLLegacyProgramStage {
public:
GrGLTextureDomainEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage);
@ -29,12 +29,12 @@ public:
private:
GrGLUniformManager::UniformHandle fNameUni;
typedef GrGLProgramStage INHERITED;
typedef GrGLLegacyProgramStage INHERITED;
};
GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage)
: GrGLProgramStage(factory)
: INHERITED(factory)
, fNameUni(GrGLUniformManager::kInvalidUniformHandle) {
}

Просмотреть файл

@ -932,9 +932,6 @@ GrGLProgramStage* GrGLProgram::GenStageCode(const GrCustomStage* stage,
&varyingFSName);
builder->setupTextureAccess(varyingFSName, texCoordVaryingType);
// Must setup variables after calling setupTextureAccess
glStage->setupVariables(builder);
int numTextures = stage->numTextures();
SkSTArray<8, GrGLShaderBuilder::TextureSampler> textureSamplers;
@ -955,13 +952,11 @@ GrGLProgramStage* GrGLProgram::GenStageCode(const GrCustomStage* stage,
vector_all_coords(GrSLTypeToVecLength(texCoordVaryingType)));
}
builder->fVSCode.appendf("\t{ // %s\n", glStage->name());
glStage->emitVS(builder, varyingVSName);
builder->fVSCode.appendf("\t}\n");
// Enclose custom code in a block to avoid namespace conflicts
builder->fVSCode.appendf("\t{ // %s\n", glStage->name());
builder->fFSCode.appendf("\t{ // %s \n", glStage->name());
glStage->emitFS(builder, fsOutColor, fsInColor, textureSamplers);
glStage->emitCode(builder, varyingVSName, fsOutColor, fsInColor, textureSamplers);
builder->fVSCode.appendf("\t}\n");
builder->fFSCode.appendf("\t}\n");
return glStage;

Просмотреть файл

@ -17,11 +17,7 @@ GrGLProgramStage::~GrGLProgramStage() {
///////////////////////////////////////////////////////////////////////////////
void GrGLProgramStage::setupVariables(GrGLShaderBuilder*) {
}
void GrGLProgramStage::setData(const GrGLUniformManager&, const GrCustomStage&) {
void GrGLProgramStage::setData(const GrGLUniformManager&, const GrCustomStage&) {
}
GrGLProgramStage::StageKey GrGLProgramStage::GenTextureKey(const GrCustomStage& stage,

Просмотреть файл

@ -19,12 +19,15 @@ struct GrGLInterface;
class GrGLTexture;
/** @file
This file contains specializations for OpenGL of the shader stages
declared in src/gpu/GrCustomStage.h. All the functions emit
GLSL shader code and OpenGL calls.
This file contains specializations for OpenGL of the shader stages declared in
include/gpu/GrCustomStage.h. Objects of type GrGLProgramStage are responsible for emitting the
GLSL code that implements a GrCustomStage and for uploading uniforms at draw time. They also
must have a function:
static inline StageKey GenKey(const GrCustomStage&, const GrGLCaps&)
that is used to implement a program cache. When two GrCustomStages produce the same key this
means that their GrGLProgramStages would emit the same GLSL code.
These objects are created by a factory function on the
GrCustomStage.
These objects are created by the factory object returned by the GrCustomStage::getFactory().
*/
class GrGLProgramStage {
@ -42,37 +45,35 @@ public:
virtual ~GrGLProgramStage();
/** Create any uniforms or varyings the vertex shader requires. */
virtual void setupVariables(GrGLShaderBuilder* builder);
/** Called when the program stage should insert its code into the shaders. The code in each
shader will be in its own block ({}) and so locally scoped names will not collide across
stages.
/** Appends vertex code to the appropriate SkString
on the state.
The code will be inside an otherwise-empty block.
Vertex shader input is a vec2 of coordinates, which may
be altered.
The code will be inside an otherwise-empty block. */
virtual void emitVS(GrGLShaderBuilder* builder,
const char* vertexCoords) = 0;
/** Appends fragment code to the appropriate SkString
on the state.
The code will be inside an otherwise-empty block.
Fragment shader inputs are a vec2 of coordinates, one texture,
and a color; output is a color. The input color may be NULL which
indicates that the input color is solid white. TODO: Better system
for communicating optimization info (e.g. input color is solid white,
trans black, known to be opaque, etc.) that allows the custom stage
to communicate back similar known info about its output.
@param builder Interface used to emit code in the shaders.
@param vertexCoords A vec2 of texture coordinates in the VS, which may be altered. This will
be removed soon and stages will be responsible for computing their own
coords.
@param outputColor A predefined vec4 in the FS in which the stage should place its output
color (or coverage).
@param inputColor A vec4 that holds the input color to the stage in the FS. This may be
NULL in which case the implied input is solid white (all ones).
TODO: Better system for communicating optimization info (e.g. input
color is solid white, trans black, known to be opaque, etc.) that allows
the custom stage to communicate back similar known info about its
output.
@param samplers One entry for each GrTextureAccess of the GrCustomStage that generated
the GrGLProgramStage. These can be passed to the builder to emit texture
reads in the generated code.
*/
virtual void emitFS(GrGLShaderBuilder* builder,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) = 0;
virtual void emitCode(GrGLShaderBuilder* builder,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) = 0;
/** A GrGLCustomStage instance can be reused with any GrCustomStage
that produces the same stage key; this function reads data from
a stage and uploads any uniform variables required by the shaders
created in emit*(). */
/** A GrGLProgramStage instance can be reused with any GrCustomStage that produces the same
stage key; this function reads data from a stage and uploads any uniform variables required
by the shaders created in emitCode(). */
virtual void setData(const GrGLUniformManager&, const GrCustomStage& stage);
const char* name() const { return fFactory.name(); }
@ -84,4 +85,32 @@ protected:
const GrProgramStageFactory& fFactory;
};
/**
* This allows program stages that implemented an older set of virtual functions on GrGLProgramStage
* to continue to work by change their parent class to this class. New program stages should not use
* this interface. It will be removed once older stages are modified to implement emitCode().
*/
class GrGLLegacyProgramStage : public GrGLProgramStage {
public:
GrGLLegacyProgramStage(const GrProgramStageFactory& factory) : GrGLProgramStage(factory) {}
virtual void setupVariables(GrGLShaderBuilder* builder) {};
virtual void emitVS(GrGLShaderBuilder* builder,
const char* vertexCoords) = 0;
virtual void emitFS(GrGLShaderBuilder* builder,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) = 0;
virtual void emitCode(GrGLShaderBuilder* builder,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
this->setupVariables(builder);
this->emitVS(builder, vertexCoords);
this->emitFS(builder, outputColor, inputColor, samplers);
}
};
#endif