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 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
869 * Gets whether the target is drawing clockwise, counterclockwise, | 869 * Gets whether the target is drawing clockwise, counterclockwise, |
870 * or both faces. | 870 * or both faces. |
871 * @return the current draw face(s). | 871 * @return the current draw face(s). |
872 */ | 872 */ |
873 DrawFace getDrawFace() const { return fDrawFace; } | 873 DrawFace getDrawFace() const { return fDrawFace; } |
874 | 874 |
875 /// @} | 875 /// @} |
876 | 876 |
877 /////////////////////////////////////////////////////////////////////////// | 877 /////////////////////////////////////////////////////////////////////////// |
878 | 878 |
879 bool operator ==(const GrDrawState& that) const { | 879 /** Return type for CombineIfPossible. */ |
880 if (fRenderTarget.get() != that.fRenderTarget.get() || | 880 enum CombinedState { |
881 fColorStages.count() != that.fColorStages.count() || | 881 /** The GrDrawStates cannot be combined. */ |
882 fCoverageStages.count() != that.fCoverageStages.count() || | 882 kIncompatible_CombinedState, |
883 fColor != that.fColor || | 883 /** Either draw state can be used in place of the other. */ |
884 !fViewMatrix.cheapEqualTo(that.fViewMatrix) || | 884 kAOrB_CombinedState, |
885 fSrcBlend != that.fSrcBlend || | 885 /** Use the first draw state. */ |
886 fDstBlend != that.fDstBlend || | 886 kA_CombinedState, |
887 fBlendConstant != that.fBlendConstant || | 887 /** Use the second draw state. */ |
888 fFlagBits != that.fFlagBits || | 888 kB_CombinedState, |
889 fVACount != that.fVACount || | 889 }; |
890 memcmp(fVAPtr, that.fVAPtr, fVACount * sizeof(GrVertexAttrib)) || | 890 |
robertphillips
2014/08/04 21:48:32
This function
bsalomon
2014/08/05 14:04:30
Done.
| |
891 fStencilSettings != that.fStencilSettings || | 891 /** This functions determines whether the GrDrawStates used for two draws ca n be combined into |
892 fCoverage != that.fCoverage || | 892 a single GrDrawState. This is used to avoid storing redundant GrDrawStat es and to determine |
robertphillips
2014/08/04 21:48:32
overlength by a char
bsalomon
2014/08/05 14:04:29
Done.
| |
893 fDrawFace != that.fDrawFace) { | 893 if draws can be batched. The return value indicates whether combining is possible and, if so, |
894 return false; | 894 which of the two inputs should be used. */ |
895 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta te& b) { | |
896 if (a.fRenderTarget.get() != b.fRenderTarget.get() || | |
897 a.fColorStages.count() != b.fColorStages.count() || | |
898 a.fCoverageStages.count() != b.fCoverageStages.count() || | |
899 a.fColor != b.fColor || | |
900 !a.fViewMatrix.cheapEqualTo(b.fViewMatrix) || | |
901 a.fSrcBlend != b.fSrcBlend || | |
902 a.fDstBlend != b.fDstBlend || | |
903 a.fBlendConstant != b.fBlendConstant || | |
904 a.fFlagBits != b.fFlagBits || | |
905 a.fVACount != b.fVACount || | |
906 memcmp(a.fVAPtr, b.fVAPtr, a.fVACount * sizeof(GrVertexAttrib)) || | |
907 a.fStencilSettings != b.fStencilSettings || | |
908 a.fCoverage != b.fCoverage || | |
909 a.fDrawFace != b.fDrawFace) { | |
910 return kIncompatible_CombinedState; | |
895 } | 911 } |
896 | 912 |
897 bool explicitLocalCoords = this->hasLocalCoordAttribute(); | 913 bool explicitLocalCoords = a.hasLocalCoordAttribute(); |
898 for (int i = 0; i < fColorStages.count(); i++) { | 914 for (int i = 0; i < a.fColorStages.count(); i++) { |
899 if (!GrEffectStage::AreCompatible(fColorStages[i], that.fColorStages [i], | 915 if (!GrEffectStage::AreCompatible(a.fColorStages[i], b.fColorStages[ i], |
900 explicitLocalCoords)) { | 916 explicitLocalCoords)) { |
901 return false; | 917 return kIncompatible_CombinedState; |
902 } | 918 } |
903 } | 919 } |
904 for (int i = 0; i < fCoverageStages.count(); i++) { | 920 for (int i = 0; i < a.fCoverageStages.count(); i++) { |
905 if (!GrEffectStage::AreCompatible(fCoverageStages[i], that.fCoverage Stages[i], | 921 if (!GrEffectStage::AreCompatible(a.fCoverageStages[i], b.fCoverageS tages[i], |
906 explicitLocalCoords)) { | 922 explicitLocalCoords)) { |
907 return false; | 923 return kIncompatible_CombinedState; |
908 } | 924 } |
909 } | 925 } |
910 SkASSERT(0 == memcmp(fFixedFunctionVertexAttribIndices, | 926 SkASSERT(0 == memcmp(a.fFixedFunctionVertexAttribIndices, |
911 that.fFixedFunctionVertexAttribIndices, | 927 b.fFixedFunctionVertexAttribIndices, |
912 sizeof(fFixedFunctionVertexAttribIndices))); | 928 sizeof(a.fFixedFunctionVertexAttribIndices))); |
913 return true; | 929 return kAOrB_CombinedState; |
914 } | 930 } |
915 bool operator !=(const GrDrawState& s) const { return !(*this == s); } | |
916 | 931 |
917 GrDrawState& operator= (const GrDrawState& that) { | 932 GrDrawState& operator= (const GrDrawState& that) { |
918 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 933 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
919 this->setRenderTarget(that.fRenderTarget.get()); | 934 this->setRenderTarget(that.fRenderTarget.get()); |
920 fColor = that.fColor; | 935 fColor = that.fColor; |
921 fViewMatrix = that.fViewMatrix; | 936 fViewMatrix = that.fViewMatrix; |
922 fSrcBlend = that.fSrcBlend; | 937 fSrcBlend = that.fSrcBlend; |
923 fDstBlend = that.fDstBlend; | 938 fDstBlend = that.fDstBlend; |
924 fBlendConstant = that.fBlendConstant; | 939 fBlendConstant = that.fBlendConstant; |
925 fFlagBits = that.fFlagBits; | 940 fFlagBits = that.fFlagBits; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1009 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt. | 1024 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt. |
1010 */ | 1025 */ |
1011 void setVertexAttribs(const GrVertexAttrib attribs[], int count); | 1026 void setVertexAttribs(const GrVertexAttrib attribs[], int count); |
1012 | 1027 |
1013 typedef SkRefCnt INHERITED; | 1028 typedef SkRefCnt INHERITED; |
1014 }; | 1029 }; |
1015 | 1030 |
1016 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | 1031 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); |
1017 | 1032 |
1018 #endif | 1033 #endif |
OLD | NEW |