blob: 928c4ffd7d0128c329d975840be7176ea448378c [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 Osmancf860852018-10-31 14:04:39 -040079 SkPMColor4f overrideColor;
Brian Salomon0088f942017-07-12 11:51:27 -040080 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,
Brian Osmancf860852018-10-31 14:04:39 -040097 SkPMColor4f* 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 Osman9a390ac2018-11-12 09:47:48 -0500104#ifdef SK_DEBUG
Brian Salomonb4d61062017-07-12 11:24:41 -0400105SkString GrSimpleMeshDrawOpHelper::dumpInfo() const {
Brian Salomon91326c32017-08-09 16:02:19 -0400106 const GrProcessorSet& processors = fProcessors ? *fProcessors : GrProcessorSet::EmptySet();
107 SkString result = processors.dumpProcessors();
Brian Salomonb4d61062017-07-12 11:24:41 -0400108 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 Osman9a390ac2018-11-12 09:47:48 -0500126#endif
Brian Salomonb4d61062017-07-12 11:24:41 -0400127
128GrPipeline::InitArgs GrSimpleMeshDrawOpHelper::pipelineInitArgs(
129 GrMeshDrawOp::Target* target) const {
130 GrPipeline::InitArgs args;
131 args.fFlags = this->pipelineFlags();
Robert Phillips2890fbf2017-07-26 15:48:41 -0400132 args.fProxy = target->proxy();
Brian Salomonb4d61062017-07-12 11:24:41 -0400133 args.fDstProxy = target->dstProxy();
134 args.fCaps = &target->caps();
135 args.fResourceProvider = target->resourceProvider();
136 return args;
137}
138
Brian Salomon49348902018-06-26 09:12:38 -0400139auto GrSimpleMeshDrawOpHelper::internalMakePipeline(GrMeshDrawOp::Target* target,
Brian Salomon7eae3e02018-08-07 14:02:38 +0000140 const GrPipeline::InitArgs& args,
141 int numPrimitiveProcessorProxies)
Brian Salomon49348902018-06-26 09:12:38 -0400142 -> PipelineAndFixedDynamicState {
Brian Salomonbfd18cd2017-08-09 16:27:09 -0400143 // 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 Salomon49348902018-06-26 09:12:38 -0400147 auto clip = target->detachAppliedClip();
Brian Salomonf5136822018-08-03 09:09:36 -0400148 GrPipeline::FixedDynamicState* fixedDynamicState = nullptr;
Brian Salomon7eae3e02018-08-07 14:02:38 +0000149 if (clip.scissorState().enabled() || numPrimitiveProcessorProxies) {
Brian Salomonf5136822018-08-03 09:09:36 -0400150 fixedDynamicState = target->allocFixedDynamicState(clip.scissorState().rect());
Brian Salomon7eae3e02018-08-07 14:02:38 +0000151 if (numPrimitiveProcessorProxies) {
152 fixedDynamicState->fPrimitiveProcessorTextures =
153 target->allocPrimitiveProcessorTextureArray(numPrimitiveProcessorProxies);
154 }
Brian Salomonf5136822018-08-03 09:09:36 -0400155 }
Brian Salomon91326c32017-08-09 16:02:19 -0400156 if (fProcessors) {
Brian Salomon49348902018-06-26 09:12:38 -0400157 return {target->allocPipeline(args, std::move(*fProcessors), std::move(clip)),
Brian Salomonf5136822018-08-03 09:09:36 -0400158 fixedDynamicState};
Brian Salomon91326c32017-08-09 16:02:19 -0400159 } else {
Brian Salomon49348902018-06-26 09:12:38 -0400160 return {target->allocPipeline(args, GrProcessorSet::MakeEmptySet(), std::move(clip)),
Brian Salomonf5136822018-08-03 09:09:36 -0400161 fixedDynamicState};
Brian Salomon91326c32017-08-09 16:02:19 -0400162 }
163}
164
Brian Salomonb4d61062017-07-12 11:24:41 -0400165GrSimpleMeshDrawOpHelperWithStencil::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
171GrDrawOp::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
179bool 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 Salomon7eae3e02018-08-07 14:02:38 +0000186auto GrSimpleMeshDrawOpHelperWithStencil::makePipeline(GrMeshDrawOp::Target* target,
187 int numPrimitiveProcessorTextures)
Brian Salomon49348902018-06-26 09:12:38 -0400188 -> PipelineAndFixedDynamicState {
Brian Salomonb4d61062017-07-12 11:24:41 -0400189 auto args = INHERITED::pipelineInitArgs(target);
190 args.fUserStencil = fStencilSettings;
Brian Salomon7eae3e02018-08-07 14:02:38 +0000191 return this->internalMakePipeline(target, args, numPrimitiveProcessorTextures);
Brian Salomonb4d61062017-07-12 11:24:41 -0400192}
193
Brian Osman9a390ac2018-11-12 09:47:48 -0500194#ifdef SK_DEBUG
Brian Salomonb4d61062017-07-12 11:24:41 -0400195SkString GrSimpleMeshDrawOpHelperWithStencil::dumpInfo() const {
196 SkString result = INHERITED::dumpInfo();
197 result.appendf("Stencil settings: %s\n", (fStencilSettings ? "yes" : "no"));
198 return result;
199}
Brian Osman9a390ac2018-11-12 09:47:48 -0500200#endif