bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 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 "GrXferProcessor.h" |
ethannicholas | de4166a | 2015-11-30 08:57:38 -0800 | [diff] [blame] | 9 | #include "GrPipeline.h" |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 10 | #include "gl/GrGLCaps.h" |
| 11 | |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 12 | GrXferProcessor::GrXferProcessor(ClassID classID) |
| 13 | : INHERITED(classID) |
| 14 | , fWillReadDstColor(false) |
Greg Daniel | 6ebe4b9 | 2017-05-19 10:56:46 -0400 | [diff] [blame] | 15 | , fDstReadUsesMixedSamples(false) |
| 16 | , fIsLCD(false) {} |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 17 | |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 18 | GrXferProcessor::GrXferProcessor(ClassID classID, bool willReadDstColor, bool hasMixedSamples, |
Greg Daniel | 6ebe4b9 | 2017-05-19 10:56:46 -0400 | [diff] [blame] | 19 | GrProcessorAnalysisCoverage coverage) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 20 | : INHERITED(classID) |
| 21 | , fWillReadDstColor(willReadDstColor) |
Greg Daniel | 6ebe4b9 | 2017-05-19 10:56:46 -0400 | [diff] [blame] | 22 | , fDstReadUsesMixedSamples(willReadDstColor && hasMixedSamples) |
| 23 | , fIsLCD(GrProcessorAnalysisCoverage::kLCD == coverage) {} |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 24 | |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 25 | bool GrXferProcessor::hasSecondaryOutput() const { |
| 26 | if (!this->willReadDstColor()) { |
| 27 | return this->onHasSecondaryOutput(); |
| 28 | } |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 29 | return this->dstReadUsesMixedSamples(); |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | void GrXferProcessor::getBlendInfo(BlendInfo* blendInfo) const { |
| 33 | blendInfo->reset(); |
| 34 | if (!this->willReadDstColor()) { |
| 35 | this->onGetBlendInfo(blendInfo); |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 36 | } else if (this->dstReadUsesMixedSamples()) { |
| 37 | blendInfo->fDstBlend = kIS2A_GrBlendCoeff; |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 41 | void GrXferProcessor::getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b, |
| 42 | const GrSurfaceOrigin* originIfDstTexture) const { |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 43 | uint32_t key = this->willReadDstColor() ? 0x1 : 0x0; |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 44 | if (key) { |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 45 | if (originIfDstTexture) { |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 46 | key |= 0x2; |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 47 | if (kTopLeft_GrSurfaceOrigin == *originIfDstTexture) { |
cdalton | 827bae1 | 2015-06-08 13:43:33 -0700 | [diff] [blame] | 48 | key |= 0x4; |
| 49 | } |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 50 | } |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 51 | if (this->dstReadUsesMixedSamples()) { |
egdaniel | 56cf6dc | 2015-11-30 10:15:58 -0800 | [diff] [blame] | 52 | key |= 0x8; |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 53 | } |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 54 | } |
Greg Daniel | 6ebe4b9 | 2017-05-19 10:56:46 -0400 | [diff] [blame] | 55 | if (fIsLCD) { |
| 56 | key |= 0x10; |
| 57 | } |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 58 | b->add32(key); |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 59 | this->onGetGLSLProcessorKey(caps, b); |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 60 | } |
| 61 | |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 62 | #ifdef SK_DEBUG |
| 63 | static 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 | |
| 105 | static 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 | |
| 147 | SkString 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 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 156 | /////////////////////////////////////////////////////////////////////////////// |
| 157 | |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 158 | GrXPFactory::AnalysisProperties GrXPFactory::GetAnalysisProperties( |
| 159 | const GrXPFactory* factory, |
Brian Salomon | a811b12 | 2017-03-30 08:21:32 -0400 | [diff] [blame] | 160 | const GrProcessorAnalysisColor& color, |
| 161 | const GrProcessorAnalysisCoverage& coverage, |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 162 | const GrCaps& caps, |
| 163 | GrPixelConfigIsClamped dstIsClamped) { |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 164 | AnalysisProperties result; |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 165 | if (factory) { |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 166 | result = factory->analysisProperties(color, coverage, caps, dstIsClamped); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 167 | } else { |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 168 | result = GrPorterDuffXPFactory::SrcOverAnalysisProperties(color, coverage, caps, |
| 169 | dstIsClamped); |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 170 | } |
| 171 | SkASSERT(!(result & AnalysisProperties::kRequiresDstTexture)); |
| 172 | if ((result & AnalysisProperties::kReadsDstInShader) && |
| 173 | !caps.shaderCaps()->dstReadInShaderSupport()) { |
| 174 | result |= AnalysisProperties::kRequiresDstTexture; |
Brian Salomon | 4fc7740 | 2017-03-30 16:48:26 -0400 | [diff] [blame] | 175 | if (caps.textureBarrierSupport()) { |
| 176 | result |= AnalysisProperties::kRequiresBarrierBetweenOverlappingDraws; |
| 177 | } |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 178 | } |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 179 | return result; |
Brian Salomon | 9a51498 | 2017-02-14 10:28:22 -0500 | [diff] [blame] | 180 | } |
| 181 | |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 182 | sk_sp<const GrXferProcessor> GrXPFactory::MakeXferProcessor(const GrXPFactory* factory, |
| 183 | const GrProcessorAnalysisColor& color, |
| 184 | GrProcessorAnalysisCoverage coverage, |
| 185 | bool hasMixedSamples, |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 186 | const GrCaps& caps, |
| 187 | GrPixelConfigIsClamped dstIsClamped) { |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 188 | SkASSERT(!hasMixedSamples || caps.shaderCaps()->dualSourceBlendingSupport()); |
Brian Salomon | a076d87 | 2017-04-04 15:17:03 -0400 | [diff] [blame] | 189 | if (factory) { |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 190 | return factory->makeXferProcessor(color, coverage, hasMixedSamples, caps, dstIsClamped); |
Brian Salomon | a076d87 | 2017-04-04 15:17:03 -0400 | [diff] [blame] | 191 | } else { |
| 192 | return GrPorterDuffXPFactory::MakeSrcOverXferProcessor(color, coverage, hasMixedSamples, |
| 193 | caps); |
| 194 | } |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 195 | } |