• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "src/gpu/GrXferProcessor.h"
9 
10 #include "src/gpu/GrCaps.h"
11 #include "src/gpu/GrPipeline.h"
12 
GrXferProcessor(ClassID classID)13 GrXferProcessor::GrXferProcessor(ClassID classID)
14         : INHERITED(classID)
15         , fWillReadDstColor(false)
16         , fDstReadUsesMixedSamples(false)
17         , fIsLCD(false) {}
18 
GrXferProcessor(ClassID classID,bool willReadDstColor,bool hasMixedSamples,GrProcessorAnalysisCoverage coverage)19 GrXferProcessor::GrXferProcessor(ClassID classID, bool willReadDstColor, bool hasMixedSamples,
20                                  GrProcessorAnalysisCoverage coverage)
21         : INHERITED(classID)
22         , fWillReadDstColor(willReadDstColor)
23         , fDstReadUsesMixedSamples(willReadDstColor && hasMixedSamples)
24         , fIsLCD(GrProcessorAnalysisCoverage::kLCD == coverage) {}
25 
hasSecondaryOutput() const26 bool GrXferProcessor::hasSecondaryOutput() const {
27     if (!this->willReadDstColor()) {
28         return this->onHasSecondaryOutput();
29     }
30     return this->dstReadUsesMixedSamples();
31 }
32 
getGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b,const GrSurfaceOrigin * originIfDstTexture) const33 void GrXferProcessor::getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b,
34                                           const GrSurfaceOrigin* originIfDstTexture) const {
35     uint32_t key = this->willReadDstColor() ? 0x1 : 0x0;
36     if (key) {
37         if (originIfDstTexture) {
38             key |= 0x2;
39             if (kTopLeft_GrSurfaceOrigin == *originIfDstTexture) {
40                 key |= 0x4;
41             }
42         }
43         if (this->dstReadUsesMixedSamples()) {
44             key |= 0x8;
45         }
46     }
47     if (fIsLCD) {
48         key |= 0x10;
49     }
50     b->add32(key);
51     this->onGetGLSLProcessorKey(caps, b);
52 }
53 
54 #ifdef SK_DEBUG
equation_string(GrBlendEquation eq)55 static 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";
93         case kIllegal_GrBlendEquation:
94             SkASSERT(false);
95             return "<illegal>";
96     }
97     return "";
98 }
99 
coeff_string(GrBlendCoeff coeff)100 static 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";
138         case kIllegal_GrBlendCoeff:
139             SkASSERT(false);
140             return "<illegal>";
141     }
142     return "";
143 }
144 
dump() const145 SkString 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.toBytes_RGBA());
150     return out;
151 }
152 #endif
153 
154 ///////////////////////////////////////////////////////////////////////////////
155 
GetAnalysisProperties(const GrXPFactory * factory,const GrProcessorAnalysisColor & color,const GrProcessorAnalysisCoverage & coverage,const GrCaps & caps,GrClampType clampType)156 GrXPFactory::AnalysisProperties GrXPFactory::GetAnalysisProperties(
157         const GrXPFactory* factory,
158         const GrProcessorAnalysisColor& color,
159         const GrProcessorAnalysisCoverage& coverage,
160         const GrCaps& caps,
161         GrClampType clampType) {
162     AnalysisProperties result;
163     if (factory) {
164         result = factory->analysisProperties(color, coverage, caps, clampType);
165     } else {
166         result = GrPorterDuffXPFactory::SrcOverAnalysisProperties(color, coverage, caps,
167                                                                   clampType);
168     }
169     SkASSERT(!(result & AnalysisProperties::kRequiresDstTexture));
170     if ((result & AnalysisProperties::kReadsDstInShader) &&
171         !caps.shaderCaps()->dstReadInShaderSupport()) {
172         result |= AnalysisProperties::kRequiresDstTexture |
173                   AnalysisProperties::kRequiresNonOverlappingDraws;
174     }
175     return result;
176 }
177 
MakeXferProcessor(const GrXPFactory * factory,const GrProcessorAnalysisColor & color,GrProcessorAnalysisCoverage coverage,bool hasMixedSamples,const GrCaps & caps,GrClampType clampType)178 sk_sp<const GrXferProcessor> GrXPFactory::MakeXferProcessor(const GrXPFactory* factory,
179                                                             const GrProcessorAnalysisColor& color,
180                                                             GrProcessorAnalysisCoverage coverage,
181                                                             bool hasMixedSamples,
182                                                             const GrCaps& caps,
183                                                             GrClampType clampType) {
184     SkASSERT(!hasMixedSamples || caps.shaderCaps()->dualSourceBlendingSupport());
185 
186     if (factory) {
187         return factory->makeXferProcessor(color, coverage, hasMixedSamples, caps, clampType);
188     } else {
189         return GrPorterDuffXPFactory::MakeSrcOverXferProcessor(color, coverage, hasMixedSamples,
190                                                                caps);
191     }
192 }
193