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 | 14 |
15 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, | 15 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, |
| 16 GrColor color, |
| 17 uint8_t coverage, |
16 const GrDrawTargetCaps& caps, | 18 const GrDrawTargetCaps& caps, |
17 const ScissorState& scissorState, | 19 const ScissorState& scissorState, |
18 const GrDeviceCoordTexture* dstCopy, | 20 const GrDeviceCoordTexture* dstCopy, |
19 GrGpu::DrawType drawType) | 21 GrGpu::DrawType drawType) |
20 : fFinalized(false) { | 22 : fFinalized(false) { |
| 23 GrColor c = GrColorPackRGBA(coverage, coverage, coverage, coverage); |
21 fDrawType = drawType; | 24 fDrawType = drawType; |
22 GrBlendCoeff optSrcCoeff; | 25 GrBlendCoeff optSrcCoeff; |
23 GrBlendCoeff optDstCoeff; | 26 GrBlendCoeff optDstCoeff; |
24 GrDrawState::BlendOpt blendOpt = drawState.getBlendOpt(false, &optSrcCoeff,
&optDstCoeff); | 27 GrDrawState::BlendOpt blendOpt = drawState.getBlendOpt(color, c, false, &opt
SrcCoeff, |
| 28 &optDstCoeff); |
25 | 29 |
26 // When path rendering the stencil settings are not always set on the draw s
tate | 30 // When path rendering the stencil settings are not always set on the draw s
tate |
27 // so we must check the draw type. In cases where we will skip drawing we si
mply return a | 31 // so we must check the draw type. In cases where we will skip drawing we si
mply return a |
28 // null GrOptDrawState. | 32 // null GrOptDrawState. |
29 if (GrDrawState::kSkipDraw_BlendOpt == blendOpt && GrGpu::kStencilPath_DrawT
ype != drawType) { | 33 if (GrDrawState::kSkipDraw_BlendOpt == blendOpt && GrGpu::kStencilPath_DrawT
ype != drawType) { |
30 // Set the fields that don't default init and return. The lack of a rend
er target will | 34 // Set the fields that don't default init and return. The lack of a rend
er target will |
31 // indicate that this can be skipped. | 35 // indicate that this can be skipped. |
32 fFlags = 0; | 36 fFlags = 0; |
33 fDrawFace = GrDrawState::kInvalid_DrawFace; | 37 fDrawFace = GrDrawState::kInvalid_DrawFace; |
34 fSrcBlend = kZero_GrBlendCoeff; | 38 fSrcBlend = kZero_GrBlendCoeff; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 70 |
67 fDescInfo.fHasVertexColor = drawState.hasGeometryProcessor() && | 71 fDescInfo.fHasVertexColor = drawState.hasGeometryProcessor() && |
68 drawState.getGeometryProcessor()->hasVertexColor
(); | 72 drawState.getGeometryProcessor()->hasVertexColor
(); |
69 | 73 |
70 fDescInfo.fHasVertexCoverage = drawState.hasGeometryProcessor() && | 74 fDescInfo.fHasVertexCoverage = drawState.hasGeometryProcessor() && |
71 drawState.getGeometryProcessor()->hasVertexCo
verage(); | 75 drawState.getGeometryProcessor()->hasVertexCo
verage(); |
72 | 76 |
73 bool hasLocalCoords = drawState.hasGeometryProcessor() && | 77 bool hasLocalCoords = drawState.hasGeometryProcessor() && |
74 drawState.getGeometryProcessor()->hasLocalCoords(); | 78 drawState.getGeometryProcessor()->hasLocalCoords(); |
75 | 79 |
76 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(); | 80 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(color); |
77 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); | 81 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); |
78 fDescInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed(); | 82 fDescInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed(); |
79 fColor = colorPOI.inputColorToEffectiveStage(); | 83 fColor = colorPOI.inputColorToEffectiveStage(); |
80 if (colorPOI.removeVertexAttrib()) { | 84 if (colorPOI.removeVertexAttrib()) { |
81 fDescInfo.fHasVertexColor = false; | 85 fDescInfo.fHasVertexColor = false; |
82 } | 86 } |
83 | 87 |
84 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use | 88 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use |
85 // drawState's coverageProcInfo (like color above) to set this initial infor
mation. | 89 // drawState's coverageProcInfo (like color above) to set this initial infor
mation. |
86 int firstCoverageStageIdx = 0; | 90 int firstCoverageStageIdx = 0; |
87 fDescInfo.fInputCoverageIsUsed = true; | 91 fDescInfo.fInputCoverageIsUsed = true; |
88 fCoverage = drawState.getCoverage(); | 92 fCoverage = coverage; |
89 | 93 |
90 this->adjustProgramForBlendOpt(drawState, blendOpt, &firstColorStageIdx, | 94 this->adjustProgramForBlendOpt(drawState, blendOpt, &firstColorStageIdx, |
91 &firstCoverageStageIdx); | 95 &firstCoverageStageIdx); |
92 | 96 |
93 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, ha
sLocalCoords); | 97 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, ha
sLocalCoords); |
94 | 98 |
95 // Copy GeometryProcesssor from DS or ODS | 99 // Copy GeometryProcesssor from DS or ODS |
96 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType) || | 100 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType) || |
97 GrGpu::kStencilPath_DrawType || | 101 GrGpu::kStencilPath_DrawType || |
98 drawState.hasGeometryProcessor()); | 102 drawState.hasGeometryProcessor()); |
(...skipping 10 matching lines...) Expand all Loading... |
109 GrPendingFragmentStage, | 113 GrPendingFragmentStage, |
110 (drawState.fColorStages[i], hasLocalCoords)); | 114 (drawState.fColorStages[i], hasLocalCoords)); |
111 } | 115 } |
112 fNumColorStages = fFragmentStages.count(); | 116 fNumColorStages = fFragmentStages.count(); |
113 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i)
{ | 117 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i)
{ |
114 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, | 118 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
115 GrPendingFragmentStage, | 119 GrPendingFragmentStage, |
116 (drawState.fCoverageStages[i], hasLocalCoords)); | 120 (drawState.fCoverageStages[i], hasLocalCoords)); |
117 } | 121 } |
118 | 122 |
119 this->setOutputStateInfo(drawState, blendOpt, caps); | 123 this->setOutputStateInfo(drawState, c, blendOpt, caps); |
120 | 124 |
121 // let the GP init the batch tracker | 125 // let the GP init the batch tracker |
122 if (drawState.hasGeometryProcessor()) { | 126 if (drawState.hasGeometryProcessor()) { |
123 GrGeometryProcessor::InitBT init; | 127 GrGeometryProcessor::InitBT init; |
124 init.fOutputColor = fDescInfo.fInputColorIsUsed; | 128 init.fOutputColor = fDescInfo.fInputColorIsUsed; |
125 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; | 129 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; |
126 init.fColor = this->getColor(); | 130 init.fColor = this->getColor(); |
127 init.fCoverage = this->getCoverage(); | 131 init.fCoverage = this->getCoverage(); |
128 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); | 132 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); |
129 } | 133 } |
130 } | 134 } |
131 | 135 |
132 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, | 136 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, |
| 137 GrColor coverage, |
133 GrDrawState::BlendOpt blendOpt, | 138 GrDrawState::BlendOpt blendOpt, |
134 const GrDrawTargetCaps& caps) { | 139 const GrDrawTargetCaps& caps) { |
135 // Set this default and then possibly change our mind if there is coverage. | 140 // Set this default and then possibly change our mind if there is coverage. |
136 fDescInfo.fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; | 141 fDescInfo.fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; |
137 fDescInfo.fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; | 142 fDescInfo.fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; |
138 | 143 |
139 // Determine whether we should use dual source blending or shader code to ke
ep coverage | 144 // Determine whether we should use dual source blending or shader code to ke
ep coverage |
140 // separate from color. | 145 // separate from color. |
141 bool keepCoverageSeparate = !(GrDrawState::kCoverageAsAlpha_BlendOpt == blen
dOpt || | 146 bool keepCoverageSeparate = !(GrDrawState::kCoverageAsAlpha_BlendOpt == blen
dOpt || |
142 GrDrawState::kEmitCoverage_BlendOpt == blendOp
t); | 147 GrDrawState::kEmitCoverage_BlendOpt == blendOp
t); |
143 if (keepCoverageSeparate && !ds.hasSolidCoverage()) { | 148 if (keepCoverageSeparate && !ds.hasSolidCoverage(coverage)) { |
144 if (caps.dualSourceBlendingSupport()) { | 149 if (caps.dualSourceBlendingSupport()) { |
145 if (kZero_GrBlendCoeff == fDstBlend) { | 150 if (kZero_GrBlendCoeff == fDstBlend) { |
146 // write the coverage value to second color | 151 // write the coverage value to second color |
147 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverage_Second
aryOutputType; | 152 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverage_Second
aryOutputType; |
148 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 153 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
149 } else if (kSA_GrBlendCoeff == fDstBlend) { | 154 } else if (kSA_GrBlendCoeff == fDstBlend) { |
150 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. | 155 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially
covered. |
151 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec
ondaryOutputType; | 156 fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec
ondaryOutputType; |
152 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; | 157 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; |
153 } else if (kSC_GrBlendCoeff == fDstBlend) { | 158 } else if (kSC_GrBlendCoeff == fDstBlend) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); | 279 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); |
275 for (int i = 0; i < this->numFragmentStages(); i++) { | 280 for (int i = 0; i < this->numFragmentStages(); i++) { |
276 | 281 |
277 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { | 282 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { |
278 return false; | 283 return false; |
279 } | 284 } |
280 } | 285 } |
281 return true; | 286 return true; |
282 } | 287 } |
283 | 288 |
OLD | NEW |