Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [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/gpu/GrAppliedClip.h" |
| 9 | #include "src/gpu/GrProcessorSet.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "src/gpu/GrUserStencilSettings.h" |
| 11 | #include "src/gpu/SkGr.h" |
Michael Ludwig | 663afe5 | 2019-06-03 16:46:19 -0400 | [diff] [blame] | 12 | #include "src/gpu/geometry/GrRect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 14 | |
| 15 | GrSimpleMeshDrawOpHelper::GrSimpleMeshDrawOpHelper(const MakeArgs& args, GrAAType aaType, |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 16 | InputFlags inputFlags) |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 17 | : fProcessors(args.fProcessorSet) |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 18 | , fPipelineFlags((GrPipeline::InputFlags)inputFlags) |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 19 | , fAAType((int)aaType) |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 20 | , fUsesLocalCoords(false) |
Brian Osman | 605c6d5 | 2019-03-15 12:10:35 -0400 | [diff] [blame] | 21 | , fCompatibleWithCoverageAsAlpha(false) { |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 22 | SkDEBUGCODE(fDidAnalysis = false); |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 23 | SkDEBUGCODE(fMadePipeline = false); |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 24 | if (GrAATypeIsHW(aaType)) { |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 25 | fPipelineFlags |= GrPipeline::InputFlags::kHWAntialias; |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 26 | } |
| 27 | } |
| 28 | |
| 29 | GrSimpleMeshDrawOpHelper::~GrSimpleMeshDrawOpHelper() { |
| 30 | if (fProcessors) { |
| 31 | fProcessors->~GrProcessorSet(); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | GrDrawOp::FixedFunctionFlags GrSimpleMeshDrawOpHelper::fixedFunctionFlags() const { |
| 36 | return GrAATypeIsHW((this->aaType())) ? GrDrawOp::FixedFunctionFlags::kUsesHWAA |
| 37 | : GrDrawOp::FixedFunctionFlags::kNone; |
| 38 | } |
| 39 | |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 40 | static bool none_as_coverage_aa_compatible(GrAAType aa1, GrAAType aa2) { |
| 41 | return (aa1 == GrAAType::kNone && aa2 == GrAAType::kCoverage) || |
| 42 | (aa1 == GrAAType::kCoverage && aa2 == GrAAType::kNone); |
| 43 | } |
| 44 | |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 45 | bool GrSimpleMeshDrawOpHelper::isCompatible(const GrSimpleMeshDrawOpHelper& that, |
| 46 | const GrCaps& caps, const SkRect& thisBounds, |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 47 | const SkRect& thatBounds, bool noneAsCoverageAA) const { |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 48 | if (SkToBool(fProcessors) != SkToBool(that.fProcessors)) { |
| 49 | return false; |
| 50 | } |
| 51 | if (fProcessors) { |
| 52 | if (*fProcessors != *that.fProcessors) { |
| 53 | return false; |
| 54 | } |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 55 | } |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 56 | bool result = fPipelineFlags == that.fPipelineFlags && (fAAType == that.fAAType || |
| 57 | (noneAsCoverageAA && none_as_coverage_aa_compatible(this->aaType(), that.aaType()))); |
Brian Osman | 605c6d5 | 2019-03-15 12:10:35 -0400 | [diff] [blame] | 58 | SkASSERT(!result || fCompatibleWithCoverageAsAlpha == that.fCompatibleWithCoverageAsAlpha); |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 59 | SkASSERT(!result || fUsesLocalCoords == that.fUsesLocalCoords); |
| 60 | return result; |
| 61 | } |
| 62 | |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 63 | GrProcessorSet::Analysis GrSimpleMeshDrawOpHelper::finalizeProcessors( |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 64 | const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage, |
| 65 | GrClampType clampType, GrProcessorAnalysisCoverage geometryCoverage, |
| 66 | SkPMColor4f* geometryColor, bool* wideColor) { |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 67 | GrProcessorAnalysisColor color = *geometryColor; |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 68 | auto result = this->finalizeProcessors( |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 69 | caps, clip, hasMixedSampledCoverage, clampType, geometryCoverage, &color); |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 70 | color.isConstant(geometryColor); |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 71 | if (wideColor) { |
| 72 | *wideColor = SkPMColor4fNeedsWideColor(*geometryColor, clampType, caps); |
| 73 | } |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 74 | return result; |
| 75 | } |
| 76 | |
| 77 | GrProcessorSet::Analysis GrSimpleMeshDrawOpHelper::finalizeProcessors( |
| 78 | const GrCaps& caps, const GrAppliedClip* clip, const GrUserStencilSettings* userStencil, |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 79 | bool hasMixedSampledCoverage, GrClampType clampType, |
| 80 | GrProcessorAnalysisCoverage geometryCoverage, GrProcessorAnalysisColor* geometryColor) { |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 81 | SkDEBUGCODE(fDidAnalysis = true); |
| 82 | GrProcessorSet::Analysis analysis; |
| 83 | if (fProcessors) { |
| 84 | GrProcessorAnalysisCoverage coverage = geometryCoverage; |
| 85 | if (GrProcessorAnalysisCoverage::kNone == coverage) { |
Chris Dalton | 6982400 | 2017-10-31 00:37:52 -0600 | [diff] [blame] | 86 | coverage = clip->numClipCoverageFragmentProcessors() |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 87 | ? GrProcessorAnalysisCoverage::kSingleChannel |
| 88 | : GrProcessorAnalysisCoverage::kNone; |
| 89 | } |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 90 | SkPMColor4f overrideColor; |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 91 | analysis = fProcessors->finalize(*geometryColor, coverage, clip, userStencil, |
| 92 | hasMixedSampledCoverage, caps, clampType, &overrideColor); |
Brian Salomon | 0088f94 | 2017-07-12 11:51:27 -0400 | [diff] [blame] | 93 | if (analysis.inputColorIsOverridden()) { |
| 94 | *geometryColor = overrideColor; |
| 95 | } |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 96 | } else { |
| 97 | analysis = GrProcessorSet::EmptySetAnalysis(); |
| 98 | } |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 99 | fUsesLocalCoords = analysis.usesLocalCoords(); |
Brian Osman | 605c6d5 | 2019-03-15 12:10:35 -0400 | [diff] [blame] | 100 | fCompatibleWithCoverageAsAlpha = analysis.isCompatibleWithCoverageAsAlpha(); |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 101 | return analysis; |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 104 | void GrSimpleMeshDrawOpHelper::executeDrawsAndUploads( |
| 105 | const GrOp* op, GrOpFlushState* flushState, const SkRect& chainBounds) { |
| 106 | if (fProcessors) { |
| 107 | flushState->executeDrawsAndUploadsForMeshDrawOp( |
| 108 | op, chainBounds, std::move(*fProcessors), fPipelineFlags); |
| 109 | } else { |
| 110 | flushState->executeDrawsAndUploadsForMeshDrawOp( |
| 111 | op, chainBounds, GrProcessorSet::MakeEmptySet(), fPipelineFlags); |
| 112 | } |
| 113 | } |
| 114 | |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 115 | #ifdef SK_DEBUG |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 116 | static void dump_pipeline_flags(GrPipeline::InputFlags flags, SkString* result) { |
| 117 | if (GrPipeline::InputFlags::kNone != flags) { |
| 118 | if (flags & GrPipeline::InputFlags::kSnapVerticesToPixelCenters) { |
| 119 | result->append("Snap vertices to pixel center.\n"); |
| 120 | } |
| 121 | if (flags & GrPipeline::InputFlags::kHWAntialias) { |
| 122 | result->append("HW Antialiasing enabled.\n"); |
| 123 | } |
| 124 | return; |
| 125 | } |
| 126 | result->append("No pipeline flags\n"); |
| 127 | } |
| 128 | |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 129 | SkString GrSimpleMeshDrawOpHelper::dumpInfo() const { |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 130 | const GrProcessorSet& processors = fProcessors ? *fProcessors : GrProcessorSet::EmptySet(); |
| 131 | SkString result = processors.dumpProcessors(); |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 132 | result.append("AA Type: "); |
| 133 | switch (this->aaType()) { |
| 134 | case GrAAType::kNone: |
| 135 | result.append(" none\n"); |
| 136 | break; |
| 137 | case GrAAType::kCoverage: |
| 138 | result.append(" coverage\n"); |
| 139 | break; |
| 140 | case GrAAType::kMSAA: |
| 141 | result.append(" msaa\n"); |
| 142 | break; |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 143 | } |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 144 | dump_pipeline_flags(fPipelineFlags, &result); |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 145 | return result; |
| 146 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 147 | #endif |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 148 | |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 149 | GrSimpleMeshDrawOpHelperWithStencil::GrSimpleMeshDrawOpHelperWithStencil( |
| 150 | const MakeArgs& args, GrAAType aaType, const GrUserStencilSettings* stencilSettings, |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 151 | InputFlags inputFlags) |
| 152 | : INHERITED(args, aaType, inputFlags) |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 153 | , fStencilSettings(stencilSettings ? stencilSettings : &GrUserStencilSettings::kUnused) {} |
| 154 | |
| 155 | GrDrawOp::FixedFunctionFlags GrSimpleMeshDrawOpHelperWithStencil::fixedFunctionFlags() const { |
| 156 | GrDrawOp::FixedFunctionFlags flags = INHERITED::fixedFunctionFlags(); |
| 157 | if (fStencilSettings != &GrUserStencilSettings::kUnused) { |
| 158 | flags |= GrDrawOp::FixedFunctionFlags::kUsesStencil; |
| 159 | } |
| 160 | return flags; |
| 161 | } |
| 162 | |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 163 | GrProcessorSet::Analysis GrSimpleMeshDrawOpHelperWithStencil::finalizeProcessors( |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 164 | const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage, |
| 165 | GrClampType clampType, GrProcessorAnalysisCoverage geometryCoverage, |
| 166 | SkPMColor4f* geometryColor, bool* wideColor) { |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 167 | GrProcessorAnalysisColor color = *geometryColor; |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 168 | auto result = this->finalizeProcessors( |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 169 | caps, clip, hasMixedSampledCoverage, clampType, geometryCoverage, &color); |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 170 | color.isConstant(geometryColor); |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 171 | if (wideColor) { |
| 172 | *wideColor = SkPMColor4fNeedsWideColor(*geometryColor, clampType, caps); |
| 173 | } |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 174 | return result; |
| 175 | } |
| 176 | |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 177 | bool GrSimpleMeshDrawOpHelperWithStencil::isCompatible( |
| 178 | const GrSimpleMeshDrawOpHelperWithStencil& that, const GrCaps& caps, |
Michael Ludwig | 6985853 | 2018-11-28 15:34:34 -0500 | [diff] [blame] | 179 | const SkRect& thisBounds, const SkRect& thatBounds, bool noneAsCoverageAA) const { |
| 180 | return INHERITED::isCompatible(that, caps, thisBounds, thatBounds, noneAsCoverageAA) && |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 181 | fStencilSettings == that.fStencilSettings; |
| 182 | } |
| 183 | |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 184 | void GrSimpleMeshDrawOpHelperWithStencil::executeDrawsAndUploads( |
| 185 | const GrOp* op, GrOpFlushState* flushState, const SkRect& chainBounds) { |
| 186 | if (fProcessors) { |
| 187 | flushState->executeDrawsAndUploadsForMeshDrawOp( |
| 188 | op, chainBounds, std::move(*fProcessors), fPipelineFlags, fStencilSettings); |
| 189 | } else { |
| 190 | flushState->executeDrawsAndUploadsForMeshDrawOp( |
| 191 | op, chainBounds, GrProcessorSet::MakeEmptySet(), fPipelineFlags, fStencilSettings); |
| 192 | } |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 193 | } |
| 194 | |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 195 | #ifdef SK_DEBUG |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 196 | SkString GrSimpleMeshDrawOpHelperWithStencil::dumpInfo() const { |
| 197 | SkString result = INHERITED::dumpInfo(); |
| 198 | result.appendf("Stencil settings: %s\n", (fStencilSettings ? "yes" : "no")); |
| 199 | return result; |
| 200 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 201 | #endif |