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 |
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 | |
66 VertexAttributesUnitTest(); | |
67 #endif | |
68 this->reset(); | 60 this->reset(); |
69 } | 61 } |
70 | 62 |
71 GrDrawState(const GrDrawState& state) { | 63 GrDrawState(const GrDrawState& state) { |
72 *this = state; | 64 *this = state; |
73 } | 65 } |
74 | 66 |
75 virtual ~GrDrawState() { | 67 virtual ~GrDrawState() { |
76 this->disableStages(); | 68 this->disableStages(); |
77 } | 69 } |
(...skipping 30 matching lines...) Expand all Loading... |
108 * GrPaint equivalents are not modified. GrPaint has fewer stages than | 100 * GrPaint equivalents are not modified. GrPaint has fewer stages than |
109 * GrDrawState. The extra GrDrawState stages are disabled. | 101 * GrDrawState. The extra GrDrawState stages are disabled. |
110 */ | 102 */ |
111 void setFromPaint(const GrPaint& paint); | 103 void setFromPaint(const GrPaint& paint); |
112 | 104 |
113 /////////////////////////////////////////////////////////////////////////// | 105 /////////////////////////////////////////////////////////////////////////// |
114 /// @name Vertex Attributes | 106 /// @name Vertex Attributes |
115 //// | 107 //// |
116 | 108 |
117 enum { | 109 enum { |
118 kVertexAttribCnt = 6, | 110 kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4, |
119 }; | 111 }; |
120 | 112 |
121 /** | 113 /** |
122 * The format of vertices is represented as an array of vertex attribute | 114 * 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 | 115 * the type of the attribute, its offset, and semantic binding (see GrVertex
Attrib in |
124 * offset in the vertex structure (see GrVertexAttrib, above). | 116 * GrTypesPriv.h). |
125 * | 117 * |
126 * This will only set up the vertex geometry. To bind the attributes in | 118 * 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 | 119 * setEffect is called. |
128 * as well. | |
129 */ | 120 */ |
130 | 121 |
131 /** | 122 /** |
132 * Sets vertex attributes for next draw. | 123 * Sets vertex attributes for next draw. |
133 * | 124 * |
134 * @param attribs the array of vertex attributes to set. | 125 * @param attribs the array of vertex attributes to set. |
135 * @param count the number of attributes being set. | 126 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. |
136 * limited to a count of kVertexAttribCnt. | |
137 */ | 127 */ |
138 void setVertexAttribs(const GrVertexAttrib attribs[], int count); | 128 void setVertexAttribs(const GrVertexAttrib attribs[], int count); |
139 | 129 |
140 const GrVertexAttrib* getVertexAttribs() const { return fVertexAttribs.begin
(); } | 130 const GrVertexAttrib* getVertexAttribs() const { return fCommon.fVertexAttri
bs.begin(); } |
141 int getVertexAttribCount() const { return fVertexAttribs.count(); } | 131 int getVertexAttribCount() const { return fCommon.fVertexAttribs.count(); } |
142 | 132 |
143 size_t getVertexSize() const; | 133 size_t getVertexSize() const; |
144 | 134 |
145 /** | 135 /** |
146 * Sets default vertex attributes for next draw. | 136 * Sets default vertex attributes for next draw. The default is a single at
tribute: |
147 * | 137 * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType} |
148 * This will also set default vertex attribute indices and bindings | |
149 */ | 138 */ |
150 void setDefaultVertexAttribs(); | 139 void setDefaultVertexAttribs(); |
151 | 140 |
| 141 /** |
| 142 * Getters for index into getVertexAttribs() for particular bindings. -1 is
returned if the |
| 143 * binding does not appear in the current attribs. These bindings should app
ear only once in |
| 144 * the attrib array. |
| 145 */ |
| 146 |
| 147 int positionAttributeIndex() const { |
| 148 return fCommon.fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttri
bBinding]; |
| 149 } |
| 150 int localCoordAttributeIndex() const { |
| 151 return fCommon.fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAtt
ribBinding]; |
| 152 } |
| 153 int colorVertexAttributeIndex() const { |
| 154 return fCommon.fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBi
nding]; |
| 155 } |
| 156 int coverageVertexAttributeIndex() const { |
| 157 return fCommon.fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttri
bBinding]; |
| 158 } |
| 159 |
| 160 bool hasLocalCoordAttribute() const { |
| 161 return -1 != fCommon.fFixedFunctionVertexAttribIndices[kLocalCoord_GrVer
texAttribBinding]; |
| 162 } |
| 163 bool hasColorVertexAttribute() const { |
| 164 return -1 != fCommon.fFixedFunctionVertexAttribIndices[kColor_GrVertexAt
tribBinding]; |
| 165 } |
| 166 bool hasCoverageVertexAttribute() const { |
| 167 return -1 != fCommon.fFixedFunctionVertexAttribIndices[kCoverage_GrVerte
xAttribBinding]; |
| 168 } |
| 169 |
152 bool validateVertexAttribs() const; | 170 bool validateVertexAttribs() const; |
153 | 171 |
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 /** | 172 /** |
162 * Accessing positions, texture coords, or colors, of a vertex within an | 173 * 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 | 174 * 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. | 175 * nicer looking. |
165 */ | 176 */ |
166 | 177 |
167 /** | 178 /** |
168 * Gets a pointer to a GrPoint of a vertex's position or texture | 179 * Gets a pointer to a GrPoint of a vertex's position or texture |
169 * coordinate. | 180 * coordinate. |
170 * @param vertices the vertex array | 181 * @param vertices the vertex array |
171 * @param vertexIndex the index of the vertex in the array | 182 * @param vertexIndex the index of the vertex in the array |
172 * @param vertexSize the size of each vertex in the array | 183 * @param vertexSize the size of each vertex in the array |
173 * @param offset the offset in bytes of the vertex component. | 184 * @param offset the offset in bytes of the vertex component. |
174 * Defaults to zero (corresponding to vertex position) | 185 * Defaults to zero (corresponding to vertex position) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 int vertexIndex, | 222 int vertexIndex, |
212 int vertexSize, | 223 int vertexSize, |
213 int offset) { | 224 int offset) { |
214 const intptr_t start = GrTCast<intptr_t>(vertices); | 225 const intptr_t start = GrTCast<intptr_t>(vertices); |
215 return GrTCast<const GrColor*>(start + offset + | 226 return GrTCast<const GrColor*>(start + offset + |
216 vertexIndex * vertexSize); | 227 vertexIndex * vertexSize); |
217 } | 228 } |
218 | 229 |
219 /// @} | 230 /// @} |
220 | 231 |
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 /** | 232 /** |
268 * Determines whether src alpha is guaranteed to be one for all src pixels | 233 * Determines whether src alpha is guaranteed to be one for all src pixels |
269 */ | 234 */ |
270 bool srcAlphaWillBeOne(GrAttribBindings) const; | 235 bool srcAlphaWillBeOne() const; |
271 | 236 |
272 /** | 237 /** |
273 * Determines whether the output coverage is guaranteed to be one for all pi
xels hit by a draw. | 238 * Determines whether the output coverage is guaranteed to be one for all pi
xels hit by a draw. |
274 */ | 239 */ |
275 bool hasSolidCoverage(GrAttribBindings) const; | 240 bool hasSolidCoverage() const; |
276 | |
277 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 | 241 |
326 /// @} | 242 /// @} |
327 | 243 |
328 /////////////////////////////////////////////////////////////////////////// | 244 /////////////////////////////////////////////////////////////////////////// |
329 /// @name Color | 245 /// @name Color |
330 //// | 246 //// |
331 | 247 |
332 /** | 248 /** |
333 * Sets color for next draw to a premultiplied-alpha color. | 249 * Sets color for next draw to a premultiplied-alpha color. |
334 * | 250 * |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 | 977 |
1062 bool isStageEnabled(int s) const { | 978 bool isStageEnabled(int s) const { |
1063 GrAssert((unsigned)s < kNumStages); | 979 GrAssert((unsigned)s < kNumStages); |
1064 return (NULL != fStages[s].getEffect()); | 980 return (NULL != fStages[s].getEffect()); |
1065 } | 981 } |
1066 | 982 |
1067 bool operator ==(const GrDrawState& s) const { | 983 bool operator ==(const GrDrawState& s) const { |
1068 if (fRenderTarget.get() != s.fRenderTarget.get() || fCommon != s.fCommon
) { | 984 if (fRenderTarget.get() != s.fRenderTarget.get() || fCommon != s.fCommon
) { |
1069 return false; | 985 return false; |
1070 } | 986 } |
1071 if (fVertexAttribs != s.fVertexAttribs) { | |
1072 return false; | |
1073 } | |
1074 for (int i = 0; i < kAttribIndexCount; ++i) { | |
1075 if ((i == kPosition_AttribIndex || s.fCommon.fAttribBindings & (1 <<
i)) && | |
1076 fAttribIndices[i] != s.fAttribIndices[i]) { | |
1077 return false; | |
1078 } | |
1079 } | |
1080 for (int i = 0; i < kNumStages; i++) { | 987 for (int i = 0; i < kNumStages; i++) { |
1081 bool enabled = this->isStageEnabled(i); | 988 bool enabled = this->isStageEnabled(i); |
1082 if (enabled != s.isStageEnabled(i)) { | 989 if (enabled != s.isStageEnabled(i)) { |
1083 return false; | 990 return false; |
1084 } | 991 } |
1085 if (enabled && this->fStages[i] != s.fStages[i]) { | 992 if (enabled && this->fStages[i] != s.fStages[i]) { |
1086 return false; | 993 return false; |
1087 } | 994 } |
1088 } | 995 } |
1089 return true; | 996 return true; |
1090 } | 997 } |
1091 bool operator !=(const GrDrawState& s) const { return !(*this == s); } | 998 bool operator !=(const GrDrawState& s) const { return !(*this == s); } |
1092 | 999 |
1093 GrDrawState& operator= (const GrDrawState& s) { | 1000 GrDrawState& operator= (const GrDrawState& s) { |
1094 this->setRenderTarget(s.fRenderTarget.get()); | 1001 this->setRenderTarget(s.fRenderTarget.get()); |
1095 fCommon = s.fCommon; | 1002 fCommon = s.fCommon; |
1096 fVertexAttribs = s.fVertexAttribs; | |
1097 for (int i = 0; i < kAttribIndexCount; i++) { | |
1098 fAttribIndices[i] = s.fAttribIndices[i]; | |
1099 } | |
1100 for (int i = 0; i < kNumStages; i++) { | 1003 for (int i = 0; i < kNumStages; i++) { |
1101 if (s.isStageEnabled(i)) { | 1004 if (s.isStageEnabled(i)) { |
1102 this->fStages[i] = s.fStages[i]; | 1005 this->fStages[i] = s.fStages[i]; |
1103 } | 1006 } |
1104 } | 1007 } |
1105 return *this; | 1008 return *this; |
1106 } | 1009 } |
1107 | 1010 |
1108 private: | 1011 private: |
1109 | 1012 |
1110 /** Fields that are identical in GrDrawState and GrDrawState::DeferredState.
*/ | 1013 /** Fields that are identical in GrDrawState and GrDrawState::DeferredState.
*/ |
1111 struct CommonState { | 1014 struct CommonState { |
1112 // These fields are roughly sorted by decreasing likelihood of being dif
ferent in op== | 1015 // These fields are roughly sorted by decreasing likelihood of being dif
ferent in op== |
1113 GrColor fColor; | 1016 GrColor fColor; |
1114 GrAttribBindings fAttribBindings; | 1017 SkMatrix fViewMatrix; |
1115 SkMatrix fViewMatrix; | 1018 GrBlendCoeff fSrcBlend; |
1116 GrBlendCoeff fSrcBlend; | 1019 GrBlendCoeff fDstBlend; |
1117 GrBlendCoeff fDstBlend; | 1020 GrColor fBlendConstant; |
1118 GrColor fBlendConstant; | 1021 uint32_t fFlagBits; |
1119 uint32_t fFlagBits; | 1022 GrVertexAttribArray<kMaxVertexAttribCnt> fVertexAttribs; |
1120 GrStencilSettings fStencilSettings; | 1023 GrStencilSettings fStencilSettings; |
1121 int fFirstCoverageStage; | 1024 int fFirstCoverageStage; |
1122 GrColor fCoverage; | 1025 GrColor fCoverage; |
1123 SkXfermode::Mode fColorFilterMode; | 1026 SkXfermode::Mode fColorFilterMode; |
1124 GrColor fColorFilterColor; | 1027 GrColor fColorFilterColor; |
1125 DrawFace fDrawFace; | 1028 DrawFace fDrawFace; |
| 1029 |
| 1030 // This is simply a different representation of info in fVertexAttribs a
nd thus does |
| 1031 // not need to be compared in op==. |
| 1032 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindin
gCnt]; |
| 1033 |
| 1034 GR_STATIC_ASSERT(kGrVertexAttribBindingCnt <= 8*sizeof(uint32_t)); |
| 1035 |
1126 bool operator== (const CommonState& other) const { | 1036 bool operator== (const CommonState& other) const { |
1127 return fColor == other.fColor && | 1037 bool result = fColor == other.fColor && |
1128 fAttribBindings == other.fAttribBindings && | 1038 fViewMatrix.cheapEqualTo(other.fViewMatrix) && |
1129 fViewMatrix.cheapEqualTo(other.fViewMatrix) && | 1039 fSrcBlend == other.fSrcBlend && |
1130 fSrcBlend == other.fSrcBlend && | 1040 fDstBlend == other.fDstBlend && |
1131 fDstBlend == other.fDstBlend && | 1041 fBlendConstant == other.fBlendConstant && |
1132 fBlendConstant == other.fBlendConstant && | 1042 fFlagBits == other.fFlagBits && |
1133 fFlagBits == other.fFlagBits && | 1043 fVertexAttribs == other.fVertexAttribs && |
1134 fStencilSettings == other.fStencilSettings && | 1044 fStencilSettings == other.fStencilSettings && |
1135 fFirstCoverageStage == other.fFirstCoverageStage && | 1045 fFirstCoverageStage == other.fFirstCoverageStage && |
1136 fCoverage == other.fCoverage && | 1046 fCoverage == other.fCoverage && |
1137 fColorFilterMode == other.fColorFilterMode && | 1047 fColorFilterMode == other.fColorFilterMode && |
1138 fColorFilterColor == other.fColorFilterColor && | 1048 fColorFilterColor == other.fColorFilterColor && |
1139 fDrawFace == other.fDrawFace; | 1049 fDrawFace == other.fDrawFace; |
| 1050 GrAssert(!result || 0 == memcmp(fFixedFunctionVertexAttribIndices, |
| 1051 other.fFixedFunctionVertexAttribIndi
ces, |
| 1052 sizeof(fFixedFunctionVertexAttribInd
ices))); |
| 1053 return result; |
1140 } | 1054 } |
1141 bool operator!= (const CommonState& other) const { return !(*this == oth
er); } | 1055 bool operator!= (const CommonState& other) const { return !(*this == oth
er); } |
1142 }; | 1056 }; |
1143 | 1057 |
1144 /** GrDrawState uses GrEffectStages to hold stage state which holds a ref on
GrEffectRef. | 1058 /** GrDrawState uses GrEffectStages to hold stage state which holds a ref on
GrEffectRef. |
1145 DeferredState must directly reference GrEffects, however. */ | 1059 DeferredState must directly reference GrEffects, however. */ |
1146 struct SavedEffectStage { | 1060 struct SavedEffectStage { |
1147 SavedEffectStage() : fEffect(NULL) {} | 1061 SavedEffectStage() : fEffect(NULL) {} |
1148 const GrEffect* fEffect; | 1062 const GrEffect* fEffect; |
1149 GrEffectStage::SavedCoordChange fCoordChange; | 1063 GrEffectStage::SavedCoordChange fCoordChange; |
(...skipping 12 matching lines...) Expand all Loading... |
1162 GR_DEBUGCODE(fInitialized = false;) | 1076 GR_DEBUGCODE(fInitialized = false;) |
1163 } | 1077 } |
1164 // TODO: Remove this when DeferredState no longer holds a ref to the RT | 1078 // TODO: Remove this when DeferredState no longer holds a ref to the RT |
1165 ~DeferredState() { SkSafeUnref(fRenderTarget); } | 1079 ~DeferredState() { SkSafeUnref(fRenderTarget); } |
1166 | 1080 |
1167 void saveFrom(const GrDrawState& drawState) { | 1081 void saveFrom(const GrDrawState& drawState) { |
1168 fCommon = drawState.fCommon; | 1082 fCommon = drawState.fCommon; |
1169 // TODO: Here we will copy the GrRenderTarget pointer without taking
a ref. | 1083 // TODO: Here we will copy the GrRenderTarget pointer without taking
a ref. |
1170 fRenderTarget = drawState.fRenderTarget.get(); | 1084 fRenderTarget = drawState.fRenderTarget.get(); |
1171 SkSafeRef(fRenderTarget); | 1085 SkSafeRef(fRenderTarget); |
1172 fVertexAttribs = drawState.fVertexAttribs; | |
1173 for (int i = 0; i < kAttribIndexCount; i++) { | |
1174 fAttribIndices[i] = drawState.fAttribIndices[i]; | |
1175 } | |
1176 // Here we ref the effects directly rather than the effect-refs. TOD
O: When the effect- | 1086 // Here we ref the effects directly rather than the effect-refs. TOD
O: When the effect- |
1177 // ref gets fully unref'ed it will cause the underlying effect to un
ref its resources | 1087 // ref gets fully unref'ed it will cause the underlying effect to un
ref its resources |
1178 // and recycle them to the cache (if no one else is holding a ref to
the resources). | 1088 // and recycle them to the cache (if no one else is holding a ref to
the resources). |
1179 for (int i = 0; i < kNumStages; ++i) { | 1089 for (int i = 0; i < kNumStages; ++i) { |
1180 fStages[i].saveFrom(drawState.fStages[i]); | 1090 fStages[i].saveFrom(drawState.fStages[i]); |
1181 } | 1091 } |
1182 GR_DEBUGCODE(fInitialized = true;) | 1092 GR_DEBUGCODE(fInitialized = true;) |
1183 } | 1093 } |
1184 | 1094 |
1185 void restoreTo(GrDrawState* drawState) { | 1095 void restoreTo(GrDrawState* drawState) { |
1186 GrAssert(fInitialized); | 1096 GrAssert(fInitialized); |
1187 drawState->fCommon = fCommon; | 1097 drawState->fCommon = fCommon; |
1188 drawState->setRenderTarget(fRenderTarget); | 1098 drawState->setRenderTarget(fRenderTarget); |
1189 drawState->fVertexAttribs = fVertexAttribs; | |
1190 for (int i = 0; i < kAttribIndexCount; i++) { | |
1191 drawState->fAttribIndices[i] = fAttribIndices[i]; | |
1192 } | |
1193 for (int i = 0; i < kNumStages; ++i) { | 1099 for (int i = 0; i < kNumStages; ++i) { |
1194 fStages[i].restoreTo(&drawState->fStages[i]); | 1100 fStages[i].restoreTo(&drawState->fStages[i]); |
1195 } | 1101 } |
1196 } | 1102 } |
1197 | 1103 |
1198 bool isEqual(const GrDrawState& state) const { | 1104 bool isEqual(const GrDrawState& state) const { |
1199 if (fRenderTarget != state.fRenderTarget.get() || fCommon != state.f
Common) { | 1105 if (fRenderTarget != state.fRenderTarget.get() || fCommon != state.f
Common) { |
1200 return false; | 1106 return false; |
1201 } | 1107 } |
1202 for (int i = 0; i < kAttribIndexCount; ++i) { | |
1203 if ((i == kPosition_AttribIndex || | |
1204 state.fCommon.fAttribBindings & kAttribIndexMasks[i]) && | |
1205 fAttribIndices[i] != state.fAttribIndices[i]) { | |
1206 return false; | |
1207 } | |
1208 } | |
1209 if (fVertexAttribs != state.fVertexAttribs) { | |
1210 return false; | |
1211 } | |
1212 for (int i = 0; i < kNumStages; ++i) { | 1108 for (int i = 0; i < kNumStages; ++i) { |
1213 if (!fStages[i].isEqual(state.fStages[i])) { | 1109 if (!fStages[i].isEqual(state.fStages[i])) { |
1214 return false; | 1110 return false; |
1215 } | 1111 } |
1216 } | 1112 } |
1217 return true; | 1113 return true; |
1218 } | 1114 } |
1219 | 1115 |
1220 private: | 1116 private: |
1221 GrRenderTarget* fRenderTarget; | 1117 GrRenderTarget* fRenderTarget; |
1222 CommonState fCommon; | 1118 CommonState fCommon; |
1223 int fAttribIndices[kAttribIndexCount]; | |
1224 GrVertexAttribArray<kVertexAttribCnt> fVertexAttribs; | |
1225 GrEffectStage::DeferredStage fStages[kNumStages]; | 1119 GrEffectStage::DeferredStage fStages[kNumStages]; |
1226 | 1120 |
1227 GR_DEBUGCODE(bool fInitialized;) | 1121 GR_DEBUGCODE(bool fInitialized;) |
1228 }; | 1122 }; |
1229 | 1123 |
1230 private: | 1124 private: |
1231 // helper array to let us check the current bindings so we know what bound a
ttrib indices | |
1232 // we care about | |
1233 static const GrAttribBindings kAttribIndexMasks[kAttribIndexCount]; | |
1234 | 1125 |
1235 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 1126 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
1236 CommonState fCommon; | 1127 CommonState fCommon; |
1237 int fAttribIndices[kAttribIndexCount]; | |
1238 GrVertexAttribArray<kVertexAttribCnt> fVertexAttribs; | |
1239 GrEffectStage fStages[kNumStages]; | 1128 GrEffectStage fStages[kNumStages]; |
1240 | 1129 |
1241 typedef GrRefCnt INHERITED; | 1130 typedef GrRefCnt INHERITED; |
1242 }; | 1131 }; |
1243 | 1132 |
1244 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | 1133 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); |
1245 | 1134 |
1246 #endif | 1135 #endif |
OLD | NEW |