Refactor GrGLUniformManager::UniformHandle to initialize itself by default

Refactor GrGLUniformManager::UniformHandle to initialize itself to
"invalid" state by default. This simplifies the effect
constructors. In the future, it should also help catch potential
uninitialized uniform variable usage.

Remove unneeded explicit uniform handle validity assertions before the
handle usage. The assertion will always be made when handle is
converted to index.

BUG=skia:1492
R=bsalomon@google.com

Author: kkinnunen@nvidia.com

Review URL: https://chromiumcodereview.appspot.com/22340010

git-svn-id: http://skia.googlecode.com/svn/trunk@10713 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2013-08-14 18:14:19 +00:00
parent 0c0e14c14e
commit 7425c124f6
21 changed files with 76 additions and 105 deletions

View File

@ -215,8 +215,6 @@ private:
GrGLBicubicEffect::GrGLBicubicEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED(factory)
, fCoefficientsUni(GrGLUniformManager::kInvalidUniformHandle)
, fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle)
, fEffectMatrix(drawEffect.castEffect<GrBicubicEffect>().coordsType()) {
}

View File

@ -391,9 +391,8 @@ public:
GLEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect&)
: INHERITED(factory)
, fMatrixHandle(GrGLUniformManager::kInvalidUniformHandle)
, fVectorHandle(GrGLUniformManager::kInvalidUniformHandle) {}
: INHERITED(factory) {
}
virtual void emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,

View File

@ -25,7 +25,6 @@ class GrGLSpecularLightingEffect;
// For brevity
typedef GrGLUniformManager::UniformHandle UniformHandle;
static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidUniformHandle;
#endif
namespace {
@ -1150,8 +1149,6 @@ GrEffectRef* GrDiffuseLightingEffect::TestCreate(SkMWCRandom* random,
GrGLLightingEffect::GrGLLightingEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED(factory)
, fImageIncrementUni(kInvalidUniformHandle)
, fSurfaceScaleUni(kInvalidUniformHandle)
, fEffectMatrix(drawEffect.castEffect<GrLightingEffect>().coordsType()) {
const GrLightingEffect& m = drawEffect.castEffect<GrLightingEffect>();
fLight = m.light()->createGLLight();
@ -1294,8 +1291,7 @@ void GrGLLightingEffect::setData(const GrGLUniformManager& uman,
GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED(factory, drawEffect)
, fKDUni(kInvalidUniformHandle) {
: INHERITED(factory, drawEffect) {
}
void GrGLDiffuseLightingEffect::emitLightFunc(GrGLShaderBuilder* builder, SkString* funcName) {
@ -1372,9 +1368,7 @@ GrEffectRef* GrSpecularLightingEffect::TestCreate(SkMWCRandom* random,
GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: GrGLLightingEffect(factory, drawEffect)
, fKSUni(kInvalidUniformHandle)
, fShininessUni(kInvalidUniformHandle) {
: INHERITED(factory, drawEffect) {
}
void GrGLSpecularLightingEffect::emitLightFunc(GrGLShaderBuilder* builder, SkString* funcName) {

View File

@ -118,9 +118,6 @@ private:
GrGLMagnifierEffect::GrGLMagnifierEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED(factory)
, fOffsetVar(GrGLUniformManager::kInvalidUniformHandle)
, fZoomVar(GrGLUniformManager::kInvalidUniformHandle)
, fInsetVar(GrGLUniformManager::kInvalidUniformHandle)
, fEffectMatrix(drawEffect.castEffect<GrMagnifierEffect>().coordsType()) {
}

View File

@ -351,11 +351,6 @@ private:
GrGLMatrixConvolutionEffect::GrGLMatrixConvolutionEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED(factory)
, fKernelUni(GrGLUniformManager::kInvalidUniformHandle)
, fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle)
, fTargetUni(GrGLUniformManager::kInvalidUniformHandle)
, fGainUni(GrGLUniformManager::kInvalidUniformHandle)
, fBiasUni(GrGLUniformManager::kInvalidUniformHandle)
, fEffectMatrix(drawEffect.castEffect<GrMatrixConvolutionEffect>().coordsType()) {
const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvolutionEffect>();
fKernelSize = m.kernelSize();

View File

@ -312,7 +312,6 @@ private:
GrGLMorphologyEffect::GrGLMorphologyEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED(factory)
, fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle)
, fEffectMatrix(drawEffect.castEffect<GrMorphologyEffect>().coordsType()) {
const GrMorphologyEffect& m = drawEffect.castEffect<GrMorphologyEffect>();
fRadius = m.radius();

View File

@ -826,7 +826,6 @@ SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
GrGLGradientEffect::GrGLGradientEffect(const GrBackendEffectFactory& factory)
: INHERITED(factory)
, fCachedYCoord(SK_ScalarMax)
, fFSYUni(GrGLUniformManager::kInvalidUniformHandle)
, fEffectMatrix(kCoordsType) {
}

View File

@ -336,7 +336,6 @@ void SkTwoPointConicalGradient::flatten(
// For brevity
typedef GrGLUniformManager::UniformHandle UniformHandle;
static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidUniformHandle;
class GrGLConical2Gradient : public GrGLGradientEffect {
public:
@ -475,8 +474,6 @@ GrEffectRef* GrConical2Gradient::TestCreate(SkMWCRandom* random,
GrGLConical2Gradient::GrGLConical2Gradient(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED(factory)
, fVSParamUni(kInvalidUniformHandle)
, fFSParamUni(kInvalidUniformHandle)
, fVSVaryingName(NULL)
, fFSVaryingName(NULL)
, fCachedCenter(SK_ScalarMax)

View File

@ -376,7 +376,6 @@ void SkTwoPointRadialGradient::init() {
// For brevity
typedef GrGLUniformManager::UniformHandle UniformHandle;
static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidUniformHandle;
class GrGLRadial2Gradient : public GrGLGradientEffect {
@ -516,8 +515,6 @@ GrEffectRef* GrRadial2Gradient::TestCreate(SkMWCRandom* random,
GrGLRadial2Gradient::GrGLRadial2Gradient(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED(factory)
, fVSParamUni(kInvalidUniformHandle)
, fFSParamUni(kInvalidUniformHandle)
, fVSVaryingName(NULL)
, fFSVaryingName(NULL)
, fCachedCenter(SK_ScalarMax)

View File

@ -14,7 +14,6 @@
// For brevity
typedef GrGLUniformManager::UniformHandle UniformHandle;
static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidUniformHandle;
class GrGLConvolutionEffect : public GrGLEffect {
public:
@ -50,9 +49,6 @@ private:
GrGLConvolutionEffect::GrGLConvolutionEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED(factory)
, fKernelUni(kInvalidUniformHandle)
, fImageIncrementUni(kInvalidUniformHandle)
, fBoundsUni(kInvalidUniformHandle)
, fEffectMatrix(drawEffect.castEffect<GrConvolutionEffect>().coordsType()) {
const GrConvolutionEffect& c = drawEffect.castEffect<GrConvolutionEffect>();
fRadius = c.radius();

View File

@ -38,7 +38,6 @@ private:
GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED(factory)
, fNameUni(GrGLUniformManager::kInvalidUniformHandle)
, fEffectMatrix(drawEffect.castEffect<GrTextureDomainEffect>().coordsType()) {
fPrevDomain[0] = SK_FloatNaN;
}

View File

@ -189,8 +189,7 @@ void GrGLEffectMatrix::setData(const GrGLUniformManager& uniformManager,
const SkMatrix& matrix,
const GrDrawEffect& drawEffect,
const GrTexture* texture) {
GrAssert((GrGLUniformManager::kInvalidUniformHandle == fUni) ==
(kVoid_GrSLType == fUniType));
GrAssert(fUni.isValid() != (kVoid_GrSLType == fUniType));
const SkMatrix& coordChangeMatrix = GrEffect::kLocal_CoordsType == fCoordsType ?
drawEffect.getCoordChangeMatrix() :
SkMatrix::I();

View File

@ -59,8 +59,7 @@ public:
};
GrGLEffectMatrix(CoordsType coordsType)
: fUni(GrGLUniformManager::kInvalidUniformHandle)
, fCoordsType(coordsType) {
: fCoordsType(coordsType) {
GrAssert(GrEffect::kLocal_CoordsType == coordsType ||
GrEffect::kPosition_CoordsType == coordsType);
fPrevMatrix = SkMatrix::InvalidMatrix();

View File

@ -753,7 +753,7 @@ bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& buil
void GrGLProgram::initSamplerUniforms() {
GL_CALL(UseProgram(fProgramID));
GrGLint texUnitIdx = 0;
if (GrGLUniformManager::kInvalidUniformHandle != fUniformHandles.fDstCopySamplerUni) {
if (fUniformHandles.fDstCopySamplerUni.isValid()) {
fUniformManager.setSampler(fUniformHandles.fDstCopySamplerUni, texUnitIdx);
fDstCopyTexUnit = texUnitIdx++;
}
@ -772,7 +772,7 @@ void GrGLProgram::initEffectSamplerUniforms(EffectAndSamplers* effect, int* texU
effect->fTextureUnits.reset(numSamplers);
for (int s = 0; s < numSamplers; ++s) {
UniformHandle handle = effect->fSamplerUnis[s];
if (GrGLUniformManager::kInvalidUniformHandle != handle) {
if (handle.isValid()) {
fUniformManager.setSampler(handle, *texUnitIdx);
effect->fTextureUnits[s] = (*texUnitIdx)++;
}
@ -795,7 +795,7 @@ void GrGLProgram::setEffectData(GrGpuGL* gpu,
GrAssert((*stage.getEffect())->numTextures() == numSamplers);
for (int s = 0; s < numSamplers; ++s) {
UniformHandle handle = effect.fSamplerUnis[s];
if (GrGLUniformManager::kInvalidUniformHandle != handle) {
if (handle.isValid()) {
const GrTextureAccess& access = (*stage.getEffect())->textureAccess(s);
GrGLTexture* texture = static_cast<GrGLTexture*>(access.getTexture());
int unit = effect.fTextureUnits[s];
@ -830,7 +830,7 @@ void GrGLProgram::setData(GrGpuGL* gpu,
this->setMatrixAndRenderTargetHeight(drawState);
// Setup the SkXfermode::Mode-based colorfilter uniform if necessary
if (GrGLUniformManager::kInvalidUniformHandle != fUniformHandles.fColorFilterUni &&
if (fUniformHandles.fColorFilterUni.isValid() &&
fColorFilterColor != drawState.getColorFilterColor()) {
GrGLfloat c[4];
GrColorToRGBAFloat(drawState.getColorFilterColor(), c);
@ -839,10 +839,7 @@ void GrGLProgram::setData(GrGpuGL* gpu,
}
if (NULL != dstCopy) {
if (GrGLUniformManager::kInvalidUniformHandle != fUniformHandles.fDstCopyTopLeftUni) {
GrAssert(GrGLUniformManager::kInvalidUniformHandle != fUniformHandles.fDstCopyScaleUni);
GrAssert(GrGLUniformManager::kInvalidUniformHandle !=
fUniformHandles.fDstCopySamplerUni);
if (fUniformHandles.fDstCopyTopLeftUni.isValid()) {
fUniformManager.set2f(fUniformHandles.fDstCopyTopLeftUni,
static_cast<GrGLfloat>(dstCopy->offset().fX),
static_cast<GrGLfloat>(dstCopy->offset().fY));
@ -853,15 +850,13 @@ void GrGLProgram::setData(GrGpuGL* gpu,
static GrTextureParams kParams; // the default is clamp, nearest filtering.
gpu->bindTexture(fDstCopyTexUnit, kParams, texture);
} else {
GrAssert(GrGLUniformManager::kInvalidUniformHandle ==
fUniformHandles.fDstCopyScaleUni);
GrAssert(GrGLUniformManager::kInvalidUniformHandle ==
fUniformHandles.fDstCopySamplerUni);
GrAssert(!fUniformHandles.fDstCopyScaleUni.isValid());
GrAssert(!fUniformHandles.fDstCopySamplerUni.isValid());
}
} else {
GrAssert(GrGLUniformManager::kInvalidUniformHandle == fUniformHandles.fDstCopyTopLeftUni);
GrAssert(GrGLUniformManager::kInvalidUniformHandle == fUniformHandles.fDstCopyScaleUni);
GrAssert(GrGLUniformManager::kInvalidUniformHandle == fUniformHandles.fDstCopySamplerUni);
GrAssert(!fUniformHandles.fDstCopyTopLeftUni.isValid());
GrAssert(!fUniformHandles.fDstCopyScaleUni.isValid());
GrAssert(!fUniformHandles.fDstCopySamplerUni.isValid());
}
for (int e = 0; e < fColorEffects.count(); ++e) {
@ -902,8 +897,6 @@ void GrGLProgram::setColor(const GrDrawState& drawState,
// OpenGL ES doesn't support unsigned byte varieties of glUniform
GrGLfloat c[4];
GrColorToRGBAFloat(color, c);
GrAssert(GrGLUniformManager::kInvalidUniformHandle !=
fUniformHandles.fColorUni);
fUniformManager.set4fv(fUniformHandles.fColorUni, 0, 1, c);
fColor = color;
}
@ -943,8 +936,6 @@ void GrGLProgram::setCoverage(const GrDrawState& drawState,
// OpenGL ES doesn't support unsigned byte varieties of glUniform
GrGLfloat c[4];
GrColorToRGBAFloat(coverage, c);
GrAssert(GrGLUniformManager::kInvalidUniformHandle !=
fUniformHandles.fCoverageUni);
fUniformManager.set4fv(fUniformHandles.fCoverageUni, 0, 1, c);
fCoverage = coverage;
}
@ -968,7 +959,7 @@ void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) {
size.set(rt->width(), rt->height());
// Load the RT height uniform if it is needed to y-flip gl_FragCoord.
if (GrGLUniformManager::kInvalidUniformHandle != fUniformHandles.fRTHeightUni &&
if (fUniformHandles.fRTHeightUni.isValid() &&
fMatrixState.fRenderTargetSize.fHeight != size.fHeight) {
fUniformManager.set1f(fUniformHandles.fRTHeightUni, SkIntToScalar(size.fHeight));
}

View File

@ -132,17 +132,6 @@ private:
UniformHandle fDstCopyTopLeftUni;
UniformHandle fDstCopyScaleUni;
UniformHandle fDstCopySamplerUni;
UniformHandles() {
fViewMatrixUni = GrGLUniformManager::kInvalidUniformHandle;
fColorUni = GrGLUniformManager::kInvalidUniformHandle;
fCoverageUni = GrGLUniformManager::kInvalidUniformHandle;
fColorFilterUni = GrGLUniformManager::kInvalidUniformHandle;
fRTHeightUni = GrGLUniformManager::kInvalidUniformHandle;
fDstCopyTopLeftUni = GrGLUniformManager::kInvalidUniformHandle;
fDstCopyScaleUni = GrGLUniformManager::kInvalidUniformHandle;
fDstCopySamplerUni = GrGLUniformManager::kInvalidUniformHandle;
}
};
typedef SkSTArray<4, UniformHandle, true> SamplerUniSArray;

View File

@ -110,9 +110,6 @@ GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
, fUsesGS(false)
#endif
, fSetupFragPosition(false)
, fRTHeightUniform(GrGLUniformManager::kInvalidUniformHandle)
, fDstCopyTopLeftUniform (GrGLUniformManager::kInvalidUniformHandle)
, fDstCopyScaleUniform (GrGLUniformManager::kInvalidUniformHandle)
, fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFragPosKey) {
const GrGLProgramDesc::KeyHeader& header = desc.getHeader();
@ -391,7 +388,7 @@ GrGLUniformManager::UniformHandle GrGLShaderBuilder::addUniformArray(uint32_t vi
GrAssert(0 != visibility);
BuilderUniform& uni = fUniforms.push_back();
UniformHandle h = index_to_handle(fUniforms.count() - 1);
UniformHandle h = GrGLUniformManager::UniformHandle::CreateFromUniformIndex(fUniforms.count() - 1);
GR_DEBUGCODE(UniformHandle h2 =)
fUniformManager.appendUniform(type, count);
// We expect the uniform manager to initially have no uniforms and that all uniforms are added
@ -418,10 +415,6 @@ GrGLUniformManager::UniformHandle GrGLShaderBuilder::addUniformArray(uint32_t vi
return h;
}
const GrGLShaderVar& GrGLShaderBuilder::getUniformVariable(UniformHandle u) const {
return fUniforms[handle_to_index(u)].fVariable;
}
bool GrGLShaderBuilder::addAttribute(GrSLType type,
const char* name) {
for (int i = 0; i < fVSAttrs.count(); ++i) {
@ -512,7 +505,7 @@ const char* GrGLShaderBuilder::fragmentPosition() {
// temporarily change the stage index because we're inserting non-stage code.
CodeStage::AutoStageRestore csar(&fCodeStage, NULL);
GrAssert(GrGLUniformManager::kInvalidUniformHandle == fRTHeightUniform);
GrAssert(!fRTHeightUniform.isValid());
const char* rtHeightName;
fRTHeightUniform = this->addUniform(kFragment_ShaderType,
@ -524,7 +517,7 @@ const char* GrGLShaderBuilder::fragmentPosition() {
kCoordName, rtHeightName);
fSetupFragPosition = true;
}
GrAssert(GrGLUniformManager::kInvalidUniformHandle != fRTHeightUniform);
GrAssert(fRTHeightUniform.isValid());
return kCoordName;
}
}

View File

@ -33,8 +33,7 @@ public:
class TextureSampler {
public:
TextureSampler()
: fConfigComponentMask(0)
, fSamplerUniform(GrGLUniformManager::kInvalidUniformHandle) {
: fConfigComponentMask(0) {
// we will memcpy the first 4 bytes from passed in swizzle. This ensures the string is
// terminated.
fSwizzle[4] = '\0';
@ -44,7 +43,7 @@ public:
TextureSampler& operator= (const TextureSampler& other) {
GrAssert(0 == fConfigComponentMask);
GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUniform);
GrAssert(!fSamplerUniform.isValid());
fConfigComponentMask = other.fConfigComponentMask;
fSamplerUniform = other.fSamplerUniform;
@ -67,7 +66,7 @@ public:
int idx) {
GrAssert(!this->isInitialized());
GrAssert(0 != configComponentMask);
GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUniform);
GrAssert(!fSamplerUniform.isValid());
GrAssert(NULL != builder);
SkString name;
@ -75,7 +74,7 @@ public:
fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kSampler2D_GrSLType,
name.c_str());
GrAssert(GrGLUniformManager::kInvalidUniformHandle != fSamplerUniform);
GrAssert(fSamplerUniform.isValid());
fConfigComponentMask = configComponentMask;
memcpy(fSwizzle, swizzle, 4);
@ -228,7 +227,9 @@ public:
int arrayCount,
const char** outName = NULL);
const GrGLShaderVar& getUniformVariable(GrGLUniformManager::UniformHandle) const;
const GrGLShaderVar& getUniformVariable(GrGLUniformManager::UniformHandle u) const {
return fUniformManager.getBuilderUniform(fUniforms, u).fVariable;
}
/**
* Shortcut for getUniformVariable(u).c_str()

View File

@ -8,9 +8,8 @@
#ifndef GrUniformHandle_DEFINED
#define GrUniformHandle_DEFINED
namespace {
inline int handle_to_index(GrGLUniformManager::UniformHandle h) { return ~h; }
inline GrGLUniformManager::UniformHandle index_to_handle(int i) { return ~i; }
inline GrGLUniformManager::UniformHandle GrGLUniformManager::UniformHandle::CreateFromUniformIndex(int index) {
return GrGLUniformManager::UniformHandle(index);
}
#endif

View File

@ -22,11 +22,11 @@ GrGLUniformManager::UniformHandle GrGLUniformManager::appendUniform(GrSLType typ
uni.fType = type;
uni.fVSLocation = kUnusedUniform;
uni.fFSLocation = kUnusedUniform;
return index_to_handle(idx);
return GrGLUniformManager::UniformHandle::CreateFromUniformIndex(idx);
}
void GrGLUniformManager::setSampler(UniformHandle u, GrGLint texUnit) const {
const Uniform& uni = fUniforms[handle_to_index(u)];
const Uniform& uni = fUniforms[u.toUniformIndex()];
GrAssert(uni.fType == kSampler2D_GrSLType);
GrAssert(GrGLShaderVar::kNonArray == uni.fArrayCount);
// FIXME: We still insert a single sampler uniform for every stage. If the shader does not
@ -42,7 +42,7 @@ void GrGLUniformManager::setSampler(UniformHandle u, GrGLint texUnit) const {
}
void GrGLUniformManager::set1f(UniformHandle u, GrGLfloat v0) const {
const Uniform& uni = fUniforms[handle_to_index(u)];
const Uniform& uni = fUniforms[u.toUniformIndex()];
GrAssert(uni.fType == kFloat_GrSLType);
GrAssert(GrGLShaderVar::kNonArray == uni.fArrayCount);
GrAssert(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
@ -58,7 +58,7 @@ void GrGLUniformManager::set1fv(UniformHandle u,
int offset,
int arrayCount,
const GrGLfloat v[]) const {
const Uniform& uni = fUniforms[handle_to_index(u)];
const Uniform& uni = fUniforms[u.toUniformIndex()];
GrAssert(uni.fType == kFloat_GrSLType);
GrAssert(arrayCount > 0);
ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
@ -75,7 +75,7 @@ void GrGLUniformManager::set1fv(UniformHandle u,
}
void GrGLUniformManager::set2f(UniformHandle u, GrGLfloat v0, GrGLfloat v1) const {
const Uniform& uni = fUniforms[handle_to_index(u)];
const Uniform& uni = fUniforms[u.toUniformIndex()];
GrAssert(uni.fType == kVec2f_GrSLType);
GrAssert(GrGLShaderVar::kNonArray == uni.fArrayCount);
GrAssert(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
@ -91,7 +91,7 @@ void GrGLUniformManager::set2fv(UniformHandle u,
int offset,
int arrayCount,
const GrGLfloat v[]) const {
const Uniform& uni = fUniforms[handle_to_index(u)];
const Uniform& uni = fUniforms[u.toUniformIndex()];
GrAssert(uni.fType == kVec2f_GrSLType);
GrAssert(arrayCount > 0);
ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
@ -105,7 +105,7 @@ void GrGLUniformManager::set2fv(UniformHandle u,
}
void GrGLUniformManager::set3f(UniformHandle u, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2) const {
const Uniform& uni = fUniforms[handle_to_index(u)];
const Uniform& uni = fUniforms[u.toUniformIndex()];
GrAssert(uni.fType == kVec3f_GrSLType);
GrAssert(GrGLShaderVar::kNonArray == uni.fArrayCount);
GrAssert(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
@ -121,7 +121,7 @@ void GrGLUniformManager::set3fv(UniformHandle u,
int offset,
int arrayCount,
const GrGLfloat v[]) const {
const Uniform& uni = fUniforms[handle_to_index(u)];
const Uniform& uni = fUniforms[u.toUniformIndex()];
GrAssert(uni.fType == kVec3f_GrSLType);
GrAssert(arrayCount > 0);
ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
@ -139,7 +139,7 @@ void GrGLUniformManager::set4f(UniformHandle u,
GrGLfloat v1,
GrGLfloat v2,
GrGLfloat v3) const {
const Uniform& uni = fUniforms[handle_to_index(u)];
const Uniform& uni = fUniforms[u.toUniformIndex()];
GrAssert(uni.fType == kVec4f_GrSLType);
GrAssert(GrGLShaderVar::kNonArray == uni.fArrayCount);
GrAssert(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
@ -155,7 +155,7 @@ void GrGLUniformManager::set4fv(UniformHandle u,
int offset,
int arrayCount,
const GrGLfloat v[]) const {
const Uniform& uni = fUniforms[handle_to_index(u)];
const Uniform& uni = fUniforms[u.toUniformIndex()];
GrAssert(uni.fType == kVec4f_GrSLType);
GrAssert(arrayCount > 0);
GrAssert(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
@ -168,7 +168,7 @@ void GrGLUniformManager::set4fv(UniformHandle u,
}
void GrGLUniformManager::setMatrix3f(UniformHandle u, const GrGLfloat matrix[]) const {
const Uniform& uni = fUniforms[handle_to_index(u)];
const Uniform& uni = fUniforms[u.toUniformIndex()];
GrAssert(uni.fType == kMat33f_GrSLType);
GrAssert(GrGLShaderVar::kNonArray == uni.fArrayCount);
// TODO: Re-enable this assert once texture matrices aren't forced on all effects
@ -182,7 +182,7 @@ void GrGLUniformManager::setMatrix3f(UniformHandle u, const GrGLfloat matrix[])
}
void GrGLUniformManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix[]) const {
const Uniform& uni = fUniforms[handle_to_index(u)];
const Uniform& uni = fUniforms[u.toUniformIndex()];
GrAssert(uni.fType == kMat44f_GrSLType);
GrAssert(GrGLShaderVar::kNonArray == uni.fArrayCount);
GrAssert(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
@ -198,7 +198,7 @@ void GrGLUniformManager::setMatrix3fv(UniformHandle u,
int offset,
int arrayCount,
const GrGLfloat matrices[]) const {
const Uniform& uni = fUniforms[handle_to_index(u)];
const Uniform& uni = fUniforms[u.toUniformIndex()];
GrAssert(uni.fType == kMat33f_GrSLType);
GrAssert(arrayCount > 0);
ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
@ -217,7 +217,7 @@ void GrGLUniformManager::setMatrix4fv(UniformHandle u,
int offset,
int arrayCount,
const GrGLfloat matrices[]) const {
const Uniform& uni = fUniforms[handle_to_index(u)];
const Uniform& uni = fUniforms[u.toUniformIndex()];
GrAssert(uni.fType == kMat44f_GrSLType);
GrAssert(arrayCount > 0);
ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
@ -267,3 +267,8 @@ void GrGLUniformManager::getUniformLocations(GrGLuint programID, const BuilderUn
}
}
}
const GrGLUniformManager::BuilderUniform&
GrGLUniformManager::getBuilderUniform(const BuilderUniformArray& array, UniformHandle handle) const {
return array[handle.toUniformIndex()];
}

View File

@ -22,8 +22,29 @@ class SkMatrix;
class GrGLUniformManager {
public:
// Opaque handle to a uniform
typedef int UniformHandle;
static const UniformHandle kInvalidUniformHandle = 0;
class UniformHandle {
public:
static UniformHandle CreateFromUniformIndex(int i);
bool isValid() const { return 0 != fValue; }
bool operator==(const UniformHandle& other) const { return other.fValue == fValue; }
UniformHandle()
: fValue(0) {
}
private:
UniformHandle(int value)
: fValue(~value) {
GrAssert(isValid());
}
int toUniformIndex() const { GrAssert(isValid()); return ~fValue; }
int fValue;
friend class GrGLUniformManager; // For accessing toUniformIndex().
};
GrGLUniformManager(const GrGLContext& context) : fContext(context) {}
@ -65,6 +86,11 @@ public:
*/
void getUniformLocations(GrGLuint programID, const BuilderUniformArray& uniforms);
/**
* Called by the GrGLShaderBuilder to access the array by the handle (index).
*/
const BuilderUniform& getBuilderUniform(const BuilderUniformArray&, GrGLUniformManager::UniformHandle) const;
private:
enum {
kUnusedUniform = -1,

View File

@ -12,7 +12,6 @@
#include "SkTSearch.h"
typedef GrGLUniformManager::UniformHandle UniformHandle;
static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidUniformHandle;
struct GrGpuGL::ProgramCache::Entry {
SK_DECLARE_INST_COUNT_ROOT(Entry);