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/gl/GrGLProgram.cpp | 60 ++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 31 deletions(-) (limited to 'src/gpu/gl/GrGLProgram.cpp') diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index 52d53bde95..a392bc26f0 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -84,9 +84,13 @@ void GrGLProgram::setData(const GrPrimitiveProcessor& primProc, const GrPipeline int nextTexSamplerIdx = 0; fPrimitiveProcessor->setData(fProgramDataManager, primProc, GrFragmentProcessor::CoordTransformIter(pipeline)); - this->bindTextures(primProc, &nextTexSamplerIdx); + for (int i = 0; i < primProc.numTextureSamplers(); ++i) { + const GrPrimitiveProcessor::TextureSampler& sampler = primProc.textureSampler(i); + fGpu->bindTexture(nextTexSamplerIdx++, sampler.samplerState(), + static_cast(sampler.peekTexture())); + } - this->setFragmentData(primProc, pipeline, &nextTexSamplerIdx); + this->setFragmentData(pipeline, &nextTexSamplerIdx); const GrXferProcessor& xp = pipeline.getXferProcessor(); SkIPoint offset; @@ -102,31 +106,47 @@ void GrGLProgram::setData(const GrPrimitiveProcessor& primProc, const GrPipeline void GrGLProgram::generateMipmaps(const GrPrimitiveProcessor& primProc, const GrPipeline& pipeline) { - this->generateMipmaps(primProc); + auto genLevelsIfNeeded = [this](GrTexture* tex, const GrSamplerState& sampler) { + if (sampler.filter() == GrSamplerState::Filter::kMipMap && + tex->texturePriv().mipMapped() == GrMipMapped::kYes && + tex->texturePriv().mipMapsAreDirty()) { + SkASSERT(fGpu->caps()->mipMapSupport()); + fGpu->regenerateMipMapLevels(static_cast(tex)); + } + }; + + for (int i = 0; i < primProc.numTextureSamplers(); ++i) { + const auto& textureSampler = primProc.textureSampler(i); + genLevelsIfNeeded(textureSampler.peekTexture(), textureSampler.samplerState()); + } GrFragmentProcessor::Iter iter(pipeline); while (const GrFragmentProcessor* fp = iter.next()) { - this->generateMipmaps(*fp); + for (int i = 0; i < fp->numTextureSamplers(); ++i) { + const auto& textureSampler = fp->textureSampler(i); + genLevelsIfNeeded(textureSampler.peekTexture(), textureSampler.samplerState()); + } } } -void GrGLProgram::setFragmentData(const GrPrimitiveProcessor& primProc, - const GrPipeline& pipeline, - int* nextTexSamplerIdx) { +void GrGLProgram::setFragmentData(const GrPipeline& pipeline, int* nextTexSamplerIdx) { GrFragmentProcessor::Iter iter(pipeline); GrGLSLFragmentProcessor::Iter glslIter(fFragmentProcessors.get(), fFragmentProcessorCnt); const GrFragmentProcessor* fp = iter.next(); GrGLSLFragmentProcessor* glslFP = glslIter.next(); while (fp && glslFP) { glslFP->setData(fProgramDataManager, *fp); - this->bindTextures(*fp, nextTexSamplerIdx); + for (int i = 0; i < fp->numTextureSamplers(); ++i) { + const GrFragmentProcessor::TextureSampler& sampler = fp->textureSampler(i); + fGpu->bindTexture((*nextTexSamplerIdx)++, sampler.samplerState(), + static_cast(sampler.peekTexture())); + } fp = iter.next(); glslFP = glslIter.next(); } SkASSERT(!fp && !glslFP); } - void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc, const GrRenderTargetProxy* proxy) { GrRenderTarget* rt = proxy->priv().peekRenderTarget(); @@ -156,25 +176,3 @@ void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc, size, proxy->origin()); } } - -void GrGLProgram::bindTextures(const GrResourceIOProcessor& processor, - int* nextTexSamplerIdx) { - for (int i = 0; i < processor.numTextureSamplers(); ++i) { - const GrResourceIOProcessor::TextureSampler& sampler = processor.textureSampler(i); - fGpu->bindTexture((*nextTexSamplerIdx)++, sampler.samplerState(), - static_cast(sampler.peekTexture())); - } -} - -void GrGLProgram::generateMipmaps(const GrResourceIOProcessor& processor) { - for (int i = 0; i < processor.numTextureSamplers(); ++i) { - const GrResourceIOProcessor::TextureSampler& sampler = processor.textureSampler(i); - auto* tex = sampler.peekTexture(); - if (sampler.samplerState().filter() == GrSamplerState::Filter::kMipMap && - tex->texturePriv().mipMapped() == GrMipMapped::kYes && - tex->texturePriv().mipMapsAreDirty()) { - SkASSERT(fGpu->caps()->mipMapSupport()); - fGpu->regenerateMipMapLevels(static_cast(sampler.peekTexture())); - } - } -} -- cgit v1.2.3