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.set(SkSafeRef(drawState.getRenderTarget()), kWrite_GrIOType); |
24 fColor = drawState.getColor(); | |
25 fCoverage = drawState.getCoverage(); | |
26 fViewMatrix = drawState.getViewMatrix(); | 24 fViewMatrix = drawState.getViewMatrix(); |
27 fBlendConstant = drawState.getBlendConstant(); | 25 fBlendConstant = drawState.getBlendConstant(); |
28 fFlagBits = drawState.getFlagBits(); | 26 fFlagBits = drawState.getFlagBits(); |
29 fVAPtr = drawState.getVertexAttribs(); | 27 fVAPtr = drawState.getVertexAttribs(); |
30 fVACount = drawState.getVertexAttribCount(); | 28 fVACount = drawState.getVertexAttribCount(); |
31 fVAStride = drawState.getVertexStride(); | 29 fVAStride = drawState.getVertexStride(); |
32 fStencilSettings = drawState.getStencil(); | 30 fStencilSettings = drawState.getStencil(); |
33 fDrawFace = (DrawFace)drawState.getDrawFace(); | 31 fDrawFace = (DrawFace)drawState.getDrawFace(); |
34 fBlendOptFlags = blendOptFlags; | 32 fBlendOptFlags = blendOptFlags; |
35 fSrcBlend = optSrcCoeff; | 33 fSrcBlend = optSrcCoeff; |
36 fDstBlend = optDstCoeff; | 34 fDstBlend = optDstCoeff; |
37 GrProgramDesc::DescInfo descInfo; | 35 GrProgramDesc::DescInfo descInfo; |
38 | 36 |
39 memcpy(descInfo.fFixedFunctionVertexAttribIndices, | 37 memcpy(descInfo.fFixedFunctionVertexAttribIndices, |
40 drawState.getFixedFunctionVertexAttribIndices(), | 38 drawState.getFixedFunctionVertexAttribIndices(), |
41 sizeof(descInfo.fFixedFunctionVertexAttribIndices)); | 39 sizeof(descInfo.fFixedFunctionVertexAttribIndices)); |
42 | 40 |
43 descInfo.fInputColorIsUsed = true; | |
44 descInfo.fInputCoverageIsUsed = true; | |
45 | |
46 int firstColorStageIdx = 0; | |
47 int firstCoverageStageIdx = 0; | |
48 | |
49 uint8_t fixedFunctionVAToRemove = 0; | 41 uint8_t fixedFunctionVAToRemove = 0; |
50 | 42 |
51 this->computeEffectiveColorStages(drawState, &descInfo, &firstColorStageIdx, | 43 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(); |
52 &fixedFunctionVAToRemove); | 44 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); |
53 this->computeEffectiveCoverageStages(drawState, &descInfo, &firstCoverageSta
geIdx); | 45 descInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed(); |
| 46 fColor = colorPOI.inputColorToEffectiveStage(); |
| 47 if (colorPOI.removeVertexAttrib()) { |
| 48 fixedFunctionVAToRemove |= 0x1 << kColor_GrVertexAttribBinding; |
| 49 } |
| 50 |
| 51 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use |
| 52 // drawState's coverageProcInfo (like color above) to set this initial infor
mation. |
| 53 int firstCoverageStageIdx = 0; |
| 54 descInfo.fInputCoverageIsUsed = true; |
| 55 fCoverage = drawState.getCoverage(); |
| 56 |
54 this->adjustFromBlendOpts(drawState, &descInfo, &firstColorStageIdx, &firstC
overageStageIdx, | 57 this->adjustFromBlendOpts(drawState, &descInfo, &firstColorStageIdx, &firstC
overageStageIdx, |
55 &fixedFunctionVAToRemove); | 58 &fixedFunctionVAToRemove); |
56 // 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 |
57 if (0 != fixedFunctionVAToRemove) { | 60 if (0 != fixedFunctionVAToRemove) { |
58 this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove, &descInf
o); | 61 this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove, &descInf
o); |
59 } | 62 } |
60 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, &d
escInfo); | 63 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, &d
escInfo); |
61 | 64 |
62 // Copy GeometryProcesssor from DS or ODS | 65 // Copy GeometryProcesssor from DS or ODS |
63 if (drawState.hasGeometryProcessor()) { | 66 if (drawState.hasGeometryProcessor()) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 descInfo->fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = n
ewIdx; | 215 descInfo->fFixedFunctionVertexAttribIndices[currAttrib.fBinding] = n
ewIdx; |
213 } | 216 } |
214 memcpy(dst, src, sizeof(GrVertexAttrib)); | 217 memcpy(dst, src, sizeof(GrVertexAttrib)); |
215 ++newIdx; | 218 ++newIdx; |
216 ++dst; | 219 ++dst; |
217 } | 220 } |
218 fVACount -= numToRemove; | 221 fVACount -= numToRemove; |
219 fVAPtr = fOptVA.get(); | 222 fVAPtr = fOptVA.get(); |
220 } | 223 } |
221 | 224 |
222 void GrOptDrawState::computeEffectiveColorStages(const GrDrawState& ds, | |
223 GrProgramDesc::DescInfo* descIn
fo, | |
224 int* firstColorStageIdx, | |
225 uint8_t* fixedFunctionVAToRemov
e) { | |
226 // Set up color and flags for ConstantColorComponent checks | |
227 GrColor color; | |
228 GrColorComponentFlags flags; | |
229 if (!descInfo->hasColorVertexAttribute()) { | |
230 color = ds.getColor(); | |
231 flags = kRGBA_GrColorComponentFlags; | |
232 } else { | |
233 if (ds.vertexColorsAreOpaque()) { | |
234 color = 0xFF << GrColor_SHIFT_A; | |
235 flags = kA_GrColorComponentFlag; | |
236 } else { | |
237 flags = static_cast<GrColorComponentFlags>(0); | |
238 // not strictly necessary but we get false alarms from tools about u
ninit. | |
239 color = 0; | |
240 } | |
241 } | |
242 GrProcOptInfo poi; | |
243 if (ds.numColorStages() > 0) { | |
244 poi.calcWithInitialValues(&ds.getColorStage(0), ds.numColorStages(), col
or, flags, false); | |
245 *firstColorStageIdx = poi.firstEffectiveStageIndex(); | |
246 descInfo->fInputColorIsUsed = poi.inputColorIsUsed(); | |
247 fColor = poi.inputColorToEffectiveStage(); | |
248 if (poi.removeVertexAttrib()) { | |
249 *fixedFunctionVAToRemove |= 0x1 << kColor_GrVertexAttribBinding; | |
250 } | |
251 } | |
252 } | |
253 | |
254 void GrOptDrawState::computeEffectiveCoverageStages(const GrDrawState& ds, | |
255 GrProgramDesc::DescInfo* des
cInfo, | |
256 int* firstCoverageStageIdx)
{ | |
257 // We do not try to optimize out constantColor coverage effects here. It is
extremely rare | |
258 // to have a coverage effect that returns a constant value for all four chan
nels. Thus we | |
259 // save having to make extra virtual calls by not checking for it. | |
260 | |
261 // Don't do any optimizations on coverage stages. It should not be the case
where we do not use | |
262 // input coverage in an effect | |
263 #ifdef OptCoverageStages | |
264 GrInvariantOutput inout; | |
265 for (int i = 0; i < ds.numCoverageStages(); ++i) { | |
266 const GrFragmentProcessor* fp = ds.getCoverageStage(i).getProcessor(); | |
267 fp->computeInvariantOutput(&inout); | |
268 if (!inout.fWillUseInputColor) { | |
269 *firstCoverageStageIdx = i; | |
270 descInfo->fInputCoverageIsUsed = false; | |
271 } | |
272 } | |
273 #endif | |
274 } | |
275 | |
276 static void get_stage_stats(const GrFragmentStage& stage, bool* readsDst, bool*
readsFragPosition) { | 225 static void get_stage_stats(const GrFragmentStage& stage, bool* readsDst, bool*
readsFragPosition) { |
277 if (stage.getProcessor()->willReadDstColor()) { | 226 if (stage.getProcessor()->willReadDstColor()) { |
278 *readsDst = true; | 227 *readsDst = true; |
279 } | 228 } |
280 if (stage.getProcessor()->willReadFragmentPosition()) { | 229 if (stage.getProcessor()->willReadFragmentPosition()) { |
281 *readsFragPosition = true; | 230 *readsFragPosition = true; |
282 } | 231 } |
283 } | 232 } |
284 | 233 |
285 void GrOptDrawState::getStageStats(const GrDrawState& ds, int firstColorStageIdx
, | 234 void GrOptDrawState::getStageStats(const GrDrawState& ds, int firstColorStageIdx
, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 bool explicitLocalCoords = this->fDesc.header().fLocalCoordAttributeIndex !=
-1; | 302 bool explicitLocalCoords = this->fDesc.header().fLocalCoordAttributeIndex !=
-1; |
354 for (int i = 0; i < this->numFragmentStages(); i++) { | 303 for (int i = 0; i < this->numFragmentStages(); i++) { |
355 if (!GrFragmentStage::AreCompatible(this->getFragmentStage(i), that.getF
ragmentStage(i), | 304 if (!GrFragmentStage::AreCompatible(this->getFragmentStage(i), that.getF
ragmentStage(i), |
356 explicitLocalCoords)) { | 305 explicitLocalCoords)) { |
357 return false; | 306 return false; |
358 } | 307 } |
359 } | 308 } |
360 return true; | 309 return true; |
361 } | 310 } |
362 | 311 |
OLD | NEW |