OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrAAHairLinePathRenderer.h" | 8 #include "GrAAHairLinePathRenderer.h" |
9 | 9 |
10 #include "GrContext.h" | 10 #include "GrContext.h" |
11 #include "GrDefaultGeoProcFactory.h" | 11 #include "GrDefaultGeoProcFactory.h" |
12 #include "GrDrawState.h" | |
13 #include "GrDrawTargetCaps.h" | 12 #include "GrDrawTargetCaps.h" |
14 #include "GrGpu.h" | 13 #include "GrGpu.h" |
15 #include "GrIndexBuffer.h" | 14 #include "GrIndexBuffer.h" |
16 #include "GrPathUtils.h" | 15 #include "GrPathUtils.h" |
| 16 #include "GrPipelineBuilder.h" |
17 #include "GrProcessor.h" | 17 #include "GrProcessor.h" |
18 #include "SkGeometry.h" | 18 #include "SkGeometry.h" |
19 #include "SkStroke.h" | 19 #include "SkStroke.h" |
20 #include "SkTemplates.h" | 20 #include "SkTemplates.h" |
21 | 21 |
22 #include "effects/GrBezierEffect.h" | 22 #include "effects/GrBezierEffect.h" |
23 | 23 |
24 // quadratics are rendered as 5-sided polys in order to bound the | 24 // quadratics are rendered as 5-sided polys in order to bound the |
25 // AA stroke around the center-curve. See comments in push_quad_index_buffer and | 25 // AA stroke around the center-curve. See comments in push_quad_index_buffer and |
26 // bloat_quad. Quadratics and conics share an index buffer | 26 // bloat_quad. Quadratics and conics share an index buffer |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 } | 636 } |
637 | 637 |
638 *vert += kLineSegNumVertices; | 638 *vert += kLineSegNumVertices; |
639 } | 639 } |
640 | 640 |
641 } | 641 } |
642 | 642 |
643 /////////////////////////////////////////////////////////////////////////////// | 643 /////////////////////////////////////////////////////////////////////////////// |
644 | 644 |
645 bool GrAAHairLinePathRenderer::createLineGeom(GrDrawTarget* target, | 645 bool GrAAHairLinePathRenderer::createLineGeom(GrDrawTarget* target, |
646 GrDrawState* drawState, | 646 GrPipelineBuilder* pipelineBuilder
, |
647 const SkMatrix& viewMatrix, | 647 const SkMatrix& viewMatrix, |
648 uint8_t coverage, | 648 uint8_t coverage, |
649 size_t vertexStride, | 649 size_t vertexStride, |
650 GrDrawTarget::AutoReleaseGeometry*
arg, | 650 GrDrawTarget::AutoReleaseGeometry*
arg, |
651 SkRect* devBounds, | 651 SkRect* devBounds, |
652 const SkPath& path, | 652 const SkPath& path, |
653 const PtArray& lines, | 653 const PtArray& lines, |
654 int lineCnt) { | 654 int lineCnt) { |
655 int vertCnt = kLineSegNumVertices * lineCnt; | 655 int vertCnt = kLineSegNumVertices * lineCnt; |
656 | 656 |
(...skipping 19 matching lines...) Expand all Loading... |
676 // All the verts computed by add_line are within sqrt(1^2 + 0.5^2) of the en
d points. | 676 // All the verts computed by add_line are within sqrt(1^2 + 0.5^2) of the en
d points. |
677 static const SkScalar kSqrtOfOneAndAQuarter = 1.118f; | 677 static const SkScalar kSqrtOfOneAndAQuarter = 1.118f; |
678 // Add a little extra to account for vector normalization precision. | 678 // Add a little extra to account for vector normalization precision. |
679 static const SkScalar kOutset = kSqrtOfOneAndAQuarter + SK_Scalar1 / 20; | 679 static const SkScalar kOutset = kSqrtOfOneAndAQuarter + SK_Scalar1 / 20; |
680 devBounds->outset(kOutset, kOutset); | 680 devBounds->outset(kOutset, kOutset); |
681 | 681 |
682 return true; | 682 return true; |
683 } | 683 } |
684 | 684 |
685 bool GrAAHairLinePathRenderer::createBezierGeom(GrDrawTarget* target, | 685 bool GrAAHairLinePathRenderer::createBezierGeom(GrDrawTarget* target, |
686 GrDrawState* drawState, | 686 GrPipelineBuilder* pipelineBuild
er, |
687 const SkMatrix& viewMatrix, | 687 const SkMatrix& viewMatrix, |
688 GrDrawTarget::AutoReleaseGeometr
y* arg, | 688 GrDrawTarget::AutoReleaseGeometr
y* arg, |
689 SkRect* devBounds, | 689 SkRect* devBounds, |
690 const SkPath& path, | 690 const SkPath& path, |
691 const PtArray& quads, | 691 const PtArray& quads, |
692 int quadCnt, | 692 int quadCnt, |
693 const PtArray& conics, | 693 const PtArray& conics, |
694 int conicCnt, | 694 int conicCnt, |
695 const IntArray& qSubdivs, | 695 const IntArray& qSubdivs, |
696 const FloatArray& cWeights, | 696 const FloatArray& cWeights, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 } | 736 } |
737 | 737 |
738 // Start Conics | 738 // Start Conics |
739 for (int i = 0; i < conicCnt; ++i) { | 739 for (int i = 0; i < conicCnt; ++i) { |
740 add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &verts, devBounds
); | 740 add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &verts, devBounds
); |
741 } | 741 } |
742 return true; | 742 return true; |
743 } | 743 } |
744 | 744 |
745 bool GrAAHairLinePathRenderer::canDrawPath(const GrDrawTarget* target, | 745 bool GrAAHairLinePathRenderer::canDrawPath(const GrDrawTarget* target, |
746 const GrDrawState* drawState, | 746 const GrPipelineBuilder* pipelineBuil
der, |
747 const SkMatrix& viewMatrix, | 747 const SkMatrix& viewMatrix, |
748 const SkPath& path, | 748 const SkPath& path, |
749 const SkStrokeRec& stroke, | 749 const SkStrokeRec& stroke, |
750 bool antiAlias) const { | 750 bool antiAlias) const { |
751 if (!antiAlias) { | 751 if (!antiAlias) { |
752 return false; | 752 return false; |
753 } | 753 } |
754 | 754 |
755 if (!IsStrokeHairlineOrEquivalent(stroke, viewMatrix, NULL)) { | 755 if (!IsStrokeHairlineOrEquivalent(stroke, viewMatrix, NULL)) { |
756 return false; | 756 return false; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 } | 794 } |
795 } | 795 } |
796 if (!first) { | 796 if (!first) { |
797 return tolDevBounds.contains(actualBounds); | 797 return tolDevBounds.contains(actualBounds); |
798 } | 798 } |
799 | 799 |
800 return true; | 800 return true; |
801 } | 801 } |
802 | 802 |
803 bool GrAAHairLinePathRenderer::onDrawPath(GrDrawTarget* target, | 803 bool GrAAHairLinePathRenderer::onDrawPath(GrDrawTarget* target, |
804 GrDrawState* drawState, | 804 GrPipelineBuilder* pipelineBuilder, |
805 GrColor color, | 805 GrColor color, |
806 const SkMatrix& viewMatrix, | 806 const SkMatrix& viewMatrix, |
807 const SkPath& path, | 807 const SkPath& path, |
808 const SkStrokeRec& stroke, | 808 const SkStrokeRec& stroke, |
809 bool antiAlias) { | 809 bool antiAlias) { |
810 SkScalar hairlineCoverage; | 810 SkScalar hairlineCoverage; |
811 uint8_t newCoverage = 0xff; | 811 uint8_t newCoverage = 0xff; |
812 if (IsStrokeHairlineOrEquivalent(stroke, viewMatrix, &hairlineCoverage)) { | 812 if (IsStrokeHairlineOrEquivalent(stroke, viewMatrix, &hairlineCoverage)) { |
813 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); | 813 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); |
814 } | 814 } |
815 | 815 |
816 SkIRect devClipBounds; | 816 SkIRect devClipBounds; |
817 target->getClip()->getConservativeBounds(drawState->getRenderTarget(), &devC
lipBounds); | 817 target->getClip()->getConservativeBounds(pipelineBuilder->getRenderTarget(),
&devClipBounds); |
818 | 818 |
819 int lineCnt; | 819 int lineCnt; |
820 int quadCnt; | 820 int quadCnt; |
821 int conicCnt; | 821 int conicCnt; |
822 PREALLOC_PTARRAY(128) lines; | 822 PREALLOC_PTARRAY(128) lines; |
823 PREALLOC_PTARRAY(128) quads; | 823 PREALLOC_PTARRAY(128) quads; |
824 PREALLOC_PTARRAY(128) conics; | 824 PREALLOC_PTARRAY(128) conics; |
825 IntArray qSubdivs; | 825 IntArray qSubdivs; |
826 FloatArray cWeights; | 826 FloatArray cWeights; |
827 quadCnt = generate_lines_and_quads(path, viewMatrix, devClipBounds, | 827 quadCnt = generate_lines_and_quads(path, viewMatrix, devClipBounds, |
(...skipping 10 matching lines...) Expand all Loading... |
838 if (!viewMatrix.invert(&invert)) { | 838 if (!viewMatrix.invert(&invert)) { |
839 return false; | 839 return false; |
840 } | 840 } |
841 } | 841 } |
842 | 842 |
843 // do lines first | 843 // do lines first |
844 if (lineCnt) { | 844 if (lineCnt) { |
845 GrDrawTarget::AutoReleaseGeometry arg; | 845 GrDrawTarget::AutoReleaseGeometry arg; |
846 SkRect devBounds; | 846 SkRect devBounds; |
847 | 847 |
848 GrDrawState::AutoRestoreEffects are(drawState); | 848 GrPipelineBuilder::AutoRestoreEffects are(pipelineBuilder); |
849 uint32_t gpFlags = GrDefaultGeoProcFactory::kPosition_GPType | | 849 uint32_t gpFlags = GrDefaultGeoProcFactory::kPosition_GPType | |
850 GrDefaultGeoProcFactory::kCoverage_GPType; | 850 GrDefaultGeoProcFactory::kCoverage_GPType; |
851 SkAutoTUnref<const GrGeometryProcessor> gp(GrDefaultGeoProcFactory::Crea
te(gpFlags, | 851 SkAutoTUnref<const GrGeometryProcessor> gp(GrDefaultGeoProcFactory::Crea
te(gpFlags, |
852
color, | 852
color, |
853
vm, | 853
vm, |
854
invert, | 854
invert, |
855
false, | 855
false, |
856
newCoverage)); | 856
newCoverage)); |
857 | 857 |
858 if (!this->createLineGeom(target, | 858 if (!this->createLineGeom(target, |
859 drawState, | 859 pipelineBuilder, |
860 viewMatrix, | 860 viewMatrix, |
861 newCoverage, | 861 newCoverage, |
862 gp->getVertexStride(), | 862 gp->getVertexStride(), |
863 &arg, | 863 &arg, |
864 &devBounds, | 864 &devBounds, |
865 path, | 865 path, |
866 lines, | 866 lines, |
867 lineCnt)) { | 867 lineCnt)) { |
868 return false; | 868 return false; |
869 } | 869 } |
870 | 870 |
871 // Check devBounds | 871 // Check devBounds |
872 SkASSERT(check_bounds<LineVertex>(viewMatrix.hasPerspective() ? viewMatr
ix : SkMatrix::I(), | 872 SkASSERT(check_bounds<LineVertex>(viewMatrix.hasPerspective() ? viewMatr
ix : SkMatrix::I(), |
873 devBounds, | 873 devBounds, |
874 arg.vertices(), | 874 arg.vertices(), |
875 kLineSegNumVertices * lineCnt)); | 875 kLineSegNumVertices * lineCnt)); |
876 | 876 |
877 { | 877 { |
878 target->setIndexSourceToBuffer(fLinesIndexBuffer); | 878 target->setIndexSourceToBuffer(fLinesIndexBuffer); |
879 int lines = 0; | 879 int lines = 0; |
880 while (lines < lineCnt) { | 880 while (lines < lineCnt) { |
881 int n = SkTMin(lineCnt - lines, kLineSegsNumInIdxBuffer); | 881 int n = SkTMin(lineCnt - lines, kLineSegsNumInIdxBuffer); |
882 target->drawIndexed(drawState, | 882 target->drawIndexed(pipelineBuilder, |
883 gp, | 883 gp, |
884 kTriangles_GrPrimitiveType, | 884 kTriangles_GrPrimitiveType, |
885 kLineSegNumVertices*lines, // startV | 885 kLineSegNumVertices*lines, // startV |
886 0, // startI | 886 0, // startI |
887 kLineSegNumVertices*n, // vCount | 887 kLineSegNumVertices*n, // vCount |
888 kIdxsPerLineSeg*n, // iCount | 888 kIdxsPerLineSeg*n, // iCount |
889 &devBounds); | 889 &devBounds); |
890 lines += n; | 890 lines += n; |
891 } | 891 } |
892 } | 892 } |
893 } | 893 } |
894 | 894 |
895 // then quadratics/conics | 895 // then quadratics/conics |
896 if (quadCnt || conicCnt) { | 896 if (quadCnt || conicCnt) { |
897 GrDrawTarget::AutoReleaseGeometry arg; | 897 GrDrawTarget::AutoReleaseGeometry arg; |
898 SkRect devBounds; | 898 SkRect devBounds; |
899 | 899 |
900 if (!this->createBezierGeom(target, | 900 if (!this->createBezierGeom(target, |
901 drawState, | 901 pipelineBuilder, |
902 viewMatrix, | 902 viewMatrix, |
903 &arg, | 903 &arg, |
904 &devBounds, | 904 &devBounds, |
905 path, | 905 path, |
906 quads, | 906 quads, |
907 quadCnt, | 907 quadCnt, |
908 conics, | 908 conics, |
909 conicCnt, | 909 conicCnt, |
910 qSubdivs, | 910 qSubdivs, |
911 cWeights, | 911 cWeights, |
(...skipping 11 matching lines...) Expand all Loading... |
923 | 923 |
924 if (quadCnt > 0) { | 924 if (quadCnt > 0) { |
925 SkAutoTUnref<GrGeometryProcessor> hairQuadProcessor( | 925 SkAutoTUnref<GrGeometryProcessor> hairQuadProcessor( |
926 GrQuadEffect::Create(color, | 926 GrQuadEffect::Create(color, |
927 vm, | 927 vm, |
928 kHairlineAA_GrProcessorEdgeType, | 928 kHairlineAA_GrProcessorEdgeType, |
929 *target->caps(), | 929 *target->caps(), |
930 invert, | 930 invert, |
931 newCoverage)); | 931 newCoverage)); |
932 SkASSERT(hairQuadProcessor); | 932 SkASSERT(hairQuadProcessor); |
933 GrDrawState::AutoRestoreEffects are(drawState); | 933 GrPipelineBuilder::AutoRestoreEffects are(pipelineBuilder); |
934 target->setIndexSourceToBuffer(fQuadsIndexBuffer); | 934 target->setIndexSourceToBuffer(fQuadsIndexBuffer); |
935 | 935 |
936 int quads = 0; | 936 int quads = 0; |
937 while (quads < quadCnt) { | 937 while (quads < quadCnt) { |
938 int n = SkTMin(quadCnt - quads, kQuadsNumInIdxBuffer); | 938 int n = SkTMin(quadCnt - quads, kQuadsNumInIdxBuffer); |
939 target->drawIndexed(drawState, | 939 target->drawIndexed(pipelineBuilder, |
940 hairQuadProcessor, | 940 hairQuadProcessor, |
941 kTriangles_GrPrimitiveType, | 941 kTriangles_GrPrimitiveType, |
942 kQuadNumVertices*quads, // sta
rtV | 942 kQuadNumVertices*quads, // sta
rtV |
943 0, // sta
rtI | 943 0, // sta
rtI |
944 kQuadNumVertices*n, // vCo
unt | 944 kQuadNumVertices*n, // vCo
unt |
945 kIdxsPerQuad*n, // iCo
unt | 945 kIdxsPerQuad*n, // iCo
unt |
946 &devBounds); | 946 &devBounds); |
947 quads += n; | 947 quads += n; |
948 } | 948 } |
949 } | 949 } |
950 | 950 |
951 if (conicCnt > 0) { | 951 if (conicCnt > 0) { |
952 SkAutoTUnref<GrGeometryProcessor> hairConicProcessor( | 952 SkAutoTUnref<GrGeometryProcessor> hairConicProcessor( |
953 GrConicEffect::Create(color, vm, kHairlineAA_GrProcessorEdge
Type, | 953 GrConicEffect::Create(color, vm, kHairlineAA_GrProcessorEdge
Type, |
954 *target->caps(), invert, newCoverage))
; | 954 *target->caps(), invert, newCoverage))
; |
955 SkASSERT(hairConicProcessor); | 955 SkASSERT(hairConicProcessor); |
956 GrDrawState::AutoRestoreEffects are(drawState); | 956 GrPipelineBuilder::AutoRestoreEffects are(pipelineBuilder); |
957 target->setIndexSourceToBuffer(fQuadsIndexBuffer); | 957 target->setIndexSourceToBuffer(fQuadsIndexBuffer); |
958 | 958 |
959 int conics = 0; | 959 int conics = 0; |
960 while (conics < conicCnt) { | 960 while (conics < conicCnt) { |
961 int n = SkTMin(conicCnt - conics, kQuadsNumInIdxBuffer); | 961 int n = SkTMin(conicCnt - conics, kQuadsNumInIdxBuffer); |
962 target->drawIndexed(drawState, | 962 target->drawIndexed(pipelineBuilder, |
963 hairConicProcessor, | 963 hairConicProcessor, |
964 kTriangles_GrPrimitiveType, | 964 kTriangles_GrPrimitiveType, |
965 kQuadNumVertices*(quadCnt + conics), // sta
rtV | 965 kQuadNumVertices*(quadCnt + conics), // sta
rtV |
966 0, // sta
rtI | 966 0, // sta
rtI |
967 kQuadNumVertices*n, // vCo
unt | 967 kQuadNumVertices*n, // vCo
unt |
968 kIdxsPerQuad*n, // iCo
unt | 968 kIdxsPerQuad*n, // iCo
unt |
969 &devBounds); | 969 &devBounds); |
970 conics += n; | 970 conics += n; |
971 } | 971 } |
972 } | 972 } |
973 } | 973 } |
974 | 974 |
975 target->resetIndexSource(); | 975 target->resetIndexSource(); |
976 | 976 |
977 return true; | 977 return true; |
978 } | 978 } |
OLD | NEW |