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 | |
| 8 | #include "GrSimpleMeshDrawOpHelper.h" |
| 9 | #include "GrAppliedClip.h" |
| 10 | #include "GrProcessorSet.h" |
| 11 | #include "GrRect.h" |
| 12 | #include "GrUserStencilSettings.h" |
| 13 | |
| 14 | GrSimpleMeshDrawOpHelper::GrSimpleMeshDrawOpHelper(const MakeArgs& args, GrAAType aaType, |
| 15 | Flags flags) |
| 16 | : fProcessors(args.fProcessorSet) |
Brian Osman | 9aa30c6 | 2018-07-02 15:21:46 -0400 | [diff] [blame] | 17 | , fPipelineFlags(0) |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 18 | , fAAType((int)aaType) |
| 19 | , fRequiresDstTexture(false) |
| 20 | , fUsesLocalCoords(false) |
| 21 | , fCompatibleWithAlphaAsCoveage(false) { |
| 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)) { |
| 25 | fPipelineFlags |= GrPipeline::kHWAntialias_Flag; |
| 26 | } |
| 27 | if (flags & Flags::kSnapVerticesToPixelCenters) { |
| 28 | fPipelineFlags |= GrPipeline::kSnapVerticesToPixelCenters_Flag; |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | GrSimpleMeshDrawOpHelper::~GrSimpleMeshDrawOpHelper() { |
| 33 | if (fProcessors) { |
| 34 | fProcessors->~GrProcessorSet(); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | GrDrawOp::FixedFunctionFlags GrSimpleMeshDrawOpHelper::fixedFunctionFlags() const { |
| 39 | return GrAATypeIsHW((this->aaType())) ? GrDrawOp::FixedFunctionFlags::kUsesHWAA |
| 40 | : GrDrawOp::FixedFunctionFlags::kNone; |
| 41 | } |
| 42 | |
| 43 | bool GrSimpleMeshDrawOpHelper::isCompatible(const GrSimpleMeshDrawOpHelper& that, |
| 44 | const GrCaps& caps, const SkRect& thisBounds, |
| 45 | const SkRect& thatBounds) const { |
| 46 | if (SkToBool(fProcessors) != SkToBool(that.fProcessors)) { |
| 47 | return false; |
| 48 | } |
| 49 | if (fProcessors) { |
| 50 | if (*fProcessors != *that.fProcessors) { |
| 51 | return false; |
| 52 | } |
| 53 | if (fRequiresDstTexture || |
| 54 | (fProcessors->xferProcessor() && fProcessors->xferProcessor()->xferBarrierType(caps))) { |
| 55 | if (GrRectsTouchOrOverlap(thisBounds, thatBounds)) { |
| 56 | return false; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | bool result = fPipelineFlags == that.fPipelineFlags && fAAType == that.fAAType; |
| 61 | SkASSERT(!result || fCompatibleWithAlphaAsCoveage == that.fCompatibleWithAlphaAsCoveage); |
| 62 | SkASSERT(!result || fUsesLocalCoords == that.fUsesLocalCoords); |
| 63 | return result; |
| 64 | } |
| 65 | |
| 66 | GrDrawOp::RequiresDstTexture GrSimpleMeshDrawOpHelper::xpRequiresDstTexture( |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 67 | const GrCaps& caps, const GrAppliedClip* clip, GrProcessorAnalysisCoverage geometryCoverage, |
| 68 | GrProcessorAnalysisColor* geometryColor) { |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 69 | SkDEBUGCODE(fDidAnalysis = true); |
| 70 | GrProcessorSet::Analysis analysis; |
| 71 | if (fProcessors) { |
| 72 | GrProcessorAnalysisCoverage coverage = geometryCoverage; |
| 73 | if (GrProcessorAnalysisCoverage::kNone == coverage) { |
Chris Dalton | 6982400 | 2017-10-31 00:37:52 -0600 | [diff] [blame] | 74 | coverage = clip->numClipCoverageFragmentProcessors() |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 75 | ? GrProcessorAnalysisCoverage::kSingleChannel |
| 76 | : GrProcessorAnalysisCoverage::kNone; |
| 77 | } |
| 78 | bool isMixedSamples = this->aaType() == GrAAType::kMixedSamples; |
Brian Salomon | 0088f94 | 2017-07-12 11:51:27 -0400 | [diff] [blame] | 79 | GrColor overrideColor; |
| 80 | analysis = fProcessors->finalize(*geometryColor, coverage, clip, isMixedSamples, caps, |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 81 | &overrideColor); |
Brian Salomon | 0088f94 | 2017-07-12 11:51:27 -0400 | [diff] [blame] | 82 | if (analysis.inputColorIsOverridden()) { |
| 83 | *geometryColor = overrideColor; |
| 84 | } |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 85 | } else { |
| 86 | analysis = GrProcessorSet::EmptySetAnalysis(); |
| 87 | } |
| 88 | fRequiresDstTexture = analysis.requiresDstTexture(); |
| 89 | fUsesLocalCoords = analysis.usesLocalCoords(); |
| 90 | fCompatibleWithAlphaAsCoveage = analysis.isCompatibleWithCoverageAsAlpha(); |
| 91 | return analysis.requiresDstTexture() ? GrDrawOp::RequiresDstTexture::kYes |
| 92 | : GrDrawOp::RequiresDstTexture::kNo; |
| 93 | } |
| 94 | |
Brian Salomon | 0088f94 | 2017-07-12 11:51:27 -0400 | [diff] [blame] | 95 | GrDrawOp::RequiresDstTexture GrSimpleMeshDrawOpHelper::xpRequiresDstTexture( |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 96 | const GrCaps& caps, const GrAppliedClip* clip, GrProcessorAnalysisCoverage geometryCoverage, |
| 97 | GrColor* geometryColor) { |
Brian Salomon | 0088f94 | 2017-07-12 11:51:27 -0400 | [diff] [blame] | 98 | GrProcessorAnalysisColor color = *geometryColor; |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 99 | auto result = this->xpRequiresDstTexture(caps, clip, geometryCoverage, &color); |
Brian Salomon | 0088f94 | 2017-07-12 11:51:27 -0400 | [diff] [blame] | 100 | color.isConstant(geometryColor); |
| 101 | return result; |
| 102 | } |
| 103 | |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 104 | SkString GrSimpleMeshDrawOpHelper::dumpInfo() const { |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 105 | const GrProcessorSet& processors = fProcessors ? *fProcessors : GrProcessorSet::EmptySet(); |
| 106 | SkString result = processors.dumpProcessors(); |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 107 | result.append("AA Type: "); |
| 108 | switch (this->aaType()) { |
| 109 | case GrAAType::kNone: |
| 110 | result.append(" none\n"); |
| 111 | break; |
| 112 | case GrAAType::kCoverage: |
| 113 | result.append(" coverage\n"); |
| 114 | break; |
| 115 | case GrAAType::kMSAA: |
| 116 | result.append(" msaa\n"); |
| 117 | break; |
| 118 | case GrAAType::kMixedSamples: |
| 119 | result.append(" mixed samples\n"); |
| 120 | break; |
| 121 | } |
| 122 | result.append(GrPipeline::DumpFlags(fPipelineFlags)); |
| 123 | return result; |
| 124 | } |
| 125 | |
| 126 | GrPipeline::InitArgs GrSimpleMeshDrawOpHelper::pipelineInitArgs( |
| 127 | GrMeshDrawOp::Target* target) const { |
| 128 | GrPipeline::InitArgs args; |
| 129 | args.fFlags = this->pipelineFlags(); |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 130 | args.fProxy = target->proxy(); |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 131 | args.fDstProxy = target->dstProxy(); |
| 132 | args.fCaps = &target->caps(); |
| 133 | args.fResourceProvider = target->resourceProvider(); |
| 134 | return args; |
| 135 | } |
| 136 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 137 | auto GrSimpleMeshDrawOpHelper::internalMakePipeline(GrMeshDrawOp::Target* target, |
| 138 | const GrPipeline::InitArgs& args) |
| 139 | -> PipelineAndFixedDynamicState { |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 140 | // A caller really should only call this once as the processor set and applied clip get |
| 141 | // moved into the GrPipeline. |
| 142 | SkASSERT(!fMadePipeline); |
| 143 | SkDEBUGCODE(fMadePipeline = true); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 144 | auto clip = target->detachAppliedClip(); |
Brian Salomon | f513682 | 2018-08-03 09:09:36 -0400 | [diff] [blame^] | 145 | GrPipeline::FixedDynamicState* fixedDynamicState = nullptr; |
| 146 | if (clip.scissorState().enabled()) { |
| 147 | fixedDynamicState = target->allocFixedDynamicState(clip.scissorState().rect()); |
| 148 | } |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 149 | if (fProcessors) { |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 150 | return {target->allocPipeline(args, std::move(*fProcessors), std::move(clip)), |
Brian Salomon | f513682 | 2018-08-03 09:09:36 -0400 | [diff] [blame^] | 151 | fixedDynamicState}; |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 152 | } else { |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 153 | return {target->allocPipeline(args, GrProcessorSet::MakeEmptySet(), std::move(clip)), |
Brian Salomon | f513682 | 2018-08-03 09:09:36 -0400 | [diff] [blame^] | 154 | fixedDynamicState}; |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 158 | GrSimpleMeshDrawOpHelperWithStencil::GrSimpleMeshDrawOpHelperWithStencil( |
| 159 | const MakeArgs& args, GrAAType aaType, const GrUserStencilSettings* stencilSettings, |
| 160 | Flags flags) |
| 161 | : INHERITED(args, aaType, flags) |
| 162 | , fStencilSettings(stencilSettings ? stencilSettings : &GrUserStencilSettings::kUnused) {} |
| 163 | |
| 164 | GrDrawOp::FixedFunctionFlags GrSimpleMeshDrawOpHelperWithStencil::fixedFunctionFlags() const { |
| 165 | GrDrawOp::FixedFunctionFlags flags = INHERITED::fixedFunctionFlags(); |
| 166 | if (fStencilSettings != &GrUserStencilSettings::kUnused) { |
| 167 | flags |= GrDrawOp::FixedFunctionFlags::kUsesStencil; |
| 168 | } |
| 169 | return flags; |
| 170 | } |
| 171 | |
| 172 | bool GrSimpleMeshDrawOpHelperWithStencil::isCompatible( |
| 173 | const GrSimpleMeshDrawOpHelperWithStencil& that, const GrCaps& caps, |
| 174 | const SkRect& thisBounds, const SkRect& thatBounds) const { |
| 175 | return INHERITED::isCompatible(that, caps, thisBounds, thatBounds) && |
| 176 | fStencilSettings == that.fStencilSettings; |
| 177 | } |
| 178 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 179 | auto GrSimpleMeshDrawOpHelperWithStencil::makePipeline(GrMeshDrawOp::Target* target) |
| 180 | -> PipelineAndFixedDynamicState { |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 181 | auto args = INHERITED::pipelineInitArgs(target); |
| 182 | args.fUserStencil = fStencilSettings; |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 183 | return this->internalMakePipeline(target, args); |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | SkString GrSimpleMeshDrawOpHelperWithStencil::dumpInfo() const { |
| 187 | SkString result = INHERITED::dumpInfo(); |
| 188 | result.appendf("Stencil settings: %s\n", (fStencilSettings ? "yes" : "no")); |
| 189 | return result; |
| 190 | } |