blob: 8f7377e0b2333339cbf980ab4aa780acf26bfe8d [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
Ethan Nicholasabff9562017-10-09 10:54:08 -040012GrXferProcessor::GrXferProcessor(ClassID classID)
13 : INHERITED(classID)
14 , fWillReadDstColor(false)
Greg Daniel6ebe4b92017-05-19 10:56:46 -040015 , fDstReadUsesMixedSamples(false)
16 , fIsLCD(false) {}
bsalomon50785a32015-02-06 07:02:37 -080017
Ethan Nicholasabff9562017-10-09 10:54:08 -040018GrXferProcessor::GrXferProcessor(ClassID classID, bool willReadDstColor, bool hasMixedSamples,
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 , fDstReadUsesMixedSamples(willReadDstColor && hasMixedSamples)
23 , fIsLCD(GrProcessorAnalysisCoverage::kLCD == coverage) {}
bsalomon50785a32015-02-06 07:02:37 -080024
cdaltonedbb31f2015-06-08 12:14:44 -070025bool GrXferProcessor::hasSecondaryOutput() const {
26 if (!this->willReadDstColor()) {
27 return this->onHasSecondaryOutput();
28 }
cdalton86ae0a92015-06-08 15:11:04 -070029 return this->dstReadUsesMixedSamples();
cdaltonedbb31f2015-06-08 12:14:44 -070030}
31
32void GrXferProcessor::getBlendInfo(BlendInfo* blendInfo) const {
33 blendInfo->reset();
34 if (!this->willReadDstColor()) {
35 this->onGetBlendInfo(blendInfo);
cdalton86ae0a92015-06-08 15:11:04 -070036 } else if (this->dstReadUsesMixedSamples()) {
37 blendInfo->fDstBlend = kIS2A_GrBlendCoeff;
cdaltonedbb31f2015-06-08 12:14:44 -070038 }
39}
40
Brian Salomon18dfa982017-04-03 16:57:43 -040041void GrXferProcessor::getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b,
42 const GrSurfaceOrigin* originIfDstTexture) const {
bsalomon50785a32015-02-06 07:02:37 -080043 uint32_t key = this->willReadDstColor() ? 0x1 : 0x0;
cdaltonedbb31f2015-06-08 12:14:44 -070044 if (key) {
Brian Salomon18dfa982017-04-03 16:57:43 -040045 if (originIfDstTexture) {
cdaltonedbb31f2015-06-08 12:14:44 -070046 key |= 0x2;
Brian Salomon18dfa982017-04-03 16:57:43 -040047 if (kTopLeft_GrSurfaceOrigin == *originIfDstTexture) {
cdalton827bae12015-06-08 13:43:33 -070048 key |= 0x4;
49 }
cdaltonedbb31f2015-06-08 12:14:44 -070050 }
cdalton86ae0a92015-06-08 15:11:04 -070051 if (this->dstReadUsesMixedSamples()) {
egdaniel56cf6dc2015-11-30 10:15:58 -080052 key |= 0x8;
cdalton86ae0a92015-06-08 15:11:04 -070053 }
bsalomon50785a32015-02-06 07:02:37 -080054 }
Greg Daniel6ebe4b92017-05-19 10:56:46 -040055 if (fIsLCD) {
56 key |= 0x10;
57 }
bsalomon50785a32015-02-06 07:02:37 -080058 b->add32(key);
egdaniel57d3b032015-11-13 11:57:27 -080059 this->onGetGLSLProcessorKey(caps, b);
bsalomon50785a32015-02-06 07:02:37 -080060}
61
bsalomonf7cc8772015-05-11 11:21:14 -070062#ifdef SK_DEBUG
63static const char* equation_string(GrBlendEquation eq) {
64 switch (eq) {
65 case kAdd_GrBlendEquation:
66 return "add";
67 case kSubtract_GrBlendEquation:
68 return "subtract";
69 case kReverseSubtract_GrBlendEquation:
70 return "reverse_subtract";
71 case kScreen_GrBlendEquation:
72 return "screen";
73 case kOverlay_GrBlendEquation:
74 return "overlay";
75 case kDarken_GrBlendEquation:
76 return "darken";
77 case kLighten_GrBlendEquation:
78 return "lighten";
79 case kColorDodge_GrBlendEquation:
80 return "color_dodge";
81 case kColorBurn_GrBlendEquation:
82 return "color_burn";
83 case kHardLight_GrBlendEquation:
84 return "hard_light";
85 case kSoftLight_GrBlendEquation:
86 return "soft_light";
87 case kDifference_GrBlendEquation:
88 return "difference";
89 case kExclusion_GrBlendEquation:
90 return "exclusion";
91 case kMultiply_GrBlendEquation:
92 return "multiply";
93 case kHSLHue_GrBlendEquation:
94 return "hsl_hue";
95 case kHSLSaturation_GrBlendEquation:
96 return "hsl_saturation";
97 case kHSLColor_GrBlendEquation:
98 return "hsl_color";
99 case kHSLLuminosity_GrBlendEquation:
100 return "hsl_luminosity";
101 };
102 return "";
103}
104
105static const char* coeff_string(GrBlendCoeff coeff) {
106 switch (coeff) {
107 case kZero_GrBlendCoeff:
108 return "zero";
109 case kOne_GrBlendCoeff:
110 return "one";
111 case kSC_GrBlendCoeff:
112 return "src_color";
113 case kISC_GrBlendCoeff:
114 return "inv_src_color";
115 case kDC_GrBlendCoeff:
116 return "dst_color";
117 case kIDC_GrBlendCoeff:
118 return "inv_dst_color";
119 case kSA_GrBlendCoeff:
120 return "src_alpha";
121 case kISA_GrBlendCoeff:
122 return "inv_src_alpha";
123 case kDA_GrBlendCoeff:
124 return "dst_alpha";
125 case kIDA_GrBlendCoeff:
126 return "inv_dst_alpha";
127 case kConstC_GrBlendCoeff:
128 return "const_color";
129 case kIConstC_GrBlendCoeff:
130 return "inv_const_color";
131 case kConstA_GrBlendCoeff:
132 return "const_alpha";
133 case kIConstA_GrBlendCoeff:
134 return "inv_const_alpha";
135 case kS2C_GrBlendCoeff:
136 return "src2_color";
137 case kIS2C_GrBlendCoeff:
138 return "inv_src2_color";
139 case kS2A_GrBlendCoeff:
140 return "src2_alpha";
141 case kIS2A_GrBlendCoeff:
142 return "inv_src2_alpha";
143 }
144 return "";
145}
146
147SkString GrXferProcessor::BlendInfo::dump() const {
148 SkString out;
149 out.printf("write_color(%d) equation(%s) src_coeff(%s) dst_coeff:(%s) const(0x%08x)",
150 fWriteColor, equation_string(fEquation), coeff_string(fSrcBlend),
151 coeff_string(fDstBlend), fBlendConstant);
152 return out;
153}
154#endif
155
bsalomon50785a32015-02-06 07:02:37 -0800156///////////////////////////////////////////////////////////////////////////////
157
Brian Salomon31853842017-03-28 16:32:05 -0400158GrXPFactory::AnalysisProperties GrXPFactory::GetAnalysisProperties(
159 const GrXPFactory* factory,
Brian Salomona811b122017-03-30 08:21:32 -0400160 const GrProcessorAnalysisColor& color,
161 const GrProcessorAnalysisCoverage& coverage,
Brian Osman9a725dd2017-09-20 09:53:22 -0400162 const GrCaps& caps,
163 GrPixelConfigIsClamped dstIsClamped) {
Brian Salomon31853842017-03-28 16:32:05 -0400164 AnalysisProperties result;
Brian Salomon5298dc82017-02-22 11:52:03 -0500165 if (factory) {
Brian Osman9a725dd2017-09-20 09:53:22 -0400166 result = factory->analysisProperties(color, coverage, caps, dstIsClamped);
Brian Salomon5298dc82017-02-22 11:52:03 -0500167 } else {
Brian Osman9a725dd2017-09-20 09:53:22 -0400168 result = GrPorterDuffXPFactory::SrcOverAnalysisProperties(color, coverage, caps,
169 dstIsClamped);
Brian Salomon31853842017-03-28 16:32:05 -0400170 }
171 SkASSERT(!(result & AnalysisProperties::kRequiresDstTexture));
172 if ((result & AnalysisProperties::kReadsDstInShader) &&
173 !caps.shaderCaps()->dstReadInShaderSupport()) {
174 result |= AnalysisProperties::kRequiresDstTexture;
Brian Salomon4fc77402017-03-30 16:48:26 -0400175 if (caps.textureBarrierSupport()) {
176 result |= AnalysisProperties::kRequiresBarrierBetweenOverlappingDraws;
177 }
Brian Salomon5298dc82017-02-22 11:52:03 -0500178 }
Brian Salomon5298dc82017-02-22 11:52:03 -0500179 return result;
Brian Salomon9a514982017-02-14 10:28:22 -0500180}
181
Brian Salomond61c9d92017-04-10 10:54:25 -0400182sk_sp<const GrXferProcessor> GrXPFactory::MakeXferProcessor(const GrXPFactory* factory,
183 const GrProcessorAnalysisColor& color,
184 GrProcessorAnalysisCoverage coverage,
185 bool hasMixedSamples,
Brian Osman9a725dd2017-09-20 09:53:22 -0400186 const GrCaps& caps,
187 GrPixelConfigIsClamped dstIsClamped) {
cdalton86ae0a92015-06-08 15:11:04 -0700188 SkASSERT(!hasMixedSamples || caps.shaderCaps()->dualSourceBlendingSupport());
Brian Salomona076d872017-04-04 15:17:03 -0400189 if (factory) {
Brian Osman9a725dd2017-09-20 09:53:22 -0400190 return factory->makeXferProcessor(color, coverage, hasMixedSamples, caps, dstIsClamped);
Brian Salomona076d872017-04-04 15:17:03 -0400191 } else {
192 return GrPorterDuffXPFactory::MakeSrcOverXferProcessor(color, coverage, hasMixedSamples,
193 caps);
194 }
bsalomon50785a32015-02-06 07:02:37 -0800195}