| 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 | 9 |
| 10 #include "GrBlend.h" | 10 #include "GrBlend.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 SkASSERT(0 == memcmp(this->fFixedFunctionVertexAttribIndices, | 68 SkASSERT(0 == memcmp(this->fFixedFunctionVertexAttribIndices, |
| 69 that.fFixedFunctionVertexAttribIndices, | 69 that.fFixedFunctionVertexAttribIndices, |
| 70 sizeof(this->fFixedFunctionVertexAttribIndices))); | 70 sizeof(this->fFixedFunctionVertexAttribIndices))); |
| 71 | 71 |
| 72 return true; | 72 return true; |
| 73 } | 73 } |
| 74 | 74 |
| 75 GrDrawState::CombinedState GrDrawState::CombineIfPossible( | |
| 76 const GrDrawState& a, const GrDrawState& b, const GrDrawTargetCaps& caps) { | |
| 77 | |
| 78 if (!a.isEqual(b)) { | |
| 79 return kIncompatible_CombinedState; | |
| 80 } | |
| 81 | |
| 82 // If the general draw states are equal (from check above) we know hasColorV
ertexAttribute() | |
| 83 // is equivalent for both a and b | |
| 84 if (a.hasColorVertexAttribute()) { | |
| 85 // If one is opaque and the other is not then the combined state is not
opaque. Moreover, | |
| 86 // if the opaqueness affects the ability to get color/coverage blending
correct then we | |
| 87 // don't combine the draw states. | |
| 88 bool aIsOpaque = (kVertexColorsAreOpaque_Hint & a.fHints); | |
| 89 bool bIsOpaque = (kVertexColorsAreOpaque_Hint & b.fHints); | |
| 90 if (aIsOpaque != bIsOpaque) { | |
| 91 const GrDrawState* opaque; | |
| 92 const GrDrawState* nonOpaque; | |
| 93 if (aIsOpaque) { | |
| 94 opaque = &a; | |
| 95 nonOpaque = &b; | |
| 96 } else { | |
| 97 opaque = &b; | |
| 98 nonOpaque = &a; | |
| 99 } | |
| 100 if (!opaque->hasSolidCoverage() && opaque->couldApplyCoverage(caps))
{ | |
| 101 SkASSERT(!nonOpaque->hasSolidCoverage()); | |
| 102 if (!nonOpaque->couldApplyCoverage(caps)) { | |
| 103 return kIncompatible_CombinedState; | |
| 104 } | |
| 105 } | |
| 106 return aIsOpaque ? kB_CombinedState : kA_CombinedState; | |
| 107 } | |
| 108 } | |
| 109 return kAOrB_CombinedState; | |
| 110 } | |
| 111 | |
| 112 //////////////////////////////////////////////////////////////////////////////s | 75 //////////////////////////////////////////////////////////////////////////////s |
| 113 | 76 |
| 114 GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatr
ix) { | 77 GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatr
ix) { |
| 115 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 78 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
| 116 *this = state; | 79 *this = state; |
| 117 if (!preConcatMatrix.isIdentity()) { | 80 if (!preConcatMatrix.isIdentity()) { |
| 118 for (int i = 0; i < this->numColorStages(); ++i) { | 81 for (int i = 0; i < this->numColorStages(); ++i) { |
| 119 fColorStages[i].localCoordChange(preConcatMatrix); | 82 fColorStages[i].localCoordChange(preConcatMatrix); |
| 120 } | 83 } |
| 121 for (int i = 0; i < this->numCoverageStages(); ++i) { | 84 for (int i = 0; i < this->numCoverageStages(); ++i) { |
| 122 fCoverageStages[i].localCoordChange(preConcatMatrix); | 85 fCoverageStages[i].localCoordChange(preConcatMatrix); |
| 123 } | 86 } |
| 124 } | 87 } |
| 125 } | 88 } |
| 126 | 89 |
| 127 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { | 90 GrDrawState& GrDrawState::operator=(const GrDrawState& that) { |
| 128 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 91 fRenderTarget.reset(SkSafeRef(that.fRenderTarget.get())); |
| 129 SkASSERT(!that.fRenderTarget.ownsPendingIO()); | |
| 130 SkASSERT(!this->fRenderTarget.ownsPendingIO()); | |
| 131 this->setRenderTarget(that.getRenderTarget()); | |
| 132 fColor = that.fColor; | 92 fColor = that.fColor; |
| 133 fViewMatrix = that.fViewMatrix; | 93 fViewMatrix = that.fViewMatrix; |
| 134 fSrcBlend = that.fSrcBlend; | 94 fSrcBlend = that.fSrcBlend; |
| 135 fDstBlend = that.fDstBlend; | 95 fDstBlend = that.fDstBlend; |
| 136 fBlendConstant = that.fBlendConstant; | 96 fBlendConstant = that.fBlendConstant; |
| 137 fFlagBits = that.fFlagBits; | 97 fFlagBits = that.fFlagBits; |
| 138 fVACount = that.fVACount; | 98 fVACount = that.fVACount; |
| 139 fVAPtr = that.fVAPtr; | 99 fVAPtr = that.fVAPtr; |
| 140 fVAStride = that.fVAStride; | 100 fVAStride = that.fVAStride; |
| 141 fStencilSettings = that.fStencilSettings; | 101 fStencilSettings = that.fStencilSettings; |
| 142 fCoverage = that.fCoverage; | 102 fCoverage = that.fCoverage; |
| 143 fDrawFace = that.fDrawFace; | 103 fDrawFace = that.fDrawFace; |
| 144 if (that.hasGeometryProcessor()) { | 104 fGeometryProcessor.reset(SkSafeRef(that.fGeometryProcessor.get())); |
| 145 fGeometryProcessor.initAndRef(that.fGeometryProcessor); | |
| 146 } else { | |
| 147 fGeometryProcessor.reset(NULL); | |
| 148 } | |
| 149 fColorStages = that.fColorStages; | 105 fColorStages = that.fColorStages; |
| 150 fCoverageStages = that.fCoverageStages; | 106 fCoverageStages = that.fCoverageStages; |
| 151 | 107 |
| 152 fHints = that.fHints; | 108 fHints = that.fHints; |
| 153 | 109 |
| 154 fColorProcInfoValid = that.fColorProcInfoValid; | 110 fColorProcInfoValid = that.fColorProcInfoValid; |
| 155 fCoverageProcInfoValid = that.fCoverageProcInfoValid; | 111 fCoverageProcInfoValid = that.fCoverageProcInfoValid; |
| 156 if (fColorProcInfoValid) { | 112 if (fColorProcInfoValid) { |
| 157 fColorProcInfo = that.fColorProcInfo; | 113 fColorProcInfo = that.fColorProcInfo; |
| 158 } | 114 } |
| 159 if (fCoverageProcInfoValid) { | 115 if (fCoverageProcInfoValid) { |
| 160 fCoverageProcInfo = that.fCoverageProcInfo; | 116 fCoverageProcInfo = that.fCoverageProcInfo; |
| 161 } | 117 } |
| 162 | 118 |
| 163 memcpy(fFixedFunctionVertexAttribIndices, | 119 memcpy(fFixedFunctionVertexAttribIndices, |
| 164 that.fFixedFunctionVertexAttribIndices, | 120 that.fFixedFunctionVertexAttribIndices, |
| 165 sizeof(fFixedFunctionVertexAttribIndices)); | 121 sizeof(fFixedFunctionVertexAttribIndices)); |
| 166 return *this; | 122 return *this; |
| 167 } | 123 } |
| 168 | 124 |
| 169 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { | 125 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { |
| 170 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 126 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
| 171 SkASSERT(!fRenderTarget.ownsPendingIO()); | 127 fRenderTarget.reset(NULL); |
| 172 | 128 |
| 173 fGeometryProcessor.reset(NULL); | 129 fGeometryProcessor.reset(NULL); |
| 174 fColorStages.reset(); | 130 fColorStages.reset(); |
| 175 fCoverageStages.reset(); | 131 fCoverageStages.reset(); |
| 176 | 132 |
| 177 fRenderTarget.reset(); | |
| 178 | 133 |
| 179 this->setDefaultVertexAttribs(); | 134 this->setDefaultVertexAttribs(); |
| 180 | 135 |
| 181 fColor = 0xffffffff; | 136 fColor = 0xffffffff; |
| 182 if (NULL == initialViewMatrix) { | 137 if (NULL == initialViewMatrix) { |
| 183 fViewMatrix.reset(); | 138 fViewMatrix.reset(); |
| 184 } else { | 139 } else { |
| 185 fViewMatrix = *initialViewMatrix; | 140 fViewMatrix = *initialViewMatrix; |
| 186 } | 141 } |
| 187 fSrcBlend = kOne_GrBlendCoeff; | 142 fSrcBlend = kOne_GrBlendCoeff; |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 | 525 |
| 571 int numCoverageStages = fDrawState->numCoverageStages(); | 526 int numCoverageStages = fDrawState->numCoverageStages(); |
| 572 for (int s = 0; s < numCoverageStages; ++s, ++i) { | 527 for (int s = 0; s < numCoverageStages; ++s, ++i) { |
| 573 fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]); | 528 fDrawState->getCoverageStage(s).saveCoordChange(&fSavedCoordChanges[i]); |
| 574 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); | 529 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); |
| 575 } | 530 } |
| 576 } | 531 } |
| 577 | 532 |
| 578 //////////////////////////////////////////////////////////////////////////////// | 533 //////////////////////////////////////////////////////////////////////////////// |
| 579 | 534 |
| 580 void GrDrawState::convertToPendingExec() { | |
| 581 fRenderTarget.markPendingIO(); | |
| 582 fRenderTarget.removeRef(); | |
| 583 for (int i = 0; i < fColorStages.count(); ++i) { | |
| 584 fColorStages[i].convertToPendingExec(); | |
| 585 } | |
| 586 if (fGeometryProcessor) { | |
| 587 fGeometryProcessor.convertToPendingExec(); | |
| 588 } | |
| 589 for (int i = 0; i < fCoverageStages.count(); ++i) { | |
| 590 fCoverageStages[i].convertToPendingExec(); | |
| 591 } | |
| 592 } | |
| 593 | |
| 594 //////////////////////////////////////////////////////////////////////////////// | |
| 595 | |
| 596 GrDrawState::~GrDrawState() { | 535 GrDrawState::~GrDrawState() { |
| 597 SkASSERT(0 == fBlockEffectRemovalCnt); | 536 SkASSERT(0 == fBlockEffectRemovalCnt); |
| 598 } | 537 } |
| 599 | 538 |
| 600 //////////////////////////////////////////////////////////////////////////////// | 539 //////////////////////////////////////////////////////////////////////////////// |
| 601 | 540 |
| 602 GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, | 541 GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, |
| 603 GrBlendCoeff* srcCoeff, | 542 GrBlendCoeff* srcCoeff, |
| 604 GrBlendCoeff* dstCoeff) con
st { | 543 GrBlendCoeff* dstCoeff) con
st { |
| 605 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; | 544 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 } else { | 693 } else { |
| 755 flags = kRGBA_GrColorComponentFlags; | 694 flags = kRGBA_GrColorComponentFlags; |
| 756 color = this->getCoverageColor(); | 695 color = this->getCoverageColor(); |
| 757 } | 696 } |
| 758 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->n
umCoverageStages(), | 697 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->n
umCoverageStages(), |
| 759 color, flags, true, fGeometryPro
cessor.get()); | 698 color, flags, true, fGeometryPro
cessor.get()); |
| 760 fCoverageProcInfoValid = true; | 699 fCoverageProcInfoValid = true; |
| 761 } | 700 } |
| 762 } | 701 } |
| 763 | 702 |
| OLD | NEW |