diff options
author | 2012-07-30 13:09:05 +0000 | |
---|---|---|
committer | 2012-07-30 13:09:05 +0000 | |
commit | cddaf340f1474cc1ff429b8ef9bc8739c72f80ba (patch) | |
tree | 56a71479f93fa814e6c14a3c6d2ce35eac49afcd /src/gpu/gl | |
parent | 79a1c34ee45a3eb5edd568fd97626dff1b64a0db (diff) |
Remove GrDrawState::setTexture/getTexture
Review URL: http://codereview.appspot.com/6455051/
git-svn-id: http://skia.googlecode.com/svn/trunk@4826 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/gl')
-rw-r--r-- | src/gpu/gl/GrGLProgram.cpp | 6 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.h | 6 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.cpp | 5 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.h | 4 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL_program.cpp | 156 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL_unittest.cpp | 11 |
6 files changed, 84 insertions, 104 deletions
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index 90ef27ae0b..ec68eae5b4 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -67,7 +67,7 @@ inline const char* dual_source_output_name() { return "dualSourceOut"; } GrGLProgram* GrGLProgram::Create(const GrGLContextInfo& gl, const Desc& desc, - GrCustomStage** customStages) { + const GrCustomStage** customStages) { GrGLProgram* program = SkNEW_ARGS(GrGLProgram, (gl, desc, customStages)); if (!program->succeeded()) { delete program; @@ -78,7 +78,7 @@ GrGLProgram* GrGLProgram::Create(const GrGLContextInfo& gl, GrGLProgram::GrGLProgram(const GrGLContextInfo& gl, const Desc& desc, - GrCustomStage** customStages) + const GrCustomStage** customStages) : fContextInfo(gl) , fUniformManager(gl) { fDesc = desc; @@ -566,7 +566,7 @@ bool GrGLProgram::compileShaders(const GrGLShaderBuilder& builder) { return true; } -bool GrGLProgram::genProgram(GrCustomStage** customStages) { +bool GrGLProgram::genProgram(const GrCustomStage** customStages) { GrAssert(0 == fProgramID); GrGLShaderBuilder builder(fContextInfo, fUniformManager); diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h index 02cb6ef55a..b6c224cfeb 100644 --- a/src/gpu/gl/GrGLProgram.h +++ b/src/gpu/gl/GrGLProgram.h @@ -43,7 +43,7 @@ public: static GrGLProgram* Create(const GrGLContextInfo& gl, const Desc& desc, - GrCustomStage** customStages); + const GrCustomStage** customStages); virtual ~GrGLProgram(); @@ -235,14 +235,14 @@ public: private: GrGLProgram(const GrGLContextInfo& gl, const Desc& desc, - GrCustomStage** customStages); + const GrCustomStage** customStages); bool succeeded() const { return 0 != fProgramID; } /** * This is the heavy initilization routine for building a GLProgram. */ - bool genProgram(GrCustomStage** customStages); + bool genProgram(const GrCustomStage** customStages); void genInputColor(GrGLShaderBuilder* builder, SkString* inColor); diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp index 79ea706cca..68f7a9a689 100644 --- a/src/gpu/gl/GrGpuGL.cpp +++ b/src/gpu/gl/GrGpuGL.cpp @@ -2135,8 +2135,9 @@ const GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { void GrGpuGL::flushBoundTextureAndParams(int stage) { GrDrawState* drawState = this->drawState(); - - GrGLTexture* nextTexture = static_cast<GrGLTexture*>(drawState->getTexture(stage)); + // FIXME: Assuming one texture maximum per custom stage + const GrCustomStage* customStage = drawState->sampler(stage)->getCustomStage(); + GrGLTexture* nextTexture = static_cast<GrGLTexture*>(customStage->texture(0)); // Currently we always use the texture params from the GrSamplerState. Soon custom stages // will provide their own params. const GrTextureParams& texParams = drawState->getSampler(stage).getTextureParams(); diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h index 2e338a1e0c..ae19b2ef13 100644 --- a/src/gpu/gl/GrGpuGL.h +++ b/src/gpu/gl/GrGpuGL.h @@ -170,7 +170,7 @@ private: ProgramCache(const GrGLContextInfo& gl); void abandon(); - GrGLProgram* getProgram(const GrGLProgram::Desc& desc, GrCustomStage** stages); + GrGLProgram* getProgram(const GrGLProgram::Desc& desc, const GrCustomStage** stages); private: enum { kKeySize = sizeof(ProgramDesc), @@ -252,7 +252,7 @@ private: void buildProgram(bool isPoints, BlendOptFlags blendOpts, GrBlendCoeff dstCoeff, - GrCustomStage** customStages, + const GrCustomStage** customStages, ProgramDesc* desc); // Inits GrDrawTarget::Caps, sublcass may enable additional caps. diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp index d87467280b..b492fd4679 100644 --- a/src/gpu/gl/GrGpuGL_program.cpp +++ b/src/gpu/gl/GrGpuGL_program.cpp @@ -32,7 +32,8 @@ void GrGpuGL::ProgramCache::abandon() { fCount = 0; } -GrGLProgram* GrGpuGL::ProgramCache::getProgram(const ProgramDesc& desc, GrCustomStage** stages) { +GrGLProgram* GrGpuGL::ProgramCache::getProgram(const ProgramDesc& desc, + const GrCustomStage** stages) { Entry newEntry; newEntry.fKey.setKeyData(desc.asKey()); @@ -195,8 +196,10 @@ bool GrGpuGL::TextureMatrixIsIdentity(const GrGLTexture* texture, void GrGpuGL::flushTextureMatrix(int s) { const GrDrawState& drawState = this->getDrawState(); - const GrGLTexture* texture = - static_cast<const GrGLTexture*>(drawState.getTexture(s)); + + // FIXME: Still assuming only a single texture per custom stage + const GrCustomStage* stage = drawState.getSampler(s).getCustomStage(); + const GrGLTexture* texture = static_cast<const GrGLTexture*>(stage->texture(0)); if (NULL != texture) { bool orientationChange = fCurrentProgram->fTextureOrientation[s] != @@ -370,7 +373,7 @@ bool GrGpuGL::flushGraphicsState(DrawType type) { return false; } - GrCustomStage* customStages [GrDrawState::kNumStages]; + const GrCustomStage* customStages [GrDrawState::kNumStages]; GrGLProgram::Desc desc; this->buildProgram(kDrawPoints_DrawType == type, blendOpts, dstCoeff, customStages, &desc); @@ -405,21 +408,12 @@ bool GrGpuGL::flushGraphicsState(DrawType type) { for (int s = 0; s < GrDrawState::kNumStages; ++s) { if (this->isStageEnabled(s)) { -#if GR_DEBUG - // check for circular rendering - GrAssert(NULL == drawState.getRenderTarget() || - NULL == drawState.getTexture(s) || - drawState.getTexture(s)->asRenderTarget() != - drawState.getRenderTarget()); -#endif this->flushBoundTextureAndParams(s); this->flushTextureMatrix(s); if (NULL != fCurrentProgram->fProgramStage[s]) { const GrSamplerState& sampler = this->getDrawState().getSampler(s); - const GrGLTexture* texture = static_cast<const GrGLTexture*>( - this->getDrawState().getTexture(s)); fCurrentProgram->fProgramStage[s]->setData(fCurrentProgram->fUniformManager, *sampler.getCustomStage(), drawState.getRenderTarget(), s); @@ -601,9 +595,9 @@ namespace { void setup_custom_stage(GrGLProgram::Desc::StageDesc* stage, const GrSamplerState& sampler, - GrCustomStage** customStages, + const GrCustomStage** customStages, GrGLProgram* program, int index) { - GrCustomStage* customStage = sampler.getCustomStage(); + const GrCustomStage* customStage = sampler.getCustomStage(); if (customStage) { const GrProgramStageFactory& factory = customStage->getFactory(); stage->fCustomStageKey = factory.glStageKey(*customStage); @@ -619,7 +613,7 @@ void setup_custom_stage(GrGLProgram::Desc::StageDesc* stage, void GrGpuGL::buildProgram(bool isPoints, BlendOptFlags blendOpts, GrBlendCoeff dstCoeff, - GrCustomStage** customStages, + const GrCustomStage** customStages, ProgramDesc* desc) { const GrDrawState& drawState = this->getDrawState(); @@ -641,11 +635,10 @@ void GrGpuGL::buildProgram(bool isPoints, desc->fEmitsPointSize = isPoints; - bool requiresAttributeColors = - !skipColor && SkToBool(desc->fVertexLayout & kColor_VertexLayoutBit); - bool requiresAttributeCoverage = - !skipCoverage && SkToBool(desc->fVertexLayout & - kCoverage_VertexLayoutBit); + bool requiresAttributeColors = !skipColor && + SkToBool(desc->fVertexLayout & kColor_VertexLayoutBit); + bool requiresAttributeCoverage = !skipCoverage && + SkToBool(desc->fVertexLayout & kCoverage_VertexLayoutBit); // fColorInput/fCoverageInput records how colors are specified for the. // program. So we strip the bits from the layout to avoid false negatives @@ -661,14 +654,12 @@ void GrGpuGL::buildProgram(bool isPoints, // no reason to do edge aa or look at per-vertex coverage if coverage is // ignored if (skipCoverage) { - desc->fVertexLayout &= ~(kEdge_VertexLayoutBit | - kCoverage_VertexLayoutBit); + desc->fVertexLayout &= ~(kEdge_VertexLayoutBit | kCoverage_VertexLayoutBit); } bool colorIsTransBlack = SkToBool(blendOpts & kEmitTransBlack_BlendOptFlag); bool colorIsSolidWhite = (blendOpts & kEmitCoverage_BlendOptFlag) || - (!requiresAttributeColors && - 0xffffffff == drawState.getColor()); + (!requiresAttributeColors && 0xffffffff == drawState.getColor()); if (GR_AGGRESSIVE_SHADER_OPTS && colorIsTransBlack) { desc->fColorInput = ProgramDesc::kTransBlack_ColorInput; } else if (GR_AGGRESSIVE_SHADER_OPTS && colorIsSolidWhite) { @@ -679,8 +670,7 @@ void GrGpuGL::buildProgram(bool isPoints, desc->fColorInput = ProgramDesc::kAttribute_ColorInput; } - bool covIsSolidWhite = !requiresAttributeCoverage && - 0xffffffff == drawState.getCoverage(); + bool covIsSolidWhite = !requiresAttributeCoverage && 0xffffffff == drawState.getCoverage(); if (skipCoverage) { desc->fCoverageInput = ProgramDesc::kTransBlack_ColorInput; @@ -694,8 +684,7 @@ void GrGpuGL::buildProgram(bool isPoints, int lastEnabledStage = -1; - if (!skipCoverage && (desc->fVertexLayout & - GrDrawTarget::kEdge_VertexLayoutBit)) { + if (!skipCoverage && (desc->fVertexLayout &GrDrawTarget::kEdge_VertexLayoutBit)) { desc->fVertexEdgeType = drawState.getVertexEdgeType(); } else { // use canonical value when not set to avoid cache misses @@ -709,52 +698,50 @@ void GrGpuGL::buildProgram(bool isPoints, stage.setEnabled(this->isStageEnabled(s)); bool skip = s < drawState.getFirstCoverageStage() ? skipColor : - skipCoverage; + skipCoverage; if (!skip && stage.isEnabled()) { lastEnabledStage = s; - const GrGLTexture* texture = - static_cast<const GrGLTexture*>(drawState.getTexture(s)); - GrAssert(NULL != texture); const GrSamplerState& sampler = drawState.getSampler(s); - // we matrix to invert when orientation is TopDown, so make sure - // we aren't in that case before flagging as identity. - if (TextureMatrixIsIdentity(texture, sampler)) { - stage.fOptFlags |= StageDesc::kIdentityMatrix_OptFlagBit; - } else if (!sampler.getMatrix().hasPerspective()) { - stage.fOptFlags |= StageDesc::kNoPerspective_OptFlagBit; - } - + // FIXME: Still assuming one texture per custom stage + const GrCustomStage* customStage = drawState.getSampler(s).getCustomStage(); + const GrGLTexture* texture = static_cast<const GrGLTexture*>(customStage->texture(0)); stage.fInConfigFlags = 0; - if (!this->glCaps().textureSwizzleSupport()) { - if (GrPixelConfigIsAlphaOnly(texture->config())) { - // if we don't have texture swizzle support then - // the shader must smear the single channel after - // reading the texture - if (this->glCaps().textureRedSupport()) { - // we can use R8 textures so use kSmearRed - stage.fInConfigFlags |= - StageDesc::kSmearRed_InConfigFlag; - } else { - // we can use A8 textures so use kSmearAlpha - stage.fInConfigFlags |= - StageDesc::kSmearAlpha_InConfigFlag; + if (NULL != texture) { + // We call this helper function rather then simply checking the client-specified + // texture matrix. This is because we may have to concat a y-inversion to account + // for texture orientation. + if (TextureMatrixIsIdentity(texture, sampler)) { + stage.fOptFlags |= StageDesc::kIdentityMatrix_OptFlagBit; + } else if (!sampler.getMatrix().hasPerspective()) { + stage.fOptFlags |= StageDesc::kNoPerspective_OptFlagBit; + } + if (!this->glCaps().textureSwizzleSupport()) { + if (GrPixelConfigIsAlphaOnly(texture->config())) { + // If we don't have texture swizzle support then the shader must smear the + // single channel after reading the texture. + if (this->glCaps().textureRedSupport()) { + // We can use R8 textures so use kSmearRed. + stage.fInConfigFlags |= StageDesc::kSmearRed_InConfigFlag; + } else { + // We can use A8 textures so use kSmearAlpha. + stage.fInConfigFlags |= StageDesc::kSmearAlpha_InConfigFlag; + } + } else if (sampler.swapsRAndB()) { + stage.fInConfigFlags |= StageDesc::kSwapRAndB_InConfigFlag; } - } else if (sampler.swapsRAndB()) { - stage.fInConfigFlags |= StageDesc::kSwapRAndB_InConfigFlag; } - } - if (GrPixelConfigIsUnpremultiplied(texture->config())) { - // The shader generator assumes that color channels are bytes - // when rounding. - GrAssert(4 == GrBytesPerPixel(texture->config())); - if (kUpOnWrite_DownOnRead_UnpremulConversion == - fUnpremulConversion) { - stage.fInConfigFlags |= - StageDesc::kMulRGBByAlpha_RoundDown_InConfigFlag; - } else { - stage.fInConfigFlags |= - StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag; + if (GrPixelConfigIsUnpremultiplied(texture->config())) { + // Assert that if we're doing a premul conversion that the texture is 1 byte + // per color component. The rounding performed by the shader generator (in + // normalized float color space) assumes this. + GrAssert(4 == GrBytesPerPixel(texture->config())); + if (kUpOnWrite_DownOnRead_UnpremulConversion == + fUnpremulConversion) { + stage.fInConfigFlags |= StageDesc::kMulRGBByAlpha_RoundDown_InConfigFlag; + } else { + stage.fInConfigFlags |= StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag; + } } } @@ -773,11 +760,9 @@ void GrGpuGL::buildProgram(bool isPoints, // when rounding. GrAssert(4 == GrBytesPerPixel(drawState.getRenderTarget()->config())); if (kUpOnWrite_DownOnRead_UnpremulConversion == fUnpremulConversion) { - desc->fOutputConfig = - ProgramDesc::kUnpremultiplied_RoundUp_OutputConfig; + desc->fOutputConfig = ProgramDesc::kUnpremultiplied_RoundUp_OutputConfig; } else { - desc->fOutputConfig = - ProgramDesc::kUnpremultiplied_RoundDown_OutputConfig; + desc->fOutputConfig = ProgramDesc::kUnpremultiplied_RoundDown_OutputConfig; } } else { desc->fOutputConfig = ProgramDesc::kPremultiplied_OutputConfig; @@ -785,18 +770,15 @@ void GrGpuGL::buildProgram(bool isPoints, desc->fDualSrcOutput = ProgramDesc::kNone_DualSrcOutput; - // currently the experimental GS will only work with triangle prims - // (and it doesn't do anything other than pass through values from - // the VS to the FS anyway). + // Currently the experimental GS will only work with triangle prims (and it doesn't do anything + // other than pass through values fromthe VS to the FS anyway). #if 0 && GR_GL_EXPERIMENTAL_GS desc->fExperimentalGS = this->getCaps().fGeometryShaderSupport; #endif - // we want to avoid generating programs with different "first cov stage" - // values when they would compute the same result. - // We set field in the desc to kNumStages when either there are no - // coverage stages or the distinction between coverage and color is - // immaterial. + // We want to avoid generating programs with different "first cov stage" values when they would + // compute the same result. We set field in the desc to kNumStages when either there are no + // coverage stages or the distinction between coverage and color is immaterial. int firstCoverageStage = GrDrawState::kNumStages; desc->fFirstCoverageStage = GrDrawState::kNumStages; bool hasCoverage = drawState.getFirstCoverageStage() <= lastEnabledStage; @@ -806,9 +788,8 @@ void GrGpuGL::buildProgram(bool isPoints, // other coverage inputs if (!hasCoverage) { - hasCoverage = - requiresAttributeCoverage || - (desc->fVertexLayout & GrDrawTarget::kEdge_VertexLayoutBit); + hasCoverage = requiresAttributeCoverage || + (desc->fVertexLayout & GrDrawTarget::kEdge_VertexLayoutBit); } if (hasCoverage) { @@ -818,20 +799,17 @@ void GrGpuGL::buildProgram(bool isPoints, } if (this->getCaps().fDualSourceBlendingSupport && - !(blendOpts & (kEmitCoverage_BlendOptFlag | - kCoverageAsAlpha_BlendOptFlag))) { + !(blendOpts & (kEmitCoverage_BlendOptFlag | kCoverageAsAlpha_BlendOptFlag))) { if (kZero_GrBlendCoeff == dstCoeff) { // write the coverage value to second color desc->fDualSrcOutput = ProgramDesc::kCoverage_DualSrcOutput; desc->fFirstCoverageStage = firstCoverageStage; } else if (kSA_GrBlendCoeff == dstCoeff) { - // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially - // cover + // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. desc->fDualSrcOutput = ProgramDesc::kCoverageISA_DualSrcOutput; desc->fFirstCoverageStage = firstCoverageStage; } else if (kSC_GrBlendCoeff == dstCoeff) { - // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially - // cover + // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. desc->fDualSrcOutput = ProgramDesc::kCoverageISC_DualSrcOutput; desc->fFirstCoverageStage = firstCoverageStage; } diff --git a/src/gpu/gl/GrGpuGL_unittest.cpp b/src/gpu/gl/GrGpuGL_unittest.cpp index fca908a58a..53fffca4de 100644 --- a/src/gpu/gl/GrGpuGL_unittest.cpp +++ b/src/gpu/gl/GrGpuGL_unittest.cpp @@ -37,8 +37,7 @@ typedef GrGLProgram::StageDesc StageDesc; // TODO: Effects should be able to register themselves for inclusion in the // randomly generated shaders. They should be able to configure themselves // randomly. -GrCustomStage* create_random_effect(StageDesc* stageDesc, - GrRandom* random) { +const GrCustomStage* create_random_effect(StageDesc* stageDesc, GrRandom* random) { enum EffectType { kConvolution_EffectType, kErode_EffectType, @@ -293,7 +292,7 @@ bool GrGpuGL::programUnitTest() { pdesc.fDualSrcOutput = ProgramDesc::kNone_DualSrcOutput; } - SkAutoTUnref<GrCustomStage> customStages[GrDrawState::kNumStages]; + SkAutoTUnref<const GrCustomStage> customStages[GrDrawState::kNumStages]; for (int s = 0; s < GrDrawState::kNumStages; ++s) { StageDesc& stage = pdesc.fStages[s]; @@ -327,8 +326,10 @@ bool GrGpuGL::programUnitTest() { } GR_STATIC_ASSERT(sizeof(customStages) == GrDrawState::kNumStages * sizeof(GrCustomStage*)); - GrCustomStage** stages = reinterpret_cast<GrCustomStage**>(&customStages); - SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContextInfo(), pdesc, stages)); + const GrCustomStage** stages = reinterpret_cast<const GrCustomStage**>(&customStages); + SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContextInfo(), + pdesc, + stages)); if (NULL == program.get()) { return false; } |