| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 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 #include "GrDrawTarget.h" | 9 #include "GrDrawTarget.h" |
| 10 | 10 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 | 379 |
| 380 #endif | 380 #endif |
| 381 if (NULL == pipelineBuilder.getRenderTarget()) { | 381 if (NULL == pipelineBuilder.getRenderTarget()) { |
| 382 return false; | 382 return false; |
| 383 } | 383 } |
| 384 return true; | 384 return true; |
| 385 } | 385 } |
| 386 | 386 |
| 387 bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuil
der, | 387 bool GrDrawTarget::setupDstReadIfNecessary(GrPipelineBuilder* pipelineBuilder, |
| 388 GrDeviceCoordTexture* dstCopy, | 388 GrDeviceCoordTexture* dstCopy, |
| 389 const SkRect* drawBounds) { | 389 const SkRect* drawBounds) { |
| 390 if (!pipelineBuilder.willXPNeedDstCopy(*this->caps())) { | 390 if (this->caps()->dstReadInShaderSupport() || !pipelineBuilder->willEffectRe
adDstColor()) { |
| 391 return true; | 391 return true; |
| 392 } | 392 } |
| 393 SkIRect copyRect; | 393 SkIRect copyRect; |
| 394 const GrClipData* clip = this->getClip(); | 394 const GrClipData* clip = this->getClip(); |
| 395 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); | 395 GrRenderTarget* rt = pipelineBuilder->getRenderTarget(); |
| 396 clip->getConservativeBounds(rt, ©Rect); | 396 clip->getConservativeBounds(rt, ©Rect); |
| 397 | 397 |
| 398 if (drawBounds) { | 398 if (drawBounds) { |
| 399 SkIRect drawIBounds; | 399 SkIRect drawIBounds; |
| 400 drawBounds->roundOut(&drawIBounds); | 400 drawBounds->roundOut(&drawIBounds); |
| 401 if (!copyRect.intersect(drawIBounds)) { | 401 if (!copyRect.intersect(drawIBounds)) { |
| 402 #ifdef SK_DEBUG | 402 #ifdef SK_DEBUG |
| 403 SkDebugf("Missed an early reject. Bailing on draw from setupDstReadI
fNecessary.\n"); | 403 SkDebugf("Missed an early reject. Bailing on draw from setupDstReadI
fNecessary.\n"); |
| 404 #endif | 404 #endif |
| 405 return false; | 405 return false; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 info.fIndexCount = indexCount; | 463 info.fIndexCount = indexCount; |
| 464 | 464 |
| 465 info.fInstanceCount = 0; | 465 info.fInstanceCount = 0; |
| 466 info.fVerticesPerInstance = 0; | 466 info.fVerticesPerInstance = 0; |
| 467 info.fIndicesPerInstance = 0; | 467 info.fIndicesPerInstance = 0; |
| 468 | 468 |
| 469 if (devBounds) { | 469 if (devBounds) { |
| 470 info.setDevBounds(*devBounds); | 470 info.setDevBounds(*devBounds); |
| 471 } | 471 } |
| 472 | 472 |
| 473 // TODO: We should continue with incorrect blending. |
| 474 GrDeviceCoordTexture dstCopy; |
| 475 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)
) { |
| 476 return; |
| 477 } |
| 473 this->setDrawBuffers(&info, gp->getVertexStride()); | 478 this->setDrawBuffers(&info, gp->getVertexStride()); |
| 474 | 479 |
| 475 this->onDraw(*pipelineBuilder, gp, info, scissorState); | 480 this->onDraw(*pipelineBuilder, gp, info, scissorState, dstCopy.texture()
? &dstCopy : NULL); |
| 476 } | 481 } |
| 477 } | 482 } |
| 478 | 483 |
| 479 void GrDrawTarget::drawNonIndexed(GrPipelineBuilder* pipelineBuilder, | 484 void GrDrawTarget::drawNonIndexed(GrPipelineBuilder* pipelineBuilder, |
| 480 const GrGeometryProcessor* gp, | 485 const GrGeometryProcessor* gp, |
| 481 GrPrimitiveType type, | 486 GrPrimitiveType type, |
| 482 int startVertex, | 487 int startVertex, |
| 483 int vertexCount, | 488 int vertexCount, |
| 484 const SkRect* devBounds) { | 489 const SkRect* devBounds) { |
| 485 SkASSERT(pipelineBuilder); | 490 SkASSERT(pipelineBuilder); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 502 info.fIndexCount = 0; | 507 info.fIndexCount = 0; |
| 503 | 508 |
| 504 info.fInstanceCount = 0; | 509 info.fInstanceCount = 0; |
| 505 info.fVerticesPerInstance = 0; | 510 info.fVerticesPerInstance = 0; |
| 506 info.fIndicesPerInstance = 0; | 511 info.fIndicesPerInstance = 0; |
| 507 | 512 |
| 508 if (devBounds) { | 513 if (devBounds) { |
| 509 info.setDevBounds(*devBounds); | 514 info.setDevBounds(*devBounds); |
| 510 } | 515 } |
| 511 | 516 |
| 517 // TODO: We should continue with incorrect blending. |
| 518 GrDeviceCoordTexture dstCopy; |
| 519 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)
) { |
| 520 return; |
| 521 } |
| 522 |
| 512 this->setDrawBuffers(&info, gp->getVertexStride()); | 523 this->setDrawBuffers(&info, gp->getVertexStride()); |
| 513 | 524 |
| 514 this->onDraw(*pipelineBuilder, gp, info, scissorState); | 525 this->onDraw(*pipelineBuilder, gp, info, scissorState, dstCopy.texture()
? &dstCopy : NULL); |
| 515 } | 526 } |
| 516 } | 527 } |
| 517 | 528 |
| 518 | 529 |
| 519 void GrDrawTarget::drawBatch(GrPipelineBuilder* pipelineBuilder, | 530 void GrDrawTarget::drawBatch(GrPipelineBuilder* pipelineBuilder, |
| 520 GrBatch* batch, | 531 GrBatch* batch, |
| 521 const SkRect* devBounds) { | 532 const SkRect* devBounds) { |
| 522 SkASSERT(pipelineBuilder); | 533 SkASSERT(pipelineBuilder); |
| 523 // TODO some kind of checkdraw, but not at this level | 534 // TODO some kind of checkdraw, but not at this level |
| 524 | 535 |
| 525 // Setup clip | 536 // Setup clip |
| 526 GrScissorState scissorState; | 537 GrScissorState scissorState; |
| 527 GrPipelineBuilder::AutoRestoreEffects are; | 538 GrPipelineBuilder::AutoRestoreEffects are; |
| 528 GrPipelineBuilder::AutoRestoreStencil ars; | 539 GrPipelineBuilder::AutoRestoreStencil ars; |
| 529 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, devBounds))
{ | 540 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, devBounds))
{ |
| 530 return; | 541 return; |
| 531 } | 542 } |
| 532 | 543 |
| 533 this->onDrawBatch(batch, *pipelineBuilder, scissorState, devBounds); | 544 GrDeviceCoordTexture dstCopy; |
| 545 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) { |
| 546 return; |
| 547 } |
| 548 |
| 549 this->onDrawBatch(batch, *pipelineBuilder, scissorState, dstCopy.texture() ?
&dstCopy : NULL); |
| 534 } | 550 } |
| 535 | 551 |
| 536 static const GrStencilSettings& winding_path_stencil_settings() { | 552 static const GrStencilSettings& winding_path_stencil_settings() { |
| 537 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, | 553 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 538 kIncClamp_StencilOp, | 554 kIncClamp_StencilOp, |
| 539 kIncClamp_StencilOp, | 555 kIncClamp_StencilOp, |
| 540 kAlwaysIfInClip_StencilFunc, | 556 kAlwaysIfInClip_StencilFunc, |
| 541 0xFFFF, 0xFFFF, 0xFFFF); | 557 0xFFFF, 0xFFFF, 0xFFFF); |
| 542 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); | 558 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 543 } | 559 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, &devBounds)
) { | 629 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, &devBounds)
) { |
| 614 return; | 630 return; |
| 615 } | 631 } |
| 616 | 632 |
| 617 // set stencil settings for path | 633 // set stencil settings for path |
| 618 GrStencilSettings stencilSettings; | 634 GrStencilSettings stencilSettings; |
| 619 this->getPathStencilSettingsForFilltype(fill, | 635 this->getPathStencilSettingsForFilltype(fill, |
| 620 pipelineBuilder->getRenderTarget()->
getStencilBuffer(), | 636 pipelineBuilder->getRenderTarget()->
getStencilBuffer(), |
| 621 &stencilSettings); | 637 &stencilSettings); |
| 622 | 638 |
| 639 GrDeviceCoordTexture dstCopy; |
| 640 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, &devBounds)) { |
| 641 return; |
| 642 } |
| 643 |
| 623 this->onDrawPath(*pipelineBuilder, pathProc, path, scissorState, stencilSett
ings, | 644 this->onDrawPath(*pipelineBuilder, pathProc, path, scissorState, stencilSett
ings, |
| 624 &devBounds); | 645 dstCopy.texture() ? &dstCopy : NULL); |
| 625 } | 646 } |
| 626 | 647 |
| 627 void GrDrawTarget::drawPaths(GrPipelineBuilder* pipelineBuilder, | 648 void GrDrawTarget::drawPaths(GrPipelineBuilder* pipelineBuilder, |
| 628 const GrPathProcessor* pathProc, | 649 const GrPathProcessor* pathProc, |
| 629 const GrPathRange* pathRange, | 650 const GrPathRange* pathRange, |
| 630 const void* indices, | 651 const void* indices, |
| 631 PathIndexType indexType, | 652 PathIndexType indexType, |
| 632 const float transformValues[], | 653 const float transformValues[], |
| 633 PathTransformType transformType, | 654 PathTransformType transformType, |
| 634 int count, | 655 int count, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 648 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, NULL)) { | 669 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, NULL)) { |
| 649 return; | 670 return; |
| 650 } | 671 } |
| 651 | 672 |
| 652 // set stencil settings for path | 673 // set stencil settings for path |
| 653 GrStencilSettings stencilSettings; | 674 GrStencilSettings stencilSettings; |
| 654 this->getPathStencilSettingsForFilltype(fill, | 675 this->getPathStencilSettingsForFilltype(fill, |
| 655 pipelineBuilder->getRenderTarget()->
getStencilBuffer(), | 676 pipelineBuilder->getRenderTarget()->
getStencilBuffer(), |
| 656 &stencilSettings); | 677 &stencilSettings); |
| 657 | 678 |
| 658 // Don't compute a bounding box for dst copy texture, we'll opt | 679 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt |
| 659 // instead for it to just copy the entire dst. Realistically this is a moot | 680 // instead for it to just copy the entire dst. Realistically this is a moot |
| 660 // point, because any context that supports NV_path_rendering will also | 681 // point, because any context that supports NV_path_rendering will also |
| 661 // support NV_blend_equation_advanced. | 682 // support NV_blend_equation_advanced. |
| 683 GrDeviceCoordTexture dstCopy; |
| 684 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, NULL)) { |
| 685 return; |
| 686 } |
| 687 |
| 662 this->onDrawPaths(*pipelineBuilder, pathProc, pathRange, indices, indexType,
transformValues, | 688 this->onDrawPaths(*pipelineBuilder, pathProc, pathRange, indices, indexType,
transformValues, |
| 663 transformType, count, scissorState, stencilSettings, NULL)
; | 689 transformType, count, scissorState, stencilSettings, |
| 690 dstCopy.texture() ? &dstCopy : NULL); |
| 664 } | 691 } |
| 665 | 692 |
| 666 void GrDrawTarget::clear(const SkIRect* rect, | 693 void GrDrawTarget::clear(const SkIRect* rect, |
| 667 GrColor color, | 694 GrColor color, |
| 668 bool canIgnoreRect, | 695 bool canIgnoreRect, |
| 669 GrRenderTarget* renderTarget) { | 696 GrRenderTarget* renderTarget) { |
| 670 if (fCaps->useDrawInsteadOfClear()) { | 697 if (fCaps->useDrawInsteadOfClear()) { |
| 671 // This works around a driver bug with clear by drawing a rect instead. | 698 // This works around a driver bug with clear by drawing a rect instead. |
| 672 // The driver will ignore a clear if it is the only thing rendered to a | 699 // The driver will ignore a clear if it is the only thing rendered to a |
| 673 // target before the target is read. | 700 // target before the target is read. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 info.fStartIndex = 0; | 786 info.fStartIndex = 0; |
| 760 info.fStartVertex = 0; | 787 info.fStartVertex = 0; |
| 761 info.fIndicesPerInstance = indicesPerInstance; | 788 info.fIndicesPerInstance = indicesPerInstance; |
| 762 info.fVerticesPerInstance = verticesPerInstance; | 789 info.fVerticesPerInstance = verticesPerInstance; |
| 763 | 790 |
| 764 // Set the same bounds for all the draws. | 791 // Set the same bounds for all the draws. |
| 765 if (devBounds) { | 792 if (devBounds) { |
| 766 info.setDevBounds(*devBounds); | 793 info.setDevBounds(*devBounds); |
| 767 } | 794 } |
| 768 | 795 |
| 796 // TODO: We should continue with incorrect blending. |
| 797 GrDeviceCoordTexture dstCopy; |
| 798 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) { |
| 799 return; |
| 800 } |
| 801 |
| 769 while (instanceCount) { | 802 while (instanceCount) { |
| 770 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); | 803 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); |
| 771 info.fVertexCount = info.fInstanceCount * verticesPerInstance; | 804 info.fVertexCount = info.fInstanceCount * verticesPerInstance; |
| 772 info.fIndexCount = info.fInstanceCount * indicesPerInstance; | 805 info.fIndexCount = info.fInstanceCount * indicesPerInstance; |
| 773 | 806 |
| 774 if (this->checkDraw(*pipelineBuilder, | 807 if (this->checkDraw(*pipelineBuilder, |
| 775 gp, | 808 gp, |
| 776 type, | 809 type, |
| 777 info.fStartVertex, | 810 info.fStartVertex, |
| 778 info.fStartIndex, | 811 info.fStartIndex, |
| 779 info.fVertexCount, | 812 info.fVertexCount, |
| 780 info.fIndexCount)) { | 813 info.fIndexCount)) { |
| 781 this->setDrawBuffers(&info, gp->getVertexStride()); | 814 this->setDrawBuffers(&info, gp->getVertexStride()); |
| 782 this->onDraw(*pipelineBuilder, gp, info, scissorState); | 815 this->onDraw(*pipelineBuilder, gp, info, scissorState, |
| 816 dstCopy.texture() ? &dstCopy : NULL); |
| 783 } | 817 } |
| 784 info.fStartVertex += info.fVertexCount; | 818 info.fStartVertex += info.fVertexCount; |
| 785 instanceCount -= info.fInstanceCount; | 819 instanceCount -= info.fInstanceCount; |
| 786 } | 820 } |
| 787 } | 821 } |
| 788 | 822 |
| 789 //////////////////////////////////////////////////////////////////////////////// | 823 //////////////////////////////////////////////////////////////////////////////// |
| 790 | 824 |
| 791 GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( | 825 GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( |
| 792 GrDrawTarget* target, | 826 GrDrawTarget* target, |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 GrPipelineBuilder::AutoRestoreStencil* ars, | 1244 GrPipelineBuilder::AutoRestoreStencil* ars, |
| 1211 GrScissorState* scissorState, | 1245 GrScissorState* scissorState, |
| 1212 const SkRect* devBounds) { | 1246 const SkRect* devBounds) { |
| 1213 return fClipMaskManager.setupClipping(pipelineBuilder, | 1247 return fClipMaskManager.setupClipping(pipelineBuilder, |
| 1214 are, | 1248 are, |
| 1215 ars, | 1249 ars, |
| 1216 scissorState, | 1250 scissorState, |
| 1217 this->getClip(), | 1251 this->getClip(), |
| 1218 devBounds); | 1252 devBounds); |
| 1219 } | 1253 } |
| OLD | NEW |