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 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 /////////////////////////////////////////////////////////////////////////// | 625 /////////////////////////////////////////////////////////////////////////// |
626 /// @name Render Target | 626 /// @name Render Target |
627 //// | 627 //// |
628 | 628 |
629 /** | 629 /** |
630 * Sets the render-target used at the next drawing call | 630 * Sets the render-target used at the next drawing call |
631 * | 631 * |
632 * @param target The render target to set. | 632 * @param target The render target to set. |
633 */ | 633 */ |
634 void setRenderTarget(GrRenderTarget* target) { | 634 void setRenderTarget(GrRenderTarget* target) { |
635 fRenderTarget.reset(SkSafeRef(target)); | 635 //SkDebugf("GrDrawState::setRenderTarget\n"); |
| 636 fRenderTarget1.reset(SkSafeRef(target)); |
636 } | 637 } |
637 | 638 |
638 /** | 639 /** |
639 * Retrieves the currently set render-target. | 640 * Retrieves the currently set render-target. |
640 * | 641 * |
641 * @return The currently set render target. | 642 * @return The currently set render target. |
642 */ | 643 */ |
643 const GrRenderTarget* getRenderTarget() const { return fRenderTarget.get();
} | 644 const GrRenderTarget* getRenderTarget() const { return fRenderTarget1.get();
} |
644 GrRenderTarget* getRenderTarget() { return fRenderTarget.get(); } | 645 GrRenderTarget* getRenderTarget() { return fRenderTarget1.get(); } |
645 | 646 |
646 class AutoRenderTargetRestore : public ::SkNoncopyable { | 647 class AutoRenderTargetRestore : public ::SkNoncopyable { |
647 public: | 648 public: |
648 AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {} | 649 AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {} |
649 AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) { | 650 AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) { |
650 fDrawState = NULL; | 651 fDrawState = NULL; |
651 fSavedTarget = NULL; | 652 fSavedTarget = NULL; |
652 this->set(ds, newTarget); | 653 this->set(ds, newTarget); |
653 } | 654 } |
654 ~AutoRenderTargetRestore() { this->restore(); } | 655 ~AutoRenderTargetRestore() { this->restore(); } |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 * or both faces. | 840 * or both faces. |
840 * @return the current draw face(s). | 841 * @return the current draw face(s). |
841 */ | 842 */ |
842 DrawFace getDrawFace() const { return fCommon.fDrawFace; } | 843 DrawFace getDrawFace() const { return fCommon.fDrawFace; } |
843 | 844 |
844 /// @} | 845 /// @} |
845 | 846 |
846 /////////////////////////////////////////////////////////////////////////// | 847 /////////////////////////////////////////////////////////////////////////// |
847 | 848 |
848 bool operator ==(const GrDrawState& s) const { | 849 bool operator ==(const GrDrawState& s) const { |
849 if (fRenderTarget.get() != s.fRenderTarget.get() || | 850 if (fRenderTarget1.get() != s.fRenderTarget1.get() || |
850 fColorStages.count() != s.fColorStages.count() || | 851 fColorStages.count() != s.fColorStages.count() || |
851 fCoverageStages.count() != s.fCoverageStages.count() || | 852 fCoverageStages.count() != s.fCoverageStages.count() || |
852 fCommon != s.fCommon) { | 853 fCommon != s.fCommon) { |
853 return false; | 854 return false; |
854 } | 855 } |
855 for (int i = 0; i < fColorStages.count(); i++) { | 856 for (int i = 0; i < fColorStages.count(); i++) { |
856 if (fColorStages[i] != s.fColorStages[i]) { | 857 if (fColorStages[i] != s.fColorStages[i]) { |
857 return false; | 858 return false; |
858 } | 859 } |
859 } | 860 } |
860 for (int i = 0; i < fCoverageStages.count(); i++) { | 861 for (int i = 0; i < fCoverageStages.count(); i++) { |
861 if (fCoverageStages[i] != s.fCoverageStages[i]) { | 862 if (fCoverageStages[i] != s.fCoverageStages[i]) { |
862 return false; | 863 return false; |
863 } | 864 } |
864 } | 865 } |
865 return true; | 866 return true; |
866 } | 867 } |
867 bool operator !=(const GrDrawState& s) const { return !(*this == s); } | 868 bool operator !=(const GrDrawState& s) const { return !(*this == s); } |
868 | 869 |
869 GrDrawState& operator= (const GrDrawState& s) { | 870 GrDrawState& operator= (const GrDrawState& s) { |
870 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 871 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
871 this->setRenderTarget(s.fRenderTarget.get()); | 872 this->setRenderTarget(s.fRenderTarget1.get()); |
872 fCommon = s.fCommon; | 873 fCommon = s.fCommon; |
873 fColorStages = s.fColorStages; | 874 fColorStages = s.fColorStages; |
874 fCoverageStages = s.fCoverageStages; | 875 fCoverageStages = s.fCoverageStages; |
875 return *this; | 876 return *this; |
876 } | 877 } |
877 | 878 |
878 private: | 879 private: |
879 | 880 |
880 void onReset(const SkMatrix* initialViewMatrix) { | 881 void onReset(const SkMatrix* initialViewMatrix) { |
881 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 882 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
882 fColorStages.reset(); | 883 fColorStages.reset(); |
883 fCoverageStages.reset(); | 884 fCoverageStages.reset(); |
884 | 885 |
885 fRenderTarget.reset(NULL); | 886 fRenderTarget1.reset(NULL); |
886 | 887 |
887 this->setDefaultVertexAttribs(); | 888 this->setDefaultVertexAttribs(); |
888 | 889 |
889 fCommon.fColor = 0xffffffff; | 890 fCommon.fColor = 0xffffffff; |
890 if (NULL == initialViewMatrix) { | 891 if (NULL == initialViewMatrix) { |
891 fCommon.fViewMatrix.reset(); | 892 fCommon.fViewMatrix.reset(); |
892 } else { | 893 } else { |
893 fCommon.fViewMatrix = *initialViewMatrix; | 894 fCommon.fViewMatrix = *initialViewMatrix; |
894 } | 895 } |
895 fCommon.fSrcBlend = kOne_GrBlendCoeff; | 896 fCommon.fSrcBlend = kOne_GrBlendCoeff; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 | 951 |
951 public: | 952 public: |
952 /** | 953 /** |
953 * DeferredState contains all of the data of a GrDrawState but does not hold
refs on GrResource | 954 * DeferredState contains all of the data of a GrDrawState but does not hold
refs on GrResource |
954 * objects. Resources are allowed to hit zero ref count while in DeferredSta
tes. Their internal | 955 * objects. Resources are allowed to hit zero ref count while in DeferredSta
tes. Their internal |
955 * dispose mechanism returns them to the cache. This allows recycling resour
ces through the | 956 * dispose mechanism returns them to the cache. This allows recycling resour
ces through the |
956 * the cache while they are in a deferred draw queue. | 957 * the cache while they are in a deferred draw queue. |
957 */ | 958 */ |
958 class DeferredState { | 959 class DeferredState { |
959 public: | 960 public: |
960 DeferredState() : fRenderTarget(NULL) { | 961 DeferredState() : fRenderTarget1(NULL) { |
961 SkDEBUGCODE(fInitialized = false;) | 962 SkDEBUGCODE(fInitialized = false;) |
962 } | 963 } |
963 // TODO: Remove this when DeferredState no longer holds a ref to the RT | 964 // TODO: Remove this when DeferredState no longer holds a ref to the RT |
964 ~DeferredState() { SkSafeUnref(fRenderTarget); } | 965 ~DeferredState() { SkSafeUnref(fRenderTarget1); } |
965 | 966 |
966 void saveFrom(const GrDrawState& drawState) { | 967 void saveFrom(const GrDrawState& drawState) { |
967 fCommon = drawState.fCommon; | 968 fCommon = drawState.fCommon; |
968 // TODO: Here we will copy the GrRenderTarget pointer without taking
a ref. | 969 // TODO: Here we will copy the GrRenderTarget pointer without taking
a ref. |
969 fRenderTarget = drawState.fRenderTarget.get(); | 970 // SkDebugf("DeferredState::render target change\n"); |
970 SkSafeRef(fRenderTarget); | 971 fRenderTarget1 = drawState.fRenderTarget1.get(); |
| 972 SkSafeRef(fRenderTarget1); |
971 // Here we ref the effects directly rather than the effect-refs. TOD
O: When the effect- | 973 // Here we ref the effects directly rather than the effect-refs. TOD
O: When the effect- |
972 // ref gets fully unref'ed it will cause the underlying effect to un
ref its resources | 974 // ref gets fully unref'ed it will cause the underlying effect to un
ref its resources |
973 // and recycle them to the cache (if no one else is holding a ref to
the resources). | 975 // and recycle them to the cache (if no one else is holding a ref to
the resources). |
974 fStages.reset(drawState.fColorStages.count() + drawState.fCoverageSt
ages.count()); | 976 fStages.reset(drawState.fColorStages.count() + drawState.fCoverageSt
ages.count()); |
975 fColorStageCnt = drawState.fColorStages.count(); | 977 fColorStageCnt = drawState.fColorStages.count(); |
976 for (int i = 0; i < fColorStageCnt; ++i) { | 978 for (int i = 0; i < fColorStageCnt; ++i) { |
977 fStages[i].saveFrom(drawState.fColorStages[i]); | 979 fStages[i].saveFrom(drawState.fColorStages[i]); |
978 } | 980 } |
979 for (int i = 0; i < drawState.fCoverageStages.count(); ++i) { | 981 for (int i = 0; i < drawState.fCoverageStages.count(); ++i) { |
980 fStages[i + fColorStageCnt].saveFrom(drawState.fCoverageStages[i
]); | 982 fStages[i + fColorStageCnt].saveFrom(drawState.fCoverageStages[i
]); |
981 } | 983 } |
982 SkDEBUGCODE(fInitialized = true;) | 984 SkDEBUGCODE(fInitialized = true;) |
983 } | 985 } |
984 | 986 |
985 void restoreTo(GrDrawState* drawState) { | 987 void restoreTo(GrDrawState* drawState) { |
986 SkASSERT(fInitialized); | 988 SkASSERT(fInitialized); |
987 drawState->fCommon = fCommon; | 989 drawState->fCommon = fCommon; |
988 drawState->setRenderTarget(fRenderTarget); | 990 drawState->setRenderTarget(fRenderTarget1); |
989 // reinflate color/cov stage arrays. | 991 // reinflate color/cov stage arrays. |
990 drawState->fColorStages.reset(); | 992 drawState->fColorStages.reset(); |
991 for (int i = 0; i < fColorStageCnt; ++i) { | 993 for (int i = 0; i < fColorStageCnt; ++i) { |
992 SkNEW_APPEND_TO_TARRAY(&drawState->fColorStages, GrEffectStage,
(fStages[i])); | 994 SkNEW_APPEND_TO_TARRAY(&drawState->fColorStages, GrEffectStage,
(fStages[i])); |
993 } | 995 } |
994 int coverageStageCnt = fStages.count() - fColorStageCnt; | 996 int coverageStageCnt = fStages.count() - fColorStageCnt; |
995 drawState->fCoverageStages.reset(); | 997 drawState->fCoverageStages.reset(); |
996 for (int i = 0; i < coverageStageCnt; ++i) { | 998 for (int i = 0; i < coverageStageCnt; ++i) { |
997 SkNEW_APPEND_TO_TARRAY(&drawState->fCoverageStages, | 999 SkNEW_APPEND_TO_TARRAY(&drawState->fCoverageStages, |
998 GrEffectStage, (fStages[i + fColorStageC
nt])); | 1000 GrEffectStage, (fStages[i + fColorStageC
nt])); |
999 } | 1001 } |
1000 } | 1002 } |
1001 | 1003 |
1002 bool isEqual(const GrDrawState& state) const { | 1004 bool isEqual(const GrDrawState& state) const { |
1003 int numCoverageStages = fStages.count() - fColorStageCnt; | 1005 int numCoverageStages = fStages.count() - fColorStageCnt; |
1004 if (fRenderTarget != state.fRenderTarget.get() || | 1006 if (fRenderTarget1 != state.fRenderTarget1.get() || |
1005 fColorStageCnt != state.fColorStages.count() || | 1007 fColorStageCnt != state.fColorStages.count() || |
1006 numCoverageStages != state.fCoverageStages.count() || | 1008 numCoverageStages != state.fCoverageStages.count() || |
1007 fCommon != state.fCommon) { | 1009 fCommon != state.fCommon) { |
1008 return false; | 1010 return false; |
1009 } | 1011 } |
1010 bool explicitLocalCoords = state.hasLocalCoordAttribute(); | 1012 bool explicitLocalCoords = state.hasLocalCoordAttribute(); |
1011 for (int i = 0; i < fColorStageCnt; ++i) { | 1013 for (int i = 0; i < fColorStageCnt; ++i) { |
1012 if (!fStages[i].isEqual(state.fColorStages[i], explicitLocalCoor
ds)) { | 1014 if (!fStages[i].isEqual(state.fColorStages[i], explicitLocalCoor
ds)) { |
1013 return false; | 1015 return false; |
1014 } | 1016 } |
1015 } | 1017 } |
1016 for (int i = 0; i < numCoverageStages; ++i) { | 1018 for (int i = 0; i < numCoverageStages; ++i) { |
1017 int s = fColorStageCnt + i; | 1019 int s = fColorStageCnt + i; |
1018 if (!fStages[s].isEqual(state.fCoverageStages[i], explicitLocalC
oords)) { | 1020 if (!fStages[s].isEqual(state.fCoverageStages[i], explicitLocalC
oords)) { |
1019 return false; | 1021 return false; |
1020 } | 1022 } |
1021 } | 1023 } |
1022 return true; | 1024 return true; |
1023 } | 1025 } |
1024 | 1026 |
1025 private: | 1027 private: |
1026 typedef SkAutoSTArray<8, GrEffectStage::DeferredStage> DeferredStageArra
y; | 1028 typedef SkAutoSTArray<8, GrEffectStage::DeferredStage> DeferredStageArra
y; |
1027 | 1029 |
1028 GrRenderTarget* fRenderTarget; | 1030 GrRenderTarget* fRenderTarget1; |
1029 CommonState fCommon; | 1031 CommonState fCommon; |
1030 int fColorStageCnt; | 1032 int fColorStageCnt; |
1031 DeferredStageArray fStages; | 1033 DeferredStageArray fStages; |
1032 | 1034 |
1033 SkDEBUGCODE(bool fInitialized;) | 1035 SkDEBUGCODE(bool fInitialized;) |
1034 }; | 1036 }; |
1035 | 1037 |
1036 private: | 1038 private: |
1037 | 1039 |
1038 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 1040 SkAutoTUnref<GrRenderTarget> fRenderTarget1; |
1039 CommonState fCommon; | 1041 CommonState fCommon; |
1040 | 1042 |
1041 typedef SkSTArray<4, GrEffectStage> EffectStageArray; | 1043 typedef SkSTArray<4, GrEffectStage> EffectStageArray; |
1042 EffectStageArray fColorStages; | 1044 EffectStageArray fColorStages; |
1043 EffectStageArray fCoverageStages; | 1045 EffectStageArray fCoverageStages; |
1044 | 1046 |
1045 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 1047 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
1046 // This is used to assert that this condition holds. | 1048 // This is used to assert that this condition holds. |
1047 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 1049 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
1048 | 1050 |
1049 /** | 1051 /** |
1050 * Sets vertex attributes for next draw. | 1052 * Sets vertex attributes for next draw. |
1051 * | 1053 * |
1052 * @param attribs the array of vertex attributes to set. | 1054 * @param attribs the array of vertex attributes to set. |
1053 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. | 1055 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. |
1054 */ | 1056 */ |
1055 void setVertexAttribs(const GrVertexAttrib attribs[], int count); | 1057 void setVertexAttribs(const GrVertexAttrib attribs[], int count); |
1056 | 1058 |
1057 typedef SkRefCnt INHERITED; | 1059 typedef SkRefCnt INHERITED; |
1058 }; | 1060 }; |
1059 | 1061 |
1060 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | 1062 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); |
1061 | 1063 |
1062 #endif | 1064 #endif |
OLD | NEW |