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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } else if (hasUVs) { | 111 } else if (hasUVs) { |
112 *localOffset = sizeof(GrPoint); | 112 *localOffset = sizeof(GrPoint); |
113 drawState->setVertexAttribs<kRectPosUVAttribs>(2); | 113 drawState->setVertexAttribs<kRectPosUVAttribs>(2); |
114 } else { | 114 } else { |
115 drawState->setVertexAttribs<kRectPosUVAttribs>(1); | 115 drawState->setVertexAttribs<kRectPosUVAttribs>(1); |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 }; | 119 }; |
120 | 120 |
| 121 enum { |
| 122 kTraceCmdBit = 0x80, |
| 123 kCmdMask = 0x7f, |
| 124 }; |
| 125 |
| 126 static uint8_t add_trace_bit(uint8_t cmd) { |
| 127 return cmd | kTraceCmdBit; |
| 128 } |
| 129 |
| 130 static uint8_t strip_trace_bit(uint8_t cmd) { |
| 131 return cmd & kCmdMask; |
| 132 } |
| 133 |
| 134 static bool cmd_has_trace_marker(uint8_t cmd) { |
| 135 return cmd & kTraceCmdBit; |
| 136 } |
| 137 |
121 void GrInOrderDrawBuffer::onDrawRect(const SkRect& rect, | 138 void GrInOrderDrawBuffer::onDrawRect(const SkRect& rect, |
122 const SkMatrix* matrix, | 139 const SkMatrix* matrix, |
123 const SkRect* localRect, | 140 const SkRect* localRect, |
124 const SkMatrix* localMatrix) { | 141 const SkMatrix* localMatrix) { |
125 GrDrawState::AutoColorRestore acr; | 142 GrDrawState::AutoColorRestore acr; |
126 | 143 |
127 GrDrawState* drawState = this->drawState(); | 144 GrDrawState* drawState = this->drawState(); |
128 | 145 |
129 GrColor color = drawState->getColor(); | 146 GrColor color = drawState->getColor(); |
130 | 147 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 266 |
250 // we only attempt to concat the case when reserved verts are used with a cl
ient-specified index | 267 // 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 | 268 // buffer. To make this work with client-specified VBs we'd need to know if
the VB was updated |
252 // between draws. | 269 // between draws. |
253 if (kReserved_GeometrySrcType != geomSrc.fVertexSrc || | 270 if (kReserved_GeometrySrcType != geomSrc.fVertexSrc || |
254 kBuffer_GeometrySrcType != geomSrc.fIndexSrc) { | 271 kBuffer_GeometrySrcType != geomSrc.fIndexSrc) { |
255 return 0; | 272 return 0; |
256 } | 273 } |
257 // Check if there is a draw info that is compatible that uses the same VB fr
om the pool and | 274 // Check if there is a draw info that is compatible that uses the same VB fr
om the pool and |
258 // the same IB | 275 // the same IB |
259 if (kDraw_Cmd != fCmds.back()) { | 276 if (kDraw_Cmd != strip_trace_bit(fCmds.back())) { |
260 return 0; | 277 return 0; |
261 } | 278 } |
262 | 279 |
263 DrawRecord* draw = &fDraws.back(); | 280 DrawRecord* draw = &fDraws.back(); |
264 GeometryPoolState& poolState = fGeoPoolStateStack.back(); | 281 GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
265 const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer; | 282 const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer; |
266 | 283 |
267 if (!draw->isInstanced() || | 284 if (!draw->isInstanced() || |
268 draw->verticesPerInstance() != info.verticesPerInstance() || | 285 draw->verticesPerInstance() != info.verticesPerInstance() || |
269 draw->indicesPerInstance() != info.indicesPerInstance() || | 286 draw->indicesPerInstance() != info.indicesPerInstance() || |
(...skipping 14 matching lines...) Expand all Loading... |
284 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerI
nstance(); | 301 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerI
nstance(); |
285 instancesToConcat -= draw->instanceCount(); | 302 instancesToConcat -= draw->instanceCount(); |
286 instancesToConcat = GrMin(instancesToConcat, info.instanceCount()); | 303 instancesToConcat = GrMin(instancesToConcat, info.instanceCount()); |
287 | 304 |
288 // update the amount of reserved vertex data actually referenced in draws | 305 // update the amount of reserved vertex data actually referenced in draws |
289 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() * | 306 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() * |
290 drawState.getVertexSize(); | 307 drawState.getVertexSize(); |
291 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, verte
xBytes); | 308 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, verte
xBytes); |
292 | 309 |
293 draw->adjustInstanceCount(instancesToConcat); | 310 draw->adjustInstanceCount(instancesToConcat); |
| 311 |
| 312 // update last fGpuCmdMarkers to include any additional trace markers that h
ave been added |
| 313 if (this->getActiveTraceMarkers().count() > 0) { |
| 314 if (cmd_has_trace_marker(fCmds.back())) { |
| 315 fGpuCmdMarkers.back().addSet(this->getActiveTraceMarkers()); |
| 316 } else { |
| 317 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); |
| 318 fCmds.back() = add_trace_bit(fCmds.back()); |
| 319 } |
| 320 } |
| 321 |
294 return instancesToConcat; | 322 return instancesToConcat; |
295 } | 323 } |
296 | 324 |
297 class AutoClipReenable { | 325 class AutoClipReenable { |
298 public: | 326 public: |
299 AutoClipReenable() : fDrawState(NULL) {} | 327 AutoClipReenable() : fDrawState(NULL) {} |
300 ~AutoClipReenable() { | 328 ~AutoClipReenable() { |
301 if (NULL != fDrawState) { | 329 if (NULL != fDrawState) { |
302 fDrawState->enableState(GrDrawState::kClip_StateBit); | 330 fDrawState->enableState(GrDrawState::kClip_StateBit); |
303 } | 331 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 rect = &r; | 462 rect = &r; |
435 } | 463 } |
436 Clear* clr = this->recordClear(); | 464 Clear* clr = this->recordClear(); |
437 clr->fColor = color; | 465 clr->fColor = color; |
438 clr->fRect = *rect; | 466 clr->fRect = *rect; |
439 clr->fCanIgnoreRect = canIgnoreRect; | 467 clr->fCanIgnoreRect = canIgnoreRect; |
440 clr->fRenderTarget = renderTarget; | 468 clr->fRenderTarget = renderTarget; |
441 renderTarget->ref(); | 469 renderTarget->ref(); |
442 } | 470 } |
443 | 471 |
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() { | 472 void GrInOrderDrawBuffer::reset() { |
457 SkASSERT(1 == fGeoPoolStateStack.count()); | 473 SkASSERT(1 == fGeoPoolStateStack.count()); |
458 this->resetVertexSource(); | 474 this->resetVertexSource(); |
459 this->resetIndexSource(); | 475 this->resetIndexSource(); |
460 int numDraws = fDraws.count(); | 476 int numDraws = fDraws.count(); |
461 for (int d = 0; d < numDraws; ++d) { | 477 for (int d = 0; d < numDraws; ++d) { |
462 // we always have a VB, but not always an IB | 478 // we always have a VB, but not always an IB |
463 SkASSERT(NULL != fDraws[d].fVertexBuffer); | 479 SkASSERT(NULL != fDraws[d].fVertexBuffer); |
464 fDraws[d].fVertexBuffer->unref(); | 480 fDraws[d].fVertexBuffer->unref(); |
465 SkSafeUnref(fDraws[d].fIndexBuffer); | 481 SkSafeUnref(fDraws[d].fIndexBuffer); |
466 } | 482 } |
467 fCmds.reset(); | 483 fCmds.reset(); |
468 fDraws.reset(); | 484 fDraws.reset(); |
469 fStencilPaths.reset(); | 485 fStencilPaths.reset(); |
470 fDrawPaths.reset(); | 486 fDrawPaths.reset(); |
471 fStates.reset(); | 487 fStates.reset(); |
472 fClears.reset(); | 488 fClears.reset(); |
473 fVertexPool.reset(); | 489 fVertexPool.reset(); |
474 fIndexPool.reset(); | 490 fIndexPool.reset(); |
475 fClips.reset(); | 491 fClips.reset(); |
476 fClipOrigins.reset(); | 492 fClipOrigins.reset(); |
477 fCopySurfaces.reset(); | 493 fCopySurfaces.reset(); |
| 494 fGpuCmdMarkers.reset(); |
478 fClipSet = true; | 495 fClipSet = true; |
479 } | 496 } |
480 | 497 |
481 void GrInOrderDrawBuffer::flush() { | 498 void GrInOrderDrawBuffer::flush() { |
482 if (fFlushing) { | 499 if (fFlushing) { |
483 return; | 500 return; |
484 } | 501 } |
485 | 502 |
486 SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); | 503 SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); |
487 SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); | 504 SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); |
(...skipping 19 matching lines...) Expand all Loading... |
507 | 524 |
508 GrClipData clipData; | 525 GrClipData clipData; |
509 | 526 |
510 int currState = 0; | 527 int currState = 0; |
511 int currClip = 0; | 528 int currClip = 0; |
512 int currClear = 0; | 529 int currClear = 0; |
513 int currDraw = 0; | 530 int currDraw = 0; |
514 int currStencilPath = 0; | 531 int currStencilPath = 0; |
515 int currDrawPath = 0; | 532 int currDrawPath = 0; |
516 int currCopySurface = 0; | 533 int currCopySurface = 0; |
| 534 int currCmdMarker = 0; |
517 | 535 |
518 for (int c = 0; c < numCmds; ++c) { | 536 for (int c = 0; c < numCmds; ++c) { |
519 switch (fCmds[c]) { | 537 GrGpuTraceMarker newMarker("", -1); |
| 538 if (cmd_has_trace_marker(fCmds[c])) { |
| 539 SkString traceString = fGpuCmdMarkers[currCmdMarker].toString(); |
| 540 newMarker.fMarker = traceString.c_str(); |
| 541 fDstGpu->addGpuTraceMarker(&newMarker); |
| 542 ++currCmdMarker; |
| 543 } |
| 544 switch (strip_trace_bit(fCmds[c])) { |
520 case kDraw_Cmd: { | 545 case kDraw_Cmd: { |
521 const DrawRecord& draw = fDraws[currDraw]; | 546 const DrawRecord& draw = fDraws[currDraw]; |
522 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer); | 547 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer); |
523 if (draw.isIndexed()) { | 548 if (draw.isIndexed()) { |
524 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer); | 549 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer); |
525 } | 550 } |
526 fDstGpu->executeDraw(draw); | 551 fDstGpu->executeDraw(draw); |
527 | |
528 ++currDraw; | 552 ++currDraw; |
529 break; | 553 break; |
530 } | 554 } |
531 case kStencilPath_Cmd: { | 555 case kStencilPath_Cmd: { |
532 const StencilPath& sp = fStencilPaths[currStencilPath]; | 556 const StencilPath& sp = fStencilPaths[currStencilPath]; |
533 fDstGpu->stencilPath(sp.fPath.get(), sp.fFill); | 557 fDstGpu->stencilPath(sp.fPath.get(), sp.fFill); |
534 ++currStencilPath; | 558 ++currStencilPath; |
535 break; | 559 break; |
536 } | 560 } |
537 case kDrawPath_Cmd: { | 561 case kDrawPath_Cmd: { |
(...skipping 21 matching lines...) Expand all Loading... |
559 ++currClear; | 583 ++currClear; |
560 break; | 584 break; |
561 case kCopySurface_Cmd: | 585 case kCopySurface_Cmd: |
562 fDstGpu->copySurface(fCopySurfaces[currCopySurface].fDst.get(), | 586 fDstGpu->copySurface(fCopySurfaces[currCopySurface].fDst.get(), |
563 fCopySurfaces[currCopySurface].fSrc.get(), | 587 fCopySurfaces[currCopySurface].fSrc.get(), |
564 fCopySurfaces[currCopySurface].fSrcRect, | 588 fCopySurfaces[currCopySurface].fSrcRect, |
565 fCopySurfaces[currCopySurface].fDstPoint); | 589 fCopySurfaces[currCopySurface].fDstPoint); |
566 ++currCopySurface; | 590 ++currCopySurface; |
567 break; | 591 break; |
568 } | 592 } |
| 593 if (cmd_has_trace_marker(fCmds[c])) { |
| 594 fDstGpu->removeGpuTraceMarker(&newMarker); |
| 595 } |
569 } | 596 } |
570 // we should have consumed all the states, clips, etc. | 597 // we should have consumed all the states, clips, etc. |
571 SkASSERT(fStates.count() == currState); | 598 SkASSERT(fStates.count() == currState); |
572 SkASSERT(fClips.count() == currClip); | 599 SkASSERT(fClips.count() == currClip); |
573 SkASSERT(fClipOrigins.count() == currClip); | 600 SkASSERT(fClipOrigins.count() == currClip); |
574 SkASSERT(fClears.count() == currClear); | 601 SkASSERT(fClears.count() == currClear); |
575 SkASSERT(fDraws.count() == currDraw); | 602 SkASSERT(fDraws.count() == currDraw); |
576 SkASSERT(fCopySurfaces.count() == currCopySurface); | 603 SkASSERT(fCopySurfaces.count() == currCopySurface); |
| 604 SkASSERT(fGpuCmdMarkers.count() == currCmdMarker); |
577 | 605 |
578 fDstGpu->setDrawState(prevDrawState); | 606 fDstGpu->setDrawState(prevDrawState); |
579 prevDrawState->unref(); | 607 prevDrawState->unref(); |
580 this->reset(); | 608 this->reset(); |
581 ++fDrawID; | 609 ++fDrawID; |
582 } | 610 } |
583 | 611 |
584 bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, | 612 bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, |
585 GrSurface* src, | 613 GrSurface* src, |
586 const SkIRect& srcRect, | 614 const SkIRect& srcRect, |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 if (fClipSet && | 850 if (fClipSet && |
823 (fClips.empty() || | 851 (fClips.empty() || |
824 fClips.back() != *this->getClip()->fClipStack || | 852 fClips.back() != *this->getClip()->fClipStack || |
825 fClipOrigins.back() != this->getClip()->fOrigin)) { | 853 fClipOrigins.back() != this->getClip()->fOrigin)) { |
826 return true; | 854 return true; |
827 } | 855 } |
828 } | 856 } |
829 return false; | 857 return false; |
830 } | 858 } |
831 | 859 |
| 860 void GrInOrderDrawBuffer::addToCmdBuffer(uint8_t cmd) { |
| 861 SkASSERT(!cmd_has_trace_marker(cmd)); |
| 862 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
| 863 if (activeTraceMarkers.count() > 0) { |
| 864 fCmds.push_back(add_trace_bit(cmd)); |
| 865 fGpuCmdMarkers.push_back(activeTraceMarkers); |
| 866 } else { |
| 867 fCmds.push_back(cmd); |
| 868 } |
| 869 } |
| 870 |
832 void GrInOrderDrawBuffer::recordClip() { | 871 void GrInOrderDrawBuffer::recordClip() { |
833 fClips.push_back() = *this->getClip()->fClipStack; | 872 fClips.push_back(*this->getClip()->fClipStack); |
834 fClipOrigins.push_back() = this->getClip()->fOrigin; | 873 fClipOrigins.push_back() = this->getClip()->fOrigin; |
835 fClipSet = false; | 874 fClipSet = false; |
836 fCmds.push_back(kSetClip_Cmd); | 875 this->addToCmdBuffer(kSetClip_Cmd); |
837 } | 876 } |
838 | 877 |
839 void GrInOrderDrawBuffer::recordState() { | 878 void GrInOrderDrawBuffer::recordState() { |
840 fStates.push_back().saveFrom(this->getDrawState()); | 879 fStates.push_back().saveFrom(this->getDrawState()); |
841 fCmds.push_back(kSetState_Cmd); | 880 this->addToCmdBuffer(kSetState_Cmd); |
842 } | 881 } |
843 | 882 |
844 GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo&
info) { | 883 GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo&
info) { |
845 fCmds.push_back(kDraw_Cmd); | 884 this->addToCmdBuffer(kDraw_Cmd); |
846 return &fDraws.push_back(info); | 885 return &fDraws.push_back(info); |
847 } | 886 } |
848 | 887 |
849 GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { | 888 GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { |
850 fCmds.push_back(kStencilPath_Cmd); | 889 this->addToCmdBuffer(kStencilPath_Cmd); |
851 return &fStencilPaths.push_back(); | 890 return &fStencilPaths.push_back(); |
852 } | 891 } |
853 | 892 |
854 GrInOrderDrawBuffer::DrawPath* GrInOrderDrawBuffer::recordDrawPath() { | 893 GrInOrderDrawBuffer::DrawPath* GrInOrderDrawBuffer::recordDrawPath() { |
855 fCmds.push_back(kDrawPath_Cmd); | 894 this->addToCmdBuffer(kDrawPath_Cmd); |
856 return &fDrawPaths.push_back(); | 895 return &fDrawPaths.push_back(); |
857 } | 896 } |
858 | 897 |
859 GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { | 898 GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { |
860 fCmds.push_back(kClear_Cmd); | 899 this->addToCmdBuffer(kClear_Cmd); |
861 return &fClears.push_back(); | 900 return &fClears.push_back(); |
862 } | 901 } |
863 | 902 |
864 GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() { | 903 GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() { |
865 fCmds.push_back(kCopySurface_Cmd); | 904 this->addToCmdBuffer(kCopySurface_Cmd); |
866 return &fCopySurfaces.push_back(); | 905 return &fCopySurfaces.push_back(); |
867 } | 906 } |
868 | 907 |
869 | 908 |
870 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { | 909 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { |
871 INHERITED::clipWillBeSet(newClipData); | 910 INHERITED::clipWillBeSet(newClipData); |
872 fClipSet = true; | 911 fClipSet = true; |
873 fClipProxyState = kUnknown_ClipProxyState; | 912 fClipProxyState = kUnknown_ClipProxyState; |
874 } | 913 } |
OLD | NEW |