blob: 3c10b8bfd41f92cd454552464d37e22d2bcf12d5 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrAppliedClip.h"
9#include "src/gpu/GrProcessorSet.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/gpu/GrUserStencilSettings.h"
11#include "src/gpu/SkGr.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040012#include "src/gpu/geometry/GrRect.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
Brian Salomonb4d61062017-07-12 11:24:41 -040014
15GrSimpleMeshDrawOpHelper::GrSimpleMeshDrawOpHelper(const MakeArgs& args, GrAAType aaType,
Chris Daltonbaa1b352019-04-03 12:03:00 -060016 InputFlags inputFlags)
Brian Salomonb4d61062017-07-12 11:24:41 -040017 : fProcessors(args.fProcessorSet)
Chris Daltonbaa1b352019-04-03 12:03:00 -060018 , fPipelineFlags((GrPipeline::InputFlags)inputFlags)
Brian Salomonb4d61062017-07-12 11:24:41 -040019 , fAAType((int)aaType)
Brian Salomonb4d61062017-07-12 11:24:41 -040020 , fUsesLocalCoords(false)
Brian Osman605c6d52019-03-15 12:10:35 -040021 , fCompatibleWithCoverageAsAlpha(false) {
Brian Salomonb4d61062017-07-12 11:24:41 -040022 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)) {
Chris Daltonbaa1b352019-04-03 12:03:00 -060025 fPipelineFlags |= GrPipeline::InputFlags::kHWAntialias;
Brian Salomonb4d61062017-07-12 11:24:41 -040026 }
27}
28
29GrSimpleMeshDrawOpHelper::~GrSimpleMeshDrawOpHelper() {
30 if (fProcessors) {
31 fProcessors->~GrProcessorSet();
32 }
33}
34
35GrDrawOp::FixedFunctionFlags GrSimpleMeshDrawOpHelper::fixedFunctionFlags() const {
36 return GrAATypeIsHW((this->aaType())) ? GrDrawOp::FixedFunctionFlags::kUsesHWAA
37 : GrDrawOp::FixedFunctionFlags::kNone;
38}
39
Michael Ludwig69858532018-11-28 15:34:34 -050040static bool none_as_coverage_aa_compatible(GrAAType aa1, GrAAType aa2) {
41 return (aa1 == GrAAType::kNone && aa2 == GrAAType::kCoverage) ||
42 (aa1 == GrAAType::kCoverage && aa2 == GrAAType::kNone);
43}
44
Brian Salomonb4d61062017-07-12 11:24:41 -040045bool GrSimpleMeshDrawOpHelper::isCompatible(const GrSimpleMeshDrawOpHelper& that,
46 const GrCaps& caps, const SkRect& thisBounds,
Michael Ludwig69858532018-11-28 15:34:34 -050047 const SkRect& thatBounds, bool noneAsCoverageAA) const {
Brian Salomonb4d61062017-07-12 11:24:41 -040048 if (SkToBool(fProcessors) != SkToBool(that.fProcessors)) {
49 return false;
50 }
51 if (fProcessors) {
52 if (*fProcessors != *that.fProcessors) {
53 return false;
54 }
Brian Salomonb4d61062017-07-12 11:24:41 -040055 }
Michael Ludwig69858532018-11-28 15:34:34 -050056 bool result = fPipelineFlags == that.fPipelineFlags && (fAAType == that.fAAType ||
57 (noneAsCoverageAA && none_as_coverage_aa_compatible(this->aaType(), that.aaType())));
Brian Osman605c6d52019-03-15 12:10:35 -040058 SkASSERT(!result || fCompatibleWithCoverageAsAlpha == that.fCompatibleWithCoverageAsAlpha);
Brian Salomonb4d61062017-07-12 11:24:41 -040059 SkASSERT(!result || fUsesLocalCoords == that.fUsesLocalCoords);
60 return result;
61}
62
Chris Dalton4b62aed2019-01-15 11:53:00 -070063GrProcessorSet::Analysis GrSimpleMeshDrawOpHelper::finalizeProcessors(
Chris Dalton6ce447a2019-06-23 18:07:38 -060064 const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
65 GrClampType clampType, GrProcessorAnalysisCoverage geometryCoverage,
66 SkPMColor4f* geometryColor, bool* wideColor) {
Chris Daltonb8fff0d2019-03-05 10:11:58 -070067 GrProcessorAnalysisColor color = *geometryColor;
Brian Osman5ced0bf2019-03-15 10:15:29 -040068 auto result = this->finalizeProcessors(
Chris Dalton6ce447a2019-06-23 18:07:38 -060069 caps, clip, hasMixedSampledCoverage, clampType, geometryCoverage, &color);
Chris Daltonb8fff0d2019-03-05 10:11:58 -070070 color.isConstant(geometryColor);
Brian Osman8fa7ab42019-03-18 10:22:42 -040071 if (wideColor) {
72 *wideColor = SkPMColor4fNeedsWideColor(*geometryColor, clampType, caps);
73 }
Chris Daltonb8fff0d2019-03-05 10:11:58 -070074 return result;
75}
76
77GrProcessorSet::Analysis GrSimpleMeshDrawOpHelper::finalizeProcessors(
78 const GrCaps& caps, const GrAppliedClip* clip, const GrUserStencilSettings* userStencil,
Chris Dalton6ce447a2019-06-23 18:07:38 -060079 bool hasMixedSampledCoverage, GrClampType clampType,
80 GrProcessorAnalysisCoverage geometryCoverage, GrProcessorAnalysisColor* geometryColor) {
Brian Salomonb4d61062017-07-12 11:24:41 -040081 SkDEBUGCODE(fDidAnalysis = true);
82 GrProcessorSet::Analysis analysis;
83 if (fProcessors) {
84 GrProcessorAnalysisCoverage coverage = geometryCoverage;
85 if (GrProcessorAnalysisCoverage::kNone == coverage) {
Chris Dalton69824002017-10-31 00:37:52 -060086 coverage = clip->numClipCoverageFragmentProcessors()
Brian Salomonb4d61062017-07-12 11:24:41 -040087 ? GrProcessorAnalysisCoverage::kSingleChannel
88 : GrProcessorAnalysisCoverage::kNone;
89 }
Brian Osmancf860852018-10-31 14:04:39 -040090 SkPMColor4f overrideColor;
Chris Dalton6ce447a2019-06-23 18:07:38 -060091 analysis = fProcessors->finalize(*geometryColor, coverage, clip, userStencil,
92 hasMixedSampledCoverage, caps, clampType, &overrideColor);
Brian Salomon0088f942017-07-12 11:51:27 -040093 if (analysis.inputColorIsOverridden()) {
94 *geometryColor = overrideColor;
95 }
Brian Salomonb4d61062017-07-12 11:24:41 -040096 } else {
97 analysis = GrProcessorSet::EmptySetAnalysis();
98 }
Brian Salomonb4d61062017-07-12 11:24:41 -040099 fUsesLocalCoords = analysis.usesLocalCoords();
Brian Osman605c6d52019-03-15 12:10:35 -0400100 fCompatibleWithCoverageAsAlpha = analysis.isCompatibleWithCoverageAsAlpha();
Chris Dalton4b62aed2019-01-15 11:53:00 -0700101 return analysis;
Brian Salomonb4d61062017-07-12 11:24:41 -0400102}
103
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700104void GrSimpleMeshDrawOpHelper::executeDrawsAndUploads(
105 const GrOp* op, GrOpFlushState* flushState, const SkRect& chainBounds) {
106 if (fProcessors) {
107 flushState->executeDrawsAndUploadsForMeshDrawOp(
108 op, chainBounds, std::move(*fProcessors), fPipelineFlags);
109 } else {
110 flushState->executeDrawsAndUploadsForMeshDrawOp(
111 op, chainBounds, GrProcessorSet::MakeEmptySet(), fPipelineFlags);
112 }
113}
114
Brian Osman9a390ac2018-11-12 09:47:48 -0500115#ifdef SK_DEBUG
Chris Daltonbaa1b352019-04-03 12:03:00 -0600116static void dump_pipeline_flags(GrPipeline::InputFlags flags, SkString* result) {
117 if (GrPipeline::InputFlags::kNone != flags) {
118 if (flags & GrPipeline::InputFlags::kSnapVerticesToPixelCenters) {
119 result->append("Snap vertices to pixel center.\n");
120 }
121 if (flags & GrPipeline::InputFlags::kHWAntialias) {
122 result->append("HW Antialiasing enabled.\n");
123 }
124 return;
125 }
126 result->append("No pipeline flags\n");
127}
128
Brian Salomonb4d61062017-07-12 11:24:41 -0400129SkString GrSimpleMeshDrawOpHelper::dumpInfo() const {
Brian Salomon91326c32017-08-09 16:02:19 -0400130 const GrProcessorSet& processors = fProcessors ? *fProcessors : GrProcessorSet::EmptySet();
131 SkString result = processors.dumpProcessors();
Brian Salomonb4d61062017-07-12 11:24:41 -0400132 result.append("AA Type: ");
133 switch (this->aaType()) {
134 case GrAAType::kNone:
135 result.append(" none\n");
136 break;
137 case GrAAType::kCoverage:
138 result.append(" coverage\n");
139 break;
140 case GrAAType::kMSAA:
141 result.append(" msaa\n");
142 break;
Brian Salomonb4d61062017-07-12 11:24:41 -0400143 }
Chris Daltonbaa1b352019-04-03 12:03:00 -0600144 dump_pipeline_flags(fPipelineFlags, &result);
Brian Salomonb4d61062017-07-12 11:24:41 -0400145 return result;
146}
Brian Osman9a390ac2018-11-12 09:47:48 -0500147#endif
Brian Salomonb4d61062017-07-12 11:24:41 -0400148
Brian Salomonb4d61062017-07-12 11:24:41 -0400149GrSimpleMeshDrawOpHelperWithStencil::GrSimpleMeshDrawOpHelperWithStencil(
150 const MakeArgs& args, GrAAType aaType, const GrUserStencilSettings* stencilSettings,
Chris Daltonbaa1b352019-04-03 12:03:00 -0600151 InputFlags inputFlags)
152 : INHERITED(args, aaType, inputFlags)
Brian Salomonb4d61062017-07-12 11:24:41 -0400153 , fStencilSettings(stencilSettings ? stencilSettings : &GrUserStencilSettings::kUnused) {}
154
155GrDrawOp::FixedFunctionFlags GrSimpleMeshDrawOpHelperWithStencil::fixedFunctionFlags() const {
156 GrDrawOp::FixedFunctionFlags flags = INHERITED::fixedFunctionFlags();
157 if (fStencilSettings != &GrUserStencilSettings::kUnused) {
158 flags |= GrDrawOp::FixedFunctionFlags::kUsesStencil;
159 }
160 return flags;
161}
162
Chris Daltonb8fff0d2019-03-05 10:11:58 -0700163GrProcessorSet::Analysis GrSimpleMeshDrawOpHelperWithStencil::finalizeProcessors(
Chris Dalton6ce447a2019-06-23 18:07:38 -0600164 const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
165 GrClampType clampType, GrProcessorAnalysisCoverage geometryCoverage,
166 SkPMColor4f* geometryColor, bool* wideColor) {
Chris Daltonb8fff0d2019-03-05 10:11:58 -0700167 GrProcessorAnalysisColor color = *geometryColor;
Brian Osman5ced0bf2019-03-15 10:15:29 -0400168 auto result = this->finalizeProcessors(
Chris Dalton6ce447a2019-06-23 18:07:38 -0600169 caps, clip, hasMixedSampledCoverage, clampType, geometryCoverage, &color);
Chris Daltonb8fff0d2019-03-05 10:11:58 -0700170 color.isConstant(geometryColor);
Brian Osman8fa7ab42019-03-18 10:22:42 -0400171 if (wideColor) {
172 *wideColor = SkPMColor4fNeedsWideColor(*geometryColor, clampType, caps);
173 }
Chris Daltonb8fff0d2019-03-05 10:11:58 -0700174 return result;
175}
176
Brian Salomonb4d61062017-07-12 11:24:41 -0400177bool GrSimpleMeshDrawOpHelperWithStencil::isCompatible(
178 const GrSimpleMeshDrawOpHelperWithStencil& that, const GrCaps& caps,
Michael Ludwig69858532018-11-28 15:34:34 -0500179 const SkRect& thisBounds, const SkRect& thatBounds, bool noneAsCoverageAA) const {
180 return INHERITED::isCompatible(that, caps, thisBounds, thatBounds, noneAsCoverageAA) &&
Brian Salomonb4d61062017-07-12 11:24:41 -0400181 fStencilSettings == that.fStencilSettings;
182}
183
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700184void GrSimpleMeshDrawOpHelperWithStencil::executeDrawsAndUploads(
185 const GrOp* op, GrOpFlushState* flushState, const SkRect& chainBounds) {
186 if (fProcessors) {
187 flushState->executeDrawsAndUploadsForMeshDrawOp(
188 op, chainBounds, std::move(*fProcessors), fPipelineFlags, fStencilSettings);
189 } else {
190 flushState->executeDrawsAndUploadsForMeshDrawOp(
191 op, chainBounds, GrProcessorSet::MakeEmptySet(), fPipelineFlags, fStencilSettings);
192 }
Brian Salomonb4d61062017-07-12 11:24:41 -0400193}
194
Brian Osman9a390ac2018-11-12 09:47:48 -0500195#ifdef SK_DEBUG
Brian Salomonb4d61062017-07-12 11:24:41 -0400196SkString GrSimpleMeshDrawOpHelperWithStencil::dumpInfo() const {
197 SkString result = INHERITED::dumpInfo();
198 result.appendf("Stencil settings: %s\n", (fStencilSettings ? "yes" : "no"));
199 return result;
200}
Brian Osman9a390ac2018-11-12 09:47:48 -0500201#endif