Add query to GrXPFactory about coverage-as-alpha optimization
authorBrian Salomon <bsalomon@google.com>
Mon, 13 Mar 2017 14:36:40 +0000 (10:36 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Mon, 13 Mar 2017 16:26:56 +0000 (16:26 +0000)
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 <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>

src/gpu/GrXferProcessor.cpp
src/gpu/GrXferProcessor.h
src/gpu/effects/GrCoverageSetOpXP.h
src/gpu/effects/GrCustomXfermode.cpp
src/gpu/effects/GrDisableColorXP.h
src/gpu/effects/GrPorterDuffXferProcessor.cpp
src/gpu/effects/GrPorterDuffXferProcessor.h

index 3b8a2bfb87cc731ed03e0a0949c315a3d7cfe031..4d877d6b270fbd5bca8ccdaeb92b7844436f28c6 100644 (file)
@@ -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,
index d6d6fa33e377bb34175fb771455beef2d999d67f..7f3fd30e8daff8f9b58ed1953047559a07f3aee8 100644 (file)
@@ -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
index 02db11b811fe3ae24ebe490979aeb7f53a4aedcf..807a2b0fc6c613807195b368286e2b15bd34c9e9 100644 (file)
@@ -45,6 +45,8 @@ private:
         return false;
     }
 
+    bool compatibleWithCoverageAsAlpha(bool colorIsOpaque) const override { return false; }
+
     GR_DECLARE_XP_FACTORY_TEST;
 
     SkRegion::Op fRegionOp;
index 8895d7c02ba1fdcc0e5909c2cd6ae01a1f73a20b..81b9e45413f28e94a92bcee9629178079418f438 100644 (file)
@@ -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;
index 6a9f2add171bb9e231bdf07df2f92a492bdd6a0d..f9206f7c1983a1bdc3e250aa091ebb69fb662cc8 100644 (file)
@@ -32,6 +32,8 @@ private:
         return false;
     }
 
+    bool compatibleWithCoverageAsAlpha(bool colorIsOpaque) const override { return true; }
+
     GrXferProcessor* onCreateXferProcessor(const GrCaps& caps,
                                            const FragmentProcessorAnalysis&,
                                            bool hasMixedSamples,
index c7e61cace337bc73cb8b284a7ae7155cd7fb5689..8b35bb996a9ab3a0d7e50309845b86b7d4e31c0d 100644 (file)
@@ -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() ||
index b82c1068ffc03bb46baf994a28d81bead9fcd339..dd790e84314dacd63ed34dbc98a22a96f802f6d1 100644 (file)
@@ -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);