OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 GrDrawState_DEFINED | 8 #ifndef GrDrawState_DEFINED |
9 #define GrDrawState_DEFINED | 9 #define GrDrawState_DEFINED |
10 | 10 |
11 | 11 |
12 #include "GrBlend.h" | 12 #include "GrBlend.h" |
13 #include "GrDrawTargetCaps.h" | 13 #include "GrDrawTargetCaps.h" |
14 #include "GrGeometryProcessor.h" | 14 #include "GrGeometryProcessor.h" |
15 #include "GrGpuResourceRef.h" | 15 #include "GrGpuResourceRef.h" |
16 #include "GrFragmentStage.h" | 16 #include "GrFragmentStage.h" |
17 #include "GrProcOptInfo.h" | 17 #include "GrProcOptInfo.h" |
18 #include "GrRenderTarget.h" | 18 #include "GrRenderTarget.h" |
19 #include "GrStencil.h" | 19 #include "GrStencil.h" |
20 #include "GrXferProcessor.h" | 20 #include "GrXferProcessor.h" |
21 #include "SkMatrix.h" | 21 #include "SkMatrix.h" |
| 22 #include "effects/GrCoverageSetOpXP.h" |
22 #include "effects/GrPorterDuffXferProcessor.h" | 23 #include "effects/GrPorterDuffXferProcessor.h" |
23 #include "effects/GrSimpleTextureEffect.h" | 24 #include "effects/GrSimpleTextureEffect.h" |
24 | 25 |
25 class GrDrawTargetCaps; | 26 class GrDrawTargetCaps; |
26 class GrPaint; | 27 class GrPaint; |
27 class GrTexture; | 28 class GrTexture; |
28 | 29 |
29 class GrDrawState { | 30 class GrDrawState { |
30 public: | 31 public: |
31 GrDrawState() { | 32 GrDrawState() { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 * the fragment shader. | 77 * the fragment shader. |
77 * | 78 * |
78 * This function considers the current draw state and the draw target's capa
bilities to | 79 * This function considers the current draw state and the draw target's capa
bilities to |
79 * determine whether coverage can be handled correctly. This function assume
s that the caller | 80 * determine whether coverage can be handled correctly. This function assume
s that the caller |
80 * intends to specify fractional pixel coverage via a primitive processor bu
t may not have | 81 * intends to specify fractional pixel coverage via a primitive processor bu
t may not have |
81 * specified it yet. | 82 * specified it yet. |
82 */ | 83 */ |
83 bool canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps)
const; | 84 bool canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps)
const; |
84 | 85 |
85 /** | 86 /** |
86 * Determines whether the output coverage is guaranteed to be one for all pi
xels hit by a draw. | |
87 */ | |
88 bool hasSolidCoverage(const GrPrimitiveProcessor*) const; | |
89 | |
90 /** | |
91 * This function returns true if the render target destination pixel values
will be read for | 87 * This function returns true if the render target destination pixel values
will be read for |
92 * blending during draw. | 88 * blending during draw. |
93 */ | 89 */ |
94 bool willBlendWithDst(const GrPrimitiveProcessor*) const; | 90 bool willBlendWithDst(const GrPrimitiveProcessor*) const; |
95 | 91 |
96 /////////////////////////////////////////////////////////////////////////// | 92 /////////////////////////////////////////////////////////////////////////// |
97 /// @name Effect Stages | 93 /// @name Effect Stages |
98 /// Each stage hosts a GrProcessor. The effect produces an output color or c
overage in the | 94 /// Each stage hosts a GrProcessor. The effect produces an output color or c
overage in the |
99 /// fragment shader. Its inputs are the output from the previous stage as we
ll as some variables | 95 /// fragment shader. Its inputs are the output from the previous stage as we
ll as some variables |
100 /// available to it in the fragment and vertex shader (e.g. the vertex posit
ion, the dst color, | 96 /// available to it in the fragment and vertex shader (e.g. the vertex posit
ion, the dst color, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 133 } |
138 | 134 |
139 void setPorterDuffXPFactory(SkXfermode::Mode mode) { | 135 void setPorterDuffXPFactory(SkXfermode::Mode mode) { |
140 fXPFactory.reset(GrPorterDuffXPFactory::Create(mode)); | 136 fXPFactory.reset(GrPorterDuffXPFactory::Create(mode)); |
141 } | 137 } |
142 | 138 |
143 void setPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst) { | 139 void setPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst) { |
144 fXPFactory.reset(GrPorterDuffXPFactory::Create(src, dst)); | 140 fXPFactory.reset(GrPorterDuffXPFactory::Create(src, dst)); |
145 } | 141 } |
146 | 142 |
| 143 void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage =
false) { |
| 144 fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCovera
ge)); |
| 145 } |
| 146 |
147 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe
ct) { | 147 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe
ct) { |
148 SkASSERT(effect); | 148 SkASSERT(effect); |
149 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); | 149 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); |
150 fColorProcInfoValid = false; | 150 fColorProcInfoValid = false; |
151 return effect; | 151 return effect; |
152 } | 152 } |
153 | 153 |
154 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e
ffect) { | 154 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e
ffect) { |
155 SkASSERT(effect); | 155 SkASSERT(effect); |
156 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); | 156 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 /** | 409 /** |
410 * Draws will respect the clip, otherwise the clip is ignored. | 410 * Draws will respect the clip, otherwise the clip is ignored. |
411 */ | 411 */ |
412 kClip_StateBit = 0x04, | 412 kClip_StateBit = 0x04, |
413 /** | 413 /** |
414 * Disables writing to the color buffer. Useful when performing stencil | 414 * Disables writing to the color buffer. Useful when performing stencil |
415 * operations. | 415 * operations. |
416 */ | 416 */ |
417 kNoColorWrites_StateBit = 0x08, | 417 kNoColorWrites_StateBit = 0x08, |
418 | 418 |
419 /** | 419 kLast_StateBit = kNoColorWrites_StateBit, |
420 * Usually coverage is applied after color blending. The color is blende
d using the coeffs | |
421 * specified by setBlendFunc(). The blended color is then combined with
dst using coeffs | |
422 * of src_coverage, 1-src_coverage. Sometimes we are explicitly drawing
a coverage mask. In | |
423 * this case there is no distinction between coverage and color and the
caller needs direct | |
424 * control over the blend coeffs. When set, there will be a single blend
step controlled by | |
425 * setBlendFunc() which will use coverage*color as the src color. | |
426 */ | |
427 kCoverageDrawing_StateBit = 0x10, | |
428 kLast_StateBit = kCoverageDrawing_StateBit, | |
429 }; | 420 }; |
430 | 421 |
431 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } | 422 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } |
432 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_
StateBit); } | 423 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_
StateBit); } |
433 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_S
tateBit); } | |
434 bool isDither() const { return 0 != (fFlagBits & kDither_StateBit); } | 424 bool isDither() const { return 0 != (fFlagBits & kDither_StateBit); } |
435 bool isHWAntialias() const { return 0 != (fFlagBits & kHWAntialias_StateBit)
; } | 425 bool isHWAntialias() const { return 0 != (fFlagBits & kHWAntialias_StateBit)
; } |
436 | 426 |
437 /** | 427 /** |
438 * Enable render state settings. | 428 * Enable render state settings. |
439 * | 429 * |
440 * @param stateBits bitfield of StateBits specifying the states to enable | 430 * @param stateBits bitfield of StateBits specifying the states to enable |
441 */ | 431 */ |
442 void enableState(uint32_t stateBits) { fFlagBits |= stateBits; } | 432 void enableState(uint32_t stateBits) { fFlagBits |= stateBits; } |
443 | 433 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 mutable bool fCoverageProcInfoValid; | 548 mutable bool fCoverageProcInfoValid; |
559 mutable GrColor fColorCache; | 549 mutable GrColor fColorCache; |
560 mutable GrColor fCoverageCache; | 550 mutable GrColor fCoverageCache; |
561 mutable const GrPrimitiveProcessor* fColorPrimProc; | 551 mutable const GrPrimitiveProcessor* fColorPrimProc; |
562 mutable const GrPrimitiveProcessor* fCoveragePrimProc; | 552 mutable const GrPrimitiveProcessor* fCoveragePrimProc; |
563 | 553 |
564 friend class GrOptDrawState; | 554 friend class GrOptDrawState; |
565 }; | 555 }; |
566 | 556 |
567 #endif | 557 #endif |
OLD | NEW |