From 3329cceab5feca230df1caee16be045249228dc1 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Fri, 20 Jan 2017 18:22:52 +0000 Subject: [PATCH] Revert "Make it possible to query GrXPFactory for dst texture without GrPipelineAnalysis." This reverts commit f833215420847565b4c9945aebdc2e7ae182937f. Reason for revert: Original change's description: > Make it possible to query GrXPFactory for dst texture without GrPipelineAnalysis. > > Change-Id: I8c140eb4e3e5f2d21ecbf8f8f3c8533dc7f50e7c > Reviewed-on: https://skia-review.googlesource.com/7316 > Commit-Queue: Brian Salomon > Reviewed-by: Greg Daniel > TBR=egdaniel@google.com,bsalomon@google.com,reviews@skia.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Change-Id: I790afb9a01422cb4c2d3a4be4ecd20e8c4466b29 Reviewed-on: https://skia-review.googlesource.com/7342 Commit-Queue: Brian Salomon Reviewed-by: Brian Salomon --- include/gpu/GrXferProcessor.h | 27 +++------------- include/gpu/effects/GrCoverageSetOpXP.h | 4 ++- include/gpu/effects/GrPorterDuffXferProcessor.h | 2 +- src/gpu/GrXferProcessor.cpp | 41 +++-------------------- src/gpu/effects/GrCustomXfermode.cpp | 22 ++++++------- src/gpu/effects/GrDisableColorXP.h | 6 ++-- src/gpu/effects/GrPorterDuffXferProcessor.cpp | 43 +++++++++++++------------ 7 files changed, 48 insertions(+), 97 deletions(-) diff --git a/include/gpu/GrXferProcessor.h b/include/gpu/GrXferProcessor.h index 353c682..17cd2c7 100644 --- a/include/gpu/GrXferProcessor.h +++ b/include/gpu/GrXferProcessor.h @@ -307,16 +307,6 @@ GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags); class GrXPFactory { public: typedef GrXferProcessor::DstTexture DstTexture; - - /** Describes known properties of a draw's color input to the GrXferProcessor. */ - enum class ColorType { kUnknown, kOpaqueConstant, kConstant, kOpaque }; - - /** - * Indicates whether a draw's coverage input to the GrXferProcessor is solid, single channel - * or LCD (four channel coverage). - */ - enum class CoverageType { kNone, kSingleChannel, kLCD }; - GrXferProcessor* createXferProcessor(const GrPipelineAnalysis&, bool hasMixedSamples, const DstTexture*, @@ -339,33 +329,24 @@ public: virtual void getInvariantBlendedColor(const GrProcOptInfo& colorPOI, InvariantBlendedColor*) const = 0; - bool willNeedDstTexture(const GrCaps& caps, const GrPipelineAnalysis& analysis) const; + bool willNeedDstTexture(const GrCaps& caps, const GrPipelineAnalysis&) const; protected: constexpr GrXPFactory() {} - static bool ColorTypeIsOpaque(ColorType type) { - return ColorType::kOpaqueConstant == type || ColorType::kOpaque == type; - } - - static bool ColorTypeIsConstant(ColorType type) { - return ColorType::kOpaqueConstant == type || ColorType::kConstant == type; - } - private: virtual GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, const GrPipelineAnalysis&, bool hasMixedSamples, const DstTexture*) const = 0; - bool willReadDstColor(const GrCaps& caps, const GrPipelineAnalysis& analysis) const; + bool willReadDstColor(const GrCaps&, const GrPipelineAnalysis&) const; /** * Returns true if the XP generated by this factory will explicitly read dst in the fragment - * shader. This will not be called for draws that read from PLS since the dst color is always - * available in such draws. + * shader. */ - virtual bool willReadDstColor(const GrCaps&, ColorType, CoverageType) const = 0; + virtual bool onWillReadDstColor(const GrCaps&, const GrPipelineAnalysis&) const = 0; }; #if defined(__GNUC__) || defined(__clang) #pragma GCC diagnostic pop diff --git a/include/gpu/effects/GrCoverageSetOpXP.h b/include/gpu/effects/GrCoverageSetOpXP.h index 385cad8..ca71abc 100644 --- a/include/gpu/effects/GrCoverageSetOpXP.h +++ b/include/gpu/effects/GrCoverageSetOpXP.h @@ -40,7 +40,9 @@ private: bool hasMixedSamples, const DstTexture*) const override; - bool willReadDstColor(const GrCaps&, ColorType, CoverageType) const override { return false; } + bool onWillReadDstColor(const GrCaps&, const GrPipelineAnalysis&) const override { + return false; + } GR_DECLARE_XP_FACTORY_TEST; diff --git a/include/gpu/effects/GrPorterDuffXferProcessor.h b/include/gpu/effects/GrPorterDuffXferProcessor.h index 028cac6..ca14275 100644 --- a/include/gpu/effects/GrPorterDuffXferProcessor.h +++ b/include/gpu/effects/GrPorterDuffXferProcessor.h @@ -63,7 +63,7 @@ private: bool hasMixedSamples, const DstTexture*) const override; - bool willReadDstColor(const GrCaps&, ColorType, CoverageType) const override; + bool onWillReadDstColor(const GrCaps&, const GrPipelineAnalysis&) const override; GR_DECLARE_XP_FACTORY_TEST; static void TestGetXPOutputTypes(const GrXferProcessor*, int* outPrimary, int* outSecondary); diff --git a/src/gpu/GrXferProcessor.cpp b/src/gpu/GrXferProcessor.cpp index d88259d..7de0d77 100644 --- a/src/gpu/GrXferProcessor.cpp +++ b/src/gpu/GrXferProcessor.cpp @@ -180,40 +180,6 @@ SkString GrXferProcessor::BlendInfo::dump() const { /////////////////////////////////////////////////////////////////////////////// -using ColorType = GrXPFactory::ColorType; -using CoverageType = GrXPFactory::CoverageType; - -ColorType analysis_color_type(const GrPipelineAnalysis& analysis) { - if (analysis.fColorPOI.validFlags() == kRGBA_GrColorComponentFlags) { - return GrColorIsOpaque(analysis.fColorPOI.color()) ? ColorType::kOpaqueConstant - : ColorType::kConstant; - } - if ((analysis.fColorPOI.validFlags() & kA_GrColorComponentFlag) && - GrColorIsOpaque(analysis.fColorPOI.color())) { - return ColorType::kOpaque; - } - return ColorType::kUnknown; -} - -CoverageType analysis_coverage_type(const GrPipelineAnalysis& analysis) { - if (analysis.fCoveragePOI.isSolidWhite()) { - return CoverageType::kNone; - } - if (analysis.fCoveragePOI.isLCDCoverage()) { - return CoverageType::kLCD; - } - return CoverageType::kSingleChannel; -} - -bool GrXPFactory::willReadDstColor(const GrCaps& caps, const GrPipelineAnalysis& analysis) const { - if (analysis.fUsesPLSDstRead) { - return true; - } - ColorType colorType = analysis_color_type(analysis); - CoverageType coverageType = analysis_coverage_type(analysis); - return this->willReadDstColor(caps, colorType, coverageType); -} - GrXferProcessor* GrXPFactory::createXferProcessor(const GrPipelineAnalysis& analysis, bool hasMixedSamples, const DstTexture* dstTexture, @@ -234,6 +200,9 @@ GrXferProcessor* GrXPFactory::createXferProcessor(const GrPipelineAnalysis& anal } bool GrXPFactory::willNeedDstTexture(const GrCaps& caps, const GrPipelineAnalysis& analysis) const { - return !analysis.fUsesPLSDstRead && !caps.shaderCaps()->dstReadInShaderSupport() && - this->willReadDstColor(caps, analysis); + return (this->willReadDstColor(caps, analysis) && !caps.shaderCaps()->dstReadInShaderSupport()); +} + +bool GrXPFactory::willReadDstColor(const GrCaps& caps, const GrPipelineAnalysis& analysis) const { + return analysis.fUsesPLSDstRead || this->onWillReadDstColor(caps, analysis); } diff --git a/src/gpu/effects/GrCustomXfermode.cpp b/src/gpu/effects/GrCustomXfermode.cpp index f8af7db..070fa2f 100644 --- a/src/gpu/effects/GrCustomXfermode.cpp +++ b/src/gpu/effects/GrCustomXfermode.cpp @@ -54,16 +54,15 @@ static constexpr GrBlendEquation hw_blend_equation(SkBlendMode mode) { } static bool can_use_hw_blend_equation(GrBlendEquation equation, - bool usePLSRead, - bool isLCDCoverage, + const GrPipelineAnalysis& analysis, const GrCaps& caps) { if (!caps.advancedBlendEquationSupport()) { return false; } - if (usePLSRead) { + if (analysis.fUsesPLSDstRead) { return false; } - if (isLCDCoverage) { + if (analysis.fCoveragePOI.isLCDCoverage()) { return false; // LCD coverage must be applied after the blend equation. } if (caps.canUseAdvancedBlendEquation(equation)) { @@ -341,7 +340,8 @@ private: bool hasMixedSamples, const DstTexture*) const override; - bool willReadDstColor(const GrCaps&, ColorType, CoverageType) const override; + bool onWillReadDstColor(const GrCaps&, const GrPipelineAnalysis&) const override; + GR_DECLARE_XP_FACTORY_TEST; @@ -359,20 +359,16 @@ GrXferProcessor* CustomXPFactory::onCreateXferProcessor(const GrCaps& caps, bool hasMixedSamples, const DstTexture* dstTexture) const { SkASSERT(GrCustomXfermode::IsSupportedMode(fMode)); - if (can_use_hw_blend_equation(fHWBlendEquation, analysis.fUsesPLSDstRead, - analysis.fCoveragePOI.isLCDCoverage(), caps)) { + if (can_use_hw_blend_equation(fHWBlendEquation, analysis, caps)) { SkASSERT(!dstTexture || !dstTexture->texture()); return new CustomXP(fMode, fHWBlendEquation); } return new CustomXP(dstTexture, hasMixedSamples, fMode); } -bool CustomXPFactory::willReadDstColor(const GrCaps& caps, ColorType colorType, - CoverageType coverageType) const { - // This should not be called if we're using PLS dst read. - static constexpr bool kUsesPLSRead = false; - return !can_use_hw_blend_equation(fHWBlendEquation, kUsesPLSRead, - CoverageType::kLCD == coverageType, caps); +bool CustomXPFactory::onWillReadDstColor(const GrCaps& caps, + const GrPipelineAnalysis& analysis) const { + return !can_use_hw_blend_equation(fHWBlendEquation, analysis, caps); } void CustomXPFactory::getInvariantBlendedColor(const GrProcOptInfo& colorPOI, diff --git a/src/gpu/effects/GrDisableColorXP.h b/src/gpu/effects/GrDisableColorXP.h index f027e3c..9f56ae5 100644 --- a/src/gpu/effects/GrDisableColorXP.h +++ b/src/gpu/effects/GrDisableColorXP.h @@ -32,13 +32,15 @@ public: private: constexpr GrDisableColorXPFactory() {} - bool willReadDstColor(const GrCaps&, ColorType, CoverageType) const override { return false; } - GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, const GrPipelineAnalysis&, bool hasMixedSamples, const DstTexture* dstTexture) const override; + bool onWillReadDstColor(const GrCaps&, const GrPipelineAnalysis&) const override { + return false; + } + GR_DECLARE_XP_FACTORY_TEST; typedef GrXPFactory INHERITED; diff --git a/src/gpu/effects/GrPorterDuffXferProcessor.cpp b/src/gpu/effects/GrPorterDuffXferProcessor.cpp index 59710eb..7f40906 100644 --- a/src/gpu/effects/GrPorterDuffXferProcessor.cpp +++ b/src/gpu/effects/GrPorterDuffXferProcessor.cpp @@ -320,17 +320,21 @@ static const BlendFormula gLCDBlendTable[(int)SkBlendMode::kLastCoeffMode + 1] = /* screen */ COEFF_FORMULA( kOne_GrBlendCoeff, kISC_GrBlendCoeff), }; -static BlendFormula get_blend_formula(bool isOpaque, - bool hasCoverage, +static BlendFormula get_blend_formula(const GrProcOptInfo& colorPOI, + const GrProcOptInfo& coveragePOI, bool hasMixedSamples, SkBlendMode xfermode) { SkASSERT((unsigned)xfermode <= (unsigned)SkBlendMode::kLastCoeffMode); - bool conflatesCoverage = hasCoverage || hasMixedSamples; - return gBlendTable[isOpaque][conflatesCoverage][(int)xfermode]; + SkASSERT(!coveragePOI.isLCDCoverage()); + + bool conflatesCoverage = !coveragePOI.isSolidWhite() || hasMixedSamples; + return gBlendTable[colorPOI.isOpaque()][conflatesCoverage][(int)xfermode]; } -static BlendFormula get_lcd_blend_formula(SkBlendMode xfermode) { +static BlendFormula get_lcd_blend_formula(const GrProcOptInfo& coveragePOI, + SkBlendMode xfermode) { SkASSERT((unsigned)xfermode <= (unsigned)SkBlendMode::kLastCoeffMode); + SkASSERT(coveragePOI.isLCDCoverage()); return gLCDBlendTable[(int)xfermode]; } @@ -755,10 +759,9 @@ GrXferProcessor* GrPorterDuffXPFactory::onCreateXferProcessor(const GrCaps& caps SkASSERT(!dstTexture || !dstTexture->texture()); return PDLCDXferProcessor::Create(fBlendMode, analysis.fColorPOI); } - blendFormula = get_lcd_blend_formula(fBlendMode); + blendFormula = get_lcd_blend_formula(analysis.fCoveragePOI, fBlendMode); } else { - blendFormula = get_blend_formula(analysis.fColorPOI.isOpaque(), - !analysis.fCoveragePOI.isSolidWhite(), hasMixedSamples, + blendFormula = get_blend_formula(analysis.fColorPOI, analysis.fCoveragePOI, hasMixedSamples, fBlendMode); } @@ -801,8 +804,8 @@ void GrPorterDuffXPFactory::getInvariantBlendedColor(const GrProcOptInfo& colorP } } -bool GrPorterDuffXPFactory::willReadDstColor(const GrCaps& caps, ColorType colorType, - CoverageType coverageType) const { +bool GrPorterDuffXPFactory::onWillReadDstColor(const GrCaps& caps, + const GrPipelineAnalysis& analysis) const { if (caps.shaderCaps()->dualSourceBlendingSupport()) { return false; } @@ -810,20 +813,20 @@ bool GrPorterDuffXPFactory::willReadDstColor(const GrCaps& caps, ColorType color // When we have four channel coverage we always need to read the dst in order to correctly // blend. The one exception is when we are using srcover mode and we know the input color into // the XP. - if (CoverageType::kLCD == coverageType) { - if (SkBlendMode::kSrcOver == fBlendMode && ColorTypeIsConstant(colorType) && + if (analysis.fCoveragePOI.isLCDCoverage()) { + if (SkBlendMode::kSrcOver == fBlendMode && + kRGBA_GrColorComponentFlags == analysis.fColorPOI.validFlags() && !caps.shaderCaps()->dstReadInShaderSupport()) { return false; } - return get_lcd_blend_formula(fBlendMode).hasSecondaryOutput(); + return get_lcd_blend_formula(analysis.fCoveragePOI, fBlendMode).hasSecondaryOutput(); } // We fallback on the shader XP when the blend formula would use dual source blending but we // don't have support for it. static const bool kHasMixedSamples = false; SkASSERT(!caps.usesMixedSamples()); // We never use mixed samples without dual source blending. - auto formula = get_blend_formula(ColorTypeIsOpaque(colorType), - CoverageType::kSingleChannel == coverageType, kHasMixedSamples, + auto formula = get_blend_formula(analysis.fColorPOI, analysis.fCoveragePOI, kHasMixedSamples, fBlendMode); return formula.hasSecondaryOutput(); } @@ -890,7 +893,7 @@ GrXferProcessor* GrPorterDuffXPFactory::CreateSrcOverXferProcessor( } BlendFormula blendFormula; - blendFormula = get_lcd_blend_formula(SkBlendMode::kSrcOver); + blendFormula = get_lcd_blend_formula(analysis.fCoveragePOI, SkBlendMode::kSrcOver); if (blendFormula.hasSecondaryOutput() && !caps.shaderCaps()->dualSourceBlendingSupport()) { return new ShaderPDXferProcessor(dstTexture, hasMixedSamples, SkBlendMode::kSrcOver); } @@ -914,17 +917,15 @@ bool GrPorterDuffXPFactory::SrcOverWillNeedDstTexture(const GrCaps& caps, !caps.shaderCaps()->dstReadInShaderSupport()) { return false; } - auto formula = get_lcd_blend_formula(SkBlendMode::kSrcOver); + auto formula = get_lcd_blend_formula(analysis.fCoveragePOI, SkBlendMode::kSrcOver); return formula.hasSecondaryOutput(); } // We fallback on the shader XP when the blend formula would use dual source blending but we // don't have support for it. static const bool kHasMixedSamples = false; - bool isOpaque = analysis.fColorPOI.isOpaque(); - bool hasCoverage = !analysis.fCoveragePOI.isSolidWhite(); SkASSERT(!caps.usesMixedSamples()); // We never use mixed samples without dual source blending. - auto formula = - get_blend_formula(isOpaque, hasCoverage, kHasMixedSamples, SkBlendMode::kSrcOver); + auto formula = get_blend_formula(analysis.fColorPOI, analysis.fCoveragePOI, kHasMixedSamples, + SkBlendMode::kSrcOver); return formula.hasSecondaryOutput(); } -- 2.7.4