Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: src/gpu/GrBlend.h

Issue 1180713008: Move blend enums into GrBlend.h (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: relative include Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« include/gpu/GrBlend.h ('K') | « include/gpu/GrXferProcessor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 #include "GrTypes.h"
10 #include "SkTLogic.h"
11 #include "GrXferProcessor.h"
12
13 #ifndef GrBlend_DEFINED
14 #define GrBlend_DEFINED
15
16 template<GrBlendCoeff Coeff>
17 struct GrTBlendCoeffRefsSrc : SkTBool<kSC_GrBlendCoeff == Coeff ||
18 kISC_GrBlendCoeff == Coeff ||
19 kSA_GrBlendCoeff == Coeff ||
20 kISA_GrBlendCoeff == Coeff> {};
21
22 #define GR_BLEND_COEFF_REFS_SRC(COEFF) \
23 GrTBlendCoeffRefsSrc<COEFF>::value
24
25 inline bool GrBlendCoeffRefsSrc(GrBlendCoeff coeff) {
26 switch (coeff) {
27 case kSC_GrBlendCoeff:
28 case kISC_GrBlendCoeff:
29 case kSA_GrBlendCoeff:
30 case kISA_GrBlendCoeff:
31 return true;
32 default:
33 return false;
34 }
35 }
36
37
38 template<GrBlendCoeff Coeff>
39 struct GrTBlendCoeffRefsDst : SkTBool<kDC_GrBlendCoeff == Coeff ||
40 kIDC_GrBlendCoeff == Coeff ||
41 kDA_GrBlendCoeff == Coeff ||
42 kIDA_GrBlendCoeff == Coeff> {};
43
44 #define GR_BLEND_COEFF_REFS_DST(COEFF) \
45 GrTBlendCoeffRefsDst<COEFF>::value
46
47 inline bool GrBlendCoeffRefsDst(GrBlendCoeff coeff) {
48 switch (coeff) {
49 case kDC_GrBlendCoeff:
50 case kIDC_GrBlendCoeff:
51 case kDA_GrBlendCoeff:
52 case kIDA_GrBlendCoeff:
53 return true;
54 default:
55 return false;
56 }
57 }
58
59
60 template<GrBlendCoeff Coeff>
61 struct GrTBlendCoeffRefsSrc2 : SkTBool<kS2C_GrBlendCoeff == Coeff ||
62 kIS2C_GrBlendCoeff == Coeff ||
63 kS2A_GrBlendCoeff == Coeff ||
64 kIS2A_GrBlendCoeff == Coeff> {};
65
66 #define GR_BLEND_COEFF_REFS_SRC2(COEFF) \
67 GrTBlendCoeffRefsSrc2<COEFF>::value
68
69 inline bool GrBlendCoeffRefsSrc2(GrBlendCoeff coeff) {
70 switch (coeff) {
71 case kS2C_GrBlendCoeff:
72 case kIS2C_GrBlendCoeff:
73 case kS2A_GrBlendCoeff:
74 case kIS2A_GrBlendCoeff:
75 return true;
76 default:
77 return false;
78 }
79 }
80
81
82 template<GrBlendCoeff SrcCoeff, GrBlendCoeff DstCoeff>
83 struct GrTBlendCoeffsUseSrcColor : SkTBool<kZero_GrBlendCoeff != SrcCoeff ||
84 GR_BLEND_COEFF_REFS_SRC(DstCoeff)> {} ;
85
86 #define GR_BLEND_COEFFS_USE_SRC_COLOR(SRC_COEFF, DST_COEFF) \
87 GrTBlendCoeffsUseSrcColor<SRC_COEFF, DST_COEFF>::value
88
89
90 template<GrBlendCoeff SrcCoeff, GrBlendCoeff DstCoeff>
91 struct GrTBlendCoeffsUseDstColor : SkTBool<GR_BLEND_COEFF_REFS_DST(SrcCoeff) ||
92 kZero_GrBlendCoeff != DstCoeff> {};
93
94 #define GR_BLEND_COEFFS_USE_DST_COLOR(SRC_COEFF, DST_COEFF) \
95 GrTBlendCoeffsUseDstColor<SRC_COEFF, DST_COEFF>::value
96
97
98 template<GrBlendEquation Equation>
99 struct GrTBlendEquationIsAdvanced : SkTBool<Equation >= kFirstAdvancedGrBlendEqu ation> {};
100
101 #define GR_BLEND_EQUATION_IS_ADVANCED(EQUATION) \
102 GrTBlendEquationIsAdvanced<EQUATION>::value
103
104 inline bool GrBlendEquationIsAdvanced(GrBlendEquation equation) {
105 return equation >= kFirstAdvancedGrBlendEquation;
106 }
107
108
109 template<GrBlendEquation BlendEquation, GrBlendCoeff SrcCoeff, GrBlendCoeff DstC oeff>
110 struct GrTBlendModifiesDst : SkTBool<(kAdd_GrBlendEquation != BlendEquation &&
111 kReverseSubtract_GrBlendEquation != BlendE quation) ||
112 kZero_GrBlendCoeff != SrcCoeff ||
113 kOne_GrBlendCoeff != DstCoeff> {};
114
115 #define GR_BLEND_MODIFIES_DST(EQUATION, SRC_COEFF, DST_COEFF) \
116 GrTBlendModifiesDst<EQUATION, SRC_COEFF, DST_COEFF>::value
117
118
119 /**
120 * Advanced blend equations can always tweak alpha for coverage. (See GrCustomXf ermode.cpp)
121 *
122 * For "add" and "reverse subtract" the blend equation with f=coverage is:
123 *
124 * D' = f * (S * srcCoeff + D * dstCoeff) + (1-f) * D
125 * = f * S * srcCoeff + D * (f * dstCoeff + (1 - f))
126 *
127 * (Let srcCoeff be negative for reverse subtract.) We can tweak alpha for cover age when the
128 * following relationship holds:
129 *
130 * (f*S) * srcCoeff' + D * dstCoeff' == f * S * srcCoeff + D * (f * dstCoeff + (1 - f))
131 *
132 * (Where srcCoeff' and dstCoeff' have any reference to S pre-multiplied by f.)
133 *
134 * It's easy to see this works for the src term as long as srcCoeff' == srcCoeff (meaning srcCoeff
135 * does not reference S). For the dst term, this will work as long as the follow ing is true:
136 *|
137 * dstCoeff' == f * dstCoeff + (1 - f)
138 * dstCoeff' == 1 - f * (1 - dstCoeff)
139 *
140 * By inspection we can see this will work as long as dstCoeff has a 1, and any other term in
141 * dstCoeff references S.
142 */
143 template<GrBlendEquation Equation, GrBlendCoeff SrcCoeff, GrBlendCoeff DstCoeff>
144 struct GrTBlendCanTweakAlphaForCoverage : SkTBool<GR_BLEND_EQUATION_IS_ADVANCED( Equation) ||
145 ((kAdd_GrBlendEquation == Equa tion ||
146 kReverseSubtract_GrBlendEqua tion == Equation) &&
147 !GR_BLEND_COEFF_REFS_SRC(SrcC oeff) &&
148 (kOne_GrBlendCoeff == DstCoef f ||
149 kISC_GrBlendCoeff == DstCoef f ||
150 kISA_GrBlendCoeff == DstCoef f))> {};
151
152 #define GR_BLEND_CAN_TWEAK_ALPHA_FOR_COVERAGE(EQUATION, SRC_COEFF, DST_COEFF) \
153 GrTBlendCanTweakAlphaForCoverage<EQUATION, SRC_COEFF, DST_COEFF>::value
154
155 #endif
OLDNEW
« include/gpu/GrBlend.h ('K') | « include/gpu/GrXferProcessor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698