diff options
Diffstat (limited to 'src')
21 files changed, 76 insertions, 105 deletions
diff --git a/src/effects/SkBicubicImageFilter.cpp b/src/effects/SkBicubicImageFilter.cpp index db8dbfd028..26d4b2eda7 100644 --- a/src/effects/SkBicubicImageFilter.cpp +++ b/src/effects/SkBicubicImageFilter.cpp @@ -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()) { } diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp index 3d1fd6f627..7bb9673d10 100644 --- a/src/effects/SkColorMatrixFilter.cpp +++ b/src/effects/SkColorMatrixFilter.cpp @@ -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&, diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp index 7a74f73624..ccb1dc5127 100644 --- a/src/effects/SkLightingImageFilter.cpp +++ b/src/effects/SkLightingImageFilter.cpp @@ -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) { diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp index f7fbda2014..a747620484 100644 --- a/src/effects/SkMagnifierImageFilter.cpp +++ b/src/effects/SkMagnifierImageFilter.cpp @@ -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()) { } diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp index bedd6f8bbc..1f60a492b2 100644 --- a/src/effects/SkMatrixConvolutionImageFilter.cpp +++ b/src/effects/SkMatrixConvolutionImageFilter.cpp @@ -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(); diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index 94a6327307..33dd2e6ce8 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -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(); diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index 4e528b5ba8..2c554dc376 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -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) { } diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp index 664ec914be..ee6e25a88e 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient.cpp +++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp @@ -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) diff --git a/src/effects/gradients/SkTwoPointRadialGradient.cpp b/src/effects/gradients/SkTwoPointRadialGradient.cpp index 3d526a6c1c..46724cb45b 100644 --- a/src/effects/gradients/SkTwoPointRadialGradient.cpp +++ b/src/effects/gradients/SkTwoPointRadialGradient.cpp @@ -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) diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp index e7fb8e5403..65da81111b 100644 --- a/src/gpu/effects/GrConvolutionEffect.cpp +++ b/src/gpu/effects/GrConvolutionEffect.cpp @@ -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(); diff --git a/src/gpu/effects/GrTextureDomainEffect.cpp b/src/gpu/effects/GrTextureDomainEffect.cpp index eb4001d949..80fa770da4 100644 --- a/src/gpu/effects/GrTextureDomainEffect.cpp +++ b/src/gpu/effects/GrTextureDomainEffect.cpp @@ -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; } diff --git a/src/gpu/gl/GrGLEffectMatrix.cpp b/src/gpu/gl/GrGLEffectMatrix.cpp index 523b37e72e..437e6832c0 100644 --- a/src/gpu/gl/GrGLEffectMatrix.cpp +++ b/src/gpu/gl/GrGLEffectMatrix.cpp @@ -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(); diff --git a/src/gpu/gl/GrGLEffectMatrix.h b/src/gpu/gl/GrGLEffectMatrix.h index fc4b783133..9c05c573b1 100644 --- a/src/gpu/gl/GrGLEffectMatrix.h +++ b/src/gpu/gl/GrGLEffectMatrix.h @@ -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(); diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index 8a24d60c14..300e7a7722 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -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)); } diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h index 3534552f98..279890f5d4 100644 --- a/src/gpu/gl/GrGLProgram.h +++ b/src/gpu/gl/GrGLProgram.h @@ -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; diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp index 36eb6d5169..5ed8f0da09 100644 --- a/src/gpu/gl/GrGLShaderBuilder.cpp +++ b/src/gpu/gl/GrGLShaderBuilder.cpp @@ -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; } } diff --git a/src/gpu/gl/GrGLShaderBuilder.h b/src/gpu/gl/GrGLShaderBuilder.h index b67846a621..e56f459ee4 100644 --- a/src/gpu/gl/GrGLShaderBuilder.h +++ b/src/gpu/gl/GrGLShaderBuilder.h @@ -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() diff --git a/src/gpu/gl/GrGLUniformHandle.h b/src/gpu/gl/GrGLUniformHandle.h index 231dd31c20..797afff4e0 100644 --- a/src/gpu/gl/GrGLUniformHandle.h +++ b/src/gpu/gl/GrGLUniformHandle.h @@ -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 diff --git a/src/gpu/gl/GrGLUniformManager.cpp b/src/gpu/gl/GrGLUniformManager.cpp index da6726bb24..b559e10d17 100644 --- a/src/gpu/gl/GrGLUniformManager.cpp +++ b/src/gpu/gl/GrGLUniformManager.cpp @@ -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()]; +} diff --git a/src/gpu/gl/GrGLUniformManager.h b/src/gpu/gl/GrGLUniformManager.h index ee693a6a5b..863d66facd 100644 --- a/src/gpu/gl/GrGLUniformManager.h +++ b/src/gpu/gl/GrGLUniformManager.h @@ -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, diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp index 786640c467..20967c6331 100644 --- a/src/gpu/gl/GrGpuGL_program.cpp +++ b/src/gpu/gl/GrGpuGL_program.cpp @@ -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); |