OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrXferProcessor_DEFINED | 8 #ifndef GrXferProcessor_DEFINED |
9 #define GrXferProcessor_DEFINED | 9 #define GrXferProcessor_DEFINED |
10 | 10 |
11 #include "GrColor.h" | 11 #include "GrColor.h" |
12 #include "GrProcessor.h" | 12 #include "GrProcessor.h" |
13 #include "GrTexture.h" | 13 #include "GrTexture.h" |
14 #include "GrTypes.h" | 14 #include "GrTypes.h" |
15 #include "SkXfermode.h" | 15 #include "SkXfermode.h" |
16 | 16 |
17 class GrShaderCaps; | 17 class GrShaderCaps; |
18 class GrGLSLCaps; | 18 class GrGLSLCaps; |
19 class GrGLXferProcessor; | 19 class GrGLXferProcessor; |
20 class GrProcOptInfo; | 20 class GrProcOptInfo; |
21 | 21 |
22 /** | 22 /** |
| 23 * Equations for alpha-blending. |
| 24 */ |
| 25 enum GrBlendEquation { |
| 26 kInvalid_GrBlendEquation = -1, |
| 27 |
| 28 // Basic blend equations. |
| 29 kAdd_GrBlendEquation, //<! Cs*S + Cd*D |
| 30 kSubtract_GrBlendEquation, //<! Cs*S - Cd*D |
| 31 kReverseSubtract_GrBlendEquation, //<! Cd*D - Cs*S |
| 32 |
| 33 // Advanced blend equations. These are described in the SVG and PDF specs. |
| 34 kScreen_GrBlendEquation, |
| 35 kOverlay_GrBlendEquation, |
| 36 kDarken_GrBlendEquation, |
| 37 kLighten_GrBlendEquation, |
| 38 kColorDodge_GrBlendEquation, |
| 39 kColorBurn_GrBlendEquation, |
| 40 kHardLight_GrBlendEquation, |
| 41 kSoftLight_GrBlendEquation, |
| 42 kDifference_GrBlendEquation, |
| 43 kExclusion_GrBlendEquation, |
| 44 kMultiply_GrBlendEquation, |
| 45 kHSLHue_GrBlendEquation, |
| 46 kHSLSaturation_GrBlendEquation, |
| 47 kHSLColor_GrBlendEquation, |
| 48 kHSLLuminosity_GrBlendEquation, |
| 49 |
| 50 kTotalGrBlendEquationCount, |
| 51 |
| 52 kFirstAdvancedGrBlendEquation = kScreen_GrBlendEquation |
| 53 }; |
| 54 |
| 55 inline bool GrBlendEquationIsAdvanced(GrBlendEquation equation) { |
| 56 return equation >= kFirstAdvancedGrBlendEquation; |
| 57 } |
| 58 |
| 59 /** |
23 * Coeffecients for alpha-blending. | 60 * Coeffecients for alpha-blending. |
24 */ | 61 */ |
25 enum GrBlendCoeff { | 62 enum GrBlendCoeff { |
26 kInvalid_GrBlendCoeff = -1, | 63 kInvalid_GrBlendCoeff = -1, |
27 | 64 |
28 kZero_GrBlendCoeff, //<! 0 | 65 kZero_GrBlendCoeff, //<! 0 |
29 kOne_GrBlendCoeff, //<! 1 | 66 kOne_GrBlendCoeff, //<! 1 |
30 kSC_GrBlendCoeff, //<! src color | 67 kSC_GrBlendCoeff, //<! src color |
31 kISC_GrBlendCoeff, //<! one minus src color | 68 kISC_GrBlendCoeff, //<! one minus src color |
32 kDC_GrBlendCoeff, //<! dst color | 69 kDC_GrBlendCoeff, //<! dst color |
(...skipping 13 matching lines...) Expand all Loading... |
46 | 83 |
47 kTotalGrBlendCoeffCount | 84 kTotalGrBlendCoeffCount |
48 }; | 85 }; |
49 | 86 |
50 /** | 87 /** |
51 * Barriers for blending. When a shader reads the dst directly, an Xfer barrier
is sometimes | 88 * Barriers for blending. When a shader reads the dst directly, an Xfer barrier
is sometimes |
52 * required after a pixel has been written, before it can be safely read again. | 89 * required after a pixel has been written, before it can be safely read again. |
53 */ | 90 */ |
54 enum GrXferBarrierType { | 91 enum GrXferBarrierType { |
55 kTexture_GrXferBarrierType, //<! Required when a shader reads and renders to
the same texture. | 92 kTexture_GrXferBarrierType, //<! Required when a shader reads and renders to
the same texture. |
| 93 kBlend_GrXferBarrierType, //<! Required by certain blend extensions. |
56 }; | 94 }; |
57 | 95 |
58 /** | 96 /** |
59 * GrXferProcessor is responsible for implementing the xfer mode that blends the
src color and dst | 97 * GrXferProcessor is responsible for implementing the xfer mode that blends the
src color and dst |
60 * color. It does this by emitting fragment shader code and controlling the fixe
d-function blend | 98 * color. It does this by emitting fragment shader code and controlling the fixe
d-function blend |
61 * state. The inputs to its shader code are the final computed src color and fra
ctional pixel | 99 * state. The inputs to its shader code are the final computed src color and fra
ctional pixel |
62 * coverage. The GrXferProcessor's shader code writes the fragment shader output
color that goes | 100 * coverage. The GrXferProcessor's shader code writes the fragment shader output
color that goes |
63 * into the fixed-function blend. When dual-source blending is available, it may
also write a | 101 * into the fixed-function blend. When dual-source blending is available, it may
also write a |
64 * seconday fragment shader output color. When allowed by the backend API, the G
rXferProcessor may | 102 * seconday fragment shader output color. When allowed by the backend API, the G
rXferProcessor may |
65 * read the destination color. The GrXferProcessor is responsible for setting th
e blend coefficients | 103 * read the destination color. The GrXferProcessor is responsible for setting th
e blend coefficients |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 /** | 173 /** |
136 * Returns whether this XP will require an Xfer barrier on the given rt. If
true, outBarrierType | 174 * Returns whether this XP will require an Xfer barrier on the given rt. If
true, outBarrierType |
137 * is updated to contain the type of barrier needed. | 175 * is updated to contain the type of barrier needed. |
138 */ | 176 */ |
139 bool willNeedXferBarrier(const GrRenderTarget* rt, | 177 bool willNeedXferBarrier(const GrRenderTarget* rt, |
140 const GrDrawTargetCaps& caps, | 178 const GrDrawTargetCaps& caps, |
141 GrXferBarrierType* outBarrierType) const; | 179 GrXferBarrierType* outBarrierType) const; |
142 | 180 |
143 struct BlendInfo { | 181 struct BlendInfo { |
144 void reset() { | 182 void reset() { |
| 183 fEquation = kAdd_GrBlendEquation; |
145 fSrcBlend = kOne_GrBlendCoeff; | 184 fSrcBlend = kOne_GrBlendCoeff; |
146 fDstBlend = kZero_GrBlendCoeff; | 185 fDstBlend = kZero_GrBlendCoeff; |
147 fBlendConstant = 0; | 186 fBlendConstant = 0; |
148 fWriteColor = true; | 187 fWriteColor = true; |
149 } | 188 } |
150 | 189 |
151 GrBlendCoeff fSrcBlend; | 190 GrBlendEquation fEquation; |
152 GrBlendCoeff fDstBlend; | 191 GrBlendCoeff fSrcBlend; |
153 GrColor fBlendConstant; | 192 GrBlendCoeff fDstBlend; |
154 bool fWriteColor; | 193 GrColor fBlendConstant; |
| 194 bool fWriteColor; |
155 }; | 195 }; |
156 | 196 |
157 void getBlendInfo(BlendInfo* blendInfo) const { | 197 void getBlendInfo(BlendInfo* blendInfo) const { |
158 blendInfo->reset(); | 198 blendInfo->reset(); |
159 this->onGetBlendInfo(blendInfo); | 199 this->onGetBlendInfo(blendInfo); |
160 } | 200 } |
161 | 201 |
162 bool willReadDstColor() const { return fWillReadDstColor; } | 202 bool willReadDstColor() const { return fWillReadDstColor; } |
163 | 203 |
164 /** | 204 /** |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 252 |
213 private: | 253 private: |
214 /** | 254 /** |
215 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate
d with this xfer | 255 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate
d with this xfer |
216 * processor's GL backend implementation. | 256 * processor's GL backend implementation. |
217 */ | 257 */ |
218 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 258 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, |
219 GrProcessorKeyBuilder* b) const = 0; | 259 GrProcessorKeyBuilder* b) const = 0; |
220 | 260 |
221 /** | 261 /** |
| 262 * If not using a texture barrier, retrieves whether the subclass will requi
re a different type |
| 263 * of barrier. |
| 264 */ |
| 265 virtual bool onWillNeedXferBarrier(const GrRenderTarget*, |
| 266 const GrDrawTargetCaps&, |
| 267 GrXferBarrierType* outBarrierType SK_UNUS
ED) const { |
| 268 return false; |
| 269 } |
| 270 |
| 271 /** |
222 * Retrieves the hardware blend state required by this Xfer processor. The B
lendInfo struct | 272 * Retrieves the hardware blend state required by this Xfer processor. The B
lendInfo struct |
223 * comes initialized to default values, so the Xfer processor only needs to
set the state it | 273 * comes initialized to default values, so the Xfer processor only needs to
set the state it |
224 * needs. It may not even need to override this method at all. | 274 * needs. It may not even need to override this method at all. |
225 */ | 275 */ |
226 virtual void onGetBlendInfo(BlendInfo*) const {} | 276 virtual void onGetBlendInfo(BlendInfo*) const {} |
227 | 277 |
228 virtual bool onIsEqual(const GrXferProcessor&) const = 0; | 278 virtual bool onIsEqual(const GrXferProcessor&) const = 0; |
229 | 279 |
230 bool fWillReadDstColor; | 280 bool fWillReadDstColor; |
231 SkIPoint fDstCopyTextureOffset; | 281 SkIPoint fDstCopyTextureOffset; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 enum { | 384 enum { |
335 kIllegalXPFClassID = 0, | 385 kIllegalXPFClassID = 0, |
336 }; | 386 }; |
337 static int32_t gCurrXPFClassID; | 387 static int32_t gCurrXPFClassID; |
338 | 388 |
339 typedef GrProgramElement INHERITED; | 389 typedef GrProgramElement INHERITED; |
340 }; | 390 }; |
341 | 391 |
342 #endif | 392 #endif |
343 | 393 |
OLD | NEW |