From eb62829a83a0a4f4fdd1230a3c08140e38052602 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Wed, 15 Feb 2017 14:12:26 -0500 Subject: Check that coverage FPs are compatible with alpha as coverage Change-Id: Ic3b6a02248d571e82f6729827c199d358fb75114 Reviewed-on: https://skia-review.googlesource.com/8508 Commit-Queue: Brian Salomon Reviewed-by: Greg Daniel --- src/effects/SkRRectsGaussianEdgeMaskFilter.cpp | 5 ++++- src/gpu/GrProcOptInfo.h | 2 ++ src/gpu/GrRenderTargetOpList.cpp | 8 ++++++++ src/gpu/effects/GrConvexPolyEffect.cpp | 6 +++++- src/gpu/effects/GrCustomXfermode.cpp | 3 ++- src/gpu/effects/GrPorterDuffXferProcessor.cpp | 3 ++- 6 files changed, 23 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/effects/SkRRectsGaussianEdgeMaskFilter.cpp b/src/effects/SkRRectsGaussianEdgeMaskFilter.cpp index 7635759ca2..b3967ecabb 100644 --- a/src/effects/SkRRectsGaussianEdgeMaskFilter.cpp +++ b/src/effects/SkRRectsGaussianEdgeMaskFilter.cpp @@ -206,7 +206,10 @@ public: }; RRectsGaussianEdgeFP(const SkRRect& first, const SkRRect& second, SkScalar radius) - : INHERITED(kNone_OptimizationFlags), fFirst(first), fSecond(second), fRadius(radius) { + : INHERITED(kCompatibleWithCoverageAsAlpha_OptimizationFlag) + , fFirst(first) + , fSecond(second) + , fRadius(radius) { this->initClassID(); fFirstMode = ComputeMode(fFirst); diff --git a/src/gpu/GrProcOptInfo.h b/src/gpu/GrProcOptInfo.h index 1a8578980d..ac3cb36966 100644 --- a/src/gpu/GrProcOptInfo.h +++ b/src/gpu/GrProcOptInfo.h @@ -26,6 +26,7 @@ public: GrProcOptInfo(const GrPipelineInput& input) : GrProcOptInfo() { fIsLCDCoverage = input.isLCDCoverage(); + fAllProcessorsCompatibleWithCoverageAsAlpha = !input.isLCDCoverage(); fIsOpaque = input.isOpaque(); GrColor color; if (input.isConstant(&color)) { @@ -37,6 +38,7 @@ public: void resetToLCDCoverage() { *this = GrProcOptInfo(); fIsLCDCoverage = true; + fAllProcessorsCompatibleWithCoverageAsAlpha = false; } void reset(const GrPipelineInput& input) { *this = GrProcOptInfo(input); } diff --git a/src/gpu/GrRenderTargetOpList.cpp b/src/gpu/GrRenderTargetOpList.cpp index 69ba279434..b7dd37a922 100644 --- a/src/gpu/GrRenderTargetOpList.cpp +++ b/src/gpu/GrRenderTargetOpList.cpp @@ -315,6 +315,14 @@ void GrRenderTargetOpList::addDrawOp(const GrPipelineBuilder& pipelineBuilder, if (const GrFragmentProcessor* clipFP = appliedClip.clipCoverageFragmentProcessor()) { args.fAnalysis.fCoveragePOI.analyzeProcessors(&clipFP, 1); } +#ifdef SK_DEBUG + // Other than tests that exercise atypical behavior we expect all coverage FPs to be compatible + // with the coverage-as-alpha optimization. + if (!args.fAnalysis.fCoveragePOI.allProcessorsCompatibleWithCoverageAsAlpha() && + !args.fAnalysis.fCoveragePOI.isLCDCoverage()) { + GrCapsDebugf(this->caps(), "Coverage FP is not compatible with coverage as alpha.\n"); + } +#endif if (!renderTargetContext->accessRenderTarget()) { return; diff --git a/src/gpu/effects/GrConvexPolyEffect.cpp b/src/gpu/effects/GrConvexPolyEffect.cpp index 0248beb9ce..838dff8e3a 100644 --- a/src/gpu/effects/GrConvexPolyEffect.cpp +++ b/src/gpu/effects/GrConvexPolyEffect.cpp @@ -253,8 +253,12 @@ sk_sp GrConvexPolyEffect::Make(GrPrimitiveEdgeType type, co return GrConstColorProcessor::Make(GrColor4f::OpaqueWhite(), GrConstColorProcessor::kModulateRGBA_InputMode); } + // This could use kIgnore instead of kModulateRGBA but it would trigger a debug print + // about a coverage processor not being compatible with the alpha-as-coverage optimization. + // We don't really care about this unlikely case so we just use kModulateRGBA to suppress + // the print. return GrConstColorProcessor::Make(GrColor4f::TransparentBlack(), - GrConstColorProcessor::kIgnore_InputMode); + GrConstColorProcessor::kModulateRGBA_InputMode); } SkVector t; diff --git a/src/gpu/effects/GrCustomXfermode.cpp b/src/gpu/effects/GrCustomXfermode.cpp index d7330691ae..36936f8db1 100644 --- a/src/gpu/effects/GrCustomXfermode.cpp +++ b/src/gpu/effects/GrCustomXfermode.cpp @@ -300,7 +300,8 @@ GrXferProcessor::OptFlags CustomXP::onGetOptimizations(const GrPipelineAnalysis& */ OptFlags flags = kNone_OptFlags; - if (analysis.fColorPOI.allProcessorsCompatibleWithCoverageAsAlpha()) { + if (analysis.fColorPOI.allProcessorsCompatibleWithCoverageAsAlpha() && + analysis.fCoveragePOI.allProcessorsCompatibleWithCoverageAsAlpha()) { flags |= kCanTweakAlphaForCoverage_OptFlag; } return flags; diff --git a/src/gpu/effects/GrPorterDuffXferProcessor.cpp b/src/gpu/effects/GrPorterDuffXferProcessor.cpp index ead4ed6f3f..6b7d0ba025 100644 --- a/src/gpu/effects/GrPorterDuffXferProcessor.cpp +++ b/src/gpu/effects/GrPorterDuffXferProcessor.cpp @@ -466,7 +466,8 @@ GrXferProcessor::OptFlags PorterDuffXferProcessor::onGetOptimizations( optFlags |= GrXferProcessor::kIgnoreColor_OptFlag; } if (analysis.fColorPOI.allProcessorsCompatibleWithCoverageAsAlpha() && - fBlendFormula.canTweakAlphaForCoverage() && !analysis.fCoveragePOI.isLCDCoverage()) { + analysis.fCoveragePOI.allProcessorsCompatibleWithCoverageAsAlpha() && + fBlendFormula.canTweakAlphaForCoverage()) { optFlags |= GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag; } } -- cgit v1.2.3