Add GL uniform manager
Review URL: http://codereview.appspot.com/6423066/
git-svn-id: http://skia.googlecode.com/svn/trunk@4758 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/effects/GrColorTableEffect.cpp b/src/gpu/effects/GrColorTableEffect.cpp
index 8ea0dbf..f047a3e 100644
--- a/src/gpu/effects/GrColorTableEffect.cpp
+++ b/src/gpu/effects/GrColorTableEffect.cpp
@@ -26,11 +26,7 @@
const char* inputColor,
const char* samplerName) SK_OVERRIDE;
- virtual void initUniforms(const GrGLShaderBuilder*,
- const GrGLInterface*,
- int programID) SK_OVERRIDE {}
-
- virtual void setData(const GrGLInterface*,
+ virtual void setData(const GrGLUniformManager&,
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE {}
diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp
index a16313e..f01caa3 100644
--- a/src/gpu/effects/GrConvolutionEffect.cpp
+++ b/src/gpu/effects/GrConvolutionEffect.cpp
@@ -11,9 +11,9 @@
#include "gl/GrGLTexture.h"
#include "GrProgramStageFactory.h"
-// For brevity, and these definitions are likely to move to a different class soon.
-typedef GrGLShaderBuilder::UniformHandle UniformHandle;
-static const UniformHandle kInvalidUniformHandle = GrGLShaderBuilder::kInvalidUniformHandle;
+// For brevity
+typedef GrGLUniformManager::UniformHandle UniformHandle;
+static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidUniformHandle;
class GrGLConvolutionEffect : public GrGLProgramStage {
public:
@@ -29,11 +29,7 @@
const char* inputColor,
const char* samplerName) SK_OVERRIDE;
- virtual void initUniforms(const GrGLShaderBuilder*,
- const GrGLInterface*,
- int programID) SK_OVERRIDE;
-
- virtual void setData(const GrGLInterface*,
+ virtual void setData(const GrGLUniformManager& uman,
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
@@ -45,9 +41,7 @@
int fRadius;
UniformHandle fKernelUni;
- GrGLint fKernelLocation;
UniformHandle fImageIncrementUni;
- GrGLint fImageIncrementLocation;
typedef GrGLProgramStage INHERITED;
};
@@ -56,9 +50,7 @@
const GrCustomStage& stage)
: GrGLProgramStage(factory)
, fKernelUni(kInvalidUniformHandle)
- , fKernelLocation(0)
- , fImageIncrementUni(kInvalidUniformHandle)
- , fImageIncrementLocation(0) {
+ , fImageIncrementUni(kInvalidUniformHandle) {
const GrConvolutionEffect& c =
static_cast<const GrConvolutionEffect&>(stage);
fRadius = c.radius();
@@ -71,9 +63,6 @@
kVec2f_GrSLType, "uImageIncrement", stage);
fKernelUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kFloat_GrSLType, "uKernel", stage, this->width());
-
- fImageIncrementLocation = kUseUniform;
- fKernelLocation = kUseUniform;
}
void GrGLConvolutionEffect::emitVS(GrGLShaderBuilder* builder,
@@ -114,16 +103,7 @@
}
}
-void GrGLConvolutionEffect::initUniforms(const GrGLShaderBuilder* builder,
- const GrGLInterface* gl,
- int programID) {
- const char* kernel = builder->getUniformCStr(fKernelUni);
- const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
- GR_GL_CALL_RET(gl, fImageIncrementLocation, GetUniformLocation(programID, imgInc));
- GR_GL_CALL_RET(gl, fKernelLocation, GetUniformLocation(programID, kernel));
-}
-
-void GrGLConvolutionEffect::setData(const GrGLInterface* gl,
+void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman,
const GrCustomStage& data,
const GrRenderTarget*,
int stageNum) {
@@ -143,9 +123,8 @@
default:
GrCrash("Unknown filter direction.");
}
- GR_GL_CALL(gl, Uniform2fv(fImageIncrementLocation, 1, imageIncrement));
-
- GR_GL_CALL(gl, Uniform1fv(fKernelLocation, this->width(), conv.kernel()));
+ uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
+ uman.set1fv(fKernelUni, 0, this->width(), conv.kernel());
}
GrGLProgramStage::StageKey GrGLConvolutionEffect::GenKey(
diff --git a/src/gpu/effects/GrGradientEffects.cpp b/src/gpu/effects/GrGradientEffects.cpp
index 34bff09..3769e21 100644
--- a/src/gpu/effects/GrGradientEffects.cpp
+++ b/src/gpu/effects/GrGradientEffects.cpp
@@ -202,9 +202,9 @@
/////////////////////////////////////////////////////////////////////
-// For brevity, and these definitions are likely to move to a different class soon.
-typedef GrGLShaderBuilder::UniformHandle UniformHandle;
-static const UniformHandle kInvalidUniformHandle = GrGLShaderBuilder::kInvalidUniformHandle;
+// For brevity
+typedef GrGLUniformManager::UniformHandle UniformHandle;
+static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidUniformHandle;
class GrGLRadial2Gradient : public GrGLGradientStage {
@@ -222,10 +222,7 @@
const char* outputColor,
const char* inputColor,
const char* samplerName) SK_OVERRIDE;
- virtual void initUniforms(const GrGLShaderBuilder* builder,
- const GrGLInterface*,
- int programID) SK_OVERRIDE;
- virtual void setData(const GrGLInterface*,
+ virtual void setData(const GrGLUniformManager&,
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
@@ -237,9 +234,7 @@
protected:
UniformHandle fVSParamUni;
- GrGLint fVSParamLocation;
UniformHandle fFSParamUni;
- GrGLint fFSParamLocation;
const char* fVSVaryingName;
const char* fFSVaryingName;
@@ -287,9 +282,6 @@
fFSParamUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kFloat_GrSLType, "uRadial2FSParams", stage, 6);
- fVSParamLocation = GrGLProgramStage::kUseUniform;
- fFSParamLocation = GrGLProgramStage::kUseUniform;
-
// For radial gradients without perspective we can pass the linear
// part of the quadratic as a varying.
if (builder->fVaryingDims == builder->fCoordDims) {
@@ -385,16 +377,7 @@
this->emitColorLookup(builder, t.c_str(), outputColor, samplerName);
}
-void GrGLRadial2Gradient::initUniforms(const GrGLShaderBuilder* builder,
- const GrGLInterface* gl,
- int programID) {
- const char* vsParam = builder->getUniformCStr(fVSParamUni);
- const char* fsParam = builder->getUniformCStr(fFSParamUni);
- GR_GL_CALL_RET(gl, fVSParamLocation, GetUniformLocation(programID, vsParam));
- GR_GL_CALL_RET(gl, fFSParamLocation, GetUniformLocation(programID, fsParam));
-}
-
-void GrGLRadial2Gradient::setData(const GrGLInterface* gl,
+void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman,
const GrCustomStage& baseData,
const GrRenderTarget*,
int stageNum) {
@@ -423,8 +406,8 @@
data.isPosRoot() ? 1.f : -1.f
};
- GR_GL_CALL(gl, Uniform1fv(fVSParamLocation, 6, values));
- GR_GL_CALL(gl, Uniform1fv(fFSParamLocation, 6, values));
+ uman.set1fv(fVSParamUni, 0, 6, values);
+ uman.set1fv(fFSParamUni, 0, 6, values);
fCachedCenter = centerX1;
fCachedRadius = radius0;
fCachedPosRoot = data.isPosRoot();
@@ -492,10 +475,7 @@
const char* outputColor,
const char* inputColor,
const char* samplerName) SK_OVERRIDE;
- virtual void initUniforms(const GrGLShaderBuilder* builder,
- const GrGLInterface*,
- int programID) SK_OVERRIDE;
- virtual void setData(const GrGLInterface*,
+ virtual void setData(const GrGLUniformManager&,
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
@@ -713,16 +693,7 @@
}
}
-void GrGLConical2Gradient::initUniforms(const GrGLShaderBuilder* builder,
- const GrGLInterface* gl,
- int programID) {
- const char* vsParam = builder->getUniformCStr(fVSParamUni);
- const char* fsParam = builder->getUniformCStr(fFSParamUni);
- GR_GL_CALL_RET(gl, fVSParamLocation, GetUniformLocation(programID, vsParam));
- GR_GL_CALL_RET(gl, fFSParamLocation, GetUniformLocation(programID, fsParam));
-}
-
-void GrGLConical2Gradient::setData(const GrGLInterface* gl,
+void GrGLConical2Gradient::setData(const GrGLUniformManager& uman,
const GrCustomStage& baseData,
const GrRenderTarget*,
int stageNum) {
@@ -753,8 +724,8 @@
GrScalarToFloat(diffRadius)
};
- GR_GL_CALL(gl, Uniform1fv(fVSParamLocation, 6, values));
- GR_GL_CALL(gl, Uniform1fv(fFSParamLocation, 6, values));
+ uman.set1fv(fVSParamUni, 0, 6, values);
+ uman.set1fv(fFSParamUni, 0, 6, values);
fCachedCenter = centerX1;
fCachedRadius = radius0;
fCachedDiffRadius = diffRadius;
diff --git a/src/gpu/effects/GrMorphologyEffect.cpp b/src/gpu/effects/GrMorphologyEffect.cpp
index 6699989..22c986a 100644
--- a/src/gpu/effects/GrMorphologyEffect.cpp
+++ b/src/gpu/effects/GrMorphologyEffect.cpp
@@ -29,10 +29,7 @@
static inline StageKey GenKey(const GrCustomStage& s);
- virtual void initUniforms(const GrGLShaderBuilder*,
- const GrGLInterface*,
- int programID) SK_OVERRIDE;
- virtual void setData(const GrGLInterface*,
+ virtual void setData(const GrGLUniformManager&,
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
@@ -40,10 +37,9 @@
private:
int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); }
- int fRadius;
- GrMorphologyEffect::MorphologyType fType;
- GrGLShaderBuilder::UniformHandle fImageIncrementUni;
- GrGLint fImageIncrementLocation;
+ int fRadius;
+ GrMorphologyEffect::MorphologyType fType;
+ GrGLUniformManager::UniformHandle fImageIncrementUni;
typedef GrGLProgramStage INHERITED;
};
@@ -51,8 +47,7 @@
GrGLMorphologyEffect ::GrGLMorphologyEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage)
: GrGLProgramStage(factory)
- , fImageIncrementUni(GrGLShaderBuilder::kInvalidUniformHandle)
- , fImageIncrementLocation(0) {
+ , fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle) {
const GrMorphologyEffect& m = static_cast<const GrMorphologyEffect&>(stage);
fRadius = m.radius();
fType = m.type();
@@ -71,13 +66,6 @@
code->appendf("\t\t%s -= vec2(%d, %d) * %s;\n", vertexCoords, fRadius, fRadius, imgInc);
}
-void GrGLMorphologyEffect::initUniforms(const GrGLShaderBuilder* builder,
- const GrGLInterface* gl,
- int programID) {
- const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
- GR_GL_CALL_RET(gl, fImageIncrementLocation, GetUniformLocation(programID, imgInc));
-}
-
void GrGLMorphologyEffect ::emitFS(GrGLShaderBuilder* builder,
const char* outputColor,
const char* inputColor,
@@ -119,7 +107,7 @@
return key;
}
-void GrGLMorphologyEffect ::setData(const GrGLInterface* gl,
+void GrGLMorphologyEffect ::setData(const GrGLUniformManager& uman,
const GrCustomStage& data,
const GrRenderTarget*,
int stageNum) {
@@ -140,7 +128,7 @@
default:
GrCrash("Unknown filter direction.");
}
- GR_GL_CALL(gl, Uniform2fv(fImageIncrementLocation, 1, imageIncrement));
+ uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/effects/GrSingleTextureEffect.cpp b/src/gpu/effects/GrSingleTextureEffect.cpp
index d8b90a1..350d9e6 100644
--- a/src/gpu/effects/GrSingleTextureEffect.cpp
+++ b/src/gpu/effects/GrSingleTextureEffect.cpp
@@ -12,10 +12,6 @@
#include "GrProgramStageFactory.h"
#include "GrTexture.h"
-// For brevity, and these definitions are likely to move to a different class soon.
-typedef GrGLShaderBuilder::UniformHandle UniformHandle;
-static const UniformHandle kInvalidUniformHandle = GrGLShaderBuilder::kInvalidUniformHandle;
-
class GrGLSingleTextureEffect : public GrGLProgramStage {
public:
GrGLSingleTextureEffect(const GrProgramStageFactory& factory,
diff --git a/src/gpu/effects/GrTextureDomainEffect.cpp b/src/gpu/effects/GrTextureDomainEffect.cpp
index e949c4c..ca8561c 100644
--- a/src/gpu/effects/GrTextureDomainEffect.cpp
+++ b/src/gpu/effects/GrTextureDomainEffect.cpp
@@ -9,10 +9,6 @@
#include "gl/GrGLProgramStage.h"
#include "GrProgramStageFactory.h"
-// For brevity, and these definitions are likely to move to a different class soon.
-typedef GrGLShaderBuilder::UniformHandle UniformHandle;
-static const UniformHandle kInvalidUniformHandle = GrGLShaderBuilder::kInvalidUniformHandle;
-
class GrGLTextureDomainEffect : public GrGLProgramStage {
public:
GrGLTextureDomainEffect(const GrProgramStageFactory& factory,
@@ -27,11 +23,7 @@
const char* inputColor,
const char* samplerName) SK_OVERRIDE;
- virtual void initUniforms(const GrGLShaderBuilder* builder,
- const GrGLInterface*,
- int programID) SK_OVERRIDE;
-
- virtual void setData(const GrGLInterface*,
+ virtual void setData(const GrGLUniformManager&,
const GrCustomStage&,
const GrRenderTarget*,
int stageNum) SK_OVERRIDE;
@@ -39,8 +31,7 @@
static inline StageKey GenKey(const GrCustomStage&) { return 0; }
private:
- UniformHandle fNameUni;
- int fNameLocation;
+ GrGLUniformManager::UniformHandle fNameUni;
typedef GrGLProgramStage INHERITED;
};
@@ -48,15 +39,13 @@
GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrProgramStageFactory& factory,
const GrCustomStage& stage)
: GrGLProgramStage(factory)
- , fNameUni(kInvalidUniformHandle)
- , fNameLocation(0) {
+ , fNameUni(GrGLUniformManager::kInvalidUniformHandle) {
}
void GrGLTextureDomainEffect::setupVariables(GrGLShaderBuilder* builder,
int stage) {
fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec4f_GrSLType, "uTexDom", stage);
- fNameLocation = kUseUniform;
};
void GrGLTextureDomainEffect::emitFS(GrGLShaderBuilder* builder,
@@ -75,17 +64,10 @@
builder->emitDefaultFetch(outputColor, samplerName);
}
-void GrGLTextureDomainEffect::initUniforms(const GrGLShaderBuilder* builder,
- const GrGLInterface* gl, int programID) {
- GR_GL_CALL_RET(gl, fNameLocation,
- GetUniformLocation(programID, builder->getUniformCStr(fNameUni)));
- GrAssert(kUnusedUniform != fNameLocation);
-}
-
-void GrGLTextureDomainEffect::setData(const GrGLInterface* gl,
- const GrCustomStage& data,
- const GrRenderTarget*,
- int stageNum) {
+void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman,
+ const GrCustomStage& data,
+ const GrRenderTarget*,
+ int stageNum) {
const GrTextureDomainEffect& effect = static_cast<const GrTextureDomainEffect&>(data);
const GrRect& domain = effect.domain();
@@ -104,8 +86,7 @@
// of elements so that values = (l, t, r, b).
SkTSwap(values[1], values[3]);
}
-
- GR_GL_CALL(gl, Uniform4fv(fNameLocation, 1, values));
+ uman.set4fv(fNameUni, 0, 1, values);
}
@@ -114,7 +95,6 @@
GrTextureDomainEffect::GrTextureDomainEffect(GrTexture* texture, GrRect domain)
: GrSingleTextureEffect(texture)
, fTextureDomain(domain) {
-
}
GrTextureDomainEffect::~GrTextureDomainEffect() {