| 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 // check consistency of effects and attributes |
| 115 static const int kMaxValidAttribIndex = kVertexAttribCnt+2; | 124 GrSLType slTypes[kMaxVertexAttribCnt]; |
| 116 int attributeTypes[kMaxValidAttribIndex]; | 125 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { |
| 117 for (int i = 0; i < kMaxValidAttribIndex; ++i) { | 126 slTypes[i] = static_cast<GrSLType>(-1); |
| 118 attributeTypes[i] = -1; | |
| 119 } | 127 } |
| 128 for (int s = 0; s < kNumStages; ++s) { |
| 129 if (this->isStageEnabled(s)) { |
| 130 const GrEffectStage& stage = fStages[s]; |
| 131 const GrEffectRef* effect = stage.getEffect(); |
| 132 // make sure that any attribute indices have the correct binding typ
e, that the attrib |
| 133 // type and effect's shader lang type are compatible, and that attri
butes shared by |
| 134 // multiple effects use the same shader lang type. |
| 135 const int* attributeIndices = stage.getVertexAttribIndices(); |
| 136 int numAttributes = stage.getVertexAttribIndexCount(); |
| 137 for (int i = 0; i < numAttributes; ++i) { |
| 138 int attribIndex = attributeIndices[i]; |
| 139 if (attribIndex >= fCommon.fVertexAttribs.count() || |
| 140 kEffect_GrVertexAttribBinding != fCommon.fVertexAttribs[attr
ibIndex].fBinding) { |
| 141 return false; |
| 142 } |
| 120 | 143 |
| 121 // sentinel to make sure effects don't try to use built-in attributes | 144 GrSLType effectSLType = (*effect)->vertexAttribType(i); |
| 122 static const int kBuiltInAttributeType = 10000; | 145 GrVertexAttribType attribType = fCommon.fVertexAttribs[attribInd
ex].fType; |
| 123 | 146 int slVecCount = GrSLTypeVectorCount(effectSLType); |
| 124 // check our built-in indices | 147 int attribVecCount = GrVertexAttribTypeVectorCount(attribType); |
| 125 if (fAttribIndices[kPosition_AttribIndex] >= kVertexAttribCnt) { | 148 if (slVecCount != attribVecCount || |
| 126 return false; | 149 (-1 != slTypes[attribIndex] && slTypes[attribIndex] != effec
tSLType)) { |
| 127 } | 150 return false; |
| 128 attributeTypes[fAttribIndices[kPosition_AttribIndex]] = kBuiltInAttributeTyp
e; | 151 } |
| 129 for (int j = kColor_AttribIndex; j <= kCoverage_AttribIndex; ++j) { | 152 slTypes[attribIndex] = effectSLType; |
| 130 if (fCommon.fAttribBindings & kAttribIndexMasks[j]) { | |
| 131 int attributeIndex = fAttribIndices[j]; | |
| 132 if (attributeIndex >= kMaxValidAttribIndex) { | |
| 133 return false; | |
| 134 } | 153 } |
| 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 } | 154 } |
| 183 } | 155 } |
| 184 | 156 |
| 185 return true; | 157 return true; |
| 186 } | 158 } |
| 187 | 159 |
| 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 //////////////////////////////////////////////////////////////////////////////// | 160 //////////////////////////////////////////////////////////////////////////////// |
| 229 | 161 |
| 230 bool GrDrawState::srcAlphaWillBeOne(GrAttribBindings bindings) const { | 162 bool GrDrawState::srcAlphaWillBeOne() const { |
| 231 | |
| 232 uint32_t validComponentFlags; | 163 uint32_t validComponentFlags; |
| 233 GrColor color; | 164 GrColor color; |
| 234 // Check if per-vertex or constant color may have partial alpha | 165 // Check if per-vertex or constant color may have partial alpha |
| 235 if (bindings & kColor_AttribBindingsBit) { | 166 if (this->hasColorVertexAttribute()) { |
| 236 validComponentFlags = 0; | 167 validComponentFlags = 0; |
| 237 color = 0; // not strictly necessary but we get false alarms from tools
about uninit. | 168 color = 0; // not strictly necessary but we get false alarms from tools
about uninit. |
| 238 } else { | 169 } else { |
| 239 validComponentFlags = kRGBA_GrColorComponentFlags; | 170 validComponentFlags = kRGBA_GrColorComponentFlags; |
| 240 color = this->getColor(); | 171 color = this->getColor(); |
| 241 } | 172 } |
| 242 | 173 |
| 243 // Run through the color stages | 174 // Run through the color stages |
| 244 int stageCnt = getFirstCoverageStage(); | 175 int stageCnt = getFirstCoverageStage(); |
| 245 for (int s = 0; s < stageCnt; ++s) { | 176 for (int s = 0; s < stageCnt; ++s) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 271 for (int s = this->getFirstCoverageStage(); s < GrDrawState::kNumStages;
++s) { | 202 for (int s = this->getFirstCoverageStage(); s < GrDrawState::kNumStages;
++s) { |
| 272 const GrEffectRef* effect = this->getStage(s).getEffect(); | 203 const GrEffectRef* effect = this->getStage(s).getEffect(); |
| 273 if (NULL != effect) { | 204 if (NULL != effect) { |
| 274 (*effect)->getConstantColorComponents(&color, &validComponentFla
gs); | 205 (*effect)->getConstantColorComponents(&color, &validComponentFla
gs); |
| 275 } | 206 } |
| 276 } | 207 } |
| 277 } | 208 } |
| 278 return (kA_GrColorComponentFlag & validComponentFlags) && 0xff == GrColorUnp
ackA(color); | 209 return (kA_GrColorComponentFlag & validComponentFlags) && 0xff == GrColorUnp
ackA(color); |
| 279 } | 210 } |
| 280 | 211 |
| 281 bool GrDrawState::hasSolidCoverage(GrAttribBindings bindings) const { | 212 bool GrDrawState::hasSolidCoverage() const { |
| 282 // If we're drawing coverage directly then coverage is effectively treated a
s color. | 213 // If we're drawing coverage directly then coverage is effectively treated a
s color. |
| 283 if (this->isCoverageDrawing()) { | 214 if (this->isCoverageDrawing()) { |
| 284 return true; | 215 return true; |
| 285 } | 216 } |
| 286 | 217 |
| 287 GrColor coverage; | 218 GrColor coverage; |
| 288 uint32_t validComponentFlags; | 219 uint32_t validComponentFlags; |
| 289 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. | 220 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. |
| 290 if (bindings & kCoverage_AttribBindingsBit) { | 221 if (this->hasCoverageVertexAttribute()) { |
| 291 validComponentFlags = 0; | 222 validComponentFlags = 0; |
| 292 } else { | 223 } else { |
| 293 coverage = fCommon.fCoverage; | 224 coverage = fCommon.fCoverage; |
| 294 validComponentFlags = kRGBA_GrColorComponentFlags; | 225 validComponentFlags = kRGBA_GrColorComponentFlags; |
| 295 } | 226 } |
| 296 | 227 |
| 297 // Run through the coverage stages and see if the coverage will be all ones
at the end. | 228 // 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
) { | 229 for (int s = this->getFirstCoverageStage(); s < GrDrawState::kNumStages; ++s
) { |
| 299 const GrEffectRef* effect = this->getStage(s).getEffect(); | 230 const GrEffectRef* effect = this->getStage(s).getEffect(); |
| 300 if (NULL != effect) { | 231 if (NULL != effect) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 322 */ | 253 */ |
| 323 return kOne_GrBlendCoeff == fCommon.fDstBlend || | 254 return kOne_GrBlendCoeff == fCommon.fDstBlend || |
| 324 kISA_GrBlendCoeff == fCommon.fDstBlend || | 255 kISA_GrBlendCoeff == fCommon.fDstBlend || |
| 325 kISC_GrBlendCoeff == fCommon.fDstBlend || | 256 kISC_GrBlendCoeff == fCommon.fDstBlend || |
| 326 this->isCoverageDrawing(); | 257 this->isCoverageDrawing(); |
| 327 } | 258 } |
| 328 | 259 |
| 329 GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, | 260 GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, |
| 330 GrBlendCoeff* srcCoeff, | 261 GrBlendCoeff* srcCoeff, |
| 331 GrBlendCoeff* dstCoeff) con
st { | 262 GrBlendCoeff* dstCoeff) con
st { |
| 332 GrAttribBindings bindings = this->getAttribBindings(); | |
| 333 | 263 |
| 334 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; | 264 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; |
| 335 if (NULL == srcCoeff) { | 265 if (NULL == srcCoeff) { |
| 336 srcCoeff = &bogusSrcCoeff; | 266 srcCoeff = &bogusSrcCoeff; |
| 337 } | 267 } |
| 338 *srcCoeff = this->getSrcBlendCoeff(); | 268 *srcCoeff = this->getSrcBlendCoeff(); |
| 339 | 269 |
| 340 if (NULL == dstCoeff) { | 270 if (NULL == dstCoeff) { |
| 341 dstCoeff = &bogusDstCoeff; | 271 dstCoeff = &bogusDstCoeff; |
| 342 } | 272 } |
| 343 *dstCoeff = this->getDstBlendCoeff(); | 273 *dstCoeff = this->getDstBlendCoeff(); |
| 344 | 274 |
| 345 if (this->isColorWriteDisabled()) { | 275 if (this->isColorWriteDisabled()) { |
| 346 *srcCoeff = kZero_GrBlendCoeff; | 276 *srcCoeff = kZero_GrBlendCoeff; |
| 347 *dstCoeff = kOne_GrBlendCoeff; | 277 *dstCoeff = kOne_GrBlendCoeff; |
| 348 } | 278 } |
| 349 | 279 |
| 350 bool srcAIsOne = this->srcAlphaWillBeOne(bindings); | 280 bool srcAIsOne = this->srcAlphaWillBeOne(); |
| 351 bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff || | 281 bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff || |
| 352 (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne); | 282 (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne); |
| 353 bool dstCoeffIsZero = kZero_GrBlendCoeff == *dstCoeff || | 283 bool dstCoeffIsZero = kZero_GrBlendCoeff == *dstCoeff || |
| 354 (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne); | 284 (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne); |
| 355 | 285 |
| 356 bool covIsZero = !this->isCoverageDrawing() && | 286 bool covIsZero = !this->isCoverageDrawing() && |
| 357 !(bindings & GrDrawState::kCoverage_AttribBindingsBit) && | 287 !this->hasCoverageVertexAttribute() && |
| 358 0 == this->getCoverage(); | 288 0 == this->getCoverage(); |
| 359 // When coeffs are (0,1) there is no reason to draw at all, unless | 289 // When coeffs are (0,1) there is no reason to draw at all, unless |
| 360 // stenciling is enabled. Having color writes disabled is effectively | 290 // stenciling is enabled. Having color writes disabled is effectively |
| 361 // (0,1). The same applies when coverage is known to be 0. | 291 // (0,1). The same applies when coverage is known to be 0. |
| 362 if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne) || covIsZero) { | 292 if ((kZero_GrBlendCoeff == *srcCoeff && dstCoeffIsOne) || covIsZero) { |
| 363 if (this->getStencil().doesWrite()) { | 293 if (this->getStencil().doesWrite()) { |
| 364 return kDisableBlend_BlendOptFlag | | 294 return kDisableBlend_BlendOptFlag | |
| 365 kEmitTransBlack_BlendOptFlag; | 295 kEmitTransBlack_BlendOptFlag; |
| 366 } else { | 296 } else { |
| 367 return kSkipDraw_BlendOptFlag; | 297 return kSkipDraw_BlendOptFlag; |
| 368 } | 298 } |
| 369 } | 299 } |
| 370 | 300 |
| 371 // check for coverage due to constant coverage, per-vertex coverage, or cove
rage stage | 301 // check for coverage due to constant coverage, per-vertex coverage, or cove
rage stage |
| 372 bool hasCoverage = forceCoverage || | 302 bool hasCoverage = forceCoverage || |
| 373 0xffffffff != this->getCoverage() || | 303 0xffffffff != this->getCoverage() || |
| 374 (bindings & GrDrawState::kCoverage_AttribBindingsBit); | 304 this->hasCoverageVertexAttribute(); |
| 375 for (int s = this->getFirstCoverageStage(); | 305 for (int s = this->getFirstCoverageStage(); !hasCoverage && s < GrDrawState:
:kNumStages; ++s) { |
| 376 !hasCoverage && s < GrDrawState::kNumStages; | |
| 377 ++s) { | |
| 378 if (this->isStageEnabled(s)) { | 306 if (this->isStageEnabled(s)) { |
| 379 hasCoverage = true; | 307 hasCoverage = true; |
| 380 } | 308 } |
| 381 } | 309 } |
| 382 | 310 |
| 383 // if we don't have coverage we can check whether the dst | 311 // if we don't have coverage we can check whether the dst |
| 384 // has to read at all. If not, we'll disable blending. | 312 // has to read at all. If not, we'll disable blending. |
| 385 if (!hasCoverage) { | 313 if (!hasCoverage) { |
| 386 if (dstCoeffIsZero) { | 314 if (dstCoeffIsZero) { |
| 387 if (kOne_GrBlendCoeff == *srcCoeff) { | 315 if (kOne_GrBlendCoeff == *srcCoeff) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 } | 433 } |
| 506 fRestoreMask |= (1 << s); | 434 fRestoreMask |= (1 << s); |
| 507 GrEffectStage* stage = drawState->fStages + s; | 435 GrEffectStage* stage = drawState->fStages + s; |
| 508 stage->saveCoordChange(&fSavedCoordChanges[s]); | 436 stage->saveCoordChange(&fSavedCoordChanges[s]); |
| 509 stage->localCoordChange(invVM); | 437 stage->localCoordChange(invVM); |
| 510 } | 438 } |
| 511 } | 439 } |
| 512 drawState->viewMatrix()->reset(); | 440 drawState->viewMatrix()->reset(); |
| 513 return true; | 441 return true; |
| 514 } | 442 } |
| OLD | NEW |