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

Side by Side Diff: include/gpu/GrXferProcessor.h

Issue 1037123003: Implement support for KHR_blend_equation_advanced (Closed) Base URL: https://skia.googlesource.com/skia.git@upload_zzz2_barriers
Patch Set: Created 5 years, 8 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
OLDNEW
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 GrDrawTargetCaps; 17 class GrDrawTargetCaps;
18 class GrGLCaps; 18 class GrGLCaps;
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 kLastBasicGrBlendEquation = kReverseSubtract_GrBlendEquation,
34
35 // Advanced blend equations. These are described in the SVG and PDF specs.
36 kScreen_GrBlendEquation,
37 kOverlay_GrBlendEquation,
38 kDarken_GrBlendEquation,
39 kLighten_GrBlendEquation,
40 kColorDodge_GrBlendEquation,
41 kColorBurn_GrBlendEquation,
42 kHardLight_GrBlendEquation,
43 kSoftLight_GrBlendEquation,
44 kDifference_GrBlendEquation,
45 kExclusion_GrBlendEquation,
46 kMultiply_GrBlendEquation,
47 kHSLHue_GrBlendEquation,
48 kHSLSaturation_GrBlendEquation,
49 kHSLColor_GrBlendEquation,
50 kHSLLuminosity_GrBlendEquation,
51
52 kTotalGrBlendEquationCount
53 };
54
55 bool constexpr GrBlendEquationIsAdvanced(GrBlendEquation equation) {
56 return equation > kLastBasicGrBlendEquation;
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
33 kIDC_GrBlendCoeff, //<! one minus dst color 70 kIDC_GrBlendCoeff, //<! one minus dst color
34 kSA_GrBlendCoeff, //<! src alpha 71 kSA_GrBlendCoeff, //<! src alpha
35 kISA_GrBlendCoeff, //<! one minus src alpha 72 kISA_GrBlendCoeff, //<! one minus src alpha
36 kDA_GrBlendCoeff, //<! dst alpha 73 kDA_GrBlendCoeff, //<! dst alpha
37 kIDA_GrBlendCoeff, //<! one minus dst alpha 74 kIDA_GrBlendCoeff, //<! one minus dst alpha
38 kConstC_GrBlendCoeff, //<! constant color 75 kConstC_GrBlendCoeff, //<! constant color
39 kIConstC_GrBlendCoeff, //<! one minus constant color 76 kIConstC_GrBlendCoeff, //<! one minus constant color
40 kConstA_GrBlendCoeff, //<! constant color alpha 77 kConstA_GrBlendCoeff, //<! constant color alpha
41 kIConstA_GrBlendCoeff, //<! one minus constant color alpha 78 kIConstA_GrBlendCoeff, //<! one minus constant color alpha
42 kS2C_GrBlendCoeff, 79 kS2C_GrBlendCoeff,
43 kIS2C_GrBlendCoeff, 80 kIS2C_GrBlendCoeff,
44 kS2A_GrBlendCoeff, 81 kS2A_GrBlendCoeff,
45 kIS2A_GrBlendCoeff, 82 kIS2A_GrBlendCoeff,
46 83
47 kTotalGrBlendCoeffCount 84 kTotalGrBlendCoeffCount
48 }; 85 };
49 86
50 /** 87 /**
88 * Barriers for blending. When a shader reads the dst directly, an Xfer barrier is sometimes
89 * required after a pixel has been written, before it can be safely read again.
90 */
91 enum GrXferBarrierType {
92 kTexture_GrXferBarrierType, //<! Required when a shader reads and renders to the same texture.
93 kBlend_GrXferBarrierType, //<! Required by certain blend extensions.
94 };
95
96 /**
51 * 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
52 * 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
53 * 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
54 * 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
55 * 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
56 * 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
57 * 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
58 * and blend constant color. 104 * and blend constant color.
59 * 105 *
60 * A GrXferProcessor is never installed directly into our draw state, but instea d is created from a 106 * A GrXferProcessor is never installed directly into our draw state, but instea d is created from a
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 * overrideColor will be the required value that should be passed into the X P. 163 * overrideColor will be the required value that should be passed into the X P.
118 * A caller who calls this function on a XP is required to honor the returne d OptFlags 164 * A caller who calls this function on a XP is required to honor the returne d OptFlags
119 * and color values for its draw. 165 * and color values for its draw.
120 */ 166 */
121 virtual OptFlags getOptimizations(const GrProcOptInfo& colorPOI, 167 virtual OptFlags getOptimizations(const GrProcOptInfo& colorPOI,
122 const GrProcOptInfo& coveragePOI, 168 const GrProcOptInfo& coveragePOI,
123 bool doesStencilWrite, 169 bool doesStencilWrite,
124 GrColor* overrideColor, 170 GrColor* overrideColor,
125 const GrDrawTargetCaps& caps) = 0; 171 const GrDrawTargetCaps& caps) = 0;
126 172
173 /**
174 * Returns whether this XP will require an Xfer barrier on the given rt. If true, outBarrierType
175 * is updated to contain the type of barrier needed.
176 */
177 virtual bool willNeedXferBarrier(const GrRenderTarget* rt,
178 const GrDrawTargetCaps& caps,
179 GrXferBarrierType* outBarrierType) const;
180
127 struct BlendInfo { 181 struct BlendInfo {
128 GrBlendCoeff fSrcBlend; 182 GrBlendEquation fEquation;
129 GrBlendCoeff fDstBlend; 183 GrBlendCoeff fSrcBlend;
130 GrColor fBlendConstant; 184 GrBlendCoeff fDstBlend;
131 bool fWriteColor; 185 GrColor fBlendConstant;
186 bool fWriteColor;
132 }; 187 };
133 188
134 void getBlendInfo(BlendInfo* blendInfo) const { 189 void getBlendInfo(BlendInfo* blendInfo) const {
190 blendInfo->fEquation = kAdd_GrBlendEquation;
135 blendInfo->fSrcBlend = kOne_GrBlendCoeff; 191 blendInfo->fSrcBlend = kOne_GrBlendCoeff;
136 blendInfo->fDstBlend = kZero_GrBlendCoeff; 192 blendInfo->fDstBlend = kZero_GrBlendCoeff;
137 blendInfo->fBlendConstant = 0; 193 blendInfo->fBlendConstant = 0;
138 blendInfo->fWriteColor = true; 194 blendInfo->fWriteColor = true;
139 this->onGetBlendInfo(blendInfo); 195 this->onGetBlendInfo(blendInfo);
140 } 196 }
141 197
142 bool willReadDstColor() const { return fWillReadDstColor; } 198 bool willReadDstColor() const { return fWillReadDstColor; }
143 199
144 /** 200 /**
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 enum { 377 enum {
322 kIllegalXPFClassID = 0, 378 kIllegalXPFClassID = 0,
323 }; 379 };
324 static int32_t gCurrXPFClassID; 380 static int32_t gCurrXPFClassID;
325 381
326 typedef GrProgramElement INHERITED; 382 typedef GrProgramElement INHERITED;
327 }; 383 };
328 384
329 #endif 385 #endif
330 386
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698