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 |
(...skipping 667 matching lines...) Loading... | |
678 } | 678 } |
679 return true; | 679 return true; |
680 } | 680 } |
681 return false; | 681 return false; |
682 } | 682 } |
683 | 683 |
684 //////////////////////////////////////////////////////////////////////////// | 684 //////////////////////////////////////////////////////////////////////////// |
685 | 685 |
686 /** | 686 /** |
687 * Preconcats the current view matrix and restores the previous view matrix in the destructor. | 687 * Preconcats the current view matrix and restores the previous view matrix in the destructor. |
688 * Effect matrices are automatically adjusted to compensate. | 688 * Effect matrices are automatically adjusted to compensate and adjusted bac k in the destructor. |
689 */ | 689 */ |
690 class AutoViewMatrixRestore : public ::GrNoncopyable { | 690 class AutoViewMatrixRestore : public ::GrNoncopyable { |
691 public: | 691 public: |
692 AutoViewMatrixRestore() : fDrawState(NULL) {} | 692 AutoViewMatrixRestore() : fDrawState(NULL) {} |
693 | 693 |
694 AutoViewMatrixRestore(GrDrawState* ds, const SkMatrix& preconcatMatrix) { | 694 AutoViewMatrixRestore(GrDrawState* ds, const SkMatrix& preconcatMatrix) { |
695 fDrawState = NULL; | 695 fDrawState = NULL; |
696 this->set(ds, preconcatMatrix); | 696 this->set(ds, preconcatMatrix); |
697 } | 697 } |
698 | 698 |
699 ~AutoViewMatrixRestore() { this->restore(); } | 699 ~AutoViewMatrixRestore() { this->restore(); } |
700 | 700 |
701 /** | 701 /** |
702 * Can be called prior to destructor to restore the original matrix. | 702 * Can be called prior to destructor to restore the original matrix. |
703 */ | 703 */ |
704 void restore(); | 704 void restore(); |
705 | 705 |
706 void set(GrDrawState* drawState, const SkMatrix& preconcatMatrix); | 706 void set(GrDrawState* drawState, const SkMatrix& preconcatMatrix); |
707 | 707 |
708 bool isSet() const { return NULL != fDrawState; } | 708 /** Sets the draw state's matrix to identity. This can fail because the current view matrix |
709 is not invertible. */ | |
710 bool setIdentity(GrDrawState* drawState); | |
711 | |
robertphillips
2013/05/22 23:47:01
delete this?
| |
712 //bool isSet() const { return NULL != fDrawState; } | |
709 | 713 |
710 private: | 714 private: |
711 GrDrawState* fDrawState; | 715 GrDrawState* fDrawState; |
712 SkMatrix fViewMatrix; | |
713 GrEffectStage::SavedCoordChange fSavedCoordChanges[GrDrawState::kNum Stages]; | |
714 uint32_t fRestoreMask; | |
715 }; | |
716 | |
717 //////////////////////////////////////////////////////////////////////////// | |
718 | |
719 /** | |
720 * This sets the view matrix to identity and adjusts stage matrices to compe nsate. The | |
721 * destructor undoes the changes, restoring the view matrix that was set bef ore the | |
722 * constructor. It is similar to passing the inverse of the current view mat rix to | |
723 * AutoViewMatrixRestore, but lazily computes the inverse only if necessary. | |
724 */ | |
725 class AutoDeviceCoordDraw : ::GrNoncopyable { | |
726 public: | |
727 AutoDeviceCoordDraw() : fDrawState(NULL) {} | |
728 /** | |
729 * If a stage's texture matrix is applied to explicit per-vertex coords, rather than to | |
730 * positions, then we don't want to modify its matrix. The explicitCoord StageMask is used | |
731 * to specify such stages. | |
732 */ | |
733 AutoDeviceCoordDraw(GrDrawState* drawState) { | |
734 fDrawState = NULL; | |
735 this->set(drawState); | |
736 } | |
737 | |
738 ~AutoDeviceCoordDraw() { this->restore(); } | |
739 | |
740 bool set(GrDrawState* drawState); | |
741 | |
742 /** | |
743 * Returns true if this object was successfully initialized on to a GrDr awState. It may | |
744 * return false because a non-default constructor or set() were never ca lled or because | |
745 * the view matrix was not invertible. | |
746 */ | |
747 bool succeeded() const { return NULL != fDrawState; } | |
748 | |
749 /** | |
750 * Returns the matrix that was set previously set on the drawState. This is only valid | |
751 * if succeeded returns true. | |
752 */ | |
753 const SkMatrix& getOriginalMatrix() const { | |
754 GrAssert(this->succeeded()); | |
755 return fViewMatrix; | |
756 } | |
757 | |
758 /** | |
759 * Can be called prior to destructor to restore the original matrix. | |
760 */ | |
761 void restore(); | |
762 | |
763 private: | |
764 GrDrawState* fDrawState; | |
765 SkMatrix fViewMatrix; | 716 SkMatrix fViewMatrix; |
766 GrEffectStage::SavedCoordChange fSavedCoordChanges[GrDrawState::kNum Stages]; | 717 GrEffectStage::SavedCoordChange fSavedCoordChanges[GrDrawState::kNum Stages]; |
767 uint32_t fRestoreMask; | 718 uint32_t fRestoreMask; |
768 }; | 719 }; |
769 | 720 |
770 /// @} | 721 /// @} |
771 | 722 |
772 /////////////////////////////////////////////////////////////////////////// | 723 /////////////////////////////////////////////////////////////////////////// |
773 /// @name Render Target | 724 /// @name Render Target |
774 //// | 725 //// |
(...skipping 376 matching lines...) Loading... | |
1151 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt. | 1102 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt. |
1152 */ | 1103 */ |
1153 void setVertexAttribs(const GrVertexAttrib attribs[], int count); | 1104 void setVertexAttribs(const GrVertexAttrib attribs[], int count); |
1154 | 1105 |
1155 typedef GrRefCnt INHERITED; | 1106 typedef GrRefCnt INHERITED; |
1156 }; | 1107 }; |
1157 | 1108 |
1158 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | 1109 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); |
1159 | 1110 |
1160 #endif | 1111 #endif |
OLD | NEW |