OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrOptDrawState.h" | 8 #include "GrOptDrawState.h" |
9 | 9 |
10 #include "GrDefaultGeoProcFactory.h" | 10 #include "GrDefaultGeoProcFactory.h" |
11 #include "GrDrawState.h" | 11 #include "GrDrawState.h" |
12 #include "GrDrawTargetCaps.h" | 12 #include "GrDrawTargetCaps.h" |
13 #include "GrGpu.h" | 13 #include "GrGpu.h" |
14 #include "GrProcOptInfo.h" | 14 #include "GrProcOptInfo.h" |
15 | 15 |
16 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, | 16 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, |
17 BlendOptFlags blendOptFlags, | 17 BlendOptFlags blendOptFlags, |
18 GrBlendCoeff optSrcCoeff, | 18 GrBlendCoeff optSrcCoeff, |
19 GrBlendCoeff optDstCoeff, | 19 GrBlendCoeff optDstCoeff, |
20 GrGpu* gpu, | 20 GrGpu* gpu, |
21 const GrDeviceCoordTexture* dstCopy, | 21 const GrDeviceCoordTexture* dstCopy, |
22 GrGpu::DrawType drawType) { | 22 GrGpu::DrawType drawType) |
23 fRenderTarget.set(SkSafeRef(drawState.getRenderTarget()), kWrite_GrIOType); | 23 : fRenderTarget(drawState.fRenderTarget.get()) { |
24 fViewMatrix = drawState.getViewMatrix(); | 24 fViewMatrix = drawState.getViewMatrix(); |
25 fBlendConstant = drawState.getBlendConstant(); | 25 fBlendConstant = drawState.getBlendConstant(); |
26 fFlagBits = drawState.getFlagBits(); | 26 fFlagBits = drawState.getFlagBits(); |
27 fVAPtr = drawState.getVertexAttribs(); | 27 fVAPtr = drawState.getVertexAttribs(); |
28 fVACount = drawState.getVertexAttribCount(); | 28 fVACount = drawState.getVertexAttribCount(); |
29 fVAStride = drawState.getVertexStride(); | 29 fVAStride = drawState.getVertexStride(); |
30 fStencilSettings = drawState.getStencil(); | 30 fStencilSettings = drawState.getStencil(); |
31 fDrawFace = (DrawFace)drawState.getDrawFace(); | 31 fDrawFace = (DrawFace)drawState.getDrawFace(); |
32 fBlendOptFlags = blendOptFlags; | 32 fBlendOptFlags = blendOptFlags; |
33 fSrcBlend = optSrcCoeff; | 33 fSrcBlend = optSrcCoeff; |
(...skipping 25 matching lines...) Expand all Loading... |
59 // Should not be setting any more FFVA to be removed at this point | 59 // Should not be setting any more FFVA to be removed at this point |
60 if (0 != fixedFunctionVAToRemove) { | 60 if (0 != fixedFunctionVAToRemove) { |
61 this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove, &descInf
o); | 61 this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove, &descInf
o); |
62 } | 62 } |
63 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, &d
escInfo); | 63 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, &d
escInfo); |
64 | 64 |
65 // Copy GeometryProcesssor from DS or ODS | 65 // Copy GeometryProcesssor from DS or ODS |
66 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType) || | 66 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType) || |
67 GrGpu::kStencilPath_DrawType || | 67 GrGpu::kStencilPath_DrawType || |
68 drawState.hasGeometryProcessor()); | 68 drawState.hasGeometryProcessor()); |
69 if (drawState.hasGeometryProcessor()) { | 69 fGeometryProcessor.reset(drawState.getGeometryProcessor()); |
70 fGeometryProcessor.initAndRef(drawState.fGeometryProcessor); | 70 |
71 } else { | 71 // Copy Stages from DS to ODS |
72 fGeometryProcessor.reset(NULL); | 72 bool explicitLocalCoords = descInfo.hasLocalCoordAttribute(); |
| 73 |
| 74 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) { |
| 75 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
| 76 GrPendingFragmentStage, |
| 77 (drawState.fColorStages[i], explicitLocalCoords))
; |
73 } | 78 } |
74 | |
75 // Copy Color Stages from DS to ODS | |
76 if (firstColorStageIdx < drawState.numColorStages()) { | |
77 fFragmentStages.reset(&drawState.getColorStage(firstColorStageIdx), | |
78 drawState.numColorStages() - firstColorStageIdx); | |
79 } else { | |
80 fFragmentStages.reset(); | |
81 } | |
82 | |
83 fNumColorStages = fFragmentStages.count(); | 79 fNumColorStages = fFragmentStages.count(); |
84 | 80 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i)
{ |
85 // Copy Coverage Stages from DS to ODS | 81 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
86 if (firstCoverageStageIdx < drawState.numCoverageStages()) { | 82 GrPendingFragmentStage, |
87 fFragmentStages.push_back_n(drawState.numCoverageStages() - firstCoverag
eStageIdx, | 83 (drawState.fCoverageStages[i], explicitLocalCoord
s)); |
88 &drawState.getCoverageStage(firstCoverageSta
geIdx)); | |
89 } | 84 } |
90 | 85 |
91 this->setOutputStateInfo(drawState, *gpu->caps(), &descInfo); | 86 this->setOutputStateInfo(drawState, *gpu->caps(), &descInfo); |
92 | 87 |
93 // now create a key | 88 // now create a key |
94 gpu->buildProgramDesc(*this, descInfo, drawType, dstCopy, &fDesc); | 89 gpu->buildProgramDesc(*this, descInfo, drawType, dstCopy, &fDesc); |
95 }; | 90 }; |
96 | 91 |
97 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState, | 92 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState, |
98 GrGpu* gpu, | 93 GrGpu* gpu, |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 } | 245 } |
251 if (ds.hasGeometryProcessor()) { | 246 if (ds.hasGeometryProcessor()) { |
252 const GrGeometryProcessor& gp = *ds.getGeometryProcessor(); | 247 const GrGeometryProcessor& gp = *ds.getGeometryProcessor(); |
253 descInfo->fReadsFragPosition = descInfo->fReadsFragPosition || gp.willRe
adFragmentPosition(); | 248 descInfo->fReadsFragPosition = descInfo->fReadsFragPosition || gp.willRe
adFragmentPosition(); |
254 } | 249 } |
255 } | 250 } |
256 | 251 |
257 //////////////////////////////////////////////////////////////////////////////// | 252 //////////////////////////////////////////////////////////////////////////////// |
258 | 253 |
259 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { | 254 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { |
260 return this->isEqual(that); | |
261 } | |
262 | |
263 bool GrOptDrawState::isEqual(const GrOptDrawState& that) const { | |
264 if (this->fDesc != that.fDesc) { | 255 if (this->fDesc != that.fDesc) { |
265 return false; | 256 return false; |
266 } | 257 } |
267 bool usingVertexColors = that.fDesc.header().fColorAttributeIndex != -1; | 258 bool usingVertexColors = that.fDesc.header().fColorAttributeIndex != -1; |
268 if (!usingVertexColors && this->fColor != that.fColor) { | 259 if (!usingVertexColors && this->fColor != that.fColor) { |
269 return false; | 260 return false; |
270 } | 261 } |
271 | 262 |
272 if (this->getRenderTarget() != that.getRenderTarget() || | 263 if (this->getRenderTarget() != that.getRenderTarget() || |
273 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || | 264 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || |
(...skipping 17 matching lines...) Expand all Loading... |
291 if (this->hasGeometryProcessor()) { | 282 if (this->hasGeometryProcessor()) { |
292 if (!that.hasGeometryProcessor()) { | 283 if (!that.hasGeometryProcessor()) { |
293 return false; | 284 return false; |
294 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce
ssor())) { | 285 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce
ssor())) { |
295 return false; | 286 return false; |
296 } | 287 } |
297 } else if (that.hasGeometryProcessor()) { | 288 } else if (that.hasGeometryProcessor()) { |
298 return false; | 289 return false; |
299 } | 290 } |
300 | 291 |
301 bool explicitLocalCoords = this->fDesc.header().fLocalCoordAttributeIndex !=
-1; | 292 // The program desc comparison should have already assured that the stage co
unts match. |
| 293 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); |
302 for (int i = 0; i < this->numFragmentStages(); i++) { | 294 for (int i = 0; i < this->numFragmentStages(); i++) { |
303 if (!GrFragmentStage::AreCompatible(this->getFragmentStage(i), that.getF
ragmentStage(i), | 295 |
304 explicitLocalCoords)) { | 296 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { |
305 return false; | 297 return false; |
306 } | 298 } |
307 } | 299 } |
308 return true; | 300 return true; |
309 } | 301 } |
310 | 302 |
OLD | NEW |