| 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 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 } | 895 } |
| 896 fCommon.fSrcBlend = kOne_GrBlendCoeff; | 896 fCommon.fSrcBlend = kOne_GrBlendCoeff; |
| 897 fCommon.fDstBlend = kZero_GrBlendCoeff; | 897 fCommon.fDstBlend = kZero_GrBlendCoeff; |
| 898 fCommon.fBlendConstant = 0x0; | 898 fCommon.fBlendConstant = 0x0; |
| 899 fCommon.fFlagBits = 0x0; | 899 fCommon.fFlagBits = 0x0; |
| 900 fCommon.fStencilSettings.setDisabled(); | 900 fCommon.fStencilSettings.setDisabled(); |
| 901 fCommon.fCoverage = 0xffffffff; | 901 fCommon.fCoverage = 0xffffffff; |
| 902 fCommon.fDrawFace = kBoth_DrawFace; | 902 fCommon.fDrawFace = kBoth_DrawFace; |
| 903 } | 903 } |
| 904 | 904 |
| 905 /** Fields that are identical in GrDrawState and GrDrawState::DeferredState.
*/ | 905 /** This will be removed soon. The fields will become members of GrDrawState
. */ |
| 906 struct CommonState { | 906 struct CommonState { |
| 907 // These fields are roughly sorted by decreasing likelihood of being dif
ferent in op== | 907 // These fields are roughly sorted by decreasing likelihood of being dif
ferent in op== |
| 908 GrColor fColor; | 908 GrColor fColor; |
| 909 SkMatrix fViewMatrix; | 909 SkMatrix fViewMatrix; |
| 910 GrBlendCoeff fSrcBlend; | 910 GrBlendCoeff fSrcBlend; |
| 911 GrBlendCoeff fDstBlend; | 911 GrBlendCoeff fDstBlend; |
| 912 GrColor fBlendConstant; | 912 GrColor fBlendConstant; |
| 913 uint32_t fFlagBits; | 913 uint32_t fFlagBits; |
| 914 const GrVertexAttrib* fVAPtr; | 914 const GrVertexAttrib* fVAPtr; |
| 915 int fVACount; | 915 int fVACount; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 934 fCoverage == other.fCoverage && | 934 fCoverage == other.fCoverage && |
| 935 fDrawFace == other.fDrawFace; | 935 fDrawFace == other.fDrawFace; |
| 936 SkASSERT(!result || 0 == memcmp(fFixedFunctionVertexAttribIndices, | 936 SkASSERT(!result || 0 == memcmp(fFixedFunctionVertexAttribIndices, |
| 937 other.fFixedFunctionVertexAttribIndi
ces, | 937 other.fFixedFunctionVertexAttribIndi
ces, |
| 938 sizeof(fFixedFunctionVertexAttribInd
ices))); | 938 sizeof(fFixedFunctionVertexAttribInd
ices))); |
| 939 return result; | 939 return result; |
| 940 } | 940 } |
| 941 bool operator!= (const CommonState& other) const { return !(*this == oth
er); } | 941 bool operator!= (const CommonState& other) const { return !(*this == oth
er); } |
| 942 }; | 942 }; |
| 943 | 943 |
| 944 /** GrDrawState uses GrEffectStages to hold stage state which holds a ref on
GrEffectRef. | |
| 945 DeferredState must directly reference GrEffects, however. */ | |
| 946 struct SavedEffectStage { | |
| 947 SavedEffectStage() : fEffect(NULL) {} | |
| 948 const GrEffect* fEffect; | |
| 949 GrEffectStage::SavedCoordChange fCoordChange; | |
| 950 }; | |
| 951 | |
| 952 public: | |
| 953 /** | |
| 954 * DeferredState contains all of the data of a GrDrawState but does not hold
refs on GrResource | |
| 955 * objects. Resources are allowed to hit zero ref count while in DeferredSta
tes. Their internal | |
| 956 * dispose mechanism returns them to the cache. This allows recycling resour
ces through the | |
| 957 * the cache while they are in a deferred draw queue. | |
| 958 */ | |
| 959 class DeferredState { | |
| 960 public: | |
| 961 DeferredState() : fRenderTarget(NULL) { | |
| 962 SkDEBUGCODE(fInitialized = false;) | |
| 963 } | |
| 964 // TODO: Remove this when DeferredState no longer holds a ref to the RT | |
| 965 ~DeferredState() { SkSafeUnref(fRenderTarget); } | |
| 966 | |
| 967 void saveFrom(const GrDrawState& drawState) { | |
| 968 fCommon = drawState.fCommon; | |
| 969 // TODO: Here we will copy the GrRenderTarget pointer without taking
a ref. | |
| 970 fRenderTarget = drawState.fRenderTarget.get(); | |
| 971 SkSafeRef(fRenderTarget); | |
| 972 // Here we ref the effects directly rather than the effect-refs. TOD
O: When the effect- | |
| 973 // ref gets fully unref'ed it will cause the underlying effect to un
ref its resources | |
| 974 // and recycle them to the cache (if no one else is holding a ref to
the resources). | |
| 975 fStages.reset(drawState.fColorStages.count() + drawState.fCoverageSt
ages.count()); | |
| 976 fColorStageCnt = drawState.fColorStages.count(); | |
| 977 for (int i = 0; i < fColorStageCnt; ++i) { | |
| 978 fStages[i].saveFrom(drawState.fColorStages[i]); | |
| 979 } | |
| 980 for (int i = 0; i < drawState.fCoverageStages.count(); ++i) { | |
| 981 fStages[i + fColorStageCnt].saveFrom(drawState.fCoverageStages[i
]); | |
| 982 } | |
| 983 SkDEBUGCODE(fInitialized = true;) | |
| 984 } | |
| 985 | |
| 986 void restoreTo(GrDrawState* drawState) const { | |
| 987 SkASSERT(fInitialized); | |
| 988 drawState->fCommon = fCommon; | |
| 989 drawState->setRenderTarget(fRenderTarget); | |
| 990 // reinflate color/cov stage arrays. | |
| 991 drawState->fColorStages.reset(); | |
| 992 for (int i = 0; i < fColorStageCnt; ++i) { | |
| 993 SkNEW_APPEND_TO_TARRAY(&drawState->fColorStages, GrEffectStage,
(fStages[i])); | |
| 994 } | |
| 995 int coverageStageCnt = fStages.count() - fColorStageCnt; | |
| 996 drawState->fCoverageStages.reset(); | |
| 997 for (int i = 0; i < coverageStageCnt; ++i) { | |
| 998 SkNEW_APPEND_TO_TARRAY(&drawState->fCoverageStages, | |
| 999 GrEffectStage, (fStages[i + fColorStageC
nt])); | |
| 1000 } | |
| 1001 } | |
| 1002 | |
| 1003 bool isEqual(const GrDrawState& state) const { | |
| 1004 int numCoverageStages = fStages.count() - fColorStageCnt; | |
| 1005 if (fRenderTarget != state.fRenderTarget.get() || | |
| 1006 fColorStageCnt != state.fColorStages.count() || | |
| 1007 numCoverageStages != state.fCoverageStages.count() || | |
| 1008 fCommon != state.fCommon) { | |
| 1009 return false; | |
| 1010 } | |
| 1011 bool explicitLocalCoords = state.hasLocalCoordAttribute(); | |
| 1012 for (int i = 0; i < fColorStageCnt; ++i) { | |
| 1013 if (!fStages[i].isEqual(state.fColorStages[i], explicitLocalCoor
ds)) { | |
| 1014 return false; | |
| 1015 } | |
| 1016 } | |
| 1017 for (int i = 0; i < numCoverageStages; ++i) { | |
| 1018 int s = fColorStageCnt + i; | |
| 1019 if (!fStages[s].isEqual(state.fCoverageStages[i], explicitLocalC
oords)) { | |
| 1020 return false; | |
| 1021 } | |
| 1022 } | |
| 1023 return true; | |
| 1024 } | |
| 1025 | |
| 1026 private: | |
| 1027 typedef SkAutoSTArray<8, GrEffectStage::DeferredStage> DeferredStageArra
y; | |
| 1028 | |
| 1029 GrRenderTarget* fRenderTarget; | |
| 1030 CommonState fCommon; | |
| 1031 int fColorStageCnt; | |
| 1032 DeferredStageArray fStages; | |
| 1033 | |
| 1034 SkDEBUGCODE(bool fInitialized;) | |
| 1035 }; | |
| 1036 | |
| 1037 private: | |
| 1038 | |
| 1039 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 944 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 1040 CommonState fCommon; | 945 CommonState fCommon; |
| 1041 | 946 |
| 1042 typedef SkSTArray<4, GrEffectStage> EffectStageArray; | 947 typedef SkSTArray<4, GrEffectStage> EffectStageArray; |
| 1043 EffectStageArray fColorStages; | 948 EffectStageArray fColorStages; |
| 1044 EffectStageArray fCoverageStages; | 949 EffectStageArray fCoverageStages; |
| 1045 | 950 |
| 1046 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 951 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
| 1047 // This is used to assert that this condition holds. | 952 // This is used to assert that this condition holds. |
| 1048 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 953 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
| 1049 | 954 |
| 1050 /** | 955 /** |
| 1051 * Sets vertex attributes for next draw. | 956 * Sets vertex attributes for next draw. |
| 1052 * | 957 * |
| 1053 * @param attribs the array of vertex attributes to set. | 958 * @param attribs the array of vertex attributes to set. |
| 1054 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. | 959 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. |
| 1055 */ | 960 */ |
| 1056 void setVertexAttribs(const GrVertexAttrib attribs[], int count); | 961 void setVertexAttribs(const GrVertexAttrib attribs[], int count); |
| 1057 | 962 |
| 1058 typedef SkRefCnt INHERITED; | 963 typedef SkRefCnt INHERITED; |
| 1059 }; | 964 }; |
| 1060 | 965 |
| 1061 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | 966 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); |
| 1062 | 967 |
| 1063 #endif | 968 #endif |
| OLD | NEW |