From e782f8472f61a5a553c57fef788ad4405844887b Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Tue, 31 Jul 2018 13:53:11 -0400 Subject: Remove GrResourceIOProcessor. Fold its functionality into GrPrimitiveProcessor and GrFragmentProcessor. Make each have its own TextureSampler nested class. Currently the only difference is that fragment processors lose the ability to inject their samplers into the vertex shader. However, this facilitates refactoring GrPrimitiveProcessor's TextureSampler class such that the textures are specified separately from the TextureSampler. Bug: skia: Change-Id: I1e590187e7a6ae79ee3147155d397fcdcf5e4619 Reviewed-on: https://skia-review.googlesource.com/142814 Commit-Queue: Brian Salomon Reviewed-by: Robert Phillips --- src/gpu/glsl/GrGLSLProgramBuilder.cpp | 45 ++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'src/gpu/glsl/GrGLSLProgramBuilder.cpp') diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp index 05b78eef0c..b0cf8169d4 100644 --- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp +++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp @@ -96,8 +96,15 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr SkASSERT(!fGeometryProcessor); fGeometryProcessor.reset(proc.createGLSLInstance(*this->shaderCaps())); - SkSTArray<4, SamplerHandle> texSamplers(proc.numTextureSamplers()); - this->emitSamplers(proc, &texSamplers); + SkAutoSTMalloc<4, SamplerHandle> texSamplers(proc.numTextureSamplers()); + for (int i = 0; i < proc.numTextureSamplers(); ++i) { + SkString name; + name.printf("TextureSampler_%d", i); + const auto& sampler = proc.textureSampler(i); + GrTextureType textureType = sampler.peekTexture()->texturePriv().textureType(); + texSamplers[i] = this->emitSampler(textureType, sampler.peekTexture()->config(), + name.c_str(), sampler.visibility()); + } GrGLSLPrimitiveProcessor::FPCoordTransformHandler transformHandler(fPipeline, &fTransformedCoordVars); @@ -111,7 +118,7 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr outputColor->c_str(), outputCoverage->c_str(), rtAdjustName, - texSamplers.begin(), + texSamplers.get(), &transformHandler); fGeometryProcessor->emitCode(args); @@ -168,15 +175,23 @@ SkString GrGLSLProgramBuilder::emitAndInstallFragProc( GrGLSLFragmentProcessor* fragProc = fp.createGLSLInstance(); - SkSTArray<4, SamplerHandle> textureSamplerArray(fp.numTextureSamplers()); - GrFragmentProcessor::Iter iter(&fp); - while (const GrFragmentProcessor* subFP = iter.next()) { - this->emitSamplers(*subFP, &textureSamplerArray); + SkSTArray<4, SamplerHandle> texSamplers; + GrFragmentProcessor::Iter fpIter(&fp); + int samplerIdx = 0; + while (const auto* subFP = fpIter.next()) { + for (int i = 0; i < subFP->numTextureSamplers(); ++i) { + SkString name; + name.printf("TextureSampler_%d", samplerIdx++); + const auto& sampler = subFP->textureSampler(i); + GrTextureType textureType = sampler.peekTexture()->texturePriv().textureType(); + texSamplers.emplace_back(this->emitSampler(textureType, sampler.peekTexture()->config(), + name.c_str(), kFragment_GrShaderFlag)); + } } const GrShaderVar* coordVars = fTransformedCoordVars.begin() + transformedCoordVarsIdx; GrGLSLFragmentProcessor::TransformedCoordVars coords(&fp, coordVars); - GrGLSLFragmentProcessor::TextureSamplers textureSamplers(&fp, textureSamplerArray.begin()); + GrGLSLFragmentProcessor::TextureSamplers textureSamplers(&fp, texSamplers.begin()); GrGLSLFragmentProcessor::EmitArgs args(&fFS, this->uniformHandler(), this->shaderCaps(), @@ -250,20 +265,6 @@ void GrGLSLProgramBuilder::emitAndInstallXferProc(const SkString& colorIn, fFS.codeAppend("}"); } -void GrGLSLProgramBuilder::emitSamplers( - const GrResourceIOProcessor& processor, - SkTArray* outTexSamplerHandles) { - SkString name; - int numTextureSamplers = processor.numTextureSamplers(); - for (int t = 0; t < numTextureSamplers; ++t) { - const GrResourceIOProcessor::TextureSampler& sampler = processor.textureSampler(t); - name.printf("TextureSampler_%d", outTexSamplerHandles->count()); - GrTextureType textureType = sampler.peekTexture()->texturePriv().textureType(); - outTexSamplerHandles->emplace_back(this->emitSampler( - textureType, sampler.peekTexture()->config(), name.c_str(), sampler.visibility())); - } -} - void GrGLSLProgramBuilder::updateSamplerCounts(GrShaderFlags visibility) { if (visibility & kVertex_GrShaderFlag) { ++fNumVertexSamplers; -- cgit v1.2.3