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 | 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 SkASSERT(that.hasXPFactory()); | |
| 109 fXPFactory.reset(SkRef(that.getXPFactory())); | |
| 105 fColorStages = that.fColorStages; | 110 fColorStages = that.fColorStages; |
| 106 fCoverageStages = that.fCoverageStages; | 111 fCoverageStages = that.fCoverageStages; |
| 107 | 112 |
| 108 fHints = that.fHints; | 113 fHints = that.fHints; |
| 109 | 114 |
| 110 fColorProcInfoValid = that.fColorProcInfoValid; | 115 fColorProcInfoValid = that.fColorProcInfoValid; |
| 111 fCoverageProcInfoValid = that.fCoverageProcInfoValid; | 116 fCoverageProcInfoValid = that.fCoverageProcInfoValid; |
| 112 if (fColorProcInfoValid) { | 117 if (fColorProcInfoValid) { |
| 113 fColorProcInfo = that.fColorProcInfo; | 118 fColorProcInfo = that.fColorProcInfo; |
| 114 } | 119 } |
| 115 if (fCoverageProcInfoValid) { | 120 if (fCoverageProcInfoValid) { |
| 116 fCoverageProcInfo = that.fCoverageProcInfo; | 121 fCoverageProcInfo = that.fCoverageProcInfo; |
| 117 } | 122 } |
| 118 | 123 |
| 119 memcpy(fFixedFunctionVertexAttribIndices, | 124 memcpy(fFixedFunctionVertexAttribIndices, |
| 120 that.fFixedFunctionVertexAttribIndices, | 125 that.fFixedFunctionVertexAttribIndices, |
| 121 sizeof(fFixedFunctionVertexAttribIndices)); | 126 sizeof(fFixedFunctionVertexAttribIndices)); |
| 122 return *this; | 127 return *this; |
| 123 } | 128 } |
| 124 | 129 |
| 125 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { | 130 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { |
| 126 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 131 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
| 127 fRenderTarget.reset(NULL); | 132 fRenderTarget.reset(NULL); |
| 128 | 133 |
| 129 fGeometryProcessor.reset(NULL); | 134 fGeometryProcessor.reset(NULL); |
| 135 fXPFactory.reset(GrDefaultXPFactory::Create()); | |
|
bsalomon
2014/11/26 21:02:45
why not NULL? Or if not, should we have the hasXPF
egdaniel
2014/12/01 18:18:24
I always want there to be an XP so a default one i
| |
| 130 fColorStages.reset(); | 136 fColorStages.reset(); |
| 131 fCoverageStages.reset(); | 137 fCoverageStages.reset(); |
| 132 | 138 |
| 133 | 139 |
| 134 this->setDefaultVertexAttribs(); | 140 this->setDefaultVertexAttribs(); |
| 135 | 141 |
| 136 fColor = 0xffffffff; | 142 fColor = 0xffffffff; |
| 137 if (NULL == initialViewMatrix) { | 143 if (NULL == initialViewMatrix) { |
| 138 fViewMatrix.reset(); | 144 fViewMatrix.reset(); |
| 139 } else { | 145 } else { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 fCoverageStages.reset(); | 185 fCoverageStages.reset(); |
| 180 | 186 |
| 181 for (int i = 0; i < paint.numColorStages(); ++i) { | 187 for (int i = 0; i < paint.numColorStages(); ++i) { |
| 182 fColorStages.push_back(paint.getColorStage(i)); | 188 fColorStages.push_back(paint.getColorStage(i)); |
| 183 } | 189 } |
| 184 | 190 |
| 185 for (int i = 0; i < paint.numCoverageStages(); ++i) { | 191 for (int i = 0; i < paint.numCoverageStages(); ++i) { |
| 186 fCoverageStages.push_back(paint.getCoverageStage(i)); | 192 fCoverageStages.push_back(paint.getCoverageStage(i)); |
| 187 } | 193 } |
| 188 | 194 |
| 195 SkASSERT(paint.hasXPFactory()); | |
| 196 fXPFactory.reset(SkRef(paint.getXPFactory())); | |
| 197 | |
| 198 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); | |
| 189 this->setRenderTarget(rt); | 199 this->setRenderTarget(rt); |
| 190 | 200 |
| 191 fViewMatrix = vm; | 201 fViewMatrix = vm; |
| 192 | 202 |
| 193 // These have no equivalent in GrPaint, set them to defaults | 203 // These have no equivalent in GrPaint, set them to defaults |
| 194 fBlendConstant = 0x0; | 204 fBlendConstant = 0x0; |
| 195 fDrawFace = kBoth_DrawFace; | 205 fDrawFace = kBoth_DrawFace; |
| 196 fStencilSettings.setDisabled(); | 206 fStencilSettings.setDisabled(); |
| 197 fFlagBits = 0; | 207 fFlagBits = 0; |
| 198 fHints = 0; | 208 fHints = 0; |
| 199 | 209 |
| 200 // Enable the clip bit | 210 // Enable the clip bit |
| 201 this->enableState(GrDrawState::kClip_StateBit); | 211 this->enableState(GrDrawState::kClip_StateBit); |
| 202 | 212 |
| 203 this->setColor(paint.getColor()); | 213 this->setColor(paint.getColor()); |
| 204 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); | 214 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); |
| 205 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); | 215 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); |
| 206 | 216 |
| 207 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); | |
| 208 this->setCoverage(0xFF); | 217 this->setCoverage(0xFF); |
| 209 fColorProcInfoValid = false; | 218 fColorProcInfoValid = false; |
| 210 fCoverageProcInfoValid = false; | 219 fCoverageProcInfoValid = false; |
| 211 } | 220 } |
| 212 | 221 |
| 213 //////////////////////////////////////////////////////////////////////////////// | 222 //////////////////////////////////////////////////////////////////////////////// |
| 214 | 223 |
| 215 bool GrDrawState::validateVertexAttribs() const { | 224 bool GrDrawState::validateVertexAttribs() const { |
| 216 // check consistency of effects and attributes | 225 // check consistency of effects and attributes |
| 217 GrSLType slTypes[kMaxVertexAttribCnt]; | 226 GrSLType slTypes[kMaxVertexAttribCnt]; |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 | 662 |
| 654 GrBlendCoeff dstCoeff = this->getDstBlendCoeff(); | 663 GrBlendCoeff dstCoeff = this->getDstBlendCoeff(); |
| 655 if (!(kZero_GrBlendCoeff == dstCoeff || | 664 if (!(kZero_GrBlendCoeff == dstCoeff || |
| 656 (kISA_GrBlendCoeff == dstCoeff && this->srcAlphaWillBeOne()))) { | 665 (kISA_GrBlendCoeff == dstCoeff && this->srcAlphaWillBeOne()))) { |
| 657 return true; | 666 return true; |
| 658 } | 667 } |
| 659 | 668 |
| 660 return false; | 669 return false; |
| 661 } | 670 } |
| 662 | 671 |
| 672 bool GrDrawState::coverageWillBeSingleComponent() const { | |
| 673 this->calcCoverageInvariantOutput(); | |
| 674 return (fColorProcInfo.isSingleComponent()); | |
|
bsalomon
2014/11/26 21:02:45
fCoverageProcInfo?
egdaniel
2014/12/01 18:18:24
yeah was fixed in follow up cl, missed propagating
bsalomon
2014/12/01 19:24:39
I'm still not seeing it.
| |
| 675 } | |
| 676 | |
| 663 void GrDrawState::calcColorInvariantOutput() const { | 677 void GrDrawState::calcColorInvariantOutput() const { |
| 664 if (!fColorProcInfoValid) { | 678 if (!fColorProcInfoValid) { |
| 665 GrColor color; | 679 GrColor color; |
| 666 GrColorComponentFlags flags; | 680 GrColorComponentFlags flags; |
| 667 if (this->hasColorVertexAttribute()) { | 681 if (this->hasColorVertexAttribute()) { |
| 668 if (fHints & kVertexColorsAreOpaque_Hint) { | 682 if (fHints & kVertexColorsAreOpaque_Hint) { |
| 669 flags = kA_GrColorComponentFlag; | 683 flags = kA_GrColorComponentFlag; |
| 670 color = 0xFF << GrColor_SHIFT_A; | 684 color = 0xFF << GrColor_SHIFT_A; |
| 671 } else { | 685 } else { |
| 672 flags = static_cast<GrColorComponentFlags>(0); | 686 flags = static_cast<GrColorComponentFlags>(0); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 693 } else { | 707 } else { |
| 694 flags = kRGBA_GrColorComponentFlags; | 708 flags = kRGBA_GrColorComponentFlags; |
| 695 color = this->getCoverageColor(); | 709 color = this->getCoverageColor(); |
| 696 } | 710 } |
| 697 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->n umCoverageStages(), | 711 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->n umCoverageStages(), |
| 698 color, flags, true, fGeometryPro cessor.get()); | 712 color, flags, true, fGeometryPro cessor.get()); |
| 699 fCoverageProcInfoValid = true; | 713 fCoverageProcInfoValid = true; |
| 700 } | 714 } |
| 701 } | 715 } |
| 702 | 716 |
| OLD | NEW |