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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 } else { | 700 } else { |
694 flags = kRGBA_GrColorComponentFlags; | 701 flags = kRGBA_GrColorComponentFlags; |
695 color = this->getCoverageColor(); | 702 color = this->getCoverageColor(); |
696 } | 703 } |
697 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->n
umCoverageStages(), | 704 fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->n
umCoverageStages(), |
698 color, flags, true, fGeometryPro
cessor.get()); | 705 color, flags, true, fGeometryPro
cessor.get()); |
699 fCoverageProcInfoValid = true; | 706 fCoverageProcInfoValid = true; |
700 } | 707 } |
701 } | 708 } |
702 | 709 |
OLD | NEW |