From f7c2d558726b8d629e1453b7201a0dd6bfda7b05 Mon Sep 17 00:00:00 2001 From: egdaniel Date: Fri, 13 Feb 2015 12:11:00 -0800 Subject: [PATCH] Determine whether we can tweakAlphaForCoverage during Pipeline/XP creation. BUG=skia: Review URL: https://codereview.chromium.org/927623002 --- include/gpu/GrInvariantOutput.h | 1 + include/gpu/GrXferProcessor.h | 4 ++++ src/gpu/GrPipeline.cpp | 2 ++ src/gpu/GrPrimitiveProcessor.h | 1 + src/gpu/GrProcOptInfo.h | 1 + src/gpu/effects/GrPorterDuffXferProcessor.cpp | 23 +++++++++++++++++-- 6 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/gpu/GrInvariantOutput.h b/include/gpu/GrInvariantOutput.h index 269748a026..4977333de4 100644 --- a/include/gpu/GrInvariantOutput.h +++ b/include/gpu/GrInvariantOutput.h @@ -210,6 +210,7 @@ private: bool willUseInputColor() const { return fWillUseInputColor; } void resetWillUseInputColor() { fWillUseInputColor = true; } + bool allStagesMulInput() const { return !fNonMulStageFound; } void resetNonMulStageFound() { fNonMulStageFound = false; } bool isLCDCoverage() const { return fIsLCDCoverage; } diff --git a/include/gpu/GrXferProcessor.h b/include/gpu/GrXferProcessor.h index f7487975e5..312e769224 100644 --- a/include/gpu/GrXferProcessor.h +++ b/include/gpu/GrXferProcessor.h @@ -73,6 +73,10 @@ public: * Set CoverageDrawing_StateBit */ kSetCoverageDrawing_OptFlag = 0x10, + /** + * Can tweak alpha for coverage. Currently this flag should only be used by a batch + */ + kCanTweakAlphaForCoverage_OptFlag = 0x20, }; GR_DECL_BITFIELD_OPS_FRIENDS(OptFlags); diff --git a/src/gpu/GrPipeline.cpp b/src/gpu/GrPipeline.cpp index 3ccc72b8df..61462469de 100644 --- a/src/gpu/GrPipeline.cpp +++ b/src/gpu/GrPipeline.cpp @@ -102,6 +102,8 @@ GrPipeline::GrPipeline(const GrPipelineBuilder& pipelineBuilder, fInitBT.fOverrideColor = fInitBT.fColorIgnored ? GrColor_ILLEGAL : overrideColor; fInitBT.fCoverageIgnored = SkToBool(optFlags & GrXferProcessor::kIgnoreCoverage_OptFlag); fInitBT.fUsesLocalCoords = usesLocalCoords; + fInitBT.fCanTweakAlphaForCoverage = + SkToBool(optFlags & GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag); } void GrPipeline::adjustProgramFromOptimizations(const GrPipelineBuilder& pipelineBuilder, diff --git a/src/gpu/GrPrimitiveProcessor.h b/src/gpu/GrPrimitiveProcessor.h index a088d38b61..45668e9be6 100644 --- a/src/gpu/GrPrimitiveProcessor.h +++ b/src/gpu/GrPrimitiveProcessor.h @@ -83,6 +83,7 @@ struct GrPipelineInfo { bool fCoverageIgnored; GrColor fOverrideColor; bool fUsesLocalCoords; + bool fCanTweakAlphaForCoverage; }; /* diff --git a/src/gpu/GrProcOptInfo.h b/src/gpu/GrProcOptInfo.h index 6e8f615d2c..059bca4dd8 100644 --- a/src/gpu/GrProcOptInfo.h +++ b/src/gpu/GrProcOptInfo.h @@ -45,6 +45,7 @@ public: bool isSolidWhite() const { return fInOut.isSolidWhite(); } bool isOpaque() const { return fInOut.isOpaque(); } bool isSingleComponent() const { return fInOut.isSingleComponent(); } + bool allStagesMultiplyInput() const { return fInOut.allStagesMulInput(); } // TODO: Once texture pixel configs quaries are updated, we no longer need this function. // For now this function will correctly tell us if we are using LCD text or not and should only diff --git a/src/gpu/effects/GrPorterDuffXferProcessor.cpp b/src/gpu/effects/GrPorterDuffXferProcessor.cpp index 6f2b63f5cb..428b76a38a 100644 --- a/src/gpu/effects/GrPorterDuffXferProcessor.cpp +++ b/src/gpu/effects/GrPorterDuffXferProcessor.cpp @@ -330,7 +330,13 @@ PorterDuffXferProcessor::internalGetOptimizations(const GrProcOptInfo& colorPOI, // check whether coverage can be safely rolled into alpha // of if we can skip color computation and just emit coverage if (can_tweak_alpha_for_coverage(fDstBlend)) { - return GrXferProcessor::kSetCoverageDrawing_OptFlag; + if (colorPOI.allStagesMultiplyInput()) { + return GrXferProcessor::kSetCoverageDrawing_OptFlag | + GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag; + } else { + return GrXferProcessor::kSetCoverageDrawing_OptFlag; + + } } if (dstCoeffIsZero) { if (kZero_GrBlendCoeff == fSrcBlend) { @@ -346,12 +352,25 @@ PorterDuffXferProcessor::internalGetOptimizations(const GrProcOptInfo& colorPOI, // If Sa is 1 then we can replace Sa with c // and set dst coeff to 1-Sa. fDstBlend = kISA_GrBlendCoeff; - return GrXferProcessor::kSetCoverageDrawing_OptFlag; + if (colorPOI.allStagesMultiplyInput()) { + return GrXferProcessor::kSetCoverageDrawing_OptFlag | + GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag; + } else { + return GrXferProcessor::kSetCoverageDrawing_OptFlag; + + } } } else if (dstCoeffIsOne) { // the dst coeff is effectively one so blend works out to: // cS + (c)(1)D + (1-c)D = cS + D. fDstBlend = kOne_GrBlendCoeff; + if (colorPOI.allStagesMultiplyInput()) { + return GrXferProcessor::kSetCoverageDrawing_OptFlag | + GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag; + } else { + return GrXferProcessor::kSetCoverageDrawing_OptFlag; + + } return GrXferProcessor::kSetCoverageDrawing_OptFlag; } }