| 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" |
| 11 #include "GrDrawTargetCaps.h" | 11 #include "GrDrawTargetCaps.h" |
| 12 #include "GrGpu.h" | 12 #include "GrGpu.h" |
| 13 #include "GrProcOptInfo.h" | 13 #include "GrProcOptInfo.h" |
| 14 #include "GrXferProcessor.h" | 14 #include "GrXferProcessor.h" |
| 15 | 15 |
| 16 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, | 16 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, |
| 17 GrColor color, |
| 18 uint8_t coverage, |
| 17 const GrDrawTargetCaps& caps, | 19 const GrDrawTargetCaps& caps, |
| 18 const ScissorState& scissorState, | 20 const ScissorState& scissorState, |
| 19 const GrDeviceCoordTexture* dstCopy, | 21 const GrDeviceCoordTexture* dstCopy, |
| 20 GrGpu::DrawType drawType) | 22 GrGpu::DrawType drawType) |
| 21 : fFinalized(false) { | 23 : fFinalized(false) { |
| 24 GrColor coverageColor = GrColorPackRGBA(coverage, coverage, coverage, covera
ge); |
| 22 fDrawType = drawType; | 25 fDrawType = drawType; |
| 23 | 26 |
| 24 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(); | 27 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(color); |
| 25 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(); | 28 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(coverageColor)
; |
| 26 | 29 |
| 27 fColor = colorPOI.inputColorToEffectiveStage(); | 30 fColor = colorPOI.inputColorToEffectiveStage(); |
| 28 fCoverage = drawState.getCoverage(); | 31 fCoverage = coverage; |
| 29 | 32 |
| 30 // Create XferProcessor from DS's XPFactory | 33 // Create XferProcessor from DS's XPFactory |
| 31 SkAutoTUnref<GrXferProcessor> xferProcessor( | 34 SkAutoTUnref<GrXferProcessor> xferProcessor( |
| 32 drawState.getXPFactory()->createXferProcessor(colorPOI, coveragePOI)); | 35 drawState.getXPFactory()->createXferProcessor(colorPOI, coveragePOI)); |
| 33 | 36 |
| 34 GrXferProcessor::OptFlags optFlags; | 37 GrXferProcessor::OptFlags optFlags; |
| 35 if (xferProcessor) { | 38 if (xferProcessor) { |
| 36 fXferProcessor.reset(xferProcessor.get()); | 39 fXferProcessor.reset(xferProcessor.get()); |
| 37 | 40 |
| 38 optFlags = xferProcessor->getOptimizations(colorPOI, | 41 optFlags = xferProcessor->getOptimizations(colorPOI, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // let the GP init the batch tracker | 140 // let the GP init the batch tracker |
| 138 if (drawState.hasGeometryProcessor()) { | 141 if (drawState.hasGeometryProcessor()) { |
| 139 GrGeometryProcessor::InitBT init; | 142 GrGeometryProcessor::InitBT init; |
| 140 init.fOutputColor = fDescInfo.fInputColorIsUsed; | 143 init.fOutputColor = fDescInfo.fInputColorIsUsed; |
| 141 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; | 144 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; |
| 142 init.fColor = this->getColor(); | 145 init.fColor = this->getColor(); |
| 143 init.fCoverage = this->getCoverage(); | 146 init.fCoverage = this->getCoverage(); |
| 144 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); | 147 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); |
| 145 } | 148 } |
| 146 | 149 |
| 147 this->setOutputStateInfo(drawState, optFlags, caps); | 150 this->setOutputStateInfo(drawState, coverageColor, optFlags, caps); |
| 148 } | 151 } |
| 149 | 152 |
| 150 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, | 153 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, |
| 154 GrColor coverage, |
| 151 GrXferProcessor::OptFlags optFlags, | 155 GrXferProcessor::OptFlags optFlags, |
| 152 const GrDrawTargetCaps& caps) { | 156 const GrDrawTargetCaps& caps) { |
| 153 // Set this default and then possibly change our mind if there is coverage. | 157 // Set this default and then possibly change our mind if there is coverage. |
| 154 fDescInfo.fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; | 158 fDescInfo.fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; |
| 155 fDescInfo.fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; | 159 fDescInfo.fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; |
| 156 | 160 |
| 157 // Determine whether we should use dual source blending or shader code to ke
ep coverage | 161 // Determine whether we should use dual source blending or shader code to ke
ep coverage |
| 158 // separate from color. | 162 // separate from color. |
| 159 bool keepCoverageSeparate = !(optFlags & GrXferProcessor::kSetCoverageDrawin
g_OptFlag); | 163 bool keepCoverageSeparate = !(optFlags & GrXferProcessor::kSetCoverageDrawin
g_OptFlag); |
| 160 if (keepCoverageSeparate && !ds.hasSolidCoverage()) { | 164 if (keepCoverageSeparate && !ds.hasSolidCoverage(coverage)) { |
| 161 if (caps.dualSourceBlendingSupport()) { | 165 if (caps.dualSourceBlendingSupport()) { |
| 162 if (kZero_GrBlendCoeff == fDstBlend) { | 166 if (kZero_GrBlendCoeff == fDstBlend) { |
| 163 // write the coverage value to second color | 167 // write the coverage value to second color |
| 164 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverage_Second
aryOutputType; | 168 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverage_Second
aryOutputType; |
| 165 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 169 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
| 166 } else if (kSA_GrBlendCoeff == fDstBlend) { | 170 } else if (kSA_GrBlendCoeff == fDstBlend) { |
| 167 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | 171 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. |
| 168 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec
ondaryOutputType; | 172 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec
ondaryOutputType; |
| 169 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 173 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
| 170 } else if (kSC_GrBlendCoeff == fDstBlend) { | 174 } else if (kSC_GrBlendCoeff == fDstBlend) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); | 266 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); |
| 263 for (int i = 0; i < this->numFragmentStages(); i++) { | 267 for (int i = 0; i < this->numFragmentStages(); i++) { |
| 264 | 268 |
| 265 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { | 269 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { |
| 266 return false; | 270 return false; |
| 267 } | 271 } |
| 268 } | 272 } |
| 269 return true; | 273 return true; |
| 270 } | 274 } |
| 271 | 275 |
| OLD | NEW |