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/GrPorterDuffXferProcessor.h" | |
14 | 16 |
15 //////////////////////////////////////////////////////////////////////////////s | 17 /////////////////////////////////////////////////////////////////////////////// |
16 | 18 |
17 bool GrDrawState::isEqual(const GrDrawState& that) const { | 19 bool GrDrawState::isEqual(const GrDrawState& that) const { |
18 bool usingVertexColors = this->hasColorVertexAttribute(); | 20 bool usingVertexColors = this->hasColorVertexAttribute(); |
19 if (!usingVertexColors && this->fColor != that.fColor) { | 21 if (!usingVertexColors && this->fColor != that.fColor) { |
20 return false; | 22 return false; |
21 } | 23 } |
22 | 24 |
23 if (this->getRenderTarget() != that.getRenderTarget() || | 25 if (this->getRenderTarget() != that.getRenderTarget() || |
24 this->fColorStages.count() != that.fColorStages.count() || | 26 this->fColorStages.count() != that.fColorStages.count() || |
25 this->fCoverageStages.count() != that.fCoverageStages.count() || | 27 this->fCoverageStages.count() != that.fCoverageStages.count() || |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 fDstBlend = that.fDstBlend; | 97 fDstBlend = that.fDstBlend; |
96 fBlendConstant = that.fBlendConstant; | 98 fBlendConstant = that.fBlendConstant; |
97 fFlagBits = that.fFlagBits; | 99 fFlagBits = that.fFlagBits; |
98 fVACount = that.fVACount; | 100 fVACount = that.fVACount; |
99 fVAPtr = that.fVAPtr; | 101 fVAPtr = that.fVAPtr; |
100 fVAStride = that.fVAStride; | 102 fVAStride = that.fVAStride; |
101 fStencilSettings = that.fStencilSettings; | 103 fStencilSettings = that.fStencilSettings; |
102 fCoverage = that.fCoverage; | 104 fCoverage = that.fCoverage; |
103 fDrawFace = that.fDrawFace; | 105 fDrawFace = that.fDrawFace; |
104 fGeometryProcessor.reset(SkSafeRef(that.fGeometryProcessor.get())); | 106 fGeometryProcessor.reset(SkSafeRef(that.fGeometryProcessor.get())); |
107 fXPFactory.reset(SkRef(that.getXPFactory())); | |
105 fColorStages = that.fColorStages; | 108 fColorStages = that.fColorStages; |
106 fCoverageStages = that.fCoverageStages; | 109 fCoverageStages = that.fCoverageStages; |
107 | 110 |
108 fHints = that.fHints; | 111 fHints = that.fHints; |
109 | 112 |
110 fColorProcInfoValid = that.fColorProcInfoValid; | 113 fColorProcInfoValid = that.fColorProcInfoValid; |
111 fCoverageProcInfoValid = that.fCoverageProcInfoValid; | 114 fCoverageProcInfoValid = that.fCoverageProcInfoValid; |
112 if (fColorProcInfoValid) { | 115 if (fColorProcInfoValid) { |
113 fColorProcInfo = that.fColorProcInfo; | 116 fColorProcInfo = that.fColorProcInfo; |
114 } | 117 } |
115 if (fCoverageProcInfoValid) { | 118 if (fCoverageProcInfoValid) { |
116 fCoverageProcInfo = that.fCoverageProcInfo; | 119 fCoverageProcInfo = that.fCoverageProcInfo; |
117 } | 120 } |
118 | 121 |
119 memcpy(fFixedFunctionVertexAttribIndices, | 122 memcpy(fFixedFunctionVertexAttribIndices, |
120 that.fFixedFunctionVertexAttribIndices, | 123 that.fFixedFunctionVertexAttribIndices, |
121 sizeof(fFixedFunctionVertexAttribIndices)); | 124 sizeof(fFixedFunctionVertexAttribIndices)); |
122 return *this; | 125 return *this; |
123 } | 126 } |
124 | 127 |
125 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { | 128 void GrDrawState::onReset(const SkMatrix* initialViewMatrix) { |
126 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 129 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
127 fRenderTarget.reset(NULL); | 130 fRenderTarget.reset(NULL); |
128 | 131 |
129 fGeometryProcessor.reset(NULL); | 132 fGeometryProcessor.reset(NULL); |
133 fXPFactory.reset(GrPorterDuffXPFactory::Create(kOne_GrBlendCoeff, | |
134 kZero_GrBlendCoeff)); | |
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 { | |
bsalomon
2014/12/02 15:36:32
Is this called anywhere?
egdaniel
2014/12/02 18:09:51
Nope. Was used in the next CL when DS was passed i
| |
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 |