| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 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 "GrBatchTest.h" | 9 #include "GrBatchTest.h" |
| 10 #include "GrColor.h" | 10 #include "GrColor.h" |
| 11 #include "GrDrawContext.h" | 11 #include "GrDrawContext.h" |
| 12 #include "GrDrawingManager.h" | 12 #include "GrDrawingManager.h" |
| 13 #include "GrOvalRenderer.h" | 13 #include "GrOvalRenderer.h" |
| 14 #include "GrPathRenderer.h" | 14 #include "GrPathRenderer.h" |
| 15 #include "GrRenderTarget.h" | 15 #include "GrRenderTarget.h" |
| 16 #include "GrRenderTargetPriv.h" | 16 #include "GrRenderTargetPriv.h" |
| 17 #include "GrResourceProvider.h" | 17 #include "GrResourceProvider.h" |
| 18 #include "SkSurfacePriv.h" | 18 #include "SkSurfacePriv.h" |
| 19 | 19 |
| 20 #include "batches/GrBatch.h" | 20 #include "batches/GrBatch.h" |
| 21 #include "batches/GrDrawAtlasBatch.h" | 21 #include "batches/GrDrawAtlasBatch.h" |
| 22 #include "batches/GrDrawVerticesBatch.h" | 22 #include "batches/GrDrawVerticesBatch.h" |
| 23 #include "batches/GrRectBatchFactory.h" | 23 #include "batches/GrRectBatchFactory.h" |
| 24 #include "batches/GrNinePatch.h" // TODO Factory | 24 #include "batches/GrNinePatch.h" // TODO Factory |
| 25 | 25 |
| 26 #include "effects/GrRRectEffect.h" |
| 27 |
| 26 #include "text/GrAtlasTextContext.h" | 28 #include "text/GrAtlasTextContext.h" |
| 27 #include "text/GrStencilAndCoverTextContext.h" | 29 #include "text/GrStencilAndCoverTextContext.h" |
| 28 | 30 |
| 29 #include "../private/GrAuditTrail.h" | 31 #include "../private/GrAuditTrail.h" |
| 30 | 32 |
| 31 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fDrawingM
anager->getContext()) | 33 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fDrawingM
anager->getContext()) |
| 32 #define ASSERT_SINGLE_OWNER \ | 34 #define ASSERT_SINGLE_OWNER \ |
| 33 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);) | 35 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);) |
| 34 #define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; } | 36 #define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; } |
| 35 #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return fa
lse; } | 37 #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return fa
lse; } |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 return; | 489 return; |
| 488 } | 490 } |
| 489 | 491 |
| 490 SkASSERT(!strokeInfo.isDashed()); // this should've been devolved to a path
in SkGpuDevice | 492 SkASSERT(!strokeInfo.isDashed()); // this should've been devolved to a path
in SkGpuDevice |
| 491 | 493 |
| 492 AutoCheckFlush acf(fDrawingManager); | 494 AutoCheckFlush acf(fDrawingManager); |
| 493 | 495 |
| 494 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 496 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 495 GrColor color = paint.getColor(); | 497 GrColor color = paint.getColor(); |
| 496 | 498 |
| 497 if (!GrOvalRenderer::DrawRRect(this->getDrawTarget(), | 499 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
| 498 pipelineBuilder, | 500 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateRRectBatch(pipelineBui
lder, |
| 499 color, | 501 color, |
| 500 viewMatrix, | 502 viewMatrix, |
| 501 paint.isAntiAlias(), | 503 paint.isAnt
iAlias(), |
| 502 rrect, | 504 rrect, |
| 503 strokeInfo)) { | 505 strokeInfo, |
| 506 shaderCaps)
); |
| 507 if (batch) { |
| 508 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 509 } else { |
| 504 SkPath path; | 510 SkPath path; |
| 505 path.setIsVolatile(true); | 511 path.setIsVolatile(true); |
| 506 path.addRRect(rrect); | 512 path.addRRect(rrect); |
| 507 this->internalDrawPath(&pipelineBuilder, viewMatrix, color, | 513 this->internalDrawPath(&pipelineBuilder, viewMatrix, color, |
| 508 paint.isAntiAlias(), path, strokeInfo); | 514 paint.isAntiAlias(), path, strokeInfo); |
| 509 } | 515 } |
| 510 } | 516 } |
| 511 | 517 |
| 512 /////////////////////////////////////////////////////////////////////////////// | 518 /////////////////////////////////////////////////////////////////////////////// |
| 513 | 519 |
| 520 static bool draw_drrect(GrDrawTarget* drawTarget, |
| 521 const GrPipelineBuilder& pipelineBuilder, |
| 522 GrColor color, |
| 523 const SkMatrix& viewMatrix, |
| 524 bool useAA, |
| 525 const SkRRect& origOuter, |
| 526 const SkRRect& origInner, |
| 527 GrShaderCaps* shaderCaps) { |
| 528 bool applyAA = useAA && !pipelineBuilder.getRenderTarget()->isUnifiedMultisa
mpled(); |
| 529 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
| 530 if (!origInner.isEmpty()) { |
| 531 SkTCopyOnFirstWrite<SkRRect> inner(origInner); |
| 532 if (!viewMatrix.isIdentity()) { |
| 533 if (!origInner.transform(viewMatrix, inner.writable())) { |
| 534 return false; |
| 535 } |
| 536 } |
| 537 GrPrimitiveEdgeType edgeType = applyAA ? |
| 538 kInverseFillAA_GrProcessorEdgeType : |
| 539 kInverseFillBW_GrProcessorEdgeType; |
| 540 // TODO this needs to be a geometry processor |
| 541 GrFragmentProcessor* fp = GrRRectEffect::Create(edgeType, *inner); |
| 542 if (nullptr == fp) { |
| 543 return false; |
| 544 } |
| 545 arfps.set(&pipelineBuilder); |
| 546 arfps.addCoverageFragmentProcessor(fp)->unref(); |
| 547 } |
| 548 |
| 549 SkStrokeRec fillRec(SkStrokeRec::kFill_InitStyle); |
| 550 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateRRectBatch(pipelineBui
lder, color, |
| 551 viewMatrix,
useAA, origOuter, |
| 552 fillRec, sh
aderCaps)); |
| 553 if (batch) { |
| 554 drawTarget->drawBatch(pipelineBuilder, batch); |
| 555 return true; |
| 556 } |
| 557 |
| 558 SkASSERT(!origOuter.isEmpty()); |
| 559 SkTCopyOnFirstWrite<SkRRect> outer(origOuter); |
| 560 if (!viewMatrix.isIdentity()) { |
| 561 if (!origOuter.transform(viewMatrix, outer.writable())) { |
| 562 return false; |
| 563 } |
| 564 } |
| 565 GrPrimitiveEdgeType edgeType = applyAA ? kFillAA_GrProcessorEdgeType : |
| 566 kFillBW_GrProcessorEdgeType; |
| 567 SkAutoTUnref<GrFragmentProcessor> effect(GrRRectEffect::Create(edgeType, *ou
ter)); |
| 568 if (!effect) { |
| 569 return false; |
| 570 } |
| 571 if (!arfps.isSet()) { |
| 572 arfps.set(&pipelineBuilder); |
| 573 } |
| 574 |
| 575 SkMatrix invert; |
| 576 if (!viewMatrix.invert(&invert)) { |
| 577 return false; |
| 578 } |
| 579 |
| 580 arfps.addCoverageFragmentProcessor(effect); |
| 581 SkRect bounds = outer->getBounds(); |
| 582 if (applyAA) { |
| 583 bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 584 } |
| 585 batch.reset(GrRectBatchFactory::CreateNonAAFill(color, SkMatrix::I(), bounds
, |
| 586 nullptr, &invert)); |
| 587 drawTarget->drawBatch(pipelineBuilder, batch); |
| 588 return true; |
| 589 } |
| 590 |
| 514 void GrDrawContext::drawDRRect(const GrClip& clip, | 591 void GrDrawContext::drawDRRect(const GrClip& clip, |
| 515 const GrPaint& paint, | 592 const GrPaint& paint, |
| 516 const SkMatrix& viewMatrix, | 593 const SkMatrix& viewMatrix, |
| 517 const SkRRect& outer, | 594 const SkRRect& outer, |
| 518 const SkRRect& inner) { | 595 const SkRRect& inner) { |
| 519 ASSERT_SINGLE_OWNER | 596 ASSERT_SINGLE_OWNER |
| 520 RETURN_IF_ABANDONED | 597 RETURN_IF_ABANDONED |
| 521 SkDEBUGCODE(this->validate();) | 598 SkDEBUGCODE(this->validate();) |
| 522 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawDRRect"); | 599 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawDRRect"); |
| 523 | 600 |
| 524 if (outer.isEmpty()) { | 601 if (outer.isEmpty()) { |
| 525 return; | 602 return; |
| 526 } | 603 } |
| 527 | 604 |
| 528 AutoCheckFlush acf(fDrawingManager); | 605 AutoCheckFlush acf(fDrawingManager); |
| 529 | 606 |
| 530 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 607 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 531 GrColor color = paint.getColor(); | 608 GrColor color = paint.getColor(); |
| 532 if (!GrOvalRenderer::DrawDRRect(this->getDrawTarget(), | 609 |
| 533 pipelineBuilder, | 610 if (!draw_drrect(this->getDrawTarget(), pipelineBuilder, |
| 534 color, | 611 color, viewMatrix, paint.isAntiAlias(), |
| 535 viewMatrix, | 612 outer, inner, fContext->caps()->shaderCaps())) { |
| 536 paint.isAntiAlias(), | |
| 537 outer, | |
| 538 inner)) { | |
| 539 SkPath path; | 613 SkPath path; |
| 540 path.setIsVolatile(true); | 614 path.setIsVolatile(true); |
| 541 path.addRRect(inner); | 615 path.addRRect(inner); |
| 542 path.addRRect(outer); | 616 path.addRRect(outer); |
| 543 path.setFillType(SkPath::kEvenOdd_FillType); | 617 path.setFillType(SkPath::kEvenOdd_FillType); |
| 544 | 618 |
| 545 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); | 619 GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); |
| 546 this->internalDrawPath(&pipelineBuilder, viewMatrix, color, | 620 this->internalDrawPath(&pipelineBuilder, viewMatrix, color, |
| 547 paint.isAntiAlias(), path, fillRec); | 621 paint.isAntiAlias(), path, fillRec); |
| 548 } | 622 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 564 return; | 638 return; |
| 565 } | 639 } |
| 566 | 640 |
| 567 SkASSERT(!strokeInfo.isDashed()); // this should've been devolved to a path
in SkGpuDevice | 641 SkASSERT(!strokeInfo.isDashed()); // this should've been devolved to a path
in SkGpuDevice |
| 568 | 642 |
| 569 AutoCheckFlush acf(fDrawingManager); | 643 AutoCheckFlush acf(fDrawingManager); |
| 570 | 644 |
| 571 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 645 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 572 GrColor color = paint.getColor(); | 646 GrColor color = paint.getColor(); |
| 573 | 647 |
| 574 if (!GrOvalRenderer::DrawOval(this->getDrawTarget(), | 648 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
| 575 pipelineBuilder, | 649 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(pipelineBuil
der, |
| 576 color, | 650 color, |
| 577 viewMatrix, | 651 viewMatrix, |
| 578 paint.isAntiAlias(), | 652 paint.isAnti
Alias(), |
| 579 oval, | 653 oval, |
| 580 strokeInfo)) { | 654 strokeInfo, |
| 655 shaderCaps))
; |
| 656 if (batch) { |
| 657 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 658 } else { |
| 581 SkPath path; | 659 SkPath path; |
| 582 path.setIsVolatile(true); | 660 path.setIsVolatile(true); |
| 583 path.addOval(oval); | 661 path.addOval(oval); |
| 584 this->internalDrawPath(&pipelineBuilder, viewMatrix, color, | 662 this->internalDrawPath(&pipelineBuilder, viewMatrix, color, |
| 585 paint.isAntiAlias(), path, strokeInfo); | 663 paint.isAntiAlias(), path, strokeInfo); |
| 586 } | 664 } |
| 587 } | 665 } |
| 588 | 666 |
| 589 void GrDrawContext::drawImageNine(const GrClip& clip, | 667 void GrDrawContext::drawImageNine(const GrClip& clip, |
| 590 const GrPaint& paint, | 668 const GrPaint& paint, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill
NestedRects( | 800 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill
NestedRects( |
| 723 color, viewMatrix, rects)); | 801 color, viewMatrix, rects)); |
| 724 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 802 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 725 return; | 803 return; |
| 726 } | 804 } |
| 727 } | 805 } |
| 728 SkRect ovalRect; | 806 SkRect ovalRect; |
| 729 bool isOval = path.isOval(&ovalRect); | 807 bool isOval = path.isOval(&ovalRect); |
| 730 | 808 |
| 731 if (isOval && !path.isInverseFillType()) { | 809 if (isOval && !path.isInverseFillType()) { |
| 732 if (GrOvalRenderer::DrawOval(this->getDrawTarget(), | 810 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
| 733 pipelineBuilder, | 811 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(pipe
lineBuilder, |
| 734 color, | 812 colo
r, |
| 735 viewMatrix, | 813 view
Matrix, |
| 736 paint.isAntiAlias(), | 814 pain
t.isAntiAlias(), |
| 737 ovalRect, | 815 oval
Rect, |
| 738 strokeInfo)) { | 816 stro
keInfo, |
| 817 shad
erCaps)); |
| 818 if (batch) { |
| 819 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 739 return; | 820 return; |
| 740 } | 821 } |
| 741 } | 822 } |
| 742 } | 823 } |
| 743 this->internalDrawPath(&pipelineBuilder, viewMatrix, color, | 824 this->internalDrawPath(&pipelineBuilder, viewMatrix, color, |
| 744 paint.isAntiAlias(), path, strokeInfo); | 825 paint.isAntiAlias(), path, strokeInfo); |
| 745 } | 826 } |
| 746 | 827 |
| 747 void GrDrawContext::internalDrawPath(GrPipelineBuilder* pipelineBuilder, | 828 void GrDrawContext::internalDrawPath(GrPipelineBuilder* pipelineBuilder, |
| 748 const SkMatrix& viewMatrix, | 829 const SkMatrix& viewMatrix, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 } | 928 } |
| 848 | 929 |
| 849 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b
atch) { | 930 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b
atch) { |
| 850 ASSERT_SINGLE_OWNER | 931 ASSERT_SINGLE_OWNER |
| 851 RETURN_IF_ABANDONED | 932 RETURN_IF_ABANDONED |
| 852 SkDEBUGCODE(this->validate();) | 933 SkDEBUGCODE(this->validate();) |
| 853 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); | 934 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); |
| 854 | 935 |
| 855 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch); | 936 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch); |
| 856 } | 937 } |
| OLD | NEW |