blob: 8c0568bcae11a8d982b06efa57fed3ef3ade9f50 [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"
ethannicholasde4166a2015-11-30 08:57:38 -08009#include "GrPipeline.h"
bsalomon50785a32015-02-06 07:02:37 -080010#include "gl/GrGLCaps.h"
11
Greg Daniel6ebe4b92017-05-19 10:56:46 -040012GrXferProcessor::GrXferProcessor()
13 : fWillReadDstColor(false)
14 , fDstReadUsesMixedSamples(false)
15 , fIsLCD(false) {}
bsalomon50785a32015-02-06 07:02:37 -080016
Greg Daniel6ebe4b92017-05-19 10:56:46 -040017GrXferProcessor::GrXferProcessor(bool willReadDstColor, bool hasMixedSamples,
18 GrProcessorAnalysisCoverage coverage)
Brian Salomon18dfa982017-04-03 16:57:43 -040019 : fWillReadDstColor(willReadDstColor)
Greg Daniel6ebe4b92017-05-19 10:56:46 -040020 , fDstReadUsesMixedSamples(willReadDstColor && hasMixedSamples)
21 , fIsLCD(GrProcessorAnalysisCoverage::kLCD == coverage) {}
bsalomon50785a32015-02-06 07:02:37 -080022
cdaltonedbb31f2015-06-08 12:14:44 -070023bool GrXferProcessor::hasSecondaryOutput() const {
24 if (!this->willReadDstColor()) {
25 return this->onHasSecondaryOutput();
26 }
cdalton86ae0a92015-06-08 15:11:04 -070027 return this->dstReadUsesMixedSamples();
cdaltonedbb31f2015-06-08 12:14:44 -070028}
29
30void GrXferProcessor::getBlendInfo(BlendInfo* blendInfo) const {
31 blendInfo->reset();
32 if (!this->willReadDstColor()) {
33 this->onGetBlendInfo(blendInfo);
cdalton86ae0a92015-06-08 15:11:04 -070034 } else if (this->dstReadUsesMixedSamples()) {
35 blendInfo->fDstBlend = kIS2A_GrBlendCoeff;
cdaltonedbb31f2015-06-08 12:14:44 -070036 }
37}
38
Brian Salomon18dfa982017-04-03 16:57:43 -040039void GrXferProcessor::getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b,
40 const GrSurfaceOrigin* originIfDstTexture) const {
bsalomon50785a32015-02-06 07:02:37 -080041 uint32_t key = this->willReadDstColor() ? 0x1 : 0x0;
cdaltonedbb31f2015-06-08 12:14:44 -070042 if (key) {
Brian Salomon18dfa982017-04-03 16:57:43 -040043 if (originIfDstTexture) {
cdaltonedbb31f2015-06-08 12:14:44 -070044 key |= 0x2;
Brian Salomon18dfa982017-04-03 16:57:43 -040045 if (kTopLeft_GrSurfaceOrigin == *originIfDstTexture) {
cdalton827bae12015-06-08 13:43:33 -070046 key |= 0x4;
47 }
cdaltonedbb31f2015-06-08 12:14:44 -070048 }
cdalton86ae0a92015-06-08 15:11:04 -070049 if (this->dstReadUsesMixedSamples()) {
egdaniel56cf6dc2015-11-30 10:15:58 -080050 key |= 0x8;
cdalton86ae0a92015-06-08 15:11:04 -070051 }
bsalomon50785a32015-02-06 07:02:37 -080052 }
Greg Daniel6ebe4b92017-05-19 10:56:46 -040053 if (fIsLCD) {
54 key |= 0x10;
55 }
bsalomon50785a32015-02-06 07:02:37 -080056 b->add32(key);
egdaniel57d3b032015-11-13 11:57:27 -080057 this->onGetGLSLProcessorKey(caps, b);
bsalomon50785a32015-02-06 07:02:37 -080058}
59
bsalomonf7cc8772015-05-11 11:21:14 -070060#ifdef SK_DEBUG
61static const char* equation_string(GrBlendEquation eq) {
62 switch (eq) {
63 case kAdd_GrBlendEquation:
64 return "add";
65 case kSubtract_GrBlendEquation:
66 return "subtract";
67 case kReverseSubtract_GrBlendEquation:
68 return "reverse_subtract";
69 case kScreen_GrBlendEquation:
70 return "screen";
71 case kOverlay_GrBlendEquation:
72 return "overlay";
73 case kDarken_GrBlendEquation:
74 return "darken";
75 case kLighten_GrBlendEquation:
76 return "lighten";
77 case kColorDodge_GrBlendEquation:
78 return "color_dodge";
79 case kColorBurn_GrBlendEquation:
80 return "color_burn";
81 case kHardLight_GrBlendEquation:
82 return "hard_light";
83 case kSoftLight_GrBlendEquation:
84 return "soft_light";
85 case kDifference_GrBlendEquation:
86 return "difference";
87 case kExclusion_GrBlendEquation:
88 return "exclusion";
89 case kMultiply_GrBlendEquation:
90 return "multiply";
91 case kHSLHue_GrBlendEquation:
92 return "hsl_hue";
93 case kHSLSaturation_GrBlendEquation:
94 return "hsl_saturation";
95 case kHSLColor_GrBlendEquation:
96 return "hsl_color";
97 case kHSLLuminosity_GrBlendEquation:
98 return "hsl_luminosity";
99 };
100 return "";
101}
102
103static const char* coeff_string(GrBlendCoeff coeff) {
104 switch (coeff) {
105 case kZero_GrBlendCoeff:
106 return "zero";
107 case kOne_GrBlendCoeff:
108 return "one";
109 case kSC_GrBlendCoeff:
110 return "src_color";
111 case kISC_GrBlendCoeff:
112 return "inv_src_color";
113 case kDC_GrBlendCoeff:
114 return "dst_color";
115 case kIDC_GrBlendCoeff:
116 return "inv_dst_color";
117 case kSA_GrBlendCoeff:
118 return "src_alpha";
119 case kISA_GrBlendCoeff:
120 return "inv_src_alpha";
121 case kDA_GrBlendCoeff:
122 return "dst_alpha";
123 case kIDA_GrBlendCoeff:
124 return "inv_dst_alpha";
125 case kConstC_GrBlendCoeff:
126 return "const_color";
127 case kIConstC_GrBlendCoeff:
128 return "inv_const_color";
129 case kConstA_GrBlendCoeff:
130 return "const_alpha";
131 case kIConstA_GrBlendCoeff:
132 return "inv_const_alpha";
133 case kS2C_GrBlendCoeff:
134 return "src2_color";
135 case kIS2C_GrBlendCoeff:
136 return "inv_src2_color";
137 case kS2A_GrBlendCoeff:
138 return "src2_alpha";
139 case kIS2A_GrBlendCoeff:
140 return "inv_src2_alpha";
141 }
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),
149 coeff_string(fDstBlend), fBlendConstant);
150 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 Salomon31853842017-03-28 16:32:05 -0400160 const GrCaps& caps) {
161 AnalysisProperties result;
Brian Salomon5298dc82017-02-22 11:52:03 -0500162 if (factory) {
Brian Salomon31853842017-03-28 16:32:05 -0400163 result = factory->analysisProperties(color, coverage, caps);
Brian Salomon5298dc82017-02-22 11:52:03 -0500164 } else {
Brian Salomon31853842017-03-28 16:32:05 -0400165 result = GrPorterDuffXPFactory::SrcOverAnalysisProperties(color, coverage, caps);
166 }
167 SkASSERT(!(result & AnalysisProperties::kRequiresDstTexture));
168 if ((result & AnalysisProperties::kReadsDstInShader) &&
169 !caps.shaderCaps()->dstReadInShaderSupport()) {
170 result |= AnalysisProperties::kRequiresDstTexture;
Brian Salomon4fc77402017-03-30 16:48:26 -0400171 if (caps.textureBarrierSupport()) {
172 result |= AnalysisProperties::kRequiresBarrierBetweenOverlappingDraws;
173 }
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,
182 const GrCaps& caps) {
cdalton86ae0a92015-06-08 15:11:04 -0700183 SkASSERT(!hasMixedSamples || caps.shaderCaps()->dualSourceBlendingSupport());
Brian Salomona076d872017-04-04 15:17:03 -0400184 if (factory) {
185 return factory->makeXferProcessor(color, coverage, hasMixedSamples, caps);
186 } else {
187 return GrPorterDuffXPFactory::MakeSrcOverXferProcessor(color, coverage, hasMixedSamples,
188 caps);
189 }
bsalomon50785a32015-02-06 07:02:37 -0800190}