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 "GrDrawState.h" | 10 #include "GrDrawState.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 GrXferProcessor::OptFlags optFlags; | 37 GrXferProcessor::OptFlags optFlags; |
38 if (xferProcessor) { | 38 if (xferProcessor) { |
39 fXferProcessor.reset(xferProcessor.get()); | 39 fXferProcessor.reset(xferProcessor.get()); |
40 | 40 |
41 optFlags = xferProcessor->getOptimizations(colorPOI, | 41 optFlags = xferProcessor->getOptimizations(colorPOI, |
42 coveragePOI, | 42 coveragePOI, |
43 drawState.isCoverageDrawing()
, | 43 drawState.isCoverageDrawing()
, |
44 drawState.isColorWriteDisable
d(), | 44 drawState.isColorWriteDisable
d(), |
45 drawState.getStencil().doesWr
ite(), | 45 drawState.getStencil().doesWr
ite(), |
46 &fColor, | 46 &fColor, |
47 &fCoverage); | 47 &fCoverage, |
| 48 caps); |
48 } | 49 } |
49 | 50 |
50 // When path rendering the stencil settings are not always set on the draw s
tate | 51 // When path rendering the stencil settings are not always set on the draw s
tate |
51 // so we must check the draw type. In cases where we will skip drawing we si
mply return a | 52 // so we must check the draw type. In cases where we will skip drawing we si
mply return a |
52 // null GrOptDrawState. | 53 // null GrOptDrawState. |
53 if (!xferProcessor || ((GrXferProcessor::kSkipDraw_OptFlag & optFlags) && | 54 if (!xferProcessor || ((GrXferProcessor::kSkipDraw_OptFlag & optFlags) && |
54 GrGpu::kStencilPath_DrawType != drawType)) { | 55 GrGpu::kStencilPath_DrawType != drawType)) { |
55 // Set the fields that don't default init and return. The lack of a rend
er target will | 56 // Set the fields that don't default init and return. The lack of a rend
er target will |
56 // indicate that this can be skipped. | 57 // indicate that this can be skipped. |
57 fFlags = 0; | 58 fFlags = 0; |
58 fDrawFace = GrDrawState::kInvalid_DrawFace; | 59 fDrawFace = GrDrawState::kInvalid_DrawFace; |
59 fSrcBlend = kZero_GrBlendCoeff; | |
60 fDstBlend = kZero_GrBlendCoeff; | |
61 fBlendConstant = 0x0; | |
62 fViewMatrix.reset(); | 60 fViewMatrix.reset(); |
63 return; | 61 return; |
64 } | 62 } |
65 | 63 |
66 fRenderTarget.reset(drawState.fRenderTarget.get()); | 64 fRenderTarget.reset(drawState.fRenderTarget.get()); |
67 SkASSERT(fRenderTarget); | 65 SkASSERT(fRenderTarget); |
68 fScissorState = scissorState; | 66 fScissorState = scissorState; |
69 fViewMatrix = drawState.getViewMatrix(); | 67 fViewMatrix = drawState.getViewMatrix(); |
70 fStencilSettings = drawState.getStencil(); | 68 fStencilSettings = drawState.getStencil(); |
71 fDrawFace = drawState.getDrawFace(); | 69 fDrawFace = drawState.getDrawFace(); |
(...skipping 29 matching lines...) Expand all Loading... |
101 } | 99 } |
102 | 100 |
103 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use | 101 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use |
104 // drawState's coverageProcInfo (like color above) to set this initial infor
mation. | 102 // drawState's coverageProcInfo (like color above) to set this initial infor
mation. |
105 int firstCoverageStageIdx = 0; | 103 int firstCoverageStageIdx = 0; |
106 fDescInfo.fInputCoverageIsUsed = true; | 104 fDescInfo.fInputCoverageIsUsed = true; |
107 | 105 |
108 | 106 |
109 GrXferProcessor::BlendInfo blendInfo; | 107 GrXferProcessor::BlendInfo blendInfo; |
110 fXferProcessor->getBlendInfo(&blendInfo); | 108 fXferProcessor->getBlendInfo(&blendInfo); |
111 fSrcBlend = blendInfo.fSrcBlend; | |
112 fDstBlend = blendInfo.fDstBlend; | |
113 fBlendConstant = blendInfo.fBlendConstant; | |
114 | 109 |
115 this->adjustProgramFromOptimizations(drawState, optFlags, colorPOI, coverage
POI, | 110 this->adjustProgramFromOptimizations(drawState, optFlags, colorPOI, coverage
POI, |
116 &firstColorStageIdx, &firstCoverageStag
eIdx); | 111 &firstColorStageIdx, &firstCoverageStag
eIdx); |
117 | 112 |
118 fDescInfo.fRequiresLocalCoordAttrib = hasLocalCoords; | 113 fDescInfo.fRequiresLocalCoordAttrib = hasLocalCoords; |
119 | 114 |
120 // Copy GeometryProcesssor from DS or ODS | 115 // Copy GeometryProcesssor from DS or ODS |
121 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType) || | 116 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType) || |
122 GrGpu::kStencilPath_DrawType || | 117 GrGpu::kStencilPath_DrawType || |
123 drawState.hasGeometryProcessor()); | 118 drawState.hasGeometryProcessor()); |
(...skipping 15 matching lines...) Expand all Loading... |
139 | 134 |
140 // let the GP init the batch tracker | 135 // let the GP init the batch tracker |
141 if (drawState.hasGeometryProcessor()) { | 136 if (drawState.hasGeometryProcessor()) { |
142 GrGeometryProcessor::InitBT init; | 137 GrGeometryProcessor::InitBT init; |
143 init.fOutputColor = fDescInfo.fInputColorIsUsed; | 138 init.fOutputColor = fDescInfo.fInputColorIsUsed; |
144 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; | 139 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; |
145 init.fColor = this->getColor(); | 140 init.fColor = this->getColor(); |
146 init.fCoverage = this->getCoverage(); | 141 init.fCoverage = this->getCoverage(); |
147 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); | 142 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); |
148 } | 143 } |
149 | |
150 this->setOutputStateInfo(drawState, coverageColor, optFlags, caps); | |
151 } | |
152 | |
153 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, | |
154 GrColor coverage, | |
155 GrXferProcessor::OptFlags optFlags, | |
156 const GrDrawTargetCaps& caps) { | |
157 // Set this default and then possibly change our mind if there is coverage. | |
158 fDescInfo.fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; | |
159 fDescInfo.fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; | |
160 | |
161 // Determine whether we should use dual source blending or shader code to ke
ep coverage | |
162 // separate from color. | |
163 bool keepCoverageSeparate = !(optFlags & GrXferProcessor::kSetCoverageDrawin
g_OptFlag); | |
164 if (keepCoverageSeparate && !ds.hasSolidCoverage(coverage)) { | |
165 if (caps.dualSourceBlendingSupport()) { | |
166 if (kZero_GrBlendCoeff == fDstBlend) { | |
167 // write the coverage value to second color | |
168 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverage_Second
aryOutputType; | |
169 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | |
170 } else if (kSA_GrBlendCoeff == fDstBlend) { | |
171 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | |
172 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec
ondaryOutputType; | |
173 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | |
174 } else if (kSC_GrBlendCoeff == fDstBlend) { | |
175 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | |
176 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISC_Sec
ondaryOutputType; | |
177 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | |
178 } | |
179 } else if (fDescInfo.fReadsDst && | |
180 kOne_GrBlendCoeff == fSrcBlend && | |
181 kZero_GrBlendCoeff == fDstBlend) { | |
182 fDescInfo.fPrimaryOutputType = GrProgramDesc::kCombineWithDst_Primar
yOutputType; | |
183 } | |
184 } | |
185 } | 144 } |
186 | 145 |
187 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds, | 146 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds, |
188 GrXferProcessor::OptFlags fl
ags, | 147 GrXferProcessor::OptFlags fl
ags, |
189 const GrProcOptInfo& colorPO
I, | 148 const GrProcOptInfo& colorPO
I, |
190 const GrProcOptInfo& coverag
ePOI, | 149 const GrProcOptInfo& coverag
ePOI, |
191 int* firstColorStageIdx, | 150 int* firstColorStageIdx, |
192 int* firstCoverageStageIdx)
{ | 151 int* firstCoverageStageIdx)
{ |
193 fDescInfo.fReadsDst = false; | 152 fDescInfo.fReadsDst = false; |
194 fDescInfo.fReadsFragPosition = false; | 153 fDescInfo.fReadsFragPosition = false; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 189 |
231 if (!fDescInfo.fHasVertexColor && this->fColor != that.fColor) { | 190 if (!fDescInfo.fHasVertexColor && this->fColor != that.fColor) { |
232 return false; | 191 return false; |
233 } | 192 } |
234 | 193 |
235 if (this->getRenderTarget() != that.getRenderTarget() || | 194 if (this->getRenderTarget() != that.getRenderTarget() || |
236 this->fFragmentStages.count() != that.fFragmentStages.count() || | 195 this->fFragmentStages.count() != that.fFragmentStages.count() || |
237 this->fNumColorStages != that.fNumColorStages || | 196 this->fNumColorStages != that.fNumColorStages || |
238 this->fScissorState != that.fScissorState || | 197 this->fScissorState != that.fScissorState || |
239 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || | 198 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || |
240 this->fSrcBlend != that.fSrcBlend || | |
241 this->fDstBlend != that.fDstBlend || | |
242 this->fDrawType != that.fDrawType || | 199 this->fDrawType != that.fDrawType || |
243 this->fBlendConstant != that.fBlendConstant || | |
244 this->fFlags != that.fFlags || | 200 this->fFlags != that.fFlags || |
245 this->fStencilSettings != that.fStencilSettings || | 201 this->fStencilSettings != that.fStencilSettings || |
246 this->fDrawFace != that.fDrawFace || | 202 this->fDrawFace != that.fDrawFace || |
247 this->fDstCopy.texture() != that.fDstCopy.texture()) { | 203 this->fDstCopy.texture() != that.fDstCopy.texture()) { |
248 return false; | 204 return false; |
249 } | 205 } |
250 | 206 |
251 if (!fDescInfo.fHasVertexCoverage && this->fCoverage != that.fCoverage) { | 207 if (!fDescInfo.fHasVertexCoverage && this->fCoverage != that.fCoverage) { |
252 return false; | 208 return false; |
253 } | 209 } |
254 | 210 |
255 if (this->hasGeometryProcessor()) { | 211 if (this->hasGeometryProcessor()) { |
256 if (!that.hasGeometryProcessor()) { | 212 if (!that.hasGeometryProcessor()) { |
257 return false; | 213 return false; |
258 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce
ssor())) { | 214 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce
ssor())) { |
259 return false; | 215 return false; |
260 } | 216 } |
261 } else if (that.hasGeometryProcessor()) { | 217 } else if (that.hasGeometryProcessor()) { |
262 return false; | 218 return false; |
263 } | 219 } |
264 | 220 |
| 221 if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) { |
| 222 return false; |
| 223 } |
| 224 |
265 // The program desc comparison should have already assured that the stage co
unts match. | 225 // The program desc comparison should have already assured that the stage co
unts match. |
266 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); | 226 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); |
267 for (int i = 0; i < this->numFragmentStages(); i++) { | 227 for (int i = 0; i < this->numFragmentStages(); i++) { |
268 | 228 |
269 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { | 229 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { |
270 return false; | 230 return false; |
271 } | 231 } |
272 } | 232 } |
273 return true; | 233 return true; |
274 } | 234 } |
275 | 235 |
OLD | NEW |