blob: 14d0355a06f201263de9f5a88eca3be0f878ae85 [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 , fDstReadUsesMixedSamples(false)
17 , fIsLCD(false) {}
bsalomon50785a32015-02-06 07:02:37 -080018
Ethan Nicholasabff9562017-10-09 10:54:08 -040019GrXferProcessor::GrXferProcessor(ClassID classID, bool willReadDstColor, bool hasMixedSamples,
Greg Daniel6ebe4b92017-05-19 10:56:46 -040020 GrProcessorAnalysisCoverage coverage)
Ethan Nicholasabff9562017-10-09 10:54:08 -040021 : INHERITED(classID)
22 , fWillReadDstColor(willReadDstColor)
Greg Daniel6ebe4b92017-05-19 10:56:46 -040023 , fDstReadUsesMixedSamples(willReadDstColor && hasMixedSamples)
24 , fIsLCD(GrProcessorAnalysisCoverage::kLCD == coverage) {}
bsalomon50785a32015-02-06 07:02:37 -080025
cdaltonedbb31f2015-06-08 12:14:44 -070026bool GrXferProcessor::hasSecondaryOutput() const {
27 if (!this->willReadDstColor()) {
28 return this->onHasSecondaryOutput();
29 }
cdalton86ae0a92015-06-08 15:11:04 -070030 return this->dstReadUsesMixedSamples();
cdaltonedbb31f2015-06-08 12:14:44 -070031}
32
Brian Salomon18dfa982017-04-03 16:57:43 -040033void GrXferProcessor::getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b,
34 const GrSurfaceOrigin* originIfDstTexture) const {
bsalomon50785a32015-02-06 07:02:37 -080035 uint32_t key = this->willReadDstColor() ? 0x1 : 0x0;
cdaltonedbb31f2015-06-08 12:14:44 -070036 if (key) {
Brian Salomon18dfa982017-04-03 16:57:43 -040037 if (originIfDstTexture) {
cdaltonedbb31f2015-06-08 12:14:44 -070038 key |= 0x2;
Brian Salomon18dfa982017-04-03 16:57:43 -040039 if (kTopLeft_GrSurfaceOrigin == *originIfDstTexture) {
cdalton827bae12015-06-08 13:43:33 -070040 key |= 0x4;
41 }
cdaltonedbb31f2015-06-08 12:14:44 -070042 }
cdalton86ae0a92015-06-08 15:11:04 -070043 if (this->dstReadUsesMixedSamples()) {
egdaniel56cf6dc2015-11-30 10:15:58 -080044 key |= 0x8;
cdalton86ae0a92015-06-08 15:11:04 -070045 }
bsalomon50785a32015-02-06 07:02:37 -080046 }
Greg Daniel6ebe4b92017-05-19 10:56:46 -040047 if (fIsLCD) {
48 key |= 0x10;
49 }
bsalomon50785a32015-02-06 07:02:37 -080050 b->add32(key);
egdaniel57d3b032015-11-13 11:57:27 -080051 this->onGetGLSLProcessorKey(caps, b);
bsalomon50785a32015-02-06 07:02:37 -080052}
53
bsalomonf7cc8772015-05-11 11:21:14 -070054#ifdef SK_DEBUG
55static const char* equation_string(GrBlendEquation eq) {
56 switch (eq) {
57 case kAdd_GrBlendEquation:
58 return "add";
59 case kSubtract_GrBlendEquation:
60 return "subtract";
61 case kReverseSubtract_GrBlendEquation:
62 return "reverse_subtract";
63 case kScreen_GrBlendEquation:
64 return "screen";
65 case kOverlay_GrBlendEquation:
66 return "overlay";
67 case kDarken_GrBlendEquation:
68 return "darken";
69 case kLighten_GrBlendEquation:
70 return "lighten";
71 case kColorDodge_GrBlendEquation:
72 return "color_dodge";
73 case kColorBurn_GrBlendEquation:
74 return "color_burn";
75 case kHardLight_GrBlendEquation:
76 return "hard_light";
77 case kSoftLight_GrBlendEquation:
78 return "soft_light";
79 case kDifference_GrBlendEquation:
80 return "difference";
81 case kExclusion_GrBlendEquation:
82 return "exclusion";
83 case kMultiply_GrBlendEquation:
84 return "multiply";
85 case kHSLHue_GrBlendEquation:
86 return "hsl_hue";
87 case kHSLSaturation_GrBlendEquation:
88 return "hsl_saturation";
89 case kHSLColor_GrBlendEquation:
90 return "hsl_color";
91 case kHSLLuminosity_GrBlendEquation:
92 return "hsl_luminosity";
Mike Klein36743362018-11-06 08:23:30 -050093 case kIllegal_GrBlendEquation:
94 SkASSERT(false);
95 return "<illegal>";
Brian Salomon23356442018-11-30 15:33:19 -050096 }
bsalomonf7cc8772015-05-11 11:21:14 -070097 return "";
98}
99
100static const char* coeff_string(GrBlendCoeff coeff) {
101 switch (coeff) {
102 case kZero_GrBlendCoeff:
103 return "zero";
104 case kOne_GrBlendCoeff:
105 return "one";
106 case kSC_GrBlendCoeff:
107 return "src_color";
108 case kISC_GrBlendCoeff:
109 return "inv_src_color";
110 case kDC_GrBlendCoeff:
111 return "dst_color";
112 case kIDC_GrBlendCoeff:
113 return "inv_dst_color";
114 case kSA_GrBlendCoeff:
115 return "src_alpha";
116 case kISA_GrBlendCoeff:
117 return "inv_src_alpha";
118 case kDA_GrBlendCoeff:
119 return "dst_alpha";
120 case kIDA_GrBlendCoeff:
121 return "inv_dst_alpha";
122 case kConstC_GrBlendCoeff:
123 return "const_color";
124 case kIConstC_GrBlendCoeff:
125 return "inv_const_color";
126 case kConstA_GrBlendCoeff:
127 return "const_alpha";
128 case kIConstA_GrBlendCoeff:
129 return "inv_const_alpha";
130 case kS2C_GrBlendCoeff:
131 return "src2_color";
132 case kIS2C_GrBlendCoeff:
133 return "inv_src2_color";
134 case kS2A_GrBlendCoeff:
135 return "src2_alpha";
136 case kIS2A_GrBlendCoeff:
137 return "inv_src2_alpha";
Mike Klein36743362018-11-06 08:23:30 -0500138 case kIllegal_GrBlendCoeff:
139 SkASSERT(false);
140 return "<illegal>";
bsalomonf7cc8772015-05-11 11:21:14 -0700141 }
142 return "";
143}
144
145SkString GrXferProcessor::BlendInfo::dump() const {
146 SkString out;
147 out.printf("write_color(%d) equation(%s) src_coeff(%s) dst_coeff:(%s) const(0x%08x)",
148 fWriteColor, equation_string(fEquation), coeff_string(fSrcBlend),
Brian Osman422f95b2018-11-05 16:49:04 -0500149 coeff_string(fDstBlend), fBlendConstant.toBytes_RGBA());
bsalomonf7cc8772015-05-11 11:21:14 -0700150 return out;
151}
152#endif
153
bsalomon50785a32015-02-06 07:02:37 -0800154///////////////////////////////////////////////////////////////////////////////
155
Brian Salomon31853842017-03-28 16:32:05 -0400156GrXPFactory::AnalysisProperties GrXPFactory::GetAnalysisProperties(
157 const GrXPFactory* factory,
Brian Salomona811b122017-03-30 08:21:32 -0400158 const GrProcessorAnalysisColor& color,
159 const GrProcessorAnalysisCoverage& coverage,
Brian Osman5ced0bf2019-03-15 10:15:29 -0400160 const GrCaps& caps,
161 GrClampType clampType) {
Brian Salomon31853842017-03-28 16:32:05 -0400162 AnalysisProperties result;
Brian Salomon5298dc82017-02-22 11:52:03 -0500163 if (factory) {
Brian Osman5ced0bf2019-03-15 10:15:29 -0400164 result = factory->analysisProperties(color, coverage, caps, clampType);
Brian Salomon5298dc82017-02-22 11:52:03 -0500165 } else {
Brian Osman5ced0bf2019-03-15 10:15:29 -0400166 result = GrPorterDuffXPFactory::SrcOverAnalysisProperties(color, coverage, caps,
167 clampType);
Brian Salomon31853842017-03-28 16:32:05 -0400168 }
169 SkASSERT(!(result & AnalysisProperties::kRequiresDstTexture));
170 if ((result & AnalysisProperties::kReadsDstInShader) &&
171 !caps.shaderCaps()->dstReadInShaderSupport()) {
Chris Dalton945ee652019-01-23 09:10:36 -0700172 result |= AnalysisProperties::kRequiresDstTexture |
173 AnalysisProperties::kRequiresNonOverlappingDraws;
Brian Salomon5298dc82017-02-22 11:52:03 -0500174 }
Brian Salomon5298dc82017-02-22 11:52:03 -0500175 return result;
Brian Salomon9a514982017-02-14 10:28:22 -0500176}
177
Brian Salomond61c9d92017-04-10 10:54:25 -0400178sk_sp<const GrXferProcessor> GrXPFactory::MakeXferProcessor(const GrXPFactory* factory,
179 const GrProcessorAnalysisColor& color,
180 GrProcessorAnalysisCoverage coverage,
181 bool hasMixedSamples,
Brian Osman5ced0bf2019-03-15 10:15:29 -0400182 const GrCaps& caps,
183 GrClampType clampType) {
cdalton86ae0a92015-06-08 15:11:04 -0700184 SkASSERT(!hasMixedSamples || caps.shaderCaps()->dualSourceBlendingSupport());
Brian Salomona076d872017-04-04 15:17:03 -0400185 if (factory) {
Brian Osman5ced0bf2019-03-15 10:15:29 -0400186 return factory->makeXferProcessor(color, coverage, hasMixedSamples, caps, clampType);
Brian Salomona076d872017-04-04 15:17:03 -0400187 } else {
188 return GrPorterDuffXPFactory::MakeSrcOverXferProcessor(color, coverage, hasMixedSamples,
189 caps);
190 }
bsalomon50785a32015-02-06 07:02:37 -0800191}