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" | |
10 #include "../private/SkTLogic.h" | |
11 | |
12 #ifndef GrBlend_DEFINED | 9 #ifndef GrBlend_DEFINED |
13 #define GrBlend_DEFINED | 10 #define GrBlend_DEFINED |
14 | 11 |
| 12 #include "GrColor.h" |
| 13 #include "../private/SkTLogic.h" |
| 14 |
15 /** | 15 /** |
16 * Equations for alpha-blending. | 16 * Equations for alpha-blending. |
17 */ | 17 */ |
18 enum GrBlendEquation { | 18 enum GrBlendEquation { |
19 // Basic blend equations. | 19 // Basic blend equations. |
20 kAdd_GrBlendEquation, //<! Cs*S + Cd*D | 20 kAdd_GrBlendEquation, //<! Cs*S + Cd*D |
21 kSubtract_GrBlendEquation, //<! Cs*S - Cd*D | 21 kSubtract_GrBlendEquation, //<! Cs*S - Cd*D |
22 kReverseSubtract_GrBlendEquation, //<! Cd*D - Cs*S | 22 kReverseSubtract_GrBlendEquation, //<! Cd*D - Cs*S |
23 | 23 |
24 // Advanced blend equations. These are described in the SVG and PDF specs. | 24 // Advanced blend equations. These are described in the SVG and PDF specs. |
(...skipping 14 matching lines...) Expand all Loading... |
39 kHSLLuminosity_GrBlendEquation, | 39 kHSLLuminosity_GrBlendEquation, |
40 | 40 |
41 kFirstAdvancedGrBlendEquation = kScreen_GrBlendEquation, | 41 kFirstAdvancedGrBlendEquation = kScreen_GrBlendEquation, |
42 kLast_GrBlendEquation = kHSLLuminosity_GrBlendEquation | 42 kLast_GrBlendEquation = kHSLLuminosity_GrBlendEquation |
43 }; | 43 }; |
44 | 44 |
45 static const int kGrBlendEquationCnt = kLast_GrBlendEquation + 1; | 45 static const int kGrBlendEquationCnt = kLast_GrBlendEquation + 1; |
46 | 46 |
47 | 47 |
48 /** | 48 /** |
49 * Coeffecients for alpha-blending. | 49 * Coefficients for alpha-blending. |
50 */ | 50 */ |
51 enum GrBlendCoeff { | 51 enum GrBlendCoeff { |
52 kZero_GrBlendCoeff, //<! 0 | 52 kZero_GrBlendCoeff, //<! 0 |
53 kOne_GrBlendCoeff, //<! 1 | 53 kOne_GrBlendCoeff, //<! 1 |
54 kSC_GrBlendCoeff, //<! src color | 54 kSC_GrBlendCoeff, //<! src color |
55 kISC_GrBlendCoeff, //<! one minus src color | 55 kISC_GrBlendCoeff, //<! one minus src color |
56 kDC_GrBlendCoeff, //<! dst color | 56 kDC_GrBlendCoeff, //<! dst color |
57 kIDC_GrBlendCoeff, //<! one minus dst color | 57 kIDC_GrBlendCoeff, //<! one minus dst color |
58 kSA_GrBlendCoeff, //<! src alpha | 58 kSA_GrBlendCoeff, //<! src alpha |
59 kISA_GrBlendCoeff, //<! one minus src alpha | 59 kISA_GrBlendCoeff, //<! one minus src alpha |
60 kDA_GrBlendCoeff, //<! dst alpha | 60 kDA_GrBlendCoeff, //<! dst alpha |
61 kIDA_GrBlendCoeff, //<! one minus dst alpha | 61 kIDA_GrBlendCoeff, //<! one minus dst alpha |
62 kConstC_GrBlendCoeff, //<! constant color | 62 kConstC_GrBlendCoeff, //<! constant color |
63 kIConstC_GrBlendCoeff, //<! one minus constant color | 63 kIConstC_GrBlendCoeff, //<! one minus constant color |
64 kConstA_GrBlendCoeff, //<! constant color alpha | 64 kConstA_GrBlendCoeff, //<! constant color alpha |
65 kIConstA_GrBlendCoeff, //<! one minus constant color alpha | 65 kIConstA_GrBlendCoeff, //<! one minus constant color alpha |
66 kS2C_GrBlendCoeff, | 66 kS2C_GrBlendCoeff, |
67 kIS2C_GrBlendCoeff, | 67 kIS2C_GrBlendCoeff, |
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 /** |
| 77 * Given a known blend equation in the form of srcCoeff * srcColor + dstCoeff *
dstColor where |
| 78 * there may be partial knowledge of the srcColor and dstColor component values,
determine what |
| 79 * components of the blended output color are known. Coeffs must not refer to th
e constant or |
| 80 * secondary src color. |
| 81 */ |
| 82 void GrGetCoeffBlendKnownComponents(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff
, |
| 83 GrColor srcColor, |
| 84 GrColorComponentFlags srcColorFlags, |
| 85 GrColor dstColor, |
| 86 GrColorComponentFlags dstColorFlags, |
| 87 GrColor* outColor, |
| 88 GrColorComponentFlags* outFlags); |
76 | 89 |
77 template<GrBlendCoeff Coeff> | 90 template<GrBlendCoeff Coeff> |
78 struct GrTBlendCoeffRefsSrc : skstd::bool_constant<kSC_GrBlendCoeff == Coeff || | 91 struct GrTBlendCoeffRefsSrc : skstd::bool_constant<kSC_GrBlendCoeff == Coeff || |
79 kISC_GrBlendCoeff == Coeff || | 92 kISC_GrBlendCoeff == Coeff || |
80 kSA_GrBlendCoeff == Coeff || | 93 kSA_GrBlendCoeff == Coeff || |
81 kISA_GrBlendCoeff == Coeff> {
}; | 94 kISA_GrBlendCoeff == Coeff> {
}; |
82 | 95 |
83 #define GR_BLEND_COEFF_REFS_SRC(COEFF) \ | 96 #define GR_BLEND_COEFF_REFS_SRC(COEFF) \ |
84 GrTBlendCoeffRefsSrc<COEFF>::value | 97 GrTBlendCoeffRefsSrc<COEFF>::value |
85 | 98 |
86 inline bool GrBlendCoeffRefsSrc(GrBlendCoeff coeff) { | 99 inline bool GrBlendCoeffRefsSrc(GrBlendCoeff coeff) { |
87 switch (coeff) { | 100 switch (coeff) { |
88 case kSC_GrBlendCoeff: | 101 case kSC_GrBlendCoeff: |
89 case kISC_GrBlendCoeff: | 102 case kISC_GrBlendCoeff: |
90 case kSA_GrBlendCoeff: | 103 case kSA_GrBlendCoeff: |
91 case kISA_GrBlendCoeff: | 104 case kISA_GrBlendCoeff: |
92 return true; | 105 return true; |
93 default: | 106 default: |
94 return false; | 107 return false; |
95 } | 108 } |
96 } | 109 } |
97 | 110 |
98 | |
99 template<GrBlendCoeff Coeff> | 111 template<GrBlendCoeff Coeff> |
100 struct GrTBlendCoeffRefsDst : skstd::bool_constant<kDC_GrBlendCoeff == Coeff || | 112 struct GrTBlendCoeffRefsDst : skstd::bool_constant<kDC_GrBlendCoeff == Coeff || |
101 kIDC_GrBlendCoeff == Coeff || | 113 kIDC_GrBlendCoeff == Coeff || |
102 kDA_GrBlendCoeff == Coeff || | 114 kDA_GrBlendCoeff == Coeff || |
103 kIDA_GrBlendCoeff == Coeff> {
}; | 115 kIDA_GrBlendCoeff == Coeff> {
}; |
104 | 116 |
105 #define GR_BLEND_COEFF_REFS_DST(COEFF) \ | 117 #define GR_BLEND_COEFF_REFS_DST(COEFF) \ |
106 GrTBlendCoeffRefsDst<COEFF>::value | 118 GrTBlendCoeffRefsDst<COEFF>::value |
107 | 119 |
108 inline bool GrBlendCoeffRefsDst(GrBlendCoeff coeff) { | 120 inline bool GrBlendCoeffRefsDst(GrBlendCoeff coeff) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 ((kAdd_GrBlendEquation == Equation || kReverseSubtract_GrBlendEquation == Eq
uation) && | 219 ((kAdd_GrBlendEquation == Equation || kReverseSubtract_GrBlendEquation == Eq
uation) && |
208 !GR_BLEND_COEFF_REFS_SRC(SrcCoeff) && | 220 !GR_BLEND_COEFF_REFS_SRC(SrcCoeff) && |
209 (kOne_GrBlendCoeff == DstCoeff || | 221 (kOne_GrBlendCoeff == DstCoeff || |
210 kISC_GrBlendCoeff == DstCoeff || | 222 kISC_GrBlendCoeff == DstCoeff || |
211 kISA_GrBlendCoeff == DstCoeff))> {}; | 223 kISA_GrBlendCoeff == DstCoeff))> {}; |
212 | 224 |
213 #define GR_BLEND_CAN_TWEAK_ALPHA_FOR_COVERAGE(EQUATION, SRC_COEFF, DST_COEFF) \ | 225 #define GR_BLEND_CAN_TWEAK_ALPHA_FOR_COVERAGE(EQUATION, SRC_COEFF, DST_COEFF) \ |
214 GrTBlendCanTweakAlphaForCoverage<EQUATION, SRC_COEFF, DST_COEFF>::value | 226 GrTBlendCanTweakAlphaForCoverage<EQUATION, SRC_COEFF, DST_COEFF>::value |
215 | 227 |
216 #endif | 228 #endif |
OLD | NEW |