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