OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "GrInOrderDrawBuffer.h" | 10 #include "GrInOrderDrawBuffer.h" |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 } | 415 } |
416 fCmds.reset(); | 416 fCmds.reset(); |
417 fDraws.reset(); | 417 fDraws.reset(); |
418 fStencilPaths.reset(); | 418 fStencilPaths.reset(); |
419 fStates.reset(); | 419 fStates.reset(); |
420 fClears.reset(); | 420 fClears.reset(); |
421 fVertexPool.reset(); | 421 fVertexPool.reset(); |
422 fIndexPool.reset(); | 422 fIndexPool.reset(); |
423 fClips.reset(); | 423 fClips.reset(); |
424 fClipOrigins.reset(); | 424 fClipOrigins.reset(); |
| 425 fCopySurfaces.reset(); |
425 fClipSet = true; | 426 fClipSet = true; |
426 } | 427 } |
427 | 428 |
428 bool GrInOrderDrawBuffer::flush() { | 429 bool GrInOrderDrawBuffer::flush() { |
429 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); | 430 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); |
430 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); | 431 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); |
431 | 432 |
432 int numCmds = fCmds.count(); | 433 int numCmds = fCmds.count(); |
433 if (0 == numCmds) { | 434 if (0 == numCmds) { |
434 return false; | 435 return false; |
(...skipping 14 matching lines...) Expand all Loading... |
449 prevDrawState->ref(); | 450 prevDrawState->ref(); |
450 fDstGpu->setDrawState(&playbackState); | 451 fDstGpu->setDrawState(&playbackState); |
451 | 452 |
452 GrClipData clipData; | 453 GrClipData clipData; |
453 | 454 |
454 int currState = 0; | 455 int currState = 0; |
455 int currClip = 0; | 456 int currClip = 0; |
456 int currClear = 0; | 457 int currClear = 0; |
457 int currDraw = 0; | 458 int currDraw = 0; |
458 int currStencilPath = 0; | 459 int currStencilPath = 0; |
| 460 int currCopySurface = 0; |
459 | 461 |
460 for (int c = 0; c < numCmds; ++c) { | 462 for (int c = 0; c < numCmds; ++c) { |
461 switch (fCmds[c]) { | 463 switch (fCmds[c]) { |
462 case kDraw_Cmd: { | 464 case kDraw_Cmd: { |
463 const DrawRecord& draw = fDraws[currDraw]; | 465 const DrawRecord& draw = fDraws[currDraw]; |
464 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer); | 466 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer); |
465 if (draw.isIndexed()) { | 467 if (draw.isIndexed()) { |
466 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer); | 468 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer); |
467 } | 469 } |
468 fDstGpu->executeDraw(draw); | 470 fDstGpu->executeDraw(draw); |
(...skipping 16 matching lines...) Expand all Loading... |
485 clipData.fOrigin = fClipOrigins[currClip]; | 487 clipData.fOrigin = fClipOrigins[currClip]; |
486 fDstGpu->setClip(&clipData); | 488 fDstGpu->setClip(&clipData); |
487 ++currClip; | 489 ++currClip; |
488 break; | 490 break; |
489 case kClear_Cmd: | 491 case kClear_Cmd: |
490 fDstGpu->clear(&fClears[currClear].fRect, | 492 fDstGpu->clear(&fClears[currClear].fRect, |
491 fClears[currClear].fColor, | 493 fClears[currClear].fColor, |
492 fClears[currClear].fRenderTarget); | 494 fClears[currClear].fRenderTarget); |
493 ++currClear; | 495 ++currClear; |
494 break; | 496 break; |
| 497 case kCopySurface_Cmd: |
| 498 fDstGpu->copySurface(fCopySurfaces[currCopySurface].fDst.get(), |
| 499 fCopySurfaces[currCopySurface].fSrc.get(), |
| 500 fCopySurfaces[currCopySurface].fSrcRect, |
| 501 fCopySurfaces[currCopySurface].fDstPoint); |
| 502 ++currCopySurface; |
| 503 break; |
495 } | 504 } |
496 } | 505 } |
497 // we should have consumed all the states, clips, etc. | 506 // we should have consumed all the states, clips, etc. |
498 GrAssert(fStates.count() == currState); | 507 GrAssert(fStates.count() == currState); |
499 GrAssert(fClips.count() == currClip); | 508 GrAssert(fClips.count() == currClip); |
500 GrAssert(fClipOrigins.count() == currClip); | 509 GrAssert(fClipOrigins.count() == currClip); |
501 GrAssert(fClears.count() == currClear); | 510 GrAssert(fClears.count() == currClear); |
502 GrAssert(fDraws.count() == currDraw); | 511 GrAssert(fDraws.count() == currDraw); |
| 512 GrAssert(fCopySurfaces.count() == currCopySurface); |
503 | 513 |
504 fDstGpu->setDrawState(prevDrawState); | 514 fDstGpu->setDrawState(prevDrawState); |
505 prevDrawState->unref(); | 515 prevDrawState->unref(); |
506 this->reset(); | 516 this->reset(); |
507 return true; | 517 return true; |
508 } | 518 } |
509 | 519 |
| 520 bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, |
| 521 GrSurface* src, |
| 522 const SkIRect& srcRect, |
| 523 const SkIPoint& dstPoint) { |
| 524 if (fDstGpu->canCopySurface(dst, src, srcRect, dstPoint)) { |
| 525 CopySurface* cs = this->recordCopySurface(); |
| 526 cs->fDst.reset(SkRef(dst)); |
| 527 cs->fSrc.reset(SkRef(src)); |
| 528 cs->fSrcRect = srcRect; |
| 529 cs->fDstPoint = dstPoint; |
| 530 return true; |
| 531 } else { |
| 532 return false; |
| 533 } |
| 534 } |
| 535 |
| 536 bool GrInOrderDrawBuffer::onCanCopySurface(GrSurface* dst, |
| 537 GrSurface* src, |
| 538 const SkIRect& srcRect, |
| 539 const SkIPoint& dstPoint) { |
| 540 return fDstGpu->canCopySurface(dst, src, srcRect, dstPoint); |
| 541 } |
| 542 |
510 void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace( | 543 void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace( |
511 int vertexCount, | 544 int vertexCount, |
512 int indexCount) { | 545 int indexCount) { |
513 // We use geometryHints() to know whether to flush the draw buffer. We | 546 // We use geometryHints() to know whether to flush the draw buffer. We |
514 // can't flush if we are inside an unbalanced pushGeometrySource. | 547 // can't flush if we are inside an unbalanced pushGeometrySource. |
515 // Moreover, flushing blows away vertex and index data that was | 548 // Moreover, flushing blows away vertex and index data that was |
516 // previously reserved. So if the vertex or index data is pulled from | 549 // previously reserved. So if the vertex or index data is pulled from |
517 // reserved space and won't be released by this request then we can't | 550 // reserved space and won't be released by this request then we can't |
518 // flush. | 551 // flush. |
519 bool insideGeoPush = fGeoPoolStateStack.count() > 1; | 552 bool insideGeoPush = fGeoPoolStateStack.count() > 1; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { | 782 GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { |
750 fCmds.push_back(kStencilPath_Cmd); | 783 fCmds.push_back(kStencilPath_Cmd); |
751 return &fStencilPaths.push_back(); | 784 return &fStencilPaths.push_back(); |
752 } | 785 } |
753 | 786 |
754 GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { | 787 GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { |
755 fCmds.push_back(kClear_Cmd); | 788 fCmds.push_back(kClear_Cmd); |
756 return &fClears.push_back(); | 789 return &fClears.push_back(); |
757 } | 790 } |
758 | 791 |
| 792 GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() { |
| 793 fCmds.push_back(kCopySurface_Cmd); |
| 794 return &fCopySurfaces.push_back(); |
| 795 } |
| 796 |
| 797 |
759 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { | 798 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { |
760 INHERITED::clipWillBeSet(newClipData); | 799 INHERITED::clipWillBeSet(newClipData); |
761 fClipSet = true; | 800 fClipSet = true; |
762 fClipProxyState = kUnknown_ClipProxyState; | 801 fClipProxyState = kUnknown_ClipProxyState; |
763 } | 802 } |
OLD | NEW |