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