From 780b41fc10fb212ec6d9a9aeb7ca4cc0292fb85e Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Mon, 13 Mar 2017 10:36:40 -0400 Subject: [PATCH] Add query to GrXPFactory about coverage-as-alpha optimization This will be needed to have GrDrawOps that haven't yet built pipelines. Change-Id: If5292aaa5dc9f98dccbe27be98960b630332158d Reviewed-on: https://skia-review.googlesource.com/9480 Reviewed-by: Greg Daniel Commit-Queue: Brian Salomon --- src/gpu/GrXferProcessor.cpp | 7 +++++++ src/gpu/GrXferProcessor.h | 4 ++++ src/gpu/effects/GrCoverageSetOpXP.h | 2 ++ src/gpu/effects/GrCustomXfermode.cpp | 2 ++ src/gpu/effects/GrDisableColorXP.h | 2 ++ src/gpu/effects/GrPorterDuffXferProcessor.cpp | 13 +++++-------- src/gpu/effects/GrPorterDuffXferProcessor.h | 5 +++-- 7 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/gpu/GrXferProcessor.cpp b/src/gpu/GrXferProcessor.cpp index 3b8a2bfb87..4d877d6b27 100644 --- a/src/gpu/GrXferProcessor.cpp +++ b/src/gpu/GrXferProcessor.cpp @@ -197,6 +197,13 @@ bool GrXPFactory::WillNeedDstTexture(const GrXPFactory* factory, const GrCaps& c return result; } +bool GrXPFactory::CompatibleWithCoverageAsAlpha(const GrXPFactory* factory, bool colorIsOpaque) { + if (factory) { + return factory->compatibleWithCoverageAsAlpha(colorIsOpaque); + } + return GrPorterDuffXPFactory::SrcOverIsCompatibleWithCoverageAsAlpha(); +} + GrXferProcessor* GrXPFactory::createXferProcessor(const FragmentProcessorAnalysis& analysis, bool hasMixedSamples, const DstTexture* dstTexture, diff --git a/src/gpu/GrXferProcessor.h b/src/gpu/GrXferProcessor.h index d6d6fa33e3..7f3fd30e8d 100644 --- a/src/gpu/GrXferProcessor.h +++ b/src/gpu/GrXferProcessor.h @@ -313,6 +313,8 @@ public: const GrCaps&, const FragmentProcessorAnalysis&); + static bool CompatibleWithCoverageAsAlpha(const GrXPFactory*, bool colorIsOpaque); + protected: constexpr GrXPFactory() {} @@ -330,6 +332,8 @@ private: * shader. */ virtual bool willReadDstInShader(const GrCaps&, const FragmentProcessorAnalysis&) const = 0; + + virtual bool compatibleWithCoverageAsAlpha(bool colorIsOpaque) const = 0; }; #if defined(__GNUC__) || defined(__clang) #pragma GCC diagnostic pop diff --git a/src/gpu/effects/GrCoverageSetOpXP.h b/src/gpu/effects/GrCoverageSetOpXP.h index 02db11b811..807a2b0fc6 100644 --- a/src/gpu/effects/GrCoverageSetOpXP.h +++ b/src/gpu/effects/GrCoverageSetOpXP.h @@ -45,6 +45,8 @@ private: return false; } + bool compatibleWithCoverageAsAlpha(bool colorIsOpaque) const override { return false; } + GR_DECLARE_XP_FACTORY_TEST; SkRegion::Op fRegionOp; diff --git a/src/gpu/effects/GrCustomXfermode.cpp b/src/gpu/effects/GrCustomXfermode.cpp index 8895d7c02b..81b9e45413 100644 --- a/src/gpu/effects/GrCustomXfermode.cpp +++ b/src/gpu/effects/GrCustomXfermode.cpp @@ -331,6 +331,8 @@ private: bool willReadDstInShader(const GrCaps&, const FragmentProcessorAnalysis&) const override; + bool compatibleWithCoverageAsAlpha(bool colorIsOpaque) const override { return true; } + GR_DECLARE_XP_FACTORY_TEST; SkBlendMode fMode; diff --git a/src/gpu/effects/GrDisableColorXP.h b/src/gpu/effects/GrDisableColorXP.h index 6a9f2add17..f9206f7c19 100644 --- a/src/gpu/effects/GrDisableColorXP.h +++ b/src/gpu/effects/GrDisableColorXP.h @@ -32,6 +32,8 @@ private: return false; } + bool compatibleWithCoverageAsAlpha(bool colorIsOpaque) const override { return true; } + GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, const FragmentProcessorAnalysis&, bool hasMixedSamples, diff --git a/src/gpu/effects/GrPorterDuffXferProcessor.cpp b/src/gpu/effects/GrPorterDuffXferProcessor.cpp index c7e61cace3..8b35bb996a 100644 --- a/src/gpu/effects/GrPorterDuffXferProcessor.cpp +++ b/src/gpu/effects/GrPorterDuffXferProcessor.cpp @@ -791,6 +791,11 @@ bool GrPorterDuffXPFactory::willReadDstInShader(const GrCaps& caps, return formula.hasSecondaryOutput(); } +bool GrPorterDuffXPFactory::compatibleWithCoverageAsAlpha(bool colorIsOpaque) const { + // We assume we have coverage (or else this doesn't matter). + return gBlendTable[colorIsOpaque][1][(int)fBlendMode].canTweakAlphaForCoverage(); +} + GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); #if GR_TEST_UTILS @@ -868,14 +873,6 @@ bool GrPorterDuffXPFactory::WillSrcOverReadDst(const FragmentProcessorAnalysis& return analysis.hasCoverage() || !analysis.isOutputColorOpaque(); } -bool GrPorterDuffXPFactory::IsSrcOverPreCoverageBlendedColorConstant( - const GrProcOptInfo& colorInput, GrColor* color) { - if (!colorInput.isOpaque()) { - return false; - } - return colorInput.hasKnownOutputColor(color); -} - bool GrPorterDuffXPFactory::WillSrcOverNeedDstTexture(const GrCaps& caps, const FragmentProcessorAnalysis& analysis) { if (caps.shaderCaps()->dstReadInShaderSupport() || diff --git a/src/gpu/effects/GrPorterDuffXferProcessor.h b/src/gpu/effects/GrPorterDuffXferProcessor.h index b82c1068ff..dd790e8431 100644 --- a/src/gpu/effects/GrPorterDuffXferProcessor.h +++ b/src/gpu/effects/GrPorterDuffXferProcessor.h @@ -38,9 +38,8 @@ public: static const GrXferProcessor& SimpleSrcOverXP(); static bool WillSrcOverReadDst(const FragmentProcessorAnalysis& analysis); - static bool IsSrcOverPreCoverageBlendedColorConstant(const GrProcOptInfo& colorInput, - GrColor* color); static bool WillSrcOverNeedDstTexture(const GrCaps&, const FragmentProcessorAnalysis&); + static bool SrcOverIsCompatibleWithCoverageAsAlpha() { return true; } private: constexpr GrPorterDuffXPFactory(SkBlendMode); @@ -54,6 +53,8 @@ private: bool willReadDstInShader(const GrCaps&, const FragmentProcessorAnalysis&) const override; + bool compatibleWithCoverageAsAlpha(bool colorIsOpaque) const override; + GR_DECLARE_XP_FACTORY_TEST; static void TestGetXPOutputTypes(const GrXferProcessor*, int* outPrimary, int* outSecondary); -- 2.34.1