blob: a008e98745ecaa96bd118c8e7d052e0eaac534dc [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
8#include "GrXferProcessor.h"
Robert Phillipsbe77a022018-04-03 17:17:05 -04009
10#include "GrCaps.h"
ethannicholasde4166a2015-11-30 08:57:38 -080011#include "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
33void GrXferProcessor::getBlendInfo(BlendInfo* blendInfo) const {
34 blendInfo->reset();
35 if (!this->willReadDstColor()) {
36 this->onGetBlendInfo(blendInfo);
cdalton86ae0a92015-06-08 15:11:04 -070037 } else if (this->dstReadUsesMixedSamples()) {
38 blendInfo->fDstBlend = kIS2A_GrBlendCoeff;
cdaltonedbb31f2015-06-08 12:14:44 -070039 }
40}
41
Brian Salomon18dfa982017-04-03 16:57:43 -040042void GrXferProcessor::getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b,
43 const GrSurfaceOrigin* originIfDstTexture) const {
bsalomon50785a32015-02-06 07:02:37 -080044 uint32_t key = this->willReadDstColor() ? 0x1 : 0x0;
cdaltonedbb31f2015-06-08 12:14:44 -070045 if (key) {
Brian Salomon18dfa982017-04-03 16:57:43 -040046 if (originIfDstTexture) {
cdaltonedbb31f2015-06-08 12:14:44 -070047 key |= 0x2;
Brian Salomon18dfa982017-04-03 16:57:43 -040048 if (kTopLeft_GrSurfaceOrigin == *originIfDstTexture) {
cdalton827bae12015-06-08 13:43:33 -070049 key |= 0x4;
50 }
cdaltonedbb31f2015-06-08 12:14:44 -070051 }
cdalton86ae0a92015-06-08 15:11:04 -070052 if (this->dstReadUsesMixedSamples()) {
egdaniel56cf6dc2015-11-30 10:15:58 -080053 key |= 0x8;
cdalton86ae0a92015-06-08 15:11:04 -070054 }
bsalomon50785a32015-02-06 07:02:37 -080055 }
Greg Daniel6ebe4b92017-05-19 10:56:46 -040056 if (fIsLCD) {
57 key |= 0x10;
58 }
bsalomon50785a32015-02-06 07:02:37 -080059 b->add32(key);
egdaniel57d3b032015-11-13 11:57:27 -080060 this->onGetGLSLProcessorKey(caps, b);
bsalomon50785a32015-02-06 07:02:37 -080061}
62
bsalomonf7cc8772015-05-11 11:21:14 -070063#ifdef SK_DEBUG
64static const char* equation_string(GrBlendEquation eq) {
65 switch (eq) {
66 case kAdd_GrBlendEquation:
67 return "add";
68 case kSubtract_GrBlendEquation:
69 return "subtract";
70 case kReverseSubtract_GrBlendEquation:
71 return "reverse_subtract";
72 case kScreen_GrBlendEquation:
73 return "screen";
74 case kOverlay_GrBlendEquation:
75 return "overlay";
76 case kDarken_GrBlendEquation:
77 return "darken";
78 case kLighten_GrBlendEquation:
79 return "lighten";
80 case kColorDodge_GrBlendEquation:
81 return "color_dodge";
82 case kColorBurn_GrBlendEquation:
83 return "color_burn";
84 case kHardLight_GrBlendEquation:
85 return "hard_light";
86 case kSoftLight_GrBlendEquation:
87 return "soft_light";
88 case kDifference_GrBlendEquation:
89 return "difference";
90 case kExclusion_GrBlendEquation:
91 return "exclusion";
92 case kMultiply_GrBlendEquation:
93 return "multiply";
94 case kHSLHue_GrBlendEquation:
95 return "hsl_hue";
96 case kHSLSaturation_GrBlendEquation:
97 return "hsl_saturation";
98 case kHSLColor_GrBlendEquation:
99 return "hsl_color";
100 case kHSLLuminosity_GrBlendEquation:
101 return "hsl_luminosity";
102 };
103 return "";
104}
105
106static const char* coeff_string(GrBlendCoeff coeff) {
107 switch (coeff) {
108 case kZero_GrBlendCoeff:
109 return "zero";
110 case kOne_GrBlendCoeff:
111 return "one";
112 case kSC_GrBlendCoeff:
113 return "src_color";
114 case kISC_GrBlendCoeff:
115 return "inv_src_color";
116 case kDC_GrBlendCoeff:
117 return "dst_color";
118 case kIDC_GrBlendCoeff:
119 return "inv_dst_color";
120 case kSA_GrBlendCoeff:
121 return "src_alpha";
122 case kISA_GrBlendCoeff:
123 return "inv_src_alpha";
124 case kDA_GrBlendCoeff:
125 return "dst_alpha";
126 case kIDA_GrBlendCoeff:
127 return "inv_dst_alpha";
128 case kConstC_GrBlendCoeff:
129 return "const_color";
130 case kIConstC_GrBlendCoeff:
131 return "inv_const_color";
132 case kConstA_GrBlendCoeff:
133 return "const_alpha";
134 case kIConstA_GrBlendCoeff:
135 return "inv_const_alpha";
136 case kS2C_GrBlendCoeff:
137 return "src2_color";
138 case kIS2C_GrBlendCoeff:
139 return "inv_src2_color";
140 case kS2A_GrBlendCoeff:
141 return "src2_alpha";
142 case kIS2A_GrBlendCoeff:
143 return "inv_src2_alpha";
144 }
145 return "";
146}
147
148SkString GrXferProcessor::BlendInfo::dump() const {
149 SkString out;
150 out.printf("write_color(%d) equation(%s) src_coeff(%s) dst_coeff:(%s) const(0x%08x)",
151 fWriteColor, equation_string(fEquation), coeff_string(fSrcBlend),
152 coeff_string(fDstBlend), fBlendConstant);
153 return out;
154}
155#endif
156
bsalomon50785a32015-02-06 07:02:37 -0800157///////////////////////////////////////////////////////////////////////////////
158
Brian Salomon31853842017-03-28 16:32:05 -0400159GrXPFactory::AnalysisProperties GrXPFactory::GetAnalysisProperties(
160 const GrXPFactory* factory,
Brian Salomona811b122017-03-30 08:21:32 -0400161 const GrProcessorAnalysisColor& color,
162 const GrProcessorAnalysisCoverage& coverage,
Brian Osman532b3f92018-07-11 10:02:07 -0400163 const GrCaps& caps) {
Brian Salomon31853842017-03-28 16:32:05 -0400164 AnalysisProperties result;
Brian Salomon5298dc82017-02-22 11:52:03 -0500165 if (factory) {
Brian Osman532b3f92018-07-11 10:02:07 -0400166 result = factory->analysisProperties(color, coverage, caps);
Brian Salomon5298dc82017-02-22 11:52:03 -0500167 } else {
Brian Osman532b3f92018-07-11 10:02:07 -0400168 result = GrPorterDuffXPFactory::SrcOverAnalysisProperties(color, coverage, caps);
Brian Salomon31853842017-03-28 16:32:05 -0400169 }
170 SkASSERT(!(result & AnalysisProperties::kRequiresDstTexture));
171 if ((result & AnalysisProperties::kReadsDstInShader) &&
172 !caps.shaderCaps()->dstReadInShaderSupport()) {
173 result |= AnalysisProperties::kRequiresDstTexture;
Brian Salomon4fc77402017-03-30 16:48:26 -0400174 if (caps.textureBarrierSupport()) {
175 result |= AnalysisProperties::kRequiresBarrierBetweenOverlappingDraws;
176 }
Brian Salomon5298dc82017-02-22 11:52:03 -0500177 }
Brian Salomon5298dc82017-02-22 11:52:03 -0500178 return result;
Brian Salomon9a514982017-02-14 10:28:22 -0500179}
180
Brian Salomond61c9d92017-04-10 10:54:25 -0400181sk_sp<const GrXferProcessor> GrXPFactory::MakeXferProcessor(const GrXPFactory* factory,
182 const GrProcessorAnalysisColor& color,
183 GrProcessorAnalysisCoverage coverage,
184 bool hasMixedSamples,
Brian Osman532b3f92018-07-11 10:02:07 -0400185 const GrCaps& caps) {
cdalton86ae0a92015-06-08 15:11:04 -0700186 SkASSERT(!hasMixedSamples || caps.shaderCaps()->dualSourceBlendingSupport());
Brian Salomona076d872017-04-04 15:17:03 -0400187 if (factory) {
Brian Osman532b3f92018-07-11 10:02:07 -0400188 return factory->makeXferProcessor(color, coverage, hasMixedSamples, caps);
Brian Salomona076d872017-04-04 15:17:03 -0400189 } else {
190 return GrPorterDuffXPFactory::MakeSrcOverXferProcessor(color, coverage, hasMixedSamples,
191 caps);
192 }
bsalomon50785a32015-02-06 07:02:37 -0800193}