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 23 matching lines...) Expand all Loading... |
34 GrXferProcessor::OptFlags optFlags; | 34 GrXferProcessor::OptFlags optFlags; |
35 if (xferProcessor.get()) { | 35 if (xferProcessor.get()) { |
36 fXferProcessor.reset(xferProcessor.get()); | 36 fXferProcessor.reset(xferProcessor.get()); |
37 | 37 |
38 optFlags = xferProcessor->getOptimizations(colorPOI, | 38 optFlags = xferProcessor->getOptimizations(colorPOI, |
39 coveragePOI, | 39 coveragePOI, |
40 drawState.isCoverageDrawing()
, | 40 drawState.isCoverageDrawing()
, |
41 drawState.isColorWriteDisable
d(), | 41 drawState.isColorWriteDisable
d(), |
42 drawState.getStencil().doesWr
ite(), | 42 drawState.getStencil().doesWr
ite(), |
43 &fColor, | 43 &fColor, |
44 &fCoverage); | 44 &fCoverage, |
| 45 caps); |
45 } | 46 } |
46 | 47 |
47 // When path rendering the stencil settings are not always set on the draw s
tate | 48 // When path rendering the stencil settings are not always set on the draw s
tate |
48 // so we must check the draw type. In cases where we will skip drawing we si
mply return a | 49 // so we must check the draw type. In cases where we will skip drawing we si
mply return a |
49 // null GrOptDrawState. | 50 // null GrOptDrawState. |
50 if (NULL == xferProcessor.get() || ((GrXferProcessor::kSkipDraw_OptFlag & op
tFlags) && | 51 if (NULL == xferProcessor.get() || ((GrXferProcessor::kSkipDraw_OptFlag & op
tFlags) && |
51 GrGpu::kStencilPath_DrawType != drawType
)) { | 52 GrGpu::kStencilPath_DrawType != drawType
)) { |
52 // Set the fields that don't default init and return. The lack of a rend
er target will | 53 // Set the fields that don't default init and return. The lack of a rend
er target will |
53 // indicate that this can be skipped. | 54 // indicate that this can be skipped. |
54 fFlags = 0; | 55 fFlags = 0; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 137 |
137 // let the GP init the batch tracker | 138 // let the GP init the batch tracker |
138 if (drawState.hasGeometryProcessor()) { | 139 if (drawState.hasGeometryProcessor()) { |
139 GrGeometryProcessor::InitBT init; | 140 GrGeometryProcessor::InitBT init; |
140 init.fOutputColor = fDescInfo.fInputColorIsUsed; | 141 init.fOutputColor = fDescInfo.fInputColorIsUsed; |
141 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; | 142 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; |
142 init.fColor = this->getColor(); | 143 init.fColor = this->getColor(); |
143 init.fCoverage = this->getCoverage(); | 144 init.fCoverage = this->getCoverage(); |
144 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); | 145 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); |
145 } | 146 } |
146 | |
147 this->setOutputStateInfo(drawState, optFlags, caps); | |
148 } | |
149 | |
150 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, | |
151 GrXferProcessor::OptFlags optFlags, | |
152 const GrDrawTargetCaps& caps) { | |
153 // Set this default and then possibly change our mind if there is coverage. | |
154 fDescInfo.fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; | |
155 fDescInfo.fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; | |
156 | |
157 // Determine whether we should use dual source blending or shader code to ke
ep coverage | |
158 // separate from color. | |
159 bool keepCoverageSeparate = !(optFlags & GrXferProcessor::kSetCoverageDrawin
g_OptFlag); | |
160 if (keepCoverageSeparate && !ds.hasSolidCoverage()) { | |
161 if (caps.dualSourceBlendingSupport()) { | |
162 if (kZero_GrBlendCoeff == fDstBlend) { | |
163 // write the coverage value to second color | |
164 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverage_Second
aryOutputType; | |
165 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | |
166 } else if (kSA_GrBlendCoeff == fDstBlend) { | |
167 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | |
168 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec
ondaryOutputType; | |
169 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | |
170 } else if (kSC_GrBlendCoeff == fDstBlend) { | |
171 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | |
172 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISC_Sec
ondaryOutputType; | |
173 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | |
174 } | |
175 } else if (fDescInfo.fReadsDst && | |
176 kOne_GrBlendCoeff == fSrcBlend && | |
177 kZero_GrBlendCoeff == fDstBlend) { | |
178 fDescInfo.fPrimaryOutputType = GrProgramDesc::kCombineWithDst_Primar
yOutputType; | |
179 } | |
180 } | |
181 } | 147 } |
182 | 148 |
183 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds, | 149 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds, |
184 GrXferProcessor::OptFlags fl
ags, | 150 GrXferProcessor::OptFlags fl
ags, |
185 const GrProcOptInfo& colorPO
I, | 151 const GrProcOptInfo& colorPO
I, |
186 const GrProcOptInfo& coverag
ePOI, | 152 const GrProcOptInfo& coverag
ePOI, |
187 int* firstColorStageIdx, | 153 int* firstColorStageIdx, |
188 int* firstCoverageStageIdx)
{ | 154 int* firstCoverageStageIdx)
{ |
189 fDescInfo.fReadsDst = false; | 155 fDescInfo.fReadsDst = false; |
190 fDescInfo.fReadsFragPosition = false; | 156 fDescInfo.fReadsFragPosition = false; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 if (this->hasGeometryProcessor()) { | 217 if (this->hasGeometryProcessor()) { |
252 if (!that.hasGeometryProcessor()) { | 218 if (!that.hasGeometryProcessor()) { |
253 return false; | 219 return false; |
254 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce
ssor())) { | 220 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce
ssor())) { |
255 return false; | 221 return false; |
256 } | 222 } |
257 } else if (that.hasGeometryProcessor()) { | 223 } else if (that.hasGeometryProcessor()) { |
258 return false; | 224 return false; |
259 } | 225 } |
260 | 226 |
| 227 if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) { |
| 228 return false; |
| 229 } |
| 230 |
261 // The program desc comparison should have already assured that the stage co
unts match. | 231 // The program desc comparison should have already assured that the stage co
unts match. |
262 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); | 232 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); |
263 for (int i = 0; i < this->numFragmentStages(); i++) { | 233 for (int i = 0; i < this->numFragmentStages(); i++) { |
264 | 234 |
265 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { | 235 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { |
266 return false; | 236 return false; |
267 } | 237 } |
268 } | 238 } |
269 return true; | 239 return true; |
270 } | 240 } |
271 | 241 |
OLD | NEW |