blob: 1d74e12593e7cc618a8d5656dafa12ef40a18676 [file] [log] [blame]
bsalomon50785a32015-02-06 07:02:37 -08001/*
2 * Copyright 2015 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/GrXferProcessor.h"
Robert Phillipsbe77a022018-04-03 17:17:05 -04009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/gpu/GrCaps.h"
11#include "src/gpu/GrPipeline.h"
bsalomon50785a32015-02-06 07:02:37 -080012
Ethan Nicholasabff9562017-10-09 10:54:08 -040013GrXferProcessor::GrXferProcessor(ClassID classID)
14 : INHERITED(classID)
15 , fWillReadDstColor(false)
Greg Daniel6ebe4b92017-05-19 10:56:46 -040016 , fIsLCD(false) {}
bsalomon50785a32015-02-06 07:02:37 -080017
Chris Dalton57ab06c2021-04-22 12:57:28 -060018GrXferProcessor::GrXferProcessor(ClassID classID, bool willReadDstColor,
Greg Daniel6ebe4b92017-05-19 10:56:46 -040019 GrProcessorAnalysisCoverage coverage)
Ethan Nicholasabff9562017-10-09 10:54:08 -040020 : INHERITED(classID)
21 , fWillReadDstColor(willReadDstColor)
Greg Daniel6ebe4b92017-05-19 10:56:46 -040022 , fIsLCD(GrProcessorAnalysisCoverage::kLCD == coverage) {}
bsalomon50785a32015-02-06 07:02:37 -080023
cdaltonedbb31f2015-06-08 12:14:44 -070024bool GrXferProcessor::hasSecondaryOutput() const {
25 if (!this->willReadDstColor()) {
26 return this->onHasSecondaryOutput();
27 }
Chris Dalton57ab06c2021-04-22 12:57:28 -060028 return false;
cdaltonedbb31f2015-06-08 12:14:44 -070029}
30
Brian Salomon18dfa982017-04-03 16:57:43 -040031void GrXferProcessor::getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b,
Greg Daniel70dd6a92020-10-09 10:09:06 -040032 const GrSurfaceOrigin* originIfDstTexture,
Greg Daniel87fab9f2021-06-07 15:18:23 -040033 bool usesInputAttachmentForDstRead) const {
bsalomon50785a32015-02-06 07:02:37 -080034 uint32_t key = this->willReadDstColor() ? 0x1 : 0x0;
cdaltonedbb31f2015-06-08 12:14:44 -070035 if (key) {
Brian Salomon18dfa982017-04-03 16:57:43 -040036 if (originIfDstTexture) {
cdaltonedbb31f2015-06-08 12:14:44 -070037 key |= 0x2;
Brian Salomon18dfa982017-04-03 16:57:43 -040038 if (kTopLeft_GrSurfaceOrigin == *originIfDstTexture) {
cdalton827bae12015-06-08 13:43:33 -070039 key |= 0x4;
40 }
Greg Daniel87fab9f2021-06-07 15:18:23 -040041 if (usesInputAttachmentForDstRead) {
Greg Daniel70dd6a92020-10-09 10:09:06 -040042 key |= 0x8;
43 }
cdaltonedbb31f2015-06-08 12:14:44 -070044 }
bsalomon50785a32015-02-06 07:02:37 -080045 }
Greg Daniel6ebe4b92017-05-19 10:56:46 -040046 if (fIsLCD) {
Chris Dalton57ab06c2021-04-22 12:57:28 -060047 key |= 0x10;
Greg Daniel6ebe4b92017-05-19 10:56:46 -040048 }
bsalomon50785a32015-02-06 07:02:37 -080049 b->add32(key);
egdaniel57d3b032015-11-13 11:57:27 -080050 this->onGetGLSLProcessorKey(caps, b);
bsalomon50785a32015-02-06 07:02:37 -080051}
52
bsalomonf7cc8772015-05-11 11:21:14 -070053#ifdef SK_DEBUG
54static const char* equation_string(GrBlendEquation eq) {
55 switch (eq) {
56 case kAdd_GrBlendEquation:
57 return "add";
58 case kSubtract_GrBlendEquation:
59 return "subtract";
60 case kReverseSubtract_GrBlendEquation:
61 return "reverse_subtract";
62 case kScreen_GrBlendEquation:
63 return "screen";
64 case kOverlay_GrBlendEquation:
65 return "overlay";
66 case kDarken_GrBlendEquation:
67 return "darken";
68 case kLighten_GrBlendEquation:
69 return "lighten";
70 case kColorDodge_GrBlendEquation:
71 return "color_dodge";
72 case kColorBurn_GrBlendEquation:
73 return "color_burn";
74 case kHardLight_GrBlendEquation:
75 return "hard_light";
76 case kSoftLight_GrBlendEquation:
77 return "soft_light";
78 case kDifference_GrBlendEquation:
79 return "difference";
80 case kExclusion_GrBlendEquation:
81 return "exclusion";
82 case kMultiply_GrBlendEquation:
83 return "multiply";
84 case kHSLHue_GrBlendEquation:
85 return "hsl_hue";
86 case kHSLSaturation_GrBlendEquation:
87 return "hsl_saturation";
88 case kHSLColor_GrBlendEquation:
89 return "hsl_color";
90 case kHSLLuminosity_GrBlendEquation:
91 return "hsl_luminosity";
Mike Klein36743362018-11-06 08:23:30 -050092 case kIllegal_GrBlendEquation:
93 SkASSERT(false);
94 return "<illegal>";
Brian Salomon23356442018-11-30 15:33:19 -050095 }
bsalomonf7cc8772015-05-11 11:21:14 -070096 return "";
97}
98
99static const char* coeff_string(GrBlendCoeff coeff) {
100 switch (coeff) {
101 case kZero_GrBlendCoeff:
102 return "zero";
103 case kOne_GrBlendCoeff:
104 return "one";
105 case kSC_GrBlendCoeff:
106 return "src_color";
107 case kISC_GrBlendCoeff:
108 return "inv_src_color";
109 case kDC_GrBlendCoeff:
110 return "dst_color";
111 case kIDC_GrBlendCoeff:
112 return "inv_dst_color";
113 case kSA_GrBlendCoeff:
114 return "src_alpha";
115 case kISA_GrBlendCoeff:
116 return "inv_src_alpha";
117 case kDA_GrBlendCoeff:
118 return "dst_alpha";
119 case kIDA_GrBlendCoeff:
120 return "inv_dst_alpha";
121 case kConstC_GrBlendCoeff:
122 return "const_color";
123 case kIConstC_GrBlendCoeff:
124 return "inv_const_color";
bsalomonf7cc8772015-05-11 11:21:14 -0700125 case kS2C_GrBlendCoeff:
126 return "src2_color";
127 case kIS2C_GrBlendCoeff:
128 return "inv_src2_color";
129 case kS2A_GrBlendCoeff:
130 return "src2_alpha";
131 case kIS2A_GrBlendCoeff:
132 return "inv_src2_alpha";
Mike Klein36743362018-11-06 08:23:30 -0500133 case kIllegal_GrBlendCoeff:
134 SkASSERT(false);
135 return "<illegal>";
bsalomonf7cc8772015-05-11 11:21:14 -0700136 }
137 return "";
138}
139
140SkString GrXferProcessor::BlendInfo::dump() const {
141 SkString out;
142 out.printf("write_color(%d) equation(%s) src_coeff(%s) dst_coeff:(%s) const(0x%08x)",
143 fWriteColor, equation_string(fEquation), coeff_string(fSrcBlend),
Brian Osman422f95b2018-11-05 16:49:04 -0500144 coeff_string(fDstBlend), fBlendConstant.toBytes_RGBA());
bsalomonf7cc8772015-05-11 11:21:14 -0700145 return out;
146}
147#endif
148
bsalomon50785a32015-02-06 07:02:37 -0800149///////////////////////////////////////////////////////////////////////////////
150
Brian Salomon31853842017-03-28 16:32:05 -0400151GrXPFactory::AnalysisProperties GrXPFactory::GetAnalysisProperties(
152 const GrXPFactory* factory,
Brian Salomona811b122017-03-30 08:21:32 -0400153 const GrProcessorAnalysisColor& color,
154 const GrProcessorAnalysisCoverage& coverage,
Brian Osman5ced0bf2019-03-15 10:15:29 -0400155 const GrCaps& caps,
156 GrClampType clampType) {
Brian Salomon31853842017-03-28 16:32:05 -0400157 AnalysisProperties result;
Brian Salomon5298dc82017-02-22 11:52:03 -0500158 if (factory) {
Chris Dalton57ab06c2021-04-22 12:57:28 -0600159 result = factory->analysisProperties(color, coverage, caps, clampType);
Brian Salomon5298dc82017-02-22 11:52:03 -0500160 } else {
Chris Dalton57ab06c2021-04-22 12:57:28 -0600161 result = GrPorterDuffXPFactory::SrcOverAnalysisProperties(color, coverage, caps, clampType);
Brian Salomon31853842017-03-28 16:32:05 -0400162 }
Greg Danielc5296812020-02-28 13:06:02 -0500163 if (coverage == GrProcessorAnalysisCoverage::kNone) {
164 result |= AnalysisProperties::kCompatibleWithCoverageAsAlpha;
165 }
Brian Salomon31853842017-03-28 16:32:05 -0400166 SkASSERT(!(result & AnalysisProperties::kRequiresDstTexture));
167 if ((result & AnalysisProperties::kReadsDstInShader) &&
168 !caps.shaderCaps()->dstReadInShaderSupport()) {
Chris Dalton945ee652019-01-23 09:10:36 -0700169 result |= AnalysisProperties::kRequiresDstTexture |
170 AnalysisProperties::kRequiresNonOverlappingDraws;
Brian Salomon5298dc82017-02-22 11:52:03 -0500171 }
Brian Salomon5298dc82017-02-22 11:52:03 -0500172 return result;
Brian Salomon9a514982017-02-14 10:28:22 -0500173}
174
Brian Salomond61c9d92017-04-10 10:54:25 -0400175sk_sp<const GrXferProcessor> GrXPFactory::MakeXferProcessor(const GrXPFactory* factory,
176 const GrProcessorAnalysisColor& color,
177 GrProcessorAnalysisCoverage coverage,
Brian Osman5ced0bf2019-03-15 10:15:29 -0400178 const GrCaps& caps,
179 GrClampType clampType) {
Brian Salomona076d872017-04-04 15:17:03 -0400180 if (factory) {
Chris Dalton57ab06c2021-04-22 12:57:28 -0600181 return factory->makeXferProcessor(color, coverage, caps, clampType);
Brian Salomona076d872017-04-04 15:17:03 -0400182 } else {
Chris Dalton57ab06c2021-04-22 12:57:28 -0600183 return GrPorterDuffXPFactory::MakeSrcOverXferProcessor(color, coverage, caps);
Brian Salomona076d872017-04-04 15:17:03 -0400184 }
bsalomon50785a32015-02-06 07:02:37 -0800185}