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 14 matching lines...) Expand all Loading... |
25 | 25 |
26 // Copy GeometryProcesssor from DS or ODS | 26 // Copy GeometryProcesssor from DS or ODS |
27 if (gp) { | 27 if (gp) { |
28 SkASSERT(!pathProc); | 28 SkASSERT(!pathProc); |
29 SkASSERT(!(GrGpu::IsPathRenderingDrawType(drawType) || | 29 SkASSERT(!(GrGpu::IsPathRenderingDrawType(drawType) || |
30 GrGpu::kStencilPath_DrawType == drawType)); | 30 GrGpu::kStencilPath_DrawType == drawType)); |
31 fGeometryProcessor.reset(gp); | 31 fGeometryProcessor.reset(gp); |
32 fPrimitiveProcessor.reset(gp); | 32 fPrimitiveProcessor.reset(gp); |
33 } else { | 33 } else { |
34 SkASSERT(!gp && pathProc && (GrGpu::IsPathRenderingDrawType(drawType) || | 34 SkASSERT(!gp && pathProc && (GrGpu::IsPathRenderingDrawType(drawType) || |
35 GrGpu::kStencilPath_DrawType == drawType)); | 35 GrGpu::kStencilPath_DrawType == drawType)); |
36 fPrimitiveProcessor.reset(pathProc); | 36 fPrimitiveProcessor.reset(pathProc); |
37 } | 37 } |
38 | 38 |
39 | 39 |
40 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(fPrimitiveProcessor)
; | 40 const GrProcOptInfo& colorPOI = drawState.colorProcInfo(fPrimitiveProcessor)
; |
41 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(fPrimitiveProc
essor); | 41 const GrProcOptInfo& coveragePOI = drawState.coverageProcInfo(fPrimitiveProc
essor); |
42 | |
43 fColor = colorPOI.inputColorToEffectiveStage(); | |
44 // TODO fix this when coverage stages work correctly | |
45 // fCoverage = coveragePOI.inputColorToEffectiveStage(); | |
46 fCoverage = fPrimitiveProcessor->coverage(); | |
47 | 42 |
48 // Create XferProcessor from DS's XPFactory | 43 // Create XferProcessor from DS's XPFactory |
49 SkAutoTUnref<GrXferProcessor> xferProcessor( | 44 SkAutoTUnref<GrXferProcessor> xferProcessor( |
50 drawState.getXPFactory()->createXferProcessor(colorPOI, coveragePOI)); | 45 drawState.getXPFactory()->createXferProcessor(colorPOI, coveragePOI)); |
51 | 46 |
| 47 GrColor overrideColor = GrColor_ILLEGAL; |
| 48 if (colorPOI.firstEffectiveStageIndex() != 0) { |
| 49 overrideColor = colorPOI.inputColorToEffectiveStage(); |
| 50 } |
| 51 |
52 GrXferProcessor::OptFlags optFlags; | 52 GrXferProcessor::OptFlags optFlags; |
53 if (xferProcessor) { | 53 if (xferProcessor) { |
54 fXferProcessor.reset(xferProcessor.get()); | 54 fXferProcessor.reset(xferProcessor.get()); |
55 | 55 |
56 optFlags = xferProcessor->getOptimizations(colorPOI, | 56 optFlags = xferProcessor->getOptimizations(colorPOI, |
57 coveragePOI, | 57 coveragePOI, |
58 drawState.isCoverageDrawing()
, | 58 drawState.isCoverageDrawing()
, |
59 drawState.isColorWriteDisable
d(), | 59 drawState.isColorWriteDisable
d(), |
60 drawState.getStencil().doesWr
ite(), | 60 drawState.getStencil().doesWr
ite(), |
61 &fColor, | 61 &overrideColor, |
62 &fCoverage, | |
63 caps); | 62 caps); |
64 } | 63 } |
65 | 64 |
66 // When path rendering the stencil settings are not always set on the draw s
tate | 65 // When path rendering the stencil settings are not always set on the draw s
tate |
67 // so we must check the draw type. In cases where we will skip drawing we si
mply return a | 66 // so we must check the draw type. In cases where we will skip drawing we si
mply return a |
68 // null GrOptDrawState. | 67 // null GrOptDrawState. |
69 if (!xferProcessor || ((GrXferProcessor::kSkipDraw_OptFlag & optFlags) && | 68 if (!xferProcessor || ((GrXferProcessor::kSkipDraw_OptFlag & optFlags) && |
70 GrGpu::kStencilPath_DrawType != drawType)) { | 69 GrGpu::kStencilPath_DrawType != drawType)) { |
71 // Set the fields that don't default init and return. The lack of a rend
er target will | 70 // Set the fields that don't default init and return. The lack of a rend
er target will |
72 // indicate that this can be skipped. | 71 // indicate that this can be skipped. |
(...skipping 18 matching lines...) Expand all Loading... |
91 if (drawState.isHWAntialias()) { | 90 if (drawState.isHWAntialias()) { |
92 fFlags |= kHWAA_Flag; | 91 fFlags |= kHWAA_Flag; |
93 } | 92 } |
94 if (drawState.isColorWriteDisabled()) { | 93 if (drawState.isColorWriteDisabled()) { |
95 fFlags |= kDisableColorWrite_Flag; | 94 fFlags |= kDisableColorWrite_Flag; |
96 } | 95 } |
97 if (drawState.isDither()) { | 96 if (drawState.isDither()) { |
98 fFlags |= kDither_Flag; | 97 fFlags |= kDither_Flag; |
99 } | 98 } |
100 | 99 |
101 fDescInfo.fHasVertexColor = gp && gp->hasVertexColor(); | 100 // TODO move local coords completely into GP |
102 | |
103 fDescInfo.fHasVertexCoverage = gp && gp->hasVertexCoverage(); | |
104 | |
105 bool hasLocalCoords = gp && gp->hasLocalCoords(); | 101 bool hasLocalCoords = gp && gp->hasLocalCoords(); |
106 | 102 |
107 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); | 103 int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); |
108 fDescInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed(); | |
109 if (colorPOI.removeVertexAttrib()) { | |
110 fDescInfo.fHasVertexColor = false; | |
111 } | |
112 | 104 |
113 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use | 105 // TODO: Once we can handle single or four channel input into coverage stage
s then we can use |
114 // drawState's coverageProcInfo (like color above) to set this initial infor
mation. | 106 // drawState's coverageProcInfo (like color above) to set this initial infor
mation. |
115 int firstCoverageStageIdx = 0; | 107 int firstCoverageStageIdx = 0; |
116 fDescInfo.fInputCoverageIsUsed = true; | |
117 | 108 |
118 GrXferProcessor::BlendInfo blendInfo; | 109 GrXferProcessor::BlendInfo blendInfo; |
119 fXferProcessor->getBlendInfo(&blendInfo); | 110 fXferProcessor->getBlendInfo(&blendInfo); |
120 | 111 |
121 this->adjustProgramFromOptimizations(drawState, optFlags, colorPOI, coverage
POI, | 112 this->adjustProgramFromOptimizations(drawState, optFlags, colorPOI, coverage
POI, |
122 &firstColorStageIdx, &firstCoverageStag
eIdx); | 113 &firstColorStageIdx, &firstCoverageStag
eIdx); |
123 | 114 |
124 fDescInfo.fRequiresLocalCoordAttrib = hasLocalCoords; | 115 fDescInfo.fRequiresLocalCoordAttrib = hasLocalCoords; |
125 | 116 |
126 // Copy Stages from DS to ODS | 117 // Copy Stages from DS to ODS |
127 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) { | 118 for (int i = firstColorStageIdx; i < drawState.numColorStages(); ++i) { |
128 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, | 119 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
129 GrPendingFragmentStage, | 120 GrPendingFragmentStage, |
130 (drawState.fColorStages[i], hasLocalCoords)); | 121 (drawState.fColorStages[i], hasLocalCoords)); |
131 } | 122 } |
132 | 123 |
133 fNumColorStages = fFragmentStages.count(); | 124 fNumColorStages = fFragmentStages.count(); |
134 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i)
{ | 125 for (int i = firstCoverageStageIdx; i < drawState.numCoverageStages(); ++i)
{ |
135 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, | 126 SkNEW_APPEND_TO_TARRAY(&fFragmentStages, |
136 GrPendingFragmentStage, | 127 GrPendingFragmentStage, |
137 (drawState.fCoverageStages[i], hasLocalCoords)); | 128 (drawState.fCoverageStages[i], hasLocalCoords)); |
138 } | 129 } |
139 | 130 |
140 // let the GP init the batch tracker | 131 // let the GP init the batch tracker |
141 if (gp) { | 132 GrGeometryProcessor::InitBT init; |
142 GrGeometryProcessor::InitBT init; | 133 init.fColorIgnored = SkToBool(optFlags & GrXferProcessor::kIgnoreColor_OptFl
ag); |
143 init.fOutputColor = fDescInfo.fInputColorIsUsed; | 134 init.fOverrideColor = init.fColorIgnored ? GrColor_ILLEGAL : overrideColor; |
144 init.fOutputCoverage = fDescInfo.fInputCoverageIsUsed; | 135 init.fCoverageIgnored = SkToBool(optFlags & GrXferProcessor::kIgnoreCoverage
_OptFlag); |
145 init.fColor = this->getColor(); | 136 fPrimitiveProcessor->initBatchTracker(&fBatchTracker, init); |
146 init.fCoverage = this->getCoverage(); | |
147 fGeometryProcessor->initBatchTracker(&fBatchTracker, init); | |
148 } | |
149 } | 137 } |
150 | 138 |
151 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds, | 139 void GrOptDrawState::adjustProgramFromOptimizations(const GrDrawState& ds, |
152 GrXferProcessor::OptFlags fl
ags, | 140 GrXferProcessor::OptFlags fl
ags, |
153 const GrProcOptInfo& colorPO
I, | 141 const GrProcOptInfo& colorPO
I, |
154 const GrProcOptInfo& coverag
ePOI, | 142 const GrProcOptInfo& coverag
ePOI, |
155 int* firstColorStageIdx, | 143 int* firstColorStageIdx, |
156 int* firstCoverageStageIdx)
{ | 144 int* firstCoverageStageIdx)
{ |
157 fDescInfo.fReadsDst = false; | 145 fDescInfo.fReadsDst = false; |
158 fDescInfo.fReadsFragPosition = false; | 146 fDescInfo.fReadsFragPosition = false; |
159 | 147 |
160 if (flags & GrXferProcessor::kClearColorStages_OptFlag || | 148 if ((flags & GrXferProcessor::kIgnoreColor_OptFlag) || |
161 flags & GrXferProcessor::kOverrideColor_OptFlag) { | 149 (flags & GrXferProcessor::kOverrideColor_OptFlag)) { |
162 fDescInfo.fInputColorIsUsed = true; | |
163 *firstColorStageIdx = ds.numColorStages(); | 150 *firstColorStageIdx = ds.numColorStages(); |
164 fDescInfo.fHasVertexColor = false; | |
165 } else { | 151 } else { |
166 fDescInfo.fReadsDst = colorPOI.readsDst(); | 152 fDescInfo.fReadsDst = colorPOI.readsDst(); |
167 fDescInfo.fReadsFragPosition = colorPOI.readsFragPosition(); | 153 fDescInfo.fReadsFragPosition = colorPOI.readsFragPosition(); |
168 } | 154 } |
169 | 155 |
170 if (flags & GrXferProcessor::kClearCoverageStages_OptFlag) { | 156 if (flags & GrXferProcessor::kIgnoreCoverage_OptFlag) { |
171 fDescInfo.fInputCoverageIsUsed = true; | |
172 *firstCoverageStageIdx = ds.numCoverageStages(); | 157 *firstCoverageStageIdx = ds.numCoverageStages(); |
173 fDescInfo.fHasVertexCoverage = false; | |
174 } else { | 158 } else { |
175 if (coveragePOI.readsDst()) { | 159 if (coveragePOI.readsDst()) { |
176 fDescInfo.fReadsDst = true; | 160 fDescInfo.fReadsDst = true; |
177 } | 161 } |
178 if (coveragePOI.readsFragPosition()) { | 162 if (coveragePOI.readsFragPosition()) { |
179 fDescInfo.fReadsFragPosition = true; | 163 fDescInfo.fReadsFragPosition = true; |
180 } | 164 } |
181 } | 165 } |
182 } | 166 } |
183 | 167 |
184 void GrOptDrawState::finalize(GrGpu* gpu) { | 168 void GrOptDrawState::finalize(GrGpu* gpu) { |
185 gpu->buildProgramDesc(*this, fDescInfo, fDrawType, &fDesc); | 169 gpu->buildProgramDesc(*this, fDescInfo, fDrawType, &fDesc); |
186 fFinalized = true; | 170 fFinalized = true; |
187 } | 171 } |
188 | 172 |
189 //////////////////////////////////////////////////////////////////////////////// | 173 //////////////////////////////////////////////////////////////////////////////// |
190 | 174 |
191 bool GrOptDrawState::operator== (const GrOptDrawState& that) const { | 175 bool GrOptDrawState::combineIfPossible(const GrOptDrawState& that) { |
192 if (fDescInfo != that.fDescInfo) { | 176 if (fDescInfo != that.fDescInfo) { |
193 return false; | 177 return false; |
194 } | 178 } |
195 | 179 |
196 if (!fDescInfo.fHasVertexColor && this->fColor != that.fColor) { | |
197 return false; | |
198 } | |
199 | |
200 if (this->getRenderTarget() != that.getRenderTarget() || | 180 if (this->getRenderTarget() != that.getRenderTarget() || |
201 this->fFragmentStages.count() != that.fFragmentStages.count() || | 181 this->fFragmentStages.count() != that.fFragmentStages.count() || |
202 this->fNumColorStages != that.fNumColorStages || | 182 this->fNumColorStages != that.fNumColorStages || |
203 this->fScissorState != that.fScissorState || | 183 this->fScissorState != that.fScissorState || |
204 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || | 184 !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || |
205 this->fDrawType != that.fDrawType || | 185 this->fDrawType != that.fDrawType || |
206 this->fFlags != that.fFlags || | 186 this->fFlags != that.fFlags || |
207 this->fStencilSettings != that.fStencilSettings || | 187 this->fStencilSettings != that.fStencilSettings || |
208 this->fDrawFace != that.fDrawFace || | 188 this->fDrawFace != that.fDrawFace || |
209 this->fDstCopy.texture() != that.fDstCopy.texture()) { | 189 this->fDstCopy.texture() != that.fDstCopy.texture()) { |
210 return false; | 190 return false; |
211 } | 191 } |
212 | 192 |
213 if (!fDescInfo.fHasVertexCoverage && this->fCoverage != that.fCoverage) { | 193 if (!this->getPrimitiveProcessor()->canMakeEqual(fBatchTracker, |
| 194 *that.getPrimitiveProcessor
(), |
| 195 that.getBatchTracker())) { |
214 return false; | 196 return false; |
215 } | 197 } |
216 | 198 |
217 if (this->hasGeometryProcessor()) { | |
218 if (!that.hasGeometryProcessor()) { | |
219 return false; | |
220 } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProce
ssor())) { | |
221 return false; | |
222 } | |
223 } else if (that.hasGeometryProcessor()) { | |
224 return false; | |
225 } | |
226 | |
227 if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) { | 199 if (!this->getXferProcessor()->isEqual(*that.getXferProcessor())) { |
228 return false; | 200 return false; |
229 } | 201 } |
230 | 202 |
231 // The program desc comparison should have already assured that the stage co
unts match. | 203 // The program desc comparison should have already assured that the stage co
unts match. |
232 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); | 204 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); |
233 for (int i = 0; i < this->numFragmentStages(); i++) { | 205 for (int i = 0; i < this->numFragmentStages(); i++) { |
234 | 206 |
235 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { | 207 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { |
236 return false; | 208 return false; |
237 } | 209 } |
238 } | 210 } |
| 211 |
| 212 // Now update the GrPrimitiveProcessor's batch tracker |
| 213 fPrimitiveProcessor->makeEqual(&fBatchTracker, that.getBatchTracker()); |
239 return true; | 214 return true; |
240 } | 215 } |
241 | 216 |
OLD | NEW |