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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrXferProcessor.h" |
Robert Phillips | be77a02 | 2018-04-03 17:17:05 -0400 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "src/gpu/GrCaps.h" |
| 11 | #include "src/gpu/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 | , fIsLCD(false) {} |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 17 | |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame^] | 18 | GrXferProcessor::GrXferProcessor(ClassID classID, bool willReadDstColor, |
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 | , fIsLCD(GrProcessorAnalysisCoverage::kLCD == coverage) {} |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 23 | |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 24 | bool GrXferProcessor::hasSecondaryOutput() const { |
| 25 | if (!this->willReadDstColor()) { |
| 26 | return this->onHasSecondaryOutput(); |
| 27 | } |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame^] | 28 | return false; |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 31 | void GrXferProcessor::getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b, |
Greg Daniel | 70dd6a9 | 2020-10-09 10:09:06 -0400 | [diff] [blame] | 32 | const GrSurfaceOrigin* originIfDstTexture, |
| 33 | GrDstSampleType dstSampleType) const { |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 34 | uint32_t key = this->willReadDstColor() ? 0x1 : 0x0; |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 35 | if (key) { |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 36 | if (originIfDstTexture) { |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 37 | key |= 0x2; |
Brian Salomon | 18dfa98 | 2017-04-03 16:57:43 -0400 | [diff] [blame] | 38 | if (kTopLeft_GrSurfaceOrigin == *originIfDstTexture) { |
cdalton | 827bae1 | 2015-06-08 13:43:33 -0700 | [diff] [blame] | 39 | key |= 0x4; |
| 40 | } |
Greg Daniel | 70dd6a9 | 2020-10-09 10:09:06 -0400 | [diff] [blame] | 41 | // We don't just add the whole dstSampleType to the key because sampling a copy or the |
| 42 | // rt directly produces the same shader code. |
| 43 | if (dstSampleType == GrDstSampleType::kAsInputAttachment) { |
| 44 | key |= 0x8; |
| 45 | } |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 46 | } |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 47 | } |
Greg Daniel | 6ebe4b9 | 2017-05-19 10:56:46 -0400 | [diff] [blame] | 48 | if (fIsLCD) { |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame^] | 49 | key |= 0x10; |
Greg Daniel | 6ebe4b9 | 2017-05-19 10:56:46 -0400 | [diff] [blame] | 50 | } |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 51 | b->add32(key); |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 52 | this->onGetGLSLProcessorKey(caps, b); |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 53 | } |
| 54 | |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 55 | #ifdef SK_DEBUG |
| 56 | static const char* equation_string(GrBlendEquation eq) { |
| 57 | switch (eq) { |
| 58 | case kAdd_GrBlendEquation: |
| 59 | return "add"; |
| 60 | case kSubtract_GrBlendEquation: |
| 61 | return "subtract"; |
| 62 | case kReverseSubtract_GrBlendEquation: |
| 63 | return "reverse_subtract"; |
| 64 | case kScreen_GrBlendEquation: |
| 65 | return "screen"; |
| 66 | case kOverlay_GrBlendEquation: |
| 67 | return "overlay"; |
| 68 | case kDarken_GrBlendEquation: |
| 69 | return "darken"; |
| 70 | case kLighten_GrBlendEquation: |
| 71 | return "lighten"; |
| 72 | case kColorDodge_GrBlendEquation: |
| 73 | return "color_dodge"; |
| 74 | case kColorBurn_GrBlendEquation: |
| 75 | return "color_burn"; |
| 76 | case kHardLight_GrBlendEquation: |
| 77 | return "hard_light"; |
| 78 | case kSoftLight_GrBlendEquation: |
| 79 | return "soft_light"; |
| 80 | case kDifference_GrBlendEquation: |
| 81 | return "difference"; |
| 82 | case kExclusion_GrBlendEquation: |
| 83 | return "exclusion"; |
| 84 | case kMultiply_GrBlendEquation: |
| 85 | return "multiply"; |
| 86 | case kHSLHue_GrBlendEquation: |
| 87 | return "hsl_hue"; |
| 88 | case kHSLSaturation_GrBlendEquation: |
| 89 | return "hsl_saturation"; |
| 90 | case kHSLColor_GrBlendEquation: |
| 91 | return "hsl_color"; |
| 92 | case kHSLLuminosity_GrBlendEquation: |
| 93 | return "hsl_luminosity"; |
Mike Klein | 3674336 | 2018-11-06 08:23:30 -0500 | [diff] [blame] | 94 | case kIllegal_GrBlendEquation: |
| 95 | SkASSERT(false); |
| 96 | return "<illegal>"; |
Brian Salomon | 2335644 | 2018-11-30 15:33:19 -0500 | [diff] [blame] | 97 | } |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 98 | return ""; |
| 99 | } |
| 100 | |
| 101 | static const char* coeff_string(GrBlendCoeff coeff) { |
| 102 | switch (coeff) { |
| 103 | case kZero_GrBlendCoeff: |
| 104 | return "zero"; |
| 105 | case kOne_GrBlendCoeff: |
| 106 | return "one"; |
| 107 | case kSC_GrBlendCoeff: |
| 108 | return "src_color"; |
| 109 | case kISC_GrBlendCoeff: |
| 110 | return "inv_src_color"; |
| 111 | case kDC_GrBlendCoeff: |
| 112 | return "dst_color"; |
| 113 | case kIDC_GrBlendCoeff: |
| 114 | return "inv_dst_color"; |
| 115 | case kSA_GrBlendCoeff: |
| 116 | return "src_alpha"; |
| 117 | case kISA_GrBlendCoeff: |
| 118 | return "inv_src_alpha"; |
| 119 | case kDA_GrBlendCoeff: |
| 120 | return "dst_alpha"; |
| 121 | case kIDA_GrBlendCoeff: |
| 122 | return "inv_dst_alpha"; |
| 123 | case kConstC_GrBlendCoeff: |
| 124 | return "const_color"; |
| 125 | case kIConstC_GrBlendCoeff: |
| 126 | return "inv_const_color"; |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 127 | case kS2C_GrBlendCoeff: |
| 128 | return "src2_color"; |
| 129 | case kIS2C_GrBlendCoeff: |
| 130 | return "inv_src2_color"; |
| 131 | case kS2A_GrBlendCoeff: |
| 132 | return "src2_alpha"; |
| 133 | case kIS2A_GrBlendCoeff: |
| 134 | return "inv_src2_alpha"; |
Mike Klein | 3674336 | 2018-11-06 08:23:30 -0500 | [diff] [blame] | 135 | case kIllegal_GrBlendCoeff: |
| 136 | SkASSERT(false); |
| 137 | return "<illegal>"; |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 138 | } |
| 139 | return ""; |
| 140 | } |
| 141 | |
| 142 | SkString GrXferProcessor::BlendInfo::dump() const { |
| 143 | SkString out; |
| 144 | out.printf("write_color(%d) equation(%s) src_coeff(%s) dst_coeff:(%s) const(0x%08x)", |
| 145 | fWriteColor, equation_string(fEquation), coeff_string(fSrcBlend), |
Brian Osman | 422f95b | 2018-11-05 16:49:04 -0500 | [diff] [blame] | 146 | coeff_string(fDstBlend), fBlendConstant.toBytes_RGBA()); |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 147 | return out; |
| 148 | } |
| 149 | #endif |
| 150 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 151 | /////////////////////////////////////////////////////////////////////////////// |
| 152 | |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 153 | GrXPFactory::AnalysisProperties GrXPFactory::GetAnalysisProperties( |
| 154 | const GrXPFactory* factory, |
Brian Salomon | a811b12 | 2017-03-30 08:21:32 -0400 | [diff] [blame] | 155 | const GrProcessorAnalysisColor& color, |
| 156 | const GrProcessorAnalysisCoverage& coverage, |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 157 | const GrCaps& caps, |
| 158 | GrClampType clampType) { |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 159 | AnalysisProperties result; |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 160 | if (factory) { |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame^] | 161 | result = factory->analysisProperties(color, coverage, caps, clampType); |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 162 | } else { |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame^] | 163 | result = GrPorterDuffXPFactory::SrcOverAnalysisProperties(color, coverage, caps, clampType); |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 164 | } |
Greg Daniel | c529681 | 2020-02-28 13:06:02 -0500 | [diff] [blame] | 165 | if (coverage == GrProcessorAnalysisCoverage::kNone) { |
| 166 | result |= AnalysisProperties::kCompatibleWithCoverageAsAlpha; |
| 167 | } |
Brian Salomon | 3185384 | 2017-03-28 16:32:05 -0400 | [diff] [blame] | 168 | SkASSERT(!(result & AnalysisProperties::kRequiresDstTexture)); |
| 169 | if ((result & AnalysisProperties::kReadsDstInShader) && |
| 170 | !caps.shaderCaps()->dstReadInShaderSupport()) { |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 171 | result |= AnalysisProperties::kRequiresDstTexture | |
| 172 | AnalysisProperties::kRequiresNonOverlappingDraws; |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 173 | } |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 174 | return result; |
Brian Salomon | 9a51498 | 2017-02-14 10:28:22 -0500 | [diff] [blame] | 175 | } |
| 176 | |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 177 | sk_sp<const GrXferProcessor> GrXPFactory::MakeXferProcessor(const GrXPFactory* factory, |
| 178 | const GrProcessorAnalysisColor& color, |
| 179 | GrProcessorAnalysisCoverage coverage, |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 180 | const GrCaps& caps, |
| 181 | GrClampType clampType) { |
Brian Salomon | a076d87 | 2017-04-04 15:17:03 -0400 | [diff] [blame] | 182 | if (factory) { |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame^] | 183 | return factory->makeXferProcessor(color, coverage, caps, clampType); |
Brian Salomon | a076d87 | 2017-04-04 15:17:03 -0400 | [diff] [blame] | 184 | } else { |
Chris Dalton | 57ab06c | 2021-04-22 12:57:28 -0600 | [diff] [blame^] | 185 | return GrPorterDuffXPFactory::MakeSrcOverXferProcessor(color, coverage, caps); |
Brian Salomon | a076d87 | 2017-04-04 15:17:03 -0400 | [diff] [blame] | 186 | } |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 187 | } |