Chromium Code Reviews| 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 | 52 |
| 53 // Enable the clip bit | 53 // Enable the clip bit |
| 54 this->enableState(GrDrawState::kClip_StateBit); | 54 this->enableState(GrDrawState::kClip_StateBit); |
| 55 | 55 |
| 56 this->setColor(paint.getColor()); | 56 this->setColor(paint.getColor()); |
| 57 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); | 57 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); |
| 58 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); | 58 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); |
| 59 | 59 |
| 60 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); | 60 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); |
| 61 this->setCoverage(paint.getCoverage()); | 61 this->setCoverage(paint.getCoverage()); |
| 62 fBlendOptFlags = kInvalid_BlendOptFlag; | |
| 62 } | 63 } |
| 63 | 64 |
| 64 //////////////////////////////////////////////////////////////////////////////// | 65 //////////////////////////////////////////////////////////////////////////////// |
| 65 | 66 |
| 66 static size_t vertex_size(const GrVertexAttrib* attribs, int count) { | 67 static size_t vertex_size(const GrVertexAttrib* attribs, int count) { |
| 67 // this works as long as we're 4 byte-aligned | 68 // this works as long as we're 4 byte-aligned |
| 68 #ifdef SK_DEBUG | 69 #ifdef SK_DEBUG |
| 69 uint32_t overlapCheck = 0; | 70 uint32_t overlapCheck = 0; |
| 70 #endif | 71 #endif |
| 71 SkASSERT(count <= GrDrawState::kMaxVertexAttribCnt); | 72 SkASSERT(count <= GrDrawState::kMaxVertexAttribCnt); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 fFixedFunctionVertexAttribIndices[attribs[i].fBinding] = i; | 113 fFixedFunctionVertexAttribIndices[attribs[i].fBinding] = i; |
| 113 } | 114 } |
| 114 #ifdef SK_DEBUG | 115 #ifdef SK_DEBUG |
| 115 size_t dwordCount = GrVertexAttribTypeSize(attribs[i].fType) >> 2; | 116 size_t dwordCount = GrVertexAttribTypeSize(attribs[i].fType) >> 2; |
| 116 uint32_t mask = (1 << dwordCount)-1; | 117 uint32_t mask = (1 << dwordCount)-1; |
| 117 size_t offsetShift = attribs[i].fOffset >> 2; | 118 size_t offsetShift = attribs[i].fOffset >> 2; |
| 118 SkASSERT(!(overlapCheck & (mask << offsetShift))); | 119 SkASSERT(!(overlapCheck & (mask << offsetShift))); |
| 119 overlapCheck |= (mask << offsetShift); | 120 overlapCheck |= (mask << offsetShift); |
| 120 #endif | 121 #endif |
| 121 } | 122 } |
| 123 fBlendOptFlags = kInvalid_BlendOptFlag; | |
| 122 // Positions must be specified. | 124 // Positions must be specified. |
| 123 SkASSERT(-1 != fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBin ding]); | 125 SkASSERT(-1 != fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBin ding]); |
| 124 } | 126 } |
| 125 | 127 |
| 126 //////////////////////////////////////////////////////////////////////////////// | 128 //////////////////////////////////////////////////////////////////////////////// |
| 127 | 129 |
| 128 void GrDrawState::setDefaultVertexAttribs() { | 130 void GrDrawState::setDefaultVertexAttribs() { |
| 129 static const GrVertexAttrib kPositionAttrib = | 131 static const GrVertexAttrib kPositionAttrib = |
| 130 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; | 132 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; |
| 131 | 133 |
| 132 fVAPtr = &kPositionAttrib; | 134 fVAPtr = &kPositionAttrib; |
| 133 fVACount = 1; | 135 fVACount = 1; |
| 134 | 136 |
| 135 // set all the fixed function indices to -1 except position. | 137 // set all the fixed function indices to -1 except position. |
| 136 memset(fFixedFunctionVertexAttribIndices, | 138 memset(fFixedFunctionVertexAttribIndices, |
| 137 0xff, | 139 0xff, |
| 138 sizeof(fFixedFunctionVertexAttribIndices)); | 140 sizeof(fFixedFunctionVertexAttribIndices)); |
| 139 fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0; | 141 fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0; |
| 142 fBlendOptFlags = kInvalid_BlendOptFlag; | |
| 140 } | 143 } |
| 141 | 144 |
| 142 //////////////////////////////////////////////////////////////////////////////// | 145 //////////////////////////////////////////////////////////////////////////////// |
| 143 | 146 |
| 144 bool GrDrawState::validateVertexAttribs() const { | 147 bool GrDrawState::validateVertexAttribs() const { |
| 145 // check consistency of effects and attributes | 148 // check consistency of effects and attributes |
| 146 GrSLType slTypes[kMaxVertexAttribCnt]; | 149 GrSLType slTypes[kMaxVertexAttribCnt]; |
| 147 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { | 150 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { |
| 148 slTypes[i] = static_cast<GrSLType>(-1); | 151 slTypes[i] = static_cast<GrSLType>(-1); |
| 149 } | 152 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 */ | 282 */ |
| 280 return kOne_GrBlendCoeff == fDstBlend || | 283 return kOne_GrBlendCoeff == fDstBlend || |
| 281 kISA_GrBlendCoeff == fDstBlend || | 284 kISA_GrBlendCoeff == fDstBlend || |
| 282 kISC_GrBlendCoeff == fDstBlend || | 285 kISC_GrBlendCoeff == fDstBlend || |
| 283 this->isCoverageDrawing(); | 286 this->isCoverageDrawing(); |
| 284 } | 287 } |
| 285 | 288 |
| 286 GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, | 289 GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, |
| 287 GrBlendCoeff* srcCoeff, | 290 GrBlendCoeff* srcCoeff, |
| 288 GrBlendCoeff* dstCoeff) con st { | 291 GrBlendCoeff* dstCoeff) con st { |
| 292 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; | |
| 293 if (NULL == srcCoeff) { | |
| 294 srcCoeff = &bogusSrcCoeff; | |
| 295 } | |
| 296 | |
| 297 if (NULL == dstCoeff) { | |
| 298 dstCoeff = &bogusDstCoeff; | |
| 299 } | |
| 300 | |
| 301 if (0 == (fBlendOptFlags & kInvalid_BlendOptFlag)) { | |
| 302 *srcCoeff = fOptSrcBlend; | |
| 303 *dstCoeff = fOptDstBlend; | |
| 304 return fBlendOptFlags; | |
| 305 } | |
| 306 | |
| 307 fBlendOptFlags = this->calcBlendOpts(forceCoverage, srcCoeff, dstCoeff); | |
| 308 fOptSrcBlend = *srcCoeff; | |
| 309 fOptDstBlend = *dstCoeff; | |
| 310 | |
| 311 return fBlendOptFlags; | |
| 312 } | |
| 313 | |
| 314 GrDrawState::BlendOptFlags GrDrawState::calcBlendOpts(bool forceCoverage, | |
| 315 GrBlendCoeff* srcCoeff, | |
| 316 GrBlendCoeff* dstCoeff) co nst { | |
| 289 | 317 |
| 290 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; | 318 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; |
| 291 if (NULL == srcCoeff) { | 319 if (NULL == srcCoeff) { |
| 292 srcCoeff = &bogusSrcCoeff; | 320 srcCoeff = &bogusSrcCoeff; |
|
bsalomon
2014/07/17 18:41:03
Seems like we don't need this anymore. Also if non
egdaniel
2014/07/17 19:35:50
I've actually already removed this in a follow up
| |
| 293 } | 321 } |
| 294 *srcCoeff = this->getSrcBlendCoeff(); | 322 *srcCoeff = this->getSrcBlendCoeff(); |
| 295 | 323 |
| 296 if (NULL == dstCoeff) { | 324 if (NULL == dstCoeff) { |
| 297 dstCoeff = &bogusDstCoeff; | 325 dstCoeff = &bogusDstCoeff; |
| 298 } | 326 } |
| 299 *dstCoeff = this->getDstBlendCoeff(); | 327 *dstCoeff = this->getDstBlendCoeff(); |
| 300 | 328 |
| 329 | |
| 301 if (this->isColorWriteDisabled()) { | 330 if (this->isColorWriteDisabled()) { |
| 302 *srcCoeff = kZero_GrBlendCoeff; | 331 *srcCoeff = kZero_GrBlendCoeff; |
| 303 *dstCoeff = kOne_GrBlendCoeff; | 332 *dstCoeff = kOne_GrBlendCoeff; |
| 304 } | 333 } |
| 305 | 334 |
| 306 bool srcAIsOne = this->srcAlphaWillBeOne(); | 335 bool srcAIsOne = this->srcAlphaWillBeOne(); |
| 307 bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff || | 336 bool dstCoeffIsOne = kOne_GrBlendCoeff == *dstCoeff || |
| 308 (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne); | 337 (kSA_GrBlendCoeff == *dstCoeff && srcAIsOne); |
| 309 bool dstCoeffIsZero = kZero_GrBlendCoeff == *dstCoeff || | 338 bool dstCoeffIsZero = kZero_GrBlendCoeff == *dstCoeff || |
| 310 (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne); | 339 (kISA_GrBlendCoeff == *dstCoeff && srcAIsOne); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); | 495 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); |
| 467 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); | 496 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); |
| 468 } | 497 } |
| 469 | 498 |
| 470 int numCoverageStages = fDrawState->numCoverageStages(); | 499 int numCoverageStages = fDrawState->numCoverageStages(); |
| 471 for (int s = 0; s < numCoverageStages; ++s, ++i) { | 500 for (int s = 0; s < numCoverageStages; ++s, ++i) { |
| 472 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); | 501 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); |
| 473 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); | 502 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); |
| 474 } | 503 } |
| 475 } | 504 } |
| OLD | NEW |