blob: 96545612c7880790867f930ba604acc6652db3b3 [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
40bool GrSimpleMeshDrawOpHelper::isCompatible(const GrSimpleMeshDrawOpHelper& that,
41 const GrCaps& caps, const SkRect& thisBounds,
Robert Phillipsb69001f2019-10-29 12:16:35 -040042 const SkRect& thatBounds, bool ignoreAAType) const {
Brian Salomonb4d61062017-07-12 11:24:41 -040043 if (SkToBool(fProcessors) != SkToBool(that.fProcessors)) {
44 return false;
45 }
46 if (fProcessors) {
47 if (*fProcessors != *that.fProcessors) {
48 return false;
49 }
Brian Salomonb4d61062017-07-12 11:24:41 -040050 }
Robert Phillipsb69001f2019-10-29 12:16:35 -040051
52#ifdef SK_DEBUG
53 if (ignoreAAType) {
54 // If we're ignoring AA it should be bc we already know they are the same or that
55 // the are different but are compatible (i.e., one is AA and the other is None)
Robert Phillipsbbd459d2019-10-29 14:40:03 -040056 SkASSERT(fAAType == that.fAAType ||
57 GrMeshDrawOp::CanUpgradeAAOnMerge(this->aaType(), that.aaType()));
Robert Phillipsb69001f2019-10-29 12:16:35 -040058 }
59#endif
60
61 bool result = fPipelineFlags == that.fPipelineFlags &&
62 (ignoreAAType || fAAType == that.fAAType);
Brian Osman605c6d52019-03-15 12:10:35 -040063 SkASSERT(!result || fCompatibleWithCoverageAsAlpha == that.fCompatibleWithCoverageAsAlpha);
Brian Salomonb4d61062017-07-12 11:24:41 -040064 SkASSERT(!result || fUsesLocalCoords == that.fUsesLocalCoords);
65 return result;
66}
67
Chris Dalton4b62aed2019-01-15 11:53:00 -070068GrProcessorSet::Analysis GrSimpleMeshDrawOpHelper::finalizeProcessors(
Chris Dalton6ce447a2019-06-23 18:07:38 -060069 const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
70 GrClampType clampType, GrProcessorAnalysisCoverage geometryCoverage,
71 SkPMColor4f* geometryColor, bool* wideColor) {
Chris Daltonb8fff0d2019-03-05 10:11:58 -070072 GrProcessorAnalysisColor color = *geometryColor;
Brian Osman5ced0bf2019-03-15 10:15:29 -040073 auto result = this->finalizeProcessors(
Chris Dalton6ce447a2019-06-23 18:07:38 -060074 caps, clip, hasMixedSampledCoverage, clampType, geometryCoverage, &color);
Chris Daltonb8fff0d2019-03-05 10:11:58 -070075 color.isConstant(geometryColor);
Brian Osman8fa7ab42019-03-18 10:22:42 -040076 if (wideColor) {
77 *wideColor = SkPMColor4fNeedsWideColor(*geometryColor, clampType, caps);
78 }
Chris Daltonb8fff0d2019-03-05 10:11:58 -070079 return result;
80}
81
82GrProcessorSet::Analysis GrSimpleMeshDrawOpHelper::finalizeProcessors(
83 const GrCaps& caps, const GrAppliedClip* clip, const GrUserStencilSettings* userStencil,
Chris Dalton6ce447a2019-06-23 18:07:38 -060084 bool hasMixedSampledCoverage, GrClampType clampType,
85 GrProcessorAnalysisCoverage geometryCoverage, GrProcessorAnalysisColor* geometryColor) {
Brian Salomonb4d61062017-07-12 11:24:41 -040086 SkDEBUGCODE(fDidAnalysis = true);
87 GrProcessorSet::Analysis analysis;
88 if (fProcessors) {
89 GrProcessorAnalysisCoverage coverage = geometryCoverage;
90 if (GrProcessorAnalysisCoverage::kNone == coverage) {
Chris Dalton69824002017-10-31 00:37:52 -060091 coverage = clip->numClipCoverageFragmentProcessors()
Brian Salomonb4d61062017-07-12 11:24:41 -040092 ? GrProcessorAnalysisCoverage::kSingleChannel
93 : GrProcessorAnalysisCoverage::kNone;
94 }
Brian Osmancf860852018-10-31 14:04:39 -040095 SkPMColor4f overrideColor;
Chris Dalton6ce447a2019-06-23 18:07:38 -060096 analysis = fProcessors->finalize(*geometryColor, coverage, clip, userStencil,
97 hasMixedSampledCoverage, caps, clampType, &overrideColor);
Brian Salomon0088f942017-07-12 11:51:27 -040098 if (analysis.inputColorIsOverridden()) {
99 *geometryColor = overrideColor;
100 }
Brian Salomonb4d61062017-07-12 11:24:41 -0400101 } else {
102 analysis = GrProcessorSet::EmptySetAnalysis();
103 }
Brian Salomonb4d61062017-07-12 11:24:41 -0400104 fUsesLocalCoords = analysis.usesLocalCoords();
Brian Osman605c6d52019-03-15 12:10:35 -0400105 fCompatibleWithCoverageAsAlpha = analysis.isCompatibleWithCoverageAsAlpha();
Chris Dalton4b62aed2019-01-15 11:53:00 -0700106 return analysis;
Brian Salomonb4d61062017-07-12 11:24:41 -0400107}
108
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700109void GrSimpleMeshDrawOpHelper::executeDrawsAndUploads(
110 const GrOp* op, GrOpFlushState* flushState, const SkRect& chainBounds) {
111 if (fProcessors) {
112 flushState->executeDrawsAndUploadsForMeshDrawOp(
113 op, chainBounds, std::move(*fProcessors), fPipelineFlags);
114 } else {
115 flushState->executeDrawsAndUploadsForMeshDrawOp(
116 op, chainBounds, GrProcessorSet::MakeEmptySet(), fPipelineFlags);
117 }
118}
119
Brian Osman9a390ac2018-11-12 09:47:48 -0500120#ifdef SK_DEBUG
Chris Daltonbaa1b352019-04-03 12:03:00 -0600121static void dump_pipeline_flags(GrPipeline::InputFlags flags, SkString* result) {
122 if (GrPipeline::InputFlags::kNone != flags) {
123 if (flags & GrPipeline::InputFlags::kSnapVerticesToPixelCenters) {
124 result->append("Snap vertices to pixel center.\n");
125 }
126 if (flags & GrPipeline::InputFlags::kHWAntialias) {
127 result->append("HW Antialiasing enabled.\n");
128 }
129 return;
130 }
131 result->append("No pipeline flags\n");
132}
133
Brian Salomonb4d61062017-07-12 11:24:41 -0400134SkString GrSimpleMeshDrawOpHelper::dumpInfo() const {
Brian Salomon91326c32017-08-09 16:02:19 -0400135 const GrProcessorSet& processors = fProcessors ? *fProcessors : GrProcessorSet::EmptySet();
136 SkString result = processors.dumpProcessors();
Brian Salomonb4d61062017-07-12 11:24:41 -0400137 result.append("AA Type: ");
138 switch (this->aaType()) {
139 case GrAAType::kNone:
140 result.append(" none\n");
141 break;
142 case GrAAType::kCoverage:
143 result.append(" coverage\n");
144 break;
145 case GrAAType::kMSAA:
146 result.append(" msaa\n");
147 break;
Brian Salomonb4d61062017-07-12 11:24:41 -0400148 }
Chris Daltonbaa1b352019-04-03 12:03:00 -0600149 dump_pipeline_flags(fPipelineFlags, &result);
Brian Salomonb4d61062017-07-12 11:24:41 -0400150 return result;
151}
Brian Osman9a390ac2018-11-12 09:47:48 -0500152#endif
Brian Salomonb4d61062017-07-12 11:24:41 -0400153
Brian Salomonb4d61062017-07-12 11:24:41 -0400154GrSimpleMeshDrawOpHelperWithStencil::GrSimpleMeshDrawOpHelperWithStencil(
155 const MakeArgs& args, GrAAType aaType, const GrUserStencilSettings* stencilSettings,
Chris Daltonbaa1b352019-04-03 12:03:00 -0600156 InputFlags inputFlags)
157 : INHERITED(args, aaType, inputFlags)
Brian Salomonb4d61062017-07-12 11:24:41 -0400158 , fStencilSettings(stencilSettings ? stencilSettings : &GrUserStencilSettings::kUnused) {}
159
160GrDrawOp::FixedFunctionFlags GrSimpleMeshDrawOpHelperWithStencil::fixedFunctionFlags() const {
161 GrDrawOp::FixedFunctionFlags flags = INHERITED::fixedFunctionFlags();
162 if (fStencilSettings != &GrUserStencilSettings::kUnused) {
163 flags |= GrDrawOp::FixedFunctionFlags::kUsesStencil;
164 }
165 return flags;
166}
167
Chris Daltonb8fff0d2019-03-05 10:11:58 -0700168GrProcessorSet::Analysis GrSimpleMeshDrawOpHelperWithStencil::finalizeProcessors(
Chris Dalton6ce447a2019-06-23 18:07:38 -0600169 const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
170 GrClampType clampType, GrProcessorAnalysisCoverage geometryCoverage,
171 SkPMColor4f* geometryColor, bool* wideColor) {
Chris Daltonb8fff0d2019-03-05 10:11:58 -0700172 GrProcessorAnalysisColor color = *geometryColor;
Brian Osman5ced0bf2019-03-15 10:15:29 -0400173 auto result = this->finalizeProcessors(
Chris Dalton6ce447a2019-06-23 18:07:38 -0600174 caps, clip, hasMixedSampledCoverage, clampType, geometryCoverage, &color);
Chris Daltonb8fff0d2019-03-05 10:11:58 -0700175 color.isConstant(geometryColor);
Brian Osman8fa7ab42019-03-18 10:22:42 -0400176 if (wideColor) {
177 *wideColor = SkPMColor4fNeedsWideColor(*geometryColor, clampType, caps);
178 }
Chris Daltonb8fff0d2019-03-05 10:11:58 -0700179 return result;
180}
181
Brian Salomonb4d61062017-07-12 11:24:41 -0400182bool GrSimpleMeshDrawOpHelperWithStencil::isCompatible(
183 const GrSimpleMeshDrawOpHelperWithStencil& that, const GrCaps& caps,
Robert Phillipsb69001f2019-10-29 12:16:35 -0400184 const SkRect& thisBounds, const SkRect& thatBounds, bool ignoreAAType) const {
185 return INHERITED::isCompatible(that, caps, thisBounds, thatBounds, ignoreAAType) &&
Brian Salomonb4d61062017-07-12 11:24:41 -0400186 fStencilSettings == that.fStencilSettings;
187}
188
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700189void GrSimpleMeshDrawOpHelperWithStencil::executeDrawsAndUploads(
190 const GrOp* op, GrOpFlushState* flushState, const SkRect& chainBounds) {
191 if (fProcessors) {
192 flushState->executeDrawsAndUploadsForMeshDrawOp(
193 op, chainBounds, std::move(*fProcessors), fPipelineFlags, fStencilSettings);
194 } else {
195 flushState->executeDrawsAndUploadsForMeshDrawOp(
196 op, chainBounds, GrProcessorSet::MakeEmptySet(), fPipelineFlags, fStencilSettings);
197 }
Brian Salomonb4d61062017-07-12 11:24:41 -0400198}
199
Brian Osman9a390ac2018-11-12 09:47:48 -0500200#ifdef SK_DEBUG
Brian Salomonb4d61062017-07-12 11:24:41 -0400201SkString GrSimpleMeshDrawOpHelperWithStencil::dumpInfo() const {
202 SkString result = INHERITED::dumpInfo();
203 result.appendf("Stencil settings: %s\n", (fStencilSettings ? "yes" : "no"));
204 return result;
205}
Brian Osman9a390ac2018-11-12 09:47:48 -0500206#endif