OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #include "GrDrawState.h" | 8 #include "GrDrawState.h" |
9 #include "GrPaint.h" | 9 #include "GrPaint.h" |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... | |
39 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); | 39 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); |
40 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); | 40 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); |
41 | 41 |
42 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); | 42 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); |
43 this->setColorFilter(paint.getColorFilterColor(), paint.getColorFilterMode() ); | 43 this->setColorFilter(paint.getColorFilterColor(), paint.getColorFilterMode() ); |
44 this->setCoverage(paint.getCoverage()); | 44 this->setCoverage(paint.getCoverage()); |
45 } | 45 } |
46 | 46 |
47 //////////////////////////////////////////////////////////////////////////////// | 47 //////////////////////////////////////////////////////////////////////////////// |
48 | 48 |
49 const size_t GrDrawState::kVertexAttribSizes[kGrVertexAttribTypeCount] = { | |
50 sizeof(float), // kFloat_GrVertexAttribType | |
51 2*sizeof(float), // kVec2_GrVertexAttribType | |
52 3*sizeof(float), // kVec3_GrVertexAttribType | |
53 4*sizeof(float), // kVec4_GrVertexAttribType | |
54 4*sizeof(char) // kCVec4_GrVertexAttribType | |
55 }; | |
56 | |
57 static size_t vertex_size(const GrVertexAttrib* attribs, int count) { | 49 static size_t vertex_size(const GrVertexAttrib* attribs, int count) { |
58 // this works as long as we're 4 byte-aligned | 50 // this works as long as we're 4 byte-aligned |
59 #if GR_DEBUG | 51 #if GR_DEBUG |
60 uint32_t overlapCheck = 0; | 52 uint32_t overlapCheck = 0; |
61 #endif | 53 #endif |
62 GrAssert(count <= GrDrawState::kVertexAttribCnt); | 54 GrAssert(count <= GrDrawState::kMaxVertexAttribCnt); |
63 size_t size = 0; | 55 size_t size = 0; |
64 for (int index = 0; index < count; ++index) { | 56 for (int index = 0; index < count; ++index) { |
65 size_t attribSize = GrDrawState::kVertexAttribSizes[attribs[index].fType ]; | 57 size_t attribSize = GrVertexAttribTypeSize(attribs[index].fType); |
66 size += attribSize; | 58 size += attribSize; |
67 #if GR_DEBUG | 59 #if GR_DEBUG |
68 size_t dwordCount = attribSize >> 2; | 60 size_t dwordCount = attribSize >> 2; |
69 uint32_t mask = (1 << dwordCount)-1; | 61 uint32_t mask = (1 << dwordCount)-1; |
70 size_t offsetShift = attribs[index].fOffset >> 2; | 62 size_t offsetShift = attribs[index].fOffset >> 2; |
71 GrAssert(!(overlapCheck & (mask << offsetShift))); | 63 GrAssert(!(overlapCheck & (mask << offsetShift))); |
72 overlapCheck |= (mask << offsetShift); | 64 overlapCheck |= (mask << offsetShift); |
73 #endif | 65 #endif |
74 } | 66 } |
75 return size; | 67 return size; |
76 } | 68 } |
77 | 69 |
78 size_t GrDrawState::getVertexSize() const { | 70 size_t GrDrawState::getVertexSize() const { |
79 return vertex_size(fVertexAttribs.begin(), fVertexAttribs.count()); | 71 return vertex_size(fCommon.fVertexAttribs.begin(), fCommon.fVertexAttribs.co unt()); |
80 } | 72 } |
81 | 73 |
82 const GrAttribBindings GrDrawState::kAttribIndexMasks[kAttribIndexCount] = { | |
83 0, // position is not reflected in the bindings | |
84 kColor_AttribBindingsBit, | |
85 kCoverage_AttribBindingsBit, | |
86 kLocalCoords_AttribBindingsBit, | |
87 }; | |
88 | |
89 //////////////////////////////////////////////////////////////////////////////// | 74 //////////////////////////////////////////////////////////////////////////////// |
90 | 75 |
91 void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count) { | 76 void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count) { |
92 GrAssert(count <= GrDrawState::kVertexAttribCnt); | 77 GrAssert(count <= kMaxVertexAttribCnt); |
93 fVertexAttribs.reset(); | 78 fCommon.fVertexAttribs.reset(attribs, count); |
94 for (int index = 0; index < count; ++index) { | 79 |
95 fVertexAttribs.push_back(attribs[index]); | 80 // Set all the indices to -1 |
81 memset(fCommon.fFixedFunctionVertexAttribIndices, | |
82 0xff, | |
83 sizeof(fCommon.fFixedFunctionVertexAttribIndices)); | |
84 #if GR_DEBUG | |
85 uint32_t overlapCheck = 0; | |
86 #endif | |
87 for (int i = 0; i < count; ++i) { | |
88 if (attribs[i].fBinding < kGrFixedFunctionVertexAttribBindingCnt) { | |
89 // The fixed function attribs can only be specified once | |
90 GrAssert(-1 == fCommon.fFixedFunctionVertexAttribIndices[attribs[i]. fBinding]); | |
91 GrAssert(GrFixedFunctionVertexAttribVectorCount(attribs[i].fBinding) == | |
92 GrVertexAttribTypeVectorCount(attribs[i].fType)); | |
93 fCommon.fFixedFunctionVertexAttribIndices[attribs[i].fBinding] = i; | |
94 } | |
95 #if GR_DEBUG | |
96 size_t dwordCount = GrVertexAttribTypeSize(attribs[i].fType) >> 2; | |
97 uint32_t mask = (1 << dwordCount)-1; | |
98 size_t offsetShift = attribs[i].fOffset >> 2; | |
99 GrAssert(!(overlapCheck & (mask << offsetShift))); | |
100 overlapCheck |= (mask << offsetShift); | |
101 #endif | |
96 } | 102 } |
103 // Positions must be specified. | |
104 GrAssert(-1 != fCommon.fFixedFunctionVertexAttribIndices[kPosition_GrVertexA ttribBinding]); | |
97 } | 105 } |
98 | 106 |
99 //////////////////////////////////////////////////////////////////////////////// | 107 //////////////////////////////////////////////////////////////////////////////// |
100 | 108 |
101 void GrDrawState::setDefaultVertexAttribs() { | 109 void GrDrawState::setDefaultVertexAttribs() { |
102 static const GrVertexAttrib kPositionAttrib = {kVec2f_GrVertexAttribType, 0} ; | 110 static const GrVertexAttrib kPositionAttrib = |
103 fVertexAttribs.reset(); | 111 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; |
104 fVertexAttribs.push_back(kPositionAttrib); | 112 fCommon.fVertexAttribs.reset(&kPositionAttrib, 1); |
105 | 113 // set all the fixed function indices to -1 except position. |
106 fCommon.fAttribBindings = kDefault_AttribBindings; | 114 memset(fCommon.fFixedFunctionVertexAttribIndices, |
107 | 115 0xff, |
108 fAttribIndices[kPosition_AttribIndex] = 0; | 116 sizeof(fCommon.fFixedFunctionVertexAttribIndices)); |
117 fCommon.fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0; | |
109 } | 118 } |
110 | 119 |
111 //////////////////////////////////////////////////////////////////////////////// | 120 //////////////////////////////////////////////////////////////////////////////// |
112 | 121 |
113 bool GrDrawState::validateVertexAttribs() const { | 122 bool GrDrawState::validateVertexAttribs() const { |
114 // color and coverage can set indices beyond the standard count | 123 #if GR_DEBUG |
bsalomon
2013/03/29 21:18:13
I think I added this in support of asserts for cod
jvanverth1
2013/03/29 21:32:45
Done.
| |
115 static const int kMaxValidAttribIndex = kVertexAttribCnt+2; | 124 uint32_t attribMask = 0; |
116 int attributeTypes[kMaxValidAttribIndex]; | 125 for (int i = 0; i < fCommon.fVertexAttribs.count(); ++i) { |
117 for (int i = 0; i < kMaxValidAttribIndex; ++i) { | 126 attribMask = (1 << fCommon.fVertexAttribs[i].fBinding); |
118 attributeTypes[i] = -1; | |
119 } | 127 } |
128 #endif | |
120 | 129 |
121 // sentinel to make sure effects don't try to use built-in attributes | 130 // check consistency of effects and attributes |
122 static const int kBuiltInAttributeType = 10000; | 131 GrSLType slTypes[kMaxVertexAttribCnt]; |
132 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { | |
133 slTypes[i] = static_cast<GrSLType>(-1); | |
134 } | |
135 for (int s = 0; s < kNumStages; ++s) { | |
136 if (this->isStageEnabled(s)) { | |
137 const GrEffectStage& stage = fStages[s]; | |
138 const GrEffectRef* effect = stage.getEffect(); | |
139 // make sure that any attribute indices have the correct binding typ e, that the attrib | |
140 // type and effect's shader lang type are compatible, and that attri butes shared by | |
141 // multiple effects use the same shader lang type. | |
142 const int* attributeIndices = stage.getVertexAttribIndices(); | |
143 int numAttributes = stage.getVertexAttribIndexCount(); | |
144 for (int i = 0; i < numAttributes; ++i) { | |
145 int attribIndex = attributeIndices[i]; | |
146 if (attribIndex >= fCommon.fVertexAttribs.count() || | |
147 kEffect_GrVertexAttribBinding != fCommon.fVertexAttribs[attr ibIndex].fBinding) { | |
148 return false; | |
149 } | |
123 | 150 |
124 // check our built-in indices | 151 GrSLType effectSLType = (*effect)->vertexAttribType(i); |
125 if (fAttribIndices[kPosition_AttribIndex] >= kVertexAttribCnt) { | 152 GrVertexAttribType attribType = fCommon.fVertexAttribs[attribInd ex].fType; |
126 return false; | 153 int slVecCount = GrSLTypeVectorCount(effectSLType); |
127 } | 154 int attribVecCount = GrVertexAttribTypeVectorCount(attribType); |
128 attributeTypes[fAttribIndices[kPosition_AttribIndex]] = kBuiltInAttributeTyp e; | 155 if (slVecCount != attribVecCount || |
129 for (int j = kColor_AttribIndex; j <= kCoverage_AttribIndex; ++j) { | 156 (-1 != slTypes[attribIndex] && slTypes[attribIndex] != effec tSLType)) { |
130 if (fCommon.fAttribBindings & kAttribIndexMasks[j]) { | 157 return false; |
131 int attributeIndex = fAttribIndices[j]; | 158 } |
132 if (attributeIndex >= kMaxValidAttribIndex) { | 159 slTypes[attribIndex] = effectSLType; |
133 return false; | |
134 } | 160 } |
135 // they should not be shared at all | |
136 if (attributeTypes[attributeIndex] != -1) { | |
137 return false; | |
138 } | |
139 attributeTypes[attributeIndex] = kBuiltInAttributeType; | |
140 } | |
141 } | |
142 if (fCommon.fAttribBindings & kAttribIndexMasks[kLocalCoords_AttribIndex]) { | |
143 int attributeIndex = fAttribIndices[kLocalCoords_AttribIndex]; | |
144 if (attributeIndex >= kVertexAttribCnt) { | |
145 return false; | |
146 } | |
147 // they should not be shared at all | |
148 if (attributeTypes[attributeIndex] != -1) { | |
149 return false; | |
150 } | |
151 attributeTypes[attributeIndex] = kBuiltInAttributeType; | |
152 } | |
153 | |
154 // now those set by effects | |
155 for (int s = 0; s < kNumStages; ++s) { | |
156 const GrEffectStage& stage = fStages[s]; | |
157 const GrEffectRef* effect = stage.getEffect(); | |
158 if (effect == NULL) { | |
159 continue; | |
160 } | |
161 | |
162 // make sure that the count in the stage and the effect matches | |
163 int numAttributes = stage.getVertexAttribIndexCount(); | |
164 if (numAttributes != effect->get()->numVertexAttribs()) { | |
165 return false; | |
166 } | |
167 | |
168 // make sure that any shared indices have the same type | |
169 const int* attributeIndices = stage.getVertexAttribIndices(); | |
170 for (int i = 0; i < numAttributes; ++i) { | |
171 int attributeIndex = attributeIndices[i]; | |
172 if (attributeIndex >= kVertexAttribCnt) { | |
173 return false; | |
174 } | |
175 | |
176 GrSLType attributeType = effect->get()->vertexAttribType(i); | |
177 if (attributeTypes[attributeIndex] != -1 && | |
178 attributeTypes[attributeIndex] != attributeType) { | |
179 return false; | |
180 } | |
181 attributeTypes[attributeIndex] = attributeType; | |
182 } | 161 } |
183 } | 162 } |
184 | 163 |
185 return true; | 164 return true; |
186 } | 165 } |
187 | 166 |
188 | |
189 void GrDrawState::VertexAttributesUnitTest() { | |
190 // not necessarily exhaustive | |
191 static bool run; | |
192 if (!run) { | |
193 run = true; | |
194 | |
195 GrVertexAttribArray<6> attribs; | |
196 GrAssert(0 == vertex_size(attribs.begin(), attribs.count())); | |
197 | |
198 GrVertexAttrib currAttrib = {kFloat_GrVertexAttribType, 0}; | |
199 attribs.push_back(currAttrib); | |
200 GrAssert(sizeof(float) == vertex_size(attribs.begin(), attribs.count())) ; | |
201 attribs[0].fType = kVec2f_GrVertexAttribType; | |
202 GrAssert(2*sizeof(float) == vertex_size(attribs.begin(), attribs.count() )); | |
203 attribs[0].fType = kVec3f_GrVertexAttribType; | |
204 GrAssert(3*sizeof(float) == vertex_size(attribs.begin(), attribs.count() )); | |
205 attribs[0].fType = kVec4f_GrVertexAttribType; | |
206 GrAssert(4*sizeof(float) == vertex_size(attribs.begin(), attribs.count() )); | |
207 attribs[0].fType = kVec4ub_GrVertexAttribType; | |
208 GrAssert(4*sizeof(char) == vertex_size(attribs.begin(), attribs.count()) ); | |
209 | |
210 currAttrib.set(kVec2f_GrVertexAttribType, attribs[0].fOffset + 4*sizeof( char)); | |
211 attribs.push_back(currAttrib); | |
212 GrAssert(4*sizeof(char) + 2*sizeof(float) == vertex_size(attribs.begin() , attribs.count())); | |
213 currAttrib.set(kVec3f_GrVertexAttribType, attribs[1].fOffset + 2*sizeof( float)); | |
214 attribs.push_back(currAttrib); | |
215 GrAssert(4*sizeof(char) + 2*sizeof(float) + 3*sizeof(float) == | |
216 vertex_size(attribs.begin(), attribs.count())); | |
217 currAttrib.set(kFloat_GrVertexAttribType, attribs[2].fOffset + 3*sizeof( float)); | |
218 attribs.push_back(currAttrib); | |
219 GrAssert(4*sizeof(char) + 2*sizeof(float) + 3*sizeof(float) + sizeof(flo at) == | |
220 vertex_size(attribs.begin(), attribs.count())); | |
221 currAttrib.set(kVec4f_GrVertexAttribType, attribs[3].fOffset + sizeof(fl oat)); | |
222 attribs.push_back(currAttrib); | |
223 GrAssert(4*sizeof(char) + 2*sizeof(float) + 3*sizeof(float) + sizeof(flo at) + 4*sizeof(float) == | |
224 vertex_size(attribs.begin(), attribs.count())); | |
225 } | |
226 } | |
227 | |
228 //////////////////////////////////////////////////////////////////////////////// | 167 //////////////////////////////////////////////////////////////////////////////// |
229 | 168 |
230 bool GrDrawState::srcAlphaWillBeOne(GrAttribBindings bindings) const { | 169 bool GrDrawState::srcAlphaWillBeOne() const { |
231 | |
232 uint32_t validComponentFlags; | 170 uint32_t validComponentFlags; |
233 GrColor color; | 171 GrColor color; |
234 // Check if per-vertex or constant color may have partial alpha | 172 // Check if per-vertex or constant color may have partial alpha |
235 if (bindings & kColor_AttribBindingsBit) { | 173 if (this->hasColorVertexAttribute()) { |
236 validComponentFlags = 0; | 174 validComponentFlags = 0; |
237 color = 0; // not strictly necessary but we get false alarms from tools about uninit. | 175 color = 0; // not strictly necessary but we get false alarms from tools about uninit. |
238 } else { | 176 } else { |
239 validComponentFlags = kRGBA_GrColorComponentFlags; | 177 validComponentFlags = kRGBA_GrColorComponentFlags; |
240 color = this->getColor(); | 178 color = this->getColor(); |
241 } | 179 } |
242 | 180 |
243 // Run through the color stages | 181 // Run through the color stages |
244 int stageCnt = getFirstCoverageStage(); | 182 int stageCnt = getFirstCoverageStage(); |
245 for (int s = 0; s < stageCnt; ++s) { | 183 for (int s = 0; s < stageCnt; ++s) { |
(...skipping 25 matching lines...) Expand all Loading... | |
271 for (int s = this->getFirstCoverageStage(); s < GrDrawState::kNumStages; ++s) { | 209 for (int s = this->getFirstCoverageStage(); s < GrDrawState::kNumStages; ++s) { |
272 const GrEffectRef* effect = this->getStage(s).getEffect(); | 210 const GrEffectRef* effect = this->getStage(s).getEffect(); |
273 if (NULL != effect) { | 211 if (NULL != effect) { |
274 (*effect)->getConstantColorComponents(&color, &validComponentFla gs); | 212 (*effect)->getConstantColorComponents(&color, &validComponentFla gs); |
275 } | 213 } |
276 } | 214 } |
277 } | 215 } |
278 return (kA_GrColorComponentFlag & validComponentFlags) && 0xff == GrColorUnp ackA(color); | 216 return (kA_GrColorComponentFlag & validComponentFlags) && 0xff == GrColorUnp ackA(color); |
279 } | 217 } |
280 | 218 |
281 bool GrDrawState::hasSolidCoverage(GrAttribBindings bindings) const { | 219 bool GrDrawState::hasSolidCoverage() const { |
282 // If we're drawing coverage directly then coverage is effectively treated a s color. | 220 // If we're drawing coverage directly then coverage is effectively treated a s color. |
283 if (this->isCoverageDrawing()) { | 221 if (this->isCoverageDrawing()) { |
284 return true; | 222 return true; |
285 } | 223 } |
286 | 224 |
287 GrColor coverage; | 225 GrColor coverage; |
288 uint32_t validComponentFlags; | 226 uint32_t validComponentFlags; |
289 // Initialize to an unknown starting coverage if per-vertex coverage is spec ified. | 227 // Initialize to an unknown starting coverage if per-vertex coverage is spec ified. |
290 if (bindings & kCoverage_AttribBindingsBit) { | 228 if (this->hasCoverageVertexAttribute()) { |
291 validComponentFlags = 0; | 229 validComponentFlags = 0; |
292 } else { | 230 } else { |
293 coverage = fCommon.fCoverage; | 231 coverage = fCommon.fCoverage; |
294 validComponentFlags = kRGBA_GrColorComponentFlags; | 232 validComponentFlags = kRGBA_GrColorComponentFlags; |
295 } | 233 } |
296 | 234 |
297 // Run through the coverage stages and see if the coverage will be all ones at the end. | 235 // Run through the coverage stages and see if the coverage will be all ones at the end. |
298 for (int s = this->getFirstCoverageStage(); s < GrDrawState::kNumStages; ++s ) { | 236 for (int s = this->getFirstCoverageStage(); s < GrDrawState::kNumStages; ++s ) { |
299 const GrEffectRef* effect = this->getStage(s).getEffect(); | 237 const GrEffectRef* effect = this->getStage(s).getEffect(); |
300 if (NULL != effect) { | 238 if (NULL != effect) { |
(...skipping 21 matching lines...) Expand all Loading... | |
322 */ | 260 */ |
323 return kOne_GrBlendCoeff == fCommon.fDstBlend || | 261 return kOne_GrBlendCoeff == fCommon.fDstBlend || |
324 kISA_GrBlendCoeff == fCommon.fDstBlend || | 262 kISA_GrBlendCoeff == fCommon.fDstBlend || |
325 kISC_GrBlendCoeff == fCommon.fDstBlend || | 263 kISC_GrBlendCoeff == fCommon.fDstBlend || |
326 this->isCoverageDrawing(); | 264 this->isCoverageDrawing(); |
327 } | 265 } |
328 | 266 |
329 GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, | 267 GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, |
330 GrBlendCoeff* srcCoeff, | 268 GrBlendCoeff* srcCoeff, |
331 GrBlendCoeff* dstCoeff) con st { | 269 GrBlendCoeff* dstCoeff) con st { |
332 GrAttribBindings bindings = this->getAttribBindings(); | |
333 | 270 |
334 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; | 271 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; |
335 if (NULL == srcCoeff) { | 272 if (NULL == srcCoeff) { |
336 srcCoeff = &bogusSrcCoeff; | 273 srcCoeff = &bogusSrcCoeff; |
337 } | 274 } |
338 *srcCoeff = this->getSrcBlendCoeff(); | 275 *srcCoeff = this->getSrcBlendCoeff(); |
339 | 276 |
340 if (NULL == dstCoeff) { | 277 if (NULL == dstCoeff) { |
341 dstCoeff = &bogusDstCoeff; | 278 dstCoeff = &bogusDstCoeff; |
342 } | 279 } |
343 *dstCoeff = this->getDstBlendCoeff(); | 280 *dstCoeff = this->getDstBlendCoeff(); |
344 | 281 |
345 if (this->isColorWriteDisabled()) { | 282 if (this->isColorWriteDisabled()) { |
346 *srcCoeff = kZero_GrBlendCoeff; | 283 *srcCoeff = kZero_GrBlendCoeff; |
347 *dstCoeff = kOne_GrBlendCoeff; | 284 *dstCoeff = kOne_GrBlendCoeff; |
348 } | 285 } |
349 | 286 |
350 bool srcAIsOne = this->srcAlphaWillBeOne(bindings); | 287 bool srcAIsOne = this->srcAlphaWillBeOne(); |
351 bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff || | 288 bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff || |
352 (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne); | 289 (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne); |
353 bool dstCoeffIsZero = kZero_GrBlendCoeff == *dstCoeff || | 290 bool dstCoeffIsZero = kZero_GrBlendCoeff == *dstCoeff || |
354 (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne); | 291 (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne); |
355 | 292 |
356 bool covIsZero = !this->isCoverageDrawing() && | 293 bool covIsZero = !this->isCoverageDrawing() && |
357 !(bindings & GrDrawState::kCoverage_AttribBindingsBit) && | 294 !this->hasCoverageVertexAttribute() && |
358 0 == this->getCoverage(); | 295 0 == this->getCoverage(); |
359 // When coeffs are (0,1) there is no reason to draw at all, unless | 296 // When coeffs are (0,1) there is no reason to draw at all, unless |
360 // stenciling is enabled. Having color writes disabled is effectively | 297 // stenciling is enabled. Having color writes disabled is effectively |
361 // (0,1). The same applies when coverage is known to be 0. | 298 // (0,1). The same applies when coverage is known to be 0. |
362 if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne) || covIsZero) { | 299 if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne) || covIsZero) { |
363 if (this->getStencil().doesWrite()) { | 300 if (this->getStencil().doesWrite()) { |
364 return kDisableBlend_BlendOptFlag | | 301 return kDisableBlend_BlendOptFlag | |
365 kEmitTransBlack_BlendOptFlag; | 302 kEmitTransBlack_BlendOptFlag; |
366 } else { | 303 } else { |
367 return kSkipDraw_BlendOptFlag; | 304 return kSkipDraw_BlendOptFlag; |
368 } | 305 } |
369 } | 306 } |
370 | 307 |
371 // check for coverage due to constant coverage, per-vertex coverage, or cove rage stage | 308 // check for coverage due to constant coverage, per-vertex coverage, or cove rage stage |
372 bool hasCoverage = forceCoverage || | 309 bool hasCoverage = forceCoverage || |
373 0xffffffff != this->getCoverage() || | 310 0xffffffff != this->getCoverage() || |
374 (bindings & GrDrawState::kCoverage_AttribBindingsBit); | 311 this->hasCoverageVertexAttribute(); |
375 for (int s = this->getFirstCoverageStage(); | 312 for (int s = this->getFirstCoverageStage(); !hasCoverage && s < GrDrawState: :kNumStages; ++s) { |
376 !hasCoverage && s < GrDrawState::kNumStages; | |
377 ++s) { | |
378 if (this->isStageEnabled(s)) { | 313 if (this->isStageEnabled(s)) { |
379 hasCoverage = true; | 314 hasCoverage = true; |
380 } | 315 } |
381 } | 316 } |
382 | 317 |
383 // if we don't have coverage we can check whether the dst | 318 // if we don't have coverage we can check whether the dst |
384 // has to read at all. If not, we'll disable blending. | 319 // has to read at all. If not, we'll disable blending. |
385 if (!hasCoverage) { | 320 if (!hasCoverage) { |
386 if (dstCoeffIsZero) { | 321 if (dstCoeffIsZero) { |
387 if (kOne_GrBlendCoeff == *srcCoeff) { | 322 if (kOne_GrBlendCoeff == *srcCoeff) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 } | 440 } |
506 fRestoreMask |= (1 << s); | 441 fRestoreMask |= (1 << s); |
507 GrEffectStage* stage = drawState->fStages + s; | 442 GrEffectStage* stage = drawState->fStages + s; |
508 stage->saveCoordChange(&fSavedCoordChanges[s]); | 443 stage->saveCoordChange(&fSavedCoordChanges[s]); |
509 stage->localCoordChange(invVM); | 444 stage->localCoordChange(invVM); |
510 } | 445 } |
511 } | 446 } |
512 drawState->viewMatrix()->reset(); | 447 drawState->viewMatrix()->reset(); |
513 return true; | 448 return true; |
514 } | 449 } |
OLD | NEW |