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"; |
Mike Klein | 3674336 | 2018-11-06 08:23:30 -0500 | [diff] [blame] | 102 | case kIllegal_GrBlendEquation: |
| 103 | SkASSERT(false); |
| 104 | return "<illegal>"; |
Brian Salomon | 2335644 | 2018-11-30 15:33:19 -0500 | [diff] [blame] | 105 | } |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 106 | return ""; |
| 107 | } |
| 108 | |
| 109 | static const char* coeff_string(GrBlendCoeff coeff) { |
| 110 | switch (coeff) { |
| 111 | case kZero_GrBlendCoeff: |
| 112 | return "zero"; |
| 113 | case kOne_GrBlendCoeff: |
| 114 | return "one"; |
| 115 | case kSC_GrBlendCoeff: |
| 116 | return "src_color"; |
| 117 | case kISC_GrBlendCoeff: |
| 118 | return "inv_src_color"; |
| 119 | case kDC_GrBlendCoeff: |
| 120 | return "dst_color"; |
| 121 | case kIDC_GrBlendCoeff: |
| 122 | return "inv_dst_color"; |
| 123 | case kSA_GrBlendCoeff: |
| 124 | return "src_alpha"; |
| 125 | case kISA_GrBlendCoeff: |
| 126 | return "inv_src_alpha"; |
| 127 | case kDA_GrBlendCoeff: |
| 128 | return "dst_alpha"; |
| 129 | case kIDA_GrBlendCoeff: |
| 130 | return "inv_dst_alpha"; |
| 131 | case kConstC_GrBlendCoeff: |
| 132 | return "const_color"; |
| 133 | case kIConstC_GrBlendCoeff: |
| 134 | return "inv_const_color"; |
| 135 | case kConstA_GrBlendCoeff: |
| 136 | return "const_alpha"; |
| 137 | case kIConstA_GrBlendCoeff: |
| 138 | return "inv_const_alpha"; |
| 139 | case kS2C_GrBlendCoeff: |
| 140 | return "src2_color"; |
| 141 | case kIS2C_GrBlendCoeff: |
| 142 | return "inv_src2_color"; |
| 143 | case kS2A_GrBlendCoeff: |
| 144 | return "src2_alpha"; |
| 145 | case kIS2A_GrBlendCoeff: |
| 146 | return "inv_src2_alpha"; |
Mike Klein | 3674336 | 2018-11-06 08:23:30 -0500 | [diff] [blame] | 147 | case kIllegal_GrBlendCoeff: |
| 148 | SkASSERT(false); |
| 149 | return "<illegal>"; |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 150 | } |
| 151 | return ""; |
| 152 | } |
| 153 | |
| 154 | SkString GrXferProcessor::BlendInfo::dump() const { |
| 155 | SkString out; |
| 156 | out.printf("write_color(%d) equation(%s) src_coeff(%s) dst_coeff:(%s) const(0x%08x)", |
| 157 | fWriteColor, equation_string(fEquation), coeff_string(fSrcBlend), |
Brian Osman | 422f95b | 2018-11-05 16:49:04 -0500 | [diff] [blame] | 158 | coeff_string(fDstBlend), fBlendConstant.toBytes_RGBA()); |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 159 | return out; |
| 160 | } |
| 161 | #endif |
| 162 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 163 | /////////////////////////////////////////////////////////////////////////////// |
| 164 | |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 165 | GrXPFactory::AnalysisProperties GrXPFactory::GetAnalysisProperties( |
| 166 | const GrXPFactory* factory, |
Brian Salomon | a811b12 | 2017-03-30 08:21:32 -0400 | [diff] [blame] | 167 | const GrProcessorAnalysisColor& color, |
| 168 | const GrProcessorAnalysisCoverage& coverage, |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 169 | const GrCaps& caps) { |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 170 | AnalysisProperties result; |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 171 | if (factory) { |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 172 | result = factory->analysisProperties(color, coverage, caps); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 173 | } else { |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 174 | result = GrPorterDuffXPFactory::SrcOverAnalysisProperties(color, coverage, caps); |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 175 | } |
| 176 | SkASSERT(!(result & AnalysisProperties::kRequiresDstTexture)); |
| 177 | if ((result & AnalysisProperties::kReadsDstInShader) && |
| 178 | !caps.shaderCaps()->dstReadInShaderSupport()) { |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 179 | result |= AnalysisProperties::kRequiresDstTexture | |
| 180 | AnalysisProperties::kRequiresNonOverlappingDraws; |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 181 | } |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 182 | return result; |
Brian Salomon | 9a51498 | 2017-02-14 10:28:22 -0500 | [diff] [blame] | 183 | } |
| 184 | |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 185 | sk_sp<const GrXferProcessor> GrXPFactory::MakeXferProcessor(const GrXPFactory* factory, |
| 186 | const GrProcessorAnalysisColor& color, |
| 187 | GrProcessorAnalysisCoverage coverage, |
| 188 | bool hasMixedSamples, |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 189 | const GrCaps& caps) { |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 190 | SkASSERT(!hasMixedSamples || caps.shaderCaps()->dualSourceBlendingSupport()); |
Brian Salomon | a076d87 | 2017-04-04 15:17:03 -0400 | [diff] [blame] | 191 | if (factory) { |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 192 | return factory->makeXferProcessor(color, coverage, hasMixedSamples, caps); |
Brian Salomon | a076d87 | 2017-04-04 15:17:03 -0400 | [diff] [blame] | 193 | } else { |
| 194 | return GrPorterDuffXPFactory::MakeSrcOverXferProcessor(color, coverage, hasMixedSamples, |
| 195 | caps); |
| 196 | } |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 197 | } |