Chromium Code Reviews| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 * Copies another draw state. | 42 * Copies another draw state. |
| 43 **/ | 43 **/ |
| 44 GrDrawState(const GrDrawState& state) : INHERITED() { | 44 GrDrawState(const GrDrawState& state) : INHERITED() { |
| 45 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 45 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
| 46 *this = state; | 46 *this = state; |
| 47 } | 47 } |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * Copies another draw state with a preconcat to the view matrix. | 50 * Copies another draw state with a preconcat to the view matrix. |
| 51 **/ | 51 **/ |
| 52 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix) { | 52 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix); |
| 53 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | |
| 54 *this = state; | |
| 55 if (!preConcatMatrix.isIdentity()) { | |
| 56 for (int i = 0; i < fColorStages.count(); ++i) { | |
| 57 fColorStages[i].localCoordChange(preConcatMatrix); | |
| 58 } | |
| 59 for (int i = 0; i < fCoverageStages.count(); ++i) { | |
| 60 fCoverageStages[i].localCoordChange(preConcatMatrix); | |
| 61 } | |
| 62 this->invalidateBlendOptFlags(); | |
| 63 } | |
| 64 } | |
| 65 | 53 |
| 66 virtual ~GrDrawState() { SkASSERT(0 == fBlockEffectRemovalCnt); } | 54 virtual ~GrDrawState() { SkASSERT(0 == fBlockEffectRemovalCnt); } |
| 67 | 55 |
| 68 /** | 56 /** |
| 69 * Resets to the default state. GrEffects will be removed from all stages. | 57 * Resets to the default state. GrEffects will be removed from all stages. |
| 70 */ | 58 */ |
| 71 void reset() { this->onReset(NULL); } | 59 void reset() { this->onReset(NULL); } |
| 72 | 60 |
| 73 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa trix); } | 61 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa trix); } |
| 74 | 62 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 return -1 != fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribB inding]; | 132 return -1 != fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribB inding]; |
| 145 } | 133 } |
| 146 | 134 |
| 147 bool validateVertexAttribs() const; | 135 bool validateVertexAttribs() const; |
| 148 | 136 |
| 149 /** | 137 /** |
| 150 * Helper to save/restore vertex attribs | 138 * Helper to save/restore vertex attribs |
| 151 */ | 139 */ |
| 152 class AutoVertexAttribRestore { | 140 class AutoVertexAttribRestore { |
| 153 public: | 141 public: |
| 154 AutoVertexAttribRestore(GrDrawState* drawState) { | 142 AutoVertexAttribRestore(GrDrawState* drawState); |
| 155 SkASSERT(NULL != drawState); | |
| 156 fDrawState = drawState; | |
| 157 fVAPtr = drawState->fVAPtr; | |
| 158 fVACount = drawState->fVACount; | |
| 159 fDrawState->setDefaultVertexAttribs(); | |
| 160 } | |
| 161 | 143 |
| 162 ~AutoVertexAttribRestore(){ | 144 ~AutoVertexAttribRestore() { fDrawState->setVertexAttribs(fVAPtr, fVACo unt); } |
| 163 fDrawState->setVertexAttribs(fVAPtr, fVACount); | |
| 164 } | |
| 165 | 145 |
| 166 private: | 146 private: |
| 167 GrDrawState* fDrawState; | 147 GrDrawState* fDrawState; |
| 168 const GrVertexAttrib* fVAPtr; | 148 const GrVertexAttrib* fVAPtr; |
| 169 int fVACount; | 149 int fVACount; |
| 170 }; | 150 }; |
| 171 | 151 |
| 172 /** | |
|
bsalomon
2014/08/04 21:05:46
These aren't used anywhere anymore.
| |
| 173 * Accessing positions, local coords, or colors, of a vertex within an array is a hassle | |
| 174 * involving casts and simple math. These helpers exist to keep GrDrawTarget clients' code a bit | |
| 175 * nicer looking. | |
| 176 */ | |
| 177 | |
| 178 /** | |
| 179 * Gets a pointer to a GrPoint of a vertex's position or texture | |
| 180 * coordinate. | |
| 181 * @param vertices the vertex array | |
| 182 * @param vertexIndex the index of the vertex in the array | |
| 183 * @param vertexSize the size of each vertex in the array | |
| 184 * @param offset the offset in bytes of the vertex component. | |
| 185 * Defaults to zero (corresponding to vertex position) | |
| 186 * @return pointer to the vertex component as a GrPoint | |
| 187 */ | |
| 188 static SkPoint* GetVertexPoint(void* vertices, | |
| 189 int vertexIndex, | |
| 190 int vertexSize, | |
| 191 int offset = 0) { | |
| 192 intptr_t start = GrTCast<intptr_t>(vertices); | |
| 193 return GrTCast<SkPoint*>(start + offset + | |
| 194 vertexIndex * vertexSize); | |
| 195 } | |
| 196 static const SkPoint* GetVertexPoint(const void* vertices, | |
| 197 int vertexIndex, | |
| 198 int vertexSize, | |
| 199 int offset = 0) { | |
| 200 intptr_t start = GrTCast<intptr_t>(vertices); | |
| 201 return GrTCast<const SkPoint*>(start + offset + | |
| 202 vertexIndex * vertexSize); | |
| 203 } | |
| 204 | |
| 205 /** | |
| 206 * Gets a pointer to a GrColor inside a vertex within a vertex array. | |
| 207 * @param vertices the vetex array | |
| 208 * @param vertexIndex the index of the vertex in the array | |
| 209 * @param vertexSize the size of each vertex in the array | |
| 210 * @param offset the offset in bytes of the vertex color | |
| 211 * @return pointer to the vertex component as a GrColor | |
| 212 */ | |
| 213 static GrColor* GetVertexColor(void* vertices, | |
| 214 int vertexIndex, | |
| 215 int vertexSize, | |
| 216 int offset) { | |
| 217 intptr_t start = GrTCast<intptr_t>(vertices); | |
| 218 return GrTCast<GrColor*>(start + offset + | |
| 219 vertexIndex * vertexSize); | |
| 220 } | |
| 221 static const GrColor* GetVertexColor(const void* vertices, | |
| 222 int vertexIndex, | |
| 223 int vertexSize, | |
| 224 int offset) { | |
| 225 const intptr_t start = GrTCast<intptr_t>(vertices); | |
| 226 return GrTCast<const GrColor*>(start + offset + | |
| 227 vertexIndex * vertexSize); | |
| 228 } | |
| 229 | |
| 230 /// @} | 152 /// @} |
| 231 | 153 |
| 232 /** | 154 /** |
| 233 * Determines whether src alpha is guaranteed to be one for all src pixels | 155 * Determines whether src alpha is guaranteed to be one for all src pixels |
| 234 */ | 156 */ |
| 235 bool srcAlphaWillBeOne() const; | 157 bool srcAlphaWillBeOne() const; |
| 236 | 158 |
| 237 /** | 159 /** |
| 238 * Determines whether the output coverage is guaranteed to be one for all pi xels hit by a draw. | 160 * Determines whether the output coverage is guaranteed to be one for all pi xels hit by a draw. |
| 239 */ | 161 */ |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 class AutoRestoreEffects : public ::SkNoncopyable { | 311 class AutoRestoreEffects : public ::SkNoncopyable { |
| 390 public: | 312 public: |
| 391 AutoRestoreEffects() : fDrawState(NULL), fColorEffectCnt(0), fCoverageEf fectCnt(0) {} | 313 AutoRestoreEffects() : fDrawState(NULL), fColorEffectCnt(0), fCoverageEf fectCnt(0) {} |
| 392 | 314 |
| 393 AutoRestoreEffects(GrDrawState* ds) : fDrawState(NULL), fColorEffectCnt( 0), fCoverageEffectCnt(0) { | 315 AutoRestoreEffects(GrDrawState* ds) : fDrawState(NULL), fColorEffectCnt( 0), fCoverageEffectCnt(0) { |
| 394 this->set(ds); | 316 this->set(ds); |
| 395 } | 317 } |
| 396 | 318 |
| 397 ~AutoRestoreEffects() { this->set(NULL); } | 319 ~AutoRestoreEffects() { this->set(NULL); } |
| 398 | 320 |
| 399 void set(GrDrawState* ds) { | 321 void set(GrDrawState* ds); |
| 400 if (NULL != fDrawState) { | |
| 401 int m = fDrawState->fColorStages.count() - fColorEffectCnt; | |
| 402 SkASSERT(m >= 0); | |
| 403 fDrawState->fColorStages.pop_back_n(m); | |
| 404 | |
| 405 int n = fDrawState->fCoverageStages.count() - fCoverageEffectCnt ; | |
| 406 SkASSERT(n >= 0); | |
| 407 fDrawState->fCoverageStages.pop_back_n(n); | |
| 408 if (m + n > 0) { | |
| 409 fDrawState->invalidateBlendOptFlags(); | |
| 410 } | |
| 411 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) | |
| 412 } | |
| 413 fDrawState = ds; | |
| 414 if (NULL != ds) { | |
| 415 fColorEffectCnt = ds->fColorStages.count(); | |
| 416 fCoverageEffectCnt = ds->fCoverageStages.count(); | |
| 417 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) | |
| 418 } | |
| 419 } | |
| 420 | 322 |
| 421 bool isSet() const { return NULL != fDrawState; } | 323 bool isSet() const { return NULL != fDrawState; } |
| 422 | 324 |
| 423 private: | 325 private: |
| 424 GrDrawState* fDrawState; | 326 GrDrawState* fDrawState; |
| 425 int fColorEffectCnt; | 327 int fColorEffectCnt; |
| 426 int fCoverageEffectCnt; | 328 int fCoverageEffectCnt; |
| 427 }; | 329 }; |
| 428 | 330 |
| 429 int numColorStages() const { return fColorStages.count(); } | 331 int numColorStages() const { return fColorStages.count(); } |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 885 /** Use the first draw state. */ | 787 /** Use the first draw state. */ |
| 886 kA_CombinedState, | 788 kA_CombinedState, |
| 887 /** Use the second draw state. */ | 789 /** Use the second draw state. */ |
| 888 kB_CombinedState, | 790 kB_CombinedState, |
| 889 }; | 791 }; |
| 890 | 792 |
| 891 /** This functions determines whether the GrDrawStates used for two draws ca n be combined into | 793 /** This functions determines whether the GrDrawStates used for two draws ca n be combined into |
| 892 a single GrDrawState. This is used to avoid storing redundant GrDrawStat es and to determine | 794 a single GrDrawState. This is used to avoid storing redundant GrDrawStat es and to determine |
| 893 if draws can be batched. The return value indicates whether combining is possible and, if so, | 795 if draws can be batched. The return value indicates whether combining is possible and, if so, |
| 894 which of the two inputs should be used. */ | 796 which of the two inputs should be used. */ |
| 895 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta te& b) { | 797 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta te& b); |
| 896 bool usingVertexColors = a.hasColorVertexAttribute(); | |
| 897 if (!usingVertexColors && a.fColor != b.fColor) { | |
| 898 return kIncompatible_CombinedState; | |
| 899 } | |
| 900 | 798 |
| 901 if (a.fRenderTarget.get() != b.fRenderTarget.get() || | 799 GrDrawState& operator= (const GrDrawState& that); |
| 902 a.fColorStages.count() != b.fColorStages.count() || | |
| 903 a.fCoverageStages.count() != b.fCoverageStages.count() || | |
| 904 !a.fViewMatrix.cheapEqualTo(b.fViewMatrix) || | |
| 905 a.fSrcBlend != b.fSrcBlend || | |
| 906 a.fDstBlend != b.fDstBlend || | |
| 907 a.fBlendConstant != b.fBlendConstant || | |
| 908 a.fFlagBits != b.fFlagBits || | |
| 909 a.fVACount != b.fVACount || | |
| 910 memcmp(a.fVAPtr, b.fVAPtr, a.fVACount * sizeof(GrVertexAttrib)) || | |
| 911 a.fStencilSettings != b.fStencilSettings || | |
| 912 a.fDrawFace != b.fDrawFace) { | |
| 913 return kIncompatible_CombinedState; | |
| 914 } | |
| 915 | |
| 916 bool usingVertexCoverage = a.hasCoverageVertexAttribute(); | |
| 917 if (!usingVertexCoverage && a.fCoverage != b.fCoverage) { | |
| 918 return kIncompatible_CombinedState; | |
| 919 } | |
| 920 | |
| 921 bool explicitLocalCoords = a.hasLocalCoordAttribute(); | |
| 922 for (int i = 0; i < a.fColorStages.count(); i++) { | |
| 923 if (!GrEffectStage::AreCompatible(a.fColorStages[i], b.fColorStages[ i], | |
| 924 explicitLocalCoords)) { | |
| 925 return kIncompatible_CombinedState; | |
| 926 } | |
| 927 } | |
| 928 for (int i = 0; i < a.fCoverageStages.count(); i++) { | |
| 929 if (!GrEffectStage::AreCompatible(a.fCoverageStages[i], b.fCoverageS tages[i], | |
| 930 explicitLocalCoords)) { | |
| 931 return kIncompatible_CombinedState; | |
| 932 } | |
| 933 } | |
| 934 SkASSERT(0 == memcmp(a.fFixedFunctionVertexAttribIndices, | |
| 935 b.fFixedFunctionVertexAttribIndices, | |
| 936 sizeof(a.fFixedFunctionVertexAttribIndices))); | |
| 937 return kAOrB_CombinedState; | |
| 938 } | |
| 939 | |
| 940 GrDrawState& operator= (const GrDrawState& that) { | |
| 941 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | |
| 942 this->setRenderTarget(that.fRenderTarget.get()); | |
| 943 fColor = that.fColor; | |
| 944 fViewMatrix = that.fViewMatrix; | |
| 945 fSrcBlend = that.fSrcBlend; | |
| 946 fDstBlend = that.fDstBlend; | |
| 947 fBlendConstant = that.fBlendConstant; | |
| 948 fFlagBits = that.fFlagBits; | |
| 949 fVACount = that.fVACount; | |
| 950 fVAPtr = that.fVAPtr; | |
| 951 fStencilSettings = that.fStencilSettings; | |
| 952 fCoverage = that.fCoverage; | |
| 953 fDrawFace = that.fDrawFace; | |
| 954 fColorStages = that.fColorStages; | |
| 955 fCoverageStages = that.fCoverageStages; | |
| 956 fOptSrcBlend = that.fOptSrcBlend; | |
| 957 fOptDstBlend = that.fOptDstBlend; | |
| 958 fBlendOptFlags = that.fBlendOptFlags; | |
| 959 | |
| 960 memcpy(fFixedFunctionVertexAttribIndices, | |
| 961 that.fFixedFunctionVertexAttribIndices, | |
| 962 sizeof(fFixedFunctionVertexAttribIndices)); | |
| 963 return *this; | |
| 964 } | |
| 965 | 800 |
| 966 private: | 801 private: |
| 967 | 802 |
| 968 void onReset(const SkMatrix* initialViewMatrix) { | 803 void onReset(const SkMatrix* initialViewMatrix); |
| 969 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | |
| 970 fColorStages.reset(); | |
| 971 fCoverageStages.reset(); | |
| 972 | |
| 973 fRenderTarget.reset(NULL); | |
| 974 | |
| 975 this->setDefaultVertexAttribs(); | |
| 976 | |
| 977 fColor = 0xffffffff; | |
| 978 if (NULL == initialViewMatrix) { | |
| 979 fViewMatrix.reset(); | |
| 980 } else { | |
| 981 fViewMatrix = *initialViewMatrix; | |
| 982 } | |
| 983 fSrcBlend = kOne_GrBlendCoeff; | |
| 984 fDstBlend = kZero_GrBlendCoeff; | |
| 985 fBlendConstant = 0x0; | |
| 986 fFlagBits = 0x0; | |
| 987 fStencilSettings.setDisabled(); | |
| 988 fCoverage = 0xffffffff; | |
| 989 fDrawFace = kBoth_DrawFace; | |
| 990 | |
| 991 this->invalidateBlendOptFlags(); | |
| 992 } | |
| 993 | 804 |
| 994 BlendOptFlags calcBlendOpts(bool forceCoverage = false, | 805 BlendOptFlags calcBlendOpts(bool forceCoverage = false, |
| 995 GrBlendCoeff* srcCoeff = NULL, | 806 GrBlendCoeff* srcCoeff = NULL, |
| 996 GrBlendCoeff* dstCoeff = NULL) const; | 807 GrBlendCoeff* dstCoeff = NULL) const; |
| 997 | 808 |
| 998 // These fields are roughly sorted by decreasing likelihood of being differe nt in op== | 809 // These fields are roughly sorted by decreasing likelihood of being differe nt in op== |
| 999 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 810 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 1000 GrColor fColor; | 811 GrColor fColor; |
| 1001 SkMatrix fViewMatrix; | 812 SkMatrix fViewMatrix; |
| 1002 GrBlendCoeff fSrcBlend; | 813 GrBlendCoeff fSrcBlend; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1032 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt. | 843 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt. |
| 1033 */ | 844 */ |
| 1034 void setVertexAttribs(const GrVertexAttrib attribs[], int count); | 845 void setVertexAttribs(const GrVertexAttrib attribs[], int count); |
| 1035 | 846 |
| 1036 typedef SkRefCnt INHERITED; | 847 typedef SkRefCnt INHERITED; |
| 1037 }; | 848 }; |
| 1038 | 849 |
| 1039 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | 850 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); |
| 1040 | 851 |
| 1041 #endif | 852 #endif |
| OLD | NEW |