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" |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 *vert += kLineSegNumVertices; | 637 *vert += kLineSegNumVertices; |
638 } | 638 } |
639 | 639 |
640 } | 640 } |
641 | 641 |
642 /////////////////////////////////////////////////////////////////////////////// | 642 /////////////////////////////////////////////////////////////////////////////// |
643 | 643 |
644 bool GrAAHairLinePathRenderer::createLineGeom(GrDrawTarget* target, | 644 bool GrAAHairLinePathRenderer::createLineGeom(GrDrawTarget* target, |
645 GrDrawState* drawState, | 645 GrDrawState* drawState, |
646 uint8_t coverage, | 646 uint8_t coverage, |
| 647 size_t vertexStride, |
647 GrDrawTarget::AutoReleaseGeometry*
arg, | 648 GrDrawTarget::AutoReleaseGeometry*
arg, |
648 SkRect* devBounds, | 649 SkRect* devBounds, |
649 const SkPath& path, | 650 const SkPath& path, |
650 const PtArray& lines, | 651 const PtArray& lines, |
651 int lineCnt) { | 652 int lineCnt) { |
652 const SkMatrix& viewM = drawState->getViewMatrix(); | 653 const SkMatrix& viewM = drawState->getViewMatrix(); |
653 | 654 |
654 int vertCnt = kLineSegNumVertices * lineCnt; | 655 int vertCnt = kLineSegNumVertices * lineCnt; |
655 | 656 |
656 size_t vstride = drawState->getGeometryProcessor()->getVertexStride(); | 657 SkASSERT(vertexStride == sizeof(LineVertex)); |
657 SkASSERT(vstride == sizeof(LineVertex)); | 658 if (!arg->set(target, vertCnt, vertexStride, 0)) { |
658 if (!arg->set(target, vertCnt, vstride, 0)) { | |
659 return false; | 659 return false; |
660 } | 660 } |
661 | 661 |
662 LineVertex* verts = reinterpret_cast<LineVertex*>(arg->vertices()); | 662 LineVertex* verts = reinterpret_cast<LineVertex*>(arg->vertices()); |
663 | 663 |
664 const SkMatrix* toSrc = NULL; | 664 const SkMatrix* toSrc = NULL; |
665 SkMatrix ivm; | 665 SkMatrix ivm; |
666 | 666 |
667 if (viewM.hasPerspective()) { | 667 if (viewM.hasPerspective()) { |
668 if (viewM.invert(&ivm)) { | 668 if (viewM.invert(&ivm)) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 conicCnt = conics.count() / 3; | 832 conicCnt = conics.count() / 3; |
833 | 833 |
834 // do lines first | 834 // do lines first |
835 if (lineCnt) { | 835 if (lineCnt) { |
836 GrDrawTarget::AutoReleaseGeometry arg; | 836 GrDrawTarget::AutoReleaseGeometry arg; |
837 SkRect devBounds; | 837 SkRect devBounds; |
838 | 838 |
839 uint32_t gpFlags = GrDefaultGeoProcFactory::kPosition_GPType | | 839 uint32_t gpFlags = GrDefaultGeoProcFactory::kPosition_GPType | |
840 GrDefaultGeoProcFactory::kCoverage_GPType; | 840 GrDefaultGeoProcFactory::kCoverage_GPType; |
841 GrDrawState::AutoRestoreEffects are(drawState); | 841 GrDrawState::AutoRestoreEffects are(drawState); |
842 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(color, | 842 SkAutoTUnref<const GrGeometryProcessor> gp(GrDefaultGeoProcFactory::Crea
te(color, |
843 gpFlags, | 843
gpFlags, |
844 newCover
age))->unref(); | 844
newCoverage)); |
845 | 845 |
846 if (!this->createLineGeom(target, | 846 if (!this->createLineGeom(target, |
847 drawState, | 847 drawState, |
848 newCoverage, | 848 newCoverage, |
| 849 gp->getVertexStride(), |
849 &arg, | 850 &arg, |
850 &devBounds, | 851 &devBounds, |
851 path, | 852 path, |
852 lines, | 853 lines, |
853 lineCnt)) { | 854 lineCnt)) { |
854 return false; | 855 return false; |
855 } | 856 } |
856 | 857 |
857 // createLineGeom transforms the geometry to device space when the matri
x does not have | 858 // createLineGeom transforms the geometry to device space when the matri
x does not have |
858 // perspective. | 859 // perspective. |
859 GrDrawState::AutoViewMatrixRestore avmr; | 860 GrDrawState::AutoViewMatrixRestore avmr; |
860 if (!drawState->getViewMatrix().hasPerspective() && !avmr.setIdentity(dr
awState)) { | 861 if (!drawState->getViewMatrix().hasPerspective() && !avmr.setIdentity(dr
awState)) { |
861 return false; | 862 return false; |
862 } | 863 } |
863 | 864 |
864 // Check devBounds | 865 // Check devBounds |
865 SkASSERT(check_bounds<LineVertex>(drawState, devBounds, arg.vertices(), | 866 SkASSERT(check_bounds<LineVertex>(drawState, devBounds, arg.vertices(), |
866 kLineSegNumVertices * lineCnt)); | 867 kLineSegNumVertices * lineCnt)); |
867 | 868 |
868 { | 869 { |
869 target->setIndexSourceToBuffer(fLinesIndexBuffer); | 870 target->setIndexSourceToBuffer(fLinesIndexBuffer); |
870 int lines = 0; | 871 int lines = 0; |
871 while (lines < lineCnt) { | 872 while (lines < lineCnt) { |
872 int n = SkTMin(lineCnt - lines, kLineSegsNumInIdxBuffer); | 873 int n = SkTMin(lineCnt - lines, kLineSegsNumInIdxBuffer); |
873 target->drawIndexed(drawState, | 874 target->drawIndexed(drawState, |
| 875 gp, |
874 kTriangles_GrPrimitiveType, | 876 kTriangles_GrPrimitiveType, |
875 kLineSegNumVertices*lines, // startV | 877 kLineSegNumVertices*lines, // startV |
876 0, // startI | 878 0, // startI |
877 kLineSegNumVertices*n, // vCount | 879 kLineSegNumVertices*n, // vCount |
878 kIdxsPerLineSeg*n, // iCount | 880 kIdxsPerLineSeg*n, // iCount |
879 &devBounds); | 881 &devBounds); |
880 lines += n; | 882 lines += n; |
881 } | 883 } |
882 } | 884 } |
883 } | 885 } |
(...skipping 24 matching lines...) Expand all Loading... |
908 if (!drawState->getViewMatrix().hasPerspective() && !avmr.setIdentity(dr
awState)) { | 910 if (!drawState->getViewMatrix().hasPerspective() && !avmr.setIdentity(dr
awState)) { |
909 return false; | 911 return false; |
910 } | 912 } |
911 | 913 |
912 | 914 |
913 // Check devBounds | 915 // Check devBounds |
914 SkASSERT(check_bounds<BezierVertex>(drawState, devBounds, arg.vertices()
, | 916 SkASSERT(check_bounds<BezierVertex>(drawState, devBounds, arg.vertices()
, |
915 kQuadNumVertices * quadCnt + kQuadNu
mVertices * conicCnt)); | 917 kQuadNumVertices * quadCnt + kQuadNu
mVertices * conicCnt)); |
916 | 918 |
917 if (quadCnt > 0) { | 919 if (quadCnt > 0) { |
918 GrGeometryProcessor* hairQuadProcessor = | 920 SkAutoTUnref<GrGeometryProcessor> hairQuadProcessor( |
919 GrQuadEffect::Create(color, | 921 GrQuadEffect::Create(color, |
920 kHairlineAA_GrProcessorEdgeType, | 922 kHairlineAA_GrProcessorEdgeType, |
921 *target->caps(), | 923 *target->caps(), |
922 newCoverage); | 924 newCoverage)); |
923 SkASSERT(hairQuadProcessor); | 925 SkASSERT(hairQuadProcessor); |
924 GrDrawState::AutoRestoreEffects are(drawState); | 926 GrDrawState::AutoRestoreEffects are(drawState); |
925 target->setIndexSourceToBuffer(fQuadsIndexBuffer); | 927 target->setIndexSourceToBuffer(fQuadsIndexBuffer); |
926 | 928 |
927 drawState->setGeometryProcessor(hairQuadProcessor)->unref(); | |
928 int quads = 0; | 929 int quads = 0; |
929 while (quads < quadCnt) { | 930 while (quads < quadCnt) { |
930 int n = SkTMin(quadCnt - quads, kQuadsNumInIdxBuffer); | 931 int n = SkTMin(quadCnt - quads, kQuadsNumInIdxBuffer); |
931 target->drawIndexed(drawState, | 932 target->drawIndexed(drawState, |
| 933 hairQuadProcessor, |
932 kTriangles_GrPrimitiveType, | 934 kTriangles_GrPrimitiveType, |
933 kQuadNumVertices*quads, // sta
rtV | 935 kQuadNumVertices*quads, // sta
rtV |
934 0, // sta
rtI | 936 0, // sta
rtI |
935 kQuadNumVertices*n, // vCo
unt | 937 kQuadNumVertices*n, // vCo
unt |
936 kIdxsPerQuad*n, // iCo
unt | 938 kIdxsPerQuad*n, // iCo
unt |
937 &devBounds); | 939 &devBounds); |
938 quads += n; | 940 quads += n; |
939 } | 941 } |
940 } | 942 } |
941 | 943 |
942 if (conicCnt > 0) { | 944 if (conicCnt > 0) { |
943 GrDrawState::AutoRestoreEffects are(drawState); | 945 GrDrawState::AutoRestoreEffects are(drawState); |
944 GrGeometryProcessor* hairConicProcessor = GrConicEffect::Create( | 946 SkAutoTUnref<GrGeometryProcessor> hairConicProcessor( |
945 color, kHairlineAA_GrProcessorEdgeType, *target->caps(), new
Coverage); | 947 GrConicEffect::Create(color, kHairlineAA_GrProcessorEdgeType
, *target->caps(), |
| 948 newCoverage)); |
946 SkASSERT(hairConicProcessor); | 949 SkASSERT(hairConicProcessor); |
947 | 950 |
948 drawState->setGeometryProcessor(hairConicProcessor)->unref(); | |
949 int conics = 0; | 951 int conics = 0; |
950 while (conics < conicCnt) { | 952 while (conics < conicCnt) { |
951 int n = SkTMin(conicCnt - conics, kQuadsNumInIdxBuffer); | 953 int n = SkTMin(conicCnt - conics, kQuadsNumInIdxBuffer); |
952 target->drawIndexed(drawState, | 954 target->drawIndexed(drawState, |
| 955 hairConicProcessor, |
953 kTriangles_GrPrimitiveType, | 956 kTriangles_GrPrimitiveType, |
954 kQuadNumVertices*(quadCnt + conics), // sta
rtV | 957 kQuadNumVertices*(quadCnt + conics), // sta
rtV |
955 0, // sta
rtI | 958 0, // sta
rtI |
956 kQuadNumVertices*n, // vCo
unt | 959 kQuadNumVertices*n, // vCo
unt |
957 kIdxsPerQuad*n, // iCo
unt | 960 kIdxsPerQuad*n, // iCo
unt |
958 &devBounds); | 961 &devBounds); |
959 conics += n; | 962 conics += n; |
960 } | 963 } |
961 } | 964 } |
962 } | 965 } |
963 | 966 |
964 target->resetIndexSource(); | 967 target->resetIndexSource(); |
965 | 968 |
966 return true; | 969 return true; |
967 } | 970 } |
OLD | NEW |