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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 if (!preConcatMatrix.isIdentity()) { | 56 if (!preConcatMatrix.isIdentity()) { |
57 for (int i = 0; i < fColorStages.count(); ++i) { | 57 for (int i = 0; i < fColorStages.count(); ++i) { |
58 fColorStages[i].localCoordChange(preConcatMatrix); | 58 fColorStages[i].localCoordChange(preConcatMatrix); |
59 } | 59 } |
60 for (int i = 0; i < fCoverageStages.count(); ++i) { | 60 for (int i = 0; i < fCoverageStages.count(); ++i) { |
61 fCoverageStages[i].localCoordChange(preConcatMatrix); | 61 fCoverageStages[i].localCoordChange(preConcatMatrix); |
62 } | 62 } |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 virtual ~GrDrawState() { GrAssert(0 == fBlockEffectRemovalCnt); } | 66 virtual ~GrDrawState() { SkASSERT(0 == fBlockEffectRemovalCnt); } |
67 | 67 |
68 /** | 68 /** |
69 * Resets to the default state. GrEffects will be removed from all stages. | 69 * Resets to the default state. GrEffects will be removed from all stages. |
70 */ | 70 */ |
71 void reset() { this->onReset(NULL); } | 71 void reset() { this->onReset(NULL); } |
72 | 72 |
73 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa
trix); } | 73 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa
trix); } |
74 | 74 |
75 /** | 75 /** |
76 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta
rget. Note that | 76 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta
rget. Note that |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 145 } |
146 | 146 |
147 bool validateVertexAttribs() const; | 147 bool validateVertexAttribs() const; |
148 | 148 |
149 /** | 149 /** |
150 * Helper to save/restore vertex attribs | 150 * Helper to save/restore vertex attribs |
151 */ | 151 */ |
152 class AutoVertexAttribRestore { | 152 class AutoVertexAttribRestore { |
153 public: | 153 public: |
154 AutoVertexAttribRestore(GrDrawState* drawState) { | 154 AutoVertexAttribRestore(GrDrawState* drawState) { |
155 GrAssert(NULL != drawState); | 155 SkASSERT(NULL != drawState); |
156 fDrawState = drawState; | 156 fDrawState = drawState; |
157 fVAPtr = drawState->fCommon.fVAPtr; | 157 fVAPtr = drawState->fCommon.fVAPtr; |
158 fVACount = drawState->fCommon.fVACount; | 158 fVACount = drawState->fCommon.fVACount; |
159 fDrawState->setDefaultVertexAttribs(); | 159 fDrawState->setDefaultVertexAttribs(); |
160 } | 160 } |
161 | 161 |
162 ~AutoVertexAttribRestore(){ | 162 ~AutoVertexAttribRestore(){ |
163 fDrawState->fCommon.fVAPtr = fVAPtr; | 163 fDrawState->fCommon.fVAPtr = fVAPtr; |
164 fDrawState->fCommon.fVACount = fVACount; | 164 fDrawState->fCommon.fVACount = fVACount; |
165 } | 165 } |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 /// | 352 /// |
353 /// The input color to the first color-stage is either the constant color or
interpolated | 353 /// The input color to the first color-stage is either the constant color or
interpolated |
354 /// per-vertex colors. The input to the first coverage stage is either a con
stant coverage | 354 /// per-vertex colors. The input to the first coverage stage is either a con
stant coverage |
355 /// (usually full-coverage) or interpolated per-vertex coverage. | 355 /// (usually full-coverage) or interpolated per-vertex coverage. |
356 /// | 356 /// |
357 /// See the documentation of kCoverageDrawing_StateBit for information about
disabling the | 357 /// See the documentation of kCoverageDrawing_StateBit for information about
disabling the |
358 /// the color / coverage distinction. | 358 /// the color / coverage distinction. |
359 //// | 359 //// |
360 | 360 |
361 const GrEffectRef* addColorEffect(const GrEffectRef* effect, int attr0 = -1,
int attr1 = -1) { | 361 const GrEffectRef* addColorEffect(const GrEffectRef* effect, int attr0 = -1,
int attr1 = -1) { |
362 GrAssert(NULL != effect); | 362 SkASSERT(NULL != effect); |
363 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att
r1)); | 363 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att
r1)); |
364 return effect; | 364 return effect; |
365 } | 365 } |
366 | 366 |
367 const GrEffectRef* addCoverageEffect(const GrEffectRef* effect, int attr0 =
-1, int attr1 = -1) { | 367 const GrEffectRef* addCoverageEffect(const GrEffectRef* effect, int attr0 =
-1, int attr1 = -1) { |
368 GrAssert(NULL != effect); | 368 SkASSERT(NULL != effect); |
369 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0,
attr1)); | 369 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0,
attr1)); |
370 return effect; | 370 return effect; |
371 } | 371 } |
372 | 372 |
373 /** | 373 /** |
374 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin
ates. | 374 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin
ates. |
375 */ | 375 */ |
376 void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { | 376 void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { |
377 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix); | 377 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix); |
378 this->addColorEffect(effect)->unref(); | 378 this->addColorEffect(effect)->unref(); |
(...skipping 28 matching lines...) Expand all Loading... |
407 | 407 |
408 AutoRestoreEffects(GrDrawState* ds) : fDrawState(NULL), fColorEffectCnt(
0), fCoverageEffectCnt(0) { | 408 AutoRestoreEffects(GrDrawState* ds) : fDrawState(NULL), fColorEffectCnt(
0), fCoverageEffectCnt(0) { |
409 this->set(ds); | 409 this->set(ds); |
410 } | 410 } |
411 | 411 |
412 ~AutoRestoreEffects() { this->set(NULL); } | 412 ~AutoRestoreEffects() { this->set(NULL); } |
413 | 413 |
414 void set(GrDrawState* ds) { | 414 void set(GrDrawState* ds) { |
415 if (NULL != fDrawState) { | 415 if (NULL != fDrawState) { |
416 int n = fDrawState->fColorStages.count() - fColorEffectCnt; | 416 int n = fDrawState->fColorStages.count() - fColorEffectCnt; |
417 GrAssert(n >= 0); | 417 SkASSERT(n >= 0); |
418 fDrawState->fColorStages.pop_back_n(n); | 418 fDrawState->fColorStages.pop_back_n(n); |
419 n = fDrawState->fCoverageStages.count() - fCoverageEffectCnt; | 419 n = fDrawState->fCoverageStages.count() - fCoverageEffectCnt; |
420 GrAssert(n >= 0); | 420 SkASSERT(n >= 0); |
421 fDrawState->fCoverageStages.pop_back_n(n); | 421 fDrawState->fCoverageStages.pop_back_n(n); |
422 GR_DEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) | 422 GR_DEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) |
423 } | 423 } |
424 fDrawState = ds; | 424 fDrawState = ds; |
425 if (NULL != ds) { | 425 if (NULL != ds) { |
426 fColorEffectCnt = ds->fColorStages.count(); | 426 fColorEffectCnt = ds->fColorStages.count(); |
427 fCoverageEffectCnt = ds->fCoverageStages.count(); | 427 fCoverageEffectCnt = ds->fCoverageStages.count(); |
428 GR_DEBUGCODE(++ds->fBlockEffectRemovalCnt;) | 428 GR_DEBUGCODE(++ds->fBlockEffectRemovalCnt;) |
429 } | 429 } |
430 } | 430 } |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 fDrawState->setRenderTarget(fSavedTarget); | 675 fDrawState->setRenderTarget(fSavedTarget); |
676 fDrawState = NULL; | 676 fDrawState = NULL; |
677 } | 677 } |
678 GrSafeSetNull(fSavedTarget); | 678 GrSafeSetNull(fSavedTarget); |
679 } | 679 } |
680 | 680 |
681 void set(GrDrawState* ds, GrRenderTarget* newTarget) { | 681 void set(GrDrawState* ds, GrRenderTarget* newTarget) { |
682 this->restore(); | 682 this->restore(); |
683 | 683 |
684 if (NULL != ds) { | 684 if (NULL != ds) { |
685 GrAssert(NULL == fSavedTarget); | 685 SkASSERT(NULL == fSavedTarget); |
686 fSavedTarget = ds->getRenderTarget(); | 686 fSavedTarget = ds->getRenderTarget(); |
687 SkSafeRef(fSavedTarget); | 687 SkSafeRef(fSavedTarget); |
688 ds->setRenderTarget(newTarget); | 688 ds->setRenderTarget(newTarget); |
689 fDrawState = ds; | 689 fDrawState = ds; |
690 } | 690 } |
691 } | 691 } |
692 private: | 692 private: |
693 GrDrawState* fDrawState; | 693 GrDrawState* fDrawState; |
694 GrRenderTarget* fSavedTarget; | 694 GrRenderTarget* fSavedTarget; |
695 }; | 695 }; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 kBoth_DrawFace, | 840 kBoth_DrawFace, |
841 kCCW_DrawFace, | 841 kCCW_DrawFace, |
842 kCW_DrawFace, | 842 kCW_DrawFace, |
843 }; | 843 }; |
844 | 844 |
845 /** | 845 /** |
846 * Controls whether clockwise, counterclockwise, or both faces are drawn. | 846 * Controls whether clockwise, counterclockwise, or both faces are drawn. |
847 * @param face the face(s) to draw. | 847 * @param face the face(s) to draw. |
848 */ | 848 */ |
849 void setDrawFace(DrawFace face) { | 849 void setDrawFace(DrawFace face) { |
850 GrAssert(kInvalid_DrawFace != face); | 850 SkASSERT(kInvalid_DrawFace != face); |
851 fCommon.fDrawFace = face; | 851 fCommon.fDrawFace = face; |
852 } | 852 } |
853 | 853 |
854 /** | 854 /** |
855 * Gets whether the target is drawing clockwise, counterclockwise, | 855 * Gets whether the target is drawing clockwise, counterclockwise, |
856 * or both faces. | 856 * or both faces. |
857 * @return the current draw face(s). | 857 * @return the current draw face(s). |
858 */ | 858 */ |
859 DrawFace getDrawFace() const { return fCommon.fDrawFace; } | 859 DrawFace getDrawFace() const { return fCommon.fDrawFace; } |
860 | 860 |
(...skipping 16 matching lines...) Expand all Loading... |
877 for (int i = 0; i < fCoverageStages.count(); i++) { | 877 for (int i = 0; i < fCoverageStages.count(); i++) { |
878 if (fCoverageStages[i] != s.fCoverageStages[i]) { | 878 if (fCoverageStages[i] != s.fCoverageStages[i]) { |
879 return false; | 879 return false; |
880 } | 880 } |
881 } | 881 } |
882 return true; | 882 return true; |
883 } | 883 } |
884 bool operator !=(const GrDrawState& s) const { return !(*this == s); } | 884 bool operator !=(const GrDrawState& s) const { return !(*this == s); } |
885 | 885 |
886 GrDrawState& operator= (const GrDrawState& s) { | 886 GrDrawState& operator= (const GrDrawState& s) { |
887 GrAssert(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 887 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
888 this->setRenderTarget(s.fRenderTarget.get()); | 888 this->setRenderTarget(s.fRenderTarget.get()); |
889 fCommon = s.fCommon; | 889 fCommon = s.fCommon; |
890 fColorStages = s.fColorStages; | 890 fColorStages = s.fColorStages; |
891 fCoverageStages = s.fCoverageStages; | 891 fCoverageStages = s.fCoverageStages; |
892 return *this; | 892 return *this; |
893 } | 893 } |
894 | 894 |
895 private: | 895 private: |
896 | 896 |
897 void onReset(const SkMatrix* initialViewMatrix) { | 897 void onReset(const SkMatrix* initialViewMatrix) { |
898 GrAssert(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 898 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
899 fColorStages.reset(); | 899 fColorStages.reset(); |
900 fCoverageStages.reset(); | 900 fCoverageStages.reset(); |
901 | 901 |
902 fRenderTarget.reset(NULL); | 902 fRenderTarget.reset(NULL); |
903 | 903 |
904 this->setDefaultVertexAttribs(); | 904 this->setDefaultVertexAttribs(); |
905 | 905 |
906 fCommon.fColor = 0xffffffff; | 906 fCommon.fColor = 0xffffffff; |
907 if (NULL == initialViewMatrix) { | 907 if (NULL == initialViewMatrix) { |
908 fCommon.fViewMatrix.reset(); | 908 fCommon.fViewMatrix.reset(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 fDstBlend == other.fDstBlend && | 948 fDstBlend == other.fDstBlend && |
949 fBlendConstant == other.fBlendConstant && | 949 fBlendConstant == other.fBlendConstant && |
950 fFlagBits == other.fFlagBits && | 950 fFlagBits == other.fFlagBits && |
951 fVACount == other.fVACount && | 951 fVACount == other.fVACount && |
952 !memcmp(fVAPtr, other.fVAPtr, fVACount * sizeof(GrVert
exAttrib)) && | 952 !memcmp(fVAPtr, other.fVAPtr, fVACount * sizeof(GrVert
exAttrib)) && |
953 fStencilSettings == other.fStencilSettings && | 953 fStencilSettings == other.fStencilSettings && |
954 fCoverage == other.fCoverage && | 954 fCoverage == other.fCoverage && |
955 fColorFilterMode == other.fColorFilterMode && | 955 fColorFilterMode == other.fColorFilterMode && |
956 fColorFilterColor == other.fColorFilterColor && | 956 fColorFilterColor == other.fColorFilterColor && |
957 fDrawFace == other.fDrawFace; | 957 fDrawFace == other.fDrawFace; |
958 GrAssert(!result || 0 == memcmp(fFixedFunctionVertexAttribIndices, | 958 SkASSERT(!result || 0 == memcmp(fFixedFunctionVertexAttribIndices, |
959 other.fFixedFunctionVertexAttribIndi
ces, | 959 other.fFixedFunctionVertexAttribIndi
ces, |
960 sizeof(fFixedFunctionVertexAttribInd
ices))); | 960 sizeof(fFixedFunctionVertexAttribInd
ices))); |
961 return result; | 961 return result; |
962 } | 962 } |
963 bool operator!= (const CommonState& other) const { return !(*this == oth
er); } | 963 bool operator!= (const CommonState& other) const { return !(*this == oth
er); } |
964 }; | 964 }; |
965 | 965 |
966 /** GrDrawState uses GrEffectStages to hold stage state which holds a ref on
GrEffectRef. | 966 /** GrDrawState uses GrEffectStages to hold stage state which holds a ref on
GrEffectRef. |
967 DeferredState must directly reference GrEffects, however. */ | 967 DeferredState must directly reference GrEffects, however. */ |
968 struct SavedEffectStage { | 968 struct SavedEffectStage { |
(...skipping 30 matching lines...) Expand all Loading... |
999 for (int i = 0; i < fColorStageCnt; ++i) { | 999 for (int i = 0; i < fColorStageCnt; ++i) { |
1000 fStages[i].saveFrom(drawState.fColorStages[i]); | 1000 fStages[i].saveFrom(drawState.fColorStages[i]); |
1001 } | 1001 } |
1002 for (int i = 0; i < drawState.fCoverageStages.count(); ++i) { | 1002 for (int i = 0; i < drawState.fCoverageStages.count(); ++i) { |
1003 fStages[i + fColorStageCnt].saveFrom(drawState.fCoverageStages[i
]); | 1003 fStages[i + fColorStageCnt].saveFrom(drawState.fCoverageStages[i
]); |
1004 } | 1004 } |
1005 GR_DEBUGCODE(fInitialized = true;) | 1005 GR_DEBUGCODE(fInitialized = true;) |
1006 } | 1006 } |
1007 | 1007 |
1008 void restoreTo(GrDrawState* drawState) { | 1008 void restoreTo(GrDrawState* drawState) { |
1009 GrAssert(fInitialized); | 1009 SkASSERT(fInitialized); |
1010 drawState->fCommon = fCommon; | 1010 drawState->fCommon = fCommon; |
1011 drawState->setRenderTarget(fRenderTarget); | 1011 drawState->setRenderTarget(fRenderTarget); |
1012 // reinflate color/cov stage arrays. | 1012 // reinflate color/cov stage arrays. |
1013 drawState->fColorStages.reset(); | 1013 drawState->fColorStages.reset(); |
1014 for (int i = 0; i < fColorStageCnt; ++i) { | 1014 for (int i = 0; i < fColorStageCnt; ++i) { |
1015 SkNEW_APPEND_TO_TARRAY(&drawState->fColorStages, GrEffectStage,
(fStages[i])); | 1015 SkNEW_APPEND_TO_TARRAY(&drawState->fColorStages, GrEffectStage,
(fStages[i])); |
1016 } | 1016 } |
1017 int coverageStageCnt = fStages.count() - fColorStageCnt; | 1017 int coverageStageCnt = fStages.count() - fColorStageCnt; |
1018 drawState->fCoverageStages.reset(); | 1018 drawState->fCoverageStages.reset(); |
1019 for (int i = 0; i < coverageStageCnt; ++i) { | 1019 for (int i = 0; i < coverageStageCnt; ++i) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. | 1076 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. |
1077 */ | 1077 */ |
1078 void setVertexAttribs(const GrVertexAttrib attribs[], int count); | 1078 void setVertexAttribs(const GrVertexAttrib attribs[], int count); |
1079 | 1079 |
1080 typedef GrRefCnt INHERITED; | 1080 typedef GrRefCnt INHERITED; |
1081 }; | 1081 }; |
1082 | 1082 |
1083 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | 1083 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); |
1084 | 1084 |
1085 #endif | 1085 #endif |
OLD | NEW |