egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | |
egdaniel | ced9010 | 2014-12-05 12:40:52 -0800 | [diff] [blame] | 8 | #include "effects/GrPorterDuffXferProcessor.h" |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 9 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 10 | #include "GrBlend.h" |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 11 | #include "GrCaps.h" |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 12 | #include "GrProcessor.h" |
egdaniel | 8750924 | 2014-12-17 13:37:13 -0800 | [diff] [blame] | 13 | #include "GrProcOptInfo.h" |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 14 | #include "GrTypes.h" |
| 15 | #include "GrXferProcessor.h" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 16 | #include "glsl/GrGLSLBlend.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 17 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 18 | #include "glsl/GrGLSLProgramBuilder.h" |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 19 | #include "glsl/GrGLSLProgramDataManager.h" |
egdaniel | fa4cc8b | 2015-11-13 08:34:52 -0800 | [diff] [blame] | 20 | #include "glsl/GrGLSLXferProcessor.h" |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 21 | |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Wraps the shader outputs and HW blend state that comprise a Porter Duff blend mode with coverage. |
| 24 | */ |
| 25 | struct BlendFormula { |
| 26 | public: |
| 27 | /** |
| 28 | * Values the shader can write to primary and secondary outputs. These must all be modulated by |
| 29 | * coverage to support mixed samples. The XP will ignore the multiplies when not using coverage. |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 30 | */ |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 31 | enum OutputType { |
| 32 | kNone_OutputType, //<! 0 |
| 33 | kCoverage_OutputType, //<! inputCoverage |
| 34 | kModulate_OutputType, //<! inputColor * inputCoverage |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 35 | kSAModulate_OutputType, //<! inputColor.a * inputCoverage |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 36 | kISAModulate_OutputType, //<! (1 - inputColor.a) * inputCoverage |
| 37 | kISCModulate_OutputType, //<! (1 - inputColor) * inputCoverage |
| 38 | |
| 39 | kLast_OutputType = kISCModulate_OutputType |
| 40 | }; |
| 41 | |
| 42 | enum Properties { |
| 43 | kModifiesDst_Property = 1, |
| 44 | kUsesDstColor_Property = 1 << 1, |
| 45 | kUsesInputColor_Property = 1 << 2, |
| 46 | kCanTweakAlphaForCoverage_Property = 1 << 3, |
| 47 | |
| 48 | kLast_Property = kCanTweakAlphaForCoverage_Property |
| 49 | }; |
| 50 | |
| 51 | BlendFormula& operator =(const BlendFormula& other) { |
| 52 | fData = other.fData; |
| 53 | return *this; |
| 54 | } |
| 55 | |
| 56 | bool operator ==(const BlendFormula& other) const { |
| 57 | return fData == other.fData; |
| 58 | } |
| 59 | |
| 60 | bool hasSecondaryOutput() const { return kNone_OutputType != fSecondaryOutputType; } |
| 61 | bool modifiesDst() const { return SkToBool(fProps & kModifiesDst_Property); } |
| 62 | bool usesDstColor() const { return SkToBool(fProps & kUsesDstColor_Property); } |
| 63 | bool usesInputColor() const { return SkToBool(fProps & kUsesInputColor_Property); } |
| 64 | bool canTweakAlphaForCoverage() const { |
| 65 | return SkToBool(fProps & kCanTweakAlphaForCoverage_Property); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Deduce the properties of a compile-time constant BlendFormula. |
| 70 | */ |
| 71 | template<OutputType PrimaryOut, OutputType SecondaryOut, |
| 72 | GrBlendEquation BlendEquation, GrBlendCoeff SrcCoeff, GrBlendCoeff DstCoeff> |
bungeman | 761cf61 | 2015-08-28 07:09:20 -0700 | [diff] [blame] | 73 | struct get_properties : skstd::integral_constant<Properties, static_cast<Properties>( |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 74 | |
| 75 | (GR_BLEND_MODIFIES_DST(BlendEquation, SrcCoeff, DstCoeff) ? |
| 76 | kModifiesDst_Property : 0) | |
| 77 | |
| 78 | (GR_BLEND_COEFFS_USE_DST_COLOR(SrcCoeff, DstCoeff) ? |
| 79 | kUsesDstColor_Property : 0) | |
| 80 | |
| 81 | ((PrimaryOut >= kModulate_OutputType && GR_BLEND_COEFFS_USE_SRC_COLOR(SrcCoeff,DstCoeff)) || |
| 82 | (SecondaryOut >= kModulate_OutputType && GR_BLEND_COEFF_REFS_SRC2(DstCoeff)) ? |
| 83 | kUsesInputColor_Property : 0) | // We assert later that SrcCoeff doesn't ref src2. |
| 84 | |
| 85 | (kModulate_OutputType == PrimaryOut && |
| 86 | kNone_OutputType == SecondaryOut && |
| 87 | GR_BLEND_CAN_TWEAK_ALPHA_FOR_COVERAGE(BlendEquation, SrcCoeff, DstCoeff) ? |
| 88 | kCanTweakAlphaForCoverage_Property : 0))> { |
| 89 | |
| 90 | // The provided formula should already be optimized. |
| 91 | GR_STATIC_ASSERT((kNone_OutputType == PrimaryOut) == |
| 92 | !GR_BLEND_COEFFS_USE_SRC_COLOR(SrcCoeff, DstCoeff)); |
| 93 | GR_STATIC_ASSERT(!GR_BLEND_COEFF_REFS_SRC2(SrcCoeff)); |
| 94 | GR_STATIC_ASSERT((kNone_OutputType == SecondaryOut) == |
| 95 | !GR_BLEND_COEFF_REFS_SRC2(DstCoeff)); |
| 96 | GR_STATIC_ASSERT(PrimaryOut != SecondaryOut || kNone_OutputType == PrimaryOut); |
| 97 | GR_STATIC_ASSERT(kNone_OutputType != PrimaryOut || kNone_OutputType == SecondaryOut); |
| 98 | }; |
| 99 | |
| 100 | union { |
| 101 | struct { |
| 102 | // We allot the enums one more bit than they require because MSVC seems to sign-extend |
| 103 | // them when the top bit is set. (This is in violation of the C++03 standard 9.6/4) |
| 104 | OutputType fPrimaryOutputType : 4; |
| 105 | OutputType fSecondaryOutputType : 4; |
| 106 | GrBlendEquation fBlendEquation : 6; |
| 107 | GrBlendCoeff fSrcCoeff : 6; |
| 108 | GrBlendCoeff fDstCoeff : 6; |
| 109 | Properties fProps : 32 - (4 + 4 + 6 + 6 + 6); |
| 110 | }; |
| 111 | uint32_t fData; |
| 112 | }; |
| 113 | |
| 114 | GR_STATIC_ASSERT(kLast_OutputType < (1 << 3)); |
| 115 | GR_STATIC_ASSERT(kLast_GrBlendEquation < (1 << 5)); |
| 116 | GR_STATIC_ASSERT(kLast_GrBlendCoeff < (1 << 5)); |
| 117 | GR_STATIC_ASSERT(kLast_Property < (1 << 6)); |
| 118 | }; |
| 119 | |
| 120 | GR_STATIC_ASSERT(4 == sizeof(BlendFormula)); |
| 121 | |
| 122 | GR_MAKE_BITFIELD_OPS(BlendFormula::Properties); |
| 123 | |
| 124 | /** |
| 125 | * Initialize a compile-time constant BlendFormula and automatically deduce fProps. |
| 126 | */ |
| 127 | #define INIT_BLEND_FORMULA(PRIMARY_OUT, SECONDARY_OUT, BLEND_EQUATION, SRC_COEFF, DST_COEFF) \ |
| 128 | {{{PRIMARY_OUT, \ |
| 129 | SECONDARY_OUT, \ |
| 130 | BLEND_EQUATION, SRC_COEFF, DST_COEFF, \ |
| 131 | BlendFormula::get_properties<PRIMARY_OUT, SECONDARY_OUT, \ |
| 132 | BLEND_EQUATION, SRC_COEFF, DST_COEFF>::value}}} |
| 133 | |
| 134 | /** |
| 135 | * When there is no coverage, or the blend mode can tweak alpha for coverage, we use the standard |
| 136 | * Porter Duff formula. |
| 137 | */ |
| 138 | #define COEFF_FORMULA(SRC_COEFF, DST_COEFF) \ |
| 139 | INIT_BLEND_FORMULA(BlendFormula::kModulate_OutputType, \ |
| 140 | BlendFormula::kNone_OutputType, \ |
| 141 | kAdd_GrBlendEquation, SRC_COEFF, DST_COEFF) |
| 142 | |
| 143 | /** |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 144 | * Basic coeff formula similar to COEFF_FORMULA but we will make the src f*Sa. This is used in |
| 145 | * LCD dst-out. |
| 146 | */ |
| 147 | #define COEFF_FORMULA_SA_MODULATE(SRC_COEFF, DST_COEFF) \ |
| 148 | INIT_BLEND_FORMULA(BlendFormula::kSAModulate_OutputType, \ |
| 149 | BlendFormula::kNone_OutputType, \ |
| 150 | kAdd_GrBlendEquation, SRC_COEFF, DST_COEFF) |
| 151 | |
| 152 | /** |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 153 | * When the coeffs are (Zero, Zero), we clear the dst. This formula has its own macro so we can set |
| 154 | * the primary output type to none. |
| 155 | */ |
| 156 | #define DST_CLEAR_FORMULA \ |
| 157 | INIT_BLEND_FORMULA(BlendFormula::kNone_OutputType, \ |
| 158 | BlendFormula::kNone_OutputType, \ |
| 159 | kAdd_GrBlendEquation, kZero_GrBlendCoeff, kZero_GrBlendCoeff) |
| 160 | |
| 161 | /** |
| 162 | * When the coeffs are (Zero, One), we don't write to the dst at all. This formula has its own macro |
| 163 | * so we can set the primary output type to none. |
| 164 | */ |
| 165 | #define NO_DST_WRITE_FORMULA \ |
| 166 | INIT_BLEND_FORMULA(BlendFormula::kNone_OutputType, \ |
| 167 | BlendFormula::kNone_OutputType, \ |
| 168 | kAdd_GrBlendEquation, kZero_GrBlendCoeff, kOne_GrBlendCoeff) |
| 169 | |
| 170 | /** |
| 171 | * When there is coverage, the equation with f=coverage is: |
| 172 | * |
| 173 | * D' = f * (S * srcCoeff + D * dstCoeff) + (1-f) * D |
| 174 | * |
| 175 | * This can be rewritten as: |
| 176 | * |
| 177 | * D' = f * S * srcCoeff + D * (1 - [f * (1 - dstCoeff)]) |
| 178 | * |
| 179 | * To implement this formula, we output [f * (1 - dstCoeff)] for the secondary color and replace the |
| 180 | * HW dst coeff with IS2C. |
| 181 | * |
| 182 | * Xfer modes: dst-atop (Sa!=1) |
| 183 | */ |
| 184 | #define COVERAGE_FORMULA(ONE_MINUS_DST_COEFF_MODULATE_OUTPUT, SRC_COEFF) \ |
| 185 | INIT_BLEND_FORMULA(BlendFormula::kModulate_OutputType, \ |
| 186 | ONE_MINUS_DST_COEFF_MODULATE_OUTPUT, \ |
| 187 | kAdd_GrBlendEquation, SRC_COEFF, kIS2C_GrBlendCoeff) |
| 188 | |
| 189 | /** |
| 190 | * When there is coverage and the src coeff is Zero, the equation with f=coverage becomes: |
| 191 | * |
| 192 | * D' = f * D * dstCoeff + (1-f) * D |
| 193 | * |
| 194 | * This can be rewritten as: |
| 195 | * |
| 196 | * D' = D - D * [f * (1 - dstCoeff)] |
| 197 | * |
| 198 | * To implement this formula, we output [f * (1 - dstCoeff)] for the primary color and use a reverse |
| 199 | * subtract HW blend equation with coeffs of (DC, One). |
| 200 | * |
| 201 | * Xfer modes: clear, dst-out (Sa=1), dst-in (Sa!=1), modulate (Sc!=1) |
| 202 | */ |
| 203 | #define COVERAGE_SRC_COEFF_ZERO_FORMULA(ONE_MINUS_DST_COEFF_MODULATE_OUTPUT) \ |
| 204 | INIT_BLEND_FORMULA(ONE_MINUS_DST_COEFF_MODULATE_OUTPUT, \ |
| 205 | BlendFormula::kNone_OutputType, \ |
| 206 | kReverseSubtract_GrBlendEquation, kDC_GrBlendCoeff, kOne_GrBlendCoeff) |
| 207 | |
| 208 | /** |
| 209 | * When there is coverage and the dst coeff is Zero, the equation with f=coverage becomes: |
| 210 | * |
| 211 | * D' = f * S * srcCoeff + (1-f) * D |
| 212 | * |
| 213 | * To implement this formula, we output [f] for the secondary color and replace the HW dst coeff |
| 214 | * with IS2A. (Note that we can avoid dual source blending when Sa=1 by using ISA.) |
| 215 | * |
| 216 | * Xfer modes (Sa!=1): src, src-in, src-out |
| 217 | */ |
| 218 | #define COVERAGE_DST_COEFF_ZERO_FORMULA(SRC_COEFF) \ |
| 219 | INIT_BLEND_FORMULA(BlendFormula::kModulate_OutputType, \ |
| 220 | BlendFormula::kCoverage_OutputType, \ |
| 221 | kAdd_GrBlendEquation, SRC_COEFF, kIS2A_GrBlendCoeff) |
| 222 | |
| 223 | /** |
| 224 | * This table outlines the blend formulas we will use with each xfermode, with and without coverage, |
| 225 | * with and without an opaque input color. Optimization properties are deduced at compile time so we |
| 226 | * can make runtime decisions quickly. RGB coverage is not supported. |
| 227 | */ |
| 228 | static const BlendFormula gBlendTable[2][2][SkXfermode::kLastCoeffMode + 1] = { |
| 229 | |
| 230 | /*>> No coverage, input color unknown <<*/ {{ |
| 231 | |
| 232 | /* clear */ DST_CLEAR_FORMULA, |
| 233 | /* src */ COEFF_FORMULA( kOne_GrBlendCoeff, kZero_GrBlendCoeff), |
| 234 | /* dst */ NO_DST_WRITE_FORMULA, |
| 235 | /* src-over */ COEFF_FORMULA( kOne_GrBlendCoeff, kISA_GrBlendCoeff), |
| 236 | /* dst-over */ COEFF_FORMULA( kIDA_GrBlendCoeff, kOne_GrBlendCoeff), |
| 237 | /* src-in */ COEFF_FORMULA( kDA_GrBlendCoeff, kZero_GrBlendCoeff), |
| 238 | /* dst-in */ COEFF_FORMULA( kZero_GrBlendCoeff, kSA_GrBlendCoeff), |
| 239 | /* src-out */ COEFF_FORMULA( kIDA_GrBlendCoeff, kZero_GrBlendCoeff), |
| 240 | /* dst-out */ COEFF_FORMULA( kZero_GrBlendCoeff, kISA_GrBlendCoeff), |
| 241 | /* src-atop */ COEFF_FORMULA( kDA_GrBlendCoeff, kISA_GrBlendCoeff), |
| 242 | /* dst-atop */ COEFF_FORMULA( kIDA_GrBlendCoeff, kSA_GrBlendCoeff), |
| 243 | /* xor */ COEFF_FORMULA( kIDA_GrBlendCoeff, kISA_GrBlendCoeff), |
| 244 | /* plus */ COEFF_FORMULA( kOne_GrBlendCoeff, kOne_GrBlendCoeff), |
| 245 | /* modulate */ COEFF_FORMULA( kZero_GrBlendCoeff, kSC_GrBlendCoeff), |
| 246 | /* screen */ COEFF_FORMULA( kOne_GrBlendCoeff, kISC_GrBlendCoeff), |
| 247 | |
| 248 | }, /*>> Has coverage, input color unknown <<*/ { |
| 249 | |
| 250 | /* clear */ COVERAGE_SRC_COEFF_ZERO_FORMULA(BlendFormula::kCoverage_OutputType), |
| 251 | /* src */ COVERAGE_DST_COEFF_ZERO_FORMULA(kOne_GrBlendCoeff), |
| 252 | /* dst */ NO_DST_WRITE_FORMULA, |
| 253 | /* src-over */ COEFF_FORMULA( kOne_GrBlendCoeff, kISA_GrBlendCoeff), |
| 254 | /* dst-over */ COEFF_FORMULA( kIDA_GrBlendCoeff, kOne_GrBlendCoeff), |
| 255 | /* src-in */ COVERAGE_DST_COEFF_ZERO_FORMULA(kDA_GrBlendCoeff), |
| 256 | /* dst-in */ COVERAGE_SRC_COEFF_ZERO_FORMULA(BlendFormula::kISAModulate_OutputType), |
| 257 | /* src-out */ COVERAGE_DST_COEFF_ZERO_FORMULA(kIDA_GrBlendCoeff), |
| 258 | /* dst-out */ COEFF_FORMULA( kZero_GrBlendCoeff, kISA_GrBlendCoeff), |
| 259 | /* src-atop */ COEFF_FORMULA( kDA_GrBlendCoeff, kISA_GrBlendCoeff), |
| 260 | /* dst-atop */ COVERAGE_FORMULA(BlendFormula::kISAModulate_OutputType, kIDA_GrBlendCoeff), |
| 261 | /* xor */ COEFF_FORMULA( kIDA_GrBlendCoeff, kISA_GrBlendCoeff), |
| 262 | /* plus */ COEFF_FORMULA( kOne_GrBlendCoeff, kOne_GrBlendCoeff), |
| 263 | /* modulate */ COVERAGE_SRC_COEFF_ZERO_FORMULA(BlendFormula::kISCModulate_OutputType), |
| 264 | /* screen */ COEFF_FORMULA( kOne_GrBlendCoeff, kISC_GrBlendCoeff), |
| 265 | |
| 266 | }}, /*>> No coverage, input color opaque <<*/ {{ |
| 267 | |
| 268 | /* clear */ DST_CLEAR_FORMULA, |
| 269 | /* src */ COEFF_FORMULA( kOne_GrBlendCoeff, kZero_GrBlendCoeff), |
| 270 | /* dst */ NO_DST_WRITE_FORMULA, |
| 271 | /* src-over */ COEFF_FORMULA( kOne_GrBlendCoeff, kZero_GrBlendCoeff), |
| 272 | /* dst-over */ COEFF_FORMULA( kIDA_GrBlendCoeff, kOne_GrBlendCoeff), |
| 273 | /* src-in */ COEFF_FORMULA( kDA_GrBlendCoeff, kZero_GrBlendCoeff), |
| 274 | /* dst-in */ NO_DST_WRITE_FORMULA, |
| 275 | /* src-out */ COEFF_FORMULA( kIDA_GrBlendCoeff, kZero_GrBlendCoeff), |
| 276 | /* dst-out */ DST_CLEAR_FORMULA, |
| 277 | /* src-atop */ COEFF_FORMULA( kDA_GrBlendCoeff, kZero_GrBlendCoeff), |
| 278 | /* dst-atop */ COEFF_FORMULA( kIDA_GrBlendCoeff, kOne_GrBlendCoeff), |
| 279 | /* xor */ COEFF_FORMULA( kIDA_GrBlendCoeff, kZero_GrBlendCoeff), |
| 280 | /* plus */ COEFF_FORMULA( kOne_GrBlendCoeff, kOne_GrBlendCoeff), |
| 281 | /* modulate */ COEFF_FORMULA( kZero_GrBlendCoeff, kSC_GrBlendCoeff), |
| 282 | /* screen */ COEFF_FORMULA( kOne_GrBlendCoeff, kISC_GrBlendCoeff), |
| 283 | |
| 284 | }, /*>> Has coverage, input color opaque <<*/ { |
| 285 | |
| 286 | /* clear */ COVERAGE_SRC_COEFF_ZERO_FORMULA(BlendFormula::kCoverage_OutputType), |
| 287 | /* src */ COEFF_FORMULA( kOne_GrBlendCoeff, kISA_GrBlendCoeff), |
| 288 | /* dst */ NO_DST_WRITE_FORMULA, |
| 289 | /* src-over */ COEFF_FORMULA( kOne_GrBlendCoeff, kISA_GrBlendCoeff), |
| 290 | /* dst-over */ COEFF_FORMULA( kIDA_GrBlendCoeff, kOne_GrBlendCoeff), |
| 291 | /* src-in */ COEFF_FORMULA( kDA_GrBlendCoeff, kISA_GrBlendCoeff), |
| 292 | /* dst-in */ NO_DST_WRITE_FORMULA, |
| 293 | /* src-out */ COEFF_FORMULA( kIDA_GrBlendCoeff, kISA_GrBlendCoeff), |
| 294 | /* dst-out */ COVERAGE_SRC_COEFF_ZERO_FORMULA(BlendFormula::kCoverage_OutputType), |
| 295 | /* src-atop */ COEFF_FORMULA( kDA_GrBlendCoeff, kISA_GrBlendCoeff), |
| 296 | /* dst-atop */ COEFF_FORMULA( kIDA_GrBlendCoeff, kOne_GrBlendCoeff), |
| 297 | /* xor */ COEFF_FORMULA( kIDA_GrBlendCoeff, kISA_GrBlendCoeff), |
| 298 | /* plus */ COEFF_FORMULA( kOne_GrBlendCoeff, kOne_GrBlendCoeff), |
| 299 | /* modulate */ COVERAGE_SRC_COEFF_ZERO_FORMULA(BlendFormula::kISCModulate_OutputType), |
| 300 | /* screen */ COEFF_FORMULA( kOne_GrBlendCoeff, kISC_GrBlendCoeff), |
| 301 | }}}; |
| 302 | |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 303 | static const BlendFormula gLCDBlendTable[SkXfermode::kLastCoeffMode + 1] = { |
| 304 | /* clear */ COVERAGE_SRC_COEFF_ZERO_FORMULA(BlendFormula::kCoverage_OutputType), |
| 305 | /* src */ COVERAGE_FORMULA(BlendFormula::kCoverage_OutputType, kOne_GrBlendCoeff), |
| 306 | /* dst */ NO_DST_WRITE_FORMULA, |
| 307 | /* src-over */ COVERAGE_FORMULA(BlendFormula::kSAModulate_OutputType, kOne_GrBlendCoeff), |
| 308 | /* dst-over */ COEFF_FORMULA( kIDA_GrBlendCoeff, kOne_GrBlendCoeff), |
| 309 | /* src-in */ COVERAGE_FORMULA(BlendFormula::kCoverage_OutputType, kDA_GrBlendCoeff), |
| 310 | /* dst-in */ COVERAGE_SRC_COEFF_ZERO_FORMULA(BlendFormula::kISAModulate_OutputType), |
| 311 | /* src-out */ COVERAGE_FORMULA(BlendFormula::kCoverage_OutputType, kIDA_GrBlendCoeff), |
| 312 | /* dst-out */ COEFF_FORMULA_SA_MODULATE( kZero_GrBlendCoeff, kISC_GrBlendCoeff), |
| 313 | /* src-atop */ COVERAGE_FORMULA(BlendFormula::kSAModulate_OutputType, kDA_GrBlendCoeff), |
| 314 | /* dst-atop */ COVERAGE_FORMULA(BlendFormula::kISAModulate_OutputType, kIDA_GrBlendCoeff), |
| 315 | /* xor */ COVERAGE_FORMULA(BlendFormula::kSAModulate_OutputType, kIDA_GrBlendCoeff), |
| 316 | /* plus */ COEFF_FORMULA( kOne_GrBlendCoeff, kOne_GrBlendCoeff), |
| 317 | /* modulate */ COVERAGE_SRC_COEFF_ZERO_FORMULA(BlendFormula::kISCModulate_OutputType), |
| 318 | /* screen */ COEFF_FORMULA( kOne_GrBlendCoeff, kISC_GrBlendCoeff), |
| 319 | }; |
| 320 | |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 321 | static BlendFormula get_blend_formula(const GrProcOptInfo& colorPOI, |
| 322 | const GrProcOptInfo& coveragePOI, |
| 323 | bool hasMixedSamples, |
| 324 | SkXfermode::Mode xfermode) { |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 325 | SkASSERT(xfermode >= 0 && xfermode <= SkXfermode::kLastCoeffMode); |
| 326 | SkASSERT(!coveragePOI.isFourChannelOutput()); |
| 327 | |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 328 | bool conflatesCoverage = !coveragePOI.isSolidWhite() || hasMixedSamples; |
| 329 | return gBlendTable[colorPOI.isOpaque()][conflatesCoverage][xfermode]; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 330 | } |
| 331 | |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 332 | static BlendFormula get_lcd_blend_formula(const GrProcOptInfo& coveragePOI, |
| 333 | SkXfermode::Mode xfermode) { |
| 334 | SkASSERT(xfermode >= 0 && xfermode <= SkXfermode::kLastCoeffMode); |
| 335 | SkASSERT(coveragePOI.isFourChannelOutput()); |
| 336 | |
| 337 | return gLCDBlendTable[xfermode]; |
| 338 | } |
| 339 | |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 340 | /////////////////////////////////////////////////////////////////////////////// |
| 341 | |
egdaniel | 41d4f09 | 2015-02-09 07:51:00 -0800 | [diff] [blame] | 342 | class PorterDuffXferProcessor : public GrXferProcessor { |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 343 | public: |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 344 | PorterDuffXferProcessor(BlendFormula blendFormula) : fBlendFormula(blendFormula) { |
| 345 | this->initClassID<PorterDuffXferProcessor>(); |
egdaniel | 41d4f09 | 2015-02-09 07:51:00 -0800 | [diff] [blame] | 346 | } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 347 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 348 | const char* name() const override { return "Porter Duff"; } |
egdaniel | 41d4f09 | 2015-02-09 07:51:00 -0800 | [diff] [blame] | 349 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 350 | GrGLSLXferProcessor* createGLSLInstance() const override; |
egdaniel | 41d4f09 | 2015-02-09 07:51:00 -0800 | [diff] [blame] | 351 | |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 352 | BlendFormula getBlendFormula() const { return fBlendFormula; } |
cdalton | f4f2b44 | 2015-04-23 09:40:23 -0700 | [diff] [blame] | 353 | |
| 354 | private: |
egdaniel | c19cdc2 | 2015-05-10 08:45:18 -0700 | [diff] [blame] | 355 | GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
| 356 | const GrProcOptInfo& coveragePOI, |
| 357 | bool doesStencilWrite, |
| 358 | GrColor* overrideColor, |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 359 | const GrCaps& caps) override; |
egdaniel | c19cdc2 | 2015-05-10 08:45:18 -0700 | [diff] [blame] | 360 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 361 | void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override; |
cdalton | f4f2b44 | 2015-04-23 09:40:23 -0700 | [diff] [blame] | 362 | |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 363 | bool onHasSecondaryOutput() const override { return fBlendFormula.hasSecondaryOutput(); } |
| 364 | |
cdalton | f4f2b44 | 2015-04-23 09:40:23 -0700 | [diff] [blame] | 365 | void onGetBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const override { |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 366 | blendInfo->fEquation = fBlendFormula.fBlendEquation; |
| 367 | blendInfo->fSrcBlend = fBlendFormula.fSrcCoeff; |
| 368 | blendInfo->fDstBlend = fBlendFormula.fDstCoeff; |
| 369 | blendInfo->fWriteColor = fBlendFormula.modifiesDst(); |
egdaniel | 41d4f09 | 2015-02-09 07:51:00 -0800 | [diff] [blame] | 370 | } |
| 371 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 372 | bool onIsEqual(const GrXferProcessor& xpBase) const override { |
egdaniel | 41d4f09 | 2015-02-09 07:51:00 -0800 | [diff] [blame] | 373 | const PorterDuffXferProcessor& xp = xpBase.cast<PorterDuffXferProcessor>(); |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 374 | return fBlendFormula == xp.fBlendFormula; |
egdaniel | 41d4f09 | 2015-02-09 07:51:00 -0800 | [diff] [blame] | 375 | } |
| 376 | |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 377 | const BlendFormula fBlendFormula; |
egdaniel | 41d4f09 | 2015-02-09 07:51:00 -0800 | [diff] [blame] | 378 | |
| 379 | typedef GrXferProcessor INHERITED; |
| 380 | }; |
| 381 | |
| 382 | /////////////////////////////////////////////////////////////////////////////// |
| 383 | |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 384 | static void append_color_output(const PorterDuffXferProcessor& xp, |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 385 | GrGLSLXPFragmentBuilder* fragBuilder, |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 386 | BlendFormula::OutputType outputType, const char* output, |
| 387 | const char* inColor, const char* inCoverage) { |
| 388 | switch (outputType) { |
| 389 | case BlendFormula::kNone_OutputType: |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 390 | fragBuilder->codeAppendf("%s = vec4(0.0);", output); |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 391 | break; |
| 392 | case BlendFormula::kCoverage_OutputType: |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 393 | // We can have a coverage formula while not reading coverage if there are mixed samples. |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 394 | fragBuilder->codeAppendf("%s = %s;", |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 395 | output, xp.readsCoverage() ? inCoverage : "vec4(1.0)"); |
| 396 | break; |
| 397 | case BlendFormula::kModulate_OutputType: |
| 398 | if (xp.readsCoverage()) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 399 | fragBuilder->codeAppendf("%s = %s * %s;", output, inColor, inCoverage); |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 400 | } else { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 401 | fragBuilder->codeAppendf("%s = %s;", output, inColor); |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 402 | } |
| 403 | break; |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 404 | case BlendFormula::kSAModulate_OutputType: |
| 405 | if (xp.readsCoverage()) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 406 | fragBuilder->codeAppendf("%s = %s.a * %s;", output, inColor, inCoverage); |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 407 | } else { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 408 | fragBuilder->codeAppendf("%s = %s;", output, inColor); |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 409 | } |
| 410 | break; |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 411 | case BlendFormula::kISAModulate_OutputType: |
| 412 | if (xp.readsCoverage()) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 413 | fragBuilder->codeAppendf("%s = (1.0 - %s.a) * %s;", output, inColor, inCoverage); |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 414 | } else { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 415 | fragBuilder->codeAppendf("%s = vec4(1.0 - %s.a);", output, inColor); |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 416 | } |
| 417 | break; |
| 418 | case BlendFormula::kISCModulate_OutputType: |
| 419 | if (xp.readsCoverage()) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 420 | fragBuilder->codeAppendf("%s = (vec4(1.0) - %s) * %s;", output, inColor, inCoverage); |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 421 | } else { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 422 | fragBuilder->codeAppendf("%s = vec4(1.0) - %s;", output, inColor); |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 423 | } |
| 424 | break; |
| 425 | default: |
| 426 | SkFAIL("Unsupported output type."); |
| 427 | break; |
egdaniel | 3ad6570 | 2015-02-17 11:15:47 -0800 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
egdaniel | fa4cc8b | 2015-11-13 08:34:52 -0800 | [diff] [blame] | 431 | class GLPorterDuffXferProcessor : public GrGLSLXferProcessor { |
egdaniel | 41d4f09 | 2015-02-09 07:51:00 -0800 | [diff] [blame] | 432 | public: |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 433 | static void GenKey(const GrProcessor& processor, GrProcessorKeyBuilder* b) { |
egdaniel | 41d4f09 | 2015-02-09 07:51:00 -0800 | [diff] [blame] | 434 | const PorterDuffXferProcessor& xp = processor.cast<PorterDuffXferProcessor>(); |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 435 | b->add32(SkToInt(xp.readsCoverage()) | |
| 436 | (xp.getBlendFormula().fPrimaryOutputType << 1) | |
| 437 | (xp.getBlendFormula().fSecondaryOutputType << 4)); |
| 438 | GR_STATIC_ASSERT(BlendFormula::kLast_OutputType < 8); |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 439 | }; |
| 440 | |
| 441 | private: |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 442 | void emitOutputsForBlendState(const EmitArgs& args) override { |
egdaniel | 41d4f09 | 2015-02-09 07:51:00 -0800 | [diff] [blame] | 443 | const PorterDuffXferProcessor& xp = args.fXP.cast<PorterDuffXferProcessor>(); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 444 | GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder; |
bungeman | c33db93 | 2015-05-22 17:55:26 -0700 | [diff] [blame] | 445 | |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 446 | BlendFormula blendFormula = xp.getBlendFormula(); |
| 447 | if (blendFormula.hasSecondaryOutput()) { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 448 | append_color_output(xp, fragBuilder, blendFormula.fSecondaryOutputType, |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 449 | args.fOutputSecondary, args.fInputColor, args.fInputCoverage); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 450 | } |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 451 | append_color_output(xp, fragBuilder, blendFormula.fPrimaryOutputType, |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 452 | args.fOutputPrimary, args.fInputColor, args.fInputCoverage); |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 453 | } |
| 454 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 455 | void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) override {} |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 456 | |
egdaniel | fa4cc8b | 2015-11-13 08:34:52 -0800 | [diff] [blame] | 457 | typedef GrGLSLXferProcessor INHERITED; |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 458 | }; |
| 459 | |
| 460 | /////////////////////////////////////////////////////////////////////////////// |
| 461 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 462 | void PorterDuffXferProcessor::onGetGLSLProcessorKey(const GrGLSLCaps&, |
| 463 | GrProcessorKeyBuilder* b) const { |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 464 | GLPorterDuffXferProcessor::GenKey(*this, b); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 465 | } |
| 466 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 467 | GrGLSLXferProcessor* PorterDuffXferProcessor::createGLSLInstance() const { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 468 | return new GLPorterDuffXferProcessor; |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 469 | } |
| 470 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 471 | GrXferProcessor::OptFlags |
egdaniel | c19cdc2 | 2015-05-10 08:45:18 -0700 | [diff] [blame] | 472 | PorterDuffXferProcessor::onGetOptimizations(const GrProcOptInfo& colorPOI, |
| 473 | const GrProcOptInfo& coveragePOI, |
| 474 | bool doesStencilWrite, |
| 475 | GrColor* overrideColor, |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 476 | const GrCaps& caps) { |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 477 | GrXferProcessor::OptFlags optFlags = GrXferProcessor::kNone_OptFlags; |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 478 | if (!fBlendFormula.modifiesDst()) { |
| 479 | if (!doesStencilWrite) { |
| 480 | optFlags |= GrXferProcessor::kSkipDraw_OptFlag; |
| 481 | } |
| 482 | optFlags |= (GrXferProcessor::kIgnoreColor_OptFlag | |
| 483 | GrXferProcessor::kIgnoreCoverage_OptFlag | |
| 484 | GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag); |
| 485 | } else { |
| 486 | if (!fBlendFormula.usesInputColor()) { |
| 487 | optFlags |= GrXferProcessor::kIgnoreColor_OptFlag; |
| 488 | } |
| 489 | if (coveragePOI.isSolidWhite()) { |
| 490 | optFlags |= GrXferProcessor::kIgnoreCoverage_OptFlag; |
| 491 | } |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 492 | if (colorPOI.allStagesMultiplyInput() && |
| 493 | fBlendFormula.canTweakAlphaForCoverage() && |
| 494 | !coveragePOI.isFourChannelOutput()) { |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 495 | optFlags |= GrXferProcessor::kCanTweakAlphaForCoverage_OptFlag; |
| 496 | } |
| 497 | } |
bungeman | c33db93 | 2015-05-22 17:55:26 -0700 | [diff] [blame] | 498 | return optFlags; |
| 499 | } |
| 500 | |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 501 | /////////////////////////////////////////////////////////////////////////////// |
| 502 | |
| 503 | class ShaderPDXferProcessor : public GrXferProcessor { |
| 504 | public: |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 505 | ShaderPDXferProcessor(const DstTexture* dstTexture, |
| 506 | bool hasMixedSamples, |
| 507 | SkXfermode::Mode xfermode) |
| 508 | : INHERITED(dstTexture, true, hasMixedSamples) |
| 509 | , fXfermode(xfermode) { |
| 510 | this->initClassID<ShaderPDXferProcessor>(); |
bungeman | c33db93 | 2015-05-22 17:55:26 -0700 | [diff] [blame] | 511 | } |
| 512 | |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 513 | const char* name() const override { return "Porter Duff Shader"; } |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 514 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 515 | GrGLSLXferProcessor* createGLSLInstance() const override; |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 516 | |
| 517 | SkXfermode::Mode getXfermode() const { return fXfermode; } |
| 518 | |
| 519 | private: |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 520 | GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo&, const GrProcOptInfo&, |
| 521 | bool, GrColor*, const GrCaps&) override { |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 522 | return kNone_OptFlags; |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 523 | } |
| 524 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 525 | void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override; |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 526 | |
| 527 | bool onIsEqual(const GrXferProcessor& xpBase) const override { |
| 528 | const ShaderPDXferProcessor& xp = xpBase.cast<ShaderPDXferProcessor>(); |
| 529 | return fXfermode == xp.fXfermode; |
| 530 | } |
| 531 | |
| 532 | const SkXfermode::Mode fXfermode; |
| 533 | |
| 534 | typedef GrXferProcessor INHERITED; |
| 535 | }; |
| 536 | |
| 537 | /////////////////////////////////////////////////////////////////////////////// |
| 538 | |
egdaniel | fa4cc8b | 2015-11-13 08:34:52 -0800 | [diff] [blame] | 539 | class GLShaderPDXferProcessor : public GrGLSLXferProcessor { |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 540 | public: |
| 541 | static void GenKey(const GrProcessor& processor, GrProcessorKeyBuilder* b) { |
| 542 | const ShaderPDXferProcessor& xp = processor.cast<ShaderPDXferProcessor>(); |
| 543 | b->add32(xp.getXfermode()); |
egdaniel | 3ad6570 | 2015-02-17 11:15:47 -0800 | [diff] [blame] | 544 | } |
egdaniel | 8750924 | 2014-12-17 13:37:13 -0800 | [diff] [blame] | 545 | |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 546 | private: |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 547 | void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb, |
| 548 | GrGLSLXPFragmentBuilder* fragBuilder, |
| 549 | const char* srcColor, |
| 550 | const char* dstColor, |
| 551 | const char* outColor, |
| 552 | const GrXferProcessor& proc) override { |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 553 | const ShaderPDXferProcessor& xp = proc.cast<ShaderPDXferProcessor>(); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 554 | |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 555 | GrGLSLBlend::AppendMode(fragBuilder, srcColor, dstColor, outColor, xp.getXfermode()); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 556 | } |
| 557 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 558 | void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) override {} |
bungeman | c33db93 | 2015-05-22 17:55:26 -0700 | [diff] [blame] | 559 | |
egdaniel | fa4cc8b | 2015-11-13 08:34:52 -0800 | [diff] [blame] | 560 | typedef GrGLSLXferProcessor INHERITED; |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 561 | }; |
bungeman | c33db93 | 2015-05-22 17:55:26 -0700 | [diff] [blame] | 562 | |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 563 | /////////////////////////////////////////////////////////////////////////////// |
bungeman | c33db93 | 2015-05-22 17:55:26 -0700 | [diff] [blame] | 564 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 565 | void ShaderPDXferProcessor::onGetGLSLProcessorKey(const GrGLSLCaps&, |
| 566 | GrProcessorKeyBuilder* b) const { |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 567 | GLShaderPDXferProcessor::GenKey(*this, b); |
bungeman | c33db93 | 2015-05-22 17:55:26 -0700 | [diff] [blame] | 568 | } |
| 569 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 570 | GrGLSLXferProcessor* ShaderPDXferProcessor::createGLSLInstance() const { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 571 | return new GLShaderPDXferProcessor; |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 572 | } |
| 573 | |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 574 | /////////////////////////////////////////////////////////////////////////////// |
| 575 | |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 576 | class PDLCDXferProcessor : public GrXferProcessor { |
| 577 | public: |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 578 | static GrXferProcessor* Create(SkXfermode::Mode xfermode, const GrProcOptInfo& colorPOI); |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 579 | |
| 580 | ~PDLCDXferProcessor() override; |
| 581 | |
| 582 | const char* name() const override { return "Porter Duff LCD"; } |
| 583 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 584 | GrGLSLXferProcessor* createGLSLInstance() const override; |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 585 | |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 586 | private: |
| 587 | PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha); |
| 588 | |
| 589 | GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
| 590 | const GrProcOptInfo& coveragePOI, |
| 591 | bool doesStencilWrite, |
| 592 | GrColor* overrideColor, |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 593 | const GrCaps& caps) override; |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 594 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 595 | void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override; |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 596 | |
| 597 | void onGetBlendInfo(GrXferProcessor::BlendInfo* blendInfo) const override { |
| 598 | blendInfo->fSrcBlend = kConstC_GrBlendCoeff; |
| 599 | blendInfo->fDstBlend = kISC_GrBlendCoeff; |
| 600 | blendInfo->fBlendConstant = fBlendConstant; |
| 601 | } |
| 602 | |
| 603 | bool onIsEqual(const GrXferProcessor& xpBase) const override { |
| 604 | const PDLCDXferProcessor& xp = xpBase.cast<PDLCDXferProcessor>(); |
| 605 | if (fBlendConstant != xp.fBlendConstant || |
| 606 | fAlpha != xp.fAlpha) { |
| 607 | return false; |
| 608 | } |
| 609 | return true; |
| 610 | } |
| 611 | |
| 612 | GrColor fBlendConstant; |
| 613 | uint8_t fAlpha; |
| 614 | |
| 615 | typedef GrXferProcessor INHERITED; |
| 616 | }; |
| 617 | |
| 618 | /////////////////////////////////////////////////////////////////////////////// |
| 619 | |
egdaniel | fa4cc8b | 2015-11-13 08:34:52 -0800 | [diff] [blame] | 620 | class GLPDLCDXferProcessor : public GrGLSLXferProcessor { |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 621 | public: |
| 622 | GLPDLCDXferProcessor(const GrProcessor&) {} |
| 623 | |
| 624 | virtual ~GLPDLCDXferProcessor() {} |
| 625 | |
| 626 | static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, |
| 627 | GrProcessorKeyBuilder* b) {} |
| 628 | |
| 629 | private: |
cdalton | edbb31f | 2015-06-08 12:14:44 -0700 | [diff] [blame] | 630 | void emitOutputsForBlendState(const EmitArgs& args) override { |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame^] | 631 | GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder; |
| 632 | fragBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, args.fInputColor, |
| 633 | args.fInputCoverage); |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 634 | } |
| 635 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 636 | void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) override {}; |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 637 | |
egdaniel | fa4cc8b | 2015-11-13 08:34:52 -0800 | [diff] [blame] | 638 | typedef GrGLSLXferProcessor INHERITED; |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 639 | }; |
| 640 | |
| 641 | /////////////////////////////////////////////////////////////////////////////// |
| 642 | |
| 643 | PDLCDXferProcessor::PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha) |
| 644 | : fBlendConstant(blendConstant) |
| 645 | , fAlpha(alpha) { |
| 646 | this->initClassID<PDLCDXferProcessor>(); |
| 647 | } |
| 648 | |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 649 | GrXferProcessor* PDLCDXferProcessor::Create(SkXfermode::Mode xfermode, |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 650 | const GrProcOptInfo& colorPOI) { |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 651 | if (SkXfermode::kSrcOver_Mode != xfermode) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 652 | return nullptr; |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | if (kRGBA_GrColorComponentFlags != colorPOI.validFlags()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 656 | return nullptr; |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 657 | } |
| 658 | |
bsalomon | ae4738f | 2015-09-15 15:33:27 -0700 | [diff] [blame] | 659 | GrColor blendConstant = GrUnpremulColor(colorPOI.color()); |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 660 | uint8_t alpha = GrColorUnpackA(blendConstant); |
| 661 | blendConstant |= (0xff << GrColor_SHIFT_A); |
| 662 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 663 | return new PDLCDXferProcessor(blendConstant, alpha); |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | PDLCDXferProcessor::~PDLCDXferProcessor() { |
| 667 | } |
| 668 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 669 | void PDLCDXferProcessor::onGetGLSLProcessorKey(const GrGLSLCaps& caps, |
| 670 | GrProcessorKeyBuilder* b) const { |
egdaniel | cc25297 | 2015-05-12 12:03:28 -0700 | [diff] [blame] | 671 | GLPDLCDXferProcessor::GenKey(*this, caps, b); |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 672 | } |
| 673 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 674 | GrGLSLXferProcessor* PDLCDXferProcessor::createGLSLInstance() const { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 675 | return new GLPDLCDXferProcessor(*this); |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | GrXferProcessor::OptFlags |
| 679 | PDLCDXferProcessor::onGetOptimizations(const GrProcOptInfo& colorPOI, |
| 680 | const GrProcOptInfo& coveragePOI, |
| 681 | bool doesStencilWrite, |
| 682 | GrColor* overrideColor, |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 683 | const GrCaps& caps) { |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 684 | // We want to force our primary output to be alpha * Coverage, where alpha is the alpha |
| 685 | // value of the blend the constant. We should already have valid blend coeff's if we are at |
| 686 | // a point where we have RGB coverage. We don't need any color stages since the known color |
| 687 | // output is already baked into the blendConstant. |
| 688 | *overrideColor = GrColorPackRGBA(fAlpha, fAlpha, fAlpha, fAlpha); |
| 689 | return GrXferProcessor::kOverrideColor_OptFlag; |
| 690 | } |
| 691 | |
| 692 | /////////////////////////////////////////////////////////////////////////////// |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 693 | |
| 694 | GrPorterDuffXPFactory::GrPorterDuffXPFactory(SkXfermode::Mode xfermode) |
| 695 | : fXfermode(xfermode) { |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 696 | SkASSERT(fXfermode <= SkXfermode::kLastCoeffMode); |
egdaniel | 915187b | 2014-12-05 12:58:28 -0800 | [diff] [blame] | 697 | this->initClassID<GrPorterDuffXPFactory>(); |
| 698 | } |
| 699 | |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 700 | GrXPFactory* GrPorterDuffXPFactory::Create(SkXfermode::Mode xfermode) { |
| 701 | static GrPorterDuffXPFactory gClearPDXPF(SkXfermode::kClear_Mode); |
| 702 | static GrPorterDuffXPFactory gSrcPDXPF(SkXfermode::kSrc_Mode); |
| 703 | static GrPorterDuffXPFactory gDstPDXPF(SkXfermode::kDst_Mode); |
| 704 | static GrPorterDuffXPFactory gSrcOverPDXPF(SkXfermode::kSrcOver_Mode); |
| 705 | static GrPorterDuffXPFactory gDstOverPDXPF(SkXfermode::kDstOver_Mode); |
| 706 | static GrPorterDuffXPFactory gSrcInPDXPF(SkXfermode::kSrcIn_Mode); |
| 707 | static GrPorterDuffXPFactory gDstInPDXPF(SkXfermode::kDstIn_Mode); |
| 708 | static GrPorterDuffXPFactory gSrcOutPDXPF(SkXfermode::kSrcOut_Mode); |
| 709 | static GrPorterDuffXPFactory gDstOutPDXPF(SkXfermode::kDstOut_Mode); |
| 710 | static GrPorterDuffXPFactory gSrcATopPDXPF(SkXfermode::kSrcATop_Mode); |
| 711 | static GrPorterDuffXPFactory gDstATopPDXPF(SkXfermode::kDstATop_Mode); |
| 712 | static GrPorterDuffXPFactory gXorPDXPF(SkXfermode::kXor_Mode); |
| 713 | static GrPorterDuffXPFactory gPlusPDXPF(SkXfermode::kPlus_Mode); |
| 714 | static GrPorterDuffXPFactory gModulatePDXPF(SkXfermode::kModulate_Mode); |
| 715 | static GrPorterDuffXPFactory gScreenPDXPF(SkXfermode::kScreen_Mode); |
| 716 | |
| 717 | static GrPorterDuffXPFactory* gFactories[] = { |
| 718 | &gClearPDXPF, &gSrcPDXPF, &gDstPDXPF, &gSrcOverPDXPF, &gDstOverPDXPF, &gSrcInPDXPF, |
| 719 | &gDstInPDXPF, &gSrcOutPDXPF, &gDstOutPDXPF, &gSrcATopPDXPF, &gDstATopPDXPF, &gXorPDXPF, |
| 720 | &gPlusPDXPF, &gModulatePDXPF, &gScreenPDXPF |
| 721 | }; |
| 722 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(gFactories) == SkXfermode::kLastCoeffMode + 1); |
| 723 | |
| 724 | if (xfermode < 0 || xfermode > SkXfermode::kLastCoeffMode) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 725 | return nullptr; |
egdaniel | c016fb8 | 2014-12-03 11:41:54 -0800 | [diff] [blame] | 726 | } |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 727 | return SkRef(gFactories[xfermode]); |
egdaniel | c016fb8 | 2014-12-03 11:41:54 -0800 | [diff] [blame] | 728 | } |
| 729 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 730 | GrXferProcessor* |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 731 | GrPorterDuffXPFactory::onCreateXferProcessor(const GrCaps& caps, |
egdaniel | 3ad6570 | 2015-02-17 11:15:47 -0800 | [diff] [blame] | 732 | const GrProcOptInfo& colorPOI, |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 733 | const GrProcOptInfo& covPOI, |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 734 | bool hasMixedSamples, |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 735 | const DstTexture* dstTexture) const { |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 736 | BlendFormula blendFormula; |
egdaniel | 0d5fd11 | 2015-05-12 06:11:35 -0700 | [diff] [blame] | 737 | if (covPOI.isFourChannelOutput()) { |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 738 | if (SkXfermode::kSrcOver_Mode == fXfermode && |
egdaniel | e73f1f6 | 2015-09-22 10:10:55 -0700 | [diff] [blame] | 739 | kRGBA_GrColorComponentFlags == colorPOI.validFlags() && |
| 740 | !caps.shaderCaps()->dualSourceBlendingSupport() && |
| 741 | !caps.shaderCaps()->dstReadInShaderSupport()) { |
| 742 | // If we don't have dual source blending or in shader dst reads, we fall back to this |
| 743 | // trick for rendering SrcOver LCD text instead of doing a dst copy. |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 744 | SkASSERT(!dstTexture || !dstTexture->texture()); |
| 745 | return PDLCDXferProcessor::Create(fXfermode, colorPOI); |
| 746 | } |
| 747 | blendFormula = get_lcd_blend_formula(covPOI, fXfermode); |
| 748 | } else { |
| 749 | blendFormula = get_blend_formula(colorPOI, covPOI, hasMixedSamples, fXfermode); |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 750 | } |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 751 | |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 752 | if (blendFormula.hasSecondaryOutput() && !caps.shaderCaps()->dualSourceBlendingSupport()) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 753 | return new ShaderPDXferProcessor(dstTexture, hasMixedSamples, fXfermode); |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | SkASSERT(!dstTexture || !dstTexture->texture()); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 757 | return new PorterDuffXferProcessor(blendFormula); |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 758 | } |
| 759 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 760 | void GrPorterDuffXPFactory::getInvariantBlendedColor(const GrProcOptInfo& colorPOI, |
| 761 | InvariantBlendedColor* blendedColor) const { |
| 762 | // Find the blended color info based on the formula that does not have coverage. |
| 763 | BlendFormula colorFormula = gBlendTable[colorPOI.isOpaque()][0][fXfermode]; |
| 764 | if (colorFormula.usesDstColor()) { |
| 765 | blendedColor->fWillBlendWithDst = true; |
| 766 | blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags; |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 767 | return; |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 768 | } |
| 769 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 770 | blendedColor->fWillBlendWithDst = false; |
bungeman | c33db93 | 2015-05-22 17:55:26 -0700 | [diff] [blame] | 771 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 772 | SkASSERT(kAdd_GrBlendEquation == colorFormula.fBlendEquation); |
bungeman | c33db93 | 2015-05-22 17:55:26 -0700 | [diff] [blame] | 773 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 774 | switch (colorFormula.fSrcCoeff) { |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 775 | case kZero_GrBlendCoeff: |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 776 | blendedColor->fKnownColor = 0; |
| 777 | blendedColor->fKnownColorFlags = kRGBA_GrColorComponentFlags; |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 778 | return; |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 779 | |
| 780 | case kOne_GrBlendCoeff: |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 781 | blendedColor->fKnownColor = colorPOI.color(); |
| 782 | blendedColor->fKnownColorFlags = colorPOI.validFlags(); |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 783 | return; |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 784 | |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 785 | default: |
| 786 | blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags; |
| 787 | return; |
egdaniel | 9e4ecdc | 2014-12-18 12:44:55 -0800 | [diff] [blame] | 788 | } |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 789 | } |
| 790 | |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 791 | bool GrPorterDuffXPFactory::willReadDstColor(const GrCaps& caps, |
egdaniel | 3ad6570 | 2015-02-17 11:15:47 -0800 | [diff] [blame] | 792 | const GrProcOptInfo& colorPOI, |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 793 | const GrProcOptInfo& covPOI, |
| 794 | bool hasMixedSamples) const { |
| 795 | if (caps.shaderCaps()->dualSourceBlendingSupport()) { |
| 796 | return false; |
bungeman | c33db93 | 2015-05-22 17:55:26 -0700 | [diff] [blame] | 797 | } |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 798 | |
| 799 | // When we have four channel coverage we always need to read the dst in order to correctly |
| 800 | // blend. The one exception is when we are using srcover mode and we know the input color into |
| 801 | // the XP. |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 802 | if (covPOI.isFourChannelOutput()) { |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 803 | if (SkXfermode::kSrcOver_Mode == fXfermode && |
egdaniel | e73f1f6 | 2015-09-22 10:10:55 -0700 | [diff] [blame] | 804 | kRGBA_GrColorComponentFlags == colorPOI.validFlags() && |
| 805 | !caps.shaderCaps()->dstReadInShaderSupport()) { |
egdaniel | 723b050 | 2015-09-15 09:31:40 -0700 | [diff] [blame] | 806 | return false; |
| 807 | } |
| 808 | return get_lcd_blend_formula(covPOI, fXfermode).hasSecondaryOutput(); |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 809 | } |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 810 | // We fallback on the shader XP when the blend formula would use dual source blending but we |
| 811 | // don't have support for it. |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 812 | return get_blend_formula(colorPOI, covPOI, hasMixedSamples, fXfermode).hasSecondaryOutput(); |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 813 | } |
| 814 | |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 815 | GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); |
| 816 | |
bsalomon | c21b09e | 2015-08-28 18:46:56 -0700 | [diff] [blame] | 817 | const GrXPFactory* GrPorterDuffXPFactory::TestCreate(GrProcessorTestData* d) { |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 818 | SkXfermode::Mode mode = SkXfermode::Mode(d->fRandom->nextULessThan(SkXfermode::kLastCoeffMode)); |
egdaniel | b197b8f | 2015-02-17 07:34:43 -0800 | [diff] [blame] | 819 | return GrPorterDuffXPFactory::Create(mode); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 820 | } |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 821 | |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 822 | void GrPorterDuffXPFactory::TestGetXPOutputTypes(const GrXferProcessor* xp, |
| 823 | int* outPrimary, |
| 824 | int* outSecondary) { |
| 825 | if (!!strcmp(xp->name(), "Porter Duff")) { |
| 826 | *outPrimary = *outSecondary = -1; |
| 827 | return; |
| 828 | } |
| 829 | BlendFormula blendFormula = static_cast<const PorterDuffXferProcessor*>(xp)->getBlendFormula(); |
| 830 | *outPrimary = blendFormula.fPrimaryOutputType; |
| 831 | *outSecondary = blendFormula.fSecondaryOutputType; |
| 832 | } |