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