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 | 9 |
10 | 10 |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 } | 376 } |
377 | 377 |
378 #endif | 378 #endif |
379 if (NULL == drawState.getRenderTarget()) { | 379 if (NULL == drawState.getRenderTarget()) { |
380 return false; | 380 return false; |
381 } | 381 } |
382 return true; | 382 return true; |
383 } | 383 } |
384 | 384 |
385 bool GrDrawTarget::setupDstReadIfNecessary(GrDrawState* ds, | 385 bool GrDrawTarget::setupDstReadIfNecessary(GrDrawState* ds, |
| 386 GrColor color, |
| 387 uint8_t coverage, |
386 GrDeviceCoordTexture* dstCopy, | 388 GrDeviceCoordTexture* dstCopy, |
387 const SkRect* drawBounds) { | 389 const SkRect* drawBounds) { |
388 if (this->caps()->dstReadInShaderSupport() || !ds->willEffectReadDstColor())
{ | 390 GrColor c = GrColorPackRGBA(coverage, coverage, coverage, coverage); |
| 391 if (this->caps()->dstReadInShaderSupport() || !ds->willEffectReadDstColor(co
lor, c)) { |
389 return true; | 392 return true; |
390 } | 393 } |
391 SkIRect copyRect; | 394 SkIRect copyRect; |
392 const GrClipData* clip = this->getClip(); | 395 const GrClipData* clip = this->getClip(); |
393 GrRenderTarget* rt = ds->getRenderTarget(); | 396 GrRenderTarget* rt = ds->getRenderTarget(); |
394 clip->getConservativeBounds(rt, ©Rect); | 397 clip->getConservativeBounds(rt, ©Rect); |
395 | 398 |
396 if (drawBounds) { | 399 if (drawBounds) { |
397 SkIRect drawIBounds; | 400 SkIRect drawIBounds; |
398 drawBounds->roundOut(&drawIBounds); | 401 drawBounds->roundOut(&drawIBounds); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 info.fInstanceCount = 0; | 464 info.fInstanceCount = 0; |
462 info.fVerticesPerInstance = 0; | 465 info.fVerticesPerInstance = 0; |
463 info.fIndicesPerInstance = 0; | 466 info.fIndicesPerInstance = 0; |
464 | 467 |
465 if (devBounds) { | 468 if (devBounds) { |
466 info.setDevBounds(*devBounds); | 469 info.setDevBounds(*devBounds); |
467 } | 470 } |
468 | 471 |
469 // TODO: We should continue with incorrect blending. | 472 // TODO: We should continue with incorrect blending. |
470 GrDeviceCoordTexture dstCopy; | 473 GrDeviceCoordTexture dstCopy; |
471 if (!this->setupDstReadIfNecessary(ds, &dstCopy, devBounds)) { | 474 const GrGeometryProcessor* gp = ds->getGeometryProcessor(); |
| 475 if (!this->setupDstReadIfNecessary(ds, gp->getColor(), gp->getCoverage()
, &dstCopy, |
| 476 devBounds)) { |
472 return; | 477 return; |
473 } | 478 } |
474 this->setDrawBuffers(&info, ds->getGeometryProcessor()->getVertexStride(
)); | 479 this->setDrawBuffers(&info, gp->getVertexStride()); |
475 | 480 |
476 this->onDraw(*ds, info, scissorState, dstCopy.texture() ? &dstCopy : NUL
L); | 481 this->onDraw(*ds, info, scissorState, dstCopy.texture() ? &dstCopy : NUL
L); |
477 } | 482 } |
478 } | 483 } |
479 | 484 |
480 void GrDrawTarget::drawNonIndexed(GrDrawState* ds, | 485 void GrDrawTarget::drawNonIndexed(GrDrawState* ds, |
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) { |
(...skipping 18 matching lines...) Expand all Loading... |
503 info.fInstanceCount = 0; | 508 info.fInstanceCount = 0; |
504 info.fVerticesPerInstance = 0; | 509 info.fVerticesPerInstance = 0; |
505 info.fIndicesPerInstance = 0; | 510 info.fIndicesPerInstance = 0; |
506 | 511 |
507 if (devBounds) { | 512 if (devBounds) { |
508 info.setDevBounds(*devBounds); | 513 info.setDevBounds(*devBounds); |
509 } | 514 } |
510 | 515 |
511 // TODO: We should continue with incorrect blending. | 516 // TODO: We should continue with incorrect blending. |
512 GrDeviceCoordTexture dstCopy; | 517 GrDeviceCoordTexture dstCopy; |
513 if (!this->setupDstReadIfNecessary(ds, &dstCopy, devBounds)) { | 518 const GrGeometryProcessor* gp = ds->getGeometryProcessor(); |
| 519 if (!this->setupDstReadIfNecessary(ds, gp->getColor(), gp->getCoverage()
, &dstCopy, |
| 520 devBounds)) { |
514 return; | 521 return; |
515 } | 522 } |
516 | 523 |
517 this->setDrawBuffers(&info, ds->getGeometryProcessor()->getVertexStride(
)); | 524 this->setDrawBuffers(&info, gp->getVertexStride()); |
518 | 525 |
519 this->onDraw(*ds, info, scissorState, dstCopy.texture() ? &dstCopy : NUL
L); | 526 this->onDraw(*ds, info, scissorState, dstCopy.texture() ? &dstCopy : NUL
L); |
520 } | 527 } |
521 } | 528 } |
522 | 529 |
523 static const GrStencilSettings& winding_path_stencil_settings() { | 530 static const GrStencilSettings& winding_path_stencil_settings() { |
524 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, | 531 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
525 kIncClamp_StencilOp, | 532 kIncClamp_StencilOp, |
526 kIncClamp_StencilOp, | 533 kIncClamp_StencilOp, |
527 kAlwaysIfInClip_StencilFunc, | 534 kAlwaysIfInClip_StencilFunc, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 // set stencil settings for path | 581 // set stencil settings for path |
575 GrStencilSettings stencilSettings; | 582 GrStencilSettings stencilSettings; |
576 this->getPathStencilSettingsForFilltype(fill, | 583 this->getPathStencilSettingsForFilltype(fill, |
577 ds->getRenderTarget()->getStencilBuf
fer(), | 584 ds->getRenderTarget()->getStencilBuf
fer(), |
578 &stencilSettings); | 585 &stencilSettings); |
579 | 586 |
580 this->onStencilPath(*ds, path, scissorState, stencilSettings); | 587 this->onStencilPath(*ds, path, scissorState, stencilSettings); |
581 } | 588 } |
582 | 589 |
583 void GrDrawTarget::drawPath(GrDrawState* ds, | 590 void GrDrawTarget::drawPath(GrDrawState* ds, |
| 591 GrColor color, |
584 const GrPath* path, | 592 const GrPath* path, |
585 GrPathRendering::FillType fill) { | 593 GrPathRendering::FillType fill) { |
586 // TODO: extract portions of checkDraw that are relevant to path rendering. | 594 // TODO: extract portions of checkDraw that are relevant to path rendering. |
587 SkASSERT(path); | 595 SkASSERT(path); |
588 SkASSERT(this->caps()->pathRenderingSupport()); | 596 SkASSERT(this->caps()->pathRenderingSupport()); |
589 SkASSERT(ds); | 597 SkASSERT(ds); |
590 | 598 |
591 SkRect devBounds = path->getBounds(); | 599 SkRect devBounds = path->getBounds(); |
592 SkMatrix viewM = ds->getViewMatrix(); | 600 SkMatrix viewM = ds->getViewMatrix(); |
593 viewM.mapRect(&devBounds); | 601 viewM.mapRect(&devBounds); |
594 | 602 |
595 // Setup clip | 603 // Setup clip |
596 GrClipMaskManager::ScissorState scissorState; | 604 GrClipMaskManager::ScissorState scissorState; |
597 GrDrawState::AutoRestoreEffects are; | 605 GrDrawState::AutoRestoreEffects are; |
598 GrDrawState::AutoRestoreStencil ars; | 606 GrDrawState::AutoRestoreStencil ars; |
599 if (!this->setupClip(&devBounds, &are, &ars, ds, &scissorState)) { | 607 if (!this->setupClip(&devBounds, &are, &ars, ds, &scissorState)) { |
600 return; | 608 return; |
601 } | 609 } |
602 | 610 |
603 // set stencil settings for path | 611 // set stencil settings for path |
604 GrStencilSettings stencilSettings; | 612 GrStencilSettings stencilSettings; |
605 this->getPathStencilSettingsForFilltype(fill, | 613 this->getPathStencilSettingsForFilltype(fill, |
606 ds->getRenderTarget()->getStencilBuf
fer(), | 614 ds->getRenderTarget()->getStencilBuf
fer(), |
607 &stencilSettings); | 615 &stencilSettings); |
608 | 616 |
609 GrDeviceCoordTexture dstCopy; | 617 GrDeviceCoordTexture dstCopy; |
610 if (!this->setupDstReadIfNecessary(ds, &dstCopy, &devBounds)) { | 618 if (!this->setupDstReadIfNecessary(ds, color, 0xff, &dstCopy, &devBounds)) { |
611 return; | 619 return; |
612 } | 620 } |
613 | 621 |
614 this->onDrawPath(*ds, path, scissorState, stencilSettings, dstCopy.texture()
? &dstCopy : NULL); | 622 this->onDrawPath(*ds, color, path, scissorState, stencilSettings, dstCopy.te
xture() ? &dstCopy : |
| 623
NULL); |
615 } | 624 } |
616 | 625 |
617 void GrDrawTarget::drawPaths(GrDrawState* ds, | 626 void GrDrawTarget::drawPaths(GrDrawState* ds, |
| 627 GrColor color, |
618 const GrPathRange* pathRange, | 628 const GrPathRange* pathRange, |
619 const void* indices, | 629 const void* indices, |
620 PathIndexType indexType, | 630 PathIndexType indexType, |
621 const float transformValues[], | 631 const float transformValues[], |
622 PathTransformType transformType, | 632 PathTransformType transformType, |
623 int count, | 633 int count, |
624 GrPathRendering::FillType fill) { | 634 GrPathRendering::FillType fill) { |
625 SkASSERT(this->caps()->pathRenderingSupport()); | 635 SkASSERT(this->caps()->pathRenderingSupport()); |
626 SkASSERT(pathRange); | 636 SkASSERT(pathRange); |
627 SkASSERT(indices); | 637 SkASSERT(indices); |
(...skipping 14 matching lines...) Expand all Loading... |
642 GrStencilSettings stencilSettings; | 652 GrStencilSettings stencilSettings; |
643 this->getPathStencilSettingsForFilltype(fill, | 653 this->getPathStencilSettingsForFilltype(fill, |
644 ds->getRenderTarget()->getStencilBuf
fer(), | 654 ds->getRenderTarget()->getStencilBuf
fer(), |
645 &stencilSettings); | 655 &stencilSettings); |
646 | 656 |
647 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt | 657 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt |
648 // instead for it to just copy the entire dst. Realistically this is a moot | 658 // instead for it to just copy the entire dst. Realistically this is a moot |
649 // point, because any context that supports NV_path_rendering will also | 659 // point, because any context that supports NV_path_rendering will also |
650 // support NV_blend_equation_advanced. | 660 // support NV_blend_equation_advanced. |
651 GrDeviceCoordTexture dstCopy; | 661 GrDeviceCoordTexture dstCopy; |
652 if (!this->setupDstReadIfNecessary(ds, &dstCopy, NULL)) { | 662 if (!this->setupDstReadIfNecessary(ds, color, 0xff, &dstCopy, NULL)) { |
653 return; | 663 return; |
654 } | 664 } |
655 | 665 |
656 this->onDrawPaths(*ds, pathRange, indices, indexType, transformValues, trans
formType, count, | 666 this->onDrawPaths(*ds, color, pathRange, indices, indexType, transformValues
, transformType, |
657 scissorState, stencilSettings, dstCopy.texture() ? &dstCop
y : NULL); | 667 count, scissorState, stencilSettings, dstCopy.texture() ?
&dstCopy : NULL); |
658 } | 668 } |
659 | 669 |
660 void GrDrawTarget::clear(const SkIRect* rect, | 670 void GrDrawTarget::clear(const SkIRect* rect, |
661 GrColor color, | 671 GrColor color, |
662 bool canIgnoreRect, | 672 bool canIgnoreRect, |
663 GrRenderTarget* renderTarget) { | 673 GrRenderTarget* renderTarget) { |
664 if (fCaps->useDrawInsteadOfClear()) { | 674 if (fCaps->useDrawInsteadOfClear()) { |
665 // This works around a driver bug with clear by drawing a rect instead. | 675 // This works around a driver bug with clear by drawing a rect instead. |
666 // The driver will ignore a clear if it is the only thing rendered to a | 676 // The driver will ignore a clear if it is the only thing rendered to a |
667 // target before the target is read. | 677 // target before the target is read. |
668 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->he
ight()); | 678 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->he
ight()); |
669 if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) { | 679 if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) { |
670 rect = &rtRect; | 680 rect = &rtRect; |
671 // We first issue a discard() since that may help tilers. | 681 // We first issue a discard() since that may help tilers. |
672 this->discard(renderTarget); | 682 this->discard(renderTarget); |
673 } | 683 } |
674 | 684 |
675 GrDrawState drawState; | 685 GrDrawState drawState; |
676 | |
677 drawState.setColor(color); | |
678 drawState.setRenderTarget(renderTarget); | 686 drawState.setRenderTarget(renderTarget); |
679 | 687 |
680 this->drawSimpleRect(&drawState, *rect); | 688 this->drawSimpleRect(&drawState, color, *rect); |
681 } else { | 689 } else { |
682 this->onClear(rect, color, canIgnoreRect, renderTarget); | 690 this->onClear(rect, color, canIgnoreRect, renderTarget); |
683 } | 691 } |
684 } | 692 } |
685 | 693 |
686 typedef GrTraceMarkerSet::Iter TMIter; | 694 typedef GrTraceMarkerSet::Iter TMIter; |
687 void GrDrawTarget::saveActiveTraceMarkers() { | 695 void GrDrawTarget::saveActiveTraceMarkers() { |
688 if (this->caps()->gpuTracingSupport()) { | 696 if (this->caps()->gpuTracingSupport()) { |
689 SkASSERT(0 == fStoredTraceMarkers.count()); | 697 SkASSERT(0 == fStoredTraceMarkers.count()); |
690 fStoredTraceMarkers.addSet(fActiveTraceMarkers); | 698 fStoredTraceMarkers.addSet(fActiveTraceMarkers); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 info.fIndicesPerInstance = indicesPerInstance; | 764 info.fIndicesPerInstance = indicesPerInstance; |
757 info.fVerticesPerInstance = verticesPerInstance; | 765 info.fVerticesPerInstance = verticesPerInstance; |
758 | 766 |
759 // Set the same bounds for all the draws. | 767 // Set the same bounds for all the draws. |
760 if (devBounds) { | 768 if (devBounds) { |
761 info.setDevBounds(*devBounds); | 769 info.setDevBounds(*devBounds); |
762 } | 770 } |
763 | 771 |
764 // TODO: We should continue with incorrect blending. | 772 // TODO: We should continue with incorrect blending. |
765 GrDeviceCoordTexture dstCopy; | 773 GrDeviceCoordTexture dstCopy; |
766 if (!this->setupDstReadIfNecessary(ds, &dstCopy, devBounds)) { | 774 const GrGeometryProcessor* gp = ds->getGeometryProcessor(); |
| 775 if (!this->setupDstReadIfNecessary(ds, gp->getColor(), gp->getCoverage(), &d
stCopy,devBounds)) { |
767 return; | 776 return; |
768 } | 777 } |
769 | 778 |
770 while (instanceCount) { | 779 while (instanceCount) { |
771 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); | 780 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); |
772 info.fVertexCount = info.fInstanceCount * verticesPerInstance; | 781 info.fVertexCount = info.fInstanceCount * verticesPerInstance; |
773 info.fIndexCount = info.fInstanceCount * indicesPerInstance; | 782 info.fIndexCount = info.fInstanceCount * indicesPerInstance; |
774 | 783 |
775 if (this->checkDraw(*ds, | 784 if (this->checkDraw(*ds, |
776 type, | 785 type, |
777 info.fStartVertex, | 786 info.fStartVertex, |
778 info.fStartIndex, | 787 info.fStartIndex, |
779 info.fVertexCount, | 788 info.fVertexCount, |
780 info.fIndexCount)) { | 789 info.fIndexCount)) { |
781 this->setDrawBuffers(&info, ds->getGeometryProcessor()->getVertexStr
ide()); | 790 this->setDrawBuffers(&info, gp->getVertexStride()); |
782 this->onDraw(*ds, info, scissorState, dstCopy.texture() ? &dstCopy :
NULL); | 791 this->onDraw(*ds, info, scissorState, dstCopy.texture() ? &dstCopy :
NULL); |
783 } | 792 } |
784 info.fStartVertex += info.fVertexCount; | 793 info.fStartVertex += info.fVertexCount; |
785 instanceCount -= info.fInstanceCount; | 794 instanceCount -= info.fInstanceCount; |
786 } | 795 } |
787 } | 796 } |
788 | 797 |
789 //////////////////////////////////////////////////////////////////////////////// | 798 //////////////////////////////////////////////////////////////////////////////// |
790 | 799 |
791 GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( | 800 GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 drawState.setRenderTarget(rt); | 946 drawState.setRenderTarget(rt); |
938 SkMatrix matrix; | 947 SkMatrix matrix; |
939 matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX)
, | 948 matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX)
, |
940 SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY))
; | 949 SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY))
; |
941 matrix.postIDiv(tex->width(), tex->height()); | 950 matrix.postIDiv(tex->width(), tex->height()); |
942 drawState.addColorTextureProcessor(tex, matrix); | 951 drawState.addColorTextureProcessor(tex, matrix); |
943 SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX, | 952 SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX, |
944 clippedDstPoint.fY, | 953 clippedDstPoint.fY, |
945 clippedSrcRect.width(), | 954 clippedSrcRect.width(), |
946 clippedSrcRect.height()); | 955 clippedSrcRect.height()); |
947 this->drawSimpleRect(&drawState, dstRect); | 956 this->drawSimpleRect(&drawState, GrColor_WHITE, dstRect); |
948 return true; | 957 return true; |
949 } | 958 } |
950 | 959 |
951 bool GrDrawTarget::canCopySurface(const GrSurface* dst, | 960 bool GrDrawTarget::canCopySurface(const GrSurface* dst, |
952 const GrSurface* src, | 961 const GrSurface* src, |
953 const SkIRect& srcRect, | 962 const SkIRect& srcRect, |
954 const SkIPoint& dstPoint) { | 963 const SkIPoint& dstPoint) { |
955 SkASSERT(dst); | 964 SkASSERT(dst); |
956 SkASSERT(src); | 965 SkASSERT(src); |
957 | 966 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 GrDrawState::AutoRestoreStencil* ars, | 1217 GrDrawState::AutoRestoreStencil* ars, |
1209 GrDrawState* ds, | 1218 GrDrawState* ds, |
1210 GrClipMaskManager::ScissorState* scissorState) { | 1219 GrClipMaskManager::ScissorState* scissorState) { |
1211 return fClipMaskManager.setupClipping(ds, | 1220 return fClipMaskManager.setupClipping(ds, |
1212 are, | 1221 are, |
1213 ars, | 1222 ars, |
1214 scissorState, | 1223 scissorState, |
1215 this->getClip(), | 1224 this->getClip(), |
1216 devBounds); | 1225 devBounds); |
1217 } | 1226 } |
OLD | NEW |