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(GrPipelineBuilder* pipelineBuilder, | 387 bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuil der, |
388 GrDeviceCoordTexture* dstCopy, | 388 GrDeviceCoordTexture* dstCopy, |
389 const SkRect* drawBounds) { | 389 const SkRect* drawBounds) { |
390 if (this->caps()->dstReadInShaderSupport() || !pipelineBuilder->willEffectRe adDstColor()) { | 390 if (!pipelineBuilder.willXPNeedDstCopy(*this->caps())) { |
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; |
406 } | 406 } |
407 } else { | 407 } else { |
408 #ifdef SK_DEBUG | 408 #ifdef SK_DEBUG |
409 //SkDebugf("No dev bounds when dst copy is made.\n"); | 409 //SkDebugf("No dev bounds when dst copy is made.\n"); |
410 #endif | 410 #endif |
411 } | 411 } |
412 | 412 |
413 // MSAA consideration: When there is support for reading MSAA samples in the shader we could | 413 // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
414 // have per-sample dst values by making the copy multisampled. | 414 // have per-sample dst values by making the copy multisampled. |
415 GrSurfaceDesc desc; | 415 GrSurfaceDesc desc; |
416 this->initCopySurfaceDstDesc(rt, &desc); | 416 this->initCopySurfaceDstDesc(rt, &desc); |
417 desc.fWidth = copyRect.width(); | 417 desc.fWidth = copyRect.width(); |
418 desc.fHeight = copyRect.height(); | 418 desc.fHeight = copyRect.height(); |
419 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | |
bsalomon
2015/02/03 17:28:24
maybe a comment here that our contract with XP is
egdaniel
2015/02/03 19:50:57
Done.
| |
419 | 420 |
420 SkAutoTUnref<GrTexture> copy( | 421 SkAutoTUnref<GrTexture> copy( |
421 fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); | 422 fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); |
422 | 423 |
423 if (!copy) { | 424 if (!copy) { |
424 SkDebugf("Failed to create temporary copy of destination texture.\n"); | 425 SkDebugf("Failed to create temporary copy of destination texture.\n"); |
425 return false; | 426 return false; |
426 } | 427 } |
427 SkIPoint dstPoint = {0, 0}; | 428 SkIPoint dstPoint = {0, 0}; |
428 if (this->copySurface(copy, rt, copyRect, dstPoint)) { | 429 if (this->copySurface(copy, rt, copyRect, dstPoint)) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 info.fIndexCount = indexCount; | 464 info.fIndexCount = indexCount; |
464 | 465 |
465 info.fInstanceCount = 0; | 466 info.fInstanceCount = 0; |
466 info.fVerticesPerInstance = 0; | 467 info.fVerticesPerInstance = 0; |
467 info.fIndicesPerInstance = 0; | 468 info.fIndicesPerInstance = 0; |
468 | 469 |
469 if (devBounds) { | 470 if (devBounds) { |
470 info.setDevBounds(*devBounds); | 471 info.setDevBounds(*devBounds); |
471 } | 472 } |
472 | 473 |
473 // TODO: We should continue with incorrect blending. | |
474 GrDeviceCoordTexture dstCopy; | |
475 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds) ) { | |
476 return; | |
477 } | |
478 this->setDrawBuffers(&info, gp->getVertexStride()); | 474 this->setDrawBuffers(&info, gp->getVertexStride()); |
479 | 475 |
480 this->onDraw(*pipelineBuilder, gp, info, scissorState, dstCopy.texture() ? &dstCopy : NULL); | 476 this->onDraw(*pipelineBuilder, gp, info, scissorState); |
481 } | 477 } |
482 } | 478 } |
483 | 479 |
484 void GrDrawTarget::drawNonIndexed(GrPipelineBuilder* pipelineBuilder, | 480 void GrDrawTarget::drawNonIndexed(GrPipelineBuilder* pipelineBuilder, |
485 const GrGeometryProcessor* gp, | 481 const GrGeometryProcessor* gp, |
486 GrPrimitiveType type, | 482 GrPrimitiveType type, |
487 int startVertex, | 483 int startVertex, |
488 int vertexCount, | 484 int vertexCount, |
489 const SkRect* devBounds) { | 485 const SkRect* devBounds) { |
490 SkASSERT(pipelineBuilder); | 486 SkASSERT(pipelineBuilder); |
(...skipping 16 matching lines...) Expand all Loading... | |
507 info.fIndexCount = 0; | 503 info.fIndexCount = 0; |
508 | 504 |
509 info.fInstanceCount = 0; | 505 info.fInstanceCount = 0; |
510 info.fVerticesPerInstance = 0; | 506 info.fVerticesPerInstance = 0; |
511 info.fIndicesPerInstance = 0; | 507 info.fIndicesPerInstance = 0; |
512 | 508 |
513 if (devBounds) { | 509 if (devBounds) { |
514 info.setDevBounds(*devBounds); | 510 info.setDevBounds(*devBounds); |
515 } | 511 } |
516 | 512 |
517 // TODO: We should continue with incorrect blending. | |
518 GrDeviceCoordTexture dstCopy; | |
519 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds) ) { | |
520 return; | |
521 } | |
522 | |
523 this->setDrawBuffers(&info, gp->getVertexStride()); | 513 this->setDrawBuffers(&info, gp->getVertexStride()); |
524 | 514 |
525 this->onDraw(*pipelineBuilder, gp, info, scissorState, dstCopy.texture() ? &dstCopy : NULL); | 515 this->onDraw(*pipelineBuilder, gp, info, scissorState); |
526 } | 516 } |
527 } | 517 } |
528 | 518 |
529 | 519 |
530 void GrDrawTarget::drawBatch(GrPipelineBuilder* pipelineBuilder, | 520 void GrDrawTarget::drawBatch(GrPipelineBuilder* pipelineBuilder, |
531 GrBatch* batch, | 521 GrBatch* batch, |
532 const SkRect* devBounds) { | 522 const SkRect* devBounds) { |
533 SkASSERT(pipelineBuilder); | 523 SkASSERT(pipelineBuilder); |
534 // TODO some kind of checkdraw, but not at this level | 524 // TODO some kind of checkdraw, but not at this level |
535 | 525 |
536 // Setup clip | 526 // Setup clip |
537 GrScissorState scissorState; | 527 GrScissorState scissorState; |
538 GrPipelineBuilder::AutoRestoreEffects are; | 528 GrPipelineBuilder::AutoRestoreEffects are; |
539 GrPipelineBuilder::AutoRestoreStencil ars; | 529 GrPipelineBuilder::AutoRestoreStencil ars; |
540 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, devBounds)) { | 530 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, devBounds)) { |
541 return; | 531 return; |
542 } | 532 } |
543 | 533 |
544 GrDeviceCoordTexture dstCopy; | 534 this->onDrawBatch(batch, *pipelineBuilder, scissorState, devBounds); |
545 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) { | |
546 return; | |
547 } | |
548 | |
549 this->onDrawBatch(batch, *pipelineBuilder, scissorState, dstCopy.texture() ? &dstCopy : NULL); | |
550 } | 535 } |
551 | 536 |
552 static const GrStencilSettings& winding_path_stencil_settings() { | 537 static const GrStencilSettings& winding_path_stencil_settings() { |
553 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, | 538 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
554 kIncClamp_StencilOp, | 539 kIncClamp_StencilOp, |
555 kIncClamp_StencilOp, | 540 kIncClamp_StencilOp, |
556 kAlwaysIfInClip_StencilFunc, | 541 kAlwaysIfInClip_StencilFunc, |
557 0xFFFF, 0xFFFF, 0xFFFF); | 542 0xFFFF, 0xFFFF, 0xFFFF); |
558 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); | 543 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
559 } | 544 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
629 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, &devBounds) ) { | 614 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, &devBounds) ) { |
630 return; | 615 return; |
631 } | 616 } |
632 | 617 |
633 // set stencil settings for path | 618 // set stencil settings for path |
634 GrStencilSettings stencilSettings; | 619 GrStencilSettings stencilSettings; |
635 this->getPathStencilSettingsForFilltype(fill, | 620 this->getPathStencilSettingsForFilltype(fill, |
636 pipelineBuilder->getRenderTarget()-> getStencilBuffer(), | 621 pipelineBuilder->getRenderTarget()-> getStencilBuffer(), |
637 &stencilSettings); | 622 &stencilSettings); |
638 | 623 |
639 GrDeviceCoordTexture dstCopy; | |
640 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, &devBounds)) { | |
641 return; | |
642 } | |
643 | |
644 this->onDrawPath(*pipelineBuilder, pathProc, path, scissorState, stencilSett ings, | 624 this->onDrawPath(*pipelineBuilder, pathProc, path, scissorState, stencilSett ings, |
645 dstCopy.texture() ? &dstCopy : NULL); | 625 &devBounds); |
646 } | 626 } |
647 | 627 |
648 void GrDrawTarget::drawPaths(GrPipelineBuilder* pipelineBuilder, | 628 void GrDrawTarget::drawPaths(GrPipelineBuilder* pipelineBuilder, |
649 const GrPathProcessor* pathProc, | 629 const GrPathProcessor* pathProc, |
650 const GrPathRange* pathRange, | 630 const GrPathRange* pathRange, |
651 const void* indices, | 631 const void* indices, |
652 PathIndexType indexType, | 632 PathIndexType indexType, |
653 const float transformValues[], | 633 const float transformValues[], |
654 PathTransformType transformType, | 634 PathTransformType transformType, |
655 int count, | 635 int count, |
(...skipping 13 matching lines...) Expand all Loading... | |
669 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, NULL)) { | 649 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, NULL)) { |
670 return; | 650 return; |
671 } | 651 } |
672 | 652 |
673 // set stencil settings for path | 653 // set stencil settings for path |
674 GrStencilSettings stencilSettings; | 654 GrStencilSettings stencilSettings; |
675 this->getPathStencilSettingsForFilltype(fill, | 655 this->getPathStencilSettingsForFilltype(fill, |
676 pipelineBuilder->getRenderTarget()-> getStencilBuffer(), | 656 pipelineBuilder->getRenderTarget()-> getStencilBuffer(), |
677 &stencilSettings); | 657 &stencilSettings); |
678 | 658 |
679 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt | 659 // Don't compute a bounding box for dst copy texture, we'll opt |
680 // instead for it to just copy the entire dst. Realistically this is a moot | 660 // instead for it to just copy the entire dst. Realistically this is a moot |
681 // point, because any context that supports NV_path_rendering will also | 661 // point, because any context that supports NV_path_rendering will also |
682 // support NV_blend_equation_advanced. | 662 // support NV_blend_equation_advanced. |
683 GrDeviceCoordTexture dstCopy; | |
684 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, NULL)) { | |
685 return; | |
686 } | |
687 | |
688 this->onDrawPaths(*pipelineBuilder, pathProc, pathRange, indices, indexType, transformValues, | 663 this->onDrawPaths(*pipelineBuilder, pathProc, pathRange, indices, indexType, transformValues, |
689 transformType, count, scissorState, stencilSettings, | 664 transformType, count, scissorState, stencilSettings, NULL) ; |
690 dstCopy.texture() ? &dstCopy : NULL); | |
691 } | 665 } |
692 | 666 |
693 void GrDrawTarget::clear(const SkIRect* rect, | 667 void GrDrawTarget::clear(const SkIRect* rect, |
694 GrColor color, | 668 GrColor color, |
695 bool canIgnoreRect, | 669 bool canIgnoreRect, |
696 GrRenderTarget* renderTarget) { | 670 GrRenderTarget* renderTarget) { |
697 if (fCaps->useDrawInsteadOfClear()) { | 671 if (fCaps->useDrawInsteadOfClear()) { |
698 // This works around a driver bug with clear by drawing a rect instead. | 672 // This works around a driver bug with clear by drawing a rect instead. |
699 // The driver will ignore a clear if it is the only thing rendered to a | 673 // The driver will ignore a clear if it is the only thing rendered to a |
700 // target before the target is read. | 674 // target before the target is read. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 info.fStartIndex = 0; | 760 info.fStartIndex = 0; |
787 info.fStartVertex = 0; | 761 info.fStartVertex = 0; |
788 info.fIndicesPerInstance = indicesPerInstance; | 762 info.fIndicesPerInstance = indicesPerInstance; |
789 info.fVerticesPerInstance = verticesPerInstance; | 763 info.fVerticesPerInstance = verticesPerInstance; |
790 | 764 |
791 // Set the same bounds for all the draws. | 765 // Set the same bounds for all the draws. |
792 if (devBounds) { | 766 if (devBounds) { |
793 info.setDevBounds(*devBounds); | 767 info.setDevBounds(*devBounds); |
794 } | 768 } |
795 | 769 |
796 // TODO: We should continue with incorrect blending. | |
797 GrDeviceCoordTexture dstCopy; | |
798 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) { | |
799 return; | |
800 } | |
801 | |
802 while (instanceCount) { | 770 while (instanceCount) { |
803 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); | 771 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); |
804 info.fVertexCount = info.fInstanceCount * verticesPerInstance; | 772 info.fVertexCount = info.fInstanceCount * verticesPerInstance; |
805 info.fIndexCount = info.fInstanceCount * indicesPerInstance; | 773 info.fIndexCount = info.fInstanceCount * indicesPerInstance; |
806 | 774 |
807 if (this->checkDraw(*pipelineBuilder, | 775 if (this->checkDraw(*pipelineBuilder, |
808 gp, | 776 gp, |
809 type, | 777 type, |
810 info.fStartVertex, | 778 info.fStartVertex, |
811 info.fStartIndex, | 779 info.fStartIndex, |
812 info.fVertexCount, | 780 info.fVertexCount, |
813 info.fIndexCount)) { | 781 info.fIndexCount)) { |
814 this->setDrawBuffers(&info, gp->getVertexStride()); | 782 this->setDrawBuffers(&info, gp->getVertexStride()); |
815 this->onDraw(*pipelineBuilder, gp, info, scissorState, | 783 this->onDraw(*pipelineBuilder, gp, info, scissorState); |
816 dstCopy.texture() ? &dstCopy : NULL); | |
817 } | 784 } |
818 info.fStartVertex += info.fVertexCount; | 785 info.fStartVertex += info.fVertexCount; |
819 instanceCount -= info.fInstanceCount; | 786 instanceCount -= info.fInstanceCount; |
820 } | 787 } |
821 } | 788 } |
822 | 789 |
823 //////////////////////////////////////////////////////////////////////////////// | 790 //////////////////////////////////////////////////////////////////////////////// |
824 | 791 |
825 GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( | 792 GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( |
826 GrDrawTarget* target, | 793 GrDrawTarget* target, |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1244 GrPipelineBuilder::AutoRestoreStencil* ars, | 1211 GrPipelineBuilder::AutoRestoreStencil* ars, |
1245 GrScissorState* scissorState, | 1212 GrScissorState* scissorState, |
1246 const SkRect* devBounds) { | 1213 const SkRect* devBounds) { |
1247 return fClipMaskManager.setupClipping(pipelineBuilder, | 1214 return fClipMaskManager.setupClipping(pipelineBuilder, |
1248 are, | 1215 are, |
1249 ars, | 1216 ars, |
1250 scissorState, | 1217 scissorState, |
1251 this->getClip(), | 1218 this->getClip(), |
1252 devBounds); | 1219 devBounds); |
1253 } | 1220 } |
OLD | NEW |