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 GrDrawState::BlendOpt blendOpt, |
18 GrBlendCoeff optSrcCoeff, | 18 GrBlendCoeff optSrcCoeff, |
19 GrBlendCoeff optDstCoeff, | 19 GrBlendCoeff optDstCoeff, |
20 GrGpu* gpu, | 20 GrGpu* gpu, |
21 const ScissorState& scissorState, | 21 const ScissorState& scissorState, |
22 const GrDeviceCoordTexture* dstCopy, | 22 const GrDeviceCoordTexture* dstCopy, |
23 GrGpu::DrawType drawType) | 23 GrGpu::DrawType drawType) |
24 : fRenderTarget(drawState.fRenderTarget.get()) { | 24 : fRenderTarget(drawState.fRenderTarget.get()) { |
25 fScissorState = scissorState; | 25 fScissorState = scissorState; |
26 fViewMatrix = drawState.getViewMatrix(); | 26 fViewMatrix = drawState.getViewMatrix(); |
27 fBlendConstant = drawState.getBlendConstant(); | 27 fBlendConstant = drawState.getBlendConstant(); |
28 fFlagBits = drawState.getFlagBits(); | |
29 fVAPtr = drawState.getVertexAttribs(); | 28 fVAPtr = drawState.getVertexAttribs(); |
30 fVACount = drawState.getVertexAttribCount(); | 29 fVACount = drawState.getVertexAttribCount(); |
31 fVAStride = drawState.getVertexStride(); | 30 fVAStride = drawState.getVertexStride(); |
32 fStencilSettings = drawState.getStencil(); | 31 fStencilSettings = drawState.getStencil(); |
33 fDrawFace = (DrawFace)drawState.getDrawFace(); | 32 fDrawFace = drawState.getDrawFace(); |
34 fBlendOptFlags = blendOptFlags; | |
35 fSrcBlend = optSrcCoeff; | 33 fSrcBlend = optSrcCoeff; |
36 fDstBlend = optDstCoeff; | 34 fDstBlend = optDstCoeff; |
37 GrProgramDesc::DescInfo descInfo; | 35 GrProgramDesc::DescInfo descInfo; |
38 | 36 |
| 37 fFlags = 0; |
| 38 if (drawState.isHWAntialias()) { |
| 39 fFlags |= kHWAA_Flag; |
| 40 } |
| 41 if (drawState.isColorWriteDisabled()) { |
| 42 fFlags |= kDisableColorWrite_Flag; |
| 43 } |
| 44 if (drawState.isDither()) { |
| 45 fFlags |= kDither_Flag; |
| 46 } |
| 47 |
39 memcpy(descInfo.fFixedFunctionVertexAttribIndices, | 48 memcpy(descInfo.fFixedFunctionVertexAttribIndices, |
40 drawState.getFixedFunctionVertexAttribIndices(), | 49 drawState.getFixedFunctionVertexAttribIndices(), |
41 sizeof(descInfo.fFixedFunctionVertexAttribIndices)); | 50 sizeof(descInfo.fFixedFunctionVertexAttribIndices)); |
42 | 51 |
43 uint8_t fixedFunctionVAToRemove = 0; | 52 uint8_t fixedFunctionVAToRemove = 0; |
44 | 53 |
45 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(); | 54 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(); |
46 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); | 55 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); |
47 descInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed(); | 56 descInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed(); |
48 fColor = colorPOI.inputColorToEffectiveStage(); | 57 fColor = colorPOI.inputColorToEffectiveStage(); |
49 if (colorPOI.removeVertexAttrib()) { | 58 if (colorPOI.removeVertexAttrib()) { |
50 fixedFunctionVAToRemove |= 0x1 << kColor_GrVertexAttribBinding; | 59 fixedFunctionVAToRemove |= 0x1 << kColor_GrVertexAttribBinding; |
51 } | 60 } |
52 | 61 |
53 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use | 62 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use |
54 // drawState's coverageProcInfo (like color above) to set this initial infor
mation. | 63 // drawState's coverageProcInfo (like color above) to set this initial infor
mation. |
55 int firstCoverageStageIdx = 0; | 64 int firstCoverageStageIdx = 0; |
56 descInfo.fInputCoverageIsUsed = true; | 65 descInfo.fInputCoverageIsUsed = true; |
57 fCoverage = drawState.getCoverage(); | 66 fCoverage = drawState.getCoverage(); |
58 | 67 |
59 this->adjustFromBlendOpts(drawState, &descInfo, &firstColorStageIdx, &firstC
overageStageIdx, | 68 this->adjustProgramForBlendOpt(drawState, blendOpt, &descInfo, &firstColorSt
ageIdx, |
60 &fixedFunctionVAToRemove); | 69 &firstCoverageStageIdx, &fixedFunctionVAToRem
ove); |
61 // Should not be setting any more FFVA to be removed at this point | 70 // Should not be setting any more FFVA to be removed at this point |
62 if (0 != fixedFunctionVAToRemove) { | 71 if (0 != fixedFunctionVAToRemove) { |
63 this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove, &descInf
o); | 72 this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove, &descInf
o); |
64 } | 73 } |
65 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, &d
escInfo); | 74 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, &d
escInfo); |
66 | 75 |
67 // Copy GeometryProcesssor from DS or ODS | 76 // Copy GeometryProcesssor from DS or ODS |
68 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType) || | 77 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType) || |
69 GrGpu::kStencilPath_DrawType || | 78 GrGpu::kStencilPath_DrawType || |
70 drawState.hasGeometryProcessor()); | 79 drawState.hasGeometryProcessor()); |
71 fGeometryProcessor.reset(drawState.getGeometryProcessor()); | 80 fGeometryProcessor.reset(drawState.getGeometryProcessor()); |
72 | 81 |
73 // Copy Stages from DS to ODS | 82 // Copy Stages from DS to ODS |
74 bool explicitLocalCoords = descInfo.hasLocalCoordAttribute(); | 83 bool explicitLocalCoords = descInfo.hasLocalCoordAttribute(); |
75 | 84 |
76 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) { | 85 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) { |
77 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, | 86 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
78 GrPendingFragmentStage, | 87 GrPendingFragmentStage, |
79 (drawState.fColorStages[i], explicitLocalCoords))
; | 88 (drawState.fColorStages[i], explicitLocalCoords))
; |
80 } | 89 } |
81 fNumColorStages = fFragmentStages.count(); | 90 fNumColorStages = fFragmentStages.count(); |
82 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i)
{ | 91 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i)
{ |
83 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, | 92 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
84 GrPendingFragmentStage, | 93 GrPendingFragmentStage, |
85 (drawState.fCoverageStages[i], explicitLocalCoord
s)); | 94 (drawState.fCoverageStages[i], explicitLocalCoord
s)); |
86 } | 95 } |
87 | 96 |
88 this->setOutputStateInfo(drawState, *gpu->caps(), &descInfo); | 97 this->setOutputStateInfo(drawState, blendOpt, *gpu->caps(), &descInfo); |
89 | 98 |
90 // now create a key | 99 // now create a key |
91 gpu->buildProgramDesc(*this, descInfo, drawType, dstCopy, &fDesc); | 100 gpu->buildProgramDesc(*this, descInfo, drawType, dstCopy, &fDesc); |
92 }; | 101 }; |
93 | 102 |
94 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState, | 103 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState, |
95 GrGpu* gpu, | 104 GrGpu* gpu, |
96 const ScissorState& scissorState, | 105 const ScissorState& scissorState, |
97 const GrDeviceCoordTexture* dstCopy, | 106 const GrDeviceCoordTexture* dstCopy, |
98 GrGpu::DrawType drawType) { | 107 GrGpu::DrawType drawType) { |
99 GrBlendCoeff srcCoeff; | 108 GrBlendCoeff srcCoeff; |
100 GrBlendCoeff dstCoeff; | 109 GrBlendCoeff dstCoeff; |
101 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false, | 110 GrDrawState::BlendOpt blendOpt = drawState.getBlendOpt(false, &srcCoeff, &ds
tCoeff); |
102 &srcCoeff, | |
103 &dstCoeff)
; | |
104 | 111 |
105 // If our blend coeffs are set to 0,1 we know we will not end up drawing unl
ess we are | 112 // If our blend coeffs are set to 0,1 we know we will not end up drawing unl
ess we are |
106 // stenciling. When path rendering the stencil settings are not always set o
n the draw state | 113 // stenciling. When path rendering the stencil settings are not always set o
n the draw state |
107 // so we must check the draw type. In cases where we will skip drawing we si
mply return a | 114 // so we must check the draw type. In cases where we will skip drawing we si
mply return a |
108 // null GrOptDrawState. | 115 // null GrOptDrawState. |
109 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff && | 116 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff && |
110 !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != d
rawType) { | 117 !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != d
rawType) { |
111 return NULL; | 118 return NULL; |
112 } | 119 } |
113 | 120 |
114 return SkNEW_ARGS(GrOptDrawState, (drawState, blendFlags, srcCoeff, | 121 return SkNEW_ARGS(GrOptDrawState, (drawState, blendOpt, srcCoeff, |
115 dstCoeff, gpu, scissorState, dstCopy, dra
wType)); | 122 dstCoeff, gpu, scissorState, dstCopy, dra
wType)); |
116 } | 123 } |
117 | 124 |
118 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, | 125 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, |
| 126 GrDrawState::BlendOpt blendOpt, |
119 const GrDrawTargetCaps& caps, | 127 const GrDrawTargetCaps& caps, |
120 GrProgramDesc::DescInfo* descInfo) { | 128 GrProgramDesc::DescInfo* descInfo) { |
121 // Set this default and then possibly change our mind if there is coverage. | 129 // Set this default and then possibly change our mind if there is coverage. |
122 descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; | 130 descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; |
123 descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; | 131 descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; |
124 | 132 |
125 // If we do have coverage determine whether it matters. Dual source blendin
g is expensive so | 133 // Determine whether we should use dual source blending or shader code to ke
ep coverage |
126 // we don't do it if we are doing coverage drawing. If we aren't then We al
ways do dual source | 134 // separate from color. |
127 // blending if we have any effective coverage stages OR the geometry process
or doesn't emits | 135 bool keepCoverageSeparate = !(GrDrawState::kCoverageAsAlpha_BlendOpt == blen
dOpt || |
128 // solid coverage. | 136 GrDrawState::kEmitCoverage_BlendOpt == blendOp
t); |
129 // TODO move the gp logic into the GP base class | 137 if (keepCoverageSeparate && !ds.hasSolidCoverage()) { |
130 if (!this->isCoverageDrawing() && !ds.hasSolidCoverage()) { | |
131 if (caps.dualSourceBlendingSupport()) { | 138 if (caps.dualSourceBlendingSupport()) { |
132 if (kZero_GrBlendCoeff == fDstBlend) { | 139 if (kZero_GrBlendCoeff == fDstBlend) { |
133 // write the coverage value to second color | 140 // write the coverage value to second color |
134 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverage_Second
aryOutputType; | 141 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverage_Second
aryOutputType; |
135 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 142 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
136 } else if (kSA_GrBlendCoeff == fDstBlend) { | 143 } else if (kSA_GrBlendCoeff == fDstBlend) { |
137 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | 144 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. |
138 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec
ondaryOutputType; | 145 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec
ondaryOutputType; |
139 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 146 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
140 } else if (kSC_GrBlendCoeff == fDstBlend) { | 147 } else if (kSC_GrBlendCoeff == fDstBlend) { |
141 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | 148 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. |
142 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISC_Sec
ondaryOutputType; | 149 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISC_Sec
ondaryOutputType; |
143 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 150 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
144 } | 151 } |
145 } else if (descInfo->fReadsDst && | 152 } else if (descInfo->fReadsDst && |
146 kOne_GrBlendCoeff == fSrcBlend && | 153 kOne_GrBlendCoeff == fSrcBlend && |
147 kZero_GrBlendCoeff == fDstBlend) { | 154 kZero_GrBlendCoeff == fDstBlend) { |
148 descInfo->fPrimaryOutputType = GrProgramDesc::kCombineWithDst_Primar
yOutputType; | 155 descInfo->fPrimaryOutputType = GrProgramDesc::kCombineWithDst_Primar
yOutputType; |
149 } | 156 } |
150 } | 157 } |
151 } | 158 } |
152 | 159 |
153 void GrOptDrawState::adjustFromBlendOpts(const GrDrawState& ds, | 160 void GrOptDrawState::adjustProgramForBlendOpt(const GrDrawState& ds, |
154 GrProgramDesc::DescInfo* descInfo, | 161 GrDrawState::BlendOpt blendOpt, |
155 int* firstColorStageIdx, | 162 GrProgramDesc::DescInfo* descInfo, |
156 int* firstCoverageStageIdx, | 163 int* firstColorStageIdx, |
157 uint8_t* fixedFunctionVAToRemove) { | 164 int* firstCoverageStageIdx, |
158 switch (fBlendOptFlags) { | 165 uint8_t* fixedFunctionVAToRemove)
{ |
159 case kNone_BlendOpt: | 166 switch (blendOpt) { |
160 case kSkipDraw_BlendOptFlag: | 167 case GrDrawState::kNone_BlendOpt: |
| 168 case GrDrawState::kSkipDraw_BlendOpt: |
| 169 case GrDrawState::kCoverageAsAlpha_BlendOpt: |
161 break; | 170 break; |
162 case kCoverageAsAlpha_BlendOptFlag: | 171 case GrDrawState::kEmitCoverage_BlendOpt: |
163 fFlagBits |= kCoverageDrawing_StateBit; | |
164 break; | |
165 case kEmitCoverage_BlendOptFlag: | |
166 fColor = 0xffffffff; | 172 fColor = 0xffffffff; |
167 descInfo->fInputColorIsUsed = true; | 173 descInfo->fInputColorIsUsed = true; |
168 *firstColorStageIdx = ds.numColorStages(); | 174 *firstColorStageIdx = ds.numColorStages(); |
169 *fixedFunctionVAToRemove |= 0x1 << kColor_GrVertexAttribBinding; | 175 *fixedFunctionVAToRemove |= 0x1 << kColor_GrVertexAttribBinding; |
170 break; | 176 break; |
171 case kEmitTransBlack_BlendOptFlag: | 177 case GrDrawState::kEmitTransBlack_BlendOpt: |
172 fColor = 0; | 178 fColor = 0; |
173 fCoverage = 0xff; | 179 fCoverage = 0xff; |
174 descInfo->fInputColorIsUsed = true; | 180 descInfo->fInputColorIsUsed = true; |
175 descInfo->fInputCoverageIsUsed = true; | 181 descInfo->fInputCoverageIsUsed = true; |
176 *firstColorStageIdx = ds.numColorStages(); | 182 *firstColorStageIdx = ds.numColorStages(); |
177 *firstCoverageStageIdx = ds.numCoverageStages(); | 183 *firstCoverageStageIdx = ds.numCoverageStages(); |
178 *fixedFunctionVAToRemove |= (0x1 << kColor_GrVertexAttribBinding | | 184 *fixedFunctionVAToRemove |= (0x1 << kColor_GrVertexAttribBinding | |
179 0x1 << kCoverage_GrVertexAttribBinding)
; | 185 0x1 << kCoverage_GrVertexAttribBinding)
; |
180 break; | 186 break; |
181 default: | |
182 SkFAIL("Unknown BlendOptFlag"); | |
183 } | 187 } |
184 } | 188 } |
185 | 189 |
186 void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag, | 190 void GrOptDrawState::removeFixedFunctionVertexAttribs(uint8_t removeVAFlag, |
187 GrProgramDesc::DescInfo* d
escInfo) { | 191 GrProgramDesc::DescInfo* d
escInfo) { |
188 int numToRemove = 0; | 192 int numToRemove = 0; |
189 uint8_t maskCheck = 0x1; | 193 uint8_t maskCheck = 0x1; |
190 // Count the number of vertex attributes that we will actually remove | 194 // Count the number of vertex attributes that we will actually remove |
191 for (int i = 0; i < kGrFixedFunctionVertexAttribBindingCnt; ++i) { | 195 for (int i = 0; i < kGrFixedFunctionVertexAttribBindingCnt; ++i) { |
192 if ((maskCheck & removeVAFlag) && -1 != descInfo->fFixedFunctionVertexAt
tribIndices[i]) { | 196 if ((maskCheck & removeVAFlag) && -1 != descInfo->fFixedFunctionVertexAt
tribIndices[i]) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 if (!usingVertexColors && this->fColor != that.fColor) { | 266 if (!usingVertexColors && this->fColor != that.fColor) { |
263 return false; | 267 return false; |
264 } | 268 } |
265 | 269 |
266 if (this->getRenderTarget() != that.getRenderTarget() || | 270 if (this->getRenderTarget() != that.getRenderTarget() || |
267 this->fScissorState != that.fScissorState || | 271 this->fScissorState != that.fScissorState || |
268 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || | 272 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || |
269 this->fSrcBlend != that.fSrcBlend || | 273 this->fSrcBlend != that.fSrcBlend || |
270 this->fDstBlend != that.fDstBlend || | 274 this->fDstBlend != that.fDstBlend || |
271 this->fBlendConstant != that.fBlendConstant || | 275 this->fBlendConstant != that.fBlendConstant || |
272 this->fFlagBits != that.fFlagBits || | 276 this->fFlags != that.fFlags || |
273 this->fVACount != that.fVACount || | 277 this->fVACount != that.fVACount || |
274 this->fVAStride != that.fVAStride || | 278 this->fVAStride != that.fVAStride || |
275 memcmp(this->fVAPtr, that.fVAPtr, this->fVACount * sizeof(GrVertexAttrib
)) || | 279 memcmp(this->fVAPtr, that.fVAPtr, this->fVACount * sizeof(GrVertexAttrib
)) || |
276 this->fStencilSettings != that.fStencilSettings || | 280 this->fStencilSettings != that.fStencilSettings || |
277 this->fDrawFace != that.fDrawFace) { | 281 this->fDrawFace != that.fDrawFace) { |
278 return false; | 282 return false; |
279 } | 283 } |
280 | 284 |
281 bool usingVertexCoverage = this->fDesc.header().fCoverageAttributeIndex != -
1; | 285 bool usingVertexCoverage = this->fDesc.header().fCoverageAttributeIndex != -
1; |
282 if (!usingVertexCoverage && this->fCoverage != that.fCoverage) { | 286 if (!usingVertexCoverage && this->fCoverage != that.fCoverage) { |
(...skipping 14 matching lines...) Expand all Loading... |
297 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); | 301 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); |
298 for (int i = 0; i < this->numFragmentStages(); i++) { | 302 for (int i = 0; i < this->numFragmentStages(); i++) { |
299 | 303 |
300 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { | 304 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { |
301 return false; | 305 return false; |
302 } | 306 } |
303 } | 307 } |
304 return true; | 308 return true; |
305 } | 309 } |
306 | 310 |
OLD | NEW |