blob: f1692e696adf9ece7e0c9e1da1b49aa994f9efc0 [file] [log] [blame]
Brian Salomonb4d61062017-07-12 11:24:41 -04001/*
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
14GrSimpleMeshDrawOpHelper::GrSimpleMeshDrawOpHelper(const MakeArgs& args, GrAAType aaType,
15 Flags flags)
16 : fProcessors(args.fProcessorSet)
Brian Osman9aa30c62018-07-02 15:21:46 -040017 , fPipelineFlags(0)
Brian Salomonb4d61062017-07-12 11:24:41 -040018 , fAAType((int)aaType)
19 , fRequiresDstTexture(false)
20 , fUsesLocalCoords(false)
21 , fCompatibleWithAlphaAsCoveage(false) {
22 SkDEBUGCODE(fDidAnalysis = false);
Brian Salomonbfd18cd2017-08-09 16:27:09 -040023 SkDEBUGCODE(fMadePipeline = false);
Brian Salomonb4d61062017-07-12 11:24:41 -040024 if (GrAATypeIsHW(aaType)) {
25 fPipelineFlags |= GrPipeline::kHWAntialias_Flag;
26 }
27 if (flags & Flags::kSnapVerticesToPixelCenters) {
28 fPipelineFlags |= GrPipeline::kSnapVerticesToPixelCenters_Flag;
29 }
30}
31
32GrSimpleMeshDrawOpHelper::~GrSimpleMeshDrawOpHelper() {
33 if (fProcessors) {
34 fProcessors->~GrProcessorSet();
35 }
36}
37
38GrDrawOp::FixedFunctionFlags GrSimpleMeshDrawOpHelper::fixedFunctionFlags() const {
39 return GrAATypeIsHW((this->aaType())) ? GrDrawOp::FixedFunctionFlags::kUsesHWAA
40 : GrDrawOp::FixedFunctionFlags::kNone;
41}
42
43bool 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
66GrDrawOp::RequiresDstTexture GrSimpleMeshDrawOpHelper::xpRequiresDstTexture(
Brian Osman532b3f92018-07-11 10:02:07 -040067 const GrCaps& caps, const GrAppliedClip* clip, GrProcessorAnalysisCoverage geometryCoverage,
68 GrProcessorAnalysisColor* geometryColor) {
Brian Salomonb4d61062017-07-12 11:24:41 -040069 SkDEBUGCODE(fDidAnalysis = true);
70 GrProcessorSet::Analysis analysis;
71 if (fProcessors) {
72 GrProcessorAnalysisCoverage coverage = geometryCoverage;
73 if (GrProcessorAnalysisCoverage::kNone == coverage) {
Chris Dalton69824002017-10-31 00:37:52 -060074 coverage = clip->numClipCoverageFragmentProcessors()
Brian Salomonb4d61062017-07-12 11:24:41 -040075 ? GrProcessorAnalysisCoverage::kSingleChannel
76 : GrProcessorAnalysisCoverage::kNone;
77 }
78 bool isMixedSamples = this->aaType() == GrAAType::kMixedSamples;
Brian Salomon0088f942017-07-12 11:51:27 -040079 GrColor overrideColor;
80 analysis = fProcessors->finalize(*geometryColor, coverage, clip, isMixedSamples, caps,
Brian Osman532b3f92018-07-11 10:02:07 -040081 &overrideColor);
Brian Salomon0088f942017-07-12 11:51:27 -040082 if (analysis.inputColorIsOverridden()) {
83 *geometryColor = overrideColor;
84 }
Brian Salomonb4d61062017-07-12 11:24:41 -040085 } 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 Salomon0088f942017-07-12 11:51:27 -040095GrDrawOp::RequiresDstTexture GrSimpleMeshDrawOpHelper::xpRequiresDstTexture(
Brian Osman532b3f92018-07-11 10:02:07 -040096 const GrCaps& caps, const GrAppliedClip* clip, GrProcessorAnalysisCoverage geometryCoverage,
97 GrColor* geometryColor) {
Brian Salomon0088f942017-07-12 11:51:27 -040098 GrProcessorAnalysisColor color = *geometryColor;
Brian Osman532b3f92018-07-11 10:02:07 -040099 auto result = this->xpRequiresDstTexture(caps, clip, geometryCoverage, &color);
Brian Salomon0088f942017-07-12 11:51:27 -0400100 color.isConstant(geometryColor);
101 return result;
102}
103
Brian Salomonb4d61062017-07-12 11:24:41 -0400104SkString GrSimpleMeshDrawOpHelper::dumpInfo() const {
Brian Salomon91326c32017-08-09 16:02:19 -0400105 const GrProcessorSet& processors = fProcessors ? *fProcessors : GrProcessorSet::EmptySet();
106 SkString result = processors.dumpProcessors();
Brian Salomonb4d61062017-07-12 11:24:41 -0400107 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
126GrPipeline::InitArgs GrSimpleMeshDrawOpHelper::pipelineInitArgs(
127 GrMeshDrawOp::Target* target) const {
128 GrPipeline::InitArgs args;
129 args.fFlags = this->pipelineFlags();
Robert Phillips2890fbf2017-07-26 15:48:41 -0400130 args.fProxy = target->proxy();
Brian Salomonb4d61062017-07-12 11:24:41 -0400131 args.fDstProxy = target->dstProxy();
132 args.fCaps = &target->caps();
133 args.fResourceProvider = target->resourceProvider();
134 return args;
135}
136
Brian Salomon49348902018-06-26 09:12:38 -0400137auto GrSimpleMeshDrawOpHelper::internalMakePipeline(GrMeshDrawOp::Target* target,
Brian Salomon7eae3e02018-08-07 14:02:38 +0000138 const GrPipeline::InitArgs& args,
139 int numPrimitiveProcessorProxies)
Brian Salomon49348902018-06-26 09:12:38 -0400140 -> PipelineAndFixedDynamicState {
Brian Salomonbfd18cd2017-08-09 16:27:09 -0400141 // A caller really should only call this once as the processor set and applied clip get
142 // moved into the GrPipeline.
143 SkASSERT(!fMadePipeline);
144 SkDEBUGCODE(fMadePipeline = true);
Brian Salomon49348902018-06-26 09:12:38 -0400145 auto clip = target->detachAppliedClip();
Brian Salomonf5136822018-08-03 09:09:36 -0400146 GrPipeline::FixedDynamicState* fixedDynamicState = nullptr;
Brian Salomon7eae3e02018-08-07 14:02:38 +0000147 if (clip.scissorState().enabled() || numPrimitiveProcessorProxies) {
Brian Salomonf5136822018-08-03 09:09:36 -0400148 fixedDynamicState = target->allocFixedDynamicState(clip.scissorState().rect());
Brian Salomon7eae3e02018-08-07 14:02:38 +0000149 if (numPrimitiveProcessorProxies) {
150 fixedDynamicState->fPrimitiveProcessorTextures =
151 target->allocPrimitiveProcessorTextureArray(numPrimitiveProcessorProxies);
152 }
Brian Salomonf5136822018-08-03 09:09:36 -0400153 }
Brian Salomon91326c32017-08-09 16:02:19 -0400154 if (fProcessors) {
Brian Salomon49348902018-06-26 09:12:38 -0400155 return {target->allocPipeline(args, std::move(*fProcessors), std::move(clip)),
Brian Salomonf5136822018-08-03 09:09:36 -0400156 fixedDynamicState};
Brian Salomon91326c32017-08-09 16:02:19 -0400157 } else {
Brian Salomon49348902018-06-26 09:12:38 -0400158 return {target->allocPipeline(args, GrProcessorSet::MakeEmptySet(), std::move(clip)),
Brian Salomonf5136822018-08-03 09:09:36 -0400159 fixedDynamicState};
Brian Salomon91326c32017-08-09 16:02:19 -0400160 }
161}
162
Brian Salomonb4d61062017-07-12 11:24:41 -0400163GrSimpleMeshDrawOpHelperWithStencil::GrSimpleMeshDrawOpHelperWithStencil(
164 const MakeArgs& args, GrAAType aaType, const GrUserStencilSettings* stencilSettings,
165 Flags flags)
166 : INHERITED(args, aaType, flags)
167 , fStencilSettings(stencilSettings ? stencilSettings : &GrUserStencilSettings::kUnused) {}
168
169GrDrawOp::FixedFunctionFlags GrSimpleMeshDrawOpHelperWithStencil::fixedFunctionFlags() const {
170 GrDrawOp::FixedFunctionFlags flags = INHERITED::fixedFunctionFlags();
171 if (fStencilSettings != &GrUserStencilSettings::kUnused) {
172 flags |= GrDrawOp::FixedFunctionFlags::kUsesStencil;
173 }
174 return flags;
175}
176
177bool GrSimpleMeshDrawOpHelperWithStencil::isCompatible(
178 const GrSimpleMeshDrawOpHelperWithStencil& that, const GrCaps& caps,
179 const SkRect& thisBounds, const SkRect& thatBounds) const {
180 return INHERITED::isCompatible(that, caps, thisBounds, thatBounds) &&
181 fStencilSettings == that.fStencilSettings;
182}
183
Brian Salomon7eae3e02018-08-07 14:02:38 +0000184auto GrSimpleMeshDrawOpHelperWithStencil::makePipeline(GrMeshDrawOp::Target* target,
185 int numPrimitiveProcessorTextures)
Brian Salomon49348902018-06-26 09:12:38 -0400186 -> PipelineAndFixedDynamicState {
Brian Salomonb4d61062017-07-12 11:24:41 -0400187 auto args = INHERITED::pipelineInitArgs(target);
188 args.fUserStencil = fStencilSettings;
Brian Salomon7eae3e02018-08-07 14:02:38 +0000189 return this->internalMakePipeline(target, args, numPrimitiveProcessorTextures);
Brian Salomonb4d61062017-07-12 11:24:41 -0400190}
191
192SkString GrSimpleMeshDrawOpHelperWithStencil::dumpInfo() const {
193 SkString result = INHERITED::dumpInfo();
194 result.appendf("Stencil settings: %s\n", (fStencilSettings ? "yes" : "no"));
195 return result;
196}