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