| 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" |
| 11 #include "GrOptDrawState.h" | 11 #include "GrOptDrawState.h" |
| 12 #include "GrPaint.h" | 12 #include "GrPaint.h" |
| 13 #include "GrProcOptInfo.h" | 13 #include "GrProcOptInfo.h" |
| 14 #include "GrXferProcessor.h" |
| 15 #include "effects/GrDefaultXferProcessor.h" |
| 16 #include "effects/GrPorterDuffXferProcessor.h" |
| 14 | 17 |
| 15 //////////////////////////////////////////////////////////////////////////////s | 18 /////////////////////////////////////////////////////////////////////////////// |
| 16 | 19 |
| 17 bool GrDrawState::isEqual(const GrDrawState& that) const { | 20 bool GrDrawState::isEqual(const GrDrawState& that) const { |
| 18 bool usingVertexColors = this->hasColorVertexAttribute(); | 21 bool usingVertexColors = this->hasColorVertexAttribute(); |
| 19 if (!usingVertexColors && this->fColor != that.fColor) { | 22 if (!usingVertexColors && this->fColor != that.fColor) { |
| 20 return false; | 23 return false; |
| 21 } | 24 } |
| 22 | 25 |
| 23 if (this->getRenderTarget() != that.getRenderTarget() || | 26 if (this->getRenderTarget() != that.getRenderTarget() || |
| 24 this->fColorStages.count() != that.fColorStages.count() || | 27 this->fColorStages.count() != that.fColorStages.count() || |
| 25 this->fCoverageStages.count() != that.fCoverageStages.count() || | 28 this->fCoverageStages.count() != that.fCoverageStages.count() || |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 fDstBlend = that.fDstBlend; | 98 fDstBlend = that.fDstBlend; |
| 96 fBlendConstant = that.fBlendConstant; | 99 fBlendConstant = that.fBlendConstant; |
| 97 fFlagBits = that.fFlagBits; | 100 fFlagBits = that.fFlagBits; |
| 98 fVACount = that.fVACount; | 101 fVACount = that.fVACount; |
| 99 fVAPtr = that.fVAPtr; | 102 fVAPtr = that.fVAPtr; |
| 100 fVAStride = that.fVAStride; | 103 fVAStride = that.fVAStride; |
| 101 fStencilSettings = that.fStencilSettings; | 104 fStencilSettings = that.fStencilSettings; |
| 102 fCoverage = that.fCoverage; | 105 fCoverage = that.fCoverage; |
| 103 fDrawFace = that.fDrawFace; | 106 fDrawFace = that.fDrawFace; |
| 104 fGeometryProcessor.reset(SkSafeRef(that.fGeometryProcessor.get())); | 107 fGeometryProcessor.reset(SkSafeRef(that.fGeometryProcessor.get())); |
| 108 fXPFactory.reset(SkRef(that.getXPFactory())); |
| 105 fColorStages = that.fColorStages; | 109 fColorStages = that.fColorStages; |
| 106 fCoverageStages = that.fCoverageStages; | 110 fCoverageStages = that.fCoverageStages; |
| 107 | 111 |
| 108 fHints = that.fHints; | 112 fHints = that.fHints; |
| 109 | 113 |
| 110 fColorProcInfoValid = that.fColorProcInfoValid; | 114 fColorProcInfoValid = that.fColorProcInfoValid; |
| 111 fCoverageProcInfoValid = that.fCoverageProcInfoValid; | 115 fCoverageProcInfoValid = that.fCoverageProcInfoValid; |
| 112 if (fColorProcInfoValid) { | 116 if (fColorProcInfoValid) { |
| 113 fColorProcInfo = that.fColorProcInfo; | 117 fColorProcInfo = that.fColorProcInfo; |
| 114 } | 118 } |
| 115 if (fCoverageProcInfoValid) { | 119 if (fCoverageProcInfoValid) { |
| 116 fCoverageProcInfo = that.fCoverageProcInfo; | 120 fCoverageProcInfo = that.fCoverageProcInfo; |
| 117 } | 121 } |
| 118 | 122 |
| 119 memcpy(fFixedFunctionVertexAttribIndices, | 123 memcpy(fFixedFunctionVertexAttribIndices, |
| 120 that.fFixedFunctionVertexAttribIndices, | 124 that.fFixedFunctionVertexAttribIndices, |
| 121 sizeof(fFixedFunctionVertexAttribIndices)); | 125 sizeof(fFixedFunctionVertexAttribIndices)); |
| 122 return *this; | 126 return *this; |
| 123 } | 127 } |
| 124 | 128 |
| 125 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { | 129 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { |
| 126 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 130 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
| 127 fRenderTarget.reset(NULL); | 131 fRenderTarget.reset(NULL); |
| 128 | 132 |
| 129 fGeometryProcessor.reset(NULL); | 133 fGeometryProcessor.reset(NULL); |
| 134 fXPFactory.reset(GrDefaultXPFactory::Create()); |
| 130 fColorStages.reset(); | 135 fColorStages.reset(); |
| 131 fCoverageStages.reset(); | 136 fCoverageStages.reset(); |
| 132 | 137 |
| 133 | 138 |
| 134 this->setDefaultVertexAttribs(); | 139 this->setDefaultVertexAttribs(); |
| 135 | 140 |
| 136 fColor = 0xffffffff; | 141 fColor = 0xffffffff; |
| 137 if (NULL == initialViewMatrix) { | 142 if (NULL == initialViewMatrix) { |
| 138 fViewMatrix.reset(); | 143 fViewMatrix.reset(); |
| 139 } else { | 144 } else { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 fCoverageStages.reset(); | 184 fCoverageStages.reset(); |
| 180 | 185 |
| 181 for (int i = 0; i < paint.numColorStages(); ++i) { | 186 for (int i = 0; i < paint.numColorStages(); ++i) { |
| 182 fColorStages.push_back(paint.getColorStage(i)); | 187 fColorStages.push_back(paint.getColorStage(i)); |
| 183 } | 188 } |
| 184 | 189 |
| 185 for (int i = 0; i < paint.numCoverageStages(); ++i) { | 190 for (int i = 0; i < paint.numCoverageStages(); ++i) { |
| 186 fCoverageStages.push_back(paint.getCoverageStage(i)); | 191 fCoverageStages.push_back(paint.getCoverageStage(i)); |
| 187 } | 192 } |
| 188 | 193 |
| 194 fXPFactory.reset(SkRef(paint.getXPFactory())); |
| 195 |
| 196 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); |
| 189 this->setRenderTarget(rt); | 197 this->setRenderTarget(rt); |
| 190 | 198 |
| 191 fViewMatrix = vm; | 199 fViewMatrix = vm; |
| 192 | 200 |
| 193 // These have no equivalent in GrPaint, set them to defaults | 201 // These have no equivalent in GrPaint, set them to defaults |
| 194 fBlendConstant = 0x0; | 202 fBlendConstant = 0x0; |
| 195 fDrawFace = kBoth_DrawFace; | 203 fDrawFace = kBoth_DrawFace; |
| 196 fStencilSettings.setDisabled(); | 204 fStencilSettings.setDisabled(); |
| 197 fFlagBits = 0; | 205 fFlagBits = 0; |
| 198 fHints = 0; | 206 fHints = 0; |
| 199 | 207 |
| 200 // Enable the clip bit | 208 // Enable the clip bit |
| 201 this->enableState(GrDrawState::kClip_StateBit); | 209 this->enableState(GrDrawState::kClip_StateBit); |
| 202 | 210 |
| 203 this->setColor(paint.getColor()); | 211 this->setColor(paint.getColor()); |
| 204 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); | 212 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); |
| 205 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); | 213 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); |
| 206 | 214 |
| 207 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); | |
| 208 this->setCoverage(0xFF); | 215 this->setCoverage(0xFF); |
| 209 fColorProcInfoValid = false; | 216 fColorProcInfoValid = false; |
| 210 fCoverageProcInfoValid = false; | 217 fCoverageProcInfoValid = false; |
| 211 } | 218 } |
| 212 | 219 |
| 213 //////////////////////////////////////////////////////////////////////////////// | 220 //////////////////////////////////////////////////////////////////////////////// |
| 214 | 221 |
| 215 bool GrDrawState::validateVertexAttribs() const { | 222 bool GrDrawState::validateVertexAttribs() const { |
| 216 // check consistency of effects and attributes | 223 // check consistency of effects and attributes |
| 217 GrSLType slTypes[kMaxVertexAttribCnt]; | 224 GrSLType slTypes[kMaxVertexAttribCnt]; |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 | 660 |
| 654 GrBlendCoeff dstCoeff = this->getDstBlendCoeff(); | 661 GrBlendCoeff dstCoeff = this->getDstBlendCoeff(); |
| 655 if (!(kZero_GrBlendCoeff == dstCoeff || | 662 if (!(kZero_GrBlendCoeff == dstCoeff || |
| 656 (kISA_GrBlendCoeff == dstCoeff && this->srcAlphaWillBeOne()))) { | 663 (kISA_GrBlendCoeff == dstCoeff && this->srcAlphaWillBeOne()))) { |
| 657 return true; | 664 return true; |
| 658 } | 665 } |
| 659 | 666 |
| 660 return false; | 667 return false; |
| 661 } | 668 } |
| 662 | 669 |
| 670 bool GrDrawState::coverageWillBeSingleComponent() const { |
| 671 this->calcCoverageInvariantOutput(); |
| 672 return (fColorProcInfo.isSingleComponent()); |
| 673 } |
| 674 |
| 663 void GrDrawState::calcColorInvariantOutput() const { | 675 void GrDrawState::calcColorInvariantOutput() const { |
| 664 if (!fColorProcInfoValid) { | 676 if (!fColorProcInfoValid) { |
| 665 GrColor color; | 677 GrColor color; |
| 666 GrColorComponentFlags flags; | 678 GrColorComponentFlags flags; |
| 667 if (this->hasColorVertexAttribute()) { | 679 if (this->hasColorVertexAttribute()) { |
| 668 if (fHints & kVertexColorsAreOpaque_Hint) { | 680 if (fHints & kVertexColorsAreOpaque_Hint) { |
| 669 flags = kA_GrColorComponentFlag; | 681 flags = kA_GrColorComponentFlag; |
| 670 color = 0xFF << GrColor_SHIFT_A; | 682 color = 0xFF << GrColor_SHIFT_A; |
| 671 } else { | 683 } else { |
| 672 flags = static_cast<GrColorComponentFlags>(0); | 684 flags = static_cast<GrColorComponentFlags>(0); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 693 } else { | 705 } else { |
| 694 flags = kRGBA_GrColorComponentFlags; | 706 flags = kRGBA_GrColorComponentFlags; |
| 695 color = this->getCoverageColor(); | 707 color = this->getCoverageColor(); |
| 696 } | 708 } |
| 697 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->n
umCoverageStages(), | 709 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->n
umCoverageStages(), |
| 698 color, flags, true, fGeometryPro
cessor.get()); | 710 color, flags, true, fGeometryPro
cessor.get()); |
| 699 fCoverageProcInfoValid = true; | 711 fCoverageProcInfoValid = true; |
| 700 } | 712 } |
| 701 } | 713 } |
| 702 | 714 |
| OLD | NEW |