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 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 * Barriers for blending. When a shader reads the dst directly, an Xfer barrier
is sometimes | 83 * Barriers for blending. When a shader reads the dst directly, an Xfer barrier
is sometimes |
84 * required after a pixel has been written, before it can be safely read again. | 84 * required after a pixel has been written, before it can be safely read again. |
85 */ | 85 */ |
86 enum GrXferBarrierType { | 86 enum GrXferBarrierType { |
87 kTexture_GrXferBarrierType, //<! Required when a shader reads and renders to
the same texture. | 87 kTexture_GrXferBarrierType, //<! Required when a shader reads and renders to
the same texture. |
88 kBlend_GrXferBarrierType, //<! Required by certain blend extensions. | 88 kBlend_GrXferBarrierType, //<! Required by certain blend extensions. |
89 }; | 89 }; |
90 | 90 |
91 /** | 91 /** |
92 * GrXferProcessor is responsible for implementing the xfer mode that blends the
src color and dst | 92 * GrXferProcessor is responsible for implementing the xfer mode that blends the
src color and dst |
93 * color. It does this by emitting fragment shader code and controlling the fixe
d-function blend | 93 * color, and for applying any coverage. It does this by emitting fragment shade
r code and |
94 * state. The inputs to its shader code are the final computed src color and fra
ctional pixel | 94 * controlling the fixed-function blend state. When dual-source blending is avai
lable, it may also |
95 * coverage. The GrXferProcessor's shader code writes the fragment shader output
color that goes | 95 * write a seconday fragment shader output color. GrXferProcessor has two modes
of operation: |
96 * into the fixed-function blend. When dual-source blending is available, it may
also write a | 96 * |
97 * seconday fragment shader output color. When allowed by the backend API, the G
rXferProcessor may | 97 * Dst read: When allowed by the backend API, or when supplied a texture of the
destination, the |
98 * read the destination color. The GrXferProcessor is responsible for setting th
e blend coefficients | 98 * GrXferProcessor may read the destination color. While operating in this mode,
the subclass only |
99 * and blend constant color. | 99 * provides shader code that blends the src and dst colors, and the base class a
pplies coverage. |
| 100 * |
| 101 * No dst read: When not performing a dst read, the subclass is given full contr
ol of the fixed- |
| 102 * function blend state and/or secondary output, and is responsible to apply cov
erage on its own. |
100 * | 103 * |
101 * A GrXferProcessor is never installed directly into our draw state, but instea
d is created from a | 104 * A GrXferProcessor is never installed directly into our draw state, but instea
d is created from a |
102 * GrXPFactory once we have finalized the state of our draw. | 105 * GrXPFactory once we have finalized the state of our draw. |
103 */ | 106 */ |
104 class GrXferProcessor : public GrProcessor { | 107 class GrXferProcessor : public GrProcessor { |
105 public: | 108 public: |
106 /** | 109 /** |
107 * A texture that contains the dst pixel values and an integer coord offset
from device space | 110 * A texture that contains the dst pixel values and an integer coord offset
from device space |
108 * to the space of the texture. Depending on GPU capabilities a DstTexture m
ay be used by a | 111 * to the space of the texture. Depending on GPU capabilities a DstTexture m
ay be used by a |
109 * GrXferProcessor for blending in the fragment shader. | 112 * GrXferProcessor for blending in the fragment shader. |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 224 |
222 SkDEBUGCODE(SkString dump() const;) | 225 SkDEBUGCODE(SkString dump() const;) |
223 | 226 |
224 GrBlendEquation fEquation; | 227 GrBlendEquation fEquation; |
225 GrBlendCoeff fSrcBlend; | 228 GrBlendCoeff fSrcBlend; |
226 GrBlendCoeff fDstBlend; | 229 GrBlendCoeff fDstBlend; |
227 GrColor fBlendConstant; | 230 GrColor fBlendConstant; |
228 bool fWriteColor; | 231 bool fWriteColor; |
229 }; | 232 }; |
230 | 233 |
231 void getBlendInfo(BlendInfo* blendInfo) const { | 234 void getBlendInfo(BlendInfo* blendInfo) const; |
232 blendInfo->reset(); | |
233 this->onGetBlendInfo(blendInfo); | |
234 } | |
235 | 235 |
236 bool willReadDstColor() const { return fWillReadDstColor; } | 236 bool willReadDstColor() const { return fWillReadDstColor; } |
237 | 237 |
238 /** | 238 /** |
239 * Returns the texture to be used as the destination when reading the dst in
the fragment | 239 * Returns the texture to be used as the destination when reading the dst in
the fragment |
240 * shader. If the returned texture is NULL then the XP is either not reading
the dst or we have | 240 * shader. If the returned texture is NULL then the XP is either not reading
the dst or we have |
241 * extentions that support framebuffer fetching and thus don't need a copy o
f the dst texture. | 241 * extentions that support framebuffer fetching and thus don't need a copy o
f the dst texture. |
242 */ | 242 */ |
243 const GrTexture* getDstTexture() const { return fDstTexture.getTexture(); } | 243 const GrTexture* getDstTexture() const { return fDstTexture.getTexture(); } |
244 | 244 |
245 /** | 245 /** |
246 * Returns the offset in device coords to use when accessing the dst texture
to get the dst | 246 * Returns the offset in device coords to use when accessing the dst texture
to get the dst |
247 * pixel color in the shader. This value is only valid if getDstTexture() !=
NULL. | 247 * pixel color in the shader. This value is only valid if getDstTexture() !=
NULL. |
248 */ | 248 */ |
249 const SkIPoint& dstTextureOffset() const { | 249 const SkIPoint& dstTextureOffset() const { |
250 SkASSERT(this->getDstTexture()); | 250 SkASSERT(this->getDstTexture()); |
251 return fDstTextureOffset; | 251 return fDstTextureOffset; |
252 } | 252 } |
253 | 253 |
254 /** | 254 /** |
255 * Returns whether or not the XP will look at coverage when doing its blendi
ng. | 255 * Returns whether or not the XP will look at coverage when doing its blendi
ng. |
256 */ | 256 */ |
257 bool readsCoverage() const { return fReadsCoverage; } | 257 bool readsCoverage() const { return fReadsCoverage; } |
258 | 258 |
259 /** | 259 /** |
260 * Returns whether or not this xferProcossor will set a secondary output to
be used with dual | 260 * Returns whether or not this xferProcossor will set a secondary output to
be used with dual |
261 * source blending. | 261 * source blending. |
262 */ | 262 */ |
263 virtual bool hasSecondaryOutput() const { return false; } | 263 bool hasSecondaryOutput() const; |
264 | 264 |
265 /** Returns true if this and other processor conservatively draw identically
. It can only return | 265 /** Returns true if this and other processor conservatively draw identically
. It can only return |
266 true when the two processor are of the same subclass (i.e. they return t
he same object from | 266 true when the two processor are of the same subclass (i.e. they return t
he same object from |
267 from getFactory()). | 267 from getFactory()). |
268 | 268 |
269 A return value of true from isEqual() should not be used to test whether
the processor would | 269 A return value of true from isEqual() should not be used to test whether
the processor would |
270 generate the same shader code. To test for identical code generation use
getGLProcessorKey*/ | 270 generate the same shader code. To test for identical code generation use
getGLProcessorKey*/ |
271 | 271 |
272 bool isEqual(const GrXferProcessor& that) const { | 272 bool isEqual(const GrXferProcessor& that) const { |
273 if (this->classID() != that.classID()) { | 273 if (this->classID() != that.classID()) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 * If not using a texture barrier, retrieves whether the subclass will requi
re a different type | 310 * If not using a texture barrier, retrieves whether the subclass will requi
re a different type |
311 * of barrier. | 311 * of barrier. |
312 */ | 312 */ |
313 virtual bool onWillNeedXferBarrier(const GrRenderTarget*, | 313 virtual bool onWillNeedXferBarrier(const GrRenderTarget*, |
314 const GrCaps&, | 314 const GrCaps&, |
315 GrXferBarrierType* outBarrierType SK_UNUS
ED) const { | 315 GrXferBarrierType* outBarrierType SK_UNUS
ED) const { |
316 return false; | 316 return false; |
317 } | 317 } |
318 | 318 |
319 /** | 319 /** |
320 * Retrieves the hardware blend state required by this Xfer processor. The B
lendInfo struct | 320 * If we are not performing a dst read, returns whether the subclass will se
t a secondary |
321 * comes initialized to default values, so the Xfer processor only needs to
set the state it | 321 * output. When using dst reads, the base class disables the secondary outpu
t and this method |
322 * needs. It may not even need to override this method at all. | 322 * will not be called. |
| 323 */ |
| 324 virtual bool onHasSecondaryOutput() const { return false; } |
| 325 |
| 326 /** |
| 327 * If we are not performing a dst read, retrieves the fixed-function blend s
tate required by the |
| 328 * subclass. When using dst reads, the base class disables fixed-function bl
ending and this |
| 329 * method will not be called. The BlendInfo struct comes initialized to "no
blending". |
323 */ | 330 */ |
324 virtual void onGetBlendInfo(BlendInfo*) const {} | 331 virtual void onGetBlendInfo(BlendInfo*) const {} |
325 | 332 |
326 virtual bool onIsEqual(const GrXferProcessor&) const = 0; | 333 virtual bool onIsEqual(const GrXferProcessor&) const = 0; |
327 | 334 |
328 bool fWillReadDstColor; | 335 bool fWillReadDstColor; |
329 bool fReadsCoverage; | 336 bool fReadsCoverage; |
330 SkIPoint fDstTextureOffset; | 337 SkIPoint fDstTextureOffset; |
331 GrTextureAccess fDstTexture; | 338 GrTextureAccess fDstTexture; |
332 | 339 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 enum { | 445 enum { |
439 kIllegalXPFClassID = 0, | 446 kIllegalXPFClassID = 0, |
440 }; | 447 }; |
441 static int32_t gCurrXPFClassID; | 448 static int32_t gCurrXPFClassID; |
442 | 449 |
443 typedef GrProgramElement INHERITED; | 450 typedef GrProgramElement INHERITED; |
444 }; | 451 }; |
445 | 452 |
446 #endif | 453 #endif |
447 | 454 |
OLD | NEW |