OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrInOrderDrawBuffer.h" | 8 #include "GrInOrderDrawBuffer.h" |
9 | 9 |
10 #include "GrBufferAllocPool.h" | 10 #include "GrBufferAllocPool.h" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 | 249 |
250 // we only attempt to concat the case when reserved verts are used with a cl ient-specified index | 250 // we only attempt to concat the case when reserved verts are used with a cl ient-specified index |
251 // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated | 251 // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated |
252 // between draws. | 252 // between draws. |
253 if (kReserved_GeometrySrcType != geomSrc.fVertexSrc || | 253 if (kReserved_GeometrySrcType != geomSrc.fVertexSrc || |
254 kBuffer_GeometrySrcType != geomSrc.fIndexSrc) { | 254 kBuffer_GeometrySrcType != geomSrc.fIndexSrc) { |
255 return 0; | 255 return 0; |
256 } | 256 } |
257 // Check if there is a draw info that is compatible that uses the same VB fr om the pool and | 257 // Check if there is a draw info that is compatible that uses the same VB fr om the pool and |
258 // the same IB | 258 // the same IB |
259 if (kDraw_Cmd != fCmds.back()) { | 259 if (kDraw_Cmd != stripTraceBit(fCmds.back())) { |
260 return 0; | 260 return 0; |
261 } | 261 } |
262 | 262 |
263 DrawRecord* draw = &fDraws.back(); | 263 DrawRecord* draw = &fDraws.back(); |
264 GeometryPoolState& poolState = fGeoPoolStateStack.back(); | 264 GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
265 const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer; | 265 const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer; |
266 | 266 |
267 if (!draw->isInstanced() || | 267 if (!draw->isInstanced() || |
268 draw->verticesPerInstance() != info.verticesPerInstance() || | 268 draw->verticesPerInstance() != info.verticesPerInstance() || |
269 draw->indicesPerInstance() != info.indicesPerInstance() || | 269 draw->indicesPerInstance() != info.indicesPerInstance() || |
(...skipping 14 matching lines...) Expand all Loading... | |
284 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerI nstance(); | 284 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerI nstance(); |
285 instancesToConcat -= draw->instanceCount(); | 285 instancesToConcat -= draw->instanceCount(); |
286 instancesToConcat = GrMin(instancesToConcat, info.instanceCount()); | 286 instancesToConcat = GrMin(instancesToConcat, info.instanceCount()); |
287 | 287 |
288 // update the amount of reserved vertex data actually referenced in draws | 288 // update the amount of reserved vertex data actually referenced in draws |
289 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() * | 289 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() * |
290 drawState.getVertexSize(); | 290 drawState.getVertexSize(); |
291 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, verte xBytes); | 291 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, verte xBytes); |
292 | 292 |
293 draw->adjustInstanceCount(instancesToConcat); | 293 draw->adjustInstanceCount(instancesToConcat); |
294 | |
295 // update last fGpuCmdMarkers to include any additional trace markers that h ave been added | |
296 if (this->getActiveTraceMarkers()->count() > 0) { | |
297 if (fCmds.back() & 0x08) { | |
bsalomon
2014/03/17 17:50:38
use enum value
| |
298 fNumMarkersPerCmd.top() += this->getActiveTraceMarkers()->count(); | |
299 } else { | |
300 fNumMarkersPerCmd.push(this->getActiveTraceMarkers()->count()); | |
301 fCmds.back() = addTraceBit(fCmds.back()); | |
302 } | |
303 for (int i = 0; i < this->getActiveTraceMarkers()->count(); ++i) { | |
304 fGpuCmdMarkers.push(this->getActiveTraceMarkers()->getAt(i)); | |
305 } | |
306 } | |
307 | |
294 return instancesToConcat; | 308 return instancesToConcat; |
295 } | 309 } |
296 | 310 |
297 class AutoClipReenable { | 311 class AutoClipReenable { |
298 public: | 312 public: |
299 AutoClipReenable() : fDrawState(NULL) {} | 313 AutoClipReenable() : fDrawState(NULL) {} |
300 ~AutoClipReenable() { | 314 ~AutoClipReenable() { |
301 if (NULL != fDrawState) { | 315 if (NULL != fDrawState) { |
302 fDrawState->enableState(GrDrawState::kClip_StateBit); | 316 fDrawState->enableState(GrDrawState::kClip_StateBit); |
303 } | 317 } |
(...skipping 24 matching lines...) Expand all Loading... | |
328 this->recordClip(); | 342 this->recordClip(); |
329 } | 343 } |
330 if (this->needsNewState()) { | 344 if (this->needsNewState()) { |
331 this->recordState(); | 345 this->recordState(); |
332 } | 346 } |
333 | 347 |
334 DrawRecord* draw; | 348 DrawRecord* draw; |
335 if (info.isInstanced()) { | 349 if (info.isInstanced()) { |
336 int instancesConcated = this->concatInstancedDraw(info); | 350 int instancesConcated = this->concatInstancedDraw(info); |
337 if (info.instanceCount() > instancesConcated) { | 351 if (info.instanceCount() > instancesConcated) { |
352 // grab cmd lock | |
338 draw = this->recordDraw(info); | 353 draw = this->recordDraw(info); |
339 draw->adjustInstanceCount(-instancesConcated); | 354 draw->adjustInstanceCount(-instancesConcated); |
340 } else { | 355 } else { |
341 return; | 356 return; |
342 } | 357 } |
343 } else { | 358 } else { |
344 draw = this->recordDraw(info); | 359 draw = this->recordDraw(info); |
345 } | 360 } |
346 | 361 |
347 switch (this->getGeomSrc().fVertexSrc) { | 362 switch (this->getGeomSrc().fVertexSrc) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
434 rect = &r; | 449 rect = &r; |
435 } | 450 } |
436 Clear* clr = this->recordClear(); | 451 Clear* clr = this->recordClear(); |
437 clr->fColor = color; | 452 clr->fColor = color; |
438 clr->fRect = *rect; | 453 clr->fRect = *rect; |
439 clr->fCanIgnoreRect = canIgnoreRect; | 454 clr->fCanIgnoreRect = canIgnoreRect; |
440 clr->fRenderTarget = renderTarget; | 455 clr->fRenderTarget = renderTarget; |
441 renderTarget->ref(); | 456 renderTarget->ref(); |
442 } | 457 } |
443 | 458 |
444 void GrInOrderDrawBuffer::onInstantGpuTraceEvent(const char* marker) { | |
445 // TODO: adds command to buffer | |
446 } | |
447 | |
448 void GrInOrderDrawBuffer::onPushGpuTraceEvent(const char* marker) { | |
449 // TODO: adds command to buffer | |
450 } | |
451 | |
452 void GrInOrderDrawBuffer::onPopGpuTraceEvent() { | |
453 // TODO: adds command to buffer | |
454 } | |
455 | |
456 void GrInOrderDrawBuffer::reset() { | 459 void GrInOrderDrawBuffer::reset() { |
457 SkASSERT(1 == fGeoPoolStateStack.count()); | 460 SkASSERT(1 == fGeoPoolStateStack.count()); |
458 this->resetVertexSource(); | 461 this->resetVertexSource(); |
459 this->resetIndexSource(); | 462 this->resetIndexSource(); |
460 int numDraws = fDraws.count(); | 463 int numDraws = fDraws.count(); |
461 for (int d = 0; d < numDraws; ++d) { | 464 for (int d = 0; d < numDraws; ++d) { |
462 // we always have a VB, but not always an IB | 465 // we always have a VB, but not always an IB |
463 SkASSERT(NULL != fDraws[d].fVertexBuffer); | 466 SkASSERT(NULL != fDraws[d].fVertexBuffer); |
464 fDraws[d].fVertexBuffer->unref(); | 467 fDraws[d].fVertexBuffer->unref(); |
465 SkSafeUnref(fDraws[d].fIndexBuffer); | 468 SkSafeUnref(fDraws[d].fIndexBuffer); |
466 } | 469 } |
467 fCmds.reset(); | 470 fCmds.reset(); |
468 fDraws.reset(); | 471 fDraws.reset(); |
469 fStencilPaths.reset(); | 472 fStencilPaths.reset(); |
470 fDrawPaths.reset(); | 473 fDrawPaths.reset(); |
471 fStates.reset(); | 474 fStates.reset(); |
472 fClears.reset(); | 475 fClears.reset(); |
473 fVertexPool.reset(); | 476 fVertexPool.reset(); |
474 fIndexPool.reset(); | 477 fIndexPool.reset(); |
475 fClips.reset(); | 478 fClips.reset(); |
476 fClipOrigins.reset(); | 479 fClipOrigins.reset(); |
477 fCopySurfaces.reset(); | 480 fCopySurfaces.reset(); |
481 fGpuCmdMarkers.reset(); | |
482 fNumMarkersPerCmd.reset(); | |
478 fClipSet = true; | 483 fClipSet = true; |
479 } | 484 } |
480 | 485 |
481 void GrInOrderDrawBuffer::flush() { | 486 void GrInOrderDrawBuffer::flush() { |
482 if (fFlushing) { | 487 if (fFlushing) { |
483 return; | 488 return; |
484 } | 489 } |
485 | 490 |
486 SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); | 491 SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); |
487 SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); | 492 SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); |
(...skipping 12 matching lines...) Expand all Loading... | |
500 GrDrawTarget::AutoClipRestore acr(fDstGpu); | 505 GrDrawTarget::AutoClipRestore acr(fDstGpu); |
501 AutoGeometryAndStatePush agasp(fDstGpu, kPreserve_ASRInit); | 506 AutoGeometryAndStatePush agasp(fDstGpu, kPreserve_ASRInit); |
502 | 507 |
503 GrDrawState playbackState; | 508 GrDrawState playbackState; |
504 GrDrawState* prevDrawState = fDstGpu->drawState(); | 509 GrDrawState* prevDrawState = fDstGpu->drawState(); |
505 prevDrawState->ref(); | 510 prevDrawState->ref(); |
506 fDstGpu->setDrawState(&playbackState); | 511 fDstGpu->setDrawState(&playbackState); |
507 | 512 |
508 GrClipData clipData; | 513 GrClipData clipData; |
509 | 514 |
510 int currState = 0; | 515 int currState = 0; |
511 int currClip = 0; | 516 int currClip = 0; |
512 int currClear = 0; | 517 int currClear = 0; |
513 int currDraw = 0; | 518 int currDraw = 0; |
514 int currStencilPath = 0; | 519 int currStencilPath = 0; |
515 int currDrawPath = 0; | 520 int currDrawPath = 0; |
516 int currCopySurface = 0; | 521 int currCopySurface = 0; |
522 int currCmdMarker = 0; | |
523 int currCmdMarkerIndex = 0; | |
517 | 524 |
518 for (int c = 0; c < numCmds; ++c) { | 525 for (int c = 0; c < numCmds; ++c) { |
519 switch (fCmds[c]) { | 526 GpuTraceMarker newMarker("", -1); |
527 if (fCmds[c] & 0x08) { | |
bsalomon
2014/03/17 17:50:38
use enum, or perhaps better add a function CmdHasT
| |
528 SkString traceString = getTraceString(&fGpuCmdMarkers, currCmdMarker Index, | |
529 fNumMarkersPerCmd[currCmdMarke r]); | |
530 newMarker.fMarker = traceString.c_str(); | |
531 fDstGpu->addGpuTraceMarker(&newMarker); | |
532 currCmdMarkerIndex += fNumMarkersPerCmd[currCmdMarker]; | |
533 ++currCmdMarker; | |
534 } | |
535 switch (stripTraceBit(fCmds[c])) { | |
bsalomon
2014/03/17 17:50:38
this-> but really the functions should probably be
| |
520 case kDraw_Cmd: { | 536 case kDraw_Cmd: { |
521 const DrawRecord& draw = fDraws[currDraw]; | 537 const DrawRecord& draw = fDraws[currDraw]; |
522 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer); | 538 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer); |
523 if (draw.isIndexed()) { | 539 if (draw.isIndexed()) { |
524 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer); | 540 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer); |
525 } | 541 } |
526 fDstGpu->executeDraw(draw); | 542 fDstGpu->executeDraw(draw); |
527 | |
528 ++currDraw; | 543 ++currDraw; |
529 break; | 544 break; |
530 } | 545 } |
531 case kStencilPath_Cmd: { | 546 case kStencilPath_Cmd: { |
532 const StencilPath& sp = fStencilPaths[currStencilPath]; | 547 const StencilPath& sp = fStencilPaths[currStencilPath]; |
533 fDstGpu->stencilPath(sp.fPath.get(), sp.fFill); | 548 fDstGpu->stencilPath(sp.fPath.get(), sp.fFill); |
534 ++currStencilPath; | 549 ++currStencilPath; |
535 break; | 550 break; |
536 } | 551 } |
537 case kDrawPath_Cmd: { | 552 case kDrawPath_Cmd: { |
(...skipping 21 matching lines...) Expand all Loading... | |
559 ++currClear; | 574 ++currClear; |
560 break; | 575 break; |
561 case kCopySurface_Cmd: | 576 case kCopySurface_Cmd: |
562 fDstGpu->copySurface(fCopySurfaces[currCopySurface].fDst.get(), | 577 fDstGpu->copySurface(fCopySurfaces[currCopySurface].fDst.get(), |
563 fCopySurfaces[currCopySurface].fSrc.get(), | 578 fCopySurfaces[currCopySurface].fSrc.get(), |
564 fCopySurfaces[currCopySurface].fSrcRect, | 579 fCopySurfaces[currCopySurface].fSrcRect, |
565 fCopySurfaces[currCopySurface].fDstPoint); | 580 fCopySurfaces[currCopySurface].fDstPoint); |
566 ++currCopySurface; | 581 ++currCopySurface; |
567 break; | 582 break; |
568 } | 583 } |
584 if (fCmds[c] & 0x08) { | |
bsalomon
2014/03/17 17:50:38
enum/function
| |
585 fDstGpu->removeGpuTraceMarker(&newMarker); | |
586 } | |
569 } | 587 } |
570 // we should have consumed all the states, clips, etc. | 588 // we should have consumed all the states, clips, etc. |
571 SkASSERT(fStates.count() == currState); | 589 SkASSERT(fStates.count() == currState); |
572 SkASSERT(fClips.count() == currClip); | 590 SkASSERT(fClips.count() == currClip); |
573 SkASSERT(fClipOrigins.count() == currClip); | 591 SkASSERT(fClipOrigins.count() == currClip); |
574 SkASSERT(fClears.count() == currClear); | 592 SkASSERT(fClears.count() == currClear); |
575 SkASSERT(fDraws.count() == currDraw); | 593 SkASSERT(fDraws.count() == currDraw); |
576 SkASSERT(fCopySurfaces.count() == currCopySurface); | 594 SkASSERT(fCopySurfaces.count() == currCopySurface); |
595 SkASSERT(fGpuCmdMarkers.count() == currCmdMarkerIndex); | |
596 SkASSERT(fNumMarkersPerCmd.count() == currCmdMarker); | |
577 | 597 |
578 fDstGpu->setDrawState(prevDrawState); | 598 fDstGpu->setDrawState(prevDrawState); |
579 prevDrawState->unref(); | 599 prevDrawState->unref(); |
580 this->reset(); | 600 this->reset(); |
581 ++fDrawID; | 601 ++fDrawID; |
582 } | 602 } |
583 | 603 |
584 bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, | 604 bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, |
585 GrSurface* src, | 605 GrSurface* src, |
586 const SkIRect& srcRect, | 606 const SkIRect& srcRect, |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
822 if (fClipSet && | 842 if (fClipSet && |
823 (fClips.empty() || | 843 (fClips.empty() || |
824 fClips.back() != *this->getClip()->fClipStack || | 844 fClips.back() != *this->getClip()->fClipStack || |
825 fClipOrigins.back() != this->getClip()->fOrigin)) { | 845 fClipOrigins.back() != this->getClip()->fOrigin)) { |
826 return true; | 846 return true; |
827 } | 847 } |
828 } | 848 } |
829 return false; | 849 return false; |
830 } | 850 } |
831 | 851 |
852 void GrInOrderDrawBuffer::addToCmdBuffer(uint8_t cmd) { | |
853 SkTDArray<GpuTraceMarker>* activeTraceMarkers = this->getActiveTraceMarkers( ); | |
854 if (activeTraceMarkers->count() > 0) { | |
855 fCmds.push_back(addTraceBit(cmd)); | |
856 for (int i = 0; i < activeTraceMarkers->count(); ++i) { | |
857 fGpuCmdMarkers.push(activeTraceMarkers->getAt(i)); | |
858 } | |
859 fNumMarkersPerCmd.push(activeTraceMarkers->count()); | |
860 } else { | |
861 fCmds.push_back(cmd); | |
862 } | |
863 } | |
864 | |
832 void GrInOrderDrawBuffer::recordClip() { | 865 void GrInOrderDrawBuffer::recordClip() { |
833 fClips.push_back() = *this->getClip()->fClipStack; | 866 fClips.push_back(*this->getClip()->fClipStack); |
834 fClipOrigins.push_back() = this->getClip()->fOrigin; | 867 fClipOrigins.push_back() = this->getClip()->fOrigin; |
835 fClipSet = false; | 868 fClipSet = false; |
836 fCmds.push_back(kSetClip_Cmd); | 869 addToCmdBuffer(kSetClip_Cmd); |
bsalomon
2014/03/17 17:50:38
this->
here and below
| |
837 } | 870 } |
838 | 871 |
839 void GrInOrderDrawBuffer::recordState() { | 872 void GrInOrderDrawBuffer::recordState() { |
840 fStates.push_back().saveFrom(this->getDrawState()); | 873 fStates.push_back().saveFrom(this->getDrawState()); |
841 fCmds.push_back(kSetState_Cmd); | 874 addToCmdBuffer(kSetState_Cmd); |
842 } | 875 } |
843 | 876 |
844 GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo& info) { | 877 GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo& info) { |
845 fCmds.push_back(kDraw_Cmd); | 878 addToCmdBuffer(kDraw_Cmd); |
846 return &fDraws.push_back(info); | 879 return &fDraws.push_back(info); |
847 } | 880 } |
848 | 881 |
849 GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { | 882 GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { |
850 fCmds.push_back(kStencilPath_Cmd); | 883 addToCmdBuffer(kStencilPath_Cmd); |
851 return &fStencilPaths.push_back(); | 884 return &fStencilPaths.push_back(); |
852 } | 885 } |
853 | 886 |
854 GrInOrderDrawBuffer::DrawPath* GrInOrderDrawBuffer::recordDrawPath() { | 887 GrInOrderDrawBuffer::DrawPath* GrInOrderDrawBuffer::recordDrawPath() { |
855 fCmds.push_back(kDrawPath_Cmd); | 888 addToCmdBuffer(kDrawPath_Cmd); |
856 return &fDrawPaths.push_back(); | 889 return &fDrawPaths.push_back(); |
857 } | 890 } |
858 | 891 |
859 GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { | 892 GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { |
860 fCmds.push_back(kClear_Cmd); | 893 addToCmdBuffer(kClear_Cmd); |
861 return &fClears.push_back(); | 894 return &fClears.push_back(); |
862 } | 895 } |
863 | 896 |
864 GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() { | 897 GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() { |
865 fCmds.push_back(kCopySurface_Cmd); | 898 addToCmdBuffer(kCopySurface_Cmd); |
866 return &fCopySurfaces.push_back(); | 899 return &fCopySurfaces.push_back(); |
867 } | 900 } |
868 | 901 |
869 | |
870 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { | 902 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { |
871 INHERITED::clipWillBeSet(newClipData); | 903 INHERITED::clipWillBeSet(newClipData); |
872 fClipSet = true; | 904 fClipSet = true; |
873 fClipProxyState = kUnknown_ClipProxyState; | 905 fClipProxyState = kUnknown_ClipProxyState; |
874 } | 906 } |
OLD | NEW |