Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: src/gpu/GrDrawState.h

Issue 13296005: Revise attribute binding interface (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
11 #include "GrBackendEffectFactory.h" 11 #include "GrBackendEffectFactory.h"
12 #include "GrColor.h" 12 #include "GrColor.h"
13 #include "GrEffectStage.h" 13 #include "GrEffectStage.h"
14 #include "GrPaint.h" 14 #include "GrPaint.h"
15 #include "GrRefCnt.h" 15 #include "GrRefCnt.h"
16 #include "GrRenderTarget.h" 16 #include "GrRenderTarget.h"
17 #include "GrStencil.h" 17 #include "GrStencil.h"
18 #include "GrTemplates.h" 18 #include "GrTemplates.h"
19 #include "GrTexture.h" 19 #include "GrTexture.h"
20 #include "GrTypesPriv.h" 20 #include "GrTypesPriv.h"
21 #include "effects/GrSimpleTextureEffect.h" 21 #include "effects/GrSimpleTextureEffect.h"
22 22
23 #include "SkMatrix.h" 23 #include "SkMatrix.h"
24 #include "SkXfermode.h" 24 #include "SkXfermode.h"
25 25
26 /**
27 * Type used to describe how attributes bind to program usage
28 */
29 typedef int GrAttribBindings;
30
31 class GrDrawState : public GrRefCnt { 26 class GrDrawState : public GrRefCnt {
32 public: 27 public:
33 SK_DECLARE_INST_COUNT(GrDrawState) 28 SK_DECLARE_INST_COUNT(GrDrawState)
34 29
35 /** 30 /**
36 * Total number of effect stages. Each stage can host a GrEffect. A stage is enabled if it has a 31 * Total number of effect stages. Each stage can host a GrEffect. A stage is enabled if it has a
37 * GrEffect. The effect produces an output color in the fragment shader. It' s inputs are the 32 * GrEffect. The effect produces an output color in the fragment shader. It' s inputs are the
38 * output from the previous enabled stage and a position. The position is ei ther derived from 33 * output from the previous enabled stage and a position. The position is ei ther derived from
39 * the interpolated vertex positions or explicit per-vertex coords, dependin g upon the 34 * the interpolated vertex positions or explicit per-vertex coords, dependin g upon the
40 * GrAttribBindings used to draw. 35 * GrAttribBindings used to draw.
41 * 36 *
42 * The stages are divided into two sets, color-computing and coverage-comput ing. The final color 37 * The stages are divided into two sets, color-computing and coverage-comput ing. The final color
43 * stage produces the final pixel color. The coverage-computing stages funct ion exactly as the 38 * stage produces the final pixel color. The coverage-computing stages funct ion exactly as the
44 * color-computing but the output of the final coverage stage is treated as a fractional pixel 39 * color-computing but the output of the final coverage stage is treated as a fractional pixel
45 * coverage rather than as input to the src/dst color blend step. 40 * coverage rather than as input to the src/dst color blend step.
46 * 41 *
47 * The input color to the first enabled color-stage is either the constant c olor or interpolated 42 * The input color to the first enabled color-stage is either the constant c olor or interpolated
48 * per-vertex colors, depending upon GrAttribBindings. The input to the firs t coverage stage is 43 * per-vertex colors. The input to the first coverage stage is either a cons tant coverage
49 * either a constant coverage (usually full-coverage) or interpolated per-ve rtex coverage. 44 * (usually full-coverage) or interpolated per-vertex coverage.
50 * 45 *
51 * See the documentation of kCoverageDrawing_StateBit for information about disabling the 46 * See the documentation of kCoverageDrawing_StateBit for information about disabling the
52 * the color / coverage distinction. 47 * the color / coverage distinction.
53 * 48 *
54 * Stages 0 through GrPaint::kTotalStages-1 are reserved for stages copied f rom the client's 49 * Stages 0 through GrPaint::kTotalStages-1 are reserved for stages copied f rom the client's
55 * GrPaint. Stage GrPaint::kTotalStages is earmarked for use by GrTextContex t, GrPathRenderer- 50 * GrPaint. Stage GrPaint::kTotalStages is earmarked for use by GrTextContex t, GrPathRenderer-
56 * derived classes, and the rect/oval helper classes. GrPaint::kTotalStages+ 1 is earmarked for 51 * derived classes, and the rect/oval helper classes. GrPaint::kTotalStages+ 1 is earmarked for
57 * clipping by GrClipMaskManager. TODO: replace fixed size array of stages w ith variable size 52 * clipping by GrClipMaskManager. TODO: replace fixed size array of stages w ith variable size
58 * arrays of color and coverage stages. 53 * arrays of color and coverage stages.
59 */ 54 */
60 enum { 55 enum {
61 kNumStages = GrPaint::kTotalStages + 2, 56 kNumStages = GrPaint::kTotalStages + 2,
62 }; 57 };
63 58
64 GrDrawState() { 59 GrDrawState() {
65 #if GR_DEBUG 60 #if 0 && GR_DEBUG
bsalomon 2013/03/29 21:18:13 Let's just remove this. I see the test is gone. (T
jvanverth1 2013/03/29 21:32:45 Done.
66 VertexAttributesUnitTest(); 61 VertexAttributesUnitTest();
67 #endif 62 #endif
68 this->reset(); 63 this->reset();
69 } 64 }
70 65
71 GrDrawState(const GrDrawState& state) { 66 GrDrawState(const GrDrawState& state) {
72 *this = state; 67 *this = state;
73 } 68 }
74 69
75 virtual ~GrDrawState() { 70 virtual ~GrDrawState() {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 * GrPaint equivalents are not modified. GrPaint has fewer stages than 103 * GrPaint equivalents are not modified. GrPaint has fewer stages than
109 * GrDrawState. The extra GrDrawState stages are disabled. 104 * GrDrawState. The extra GrDrawState stages are disabled.
110 */ 105 */
111 void setFromPaint(const GrPaint& paint); 106 void setFromPaint(const GrPaint& paint);
112 107
113 /////////////////////////////////////////////////////////////////////////// 108 ///////////////////////////////////////////////////////////////////////////
114 /// @name Vertex Attributes 109 /// @name Vertex Attributes
115 //// 110 ////
116 111
117 enum { 112 enum {
118 kVertexAttribCnt = 6, 113 kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4,
119 }; 114 };
120 115
121 /** 116 /**
122 * The format of vertices is represented as an array of vertex attribute 117 * The format of vertices is represented as an array of GrVertexAttribs, wit h each representing
123 * pair, with each pair representing the type of the attribute and the 118 * the type of the attribute, its offset, and semantic binding (see GrVertex Attrib in
124 * offset in the vertex structure (see GrVertexAttrib, above). 119 * GrTypesPriv.h).
125 * 120 *
126 * This will only set up the vertex geometry. To bind the attributes in 121 * The mapping of attributes with kEffect bindings to GrEffect inputs is spe cified when
127 * the shaders, attribute indices and attribute bindings need to be set 122 * setEffect is called.
128 * as well.
129 */ 123 */
130 124
131 /** 125 /**
132 * Sets vertex attributes for next draw. 126 * Sets vertex attributes for next draw.
133 * 127 *
134 * @param attribs the array of vertex attributes to set. 128 * @param attribs the array of vertex attributes to set.
135 * @param count the number of attributes being set. 129 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt.
136 * limited to a count of kVertexAttribCnt.
137 */ 130 */
138 void setVertexAttribs(const GrVertexAttrib attribs[], int count); 131 void setVertexAttribs(const GrVertexAttrib attribs[], int count);
139 132
140 const GrVertexAttrib* getVertexAttribs() const { return fVertexAttribs.begin (); } 133 const GrVertexAttrib* getVertexAttribs() const { return fCommon.fVertexAttri bs.begin(); }
141 int getVertexAttribCount() const { return fVertexAttribs.count(); } 134 int getVertexAttribCount() const { return fCommon.fVertexAttribs.count(); }
142 135
143 size_t getVertexSize() const; 136 size_t getVertexSize() const;
144 137
145 /** 138 /**
146 * Sets default vertex attributes for next draw. 139 * Sets default vertex attributes for next draw. The default is a single at tribute:
147 * 140 * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType}
148 * This will also set default vertex attribute indices and bindings
149 */ 141 */
150 void setDefaultVertexAttribs(); 142 void setDefaultVertexAttribs();
151 143
144 /**
145 * Getters for index into getVertexAttribs() for particular bindings. -1 is returned if the
146 * binding does not appear in the current attribs. These bindings should app ear only once in
147 * the attrib array.
148 */
149
150 int positionAttributeIndex() const {
151 return fCommon.fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttri bBinding];
152 }
153 int localCoordAttributeIndex() const {
154 return fCommon.fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAtt ribBinding];
155 }
156 int colorVertexAttributeIndex() const {
157 return fCommon.fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBi nding];
158 }
159 int coverageVertexAttributeIndex() const {
160 return fCommon.fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttri bBinding];
161 }
162
163 bool hasLocalCoordAttribute() const {
164 return -1 != fCommon.fFixedFunctionVertexAttribIndices[kLocalCoord_GrVer texAttribBinding];
165 }
166 bool hasColorVertexAttribute() const {
167 return -1 != fCommon.fFixedFunctionVertexAttribIndices[kColor_GrVertexAt tribBinding];
168 }
169 bool hasCoverageVertexAttribute() const {
170 return -1 != fCommon.fFixedFunctionVertexAttribIndices[kCoverage_GrVerte xAttribBinding];
171 }
172
152 bool validateVertexAttribs() const; 173 bool validateVertexAttribs() const;
153 174
154 ////////////////////////////////////////////////////////////////////////////
155 // Helpers for picking apart vertex attributes
156
157 // helper array to let us check the expected so we know what bound attrib in dices
158 // we care about
159 static const size_t kVertexAttribSizes[kGrVertexAttribTypeCount];
160
161 /** 175 /**
162 * Accessing positions, texture coords, or colors, of a vertex within an 176 * Accessing positions, local coords, or colors, of a vertex within an array is a hassle
163 * array is a hassle involving casts and simple math. These helpers exist 177 * involving casts and simple math. These helpers exist to keep GrDrawTarget clients' code a bit
164 * to keep GrDrawTarget clients' code a bit nicer looking. 178 * nicer looking.
165 */ 179 */
166 180
167 /** 181 /**
168 * Gets a pointer to a GrPoint of a vertex's position or texture 182 * Gets a pointer to a GrPoint of a vertex's position or texture
169 * coordinate. 183 * coordinate.
170 * @param vertices the vertex array 184 * @param vertices the vertex array
171 * @param vertexIndex the index of the vertex in the array 185 * @param vertexIndex the index of the vertex in the array
172 * @param vertexSize the size of each vertex in the array 186 * @param vertexSize the size of each vertex in the array
173 * @param offset the offset in bytes of the vertex component. 187 * @param offset the offset in bytes of the vertex component.
174 * Defaults to zero (corresponding to vertex position) 188 * Defaults to zero (corresponding to vertex position)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 int vertexIndex, 225 int vertexIndex,
212 int vertexSize, 226 int vertexSize,
213 int offset) { 227 int offset) {
214 const intptr_t start = GrTCast<intptr_t>(vertices); 228 const intptr_t start = GrTCast<intptr_t>(vertices);
215 return GrTCast<const GrColor*>(start + offset + 229 return GrTCast<const GrColor*>(start + offset +
216 vertexIndex * vertexSize); 230 vertexIndex * vertexSize);
217 } 231 }
218 232
219 /// @} 233 /// @}
220 234
221 ///////////////////////////////////////////////////////////////////////////
222 /// @name Attribute Bindings
223 ////
224
225 /**
226 * The vertex data used by the current program is represented as a bitfield
227 * of flags. Programs always use positions and may also use texture
228 * coordinates, per-vertex colors, per-vertex coverage and edge data. The
229 * local coords accessible by effects may either come from positions or
230 * be specified explicitly.
231 */
232
233 /**
234 * Additional Bits that can be specified in GrAttribBindings.
235 */
236 enum AttribBindingsBits {
237 /** explicit local coords are provided (instead of using pre-view-matrix positions) */
238 kLocalCoords_AttribBindingsBit = 0x1,
239 /* program uses colors (GrColor) */
240 kColor_AttribBindingsBit = 0x2,
241 /* program uses coverage (GrColor)
242 */
243 kCoverage_AttribBindingsBit = 0x4,
244 // for below assert
245 kDummyAttribBindingsBit,
246 kHighAttribBindingsBit = kDummyAttribBindingsBit - 1
247 };
248 // make sure we haven't exceeded the number of bits in GrAttribBindings.
249 GR_STATIC_ASSERT(kHighAttribBindingsBit < ((uint64_t)1 << 8*sizeof(GrAttribB indings)));
250
251 enum AttribBindings {
252 kDefault_AttribBindings = 0
253 };
254
255 /**
256 * Sets attribute bindings for next draw.
257 *
258 * @param bindings the attribute bindings to set.
259 */
260 void setAttribBindings(GrAttribBindings bindings) { fCommon.fAttribBindings = bindings; }
261
262 GrAttribBindings getAttribBindings() const { return fCommon.fAttribBindings; }
263
264 ////////////////////////////////////////////////////////////////////////////
265 // Helpers for picking apart attribute bindings
266
267 /** 235 /**
268 * Determines whether src alpha is guaranteed to be one for all src pixels 236 * Determines whether src alpha is guaranteed to be one for all src pixels
269 */ 237 */
270 bool srcAlphaWillBeOne(GrAttribBindings) const; 238 bool srcAlphaWillBeOne() const;
271 239
272 /** 240 /**
273 * Determines whether the output coverage is guaranteed to be one for all pi xels hit by a draw. 241 * Determines whether the output coverage is guaranteed to be one for all pi xels hit by a draw.
274 */ 242 */
275 bool hasSolidCoverage(GrAttribBindings) const; 243 bool hasSolidCoverage() const;
276 244
277 static void VertexAttributesUnitTest(); 245 //static void VertexAttributesUnitTest();
278
279 /// @}
280
281 ///////////////////////////////////////////////////////////////////////////
282 /// @name Vertex Attribute Indices
283 ////
284
285 /**
286 * Vertex attribute indices map the data set in the vertex attribute array
287 * to the bindings specified in the attribute bindings. Each binding type
288 * has an associated index in the attribute array. This index is used to
289 * look up the vertex attribute data from the array, and potentially as the
290 * attribute index if we're binding attributes in GL.
291 *
292 * Indices which do not have active attribute bindings will be ignored.
293 */
294
295 enum AttribIndex {
296 kPosition_AttribIndex = 0,
297 kColor_AttribIndex,
298 kCoverage_AttribIndex,
299 kLocalCoords_AttribIndex,
300
301 kLast_AttribIndex = kLocalCoords_AttribIndex
302 };
303 static const int kAttribIndexCount = kLast_AttribIndex + 1;
304
305 // these are used when vertex color and coverage isn't set
306 enum {
307 kColorOverrideAttribIndexValue = GrDrawState::kVertexAttribCnt,
308 kCoverageOverrideAttribIndexValue = GrDrawState::kVertexAttribCnt+1,
309 };
310
311 ////////////////////////////////////////////////////////////////////////////
312 // Helpers to set attribute indices. These should match the index in the
313 // current attribute index array.
314
315 /**
316 * Sets index for next draw. This is used to look up the offset
317 * from the current vertex attribute array and to bind the attributes.
318 *
319 * @param index the attribute index we're setting
320 * @param value the value of the index
321 */
322 void setAttribIndex(AttribIndex index, int value) { fAttribIndices[index] = value; }
323
324 int getAttribIndex(AttribIndex index) const { return fAttribIndices[in dex]; }
325 246
326 /// @} 247 /// @}
327 248
328 /////////////////////////////////////////////////////////////////////////// 249 ///////////////////////////////////////////////////////////////////////////
329 /// @name Color 250 /// @name Color
330 //// 251 ////
331 252
332 /** 253 /**
333 * Sets color for next draw to a premultiplied-alpha color. 254 * Sets color for next draw to a premultiplied-alpha color.
334 * 255 *
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 970
1050 bool isStageEnabled(int s) const { 971 bool isStageEnabled(int s) const {
1051 GrAssert((unsigned)s < kNumStages); 972 GrAssert((unsigned)s < kNumStages);
1052 return (NULL != fStages[s].getEffect()); 973 return (NULL != fStages[s].getEffect());
1053 } 974 }
1054 975
1055 bool operator ==(const GrDrawState& s) const { 976 bool operator ==(const GrDrawState& s) const {
1056 if (fRenderTarget.get() != s.fRenderTarget.get() || fCommon != s.fCommon ) { 977 if (fRenderTarget.get() != s.fRenderTarget.get() || fCommon != s.fCommon ) {
1057 return false; 978 return false;
1058 } 979 }
1059 if (fVertexAttribs != s.fVertexAttribs) {
1060 return false;
1061 }
1062 for (int i = 0; i < kAttribIndexCount; ++i) {
1063 if ((i == kPosition_AttribIndex || s.fCommon.fAttribBindings & (1 << i)) &&
1064 fAttribIndices[i] != s.fAttribIndices[i]) {
1065 return false;
1066 }
1067 }
1068 for (int i = 0; i < kNumStages; i++) { 980 for (int i = 0; i < kNumStages; i++) {
1069 bool enabled = this->isStageEnabled(i); 981 bool enabled = this->isStageEnabled(i);
1070 if (enabled != s.isStageEnabled(i)) { 982 if (enabled != s.isStageEnabled(i)) {
1071 return false; 983 return false;
1072 } 984 }
1073 if (enabled && this->fStages[i] != s.fStages[i]) { 985 if (enabled && this->fStages[i] != s.fStages[i]) {
1074 return false; 986 return false;
1075 } 987 }
1076 } 988 }
1077 return true; 989 return true;
1078 } 990 }
1079 bool operator !=(const GrDrawState& s) const { return !(*this == s); } 991 bool operator !=(const GrDrawState& s) const { return !(*this == s); }
1080 992
1081 GrDrawState& operator= (const GrDrawState& s) { 993 GrDrawState& operator= (const GrDrawState& s) {
1082 this->setRenderTarget(s.fRenderTarget.get()); 994 this->setRenderTarget(s.fRenderTarget.get());
1083 fCommon = s.fCommon; 995 fCommon = s.fCommon;
1084 fVertexAttribs = s.fVertexAttribs;
1085 for (int i = 0; i < kAttribIndexCount; i++) {
1086 fAttribIndices[i] = s.fAttribIndices[i];
1087 }
1088 for (int i = 0; i < kNumStages; i++) { 996 for (int i = 0; i < kNumStages; i++) {
1089 if (s.isStageEnabled(i)) { 997 if (s.isStageEnabled(i)) {
1090 this->fStages[i] = s.fStages[i]; 998 this->fStages[i] = s.fStages[i];
1091 } 999 }
1092 } 1000 }
1093 return *this; 1001 return *this;
1094 } 1002 }
1095 1003
1096 private: 1004 private:
1097 1005
1098 /** Fields that are identical in GrDrawState and GrDrawState::DeferredState. */ 1006 /** Fields that are identical in GrDrawState and GrDrawState::DeferredState. */
1099 struct CommonState { 1007 struct CommonState {
1100 // These fields are roughly sorted by decreasing likelihood of being dif ferent in op== 1008 // These fields are roughly sorted by decreasing likelihood of being dif ferent in op==
1101 GrColor fColor; 1009 GrColor fColor;
1102 GrAttribBindings fAttribBindings; 1010 SkMatrix fViewMatrix;
1103 SkMatrix fViewMatrix; 1011 GrBlendCoeff fSrcBlend;
1104 GrBlendCoeff fSrcBlend; 1012 GrBlendCoeff fDstBlend;
1105 GrBlendCoeff fDstBlend; 1013 GrColor fBlendConstant;
1106 GrColor fBlendConstant; 1014 uint32_t fFlagBits;
1107 uint32_t fFlagBits; 1015 GrVertexAttribArray<kMaxVertexAttribCnt> fVertexAttribs;
1108 GrStencilSettings fStencilSettings; 1016 GrStencilSettings fStencilSettings;
1109 int fFirstCoverageStage; 1017 int fFirstCoverageStage;
1110 GrColor fCoverage; 1018 GrColor fCoverage;
1111 SkXfermode::Mode fColorFilterMode; 1019 SkXfermode::Mode fColorFilterMode;
1112 GrColor fColorFilterColor; 1020 GrColor fColorFilterColor;
1113 DrawFace fDrawFace; 1021 DrawFace fDrawFace;
1022
1023 // This is simply a different representation of info in fVertexAttribs a nd thus does
1024 // not need to be compared in op==.
1025 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindin gCnt];
1026
1027 GR_STATIC_ASSERT(kGrVertexAttribBindingCnt <= 8*sizeof(uint32_t));
1028
1114 bool operator== (const CommonState& other) const { 1029 bool operator== (const CommonState& other) const {
1115 return fColor == other.fColor && 1030 bool result = fColor == other.fColor &&
1116 fAttribBindings == other.fAttribBindings && 1031 fViewMatrix.cheapEqualTo(other.fViewMatrix) &&
1117 fViewMatrix.cheapEqualTo(other.fViewMatrix) && 1032 fSrcBlend == other.fSrcBlend &&
1118 fSrcBlend == other.fSrcBlend && 1033 fDstBlend == other.fDstBlend &&
1119 fDstBlend == other.fDstBlend && 1034 fBlendConstant == other.fBlendConstant &&
1120 fBlendConstant == other.fBlendConstant && 1035 fFlagBits == other.fFlagBits &&
1121 fFlagBits == other.fFlagBits && 1036 fVertexAttribs == other.fVertexAttribs &&
1122 fStencilSettings == other.fStencilSettings && 1037 fStencilSettings == other.fStencilSettings &&
1123 fFirstCoverageStage == other.fFirstCoverageStage && 1038 fFirstCoverageStage == other.fFirstCoverageStage &&
1124 fCoverage == other.fCoverage && 1039 fCoverage == other.fCoverage &&
1125 fColorFilterMode == other.fColorFilterMode && 1040 fColorFilterMode == other.fColorFilterMode &&
1126 fColorFilterColor == other.fColorFilterColor && 1041 fColorFilterColor == other.fColorFilterColor &&
1127 fDrawFace == other.fDrawFace; 1042 fDrawFace == other.fDrawFace;
1043 GrAssert(!result || 0 == memcmp(fFixedFunctionVertexAttribIndices,
1044 other.fFixedFunctionVertexAttribIndi ces,
1045 sizeof(fFixedFunctionVertexAttribInd ices)));
1046 return result;
1128 } 1047 }
1129 bool operator!= (const CommonState& other) const { return !(*this == oth er); } 1048 bool operator!= (const CommonState& other) const { return !(*this == oth er); }
1130 }; 1049 };
1131 1050
1132 /** GrDrawState uses GrEffectStages to hold stage state which holds a ref on GrEffectRef. 1051 /** GrDrawState uses GrEffectStages to hold stage state which holds a ref on GrEffectRef.
1133 DeferredState must directly reference GrEffects, however. */ 1052 DeferredState must directly reference GrEffects, however. */
1134 struct SavedEffectStage { 1053 struct SavedEffectStage {
1135 SavedEffectStage() : fEffect(NULL) {} 1054 SavedEffectStage() : fEffect(NULL) {}
1136 const GrEffect* fEffect; 1055 const GrEffect* fEffect;
1137 GrEffectStage::SavedCoordChange fCoordChange; 1056 GrEffectStage::SavedCoordChange fCoordChange;
(...skipping 12 matching lines...) Expand all
1150 GR_DEBUGCODE(fInitialized = false;) 1069 GR_DEBUGCODE(fInitialized = false;)
1151 } 1070 }
1152 // TODO: Remove this when DeferredState no longer holds a ref to the RT 1071 // TODO: Remove this when DeferredState no longer holds a ref to the RT
1153 ~DeferredState() { SkSafeUnref(fRenderTarget); } 1072 ~DeferredState() { SkSafeUnref(fRenderTarget); }
1154 1073
1155 void saveFrom(const GrDrawState& drawState) { 1074 void saveFrom(const GrDrawState& drawState) {
1156 fCommon = drawState.fCommon; 1075 fCommon = drawState.fCommon;
1157 // TODO: Here we will copy the GrRenderTarget pointer without taking a ref. 1076 // TODO: Here we will copy the GrRenderTarget pointer without taking a ref.
1158 fRenderTarget = drawState.fRenderTarget.get(); 1077 fRenderTarget = drawState.fRenderTarget.get();
1159 SkSafeRef(fRenderTarget); 1078 SkSafeRef(fRenderTarget);
1160 fVertexAttribs = drawState.fVertexAttribs;
1161 for (int i = 0; i < kAttribIndexCount; i++) {
1162 fAttribIndices[i] = drawState.fAttribIndices[i];
1163 }
1164 // Here we ref the effects directly rather than the effect-refs. TOD O: When the effect- 1079 // Here we ref the effects directly rather than the effect-refs. TOD O: When the effect-
1165 // ref gets fully unref'ed it will cause the underlying effect to un ref its resources 1080 // ref gets fully unref'ed it will cause the underlying effect to un ref its resources
1166 // and recycle them to the cache (if no one else is holding a ref to the resources). 1081 // and recycle them to the cache (if no one else is holding a ref to the resources).
1167 for (int i = 0; i < kNumStages; ++i) { 1082 for (int i = 0; i < kNumStages; ++i) {
1168 fStages[i].saveFrom(drawState.fStages[i]); 1083 fStages[i].saveFrom(drawState.fStages[i]);
1169 } 1084 }
1170 GR_DEBUGCODE(fInitialized = true;) 1085 GR_DEBUGCODE(fInitialized = true;)
1171 } 1086 }
1172 1087
1173 void restoreTo(GrDrawState* drawState) { 1088 void restoreTo(GrDrawState* drawState) {
1174 GrAssert(fInitialized); 1089 GrAssert(fInitialized);
1175 drawState->fCommon = fCommon; 1090 drawState->fCommon = fCommon;
1176 drawState->setRenderTarget(fRenderTarget); 1091 drawState->setRenderTarget(fRenderTarget);
1177 drawState->fVertexAttribs = fVertexAttribs;
1178 for (int i = 0; i < kAttribIndexCount; i++) {
1179 drawState->fAttribIndices[i] = fAttribIndices[i];
1180 }
1181 for (int i = 0; i < kNumStages; ++i) { 1092 for (int i = 0; i < kNumStages; ++i) {
1182 fStages[i].restoreTo(&drawState->fStages[i]); 1093 fStages[i].restoreTo(&drawState->fStages[i]);
1183 } 1094 }
1184 } 1095 }
1185 1096
1186 bool isEqual(const GrDrawState& state) const { 1097 bool isEqual(const GrDrawState& state) const {
1187 if (fRenderTarget != state.fRenderTarget.get() || fCommon != state.f Common) { 1098 if (fRenderTarget != state.fRenderTarget.get() || fCommon != state.f Common) {
1188 return false; 1099 return false;
1189 } 1100 }
1190 for (int i = 0; i < kAttribIndexCount; ++i) {
1191 if ((i == kPosition_AttribIndex ||
1192 state.fCommon.fAttribBindings & kAttribIndexMasks[i]) &&
1193 fAttribIndices[i] != state.fAttribIndices[i]) {
1194 return false;
1195 }
1196 }
1197 if (fVertexAttribs != state.fVertexAttribs) {
1198 return false;
1199 }
1200 for (int i = 0; i < kNumStages; ++i) { 1101 for (int i = 0; i < kNumStages; ++i) {
1201 if (!fStages[i].isEqual(state.fStages[i])) { 1102 if (!fStages[i].isEqual(state.fStages[i])) {
1202 return false; 1103 return false;
1203 } 1104 }
1204 } 1105 }
1205 return true; 1106 return true;
1206 } 1107 }
1207 1108
1208 private: 1109 private:
1209 GrRenderTarget* fRenderTarget; 1110 GrRenderTarget* fRenderTarget;
1210 CommonState fCommon; 1111 CommonState fCommon;
1211 int fAttribIndices[kAttribIndexCount];
1212 GrVertexAttribArray<kVertexAttribCnt> fVertexAttribs;
1213 GrEffectStage::DeferredStage fStages[kNumStages]; 1112 GrEffectStage::DeferredStage fStages[kNumStages];
1214 1113
1215 GR_DEBUGCODE(bool fInitialized;) 1114 GR_DEBUGCODE(bool fInitialized;)
1216 }; 1115 };
1217 1116
1218 private: 1117 private:
1219 // helper array to let us check the current bindings so we know what bound a ttrib indices
1220 // we care about
1221 static const GrAttribBindings kAttribIndexMasks[kAttribIndexCount];
1222 1118
1223 SkAutoTUnref<GrRenderTarget> fRenderTarget; 1119 SkAutoTUnref<GrRenderTarget> fRenderTarget;
1224 CommonState fCommon; 1120 CommonState fCommon;
1225 int fAttribIndices[kAttribIndexCount];
1226 GrVertexAttribArray<kVertexAttribCnt> fVertexAttribs;
1227 GrEffectStage fStages[kNumStages]; 1121 GrEffectStage fStages[kNumStages];
1228 1122
1229 typedef GrRefCnt INHERITED; 1123 typedef GrRefCnt INHERITED;
1230 }; 1124 };
1231 1125
1232 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); 1126 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags);
1233 1127
1234 #endif 1128 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrDrawState.cpp » ('j') | src/gpu/GrDrawState.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698