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 29 matching lines...) Expand all Loading... |
40 SkASSERT(!fCmdBuffer.empty()); | 40 SkASSERT(!fCmdBuffer.empty()); |
41 SkASSERT(info.isInstanced()); | 41 SkASSERT(info.isInstanced()); |
42 | 42 |
43 const GrIndexBuffer* ib; | 43 const GrIndexBuffer* ib; |
44 if (!iodb->canConcatToIndexBuffer(&ib)) { | 44 if (!iodb->canConcatToIndexBuffer(&ib)) { |
45 return 0; | 45 return 0; |
46 } | 46 } |
47 | 47 |
48 // Check if there is a draw info that is compatible that uses the same VB fr
om the pool and | 48 // Check if there is a draw info that is compatible that uses the same VB fr
om the pool and |
49 // the same IB | 49 // the same IB |
50 if (Cmd::kDraw_Cmd != fCmdBuffer.back().type()) { | 50 if (Cmd::kDraw_CmdType != fCmdBuffer.back().type()) { |
51 return 0; | 51 return 0; |
52 } | 52 } |
53 | 53 |
54 Draw* draw = static_cast<Draw*>(&fCmdBuffer.back()); | 54 Draw* draw = static_cast<Draw*>(&fCmdBuffer.back()); |
55 | 55 |
56 if (!draw->fInfo.isInstanced() || | 56 if (!draw->fInfo.isInstanced() || |
57 draw->fInfo.primitiveType() != info.primitiveType() || | 57 draw->fInfo.primitiveType() != info.primitiveType() || |
58 draw->fInfo.verticesPerInstance() != info.verticesPerInstance() || | 58 draw->fInfo.verticesPerInstance() != info.verticesPerInstance() || |
59 draw->fInfo.indicesPerInstance() != info.indicesPerInstance() || | 59 draw->fInfo.indicesPerInstance() != info.indicesPerInstance() || |
60 draw->fInfo.vertexBuffer() != info.vertexBuffer() || | 60 draw->fInfo.vertexBuffer() != info.vertexBuffer() || |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 GrTargetCommands::Cmd* GrTargetCommands::recordDrawBatch( | 108 GrTargetCommands::Cmd* GrTargetCommands::recordDrawBatch( |
109 GrInOrderDrawBuffer* iodb, | 109 GrInOrderDrawBuffer* iodb, |
110 GrBatch* batch, | 110 GrBatch* batch, |
111 const GrDrawTarget::PipelineIn
fo& pipelineInfo) { | 111 const GrDrawTarget::PipelineIn
fo& pipelineInfo) { |
112 if (!this->setupPipelineAndShouldDraw(iodb, batch, pipelineInfo)) { | 112 if (!this->setupPipelineAndShouldDraw(iodb, batch, pipelineInfo)) { |
113 return NULL; | 113 return NULL; |
114 } | 114 } |
115 | 115 |
116 // Check if there is a Batch Draw we can batch with | 116 // Check if there is a Batch Draw we can batch with |
117 if (Cmd::kDrawBatch_Cmd != fCmdBuffer.back().type() || !fDrawBatch) { | 117 if (Cmd::kDrawBatch_CmdType != fCmdBuffer.back().type() || !fDrawBatch) { |
118 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fB
atchTarget)); | 118 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fB
atchTarget)); |
119 return fDrawBatch; | 119 return fDrawBatch; |
120 } | 120 } |
121 | 121 |
122 SkASSERT(&fCmdBuffer.back() == fDrawBatch); | 122 SkASSERT(&fCmdBuffer.back() == fDrawBatch); |
123 if (!fDrawBatch->fBatch->combineIfPossible(batch)) { | 123 if (!fDrawBatch->fBatch->combineIfPossible(batch)) { |
124 this->closeBatch(); | 124 this->closeBatch(); |
125 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fB
atchTarget)); | 125 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch, &fB
atchTarget)); |
126 } | 126 } |
127 | 127 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 return NULL; | 184 return NULL; |
185 } | 185 } |
186 | 186 |
187 char* savedIndices; | 187 char* savedIndices; |
188 float* savedTransforms; | 188 float* savedTransforms; |
189 | 189 |
190 iodb->appendIndicesAndTransforms(indexValues, indexType, | 190 iodb->appendIndicesAndTransforms(indexValues, indexType, |
191 transformValues, transformType, | 191 transformValues, transformType, |
192 count, &savedIndices, &savedTransforms); | 192 count, &savedIndices, &savedTransforms); |
193 | 193 |
194 if (Cmd::kDrawPaths_Cmd == fCmdBuffer.back().type()) { | 194 if (Cmd::kDrawPaths_CmdType == fCmdBuffer.back().type()) { |
195 // The previous command was also DrawPaths. Try to collapse this call in
to the one | 195 // The previous command was also DrawPaths. Try to collapse this call in
to the one |
196 // before. Note that stenciling all the paths at once, then covering, ma
y not be | 196 // before. Note that stenciling all the paths at once, then covering, ma
y not be |
197 // equivalent to two separate draw calls if there is overlap. Blending w
on't work, | 197 // equivalent to two separate draw calls if there is overlap. Blending w
on't work, |
198 // and the combined calls may also cancel each other's winding numbers i
n some | 198 // and the combined calls may also cancel each other's winding numbers i
n some |
199 // places. For now the winding numbers are only an issue if the fill is
even/odd, | 199 // places. For now the winding numbers are only an issue if the fill is
even/odd, |
200 // because DrawPaths is currently only used for glyphs, and glyphs in th
e same | 200 // because DrawPaths is currently only used for glyphs, and glyphs in th
e same |
201 // font tend to all wind in the same direction. | 201 // font tend to all wind in the same direction. |
202 DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back()); | 202 DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back()); |
203 if (pathRange == previous->pathRange() && | 203 if (pathRange == previous->pathRange() && |
204 indexType == previous->fIndexType && | 204 indexType == previous->fIndexType && |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 fCmdBuffer.reset(); | 279 fCmdBuffer.reset(); |
280 fPrevState = NULL; | 280 fPrevState = NULL; |
281 fDrawBatch = NULL; | 281 fDrawBatch = NULL; |
282 } | 282 } |
283 | 283 |
284 void GrTargetCommands::flush(GrInOrderDrawBuffer* iodb) { | 284 void GrTargetCommands::flush(GrInOrderDrawBuffer* iodb) { |
285 if (fCmdBuffer.empty()) { | 285 if (fCmdBuffer.empty()) { |
286 return; | 286 return; |
287 } | 287 } |
288 | 288 |
289 // Updated every time we find a set state cmd to reflect the current state i
n the playback | |
290 // stream. | |
291 SetState* currentState = NULL; | |
292 | |
293 // TODO this is temporary while batch is being rolled out | 289 // TODO this is temporary while batch is being rolled out |
294 this->closeBatch(); | 290 this->closeBatch(); |
295 iodb->getVertexAllocPool()->unmap(); | 291 iodb->getVertexAllocPool()->unmap(); |
296 iodb->getIndexAllocPool()->unmap(); | 292 iodb->getIndexAllocPool()->unmap(); |
297 fBatchTarget.preFlush(); | 293 fBatchTarget.preFlush(); |
298 | 294 |
299 currentState = NULL; | 295 // Updated every time we find a set state cmd to reflect the current state i
n the playback |
| 296 // stream. |
| 297 SetState* currentState = NULL; |
| 298 |
300 CmdBuffer::Iter iter(fCmdBuffer); | 299 CmdBuffer::Iter iter(fCmdBuffer); |
301 | 300 |
302 int currCmdMarker = 0; | |
303 | |
304 GrGpu* gpu = iodb->getGpu(); | 301 GrGpu* gpu = iodb->getGpu(); |
305 | 302 |
306 int i = 0; | |
307 while (iter.next()) { | 303 while (iter.next()) { |
308 i++; | |
309 GrGpuTraceMarker newMarker("", -1); | 304 GrGpuTraceMarker newMarker("", -1); |
310 SkString traceString; | 305 SkString traceString; |
311 if (iter->isTraced()) { | 306 if (iter->isTraced()) { |
312 traceString = iodb->getCmdString(currCmdMarker); | 307 traceString = iodb->getCmdString(iter->markerID()); |
313 newMarker.fMarker = traceString.c_str(); | 308 newMarker.fMarker = traceString.c_str(); |
314 gpu->addGpuTraceMarker(&newMarker); | 309 gpu->addGpuTraceMarker(&newMarker); |
315 ++currCmdMarker; | |
316 } | 310 } |
317 | 311 |
318 // TODO temporary hack | 312 // TODO temporary hack |
319 if (Cmd::kDrawBatch_Cmd == iter->type()) { | 313 if (Cmd::kDrawBatch_CmdType == iter->type()) { |
320 DrawBatch* db = reinterpret_cast<DrawBatch*>(iter.get()); | 314 DrawBatch* db = reinterpret_cast<DrawBatch*>(iter.get()); |
321 fBatchTarget.flushNext(db->fBatch->numberOfDraws()); | 315 fBatchTarget.flushNext(db->fBatch->numberOfDraws()); |
322 | 316 |
323 if (iter->isTraced()) { | 317 if (iter->isTraced()) { |
324 gpu->removeGpuTraceMarker(&newMarker); | 318 gpu->removeGpuTraceMarker(&newMarker); |
325 } | 319 } |
326 continue; | 320 continue; |
327 } | 321 } |
328 | 322 |
329 if (Cmd::kSetState_Cmd == iter->type()) { | 323 if (Cmd::kSetState_CmdType == iter->type()) { |
330 SetState* ss = reinterpret_cast<SetState*>(iter.get()); | 324 SetState* ss = reinterpret_cast<SetState*>(iter.get()); |
331 | 325 |
332 // TODO sometimes we have a prim proc, othertimes we have a GrBatch.
Eventually we | 326 ss->execute(gpu, currentState); |
333 // will only have GrBatch and we can delete this | |
334 if (ss->fPrimitiveProcessor) { | |
335 gpu->buildProgramDesc(&ss->fDesc, *ss->fPrimitiveProcessor, | |
336 *ss->getPipeline(), | |
337 ss->fBatchTracker); | |
338 } | |
339 currentState = ss; | 327 currentState = ss; |
340 } else { | 328 } else { |
341 iter->execute(gpu, currentState); | 329 iter->execute(gpu, currentState); |
342 } | 330 } |
343 | 331 |
344 if (iter->isTraced()) { | 332 if (iter->isTraced()) { |
345 gpu->removeGpuTraceMarker(&newMarker); | 333 gpu->removeGpuTraceMarker(&newMarker); |
346 } | 334 } |
347 } | 335 } |
348 | 336 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 fIndices, fIndexType, | 371 fIndices, fIndexType, |
384 fTransforms, fTransformType, | 372 fTransforms, fTransformType, |
385 fCount, fStencilSettings); | 373 fCount, fStencilSettings); |
386 } | 374 } |
387 | 375 |
388 void GrTargetCommands::DrawBatch::execute(GrGpu*, const SetState* state) { | 376 void GrTargetCommands::DrawBatch::execute(GrGpu*, const SetState* state) { |
389 SkASSERT(state); | 377 SkASSERT(state); |
390 fBatch->generateGeometry(fBatchTarget, state->getPipeline()); | 378 fBatch->generateGeometry(fBatchTarget, state->getPipeline()); |
391 } | 379 } |
392 | 380 |
393 void GrTargetCommands::SetState::execute(GrGpu*, const SetState*) {} | 381 void GrTargetCommands::SetState::execute(GrGpu* gpu, const SetState*) { |
| 382 // TODO sometimes we have a prim proc, othertimes we have a GrBatch. Eventu
ally we |
| 383 // will only have GrBatch and we can delete this |
| 384 if (fPrimitiveProcessor) { |
| 385 gpu->buildProgramDesc(&fDesc, *fPrimitiveProcessor, *getPipeline(), fBat
chTracker); |
| 386 } |
| 387 } |
394 | 388 |
395 void GrTargetCommands::Clear::execute(GrGpu* gpu, const SetState*) { | 389 void GrTargetCommands::Clear::execute(GrGpu* gpu, const SetState*) { |
396 if (GrColor_ILLEGAL == fColor) { | 390 if (GrColor_ILLEGAL == fColor) { |
397 gpu->discard(this->renderTarget()); | 391 gpu->discard(this->renderTarget()); |
398 } else { | 392 } else { |
399 gpu->clear(&fRect, fColor, fCanIgnoreRect, this->renderTarget()); | 393 gpu->clear(&fRect, fColor, fCanIgnoreRect, this->renderTarget()); |
400 } | 394 } |
401 } | 395 } |
402 | 396 |
403 void GrTargetCommands::ClearStencilClip::execute(GrGpu* gpu, const SetState*) { | 397 void GrTargetCommands::ClearStencilClip::execute(GrGpu* gpu, const SetState*) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 fPrevState->getPipeline()->isEqual(*ss->getPipeline())) { | 461 fPrevState->getPipeline()->isEqual(*ss->getPipeline())) { |
468 fCmdBuffer.pop_back(); | 462 fCmdBuffer.pop_back(); |
469 } else { | 463 } else { |
470 this->closeBatch(); | 464 this->closeBatch(); |
471 fPrevState = ss; | 465 fPrevState = ss; |
472 iodb->recordTraceMarkersIfNecessary(ss); | 466 iodb->recordTraceMarkersIfNecessary(ss); |
473 } | 467 } |
474 return true; | 468 return true; |
475 } | 469 } |
476 | 470 |
OLD | NEW |