Chromium Code Reviews| Index: src/gpu/gl/GrGLProgram.cpp |
| diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp |
| index e0d4939323b0f2438944fcaad78712d7b6120d63..fdeab891f20308f2b08523ee59d4d81076c05996 100644 |
| --- a/src/gpu/gl/GrGLProgram.cpp |
| +++ b/src/gpu/gl/GrGLProgram.cpp |
| @@ -10,6 +10,7 @@ |
| #include "GrAllocator.h" |
| #include "GrProcessor.h" |
| #include "GrCoordTransform.h" |
| +#include "GrGLGeometryProcessor.h" |
| #include "GrGLProcessor.h" |
| #include "GrGpuGL.h" |
| #include "GrGLPathRendering.h" |
| @@ -24,7 +25,7 @@ |
| /** |
| * Retrieves the final matrix that a transform needs to apply to its source coords. |
| */ |
| -static SkMatrix get_transform_matrix(const GrProcessorStage& processorStage, |
| +static SkMatrix get_transform_matrix(const GrFragmentStage& processorStage, |
| bool useExplicitLocalCoords, |
| int transformIdx) { |
| const GrCoordTransform& coordTransform = |
| @@ -59,17 +60,15 @@ GrGLProgram::GrGLProgram(GrGpuGL* gpu, |
| const BuiltinUniformHandles& builtinUniforms, |
| GrGLuint programID, |
| const UniformInfoArray& uniforms, |
| - GrGLInstalledProcessors* geometryProcessor, |
| - GrGLInstalledProcessors* colorProcessors, |
| - GrGLInstalledProcessors* coverageProcessors) |
| + GrGLInstalledGeoProc* geometryProcessor, |
| + GrGLInstalledFragProcs* fragmentProcessors) |
| : fColor(GrColor_ILLEGAL) |
| , fCoverage(GrColor_ILLEGAL) |
| , fDstCopyTexUnit(-1) |
| , fBuiltinUniformHandles(builtinUniforms) |
| , fProgramID(programID) |
| - , fGeometryProcessor(SkSafeRef(geometryProcessor)) |
| - , fColorEffects(SkRef(colorProcessors)) |
| - , fCoverageEffects(SkRef(coverageProcessors)) |
| + , fGeometryProcessor(geometryProcessor) |
| + , fFragmentProcessors(SkRef(fragmentProcessors)) |
| , fDesc(desc) |
| , fGpu(gpu) |
| , fProgramDataManager(gpu, uniforms) { |
| @@ -96,28 +95,24 @@ void GrGLProgram::initSamplerUniforms() { |
| if (fGeometryProcessor.get()) { |
| this->initSamplers(fGeometryProcessor.get(), &texUnitIdx); |
| } |
| - this->initSamplers(fColorEffects.get(), &texUnitIdx); |
| - this->initSamplers(fCoverageEffects.get(), &texUnitIdx); |
| + int numProcs = fFragmentProcessors->fProcs.count(); |
| + for (int i = 0; i < numProcs; i++) { |
| + this->initSamplers(fFragmentProcessors->fProcs[i], &texUnitIdx); |
| + } |
| } |
| -void GrGLProgram::initSamplers(GrGLInstalledProcessors* ip, int* texUnitIdx) { |
| - int numEffects = ip->fGLProcessors.count(); |
| - SkASSERT(numEffects == ip->fSamplers.count()); |
| - for (int e = 0; e < numEffects; ++e) { |
| - SkTArray<GrGLInstalledProcessors::Sampler, true>& samplers = ip->fSamplers[e]; |
| - int numSamplers = samplers.count(); |
| - for (int s = 0; s < numSamplers; ++s) { |
| - SkASSERT(samplers[s].fUniform.isValid()); |
| - fProgramDataManager.setSampler(samplers[s].fUniform, *texUnitIdx); |
| - samplers[s].fTextureUnit = (*texUnitIdx)++; |
| - } |
| +void GrGLProgram::initSamplers(GrGLInstalledProc* ip, int* texUnitIdx) { |
| + SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers; |
| + int numSamplers = samplers.count(); |
| + for (int s = 0; s < numSamplers; ++s) { |
| + SkASSERT(samplers[s].fUniform.isValid()); |
| + fProgramDataManager.setSampler(samplers[s].fUniform, *texUnitIdx); |
| + samplers[s].fTextureUnit = (*texUnitIdx)++; |
| } |
| } |
| -void GrGLProgram::bindTextures(const GrGLInstalledProcessors* ip, |
| - const GrProcessor& processor, |
| - int effectIdx) { |
| - const SkTArray<GrGLInstalledProcessors::Sampler, true>& samplers = ip->fSamplers[effectIdx]; |
| +void GrGLProgram::bindTextures(const GrGLInstalledProc* ip, const GrProcessor& processor) { |
| + const SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers; |
| int numSamplers = samplers.count(); |
| SkASSERT(numSamplers == processor.numTextures()); |
| for (int s = 0; s < numSamplers; ++s) { |
| @@ -134,9 +129,6 @@ void GrGLProgram::bindTextures(const GrGLInstalledProcessors* ip, |
| void GrGLProgram::setData(const GrOptDrawState& optState, |
| GrGpu::DrawType drawType, |
| - const GrGeometryStage* geometryProcessor, |
| - const GrFragmentStage* colorStages[], |
| - const GrFragmentStage* coverageStages[], |
| const GrDeviceCoordTexture* dstCopy, |
| SharedGLState* sharedState) { |
| GrColor color = optState.getColor(); |
| @@ -170,25 +162,34 @@ void GrGLProgram::setData(const GrOptDrawState& optState, |
| // we set the textures, and uniforms for installed processors in a generic way, but subclasses |
| // of GLProgram determine how to set coord transforms |
| if (fGeometryProcessor.get()) { |
| - SkASSERT(geometryProcessor); |
| - this->setData<GrGeometryStage>(&geometryProcessor, fGeometryProcessor.get()); |
| + SkASSERT(optState.hasGeometryProcessor()); |
| + const GrGeometryProcessor& gp = *optState.getGeometryProcessor(); |
| + fGeometryProcessor->fGLProc->setData(fProgramDataManager, gp); |
| + this->bindTextures(fGeometryProcessor, gp); |
| } |
| - this->setData<GrFragmentStage>(colorStages, fColorEffects.get()); |
| - this->setData<GrFragmentStage>(coverageStages, fCoverageEffects.get()); |
| + this->setFragmentData(optState); |
| // Some of GrGLProgram subclasses need to update state here |
| this->didSetData(drawType); |
| } |
| -void GrGLProgram::setTransformData(const GrProcessorStage& processor, |
| - int effectIdx, |
| - GrGLInstalledProcessors* ip) { |
| - SkTArray<GrGLInstalledProcessors::Transform, true>& transforms = ip->fTransforms[effectIdx]; |
| +void GrGLProgram::setFragmentData(const GrOptDrawState& optState) { |
| + int numEffects = fFragmentProcessors->fProcs.count(); |
|
bsalomon
2014/10/10 15:25:49
numProcessors?
|
| + for (int e = 0; e < numEffects; ++e) { |
| + const GrFragmentStage& stage = optState.getFragmentStage(e); |
| + const GrProcessor& effect = *stage.getProcessor(); |
|
bsalomon
2014/10/10 15:25:49
processor?
|
| + fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, effect); |
| + this->setTransformData(stage, fFragmentProcessors->fProcs[e]); |
| + this->bindTextures(fFragmentProcessors->fProcs[e], effect); |
| + } |
| +} |
| +void GrGLProgram::setTransformData(const GrFragmentStage& processor, GrGLInstalledFragProc* ip) { |
| + SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms; |
| int numTransforms = transforms.count(); |
| SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); |
| for (int t = 0; t < numTransforms; ++t) { |
| SkASSERT(transforms[t].fHandle.isValid()); |
| - const SkMatrix& matrix = get_transform_matrix(processor, ip->fHasExplicitLocalCoords, t); |
| + const SkMatrix& matrix = get_transform_matrix(processor, ip->fUseLocalCoords, t); |
|
bsalomon
2014/10/10 15:25:49
We always have local coords of some kind. Usually
|
| if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { |
| fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUniformHandle(), matrix); |
| transforms[t].fCurrentValue = matrix; |
| @@ -321,10 +322,8 @@ GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu, |
| const BuiltinUniformHandles& builtinUniforms, |
| GrGLuint programID, |
| const UniformInfoArray& uniforms, |
| - GrGLInstalledProcessors* colorProcessors, |
| - GrGLInstalledProcessors* coverageProcessors) |
| - : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, colorProcessors, |
| - coverageProcessors) { |
| + GrGLInstalledFragProcs* fragmentProcessors) |
| + : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, fragmentProcessors) { |
| } |
| void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, |
| @@ -343,11 +342,9 @@ GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu, |
| const BuiltinUniformHandles& builtinUniforms, |
| GrGLuint programID, |
| const UniformInfoArray& uniforms, |
| - GrGLInstalledProcessors* colorProcessors, |
| - GrGLInstalledProcessors* coverageProcessors, |
| + GrGLInstalledFragProcs* fragmentProcessors, |
| const SeparableVaryingInfoArray& separableVaryings) |
| - : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, colorProcessors, |
| - coverageProcessors) { |
| + : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fragmentProcessors) { |
| int count = separableVaryings.count(); |
| fVaryings.push_back_n(count); |
| for (int i = 0; i < count; i++) { |
| @@ -365,15 +362,13 @@ void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) { |
| SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
| } |
| -void GrGLNvprProgram::setTransformData(const GrProcessorStage& processor, |
| - int effectIdx, |
| - GrGLInstalledProcessors* ip) { |
| - SkTArray<GrGLInstalledProcessors::Transform, true>& transforms = ip->fTransforms[effectIdx]; |
| +void GrGLNvprProgram::setTransformData(const GrFragmentStage& proc, GrGLInstalledFragProc* ip) { |
| + SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms; |
| int numTransforms = transforms.count(); |
| - SkASSERT(numTransforms == processor.getProcessor()->numTransforms()); |
| + SkASSERT(numTransforms == proc.getProcessor()->numTransforms()); |
| for (int t = 0; t < numTransforms; ++t) { |
| SkASSERT(transforms[t].fHandle.isValid()); |
| - const SkMatrix& transform = get_transform_matrix(processor, ip->fHasExplicitLocalCoords, t); |
| + const SkMatrix& transform = get_transform_matrix(proc, ip->fUseLocalCoords, t); |
| if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { |
| continue; |
| } |
| @@ -392,15 +387,13 @@ void GrGLNvprProgram::setTransformData(const GrProcessorStage& processor, |
| ////////////////////////////////////////////////////////////////////////////////////// |
| GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu, |
| - const GrGLProgramDesc& desc, |
| - const BuiltinUniformHandles& builtinUniforms, |
| - GrGLuint programID, |
| - const UniformInfoArray& uniforms, |
| - GrGLInstalledProcessors* colorProcessors, |
| - GrGLInstalledProcessors* coverageProcessors, |
| - int texCoordSetCnt) |
| - : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, colorProcessors, |
| - coverageProcessors) |
| + const GrGLProgramDesc& desc, |
| + const BuiltinUniformHandles& builtinUniforms, |
| + GrGLuint programID, |
| + const UniformInfoArray& uniforms, |
| + GrGLInstalledFragProcs* fps, |
| + int texCoordSetCnt) |
| + : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fps) |
| , fTexCoordSetCnt(texCoordSetCnt) { |
| } |
| @@ -409,17 +402,16 @@ void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { |
| fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); |
| } |
| -void GrGLLegacyNvprProgram::setTransformData(const GrProcessorStage& processorStage, |
| - int effectIdx, |
| - GrGLInstalledProcessors* ip) { |
| +void |
| +GrGLLegacyNvprProgram::setTransformData(const GrFragmentStage& proc, GrGLInstalledFragProc* ip) { |
| // We've hidden the texcoord index in the first entry of the transforms array for each effect |
| - int texCoordIndex = ip->fTransforms[effectIdx][0].fHandle.handle(); |
| - int numTransforms = processorStage.getProcessor()->numTransforms(); |
| + int texCoordIndex = ip->fTransforms[0].fHandle.handle(); |
| + int numTransforms = proc.getProcessor()->numTransforms(); |
| for (int t = 0; t < numTransforms; ++t) { |
| - const SkMatrix& transform = get_transform_matrix(processorStage, false, t); |
| + const SkMatrix& transform = get_transform_matrix(proc, false, t); |
| GrGLPathRendering::PathTexGenComponents components = |
| GrGLPathRendering::kST_PathTexGenComponents; |
| - if (processorStage.isPerspectiveCoordTransform(t, false)) { |
| + if (proc.isPerspectiveCoordTransform(t, false)) { |
| components = GrGLPathRendering::kSTR_PathTexGenComponents; |
| } |
| fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, transform); |