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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 3*sizeof(float), // kVec3_GrVertexAttribType | 52 3*sizeof(float), // kVec3_GrVertexAttribType |
53 4*sizeof(float), // kVec4_GrVertexAttribType | 53 4*sizeof(float), // kVec4_GrVertexAttribType |
54 4*sizeof(char) // kCVec4_GrVertexAttribType | 54 4*sizeof(char) // kCVec4_GrVertexAttribType |
55 }; | 55 }; |
56 | 56 |
57 static size_t vertex_size(const GrVertexAttrib* attribs, int count) { | 57 static size_t vertex_size(const GrVertexAttrib* attribs, int count) { |
58 // this works as long as we're 4 byte-aligned | 58 // this works as long as we're 4 byte-aligned |
59 #if GR_DEBUG | 59 #if GR_DEBUG |
60 uint32_t overlapCheck = 0; | 60 uint32_t overlapCheck = 0; |
61 #endif | 61 #endif |
62 GrAssert(count <= GrDrawState::kAttribIndexCount); | 62 GrAssert(count <= GrDrawState::kVertexAttribCnt); |
63 size_t size = 0; | 63 size_t size = 0; |
64 for (int index = 0; index < count; ++index) { | 64 for (int index = 0; index < count; ++index) { |
65 size_t attribSize = GrDrawState::kVertexAttribSizes[attribs[index].fType
]; | 65 size_t attribSize = GrDrawState::kVertexAttribSizes[attribs[index].fType
]; |
66 size += attribSize; | 66 size += attribSize; |
67 #if GR_DEBUG | 67 #if GR_DEBUG |
68 size_t dwordCount = attribSize >> 2; | 68 size_t dwordCount = attribSize >> 2; |
69 uint32_t mask = (1 << dwordCount)-1; | 69 uint32_t mask = (1 << dwordCount)-1; |
70 size_t offsetShift = attribs[index].fOffset >> 2; | 70 size_t offsetShift = attribs[index].fOffset >> 2; |
71 GrAssert(!(overlapCheck & (mask << offsetShift))); | 71 GrAssert(!(overlapCheck & (mask << offsetShift))); |
72 overlapCheck |= (mask << offsetShift); | 72 overlapCheck |= (mask << offsetShift); |
73 #endif | 73 #endif |
74 } | 74 } |
75 return size; | 75 return size; |
76 } | 76 } |
77 | 77 |
78 size_t GrDrawState::getVertexSize() const { | 78 size_t GrDrawState::getVertexSize() const { |
79 return vertex_size(fVertexAttribs.begin(), fVertexAttribs.count()); | 79 return vertex_size(fVertexAttribs.begin(), fVertexAttribs.count()); |
80 } | 80 } |
81 | 81 |
82 const GrAttribBindings GrDrawState::kAttribIndexMasks[kAttribIndexCount] = { | 82 const GrAttribBindings GrDrawState::kAttribIndexMasks[kAttribIndexCount] = { |
83 0, // position is not reflected in the bindings | 83 0, // position is not reflected in the bindings |
84 kColor_AttribBindingsBit, | 84 kColor_AttribBindingsBit, |
85 kCoverage_AttribBindingsBit, | 85 kCoverage_AttribBindingsBit, |
86 kEdge_AttribBindingsBit, | |
87 kLocalCoords_AttribBindingsBit, | 86 kLocalCoords_AttribBindingsBit, |
88 }; | 87 }; |
89 | 88 |
90 //////////////////////////////////////////////////////////////////////////////// | 89 //////////////////////////////////////////////////////////////////////////////// |
91 | 90 |
92 void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count) { | 91 void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count) { |
93 GrAssert(count <= GrDrawState::kAttribIndexCount); | 92 GrAssert(count <= GrDrawState::kVertexAttribCnt); |
94 fVertexAttribs.reset(); | 93 fVertexAttribs.reset(); |
95 for (int index = 0; index < count; ++index) { | 94 for (int index = 0; index < count; ++index) { |
96 fVertexAttribs.push_back(attribs[index]); | 95 fVertexAttribs.push_back(attribs[index]); |
97 } | 96 } |
98 } | 97 } |
99 | 98 |
100 //////////////////////////////////////////////////////////////////////////////// | 99 //////////////////////////////////////////////////////////////////////////////// |
101 | 100 |
102 void GrDrawState::setDefaultVertexAttribs() { | 101 void GrDrawState::setDefaultVertexAttribs() { |
103 static const GrVertexAttrib kPositionAttrib = {kVec2f_GrVertexAttribType, 0}
; | 102 static const GrVertexAttrib kPositionAttrib = {kVec2f_GrVertexAttribType, 0}
; |
(...skipping 29 matching lines...) Expand all Loading... |
133 if (attributeIndex >= kMaxValidAttribIndex) { | 132 if (attributeIndex >= kMaxValidAttribIndex) { |
134 return false; | 133 return false; |
135 } | 134 } |
136 // they should not be shared at all | 135 // they should not be shared at all |
137 if (attributeTypes[attributeIndex] != -1) { | 136 if (attributeTypes[attributeIndex] != -1) { |
138 return false; | 137 return false; |
139 } | 138 } |
140 attributeTypes[attributeIndex] = kBuiltInAttributeType; | 139 attributeTypes[attributeIndex] = kBuiltInAttributeType; |
141 } | 140 } |
142 } | 141 } |
143 for (int j = kEdge_AttribIndex; j < kAttribIndexCount; ++j) { | 142 if (fCommon.fAttribBindings & kAttribIndexMasks[kLocalCoords_AttribIndex]) { |
144 if (fCommon.fAttribBindings & kAttribIndexMasks[j]) { | 143 int attributeIndex = fAttribIndices[kLocalCoords_AttribIndex]; |
145 int attributeIndex = fAttribIndices[j]; | 144 if (attributeIndex >= kVertexAttribCnt) { |
146 if (attributeIndex >= kVertexAttribCnt) { | 145 return false; |
147 return false; | |
148 } | |
149 // they should not be shared at all | |
150 if (attributeTypes[attributeIndex] != -1) { | |
151 return false; | |
152 } | |
153 attributeTypes[attributeIndex] = kBuiltInAttributeType; | |
154 } | 146 } |
| 147 // they should not be shared at all |
| 148 if (attributeTypes[attributeIndex] != -1) { |
| 149 return false; |
| 150 } |
| 151 attributeTypes[attributeIndex] = kBuiltInAttributeType; |
155 } | 152 } |
156 | 153 |
157 // now those set by effects | 154 // now those set by effects |
158 for (int s = 0; s < kNumStages; ++s) { | 155 for (int s = 0; s < kNumStages; ++s) { |
159 const GrEffectStage& stage = fStages[s]; | 156 const GrEffectStage& stage = fStages[s]; |
160 const GrEffectRef* effect = stage.getEffect(); | 157 const GrEffectRef* effect = stage.getEffect(); |
161 if (effect == NULL) { | 158 if (effect == NULL) { |
162 continue; | 159 continue; |
163 } | 160 } |
164 | 161 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 // (0,1). The same applies when coverage is known to be 0. | 361 // (0,1). The same applies when coverage is known to be 0. |
365 if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne) || covIsZero) { | 362 if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne) || covIsZero) { |
366 if (this->getStencil().doesWrite()) { | 363 if (this->getStencil().doesWrite()) { |
367 return kDisableBlend_BlendOptFlag | | 364 return kDisableBlend_BlendOptFlag | |
368 kEmitTransBlack_BlendOptFlag; | 365 kEmitTransBlack_BlendOptFlag; |
369 } else { | 366 } else { |
370 return kSkipDraw_BlendOptFlag; | 367 return kSkipDraw_BlendOptFlag; |
371 } | 368 } |
372 } | 369 } |
373 | 370 |
374 // check for coverage due to constant coverage, per-vertex coverage, | 371 // check for coverage due to constant coverage, per-vertex coverage, or cove
rage stage |
375 // edge aa or coverage stage | |
376 bool hasCoverage = forceCoverage || | 372 bool hasCoverage = forceCoverage || |
377 0xffffffff != this->getCoverage() || | 373 0xffffffff != this->getCoverage() || |
378 (bindings & GrDrawState::kCoverage_AttribBindingsBit) || | 374 (bindings & GrDrawState::kCoverage_AttribBindingsBit); |
379 (bindings & GrDrawState::kEdge_AttribBindingsBit); | |
380 for (int s = this->getFirstCoverageStage(); | 375 for (int s = this->getFirstCoverageStage(); |
381 !hasCoverage && s < GrDrawState::kNumStages; | 376 !hasCoverage && s < GrDrawState::kNumStages; |
382 ++s) { | 377 ++s) { |
383 if (this->isStageEnabled(s)) { | 378 if (this->isStageEnabled(s)) { |
384 hasCoverage = true; | 379 hasCoverage = true; |
385 } | 380 } |
386 } | 381 } |
387 | 382 |
388 // if we don't have coverage we can check whether the dst | 383 // if we don't have coverage we can check whether the dst |
389 // has to read at all. If not, we'll disable blending. | 384 // has to read at all. If not, we'll disable blending. |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 } | 505 } |
511 fRestoreMask |= (1 << s); | 506 fRestoreMask |= (1 << s); |
512 GrEffectStage* stage = drawState->fStages + s; | 507 GrEffectStage* stage = drawState->fStages + s; |
513 stage->saveCoordChange(&fSavedCoordChanges[s]); | 508 stage->saveCoordChange(&fSavedCoordChanges[s]); |
514 stage->localCoordChange(invVM); | 509 stage->localCoordChange(invVM); |
515 } | 510 } |
516 } | 511 } |
517 drawState->viewMatrix()->reset(); | 512 drawState->viewMatrix()->reset(); |
518 return true; | 513 return true; |
519 } | 514 } |
OLD | NEW |