| 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); | |
| 49 } | 48 } |
| 50 | 49 |
| 51 // When path rendering the stencil settings are not always set on the draw s
tate | 50 // When path rendering the stencil settings are not always set on the draw s
tate |
| 52 // so we must check the draw type. In cases where we will skip drawing we si
mply return a | 51 // so we must check the draw type. In cases where we will skip drawing we si
mply return a |
| 53 // null GrOptDrawState. | 52 // null GrOptDrawState. |
| 54 if (!xferProcessor || ((GrXferProcessor::kSkipDraw_OptFlag & optFlags) && | 53 if (!xferProcessor || ((GrXferProcessor::kSkipDraw_OptFlag & optFlags) && |
| 55 GrGpu::kStencilPath_DrawType != drawType)) { | 54 GrGpu::kStencilPath_DrawType != drawType)) { |
| 56 // Set the fields that don't default init and return. The lack of a rend
er target will | 55 // Set the fields that don't default init and return. The lack of a rend
er target will |
| 57 // indicate that this can be skipped. | 56 // indicate that this can be skipped. |
| 58 fFlags = 0; | 57 fFlags = 0; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 139 |
| 141 // let the GP init the batch tracker | 140 // let the GP init the batch tracker |
| 142 if (drawState.hasGeometryProcessor()) { | 141 if (drawState.hasGeometryProcessor()) { |
| 143 GrGeometryProcessor::InitBT init; | 142 GrGeometryProcessor::InitBT init; |
| 144 init.fOutputColor = fDescInfo.fInputColorIsUsed; | 143 init.fOutputColor = fDescInfo.fInputColorIsUsed; |
| 145 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; | 144 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; |
| 146 init.fColor = this->getColor(); | 145 init.fColor = this->getColor(); |
| 147 init.fCoverage = this->getCoverage(); | 146 init.fCoverage = this->getCoverage(); |
| 148 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); | 147 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); |
| 149 } | 148 } |
| 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 } |
| 150 } | 185 } |
| 151 | 186 |
| 152 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds, | 187 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds, |
| 153 GrXferProcessor::OptFlags fl
ags, | 188 GrXferProcessor::OptFlags fl
ags, |
| 154 const GrProcOptInfo& colorPO
I, | 189 const GrProcOptInfo& colorPO
I, |
| 155 const GrProcOptInfo& coverag
ePOI, | 190 const GrProcOptInfo& coverag
ePOI, |
| 156 int* firstColorStageIdx, | 191 int* firstColorStageIdx, |
| 157 int* firstCoverageStageIdx)
{ | 192 int* firstCoverageStageIdx)
{ |
| 158 fDescInfo.fReadsDst = false; | 193 fDescInfo.fReadsDst = false; |
| 159 fDescInfo.fReadsFragPosition = false; | 194 fDescInfo.fReadsFragPosition = false; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 if (this->hasGeometryProcessor()) { | 255 if (this->hasGeometryProcessor()) { |
| 221 if (!that.hasGeometryProcessor()) { | 256 if (!that.hasGeometryProcessor()) { |
| 222 return false; | 257 return false; |
| 223 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce
ssor())) { | 258 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce
ssor())) { |
| 224 return false; | 259 return false; |
| 225 } | 260 } |
| 226 } else if (that.hasGeometryProcessor()) { | 261 } else if (that.hasGeometryProcessor()) { |
| 227 return false; | 262 return false; |
| 228 } | 263 } |
| 229 | 264 |
| 230 if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) { | |
| 231 return false; | |
| 232 } | |
| 233 | |
| 234 // The program desc comparison should have already assured that the stage co
unts match. | 265 // The program desc comparison should have already assured that the stage co
unts match. |
| 235 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); | 266 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); |
| 236 for (int i = 0; i < this->numFragmentStages(); i++) { | 267 for (int i = 0; i < this->numFragmentStages(); i++) { |
| 237 | 268 |
| 238 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { | 269 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { |
| 239 return false; | 270 return false; |
| 240 } | 271 } |
| 241 } | 272 } |
| 242 return true; | 273 return true; |
| 243 } | 274 } |
| 244 | 275 |
| OLD | NEW |