| Index: src/gpu/gl/GrGLShaderBuilder.cpp
|
| diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp
|
| index 36eb6d5169ebd23a3eb7104f801ab8bb102ac9c9..5556baf9bdf4cdab92550e48e97b2f400cb4c0f3 100644
|
| --- a/src/gpu/gl/GrGLShaderBuilder.cpp
|
| +++ b/src/gpu/gl/GrGLShaderBuilder.cpp
|
| @@ -7,7 +7,6 @@
|
|
|
| #include "gl/GrGLShaderBuilder.h"
|
| #include "gl/GrGLProgram.h"
|
| -#include "gl/GrGLUniformHandle.h"
|
| #include "GrDrawEffect.h"
|
| #include "GrTexture.h"
|
|
|
| @@ -20,7 +19,6 @@ static const int kMaxFSOutputs = 2;
|
| // ES2 FS only guarantees mediump and lowp support
|
| static const GrGLShaderVar::Precision kDefaultFragmentPrecision = GrGLShaderVar::kMedium_Precision;
|
|
|
| -typedef GrGLUniformManager::UniformHandle UniformHandle;
|
| ///////////////////////////////////////////////////////////////////////////////
|
|
|
| namespace {
|
| @@ -92,7 +90,7 @@ static const char kDstCopyColorName[] = "_dstColor";
|
| ///////////////////////////////////////////////////////////////////////////////
|
|
|
| GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
|
| - GrGLUniformManager& uniformManager,
|
| + GrGLProgram& program,
|
| const GrGLProgramDesc& desc)
|
| : fUniforms(kVarsPerBlock)
|
| , fVSAttrs(kVarsPerBlock)
|
| @@ -102,7 +100,7 @@ GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
|
| , fFSInputs(kVarsPerBlock)
|
| , fFSOutputs(kMaxFSOutputs)
|
| , fCtxInfo(ctxInfo)
|
| - , fUniformManager(uniformManager)
|
| + , fProgram(program)
|
| , fFSFeaturesAddedMask(0)
|
| #if GR_GL_EXPERIMENTAL_GS
|
| , fUsesGS(SkToBool(desc.getHeader().fExperimentalGS))
|
| @@ -110,9 +108,9 @@ GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
|
| , fUsesGS(false)
|
| #endif
|
| , fSetupFragPosition(false)
|
| - , fRTHeightUniform(GrGLUniformManager::kInvalidUniformHandle)
|
| - , fDstCopyTopLeftUniform (GrGLUniformManager::kInvalidUniformHandle)
|
| - , fDstCopyScaleUniform (GrGLUniformManager::kInvalidUniformHandle)
|
| + , fRTHeightUniform(NULL)
|
| + , fDstCopyTopLeftUniform(NULL)
|
| + , fDstCopyScaleUniform(NULL)
|
| , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFragPosKey) {
|
|
|
| const GrGLProgramDesc::KeyHeader& header = desc.getHeader();
|
| @@ -144,11 +142,11 @@ GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
|
| fDstCopyTopLeftUniform = this->addUniform(kFragment_ShaderType,
|
| kVec2f_GrSLType,
|
| "DstCopyUpperLeft",
|
| - &dstCopyTopLeftName);
|
| + &dstCopyTopLeftName)->glUniform();
|
| fDstCopyScaleUniform = this->addUniform(kFragment_ShaderType,
|
| kVec2f_GrSLType,
|
| "DstCopyCoordScale",
|
| - &dstCopyCoordScaleName);
|
| + &dstCopyCoordScaleName)->glUniform();
|
| const char* fragPos = this->fragmentPosition();
|
| this->fsCodeAppend("\t// Read color from copy of the destination.\n");
|
| this->fsCodeAppendf("\tvec2 _dstTexCoord = (%s.xy - %s) * %s;\n",
|
| @@ -300,7 +298,7 @@ void GrGLShaderBuilder::appendTextureLookup(SkString* out,
|
|
|
| out->appendf("%s(%s, %s)",
|
| sample_function_name(varyingType, fCtxInfo.glslGeneration()),
|
| - this->getUniformCStr(sampler.fSamplerUniform),
|
| + sampler.fSamplerUniform->c_str(),
|
| coordName);
|
| append_swizzle(out, sampler, *fCtxInfo.caps());
|
| }
|
| @@ -380,23 +378,20 @@ const GrGLenum* GrGLShaderBuilder::GetTexParamSwizzle(GrPixelConfig config, cons
|
| }
|
| }
|
|
|
| -GrGLUniformManager::UniformHandle GrGLShaderBuilder::addUniformArray(uint32_t visibility,
|
| - GrSLType type,
|
| - const char* name,
|
| - int count,
|
| - const char** outName) {
|
| +GrGLShaderBuilder::Uniform* GrGLShaderBuilder::addUniformArray(uint32_t visibility,
|
| + GrSLType type,
|
| + const char* name,
|
| + int count,
|
| + const char** outName) {
|
| GrAssert(name && strlen(name));
|
| SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_ShaderType | kFragment_ShaderType);
|
| GrAssert(0 == (~kVisibilityMask & visibility));
|
| GrAssert(0 != visibility);
|
|
|
| - BuilderUniform& uni = fUniforms.push_back();
|
| - UniformHandle h = index_to_handle(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
|
| - // by this function. Therefore, the handles should match.
|
| - GrAssert(h2 == h);
|
| + Uniform& uni = fUniforms.push_back();
|
| + uni.fGLUniform = fProgram.appendUniform();
|
| + GR_DEBUGCODE(uni.fGLUniform->initType(count, type));
|
| +
|
| uni.fVariable.setType(type);
|
| uni.fVariable.setTypeModifier(GrGLShaderVar::kUniform_TypeModifier);
|
| this->nameVariable(uni.fVariable.accessName(), 'u', name);
|
| @@ -415,11 +410,7 @@ GrGLUniformManager::UniformHandle GrGLShaderBuilder::addUniformArray(uint32_t vi
|
| *outName = uni.fVariable.c_str();
|
| }
|
|
|
| - return h;
|
| -}
|
| -
|
| -const GrGLShaderVar& GrGLShaderBuilder::getUniformVariable(UniformHandle u) const {
|
| - return fUniforms[handle_to_index(u)].fVariable;
|
| + return &uni;
|
| }
|
|
|
| bool GrGLShaderBuilder::addAttribute(GrSLType type,
|
| @@ -512,19 +503,19 @@ 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(NULL == fRTHeightUniform);
|
| const char* rtHeightName;
|
|
|
| fRTHeightUniform = this->addUniform(kFragment_ShaderType,
|
| kFloat_GrSLType,
|
| "RTHeight",
|
| - &rtHeightName);
|
| + &rtHeightName)->glUniform();
|
|
|
| this->fFSCode.prependf("\tvec4 %s = vec4(gl_FragCoord.x, %s - gl_FragCoord.y, gl_FragCoord.zw);\n",
|
| kCoordName, rtHeightName);
|
| fSetupFragPosition = true;
|
| }
|
| - GrAssert(GrGLUniformManager::kInvalidUniformHandle != fRTHeightUniform);
|
| + GrAssert(NULL != fRTHeightUniform);
|
| return kCoordName;
|
| }
|
| }
|
| @@ -640,8 +631,11 @@ void GrGLShaderBuilder::getShader(ShaderType type, SkString* shaderStr) const {
|
| }
|
| }
|
|
|
| -void GrGLShaderBuilder::finished(GrGLuint programID) {
|
| - fUniformManager.getUniformLocations(programID, fUniforms);
|
| +void GrGLShaderBuilder::finished(const GrGLContext& context, GrGLuint programID) {
|
| + int count = fUniforms.count();
|
| + for (int i = 0; i < count; ++i) {
|
| + fUniforms[i].glUniform()->initLocations(context, programID, fUniforms[i].c_str(), fUniforms[i].fVisibility);
|
| + }
|
| }
|
|
|
| void GrGLShaderBuilder::emitEffects(
|
| @@ -650,7 +644,7 @@ void GrGLShaderBuilder::emitEffects(
|
| int effectCnt,
|
| SkString* fsInOutColor,
|
| GrSLConstantVec* fsInOutColorKnownValue,
|
| - SkTArray<GrGLUniformManager::UniformHandle, true>* effectSamplerHandles[],
|
| + SkTArray<GrGLUniform*, true>* effectSamplerHandles[],
|
| GrGLEffect* glEffects[]) {
|
| bool effectEmitted = false;
|
|
|
| @@ -669,7 +663,7 @@ void GrGLShaderBuilder::emitEffects(
|
| textureSamplers.push_back_n(numTextures);
|
| for (int t = 0; t < numTextures; ++t) {
|
| textureSamplers[t].init(this, &effect->textureAccess(t), t);
|
| - effectSamplerHandles[e]->push_back(textureSamplers[t].fSamplerUniform);
|
| + effectSamplerHandles[e]->push_back(textureSamplers[t].fSamplerUniform->glUniform());
|
| }
|
| GrDrawEffect drawEffect(stage, this->hasExplicitLocalCoords());
|
|
|
| @@ -734,3 +728,5 @@ const SkString* GrGLShaderBuilder::getEffectAttributeName(int attributeIndex) co
|
|
|
| return NULL;
|
| }
|
| +
|
| +
|
|
|