| 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 rect = &r; | 504 rect = &r; |
| 477 } | 505 } |
| 478 Clear* clr = this->recordClear(); | 506 Clear* clr = this->recordClear(); |
| 479 clr->fColor = color; | 507 clr->fColor = color; |
| 480 clr->fRect = *rect; | 508 clr->fRect = *rect; |
| 481 clr->fCanIgnoreRect = canIgnoreRect; | 509 clr->fCanIgnoreRect = canIgnoreRect; |
| 482 clr->fRenderTarget = renderTarget; | 510 clr->fRenderTarget = renderTarget; |
| 483 renderTarget->ref(); | 511 renderTarget->ref(); |
| 484 } | 512 } |
| 485 | 513 |
| 486 void GrInOrderDrawBuffer::onInstantGpuTraceEvent(const char* marker) { | |
| 487 // TODO: adds command to buffer | |
| 488 } | |
| 489 | |
| 490 void GrInOrderDrawBuffer::onPushGpuTraceEvent(const char* marker) { | |
| 491 // TODO: adds command to buffer | |
| 492 } | |
| 493 | |
| 494 void GrInOrderDrawBuffer::onPopGpuTraceEvent() { | |
| 495 // TODO: adds command to buffer | |
| 496 } | |
| 497 | |
| 498 void GrInOrderDrawBuffer::reset() { | 514 void GrInOrderDrawBuffer::reset() { |
| 499 SkASSERT(1 == fGeoPoolStateStack.count()); | 515 SkASSERT(1 == fGeoPoolStateStack.count()); |
| 500 this->resetVertexSource(); | 516 this->resetVertexSource(); |
| 501 this->resetIndexSource(); | 517 this->resetIndexSource(); |
| 502 int numDraws = fDraws.count(); | 518 int numDraws = fDraws.count(); |
| 503 for (int d = 0; d < numDraws; ++d) { | 519 for (int d = 0; d < numDraws; ++d) { |
| 504 // we always have a VB, but not always an IB | 520 // we always have a VB, but not always an IB |
| 505 SkASSERT(NULL != fDraws[d].fVertexBuffer); | 521 SkASSERT(NULL != fDraws[d].fVertexBuffer); |
| 506 fDraws[d].fVertexBuffer->unref(); | 522 fDraws[d].fVertexBuffer->unref(); |
| 507 SkSafeUnref(fDraws[d].fIndexBuffer); | 523 SkSafeUnref(fDraws[d].fIndexBuffer); |
| 508 } | 524 } |
| 509 fCmds.reset(); | 525 fCmds.reset(); |
| 510 fDraws.reset(); | 526 fDraws.reset(); |
| 511 fStencilPaths.reset(); | 527 fStencilPaths.reset(); |
| 512 fDrawPath.reset(); | 528 fDrawPath.reset(); |
| 513 fDrawPaths.reset(); | 529 fDrawPaths.reset(); |
| 514 fStates.reset(); | 530 fStates.reset(); |
| 515 fClears.reset(); | 531 fClears.reset(); |
| 516 fVertexPool.reset(); | 532 fVertexPool.reset(); |
| 517 fIndexPool.reset(); | 533 fIndexPool.reset(); |
| 518 fClips.reset(); | 534 fClips.reset(); |
| 519 fClipOrigins.reset(); | 535 fClipOrigins.reset(); |
| 520 fCopySurfaces.reset(); | 536 fCopySurfaces.reset(); |
| 537 fGpuCmdMarkers.reset(); |
| 521 fClipSet = true; | 538 fClipSet = true; |
| 522 } | 539 } |
| 523 | 540 |
| 524 void GrInOrderDrawBuffer::flush() { | 541 void GrInOrderDrawBuffer::flush() { |
| 525 if (fFlushing) { | 542 if (fFlushing) { |
| 526 return; | 543 return; |
| 527 } | 544 } |
| 528 | 545 |
| 529 SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); | 546 SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); |
| 530 SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); | 547 SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 551 GrClipData clipData; | 568 GrClipData clipData; |
| 552 | 569 |
| 553 int currState = 0; | 570 int currState = 0; |
| 554 int currClip = 0; | 571 int currClip = 0; |
| 555 int currClear = 0; | 572 int currClear = 0; |
| 556 int currDraw = 0; | 573 int currDraw = 0; |
| 557 int currStencilPath = 0; | 574 int currStencilPath = 0; |
| 558 int currDrawPath = 0; | 575 int currDrawPath = 0; |
| 559 int currDrawPaths = 0; | 576 int currDrawPaths = 0; |
| 560 int currCopySurface = 0; | 577 int currCopySurface = 0; |
| 578 int currCmdMarker = 0; |
| 561 | 579 |
| 562 for (int c = 0; c < numCmds; ++c) { | 580 for (int c = 0; c < numCmds; ++c) { |
| 563 switch (fCmds[c]) { | 581 GrGpuTraceMarker newMarker("", -1); |
| 582 if (cmd_has_trace_marker(fCmds[c])) { |
| 583 SkString traceString = fGpuCmdMarkers[currCmdMarker].toString(); |
| 584 newMarker.fMarker = traceString.c_str(); |
| 585 fDstGpu->addGpuTraceMarker(&newMarker); |
| 586 ++currCmdMarker; |
| 587 } |
| 588 switch (strip_trace_bit(fCmds[c])) { |
| 564 case kDraw_Cmd: { | 589 case kDraw_Cmd: { |
| 565 const DrawRecord& draw = fDraws[currDraw]; | 590 const DrawRecord& draw = fDraws[currDraw]; |
| 566 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer); | 591 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer); |
| 567 if (draw.isIndexed()) { | 592 if (draw.isIndexed()) { |
| 568 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer); | 593 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer); |
| 569 } | 594 } |
| 570 fDstGpu->executeDraw(draw); | 595 fDstGpu->executeDraw(draw); |
| 571 | |
| 572 ++currDraw; | 596 ++currDraw; |
| 573 break; | 597 break; |
| 574 } | 598 } |
| 575 case kStencilPath_Cmd: { | 599 case kStencilPath_Cmd: { |
| 576 const StencilPath& sp = fStencilPaths[currStencilPath]; | 600 const StencilPath& sp = fStencilPaths[currStencilPath]; |
| 577 fDstGpu->stencilPath(sp.fPath.get(), sp.fFill); | 601 fDstGpu->stencilPath(sp.fPath.get(), sp.fFill); |
| 578 ++currStencilPath; | 602 ++currStencilPath; |
| 579 break; | 603 break; |
| 580 } | 604 } |
| 581 case kDrawPath_Cmd: { | 605 case kDrawPath_Cmd: { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 ++currClear; | 637 ++currClear; |
| 614 break; | 638 break; |
| 615 case kCopySurface_Cmd: | 639 case kCopySurface_Cmd: |
| 616 fDstGpu->copySurface(fCopySurfaces[currCopySurface].fDst.get(), | 640 fDstGpu->copySurface(fCopySurfaces[currCopySurface].fDst.get(), |
| 617 fCopySurfaces[currCopySurface].fSrc.get(), | 641 fCopySurfaces[currCopySurface].fSrc.get(), |
| 618 fCopySurfaces[currCopySurface].fSrcRect, | 642 fCopySurfaces[currCopySurface].fSrcRect, |
| 619 fCopySurfaces[currCopySurface].fDstPoint); | 643 fCopySurfaces[currCopySurface].fDstPoint); |
| 620 ++currCopySurface; | 644 ++currCopySurface; |
| 621 break; | 645 break; |
| 622 } | 646 } |
| 647 if (cmd_has_trace_marker(fCmds[c])) { |
| 648 fDstGpu->removeGpuTraceMarker(&newMarker); |
| 649 } |
| 623 } | 650 } |
| 624 // we should have consumed all the states, clips, etc. | 651 // we should have consumed all the states, clips, etc. |
| 625 SkASSERT(fStates.count() == currState); | 652 SkASSERT(fStates.count() == currState); |
| 626 SkASSERT(fClips.count() == currClip); | 653 SkASSERT(fClips.count() == currClip); |
| 627 SkASSERT(fClipOrigins.count() == currClip); | 654 SkASSERT(fClipOrigins.count() == currClip); |
| 628 SkASSERT(fClears.count() == currClear); | 655 SkASSERT(fClears.count() == currClear); |
| 629 SkASSERT(fDraws.count() == currDraw); | 656 SkASSERT(fDraws.count() == currDraw); |
| 630 SkASSERT(fCopySurfaces.count() == currCopySurface); | 657 SkASSERT(fCopySurfaces.count() == currCopySurface); |
| 658 SkASSERT(fGpuCmdMarkers.count() == currCmdMarker); |
| 631 | 659 |
| 632 fDstGpu->setDrawState(prevDrawState); | 660 fDstGpu->setDrawState(prevDrawState); |
| 633 prevDrawState->unref(); | 661 prevDrawState->unref(); |
| 634 this->reset(); | 662 this->reset(); |
| 635 ++fDrawID; | 663 ++fDrawID; |
| 636 } | 664 } |
| 637 | 665 |
| 638 bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, | 666 bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, |
| 639 GrSurface* src, | 667 GrSurface* src, |
| 640 const SkIRect& srcRect, | 668 const SkIRect& srcRect, |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 if (fClipSet && | 904 if (fClipSet && |
| 877 (fClips.empty() || | 905 (fClips.empty() || |
| 878 fClips.back() != *this->getClip()->fClipStack || | 906 fClips.back() != *this->getClip()->fClipStack || |
| 879 fClipOrigins.back() != this->getClip()->fOrigin)) { | 907 fClipOrigins.back() != this->getClip()->fOrigin)) { |
| 880 return true; | 908 return true; |
| 881 } | 909 } |
| 882 } | 910 } |
| 883 return false; | 911 return false; |
| 884 } | 912 } |
| 885 | 913 |
| 914 void GrInOrderDrawBuffer::addToCmdBuffer(uint8_t cmd) { |
| 915 SkASSERT(!cmd_has_trace_marker(cmd)); |
| 916 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
| 917 if (activeTraceMarkers.count() > 0) { |
| 918 fCmds.push_back(add_trace_bit(cmd)); |
| 919 fGpuCmdMarkers.push_back(activeTraceMarkers); |
| 920 } else { |
| 921 fCmds.push_back(cmd); |
| 922 } |
| 923 } |
| 924 |
| 886 void GrInOrderDrawBuffer::recordClip() { | 925 void GrInOrderDrawBuffer::recordClip() { |
| 887 fClips.push_back() = *this->getClip()->fClipStack; | 926 fClips.push_back(*this->getClip()->fClipStack); |
| 888 fClipOrigins.push_back() = this->getClip()->fOrigin; | 927 fClipOrigins.push_back() = this->getClip()->fOrigin; |
| 889 fClipSet = false; | 928 fClipSet = false; |
| 890 fCmds.push_back(kSetClip_Cmd); | 929 this->addToCmdBuffer(kSetClip_Cmd); |
| 891 } | 930 } |
| 892 | 931 |
| 893 void GrInOrderDrawBuffer::recordState() { | 932 void GrInOrderDrawBuffer::recordState() { |
| 894 fStates.push_back().saveFrom(this->getDrawState()); | 933 fStates.push_back().saveFrom(this->getDrawState()); |
| 895 fCmds.push_back(kSetState_Cmd); | 934 this->addToCmdBuffer(kSetState_Cmd); |
| 896 } | 935 } |
| 897 | 936 |
| 898 GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo&
info) { | 937 GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo&
info) { |
| 899 fCmds.push_back(kDraw_Cmd); | 938 this->addToCmdBuffer(kDraw_Cmd); |
| 900 return &fDraws.push_back(info); | 939 return &fDraws.push_back(info); |
| 901 } | 940 } |
| 902 | 941 |
| 903 GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { | 942 GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { |
| 904 fCmds.push_back(kStencilPath_Cmd); | 943 this->addToCmdBuffer(kStencilPath_Cmd); |
| 905 return &fStencilPaths.push_back(); | 944 return &fStencilPaths.push_back(); |
| 906 } | 945 } |
| 907 | 946 |
| 908 GrInOrderDrawBuffer::DrawPath* GrInOrderDrawBuffer::recordDrawPath() { | 947 GrInOrderDrawBuffer::DrawPath* GrInOrderDrawBuffer::recordDrawPath() { |
| 909 fCmds.push_back(kDrawPath_Cmd); | 948 this->addToCmdBuffer(kDrawPath_Cmd); |
| 910 return &fDrawPath.push_back(); | 949 return &fDrawPath.push_back(); |
| 911 } | 950 } |
| 912 | 951 |
| 913 GrInOrderDrawBuffer::DrawPaths* GrInOrderDrawBuffer::recordDrawPaths() { | 952 GrInOrderDrawBuffer::DrawPaths* GrInOrderDrawBuffer::recordDrawPaths() { |
| 914 fCmds.push_back(kDrawPaths_Cmd); | 953 this->addToCmdBuffer(kDrawPaths_Cmd); |
| 915 return &fDrawPaths.push_back(); | 954 return &fDrawPaths.push_back(); |
| 916 } | 955 } |
| 917 | 956 |
| 918 GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { | 957 GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { |
| 919 fCmds.push_back(kClear_Cmd); | 958 this->addToCmdBuffer(kClear_Cmd); |
| 920 return &fClears.push_back(); | 959 return &fClears.push_back(); |
| 921 } | 960 } |
| 922 | 961 |
| 923 GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() { | 962 GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() { |
| 924 fCmds.push_back(kCopySurface_Cmd); | 963 this->addToCmdBuffer(kCopySurface_Cmd); |
| 925 return &fCopySurfaces.push_back(); | 964 return &fCopySurfaces.push_back(); |
| 926 } | 965 } |
| 927 | 966 |
| 928 | 967 |
| 929 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { | 968 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { |
| 930 INHERITED::clipWillBeSet(newClipData); | 969 INHERITED::clipWillBeSet(newClipData); |
| 931 fClipSet = true; | 970 fClipSet = true; |
| 932 fClipProxyState = kUnknown_ClipProxyState; | 971 fClipProxyState = kUnknown_ClipProxyState; |
| 933 } | 972 } |
| OLD | NEW |