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 Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 79 | SkPMColor4f overrideColor; |
Brian Salomon | 0088f94 | 2017-07-12 11:51:27 -0400 | [diff] [blame] | 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, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 97 | SkPMColor4f* 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 Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame^] | 104 | #ifdef SK_DEBUG |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 105 | SkString GrSimpleMeshDrawOpHelper::dumpInfo() const { |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 106 | const GrProcessorSet& processors = fProcessors ? *fProcessors : GrProcessorSet::EmptySet(); |
| 107 | SkString result = processors.dumpProcessors(); |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 108 | result.append("AA Type: "); |
| 109 | switch (this->aaType()) { |
| 110 | case GrAAType::kNone: |
| 111 | result.append(" none\n"); |
| 112 | break; |
| 113 | case GrAAType::kCoverage: |
| 114 | result.append(" coverage\n"); |
| 115 | break; |
| 116 | case GrAAType::kMSAA: |
| 117 | result.append(" msaa\n"); |
| 118 | break; |
| 119 | case GrAAType::kMixedSamples: |
| 120 | result.append(" mixed samples\n"); |
| 121 | break; |
| 122 | } |
| 123 | result.append(GrPipeline::DumpFlags(fPipelineFlags)); |
| 124 | return result; |
| 125 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame^] | 126 | #endif |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 127 | |
| 128 | GrPipeline::InitArgs GrSimpleMeshDrawOpHelper::pipelineInitArgs( |
| 129 | GrMeshDrawOp::Target* target) const { |
| 130 | GrPipeline::InitArgs args; |
| 131 | args.fFlags = this->pipelineFlags(); |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 132 | args.fProxy = target->proxy(); |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 133 | args.fDstProxy = target->dstProxy(); |
| 134 | args.fCaps = &target->caps(); |
| 135 | args.fResourceProvider = target->resourceProvider(); |
| 136 | return args; |
| 137 | } |
| 138 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 139 | auto GrSimpleMeshDrawOpHelper::internalMakePipeline(GrMeshDrawOp::Target* target, |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 140 | const GrPipeline::InitArgs& args, |
| 141 | int numPrimitiveProcessorProxies) |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 142 | -> PipelineAndFixedDynamicState { |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 143 | // A caller really should only call this once as the processor set and applied clip get |
| 144 | // moved into the GrPipeline. |
| 145 | SkASSERT(!fMadePipeline); |
| 146 | SkDEBUGCODE(fMadePipeline = true); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 147 | auto clip = target->detachAppliedClip(); |
Brian Salomon | f513682 | 2018-08-03 09:09:36 -0400 | [diff] [blame] | 148 | GrPipeline::FixedDynamicState* fixedDynamicState = nullptr; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 149 | if (clip.scissorState().enabled() || numPrimitiveProcessorProxies) { |
Brian Salomon | f513682 | 2018-08-03 09:09:36 -0400 | [diff] [blame] | 150 | fixedDynamicState = target->allocFixedDynamicState(clip.scissorState().rect()); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 151 | if (numPrimitiveProcessorProxies) { |
| 152 | fixedDynamicState->fPrimitiveProcessorTextures = |
| 153 | target->allocPrimitiveProcessorTextureArray(numPrimitiveProcessorProxies); |
| 154 | } |
Brian Salomon | f513682 | 2018-08-03 09:09:36 -0400 | [diff] [blame] | 155 | } |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 156 | if (fProcessors) { |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 157 | return {target->allocPipeline(args, std::move(*fProcessors), std::move(clip)), |
Brian Salomon | f513682 | 2018-08-03 09:09:36 -0400 | [diff] [blame] | 158 | fixedDynamicState}; |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 159 | } else { |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 160 | return {target->allocPipeline(args, GrProcessorSet::MakeEmptySet(), std::move(clip)), |
Brian Salomon | f513682 | 2018-08-03 09:09:36 -0400 | [diff] [blame] | 161 | fixedDynamicState}; |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 165 | GrSimpleMeshDrawOpHelperWithStencil::GrSimpleMeshDrawOpHelperWithStencil( |
| 166 | const MakeArgs& args, GrAAType aaType, const GrUserStencilSettings* stencilSettings, |
| 167 | Flags flags) |
| 168 | : INHERITED(args, aaType, flags) |
| 169 | , fStencilSettings(stencilSettings ? stencilSettings : &GrUserStencilSettings::kUnused) {} |
| 170 | |
| 171 | GrDrawOp::FixedFunctionFlags GrSimpleMeshDrawOpHelperWithStencil::fixedFunctionFlags() const { |
| 172 | GrDrawOp::FixedFunctionFlags flags = INHERITED::fixedFunctionFlags(); |
| 173 | if (fStencilSettings != &GrUserStencilSettings::kUnused) { |
| 174 | flags |= GrDrawOp::FixedFunctionFlags::kUsesStencil; |
| 175 | } |
| 176 | return flags; |
| 177 | } |
| 178 | |
| 179 | bool GrSimpleMeshDrawOpHelperWithStencil::isCompatible( |
| 180 | const GrSimpleMeshDrawOpHelperWithStencil& that, const GrCaps& caps, |
| 181 | const SkRect& thisBounds, const SkRect& thatBounds) const { |
| 182 | return INHERITED::isCompatible(that, caps, thisBounds, thatBounds) && |
| 183 | fStencilSettings == that.fStencilSettings; |
| 184 | } |
| 185 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 186 | auto GrSimpleMeshDrawOpHelperWithStencil::makePipeline(GrMeshDrawOp::Target* target, |
| 187 | int numPrimitiveProcessorTextures) |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 188 | -> PipelineAndFixedDynamicState { |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 189 | auto args = INHERITED::pipelineInitArgs(target); |
| 190 | args.fUserStencil = fStencilSettings; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 191 | return this->internalMakePipeline(target, args, numPrimitiveProcessorTextures); |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 192 | } |
| 193 | |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame^] | 194 | #ifdef SK_DEBUG |
Brian Salomon | b4d6106 | 2017-07-12 11:24:41 -0400 | [diff] [blame] | 195 | SkString GrSimpleMeshDrawOpHelperWithStencil::dumpInfo() const { |
| 196 | SkString result = INHERITED::dumpInfo(); |
| 197 | result.appendf("Stencil settings: %s\n", (fStencilSettings ? "yes" : "no")); |
| 198 | return result; |
| 199 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame^] | 200 | #endif |