| 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 |
| 11 //////////////////////////////////////////////////////////////////////////////s | 11 //////////////////////////////////////////////////////////////////////////////s |
| 12 | 12 |
| 13 bool GrDrawState::State::HaveCompatibleState(const State& a, const State& b, |
| 14 bool explicitLocalCoords) { |
| 15 if (a.fColorStages.count() != b.fColorStages.count() || |
| 16 a.fCoverageStages.count() != b.fCoverageStages.count() || |
| 17 a.fSrcBlend != b.fSrcBlend || |
| 18 a.fDstBlend != b.fDstBlend) { |
| 19 return false; |
| 20 } |
| 21 for (int i = 0; i < a.fColorStages.count(); i++) { |
| 22 if (!GrEffectStage::AreCompatible(a.fColorStages[i], b.fColorStages[i], |
| 23 explicitLocalCoords)) { |
| 24 return false; |
| 25 } |
| 26 } |
| 27 for (int i = 0; i < a.fCoverageStages.count(); i++) { |
| 28 if (!GrEffectStage::AreCompatible(a.fCoverageStages[i], b.fCoverageStage
s[i], |
| 29 explicitLocalCoords)) { |
| 30 return false; |
| 31 } |
| 32 } |
| 33 return true; |
| 34 } |
| 35 //////////////////////////////////////////////////////////////////////////////s |
| 13 GrDrawState::CombinedState GrDrawState::CombineIfPossible( | 36 GrDrawState::CombinedState GrDrawState::CombineIfPossible( |
| 14 const GrDrawState& a, const GrDrawState& b) { | 37 const GrDrawState& a, const GrDrawState& b) { |
| 15 | 38 |
| 16 bool usingVertexColors = a.hasColorVertexAttribute(); | 39 bool usingVertexColors = a.hasColorVertexAttribute(); |
| 17 if (!usingVertexColors && a.fColor != b.fColor) { | 40 if (!usingVertexColors && a.fColor != b.fColor) { |
| 18 return kIncompatible_CombinedState; | 41 return kIncompatible_CombinedState; |
| 19 } | 42 } |
| 20 | 43 |
| 21 if (a.fRenderTarget.get() != b.fRenderTarget.get() || | 44 if (a.fRenderTarget.get() != b.fRenderTarget.get() || |
| 22 a.fColorStages.count() != b.fColorStages.count() || | |
| 23 a.fCoverageStages.count() != b.fCoverageStages.count() || | |
| 24 !a.fViewMatrix.cheapEqualTo(b.fViewMatrix) || | 45 !a.fViewMatrix.cheapEqualTo(b.fViewMatrix) || |
| 25 a.fSrcBlend != b.fSrcBlend || | |
| 26 a.fDstBlend != b.fDstBlend || | |
| 27 a.fBlendConstant != b.fBlendConstant || | 46 a.fBlendConstant != b.fBlendConstant || |
| 28 a.fFlagBits != b.fFlagBits || | 47 a.fFlagBits != b.fFlagBits || |
| 29 a.fVACount != b.fVACount || | 48 a.fVACount != b.fVACount || |
| 30 memcmp(a.fVAPtr, b.fVAPtr, a.fVACount * sizeof(GrVertexAttrib)) || | 49 memcmp(a.fVAPtr, b.fVAPtr, a.fVACount * sizeof(GrVertexAttrib)) || |
| 31 a.fStencilSettings != b.fStencilSettings || | 50 a.fStencilSettings != b.fStencilSettings || |
| 32 a.fDrawFace != b.fDrawFace) { | 51 a.fDrawFace != b.fDrawFace) { |
| 33 return kIncompatible_CombinedState; | 52 return kIncompatible_CombinedState; |
| 34 } | 53 } |
| 35 | 54 |
| 36 bool usingVertexCoverage = a.hasCoverageVertexAttribute(); | 55 bool usingVertexCoverage = a.hasCoverageVertexAttribute(); |
| 37 if (!usingVertexCoverage && a.fCoverage != b.fCoverage) { | 56 if (!usingVertexCoverage && a.fCoverage != b.fCoverage) { |
| 38 return kIncompatible_CombinedState; | 57 return kIncompatible_CombinedState; |
| 39 } | 58 } |
| 40 | 59 |
| 41 bool explicitLocalCoords = a.hasLocalCoordAttribute(); | 60 bool explicitLocalCoords = a.hasLocalCoordAttribute(); |
| 42 for (int i = 0; i < a.fColorStages.count(); i++) { | 61 |
| 43 if (!GrEffectStage::AreCompatible(a.fColorStages[i], b.fColorStages[i], | |
| 44 explicitLocalCoords)) { | |
| 45 return kIncompatible_CombinedState; | |
| 46 } | |
| 47 } | |
| 48 for (int i = 0; i < a.fCoverageStages.count(); i++) { | |
| 49 if (!GrEffectStage::AreCompatible(a.fCoverageStages[i], b.fCoverageStage
s[i], | |
| 50 explicitLocalCoords)) { | |
| 51 return kIncompatible_CombinedState; | |
| 52 } | |
| 53 } | |
| 54 SkASSERT(0 == memcmp(a.fFixedFunctionVertexAttribIndices, | 62 SkASSERT(0 == memcmp(a.fFixedFunctionVertexAttribIndices, |
| 55 b.fFixedFunctionVertexAttribIndices, | 63 b.fFixedFunctionVertexAttribIndices, |
| 56 sizeof(a.fFixedFunctionVertexAttribIndices))); | 64 sizeof(a.fFixedFunctionVertexAttribIndices))); |
| 65 if (!State::HaveCompatibleState(a.fState, b.fState, explicitLocalCoords)) { |
| 66 return kIncompatible_CombinedState; |
| 67 } |
| 57 return kAOrB_CombinedState; | 68 return kAOrB_CombinedState; |
| 58 } | 69 } |
| 59 | 70 |
| 60 | 71 |
| 61 //////////////////////////////////////////////////////////////////////////////s | 72 //////////////////////////////////////////////////////////////////////////////s |
| 62 | 73 |
| 63 GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatr
ix) { | 74 GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatr
ix) { |
| 64 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 75 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
| 65 *this = state; | 76 *this = state; |
| 66 if (!preConcatMatrix.isIdentity()) { | 77 if (!preConcatMatrix.isIdentity()) { |
| 67 for (int i = 0; i < fColorStages.count(); ++i) { | 78 for (int i = 0; i < this->numColorStages(); ++i) { |
| 68 fColorStages[i].localCoordChange(preConcatMatrix); | 79 fState.fColorStages[i].localCoordChange(preConcatMatrix); |
| 69 } | 80 } |
| 70 for (int i = 0; i < fCoverageStages.count(); ++i) { | 81 for (int i = 0; i < this->numCoverageStages(); ++i) { |
| 71 fCoverageStages[i].localCoordChange(preConcatMatrix); | 82 fState.fCoverageStages[i].localCoordChange(preConcatMatrix); |
| 72 } | 83 } |
| 73 this->invalidateBlendOptFlags(); | 84 this->invalidateBlendOptFlags(); |
| 74 } | 85 } |
| 75 } | 86 } |
| 76 | 87 |
| 77 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { | 88 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { |
| 78 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 89 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
| 79 this->setRenderTarget(that.fRenderTarget.get()); | 90 this->setRenderTarget(that.fRenderTarget.get()); |
| 80 fColor = that.fColor; | 91 fColor = that.fColor; |
| 81 fViewMatrix = that.fViewMatrix; | 92 fViewMatrix = that.fViewMatrix; |
| 82 fSrcBlend = that.fSrcBlend; | |
| 83 fDstBlend = that.fDstBlend; | |
| 84 fBlendConstant = that.fBlendConstant; | 93 fBlendConstant = that.fBlendConstant; |
| 85 fFlagBits = that.fFlagBits; | 94 fFlagBits = that.fFlagBits; |
| 86 fVACount = that.fVACount; | 95 fVACount = that.fVACount; |
| 87 fVAPtr = that.fVAPtr; | 96 fVAPtr = that.fVAPtr; |
| 88 fStencilSettings = that.fStencilSettings; | 97 fStencilSettings = that.fStencilSettings; |
| 89 fCoverage = that.fCoverage; | 98 fCoverage = that.fCoverage; |
| 90 fDrawFace = that.fDrawFace; | 99 fDrawFace = that.fDrawFace; |
| 91 fColorStages = that.fColorStages; | |
| 92 fCoverageStages = that.fCoverageStages; | |
| 93 fOptSrcBlend = that.fOptSrcBlend; | 100 fOptSrcBlend = that.fOptSrcBlend; |
| 94 fOptDstBlend = that.fOptDstBlend; | 101 fOptDstBlend = that.fOptDstBlend; |
| 95 fBlendOptFlags = that.fBlendOptFlags; | 102 fBlendOptFlags = that.fBlendOptFlags; |
| 96 | 103 |
| 104 fState = that.fState; |
| 105 |
| 97 memcpy(fFixedFunctionVertexAttribIndices, | 106 memcpy(fFixedFunctionVertexAttribIndices, |
| 98 that.fFixedFunctionVertexAttribIndices, | 107 that.fFixedFunctionVertexAttribIndices, |
| 99 sizeof(fFixedFunctionVertexAttribIndices)); | 108 sizeof(fFixedFunctionVertexAttribIndices)); |
| 100 return *this; | 109 return *this; |
| 101 } | 110 } |
| 102 | 111 |
| 103 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { | 112 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { |
| 104 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 113 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
| 105 fColorStages.reset(); | 114 fState.reset(); |
| 106 fCoverageStages.reset(); | |
| 107 | 115 |
| 108 fRenderTarget.reset(NULL); | 116 fRenderTarget.reset(NULL); |
| 109 | 117 |
| 110 this->setDefaultVertexAttribs(); | 118 this->setDefaultVertexAttribs(); |
| 111 | 119 |
| 112 fColor = 0xffffffff; | 120 fColor = 0xffffffff; |
| 113 if (NULL == initialViewMatrix) { | 121 if (NULL == initialViewMatrix) { |
| 114 fViewMatrix.reset(); | 122 fViewMatrix.reset(); |
| 115 } else { | 123 } else { |
| 116 fViewMatrix = *initialViewMatrix; | 124 fViewMatrix = *initialViewMatrix; |
| 117 } | 125 } |
| 118 fSrcBlend = kOne_GrBlendCoeff; | |
| 119 fDstBlend = kZero_GrBlendCoeff; | |
| 120 fBlendConstant = 0x0; | 126 fBlendConstant = 0x0; |
| 121 fFlagBits = 0x0; | 127 fFlagBits = 0x0; |
| 122 fStencilSettings.setDisabled(); | 128 fStencilSettings.setDisabled(); |
| 123 fCoverage = 0xffffffff; | 129 fCoverage = 0xffffffff; |
| 124 fDrawFace = kBoth_DrawFace; | 130 fDrawFace = kBoth_DrawFace; |
| 125 | 131 |
| 126 this->invalidateBlendOptFlags(); | 132 this->invalidateBlendOptFlags(); |
| 127 } | 133 } |
| 128 | 134 |
| 129 bool GrDrawState::setIdentityViewMatrix() { | 135 bool GrDrawState::setIdentityViewMatrix() { |
| 130 if (fColorStages.count() || fCoverageStages.count()) { | 136 if (this->numTotalStages()) { |
| 131 SkMatrix invVM; | 137 SkMatrix invVM; |
| 132 if (!fViewMatrix.invert(&invVM)) { | 138 if (!fViewMatrix.invert(&invVM)) { |
| 133 // sad trombone sound | 139 // sad trombone sound |
| 134 return false; | 140 return false; |
| 135 } | 141 } |
| 136 for (int s = 0; s < fColorStages.count(); ++s) { | 142 for (int s = 0; s < this->numColorStages(); ++s) { |
| 137 fColorStages[s].localCoordChange(invVM); | 143 fState.fColorStages[s].localCoordChange(invVM); |
| 138 } | 144 } |
| 139 for (int s = 0; s < fCoverageStages.count(); ++s) { | 145 for (int s = 0; s < this->numCoverageStages(); ++s) { |
| 140 fCoverageStages[s].localCoordChange(invVM); | 146 fState.fCoverageStages[s].localCoordChange(invVM); |
| 141 } | 147 } |
| 142 } | 148 } |
| 143 fViewMatrix.reset(); | 149 fViewMatrix.reset(); |
| 144 return true; | 150 return true; |
| 145 } | 151 } |
| 146 | 152 |
| 147 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende
rTarget* rt) { | 153 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende
rTarget* rt) { |
| 148 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 154 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
| 149 | 155 |
| 150 fColorStages.reset(); | 156 fState.reset(); |
| 151 fCoverageStages.reset(); | |
| 152 | 157 |
| 153 for (int i = 0; i < paint.numColorStages(); ++i) { | 158 for (int i = 0; i < paint.numColorStages(); ++i) { |
| 154 fColorStages.push_back(paint.getColorStage(i)); | 159 fState.fColorStages.push_back(paint.getColorStage(i)); |
| 155 } | 160 } |
| 156 | 161 |
| 157 for (int i = 0; i < paint.numCoverageStages(); ++i) { | 162 for (int i = 0; i < paint.numCoverageStages(); ++i) { |
| 158 fCoverageStages.push_back(paint.getCoverageStage(i)); | 163 fState.fCoverageStages.push_back(paint.getCoverageStage(i)); |
| 159 } | 164 } |
| 160 | 165 |
| 161 this->setRenderTarget(rt); | 166 this->setRenderTarget(rt); |
| 162 | 167 |
| 163 fViewMatrix = vm; | 168 fViewMatrix = vm; |
| 164 | 169 |
| 165 // These have no equivalent in GrPaint, set them to defaults | 170 // These have no equivalent in GrPaint, set them to defaults |
| 166 fBlendConstant = 0x0; | 171 fBlendConstant = 0x0; |
| 167 fDrawFace = kBoth_DrawFace; | 172 fDrawFace = kBoth_DrawFace; |
| 168 fStencilSettings.setDisabled(); | 173 fStencilSettings.setDisabled(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 } | 266 } |
| 262 | 267 |
| 263 //////////////////////////////////////////////////////////////////////////////// | 268 //////////////////////////////////////////////////////////////////////////////// |
| 264 | 269 |
| 265 bool GrDrawState::validateVertexAttribs() const { | 270 bool GrDrawState::validateVertexAttribs() const { |
| 266 // check consistency of effects and attributes | 271 // check consistency of effects and attributes |
| 267 GrSLType slTypes[kMaxVertexAttribCnt]; | 272 GrSLType slTypes[kMaxVertexAttribCnt]; |
| 268 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { | 273 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { |
| 269 slTypes[i] = static_cast<GrSLType>(-1); | 274 slTypes[i] = static_cast<GrSLType>(-1); |
| 270 } | 275 } |
| 271 int totalStages = fColorStages.count() + fCoverageStages.count(); | 276 int totalStages = this->numTotalStages(); |
| 272 for (int s = 0; s < totalStages; ++s) { | 277 for (int s = 0; s < totalStages; ++s) { |
| 273 int covIdx = s - fColorStages.count(); | 278 int covIdx = s - this->numColorStages(); |
| 274 const GrEffectStage& stage = covIdx < 0 ? fColorStages[s] : fCoverageSta
ges[covIdx]; | 279 const GrEffectStage& stage = covIdx < 0 ? this->getColorStage(s) : |
| 280 this->getCoverageStage(covIdx)
; |
| 275 const GrEffect* effect = stage.getEffect(); | 281 const GrEffect* effect = stage.getEffect(); |
| 276 SkASSERT(NULL != effect); | 282 SkASSERT(NULL != effect); |
| 277 // make sure that any attribute indices have the correct binding type, t
hat the attrib | 283 // make sure that any attribute indices have the correct binding type, t
hat the attrib |
| 278 // type and effect's shader lang type are compatible, and that attribute
s shared by | 284 // type and effect's shader lang type are compatible, and that attribute
s shared by |
| 279 // multiple effects use the same shader lang type. | 285 // multiple effects use the same shader lang type. |
| 280 const int* attributeIndices = stage.getVertexAttribIndices(); | 286 const int* attributeIndices = stage.getVertexAttribIndices(); |
| 281 int numAttributes = stage.getVertexAttribIndexCount(); | 287 int numAttributes = stage.getVertexAttribIndexCount(); |
| 282 for (int i = 0; i < numAttributes; ++i) { | 288 for (int i = 0; i < numAttributes; ++i) { |
| 283 int attribIndex = attributeIndices[i]; | 289 int attribIndex = attributeIndices[i]; |
| 284 if (attribIndex >= fVACount || | 290 if (attribIndex >= fVACount || |
| (...skipping 12 matching lines...) Expand all Loading... |
| 297 } | 303 } |
| 298 slTypes[attribIndex] = effectSLType; | 304 slTypes[attribIndex] = effectSLType; |
| 299 } | 305 } |
| 300 } | 306 } |
| 301 | 307 |
| 302 return true; | 308 return true; |
| 303 } | 309 } |
| 304 | 310 |
| 305 bool GrDrawState::willEffectReadDstColor() const { | 311 bool GrDrawState::willEffectReadDstColor() const { |
| 306 if (!this->isColorWriteDisabled()) { | 312 if (!this->isColorWriteDisabled()) { |
| 307 for (int s = 0; s < fColorStages.count(); ++s) { | 313 for (int s = 0; s < this->numColorStages(); ++s) { |
| 308 if (fColorStages[s].getEffect()->willReadDstColor()) { | 314 if (this->getColorStage(s).getEffect()->willReadDstColor()) { |
| 309 return true; | 315 return true; |
| 310 } | 316 } |
| 311 } | 317 } |
| 312 } | 318 } |
| 313 for (int s = 0; s < fCoverageStages.count(); ++s) { | 319 for (int s = 0; s < this->numCoverageStages(); ++s) { |
| 314 if (fCoverageStages[s].getEffect()->willReadDstColor()) { | 320 if (this->getCoverageStage(s).getEffect()->willReadDstColor()) { |
| 315 return true; | 321 return true; |
| 316 } | 322 } |
| 317 } | 323 } |
| 318 return false; | 324 return false; |
| 319 } | 325 } |
| 320 | 326 |
| 321 //////////////////////////////////////////////////////////////////////////////// | 327 //////////////////////////////////////////////////////////////////////////////// |
| 322 | 328 |
| 323 bool GrDrawState::srcAlphaWillBeOne() const { | 329 bool GrDrawState::srcAlphaWillBeOne() const { |
| 324 uint32_t validComponentFlags; | 330 uint32_t validComponentFlags; |
| 325 GrColor color; | 331 GrColor color; |
| 326 // Check if per-vertex or constant color may have partial alpha | 332 // Check if per-vertex or constant color may have partial alpha |
| 327 if (this->hasColorVertexAttribute()) { | 333 if (this->hasColorVertexAttribute()) { |
| 328 validComponentFlags = 0; | 334 validComponentFlags = 0; |
| 329 color = 0; // not strictly necessary but we get false alarms from tools
about uninit. | 335 color = 0; // not strictly necessary but we get false alarms from tools
about uninit. |
| 330 } else { | 336 } else { |
| 331 validComponentFlags = kRGBA_GrColorComponentFlags; | 337 validComponentFlags = kRGBA_GrColorComponentFlags; |
| 332 color = this->getColor(); | 338 color = this->getColor(); |
| 333 } | 339 } |
| 334 | 340 |
| 335 // Run through the color stages | 341 // Run through the color stages |
| 336 for (int s = 0; s < fColorStages.count(); ++s) { | 342 for (int s = 0; s < this->numColorStages(); ++s) { |
| 337 const GrEffect* effect = fColorStages[s].getEffect(); | 343 const GrEffect* effect = this->getColorStage(s).getEffect(); |
| 338 effect->getConstantColorComponents(&color, &validComponentFlags); | 344 effect->getConstantColorComponents(&color, &validComponentFlags); |
| 339 } | 345 } |
| 340 | 346 |
| 341 // Check whether coverage is treated as color. If so we run through the cove
rage computation. | 347 // Check whether coverage is treated as color. If so we run through the cove
rage computation. |
| 342 if (this->isCoverageDrawing()) { | 348 if (this->isCoverageDrawing()) { |
| 343 GrColor coverageColor = this->getCoverageColor(); | 349 GrColor coverageColor = this->getCoverageColor(); |
| 344 GrColor oldColor = color; | 350 GrColor oldColor = color; |
| 345 color = 0; | 351 color = 0; |
| 346 for (int c = 0; c < 4; ++c) { | 352 for (int c = 0; c < 4; ++c) { |
| 347 if (validComponentFlags & (1 << c)) { | 353 if (validComponentFlags & (1 << c)) { |
| 348 U8CPU a = (oldColor >> (c * 8)) & 0xff; | 354 U8CPU a = (oldColor >> (c * 8)) & 0xff; |
| 349 U8CPU b = (coverageColor >> (c * 8)) & 0xff; | 355 U8CPU b = (coverageColor >> (c * 8)) & 0xff; |
| 350 color |= (SkMulDiv255Round(a, b) << (c * 8)); | 356 color |= (SkMulDiv255Round(a, b) << (c * 8)); |
| 351 } | 357 } |
| 352 } | 358 } |
| 353 for (int s = 0; s < fCoverageStages.count(); ++s) { | 359 for (int s = 0; s < this->numCoverageStages(); ++s) { |
| 354 const GrEffect* effect = fCoverageStages[s].getEffect(); | 360 const GrEffect* effect = this->getCoverageStage(s).getEffect(); |
| 355 effect->getConstantColorComponents(&color, &validComponentFlags); | 361 effect->getConstantColorComponents(&color, &validComponentFlags); |
| 356 } | 362 } |
| 357 } | 363 } |
| 358 return (kA_GrColorComponentFlag & validComponentFlags) && 0xff == GrColorUnp
ackA(color); | 364 return (kA_GrColorComponentFlag & validComponentFlags) && 0xff == GrColorUnp
ackA(color); |
| 359 } | 365 } |
| 360 | 366 |
| 361 bool GrDrawState::hasSolidCoverage() const { | 367 bool GrDrawState::hasSolidCoverage() const { |
| 362 // If we're drawing coverage directly then coverage is effectively treated a
s color. | 368 // If we're drawing coverage directly then coverage is effectively treated a
s color. |
| 363 if (this->isCoverageDrawing()) { | 369 if (this->isCoverageDrawing()) { |
| 364 return true; | 370 return true; |
| 365 } | 371 } |
| 366 | 372 |
| 367 GrColor coverage; | 373 GrColor coverage; |
| 368 uint32_t validComponentFlags; | 374 uint32_t validComponentFlags; |
| 369 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. | 375 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. |
| 370 if (this->hasCoverageVertexAttribute()) { | 376 if (this->hasCoverageVertexAttribute()) { |
| 371 validComponentFlags = 0; | 377 validComponentFlags = 0; |
| 372 } else { | 378 } else { |
| 373 coverage = fCoverage; | 379 coverage = fCoverage; |
| 374 validComponentFlags = kRGBA_GrColorComponentFlags; | 380 validComponentFlags = kRGBA_GrColorComponentFlags; |
| 375 } | 381 } |
| 376 | 382 |
| 377 // Run through the coverage stages and see if the coverage will be all ones
at the end. | 383 // Run through the coverage stages and see if the coverage will be all ones
at the end. |
| 378 for (int s = 0; s < fCoverageStages.count(); ++s) { | 384 for (int s = 0; s < this->numCoverageStages(); ++s) { |
| 379 const GrEffect* effect = fCoverageStages[s].getEffect(); | 385 const GrEffect* effect = this->getCoverageStage(s).getEffect(); |
| 380 effect->getConstantColorComponents(&coverage, &validComponentFlags); | 386 effect->getConstantColorComponents(&coverage, &validComponentFlags); |
| 381 } | 387 } |
| 382 return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff =
= coverage); | 388 return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff =
= coverage); |
| 383 } | 389 } |
| 384 | 390 |
| 385 //////////////////////////////////////////////////////////////////////////////// | 391 //////////////////////////////////////////////////////////////////////////////// |
| 386 | 392 |
| 387 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while | 393 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while |
| 388 // others will blend incorrectly. | 394 // others will blend incorrectly. |
| 389 bool GrDrawState::canTweakAlphaForCoverage() const { | 395 bool GrDrawState::canTweakAlphaForCoverage() const { |
| 390 /* | 396 /* |
| 391 The fractional coverage is f. | 397 The fractional coverage is f. |
| 392 The src and dst coeffs are Cs and Cd. | 398 The src and dst coeffs are Cs and Cd. |
| 393 The dst and src colors are S and D. | 399 The dst and src colors are S and D. |
| 394 We want the blend to compute: f*Cs*S + (f*Cd + (1-f))D. By tweaking the sou
rce color's alpha | 400 We want the blend to compute: f*Cs*S + (f*Cd + (1-f))D. By tweaking the sou
rce color's alpha |
| 395 we're replacing S with S'=fS. It's obvious that that first term will always
be ok. The second | 401 we're replacing S with S'=fS. It's obvious that that first term will always
be ok. The second |
| 396 term can be rearranged as [1-(1-Cd)f]D. By substituting in the various poss
ibilities for Cd we | 402 term can be rearranged as [1-(1-Cd)f]D. By substituting in the various poss
ibilities for Cd we |
| 397 find that only 1, ISA, and ISC produce the correct destination when applied
to S' and D. | 403 find that only 1, ISA, and ISC produce the correct destination when applied
to S' and D. |
| 398 Also, if we're directly rendering coverage (isCoverageDrawing) then coverag
e is treated as | 404 Also, if we're directly rendering coverage (isCoverageDrawing) then coverag
e is treated as |
| 399 color by definition. | 405 color by definition. |
| 400 */ | 406 */ |
| 401 return kOne_GrBlendCoeff == fDstBlend || | 407 return kOne_GrBlendCoeff == fState.fDstBlend || |
| 402 kISA_GrBlendCoeff == fDstBlend || | 408 kISA_GrBlendCoeff == fState.fDstBlend || |
| 403 kISC_GrBlendCoeff == fDstBlend || | 409 kISC_GrBlendCoeff == fState.fDstBlend || |
| 404 this->isCoverageDrawing(); | 410 this->isCoverageDrawing(); |
| 405 } | 411 } |
| 406 | 412 |
| 407 GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, | 413 GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, |
| 408 GrBlendCoeff* srcCoeff, | 414 GrBlendCoeff* srcCoeff, |
| 409 GrBlendCoeff* dstCoeff) con
st { | 415 GrBlendCoeff* dstCoeff) con
st { |
| 410 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; | 416 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; |
| 411 if (NULL == srcCoeff) { | 417 if (NULL == srcCoeff) { |
| 412 srcCoeff = &bogusSrcCoeff; | 418 srcCoeff = &bogusSrcCoeff; |
| 413 } | 419 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 return kEmitCoverage_BlendOptFlag; | 466 return kEmitCoverage_BlendOptFlag; |
| 461 } else { | 467 } else { |
| 462 return kSkipDraw_BlendOptFlag; | 468 return kSkipDraw_BlendOptFlag; |
| 463 } | 469 } |
| 464 } | 470 } |
| 465 | 471 |
| 466 // check for coverage due to constant coverage, per-vertex coverage, or cove
rage stage | 472 // check for coverage due to constant coverage, per-vertex coverage, or cove
rage stage |
| 467 bool hasCoverage = forceCoverage || | 473 bool hasCoverage = forceCoverage || |
| 468 0xffffffff != this->getCoverageColor() || | 474 0xffffffff != this->getCoverageColor() || |
| 469 this->hasCoverageVertexAttribute() || | 475 this->hasCoverageVertexAttribute() || |
| 470 fCoverageStages.count() > 0; | 476 this->numCoverageStages() > 0; |
| 471 | 477 |
| 472 // if we don't have coverage we can check whether the dst | 478 // if we don't have coverage we can check whether the dst |
| 473 // has to read at all. If not, we'll disable blending. | 479 // has to read at all. If not, we'll disable blending. |
| 474 if (!hasCoverage) { | 480 if (!hasCoverage) { |
| 475 if (dstCoeffIsZero) { | 481 if (dstCoeffIsZero) { |
| 476 if (kOne_GrBlendCoeff == *srcCoeff) { | 482 if (kOne_GrBlendCoeff == *srcCoeff) { |
| 477 // if there is no coverage and coeffs are (1,0) then we | 483 // if there is no coverage and coeffs are (1,0) then we |
| 478 // won't need to read the dst at all, it gets replaced by src | 484 // won't need to read the dst at all, it gets replaced by src |
| 479 *dstCoeff = kZero_GrBlendCoeff; | 485 *dstCoeff = kZero_GrBlendCoeff; |
| 480 return kNone_BlendOpt; | 486 return kNone_BlendOpt; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 fDrawState = drawState; | 543 fDrawState = drawState; |
| 538 fVAPtr = drawState->fVAPtr; | 544 fVAPtr = drawState->fVAPtr; |
| 539 fVACount = drawState->fVACount; | 545 fVACount = drawState->fVACount; |
| 540 fDrawState->setDefaultVertexAttribs(); | 546 fDrawState->setDefaultVertexAttribs(); |
| 541 } | 547 } |
| 542 | 548 |
| 543 //////////////////////////////////////////////////////////////////////////////s | 549 //////////////////////////////////////////////////////////////////////////////s |
| 544 | 550 |
| 545 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { | 551 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { |
| 546 if (NULL != fDrawState) { | 552 if (NULL != fDrawState) { |
| 547 int m = fDrawState->fColorStages.count() - fColorEffectCnt; | 553 int m = fDrawState->numColorStages() - fColorEffectCnt; |
| 548 SkASSERT(m >= 0); | 554 SkASSERT(m >= 0); |
| 549 fDrawState->fColorStages.pop_back_n(m); | 555 fDrawState->fState.fColorStages.pop_back_n(m); |
| 550 | 556 |
| 551 int n = fDrawState->fCoverageStages.count() - fCoverageEffectCnt; | 557 int n = fDrawState->numCoverageStages() - fCoverageEffectCnt; |
| 552 SkASSERT(n >= 0); | 558 SkASSERT(n >= 0); |
| 553 fDrawState->fCoverageStages.pop_back_n(n); | 559 fDrawState->fState.fCoverageStages.pop_back_n(n); |
| 554 if (m + n > 0) { | 560 if (m + n > 0) { |
| 555 fDrawState->invalidateBlendOptFlags(); | 561 fDrawState->invalidateBlendOptFlags(); |
| 556 } | 562 } |
| 557 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) | 563 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) |
| 558 } | 564 } |
| 559 fDrawState = ds; | 565 fDrawState = ds; |
| 560 if (NULL != ds) { | 566 if (NULL != ds) { |
| 561 fColorEffectCnt = ds->fColorStages.count(); | 567 fColorEffectCnt = ds->numColorStages(); |
| 562 fCoverageEffectCnt = ds->fCoverageStages.count(); | 568 fCoverageEffectCnt = ds->numCoverageStages(); |
| 563 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) | 569 SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) |
| 564 } | 570 } |
| 565 } | 571 } |
| 566 | 572 |
| 567 //////////////////////////////////////////////////////////////////////////////// | 573 //////////////////////////////////////////////////////////////////////////////// |
| 568 | 574 |
| 569 void GrDrawState::AutoViewMatrixRestore::restore() { | 575 void GrDrawState::AutoViewMatrixRestore::restore() { |
| 570 if (NULL != fDrawState) { | 576 if (NULL != fDrawState) { |
| 571 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) | 577 SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) |
| 572 fDrawState->fViewMatrix = fViewMatrix; | 578 fDrawState->fViewMatrix = fViewMatrix; |
| 573 SkASSERT(fDrawState->numColorStages() >= fNumColorStages); | 579 SkASSERT(fDrawState->numColorStages() >= fNumColorStages); |
| 574 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages; | 580 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages; |
| 575 SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages); | 581 SkASSERT(fDrawState->numCoverageStages() >= numCoverageStages); |
| 576 | 582 |
| 577 int i = 0; | 583 int i = 0; |
| 578 for (int s = 0; s < fNumColorStages; ++s, ++i) { | 584 for (int s = 0; s < fNumColorStages; ++s, ++i) { |
| 579 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i]
); | 585 fDrawState->fState.fColorStages[s].restoreCoordChange(fSavedCoordCha
nges[i]); |
| 580 } | 586 } |
| 581 for (int s = 0; s < numCoverageStages; ++s, ++i) { | 587 for (int s = 0; s < numCoverageStages; ++s, ++i) { |
| 582 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges
[i]); | 588 fDrawState->fState.fCoverageStages[s].restoreCoordChange(fSavedCoord
Changes[i]); |
| 583 } | 589 } |
| 584 fDrawState = NULL; | 590 fDrawState = NULL; |
| 585 } | 591 } |
| 586 } | 592 } |
| 587 | 593 |
| 588 void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState, | 594 void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState, |
| 589 const SkMatrix& preconcatMatrix) { | 595 const SkMatrix& preconcatMatrix) { |
| 590 this->restore(); | 596 this->restore(); |
| 591 | 597 |
| 592 SkASSERT(NULL == fDrawState); | 598 SkASSERT(NULL == fDrawState); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 return true; | 639 return true; |
| 634 } | 640 } |
| 635 } | 641 } |
| 636 | 642 |
| 637 void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& co
ordChangeMatrix) { | 643 void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& co
ordChangeMatrix) { |
| 638 fSavedCoordChanges.reset(fDrawState->numTotalStages()); | 644 fSavedCoordChanges.reset(fDrawState->numTotalStages()); |
| 639 int i = 0; | 645 int i = 0; |
| 640 | 646 |
| 641 fNumColorStages = fDrawState->numColorStages(); | 647 fNumColorStages = fDrawState->numColorStages(); |
| 642 for (int s = 0; s < fNumColorStages; ++s, ++i) { | 648 for (int s = 0; s < fNumColorStages; ++s, ++i) { |
| 643 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); | 649 fDrawState->getColorStage(s).saveCoordChange(&fSavedCoordChanges[i]); |
| 644 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); | 650 fDrawState->fState.fColorStages[s].localCoordChange(coordChangeMatrix); |
| 645 } | 651 } |
| 646 | 652 |
| 647 int numCoverageStages = fDrawState->numCoverageStages(); | 653 int numCoverageStages = fDrawState->numCoverageStages(); |
| 648 for (int s = 0; s < numCoverageStages; ++s, ++i) { | 654 for (int s = 0; s < numCoverageStages; ++s, ++i) { |
| 649 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); | 655 fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]); |
| 650 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); | 656 fDrawState->fState.fCoverageStages[s].localCoordChange(coordChangeMatrix
); |
| 651 } | 657 } |
| 652 } | 658 } |
| OLD | NEW |