Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/core/SkBlendModePriv.h" |
| 9 | #include "src/gpu/GrAppliedClip.h" |
| 10 | #include "src/gpu/GrCaps.h" |
| 11 | #include "src/gpu/GrProcessorSet.h" |
| 12 | #include "src/gpu/GrUserStencilSettings.h" |
| 13 | #include "src/gpu/GrXferProcessor.h" |
| 14 | #include "src/gpu/effects/GrPorterDuffXferProcessor.h" |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 15 | |
Brian Salomon | 292bf7a | 2017-05-17 09:43:55 -0400 | [diff] [blame] | 16 | const GrProcessorSet& GrProcessorSet::EmptySet() { |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 17 | static GrProcessorSet gEmpty(GrProcessorSet::Empty::kEmpty); |
Brian Salomon | 292bf7a | 2017-05-17 09:43:55 -0400 | [diff] [blame] | 18 | return gEmpty; |
| 19 | } |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 20 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 21 | GrProcessorSet GrProcessorSet::MakeEmptySet() { |
| 22 | return GrProcessorSet(GrProcessorSet::Empty::kEmpty); |
| 23 | } |
| 24 | |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 25 | GrProcessorSet::GrProcessorSet(GrPaint&& paint) : fXP(paint.getXPFactory()) { |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 26 | fColorFragmentProcessor = std::move(paint.fColorFragmentProcessor); |
| 27 | fCoverageFragmentProcessor = std::move(paint.fCoverageFragmentProcessor); |
John Stiles | 5933d7d | 2020-07-21 12:28:35 -0400 | [diff] [blame] | 28 | |
Mike Klein | 1688507 | 2018-12-11 09:54:31 -0500 | [diff] [blame] | 29 | SkDEBUGCODE(paint.fAlive = false;) |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 30 | } |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 31 | |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 32 | GrProcessorSet::GrProcessorSet(SkBlendMode mode) : fXP(SkBlendMode_AsXPFactory(mode)) {} |
Brian Salomon | 477d0ef | 2017-07-14 10:12:26 -0400 | [diff] [blame] | 33 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 34 | GrProcessorSet::GrProcessorSet(std::unique_ptr<GrFragmentProcessor> colorFP) |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 35 | : fXP((const GrXPFactory*)nullptr) { |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 36 | SkASSERT(colorFP); |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 37 | fColorFragmentProcessor = std::move(colorFP); |
Brian Salomon | 82ddc94 | 2017-07-14 12:00:13 -0400 | [diff] [blame] | 38 | } |
| 39 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 40 | GrProcessorSet::GrProcessorSet(GrProcessorSet&& that) |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 41 | : fColorFragmentProcessor(std::move(that.fColorFragmentProcessor)) |
| 42 | , fCoverageFragmentProcessor(std::move(that.fCoverageFragmentProcessor)) |
| 43 | , fXP(std::move(that.fXP)) |
| 44 | , fFlags(that.fFlags) {} |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 45 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 46 | GrProcessorSet::~GrProcessorSet() { |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 47 | if (this->isFinalized() && this->xferProcessor()) { |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 48 | this->xferProcessor()->unref(); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
John Stiles | 8d9bf64 | 2020-08-12 15:07:45 -0400 | [diff] [blame] | 52 | #if GR_TEST_UTILS |
Brian Salomon | 82dfd3d | 2017-06-14 12:30:35 -0400 | [diff] [blame] | 53 | SkString GrProcessorSet::dumpProcessors() const { |
| 54 | SkString result; |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 55 | if (this->hasColorFragmentProcessor()) { |
| 56 | result.append("Color Fragment Processor:\n"); |
John Stiles | ba1879d | 2020-08-11 13:58:32 -0400 | [diff] [blame] | 57 | result += this->colorFragmentProcessor()->dumpTreeInfo(); |
Brian Salomon | 82dfd3d | 2017-06-14 12:30:35 -0400 | [diff] [blame] | 58 | } else { |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 59 | result.append("No color fragment processor.\n"); |
| 60 | } |
John Stiles | df9ed89 | 2020-08-12 18:07:26 -0400 | [diff] [blame] | 61 | if (this->hasCoverageFragmentProcessor()) { |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 62 | result.append("Coverage Fragment Processor:\n"); |
John Stiles | ba1879d | 2020-08-11 13:58:32 -0400 | [diff] [blame] | 63 | result += this->coverageFragmentProcessor()->dumpTreeInfo(); |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 64 | } else { |
| 65 | result.append("No coverage fragment processors.\n"); |
Brian Salomon | 82dfd3d | 2017-06-14 12:30:35 -0400 | [diff] [blame] | 66 | } |
| 67 | if (this->isFinalized()) { |
| 68 | result.append("Xfer Processor: "); |
| 69 | if (this->xferProcessor()) { |
| 70 | result.appendf("%s\n", this->xferProcessor()->name()); |
| 71 | } else { |
| 72 | result.append("SrcOver\n"); |
| 73 | } |
| 74 | } else { |
Derek Sollenberger | 08c0629 | 2019-01-24 16:30:28 +0000 | [diff] [blame] | 75 | result.append("XP Factory dumping not implemented.\n"); |
Brian Salomon | 82dfd3d | 2017-06-14 12:30:35 -0400 | [diff] [blame] | 76 | } |
| 77 | return result; |
| 78 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 79 | #endif |
Brian Salomon | 82dfd3d | 2017-06-14 12:30:35 -0400 | [diff] [blame] | 80 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 81 | bool GrProcessorSet::operator==(const GrProcessorSet& that) const { |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 82 | SkASSERT(this->isFinalized()); |
| 83 | SkASSERT(that.isFinalized()); |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 84 | if (((fFlags ^ that.fFlags) & ~kFinalized_Flag) || |
| 85 | this->hasColorFragmentProcessor() != that.hasColorFragmentProcessor() || |
| 86 | this->hasCoverageFragmentProcessor() != that.hasCoverageFragmentProcessor()) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 87 | return false; |
| 88 | } |
Brian Salomon | 70288c0 | 2017-03-24 12:27:17 -0400 | [diff] [blame] | 89 | |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 90 | if (this->hasColorFragmentProcessor()) { |
| 91 | if (!colorFragmentProcessor()->isEqual(*that.colorFragmentProcessor())) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 92 | return false; |
| 93 | } |
| 94 | } |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 95 | |
| 96 | if (this->hasCoverageFragmentProcessor()) { |
| 97 | if (!coverageFragmentProcessor()->isEqual(*that.coverageFragmentProcessor())) { |
| 98 | return false; |
| 99 | } |
| 100 | } |
| 101 | |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 102 | // Most of the time both of these are null |
| 103 | if (!this->xferProcessor() && !that.xferProcessor()) { |
| 104 | return true; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 105 | } |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 106 | const GrXferProcessor& thisXP = this->xferProcessor() |
| 107 | ? *this->xferProcessor() |
| 108 | : GrPorterDuffXPFactory::SimpleSrcOverXP(); |
| 109 | const GrXferProcessor& thatXP = that.xferProcessor() |
| 110 | ? *that.xferProcessor() |
| 111 | : GrPorterDuffXPFactory::SimpleSrcOverXP(); |
| 112 | return thisXP.isEqual(thatXP); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 113 | } |
| 114 | |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 115 | GrProcessorSet::Analysis GrProcessorSet::finalize( |
| 116 | const GrProcessorAnalysisColor& colorInput, const GrProcessorAnalysisCoverage coverageInput, |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 117 | const GrAppliedClip* clip, const GrUserStencilSettings* userStencil, |
| 118 | bool hasMixedSampledCoverage, const GrCaps& caps, GrClampType clampType, |
| 119 | SkPMColor4f* overrideInputColor) { |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 120 | SkASSERT(!this->isFinalized()); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 121 | |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 122 | GrProcessorSet::Analysis analysis; |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 123 | analysis.fCompatibleWithCoverageAsAlpha = GrProcessorAnalysisCoverage::kLCD != coverageInput; |
| 124 | |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 125 | GrColorFragmentProcessorAnalysis colorAnalysis(colorInput, &fColorFragmentProcessor, |
| 126 | this->hasColorFragmentProcessor() ? 1 : 0); |
| 127 | bool hasCoverageFP = this->hasCoverageFragmentProcessor(); |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 128 | bool coverageUsesLocalCoords = false; |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 129 | if (hasCoverageFP) { |
| 130 | if (!fCoverageFragmentProcessor->compatibleWithCoverageAsAlpha()) { |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 131 | analysis.fCompatibleWithCoverageAsAlpha = false; |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 132 | } |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 133 | coverageUsesLocalCoords |= fCoverageFragmentProcessor->usesVaryingCoords(); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 134 | } |
John Stiles | 59e18dc | 2020-07-22 18:18:12 -0400 | [diff] [blame] | 135 | if (clip && clip->hasCoverageFragmentProcessor()) { |
| 136 | hasCoverageFP = true; |
| 137 | const GrFragmentProcessor* clipFP = clip->coverageFragmentProcessor(); |
| 138 | analysis.fCompatibleWithCoverageAsAlpha &= clipFP->compatibleWithCoverageAsAlpha(); |
| 139 | coverageUsesLocalCoords |= clipFP->usesVaryingCoords(); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 140 | } |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 141 | int colorFPsToEliminate = colorAnalysis.initialProcessorsToEliminate(overrideInputColor); |
| 142 | analysis.fInputColorType = static_cast<Analysis::PackedInputColorType>( |
| 143 | colorFPsToEliminate ? Analysis::kOverridden_InputColorType |
| 144 | : Analysis::kOriginal_InputColorType); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 145 | |
Brian Salomon | a811b12 | 2017-03-30 08:21:32 -0400 | [diff] [blame] | 146 | GrProcessorAnalysisCoverage outputCoverage; |
| 147 | if (GrProcessorAnalysisCoverage::kLCD == coverageInput) { |
| 148 | outputCoverage = GrProcessorAnalysisCoverage::kLCD; |
| 149 | } else if (hasCoverageFP || GrProcessorAnalysisCoverage::kSingleChannel == coverageInput) { |
| 150 | outputCoverage = GrProcessorAnalysisCoverage::kSingleChannel; |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 151 | } else { |
Brian Salomon | a811b12 | 2017-03-30 08:21:32 -0400 | [diff] [blame] | 152 | outputCoverage = GrProcessorAnalysisCoverage::kNone; |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 153 | } |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 154 | |
| 155 | GrXPFactory::AnalysisProperties props = GrXPFactory::GetAnalysisProperties( |
Chris Dalton | 2833ec6 | 2020-12-03 01:43:08 -0700 | [diff] [blame] | 156 | this->xpFactory(), colorAnalysis.outputColor(), outputCoverage, hasMixedSampledCoverage, |
| 157 | caps, clampType); |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 158 | analysis.fRequiresDstTexture = |
| 159 | SkToBool(props & GrXPFactory::AnalysisProperties::kRequiresDstTexture); |
| 160 | analysis.fCompatibleWithCoverageAsAlpha &= |
Brian Osman | 605c6d5 | 2019-03-15 12:10:35 -0400 | [diff] [blame] | 161 | SkToBool(props & GrXPFactory::AnalysisProperties::kCompatibleWithCoverageAsAlpha); |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 162 | analysis.fRequiresNonOverlappingDraws = |
| 163 | SkToBool(props & GrXPFactory::AnalysisProperties::kRequiresNonOverlappingDraws); |
Greg Daniel | 9a18b08 | 2020-08-14 14:03:50 -0400 | [diff] [blame] | 164 | analysis.fUsesNonCoherentHWBlending = |
| 165 | SkToBool(props & GrXPFactory::AnalysisProperties::kUsesNonCoherentHWBlending); |
Chris Dalton | f2fb80f | 2020-12-03 12:37:59 -0700 | [diff] [blame] | 166 | analysis.fUnaffectedByDstValue = |
| 167 | SkToBool(props & GrXPFactory::AnalysisProperties::kUnaffectedByDstValue); |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 168 | if (props & GrXPFactory::AnalysisProperties::kIgnoresInputColor) { |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 169 | colorFPsToEliminate = this->hasColorFragmentProcessor() ? 1 : 0; |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 170 | analysis.fInputColorType = |
| 171 | static_cast<Analysis::PackedInputColorType>(Analysis::kIgnored_InputColorType); |
| 172 | analysis.fUsesLocalCoords = coverageUsesLocalCoords; |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 173 | } else { |
Michael Ludwig | 0cb2fde | 2019-05-28 13:14:41 -0400 | [diff] [blame] | 174 | analysis.fCompatibleWithCoverageAsAlpha &= |
| 175 | colorAnalysis.allProcessorsCompatibleWithCoverageAsAlpha(); |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 176 | analysis.fUsesLocalCoords = coverageUsesLocalCoords | colorAnalysis.usesLocalCoords(); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 177 | } |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 178 | if (colorFPsToEliminate) { |
| 179 | SkASSERT(colorFPsToEliminate == 1); |
| 180 | fColorFragmentProcessor = nullptr; |
Brian Salomon | 5dac9b3 | 2017-04-08 02:53:30 +0000 | [diff] [blame] | 181 | } |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 182 | analysis.fHasColorFragmentProcessor = this->hasColorFragmentProcessor(); |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 183 | |
| 184 | auto xp = GrXPFactory::MakeXferProcessor(this->xpFactory(), colorAnalysis.outputColor(), |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 185 | outputCoverage, hasMixedSampledCoverage, caps, |
| 186 | clampType); |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 187 | fXP.fProcessor = xp.release(); |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 188 | |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 189 | fFlags |= kFinalized_Flag; |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 190 | analysis.fIsInitialized = true; |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 191 | #ifdef SK_DEBUG |
| 192 | bool hasXferBarrier = |
| 193 | fXP.fProcessor && |
| 194 | GrXferBarrierType::kNone_GrXferBarrierType != fXP.fProcessor->xferBarrierType(caps); |
| 195 | bool needsNonOverlappingDraws = analysis.fRequiresDstTexture || hasXferBarrier; |
| 196 | SkASSERT(analysis.fRequiresNonOverlappingDraws == needsNonOverlappingDraws); |
| 197 | #endif |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 198 | return analysis; |
Brian Salomon | 70288c0 | 2017-03-24 12:27:17 -0400 | [diff] [blame] | 199 | } |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 200 | |
| 201 | void GrProcessorSet::visitProxies(const GrOp::VisitProxyFunc& func) const { |
John Stiles | 29d3e22 | 2020-07-21 17:28:12 -0400 | [diff] [blame] | 202 | if (this->hasColorFragmentProcessor()) { |
| 203 | fColorFragmentProcessor->visitProxies(func); |
| 204 | } |
| 205 | if (this->hasCoverageFragmentProcessor()) { |
| 206 | fCoverageFragmentProcessor->visitProxies(func); |
Brian Salomon | c241b58 | 2019-11-27 08:57:17 -0500 | [diff] [blame] | 207 | } |
| 208 | } |