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" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 | 37 |
38 memcpy(descInfo.fFixedFunctionVertexAttribIndices, | 38 memcpy(descInfo.fFixedFunctionVertexAttribIndices, |
39 drawState.getFixedFunctionVertexAttribIndices(), | 39 drawState.getFixedFunctionVertexAttribIndices(), |
40 sizeof(descInfo.fFixedFunctionVertexAttribIndices)); | 40 sizeof(descInfo.fFixedFunctionVertexAttribIndices)); |
41 | 41 |
42 descInfo.fInputColorIsUsed = true; | 42 descInfo.fInputColorIsUsed = true; |
43 descInfo.fInputCoverageIsUsed = true; | 43 descInfo.fInputCoverageIsUsed = true; |
44 | 44 |
45 int firstColorStageIdx = 0; | 45 int firstColorStageIdx = 0; |
46 int firstCoverageStageIdx = 0; | 46 int firstCoverageStageIdx = 0; |
47 bool separateCoverageFromColor; | |
48 | 47 |
49 uint8_t fixedFunctionVAToRemove = 0; | 48 uint8_t fixedFunctionVAToRemove = 0; |
50 | 49 |
51 this->computeEffectiveColorStages(drawState, &descInfo, &firstColorStageIdx, | 50 this->computeEffectiveColorStages(drawState, &descInfo, &firstColorStageIdx, |
52 &fixedFunctionVAToRemove); | 51 &fixedFunctionVAToRemove); |
53 this->computeEffectiveCoverageStages(drawState, &descInfo, &firstCoverageSta geIdx); | 52 this->computeEffectiveCoverageStages(drawState, &descInfo, &firstCoverageSta geIdx); |
54 this->adjustFromBlendOpts(drawState, &descInfo, &firstColorStageIdx, &firstC overageStageIdx, | 53 this->adjustFromBlendOpts(drawState, &descInfo, &firstColorStageIdx, &firstC overageStageIdx, |
55 &fixedFunctionVAToRemove); | 54 &fixedFunctionVAToRemove); |
56 // Should not be setting any more FFVA to be removed at this point | 55 // Should not be setting any more FFVA to be removed at this point |
57 if (0 != fixedFunctionVAToRemove) { | 56 if (0 != fixedFunctionVAToRemove) { |
58 this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove, &descInf o); | 57 this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove, &descInf o); |
59 } | 58 } |
60 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, &d escInfo); | 59 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, &d escInfo); |
61 this->setOutputStateInfo(drawState, *gpu->caps(), firstCoverageStageIdx, &de scInfo, | 60 this->setOutputStateInfo(drawState, *gpu->caps(), firstCoverageStageIdx, &de scInfo); |
62 &separateCoverageFromColor); | |
63 | 61 |
64 // Copy GeometryProcesssor from DS or ODS | 62 // Copy GeometryProcesssor from DS or ODS |
65 if (drawState.hasGeometryProcessor()) { | 63 if (drawState.hasGeometryProcessor()) { |
66 fGeometryProcessor.initAndRef(drawState.fGeometryProcessor); | 64 fGeometryProcessor.initAndRef(drawState.fGeometryProcessor); |
67 } else if (!GrGpu::IsPathRenderingDrawType(drawType)) { | 65 } else if (!GrGpu::IsPathRenderingDrawType(drawType)) { |
68 // Install default GP, this will be ignored if we are rendering with fra gment shader only | 66 // Install default GP, this will be ignored if we are rendering with fra gment shader only |
69 // TODO(joshualitt) rendering code should do this | 67 // TODO(joshualitt) rendering code should do this |
70 fGeometryProcessor.reset(GrDefaultGeoProcFactory::Create()); | 68 fGeometryProcessor.reset(GrDefaultGeoProcFactory::Create()); |
71 } else { | 69 } else { |
72 fGeometryProcessor.reset(NULL); | 70 fGeometryProcessor.reset(NULL); |
73 } | 71 } |
74 | 72 |
75 // Copy Color Stages from DS to ODS | 73 // Copy Color Stages from DS to ODS |
76 if (firstColorStageIdx < drawState.numColorStages()) { | 74 if (firstColorStageIdx < drawState.numColorStages()) { |
77 fFragmentStages.reset(&drawState.getColorStage(firstColorStageIdx), | 75 fFragmentStages.reset(&drawState.getColorStage(firstColorStageIdx), |
78 drawState.numColorStages() - firstColorStageIdx); | 76 drawState.numColorStages() - firstColorStageIdx); |
79 } else { | 77 } else { |
80 fFragmentStages.reset(); | 78 fFragmentStages.reset(); |
81 } | 79 } |
82 | 80 |
83 fNumColorStages = fFragmentStages.count(); | 81 fNumColorStages = fFragmentStages.count(); |
84 | 82 |
85 // Copy Coverage Stages from DS to ODS | 83 // Copy Coverage Stages from DS to ODS |
86 if (firstCoverageStageIdx < drawState.numCoverageStages()) { | 84 if (firstCoverageStageIdx < drawState.numCoverageStages()) { |
87 fFragmentStages.push_back_n(drawState.numCoverageStages() - firstCoverag eStageIdx, | 85 fFragmentStages.push_back_n(drawState.numCoverageStages() - firstCoverag eStageIdx, |
88 &drawState.getCoverageStage(firstCoverageSta geIdx)); | 86 &drawState.getCoverageStage(firstCoverageSta geIdx)); |
89 if (!separateCoverageFromColor) { | |
90 fNumColorStages = fFragmentStages.count(); | |
91 } | |
92 } | 87 } |
93 | 88 |
94 // now create a key | 89 // now create a key |
95 gpu->buildProgramDesc(*this, descInfo, drawType, dstCopy, &fDesc); | 90 gpu->buildProgramDesc(*this, descInfo, drawType, dstCopy, &fDesc); |
96 }; | 91 }; |
97 | 92 |
98 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState, | 93 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState, |
99 GrGpu* gpu, | 94 GrGpu* gpu, |
100 const GrDeviceCoordTexture* dstCopy, | 95 const GrDeviceCoordTexture* dstCopy, |
101 GrGpu::DrawType drawType) { | 96 GrGpu::DrawType drawType) { |
(...skipping 28 matching lines...) Expand all Loading... | |
130 drawType) == *drawState.fCachedOptState); | 125 drawType) == *drawState.fCachedOptState); |
131 #endif | 126 #endif |
132 } | 127 } |
133 drawState.fCachedOptState->ref(); | 128 drawState.fCachedOptState->ref(); |
134 return drawState.fCachedOptState; | 129 return drawState.fCachedOptState; |
135 } | 130 } |
136 | 131 |
137 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, | 132 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, |
138 const GrDrawTargetCaps& caps, | 133 const GrDrawTargetCaps& caps, |
139 int firstCoverageStageIdx, | 134 int firstCoverageStageIdx, |
140 GrProgramDesc::DescInfo* descInfo, | 135 GrProgramDesc::DescInfo* descInfo) { |
141 bool* separateCoverageFromColor) { | |
142 // Set this default and then possibly change our mind if there is coverage. | 136 // Set this default and then possibly change our mind if there is coverage. |
143 descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; | 137 descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; |
144 descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; | 138 descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; |
145 | 139 |
146 // If we do have coverage determine whether it matters. | 140 // If we do have coverage determine whether it matters. |
147 *separateCoverageFromColor = this->hasGeometryProcessor(); | |
148 if (!this->isCoverageDrawing() && | 141 if (!this->isCoverageDrawing() && |
bsalomon
2014/11/10 18:50:12
Can we make GrOptDrawState have something like:
b
| |
149 (ds.numCoverageStages() - firstCoverageStageIdx > 0 || | 142 (ds.numCoverageStages() - firstCoverageStageIdx > 0 || |
150 ds.hasGeometryProcessor() || | 143 ds.hasGeometryProcessor() || |
151 descInfo->hasCoverageVertexAttribute())) { | 144 descInfo->hasCoverageVertexAttribute())) { |
152 | 145 |
153 if (caps.dualSourceBlendingSupport()) { | 146 if (caps.dualSourceBlendingSupport()) { |
154 if (kZero_GrBlendCoeff == fDstBlend) { | 147 if (kZero_GrBlendCoeff == fDstBlend) { |
155 // write the coverage value to second color | 148 // write the coverage value to second color |
156 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverage_Second aryOutputType; | 149 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverage_Second aryOutputType; |
157 *separateCoverageFromColor = true; | |
158 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 150 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
159 } else if (kSA_GrBlendCoeff == fDstBlend) { | 151 } else if (kSA_GrBlendCoeff == fDstBlend) { |
160 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. | 152 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. |
161 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec ondaryOutputType; | 153 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec ondaryOutputType; |
162 *separateCoverageFromColor = true; | |
163 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 154 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
164 } else if (kSC_GrBlendCoeff == fDstBlend) { | 155 } else if (kSC_GrBlendCoeff == fDstBlend) { |
165 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. | 156 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. |
166 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISC_Sec ondaryOutputType; | 157 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISC_Sec ondaryOutputType; |
167 *separateCoverageFromColor = true; | |
168 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 158 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
169 } | 159 } |
170 } else if (descInfo->fReadsDst && | 160 } else if (descInfo->fReadsDst && |
171 kOne_GrBlendCoeff == fSrcBlend && | 161 kOne_GrBlendCoeff == fSrcBlend && |
172 kZero_GrBlendCoeff == fDstBlend) { | 162 kZero_GrBlendCoeff == fDstBlend) { |
173 descInfo->fPrimaryOutputType = GrProgramDesc::kCombineWithDst_Primar yOutputType; | 163 descInfo->fPrimaryOutputType = GrProgramDesc::kCombineWithDst_Primar yOutputType; |
174 *separateCoverageFromColor = true; | |
175 } | 164 } |
176 } | 165 } |
177 } | 166 } |
178 | 167 |
179 void GrOptDrawState::adjustFromBlendOpts(const GrDrawState& ds, | 168 void GrOptDrawState::adjustFromBlendOpts(const GrDrawState& ds, |
180 GrProgramDesc::DescInfo* descInfo, | 169 GrProgramDesc::DescInfo* descInfo, |
181 int* firstColorStageIdx, | 170 int* firstColorStageIdx, |
182 int* firstCoverageStageIdx, | 171 int* firstCoverageStageIdx, |
183 uint8_t* fixedFunctionVAToRemove) { | 172 uint8_t* fixedFunctionVAToRemove) { |
184 switch (fBlendOptFlags) { | 173 switch (fBlendOptFlags) { |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 bool explicitLocalCoords = this->fDesc.header().fLocalCoordAttributeIndex != -1; | 376 bool explicitLocalCoords = this->fDesc.header().fLocalCoordAttributeIndex != -1; |
388 for (int i = 0; i < this->numFragmentStages(); i++) { | 377 for (int i = 0; i < this->numFragmentStages(); i++) { |
389 if (!GrFragmentStage::AreCompatible(this->getFragmentStage(i), that.getF ragmentStage(i), | 378 if (!GrFragmentStage::AreCompatible(this->getFragmentStage(i), that.getF ragmentStage(i), |
390 explicitLocalCoords)) { | 379 explicitLocalCoords)) { |
391 return false; | 380 return false; |
392 } | 381 } |
393 } | 382 } |
394 return true; | 383 return true; |
395 } | 384 } |
396 | 385 |
OLD | NEW |