| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrTypes.h" | 9 #include "GrTypes.h" |
| 10 #include "../private/SkTLogic.h" | 10 #include "../private/SkTLogic.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 kS2A_GrBlendCoeff, | 68 kS2A_GrBlendCoeff, |
| 69 kIS2A_GrBlendCoeff, | 69 kIS2A_GrBlendCoeff, |
| 70 | 70 |
| 71 kLast_GrBlendCoeff = kIS2A_GrBlendCoeff | 71 kLast_GrBlendCoeff = kIS2A_GrBlendCoeff |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 static const int kGrBlendCoeffCnt = kLast_GrBlendCoeff + 1; | 74 static const int kGrBlendCoeffCnt = kLast_GrBlendCoeff + 1; |
| 75 | 75 |
| 76 | 76 |
| 77 template<GrBlendCoeff Coeff> | 77 template<GrBlendCoeff Coeff> |
| 78 struct GrTBlendCoeffRefsSrc : SkTBool<kSC_GrBlendCoeff == Coeff || | 78 struct GrTBlendCoeffRefsSrc : skstd::bool_constant<kSC_GrBlendCoeff == Coeff || |
| 79 kISC_GrBlendCoeff == Coeff || | 79 kISC_GrBlendCoeff == Coeff || |
| 80 kSA_GrBlendCoeff == Coeff || | 80 kSA_GrBlendCoeff == Coeff || |
| 81 kISA_GrBlendCoeff == Coeff> {}; | 81 kISA_GrBlendCoeff == Coeff> {
}; |
| 82 | 82 |
| 83 #define GR_BLEND_COEFF_REFS_SRC(COEFF) \ | 83 #define GR_BLEND_COEFF_REFS_SRC(COEFF) \ |
| 84 GrTBlendCoeffRefsSrc<COEFF>::value | 84 GrTBlendCoeffRefsSrc<COEFF>::value |
| 85 | 85 |
| 86 inline bool GrBlendCoeffRefsSrc(GrBlendCoeff coeff) { | 86 inline bool GrBlendCoeffRefsSrc(GrBlendCoeff coeff) { |
| 87 switch (coeff) { | 87 switch (coeff) { |
| 88 case kSC_GrBlendCoeff: | 88 case kSC_GrBlendCoeff: |
| 89 case kISC_GrBlendCoeff: | 89 case kISC_GrBlendCoeff: |
| 90 case kSA_GrBlendCoeff: | 90 case kSA_GrBlendCoeff: |
| 91 case kISA_GrBlendCoeff: | 91 case kISA_GrBlendCoeff: |
| 92 return true; | 92 return true; |
| 93 default: | 93 default: |
| 94 return false; | 94 return false; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 | 98 |
| 99 template<GrBlendCoeff Coeff> | 99 template<GrBlendCoeff Coeff> |
| 100 struct GrTBlendCoeffRefsDst : SkTBool<kDC_GrBlendCoeff == Coeff || | 100 struct GrTBlendCoeffRefsDst : skstd::bool_constant<kDC_GrBlendCoeff == Coeff || |
| 101 kIDC_GrBlendCoeff == Coeff || | 101 kIDC_GrBlendCoeff == Coeff || |
| 102 kDA_GrBlendCoeff == Coeff || | 102 kDA_GrBlendCoeff == Coeff || |
| 103 kIDA_GrBlendCoeff == Coeff> {}; | 103 kIDA_GrBlendCoeff == Coeff> {
}; |
| 104 | 104 |
| 105 #define GR_BLEND_COEFF_REFS_DST(COEFF) \ | 105 #define GR_BLEND_COEFF_REFS_DST(COEFF) \ |
| 106 GrTBlendCoeffRefsDst<COEFF>::value | 106 GrTBlendCoeffRefsDst<COEFF>::value |
| 107 | 107 |
| 108 inline bool GrBlendCoeffRefsDst(GrBlendCoeff coeff) { | 108 inline bool GrBlendCoeffRefsDst(GrBlendCoeff coeff) { |
| 109 switch (coeff) { | 109 switch (coeff) { |
| 110 case kDC_GrBlendCoeff: | 110 case kDC_GrBlendCoeff: |
| 111 case kIDC_GrBlendCoeff: | 111 case kIDC_GrBlendCoeff: |
| 112 case kDA_GrBlendCoeff: | 112 case kDA_GrBlendCoeff: |
| 113 case kIDA_GrBlendCoeff: | 113 case kIDA_GrBlendCoeff: |
| 114 return true; | 114 return true; |
| 115 default: | 115 default: |
| 116 return false; | 116 return false; |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 template<GrBlendCoeff Coeff> | 121 template<GrBlendCoeff Coeff> |
| 122 struct GrTBlendCoeffRefsSrc2 : SkTBool<kS2C_GrBlendCoeff == Coeff || | 122 struct GrTBlendCoeffRefsSrc2 : skstd::bool_constant<kS2C_GrBlendCoeff == Coeff |
| |
| 123 kIS2C_GrBlendCoeff == Coeff || | 123 kIS2C_GrBlendCoeff == Coeff
|| |
| 124 kS2A_GrBlendCoeff == Coeff || | 124 kS2A_GrBlendCoeff == Coeff |
| |
| 125 kIS2A_GrBlendCoeff == Coeff> {}; | 125 kIS2A_GrBlendCoeff == Coeff>
{}; |
| 126 | 126 |
| 127 #define GR_BLEND_COEFF_REFS_SRC2(COEFF) \ | 127 #define GR_BLEND_COEFF_REFS_SRC2(COEFF) \ |
| 128 GrTBlendCoeffRefsSrc2<COEFF>::value | 128 GrTBlendCoeffRefsSrc2<COEFF>::value |
| 129 | 129 |
| 130 inline bool GrBlendCoeffRefsSrc2(GrBlendCoeff coeff) { | 130 inline bool GrBlendCoeffRefsSrc2(GrBlendCoeff coeff) { |
| 131 switch (coeff) { | 131 switch (coeff) { |
| 132 case kS2C_GrBlendCoeff: | 132 case kS2C_GrBlendCoeff: |
| 133 case kIS2C_GrBlendCoeff: | 133 case kIS2C_GrBlendCoeff: |
| 134 case kS2A_GrBlendCoeff: | 134 case kS2A_GrBlendCoeff: |
| 135 case kIS2A_GrBlendCoeff: | 135 case kIS2A_GrBlendCoeff: |
| 136 return true; | 136 return true; |
| 137 default: | 137 default: |
| 138 return false; | 138 return false; |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 | 142 |
| 143 template<GrBlendCoeff SrcCoeff, GrBlendCoeff DstCoeff> | 143 template<GrBlendCoeff SrcCoeff, GrBlendCoeff DstCoeff> |
| 144 struct GrTBlendCoeffsUseSrcColor : SkTBool<kZero_GrBlendCoeff != SrcCoeff || | 144 struct GrTBlendCoeffsUseSrcColor : skstd::bool_constant<kZero_GrBlendCoeff != Sr
cCoeff || |
| 145 GR_BLEND_COEFF_REFS_SRC(DstCoeff)> {}
; | 145 GR_BLEND_COEFF_REFS_SRC(
DstCoeff)> {}; |
| 146 | 146 |
| 147 #define GR_BLEND_COEFFS_USE_SRC_COLOR(SRC_COEFF, DST_COEFF) \ | 147 #define GR_BLEND_COEFFS_USE_SRC_COLOR(SRC_COEFF, DST_COEFF) \ |
| 148 GrTBlendCoeffsUseSrcColor<SRC_COEFF, DST_COEFF>::value | 148 GrTBlendCoeffsUseSrcColor<SRC_COEFF, DST_COEFF>::value |
| 149 | 149 |
| 150 | 150 |
| 151 template<GrBlendCoeff SrcCoeff, GrBlendCoeff DstCoeff> | 151 template<GrBlendCoeff SrcCoeff, GrBlendCoeff DstCoeff> |
| 152 struct GrTBlendCoeffsUseDstColor : SkTBool<GR_BLEND_COEFF_REFS_DST(SrcCoeff) || | 152 struct GrTBlendCoeffsUseDstColor : skstd::bool_constant<GR_BLEND_COEFF_REFS_DST(
SrcCoeff) || |
| 153 kZero_GrBlendCoeff != DstCoeff> {}; | 153 kZero_GrBlendCoeff != Ds
tCoeff> {}; |
| 154 | 154 |
| 155 #define GR_BLEND_COEFFS_USE_DST_COLOR(SRC_COEFF, DST_COEFF) \ | 155 #define GR_BLEND_COEFFS_USE_DST_COLOR(SRC_COEFF, DST_COEFF) \ |
| 156 GrTBlendCoeffsUseDstColor<SRC_COEFF, DST_COEFF>::value | 156 GrTBlendCoeffsUseDstColor<SRC_COEFF, DST_COEFF>::value |
| 157 | 157 |
| 158 | 158 |
| 159 template<GrBlendEquation Equation> | 159 template<GrBlendEquation Equation> |
| 160 struct GrTBlendEquationIsAdvanced : SkTBool<Equation >= kFirstAdvancedGrBlendEqu
ation> {}; | 160 struct GrTBlendEquationIsAdvanced : skstd::bool_constant<Equation >= kFirstAdvan
cedGrBlendEquation> {}; |
| 161 | 161 |
| 162 #define GR_BLEND_EQUATION_IS_ADVANCED(EQUATION) \ | 162 #define GR_BLEND_EQUATION_IS_ADVANCED(EQUATION) \ |
| 163 GrTBlendEquationIsAdvanced<EQUATION>::value | 163 GrTBlendEquationIsAdvanced<EQUATION>::value |
| 164 | 164 |
| 165 inline bool GrBlendEquationIsAdvanced(GrBlendEquation equation) { | 165 inline bool GrBlendEquationIsAdvanced(GrBlendEquation equation) { |
| 166 return equation >= kFirstAdvancedGrBlendEquation; | 166 return equation >= kFirstAdvancedGrBlendEquation; |
| 167 } | 167 } |
| 168 | 168 |
| 169 | 169 |
| 170 template<GrBlendEquation BlendEquation, GrBlendCoeff SrcCoeff, GrBlendCoeff DstC
oeff> | 170 template<GrBlendEquation BlendEquation, GrBlendCoeff SrcCoeff, GrBlendCoeff DstC
oeff> |
| 171 struct GrTBlendModifiesDst : SkTBool<(kAdd_GrBlendEquation != BlendEquation && | 171 struct GrTBlendModifiesDst : skstd::bool_constant< |
| 172 kReverseSubtract_GrBlendEquation != BlendE
quation) || | 172 (kAdd_GrBlendEquation != BlendEquation && kReverseSubtract_GrBlendEquation !
= BlendEquation) || |
| 173 kZero_GrBlendCoeff != SrcCoeff || | 173 kZero_GrBlendCoeff != SrcCoeff || |
| 174 kOne_GrBlendCoeff != DstCoeff> {}; | 174 kOne_GrBlendCoeff != DstCoeff> {}; |
| 175 | 175 |
| 176 #define GR_BLEND_MODIFIES_DST(EQUATION, SRC_COEFF, DST_COEFF) \ | 176 #define GR_BLEND_MODIFIES_DST(EQUATION, SRC_COEFF, DST_COEFF) \ |
| 177 GrTBlendModifiesDst<EQUATION, SRC_COEFF, DST_COEFF>::value | 177 GrTBlendModifiesDst<EQUATION, SRC_COEFF, DST_COEFF>::value |
| 178 | 178 |
| 179 | 179 |
| 180 /** | 180 /** |
| 181 * Advanced blend equations can always tweak alpha for coverage. (See GrCustomXf
ermode.cpp) | 181 * Advanced blend equations can always tweak alpha for coverage. (See GrCustomXf
ermode.cpp) |
| 182 * | 182 * |
| 183 * For "add" and "reverse subtract" the blend equation with f=coverage is: | 183 * For "add" and "reverse subtract" the blend equation with f=coverage is: |
| 184 * | 184 * |
| (...skipping 10 matching lines...) Expand all Loading... |
| 195 * It's easy to see this works for the src term as long as srcCoeff' == srcCoeff
(meaning srcCoeff | 195 * It's easy to see this works for the src term as long as srcCoeff' == srcCoeff
(meaning srcCoeff |
| 196 * does not reference S). For the dst term, this will work as long as the follow
ing is true: | 196 * does not reference S). For the dst term, this will work as long as the follow
ing is true: |
| 197 *| | 197 *| |
| 198 * dstCoeff' == f * dstCoeff + (1 - f) | 198 * dstCoeff' == f * dstCoeff + (1 - f) |
| 199 * dstCoeff' == 1 - f * (1 - dstCoeff) | 199 * dstCoeff' == 1 - f * (1 - dstCoeff) |
| 200 * | 200 * |
| 201 * By inspection we can see this will work as long as dstCoeff has a 1, and any
other term in | 201 * By inspection we can see this will work as long as dstCoeff has a 1, and any
other term in |
| 202 * dstCoeff references S. | 202 * dstCoeff references S. |
| 203 */ | 203 */ |
| 204 template<GrBlendEquation Equation, GrBlendCoeff SrcCoeff, GrBlendCoeff DstCoeff> | 204 template<GrBlendEquation Equation, GrBlendCoeff SrcCoeff, GrBlendCoeff DstCoeff> |
| 205 struct GrTBlendCanTweakAlphaForCoverage : SkTBool<GR_BLEND_EQUATION_IS_ADVANCED(
Equation) || | 205 struct GrTBlendCanTweakAlphaForCoverage : skstd::bool_constant< |
| 206 ((kAdd_GrBlendEquation == Equa
tion || | 206 GR_BLEND_EQUATION_IS_ADVANCED(Equation) || |
| 207 kReverseSubtract_GrBlendEqua
tion == Equation) && | 207 ((kAdd_GrBlendEquation == Equation || kReverseSubtract_GrBlendEquation == Eq
uation) && |
| 208 !GR_BLEND_COEFF_REFS_SRC(SrcC
oeff) && | 208 !GR_BLEND_COEFF_REFS_SRC(SrcCoeff) && |
| 209 (kOne_GrBlendCoeff == DstCoef
f || | 209 (kOne_GrBlendCoeff == DstCoeff || |
| 210 kISC_GrBlendCoeff == DstCoef
f || | 210 kISC_GrBlendCoeff == DstCoeff || |
| 211 kISA_GrBlendCoeff == DstCoef
f))> {}; | 211 kISA_GrBlendCoeff == DstCoeff))> {}; |
| 212 | 212 |
| 213 #define GR_BLEND_CAN_TWEAK_ALPHA_FOR_COVERAGE(EQUATION, SRC_COEFF, DST_COEFF) \ | 213 #define GR_BLEND_CAN_TWEAK_ALPHA_FOR_COVERAGE(EQUATION, SRC_COEFF, DST_COEFF) \ |
| 214 GrTBlendCanTweakAlphaForCoverage<EQUATION, SRC_COEFF, DST_COEFF>::value | 214 GrTBlendCanTweakAlphaForCoverage<EQUATION, SRC_COEFF, DST_COEFF>::value |
| 215 | 215 |
| 216 #endif | 216 #endif |
| OLD | NEW |