9 #ifndef GrBlend_DEFINED
10 #define GrBlend_DEFINED
13 #include "../private/SkTLogic.h"
18 enum GrBlendEquation {
21 kSubtract_GrBlendEquation,
22 kReverseSubtract_GrBlendEquation,
25 kScreen_GrBlendEquation,
26 kOverlay_GrBlendEquation,
27 kDarken_GrBlendEquation,
28 kLighten_GrBlendEquation,
29 kColorDodge_GrBlendEquation,
30 kColorBurn_GrBlendEquation,
31 kHardLight_GrBlendEquation,
32 kSoftLight_GrBlendEquation,
33 kDifference_GrBlendEquation,
34 kExclusion_GrBlendEquation,
35 kMultiply_GrBlendEquation,
36 kHSLHue_GrBlendEquation,
37 kHSLSaturation_GrBlendEquation,
38 kHSLColor_GrBlendEquation,
39 kHSLLuminosity_GrBlendEquation,
41 kFirstAdvancedGrBlendEquation = kScreen_GrBlendEquation,
42 kLast_GrBlendEquation = kHSLLuminosity_GrBlendEquation
45 static const int kGrBlendEquationCnt = kLast_GrBlendEquation + 1;
63 kIConstC_GrBlendCoeff,
65 kIConstA_GrBlendCoeff,
71 kLast_GrBlendCoeff = kIS2A_GrBlendCoeff
74 static const int kGrBlendCoeffCnt = kLast_GrBlendCoeff + 1;
76 static constexpr
bool GrBlendCoeffRefsSrc(
const GrBlendCoeff coeff) {
77 return kSC_GrBlendCoeff == coeff || kISC_GrBlendCoeff == coeff || kSA_GrBlendCoeff == coeff ||
78 kISA_GrBlendCoeff == coeff;
81 static constexpr
bool GrBlendCoeffRefsDst(
const GrBlendCoeff coeff) {
82 return kDC_GrBlendCoeff == coeff || kIDC_GrBlendCoeff == coeff || kDA_GrBlendCoeff == coeff ||
83 kIDA_GrBlendCoeff == coeff;
86 static constexpr
bool GrBlendCoeffRefsSrc2(
const GrBlendCoeff coeff) {
87 return kS2C_GrBlendCoeff == coeff || kIS2C_GrBlendCoeff == coeff ||
88 kS2A_GrBlendCoeff == coeff || kIS2A_GrBlendCoeff == coeff;
91 static constexpr
bool GrBlendCoeffsUseSrcColor(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) {
92 return kZero_GrBlendCoeff != srcCoeff || GrBlendCoeffRefsSrc(dstCoeff);
95 static constexpr
bool GrBlendCoeffsUseDstColor(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) {
96 return GrBlendCoeffRefsDst(srcCoeff) || kZero_GrBlendCoeff != dstCoeff;
99 static constexpr
bool GrBlendEquationIsAdvanced(GrBlendEquation equation) {
100 return equation >= kFirstAdvancedGrBlendEquation;
103 static constexpr
bool GrBlendModifiesDst(GrBlendEquation equation, GrBlendCoeff srcCoeff,
104 GrBlendCoeff dstCoeff) {
105 return (kAdd_GrBlendEquation != equation && kReverseSubtract_GrBlendEquation != equation) ||
106 kZero_GrBlendCoeff != srcCoeff || kOne_GrBlendCoeff != dstCoeff;
136 static constexpr
bool GrBlendAllowsCoverageAsAlpha(GrBlendEquation equation,
137 GrBlendCoeff srcCoeff,
138 GrBlendCoeff dstCoeff) {
139 return GrBlendEquationIsAdvanced(equation) ||
140 !GrBlendModifiesDst(equation, srcCoeff, dstCoeff) ||
141 ((kAdd_GrBlendEquation == equation || kReverseSubtract_GrBlendEquation == equation) &&
142 !GrBlendCoeffRefsSrc(srcCoeff) &&
143 (kOne_GrBlendCoeff == dstCoeff || kISC_GrBlendCoeff == dstCoeff ||
144 kISA_GrBlendCoeff == dstCoeff));