OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrMSAAPathRenderer.h" | 8 #include "GrMSAAPathRenderer.h" |
9 | 9 |
10 #include "GrAuditTrail.h" | |
10 #include "GrBatchFlushState.h" | 11 #include "GrBatchFlushState.h" |
12 #include "GrClip.h" | |
11 #include "GrDefaultGeoProcFactory.h" | 13 #include "GrDefaultGeoProcFactory.h" |
12 #include "GrPathStencilSettings.h" | 14 #include "GrPathStencilSettings.h" |
13 #include "GrPathUtils.h" | 15 #include "GrPathUtils.h" |
14 #include "GrPipelineBuilder.h" | 16 #include "GrPipelineBuilder.h" |
15 #include "GrMesh.h" | 17 #include "GrMesh.h" |
16 #include "SkGeometry.h" | 18 #include "SkGeometry.h" |
17 #include "SkTraceEvent.h" | 19 #include "SkTraceEvent.h" |
18 #include "glsl/GrGLSLGeometryProcessor.h" | 20 #include "glsl/GrGLSLGeometryProcessor.h" |
19 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 21 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
20 #include "glsl/GrGLSLVertexShaderBuilder.h" | 22 #include "glsl/GrGLSLVertexShaderBuilder.h" |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 SkMatrix fViewMatrix; | 561 SkMatrix fViewMatrix; |
560 int fMaxLineVertices; | 562 int fMaxLineVertices; |
561 int fMaxQuadVertices; | 563 int fMaxQuadVertices; |
562 int fMaxLineIndices; | 564 int fMaxLineIndices; |
563 int fMaxQuadIndices; | 565 int fMaxQuadIndices; |
564 bool fIsIndexed; | 566 bool fIsIndexed; |
565 | 567 |
566 typedef GrVertexBatch INHERITED; | 568 typedef GrVertexBatch INHERITED; |
567 }; | 569 }; |
568 | 570 |
569 bool GrMSAAPathRenderer::internalDrawPath(GrDrawTarget* target, | 571 bool GrMSAAPathRenderer::internalDrawPath(GrDrawContext* drawContext, |
570 GrPipelineBuilder* pipelineBuilder, | 572 const GrPaint& paint, |
573 const GrUserStencilSettings* userStenc ilSettings, | |
571 const GrClip& clip, | 574 const GrClip& clip, |
572 GrColor color, | 575 GrColor color, |
573 const SkMatrix& viewMatrix, | 576 const SkMatrix& viewMatrix, |
574 const SkPath& path, | 577 const SkPath& path, |
575 bool stencilOnly) { | 578 bool stencilOnly) { |
576 | |
577 const GrXPFactory* xpFactory = pipelineBuilder->getXPFactory(); | |
578 SkAutoTUnref<const GrXPFactory> backupXPFactory(SkSafeRef(xpFactory)); | |
579 // face culling doesn't make sense here | |
580 SkASSERT(GrPipelineBuilder::kBoth_DrawFace == pipelineBuilder->getDrawFace() ); | |
581 | |
582 int passCount = 0; | 579 int passCount = 0; |
583 const GrUserStencilSettings* passes[3]; | 580 const GrUserStencilSettings* passes[3]; |
584 GrPipelineBuilder::DrawFace drawFace[3]; | 581 GrPipelineBuilder::DrawFace drawFace[3]; |
585 bool reverse = false; | 582 bool reverse = false; |
586 bool lastPassIsBounds; | 583 bool lastPassIsBounds; |
587 | 584 |
588 if (single_pass_path(path)) { | 585 if (single_pass_path(path)) { |
589 passCount = 1; | 586 passCount = 1; |
590 if (stencilOnly) { | 587 if (stencilOnly) { |
591 passes[0] = &gDirectToStencil; | 588 passes[0] = &gDirectToStencil; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
636 } | 633 } |
637 } | 634 } |
638 break; | 635 break; |
639 default: | 636 default: |
640 SkDEBUGFAIL("Unknown path fFill!"); | 637 SkDEBUGFAIL("Unknown path fFill!"); |
641 return false; | 638 return false; |
642 } | 639 } |
643 } | 640 } |
644 | 641 |
645 SkRect devBounds; | 642 SkRect devBounds; |
646 GetPathDevBounds(path, pipelineBuilder->getRenderTarget(), viewMatrix, &devB ounds); | 643 GetPathDevBounds(path, drawContext->width(), drawContext->height(), viewMatr ix, &devBounds); |
647 | 644 |
648 for (int p = 0; p < passCount; ++p) { | 645 for (int p = 0; p < passCount; ++p) { |
649 pipelineBuilder->setDrawFace(drawFace[p]); | |
650 if (passes[p]) { | |
651 pipelineBuilder->setUserStencil(passes[p]); | |
652 } | |
653 | |
654 if (lastPassIsBounds && (p == passCount-1)) { | 646 if (lastPassIsBounds && (p == passCount-1)) { |
655 // Reset the XP Factory on pipelineBuilder | |
656 pipelineBuilder->setXPFactory(backupXPFactory); | |
657 SkRect bounds; | 647 SkRect bounds; |
658 SkMatrix localMatrix = SkMatrix::I(); | 648 SkMatrix localMatrix = SkMatrix::I(); |
659 if (reverse) { | 649 if (reverse) { |
660 SkASSERT(pipelineBuilder->getRenderTarget()); | |
661 // draw over the dev bounds (which will be the whole dst surface for inv fill). | 650 // draw over the dev bounds (which will be the whole dst surface for inv fill). |
662 bounds = devBounds; | 651 bounds = devBounds; |
663 SkMatrix vmi; | 652 SkMatrix vmi; |
664 // mapRect through persp matrix may not be correct | 653 // mapRect through persp matrix may not be correct |
665 if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { | 654 if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { |
666 vmi.mapRect(&bounds); | 655 vmi.mapRect(&bounds); |
667 } else { | 656 } else { |
668 if (!viewMatrix.invert(&localMatrix)) { | 657 if (!viewMatrix.invert(&localMatrix)) { |
669 return false; | 658 return false; |
670 } | 659 } |
671 } | 660 } |
672 } else { | 661 } else { |
673 bounds = path.getBounds(); | 662 bounds = path.getBounds(); |
674 } | 663 } |
675 const SkMatrix& viewM = (reverse && viewMatrix.hasPerspective()) ? S kMatrix::I() : | 664 const SkMatrix& viewM = (reverse && viewMatrix.hasPerspective()) ? S kMatrix::I() : |
676 v iewMatrix; | 665 v iewMatrix; |
677 SkAutoTUnref<GrDrawBatch> batch( | 666 SkAutoTUnref<GrDrawBatch> batch( |
678 GrRectBatchFactory::CreateNonAAFill(color, viewM, bounds, nu llptr, | 667 GrRectBatchFactory::CreateNonAAFill(color, viewM, bounds, nu llptr, |
679 &localMatrix)); | 668 &localMatrix)); |
680 target->drawBatch(*pipelineBuilder, clip, batch); | 669 |
681 } else { | 670 GrPipelineBuilder pipelineBuilder(paint, drawContext->isUnifiedMulti sampled()); |
682 if (passCount > 1) { | 671 pipelineBuilder.setRenderTarget(drawContext->accessRenderTarget()); |
683 pipelineBuilder->setDisableColorXPFactory(); | 672 pipelineBuilder.setDrawFace(drawFace[p]); |
673 if (passes[p]) { | |
674 pipelineBuilder.setUserStencil(passes[p]); | |
675 } else { | |
676 pipelineBuilder.setUserStencil(userStencilSettings); | |
684 } | 677 } |
685 | 678 |
679 drawContext->drawBatch(pipelineBuilder, clip, batch); | |
680 } else { | |
686 MSAAPathBatch::Geometry geometry; | 681 MSAAPathBatch::Geometry geometry; |
687 geometry.fColor = color; | 682 geometry.fColor = color; |
688 geometry.fPath = path; | 683 geometry.fPath = path; |
689 geometry.fTolerance = kTolerance; | 684 geometry.fTolerance = kTolerance; |
690 | 685 |
691 SkAutoTUnref<MSAAPathBatch> batch(MSAAPathBatch::Create(geometry, vi ewMatrix, | 686 SkAutoTUnref<MSAAPathBatch> batch(MSAAPathBatch::Create(geometry, vi ewMatrix, |
692 devBounds)); | 687 devBounds)); |
693 if (batch->isValid()) { | 688 if (!batch->isValid()) { |
694 target->drawBatch(*pipelineBuilder, clip, batch); | |
695 } | |
696 else { | |
697 return false; | 689 return false; |
698 } | 690 } |
691 | |
692 GrPipelineBuilder pipelineBuilder(paint, drawContext->isUnifiedMulti sampled()); | |
693 pipelineBuilder.setRenderTarget(drawContext->accessRenderTarget()); | |
694 pipelineBuilder.setDrawFace(drawFace[p]); | |
695 if (passes[p]) { | |
696 pipelineBuilder.setUserStencil(passes[p]); | |
697 } else { | |
698 pipelineBuilder.setUserStencil(userStencilSettings); | |
699 } | |
700 if (passCount > 1) { | |
701 pipelineBuilder.setDisableColorXPFactory(); | |
702 } | |
703 | |
704 drawContext->drawBatch(pipelineBuilder, clip, batch); | |
699 } | 705 } |
700 } | 706 } |
701 return true; | 707 return true; |
702 } | 708 } |
703 | 709 |
704 bool GrMSAAPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { | 710 bool GrMSAAPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
705 // This path renderer does not support hairlines. We defer on anything that could be handled | 711 // This path renderer does not support hairlines. We defer on anything that could be handled |
706 // as a hairline by another path renderer. Also, arbitrary path effects coul d produce | 712 // as a hairline by another path renderer. Also, arbitrary path effects coul d produce |
707 // a hairline result. | 713 // a hairline result. |
708 return !IsStrokeHairlineOrEquivalent(*args.fStyle, *args.fViewMatrix, nullpt r) && | 714 return !IsStrokeHairlineOrEquivalent(*args.fStyle, *args.fViewMatrix, nullpt r) && |
709 !args.fStyle->strokeRec().isHairlineStyle() && | 715 !args.fStyle->strokeRec().isHairlineStyle() && |
710 !args.fStyle->hasNonDashPathEffect() && !args.fAntiAlias; | 716 !args.fStyle->hasNonDashPathEffect() && !args.fAntiAlias; |
711 } | 717 } |
712 | 718 |
713 bool GrMSAAPathRenderer::onDrawPath(const DrawPathArgs& args) { | 719 bool GrMSAAPathRenderer::onDrawPath(const DrawPathArgs& args) { |
714 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), "GrMSAAPathRenderer ::onDrawPath"); | 720 GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), |
721 "GrMSAAPathRenderer::onDrawPath"); | |
715 SkPath tmpPath; | 722 SkPath tmpPath; |
716 const SkPath* path; | 723 const SkPath* path; |
717 if (args.fStyle->applies()) { | 724 if (args.fStyle->applies()) { |
718 SkStrokeRec::InitStyle fill; | 725 SkStrokeRec::InitStyle fill; |
719 SkScalar styleScale = GrStyle::MatrixToScaleFactor(*args.fViewMatrix); | 726 SkScalar styleScale = GrStyle::MatrixToScaleFactor(*args.fViewMatrix); |
720 if (!args.fStyle->applyToPath(&tmpPath, &fill, *args.fPath, styleScale)) { | 727 if (!args.fStyle->applyToPath(&tmpPath, &fill, *args.fPath, styleScale)) { |
721 return false; | 728 return false; |
722 } | 729 } |
723 // We don't accept styles that are hairlines or have path effects that c ould produce | 730 // We don't accept styles that are hairlines or have path effects that c ould produce |
724 // hairlines. | 731 // hairlines. |
725 SkASSERT(SkStrokeRec::kFill_InitStyle == fill); | 732 SkASSERT(SkStrokeRec::kFill_InitStyle == fill); |
726 path = &tmpPath; | 733 path = &tmpPath; |
727 } else { | 734 } else { |
728 path = args.fPath; | 735 path = args.fPath; |
729 } | 736 } |
730 return this->internalDrawPath(args.fTarget, | 737 return this->internalDrawPath(args.fDrawContext, |
731 args.fPipelineBuilder, | 738 *args.fPaint, |
739 args.fUserStencilSettings, | |
732 *args.fClip, | 740 *args.fClip, |
733 args.fColor, | 741 args.fColor, |
734 *args.fViewMatrix, | 742 *args.fViewMatrix, |
735 *path, | 743 *path, |
736 false); | 744 false); |
737 } | 745 } |
738 | 746 |
739 void GrMSAAPathRenderer::onStencilPath(const StencilPathArgs& args) { | 747 void GrMSAAPathRenderer::onStencilPath(const StencilPathArgs& args) { |
740 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(),"GrMSAAPathRenderer: :onStencilPath"); | 748 GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), |
749 "GrMSAAPathRenderer::onStencilPath"); | |
741 SkASSERT(SkPath::kInverseEvenOdd_FillType != args.fPath->getFillType()); | 750 SkASSERT(SkPath::kInverseEvenOdd_FillType != args.fPath->getFillType()); |
742 SkASSERT(SkPath::kInverseWinding_FillType != args.fPath->getFillType()); | 751 SkASSERT(SkPath::kInverseWinding_FillType != args.fPath->getFillType()); |
743 this->internalDrawPath(args.fTarget, args.fPipelineBuilder, *args.fClip, GrC olor_WHITE, | 752 |
744 *args.fViewMatrix, *args.fPath, true); | 753 GrPaint paint; |
754 paint.setXPFactory(GrDisableColorXPFactory::Create()); | |
bungeman-skia
2016/06/03 23:57:03
leak
| |
755 paint.setAntiAlias(args.fIsAA); | |
756 | |
757 this->internalDrawPath(args.fDrawContext, | |
758 paint, | |
759 &GrUserStencilSettings::kUnused, | |
760 *args.fClip, | |
761 GrColor_WHITE, | |
762 *args.fViewMatrix, | |
763 *args.fPath, | |
764 true); | |
745 } | 765 } |
746 | 766 |
747 //////////////////////////////////////////////////////////////////////////////// /////////////////// | 767 //////////////////////////////////////////////////////////////////////////////// /////////////////// |
OLD | NEW |