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 "SkMatrix.h" | 20 #include "SkMatrix.h" |
21 #include "effects/GrSimpleTextureEffect.h" | 21 #include "effects/GrSimpleTextureEffect.h" |
22 | 22 |
23 class GrDrawTargetCaps; | 23 class GrDrawTargetCaps; |
24 class GrOptDrawState; | |
25 class GrPaint; | 24 class GrPaint; |
26 class GrTexture; | 25 class GrTexture; |
27 | 26 |
28 class GrDrawState { | 27 class GrDrawState { |
29 public: | 28 public: |
30 GrDrawState() { | 29 GrDrawState() { |
31 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 30 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
32 this->reset(); | 31 this->reset(); |
33 } | 32 } |
34 | 33 |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 * D' = sat(S*srcCoef + D*dstCoef) | 409 * D' = sat(S*srcCoef + D*dstCoef) |
411 * | 410 * |
412 * where D is the existing destination color, S is the incoming source | 411 * where D is the existing destination color, S is the incoming source |
413 * color, and D' is the new destination color that will be written. sat() | 412 * color, and D' is the new destination color that will be written. sat() |
414 * is the saturation function. | 413 * is the saturation function. |
415 * | 414 * |
416 * @param srcCoef coefficient applied to the src color. | 415 * @param srcCoef coefficient applied to the src color. |
417 * @param dstCoef coefficient applied to the dst color. | 416 * @param dstCoef coefficient applied to the dst color. |
418 */ | 417 */ |
419 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { | 418 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { |
420 if (srcCoeff != fSrcBlend || dstCoeff != fDstBlend) { | 419 fSrcBlend = srcCoeff; |
421 fSrcBlend = srcCoeff; | 420 fDstBlend = dstCoeff; |
422 fDstBlend = dstCoeff; | |
423 } | |
424 #ifdef SK_DEBUG | 421 #ifdef SK_DEBUG |
425 if (GrBlendCoeffRefsDst(dstCoeff)) { | 422 if (GrBlendCoeffRefsDst(dstCoeff)) { |
426 SkDebugf("Unexpected dst blend coeff. Won't work correctly with cove
rage stages.\n"); | 423 SkDebugf("Unexpected dst blend coeff. Won't work correctly with cove
rage stages.\n"); |
427 } | 424 } |
428 if (GrBlendCoeffRefsSrc(srcCoeff)) { | 425 if (GrBlendCoeffRefsSrc(srcCoeff)) { |
429 SkDebugf("Unexpected src blend coeff. Won't work correctly with cove
rage stages.\n"); | 426 SkDebugf("Unexpected src blend coeff. Won't work correctly with cove
rage stages.\n"); |
430 } | 427 } |
431 #endif | 428 #endif |
432 } | 429 } |
433 | 430 |
434 /** | 431 /** |
435 * Sets the blending function constant referenced by the following blending | 432 * Sets the blending function constant referenced by the following blending |
436 * coefficients: | 433 * coefficients: |
437 * kConstC_GrBlendCoeff | 434 * kConstC_GrBlendCoeff |
438 * kIConstC_GrBlendCoeff | 435 * kIConstC_GrBlendCoeff |
439 * kConstA_GrBlendCoeff | 436 * kConstA_GrBlendCoeff |
440 * kIConstA_GrBlendCoeff | 437 * kIConstA_GrBlendCoeff |
441 * | 438 * |
442 * @param constant the constant to set | 439 * @param constant the constant to set |
443 */ | 440 */ |
444 void setBlendConstant(GrColor constant) { | 441 void setBlendConstant(GrColor constant) { fBlendConstant = constant; } |
445 if (constant != fBlendConstant) { | |
446 fBlendConstant = constant; | |
447 } | |
448 } | |
449 | 442 |
450 /// @} | 443 /// @} |
451 | 444 |
452 /////////////////////////////////////////////////////////////////////////// | 445 /////////////////////////////////////////////////////////////////////////// |
453 /// @name View Matrix | 446 /// @name View Matrix |
454 //// | 447 //// |
455 | 448 |
456 /** | 449 /** |
457 * Retrieves the current view matrix | 450 * Retrieves the current view matrix |
458 * @return the current view matrix. | 451 * @return the current view matrix. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 | 543 |
551 const GrStencilSettings& getStencil() const { return fStencilSettings; } | 544 const GrStencilSettings& getStencil() const { return fStencilSettings; } |
552 | 545 |
553 /** | 546 /** |
554 * Sets the stencil settings to use for the next draw. | 547 * Sets the stencil settings to use for the next draw. |
555 * Changing the clip has the side-effect of possibly zeroing | 548 * Changing the clip has the side-effect of possibly zeroing |
556 * out the client settable stencil bits. So multipass algorithms | 549 * out the client settable stencil bits. So multipass algorithms |
557 * using stencil should not change the clip between passes. | 550 * using stencil should not change the clip between passes. |
558 * @param settings the stencil settings to use. | 551 * @param settings the stencil settings to use. |
559 */ | 552 */ |
560 void setStencil(const GrStencilSettings& settings) { | 553 void setStencil(const GrStencilSettings& settings) { fStencilSettings = sett
ings; } |
561 if (settings != fStencilSettings) { | |
562 fStencilSettings = settings; | |
563 } | |
564 } | |
565 | 554 |
566 /** | 555 /** |
567 * Shortcut to disable stencil testing and ops. | 556 * Shortcut to disable stencil testing and ops. |
568 */ | 557 */ |
569 void disableStencil() { | 558 void disableStencil() { fStencilSettings.setDisabled(); } |
570 if (!fStencilSettings.isDisabled()) { | |
571 fStencilSettings.setDisabled(); | |
572 } | |
573 } | |
574 | 559 |
575 GrStencilSettings* stencil() { return &fStencilSettings; } | 560 GrStencilSettings* stencil() { return &fStencilSettings; } |
576 | 561 |
577 /// @} | 562 /// @} |
578 | 563 |
579 /////////////////////////////////////////////////////////////////////////// | 564 /////////////////////////////////////////////////////////////////////////// |
580 /// @name State Flags | 565 /// @name State Flags |
581 //// | 566 //// |
582 | 567 |
583 /** | 568 /** |
(...skipping 26 matching lines...) Expand all Loading... |
610 * specified by setBlendFunc(). The blended color is then combined with
dst using coeffs | 595 * specified by setBlendFunc(). The blended color is then combined with
dst using coeffs |
611 * of src_coverage, 1-src_coverage. Sometimes we are explicitly drawing
a coverage mask. In | 596 * of src_coverage, 1-src_coverage. Sometimes we are explicitly drawing
a coverage mask. In |
612 * this case there is no distinction between coverage and color and the
caller needs direct | 597 * this case there is no distinction between coverage and color and the
caller needs direct |
613 * control over the blend coeffs. When set, there will be a single blend
step controlled by | 598 * control over the blend coeffs. When set, there will be a single blend
step controlled by |
614 * setBlendFunc() which will use coverage*color as the src color. | 599 * setBlendFunc() which will use coverage*color as the src color. |
615 */ | 600 */ |
616 kCoverageDrawing_StateBit = 0x10, | 601 kCoverageDrawing_StateBit = 0x10, |
617 kLast_StateBit = kCoverageDrawing_StateBit, | 602 kLast_StateBit = kCoverageDrawing_StateBit, |
618 }; | 603 }; |
619 | 604 |
620 uint32_t getFlagBits() const { return fFlagBits; } | |
621 | |
622 bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & f
FlagBits); } | |
623 | |
624 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } | 605 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } |
625 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_
StateBit); } | 606 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_
StateBit); } |
626 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_S
tateBit); } | 607 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_S
tateBit); } |
627 | 608 bool isDither() const { return 0 != (fFlagBits & kDither_StateBit); } |
628 void resetStateFlags() { | 609 bool isHWAntialias() const { return 0 != (fFlagBits & kHWAntialias_StateBit)
; } |
629 if (0 != fFlagBits) { | |
630 fFlagBits = 0; | |
631 } | |
632 } | |
633 | 610 |
634 /** | 611 /** |
635 * Enable render state settings. | 612 * Enable render state settings. |
636 * | 613 * |
637 * @param stateBits bitfield of StateBits specifying the states to enable | 614 * @param stateBits bitfield of StateBits specifying the states to enable |
638 */ | 615 */ |
639 void enableState(uint32_t stateBits) { | 616 void enableState(uint32_t stateBits) { fFlagBits |= stateBits; } |
640 if (stateBits & ~fFlagBits) { | |
641 fFlagBits |= stateBits; | |
642 } | |
643 } | |
644 | 617 |
645 /** | 618 /** |
646 * Disable render state settings. | 619 * Disable render state settings. |
647 * | 620 * |
648 * @param stateBits bitfield of StateBits specifying the states to disable | 621 * @param stateBits bitfield of StateBits specifying the states to disable |
649 */ | 622 */ |
650 void disableState(uint32_t stateBits) { | 623 void disableState(uint32_t stateBits) { fFlagBits &= ~(stateBits); } |
651 if (stateBits & fFlagBits) { | |
652 fFlagBits &= ~(stateBits); | |
653 } | |
654 } | |
655 | 624 |
656 /** | 625 /** |
657 * Enable or disable stateBits based on a boolean. | 626 * Enable or disable stateBits based on a boolean. |
658 * | 627 * |
659 * @param stateBits bitfield of StateBits to enable or disable | 628 * @param stateBits bitfield of StateBits to enable or disable |
660 * @param enable if true enable stateBits, otherwise disable | 629 * @param enable if true enable stateBits, otherwise disable |
661 */ | 630 */ |
662 void setState(uint32_t stateBits, bool enable) { | 631 void setState(uint32_t stateBits, bool enable) { |
663 if (enable) { | 632 if (enable) { |
664 this->enableState(stateBits); | 633 this->enableState(stateBits); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 /////////////////////////////////////////////////////////////////////////// | 687 /////////////////////////////////////////////////////////////////////////// |
719 | 688 |
720 GrDrawState& operator= (const GrDrawState& that); | 689 GrDrawState& operator= (const GrDrawState& that); |
721 | 690 |
722 private: | 691 private: |
723 bool isEqual(const GrDrawState& that) const; | 692 bool isEqual(const GrDrawState& that) const; |
724 | 693 |
725 /** | 694 /** |
726 * Optimizations for blending / coverage to that can be applied based on the
current state. | 695 * Optimizations for blending / coverage to that can be applied based on the
current state. |
727 */ | 696 */ |
728 enum BlendOptFlags { | 697 enum BlendOpt { |
729 /** | 698 /** |
730 * No optimization | 699 * No optimization |
731 */ | 700 */ |
732 kNone_BlendOpt = 0, | 701 kNone_BlendOpt, |
733 /** | 702 /** |
734 * Don't draw at all | 703 * Don't draw at all |
735 */ | 704 */ |
736 kSkipDraw_BlendOptFlag = 0x1, | 705 kSkipDraw_BlendOpt, |
737 /** | 706 /** |
738 * The coverage value does not have to be computed separately from alpha
, the the output | 707 * The coverage value does not have to be computed separately from alpha
, the the output |
739 * color can be the modulation of the two. | 708 * color can be the modulation of the two. |
740 */ | 709 */ |
741 kCoverageAsAlpha_BlendOptFlag = 0x2, | 710 kCoverageAsAlpha_BlendOpt, |
742 /** | 711 /** |
743 * Instead of emitting a src color, emit coverage in the alpha channel a
nd r,g,b are | 712 * Instead of emitting a src color, emit coverage in the alpha channel a
nd r,g,b are |
744 * "don't cares". | 713 * "don't cares". |
745 */ | 714 */ |
746 kEmitCoverage_BlendOptFlag = 0x4, | 715 kEmitCoverage_BlendOpt, |
747 /** | 716 /** |
748 * Emit transparent black instead of the src color, no need to compute c
overage. | 717 * Emit transparent black instead of the src color, no need to compute c
overage. |
749 */ | 718 */ |
750 kEmitTransBlack_BlendOptFlag = 0x8, | 719 kEmitTransBlack_BlendOpt |
751 }; | 720 }; |
752 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); | |
753 | 721 |
754 /** | 722 /** |
755 * Determines what optimizations can be applied based on the blend. The coef
ficients may have | 723 * Determines what optimizations can be applied based on the blend. The coef
ficients may have |
756 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef
f are optional | 724 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef
f are optional |
757 * params that receive the tweaked coefficients. Normally the function looks
at the current | 725 * params that receive the tweaked coefficients. Normally the function looks
at the current |
758 * state to see if coverage is enabled. By setting forceCoverage the caller
can speculatively | 726 * state to see if coverage is enabled. By setting forceCoverage the caller
can speculatively |
759 * determine the blend optimizations that would be used if there was partial
pixel coverage. | 727 * determine the blend optimizations that would be used if there was partial
pixel coverage. |
760 * | 728 * |
761 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j
ust buffer for | 729 * This is used internally and when constructing a GrOptDrawState. |
762 * playback) must call this function and respect the flags that replace the
output color. | |
763 * | |
764 * If the cached BlendOptFlags does not have the invalidate bit set, then ge
tBlendOpts will | |
765 * simply returned the cached flags and coefficients. Otherwise it will calc
ulate the values. | |
766 */ | 730 */ |
767 BlendOptFlags getBlendOpts(bool forceCoverage = false, | 731 BlendOpt getBlendOpt(bool forceCoverage = false, |
768 GrBlendCoeff* srcCoeff = NULL, | 732 GrBlendCoeff* srcCoeff = NULL, |
769 GrBlendCoeff* dstCoeff = NULL) const; | 733 GrBlendCoeff* dstCoeff = NULL) const; |
770 | 734 |
771 const GrProcOptInfo& colorProcInfo() const { | 735 const GrProcOptInfo& colorProcInfo() const { |
772 this->calcColorInvariantOutput(); | 736 this->calcColorInvariantOutput(); |
773 return fColorProcInfo; | 737 return fColorProcInfo; |
774 } | 738 } |
775 | 739 |
776 const GrProcOptInfo& coverageProcInfo() const { | 740 const GrProcOptInfo& coverageProcInfo() const { |
777 this->calcCoverageInvariantOutput(); | 741 this->calcCoverageInvariantOutput(); |
778 return fCoverageProcInfo; | 742 return fCoverageProcInfo; |
779 } | 743 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt
]; | 792 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt
]; |
829 | 793 |
830 mutable GrProcOptInfo fColorProcInfo; | 794 mutable GrProcOptInfo fColorProcInfo; |
831 mutable GrProcOptInfo fCoverageProcInfo; | 795 mutable GrProcOptInfo fCoverageProcInfo; |
832 mutable bool fColorProcInfoValid; | 796 mutable bool fColorProcInfoValid; |
833 mutable bool fCoverageProcInfoValid; | 797 mutable bool fCoverageProcInfoValid; |
834 | 798 |
835 friend class GrOptDrawState; | 799 friend class GrOptDrawState; |
836 }; | 800 }; |
837 | 801 |
838 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | |
839 | |
840 #endif | 802 #endif |
OLD | NEW |