OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrTargetCommands.h" | 8 #include "GrTargetCommands.h" |
9 | 9 |
10 #include "GrColor.h" | 10 #include "GrColor.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 } | 27 } |
28 | 28 |
29 GrTargetCommands::Cmd* GrTargetCommands::recordDrawBatch( | 29 GrTargetCommands::Cmd* GrTargetCommands::recordDrawBatch( |
30 GrInOrderDrawBuffer* iodb, | 30 GrInOrderDrawBuffer* iodb, |
31 GrBatch* batch, | 31 GrBatch* batch, |
32 const GrDrawTarget::PipelineIn fo& pipelineInfo) { | 32 const GrDrawTarget::PipelineIn fo& pipelineInfo) { |
33 if (!this->setupPipelineAndShouldDraw(iodb, batch, pipelineInfo)) { | 33 if (!this->setupPipelineAndShouldDraw(iodb, batch, pipelineInfo)) { |
34 return NULL; | 34 return NULL; |
35 } | 35 } |
36 | 36 |
37 // Check if there is a Batch Draw we can batch with | 37 // Check if there is a Batch Draw we can batch with |
robertphillips
2015/04/30 15:51:08
Why don't we need a "fCmdBuffer.count() && ..." in
| |
38 if (Cmd::kDrawBatch_CmdType != fCmdBuffer.back().type() || !fDrawBatch) { | 38 if (Cmd::kDrawBatch_CmdType == fCmdBuffer.back().type()) { |
39 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fB atchTarget)); | 39 DrawBatch* previous = static_cast<DrawBatch*>(&fCmdBuffer.back()); |
40 return fDrawBatch; | 40 if (!previous->fBatch->combineIfPossible(batch)) { |
robertphillips
2015/04/30 15:51:08
Why not return NULL here and just fall through oth
| |
41 return GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fBat chTarget)); | |
42 } | |
43 // We batched | |
44 return NULL; | |
41 } | 45 } |
42 | 46 |
43 SkASSERT(&fCmdBuffer.back() == fDrawBatch); | 47 DrawBatch* current = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fBatchTarget)); |
44 if (!fDrawBatch->fBatch->combineIfPossible(batch)) { | 48 return current; |
45 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fB atchTarget)); | |
46 } | |
47 | |
48 return fDrawBatch; | |
49 } | 49 } |
50 | 50 |
51 GrTargetCommands::Cmd* GrTargetCommands::recordStencilPath( | 51 GrTargetCommands::Cmd* GrTargetCommands::recordStencilPath( |
52 GrInOrderDrawBuffer* iod b, | 52 GrInOrderDrawBuffer* iod b, |
53 const GrPipelineBuilder& pipelineBuilder, | 53 const GrPipelineBuilder& pipelineBuilder, |
54 const GrPathProcessor* p athProc, | 54 const GrPathProcessor* p athProc, |
55 const GrPath* path, | 55 const GrPath* path, |
56 const GrScissorState& sc issorState, | 56 const GrScissorState& sc issorState, |
57 const GrStencilSettings& stencilSettings) { | 57 const GrStencilSettings& stencilSettings) { |
58 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, | 58 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 SkASSERT(renderTarget); | 183 SkASSERT(renderTarget); |
184 | 184 |
185 Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); | 185 Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); |
186 clr->fColor = GrColor_ILLEGAL; | 186 clr->fColor = GrColor_ILLEGAL; |
187 return clr; | 187 return clr; |
188 } | 188 } |
189 | 189 |
190 void GrTargetCommands::reset() { | 190 void GrTargetCommands::reset() { |
191 fCmdBuffer.reset(); | 191 fCmdBuffer.reset(); |
192 fPrevState = NULL; | 192 fPrevState = NULL; |
193 fDrawBatch = NULL; | |
194 } | 193 } |
195 | 194 |
196 void GrTargetCommands::flush(GrInOrderDrawBuffer* iodb) { | 195 void GrTargetCommands::flush(GrInOrderDrawBuffer* iodb) { |
197 if (fCmdBuffer.empty()) { | 196 if (fCmdBuffer.empty()) { |
198 return; | 197 return; |
199 } | 198 } |
200 | 199 |
201 // Updated every time we find a set state cmd to reflect the current state i n the playback | 200 // Updated every time we find a set state cmd to reflect the current state i n the playback |
202 // stream. | 201 // stream. |
203 SetState* currentState = NULL; | 202 SetState* currentState = NULL; |
204 | 203 |
205 GrGpu* gpu = iodb->getGpu(); | 204 GrGpu* gpu = iodb->getGpu(); |
206 | 205 |
207 #ifdef USE_BITMAP_TEXTBLOBS | |
208 // Loop over all batches and generate geometry | 206 // Loop over all batches and generate geometry |
209 CmdBuffer::Iter genIter(fCmdBuffer); | 207 CmdBuffer::Iter genIter(fCmdBuffer); |
210 while (genIter.next()) { | 208 while (genIter.next()) { |
211 if (Cmd::kDrawBatch_CmdType == genIter->type()) { | 209 if (Cmd::kDrawBatch_CmdType == genIter->type()) { |
212 DrawBatch* db = reinterpret_cast<DrawBatch*>(genIter.get()); | 210 DrawBatch* db = reinterpret_cast<DrawBatch*>(genIter.get()); |
213 fBatchTarget.resetNumberOfDraws(); | 211 fBatchTarget.resetNumberOfDraws(); |
214 db->execute(NULL, currentState); | 212 db->execute(NULL, currentState); |
215 db->fBatch->setNumberOfDraws(fBatchTarget.numberOfDraws()); | 213 db->fBatch->setNumberOfDraws(fBatchTarget.numberOfDraws()); |
216 } else if (Cmd::kSetState_CmdType == genIter->type()) { | 214 } else if (Cmd::kSetState_CmdType == genIter->type()) { |
217 SetState* ss = reinterpret_cast<SetState*>(genIter.get()); | 215 SetState* ss = reinterpret_cast<SetState*>(genIter.get()); |
218 | 216 |
219 ss->execute(gpu, currentState); | 217 ss->execute(gpu, currentState); |
220 currentState = ss; | 218 currentState = ss; |
221 } | 219 } |
222 } | 220 } |
223 #endif | |
224 | 221 |
225 iodb->getVertexAllocPool()->unmap(); | 222 iodb->getVertexAllocPool()->unmap(); |
226 iodb->getIndexAllocPool()->unmap(); | 223 iodb->getIndexAllocPool()->unmap(); |
227 fBatchTarget.preFlush(); | 224 fBatchTarget.preFlush(); |
228 | 225 |
229 CmdBuffer::Iter iter(fCmdBuffer); | 226 CmdBuffer::Iter iter(fCmdBuffer); |
230 | 227 |
231 while (iter.next()) { | 228 while (iter.next()) { |
232 GrGpuTraceMarker newMarker("", -1); | 229 GrGpuTraceMarker newMarker("", -1); |
233 SkString traceString; | 230 SkString traceString; |
234 if (iter->isTraced()) { | 231 if (iter->isTraced()) { |
235 traceString = iodb->getCmdString(iter->markerID()); | 232 traceString = iodb->getCmdString(iter->markerID()); |
236 newMarker.fMarker = traceString.c_str(); | 233 newMarker.fMarker = traceString.c_str(); |
237 gpu->addGpuTraceMarker(&newMarker); | 234 gpu->addGpuTraceMarker(&newMarker); |
238 } | 235 } |
239 | 236 |
240 // TODO temporary hack | |
241 if (Cmd::kDrawBatch_CmdType == iter->type()) { | 237 if (Cmd::kDrawBatch_CmdType == iter->type()) { |
242 DrawBatch* db = reinterpret_cast<DrawBatch*>(iter.get()); | 238 DrawBatch* db = reinterpret_cast<DrawBatch*>(iter.get()); |
243 fBatchTarget.flushNext(db->fBatch->numberOfDraws()); | 239 fBatchTarget.flushNext(db->fBatch->numberOfDraws()); |
244 | 240 |
245 if (iter->isTraced()) { | 241 if (iter->isTraced()) { |
246 gpu->removeGpuTraceMarker(&newMarker); | 242 gpu->removeGpuTraceMarker(&newMarker); |
247 } | 243 } |
248 continue; | 244 continue; |
249 } | 245 } |
250 | 246 |
251 if (Cmd::kSetState_CmdType == iter->type()) { | 247 if (Cmd::kSetState_CmdType == iter->type()) { |
252 #ifndef USE_BITMAP_TEXTBLOBS | |
253 SetState* ss = reinterpret_cast<SetState*>(iter.get()); | |
254 | |
255 ss->execute(gpu, currentState); | |
256 currentState = ss; | |
257 #else | |
258 // TODO this is just until NVPR is in batch | 248 // TODO this is just until NVPR is in batch |
259 SetState* ss = reinterpret_cast<SetState*>(iter.get()); | 249 SetState* ss = reinterpret_cast<SetState*>(iter.get()); |
260 | 250 |
261 if (ss->fPrimitiveProcessor) { | 251 if (ss->fPrimitiveProcessor) { |
262 ss->execute(gpu, currentState); | 252 ss->execute(gpu, currentState); |
263 } | 253 } |
264 currentState = ss; | 254 currentState = ss; |
265 #endif | |
266 | 255 |
267 } else { | 256 } else { |
268 iter->execute(gpu, currentState); | 257 iter->execute(gpu, currentState); |
269 } | 258 } |
270 | 259 |
271 if (iter->isTraced()) { | 260 if (iter->isTraced()) { |
272 gpu->removeGpuTraceMarker(&newMarker); | 261 gpu->removeGpuTraceMarker(&newMarker); |
273 } | 262 } |
274 } | 263 } |
275 | 264 |
276 // TODO see copious notes about hack | |
277 fBatchTarget.postFlush(); | 265 fBatchTarget.postFlush(); |
278 } | 266 } |
279 | 267 |
280 void GrTargetCommands::Draw::execute(GrGpu* gpu, const SetState* state) { | |
281 SkASSERT(state); | |
282 DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state ->fDesc, | |
283 &state->fBatchTracker); | |
284 gpu->draw(args, fInfo); | |
285 } | |
286 | |
287 void GrTargetCommands::StencilPath::execute(GrGpu* gpu, const SetState*) { | 268 void GrTargetCommands::StencilPath::execute(GrGpu* gpu, const SetState*) { |
288 GrGpu::StencilPathState state; | 269 GrGpu::StencilPathState state; |
289 state.fRenderTarget = fRenderTarget.get(); | 270 state.fRenderTarget = fRenderTarget.get(); |
290 state.fScissor = &fScissor; | 271 state.fScissor = &fScissor; |
291 state.fStencil = &fStencil; | 272 state.fStencil = &fStencil; |
292 state.fUseHWAA = fUseHWAA; | 273 state.fUseHWAA = fUseHWAA; |
293 state.fViewMatrix = &fViewMatrix; | 274 state.fViewMatrix = &fViewMatrix; |
294 | 275 |
295 gpu->stencilPath(this->path(), state); | 276 gpu->stencilPath(this->path(), state); |
296 } | 277 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 if (!xp.willNeedXferBarrier(rt, *iodb->caps(), &barrierType)) { | 400 if (!xp.willNeedXferBarrier(rt, *iodb->caps(), &barrierType)) { |
420 return; | 401 return; |
421 } | 402 } |
422 | 403 |
423 XferBarrier* xb = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, XferBarrier, ()); | 404 XferBarrier* xb = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, XferBarrier, ()); |
424 xb->fBarrierType = barrierType; | 405 xb->fBarrierType = barrierType; |
425 | 406 |
426 iodb->recordTraceMarkersIfNecessary(xb); | 407 iodb->recordTraceMarkersIfNecessary(xb); |
427 } | 408 } |
428 | 409 |
OLD | NEW |