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 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 PREALLOC_PTARRAY(128) lines; | 825 PREALLOC_PTARRAY(128) lines; |
826 PREALLOC_PTARRAY(128) quads; | 826 PREALLOC_PTARRAY(128) quads; |
827 PREALLOC_PTARRAY(128) conics; | 827 PREALLOC_PTARRAY(128) conics; |
828 IntArray qSubdivs; | 828 IntArray qSubdivs; |
829 FloatArray cWeights; | 829 FloatArray cWeights; |
830 quadCnt = generate_lines_and_quads(path, drawState->getViewMatrix(), devClip
Bounds, | 830 quadCnt = generate_lines_and_quads(path, drawState->getViewMatrix(), devClip
Bounds, |
831 &lines, &quads, &conics, &qSubdivs, &cWei
ghts); | 831 &lines, &quads, &conics, &qSubdivs, &cWei
ghts); |
832 lineCnt = lines.count() / 2; | 832 lineCnt = lines.count() / 2; |
833 conicCnt = conics.count() / 3; | 833 conicCnt = conics.count() / 3; |
834 | 834 |
| 835 // createGeom transforms the geometry to device space when the matrix does n
ot have |
| 836 // perspective. |
| 837 GrDrawState::AutoViewMatrixRestore avmr; |
| 838 SkMatrix invert = SkMatrix::I(); |
| 839 if (!drawState->getViewMatrix().hasPerspective()) { |
| 840 avmr.setIdentity(drawState); |
| 841 if (!drawState->getViewMatrix().invert(&invert)) { |
| 842 return false; |
| 843 } |
| 844 } |
| 845 |
835 // do lines first | 846 // do lines first |
836 if (lineCnt) { | 847 if (lineCnt) { |
837 GrDrawTarget::AutoReleaseGeometry arg; | 848 GrDrawTarget::AutoReleaseGeometry arg; |
838 SkRect devBounds; | 849 SkRect devBounds; |
839 | 850 |
| 851 GrDrawState::AutoRestoreEffects are(drawState); |
840 uint32_t gpFlags = GrDefaultGeoProcFactory::kPosition_GPType | | 852 uint32_t gpFlags = GrDefaultGeoProcFactory::kPosition_GPType | |
841 GrDefaultGeoProcFactory::kCoverage_GPType; | 853 GrDefaultGeoProcFactory::kCoverage_GPType; |
842 GrDrawState::AutoRestoreEffects are(drawState); | |
843 SkAutoTUnref<const GrGeometryProcessor> gp(GrDefaultGeoProcFactory::Crea
te(color, | 854 SkAutoTUnref<const GrGeometryProcessor> gp(GrDefaultGeoProcFactory::Crea
te(color, |
844
gpFlags, | 855
gpFlags, |
845
false, | 856
false, |
846
newCoverage)); | 857
newCoverage, |
| 858
invert)); |
847 | 859 |
848 if (!this->createLineGeom(target, | 860 if (!this->createLineGeom(target, |
849 drawState, | 861 drawState, |
850 newCoverage, | 862 newCoverage, |
851 gp->getVertexStride(), | 863 gp->getVertexStride(), |
852 &arg, | 864 &arg, |
853 &devBounds, | 865 &devBounds, |
854 path, | 866 path, |
855 lines, | 867 lines, |
856 lineCnt)) { | 868 lineCnt)) { |
857 return false; | 869 return false; |
858 } | 870 } |
859 | 871 |
860 // createLineGeom transforms the geometry to device space when the matri
x does not have | |
861 // perspective. | |
862 GrDrawState::AutoViewMatrixRestore avmr; | |
863 if (!drawState->getViewMatrix().hasPerspective() && !avmr.setIdentity(dr
awState)) { | |
864 return false; | |
865 } | |
866 | |
867 // Check devBounds | 872 // Check devBounds |
868 SkASSERT(check_bounds<LineVertex>(drawState, devBounds, arg.vertices(), | 873 SkASSERT(check_bounds<LineVertex>(drawState, devBounds, arg.vertices(), |
869 kLineSegNumVertices * lineCnt)); | 874 kLineSegNumVertices * lineCnt)); |
870 | 875 |
871 { | 876 { |
872 target->setIndexSourceToBuffer(fLinesIndexBuffer); | 877 target->setIndexSourceToBuffer(fLinesIndexBuffer); |
873 int lines = 0; | 878 int lines = 0; |
874 while (lines < lineCnt) { | 879 while (lines < lineCnt) { |
875 int n = SkTMin(lineCnt - lines, kLineSegsNumInIdxBuffer); | 880 int n = SkTMin(lineCnt - lines, kLineSegsNumInIdxBuffer); |
876 target->drawIndexed(drawState, | 881 target->drawIndexed(drawState, |
(...skipping 22 matching lines...) Expand all Loading... |
899 quads, | 904 quads, |
900 quadCnt, | 905 quadCnt, |
901 conics, | 906 conics, |
902 conicCnt, | 907 conicCnt, |
903 qSubdivs, | 908 qSubdivs, |
904 cWeights, | 909 cWeights, |
905 sizeof(BezierVertex))) { | 910 sizeof(BezierVertex))) { |
906 return false; | 911 return false; |
907 } | 912 } |
908 | 913 |
909 // createGeom transforms the geometry to device space when the matrix do
es not have | |
910 // perspective. | |
911 GrDrawState::AutoViewMatrixRestore avmr; | |
912 if (!drawState->getViewMatrix().hasPerspective() && !avmr.setIdentity(dr
awState)) { | |
913 return false; | |
914 } | |
915 | |
916 | |
917 // Check devBounds | 914 // Check devBounds |
918 SkASSERT(check_bounds<BezierVertex>(drawState, devBounds, arg.vertices()
, | 915 SkASSERT(check_bounds<BezierVertex>(drawState, devBounds, arg.vertices()
, |
919 kQuadNumVertices * quadCnt + kQuadNu
mVertices * conicCnt)); | 916 kQuadNumVertices * quadCnt + kQuadNu
mVertices * conicCnt)); |
920 | 917 |
921 if (quadCnt > 0) { | 918 if (quadCnt > 0) { |
922 SkAutoTUnref<GrGeometryProcessor> hairQuadProcessor( | 919 SkAutoTUnref<GrGeometryProcessor> hairQuadProcessor( |
923 GrQuadEffect::Create(color, | 920 GrQuadEffect::Create(color, |
924 kHairlineAA_GrProcessorEdgeType, | 921 kHairlineAA_GrProcessorEdgeType, |
925 *target->caps(), | 922 *target->caps(), |
| 923 invert, |
926 newCoverage)); | 924 newCoverage)); |
927 SkASSERT(hairQuadProcessor); | 925 SkASSERT(hairQuadProcessor); |
928 GrDrawState::AutoRestoreEffects are(drawState); | 926 GrDrawState::AutoRestoreEffects are(drawState); |
929 target->setIndexSourceToBuffer(fQuadsIndexBuffer); | 927 target->setIndexSourceToBuffer(fQuadsIndexBuffer); |
930 | 928 |
931 int quads = 0; | 929 int quads = 0; |
932 while (quads < quadCnt) { | 930 while (quads < quadCnt) { |
933 int n = SkTMin(quadCnt - quads, kQuadsNumInIdxBuffer); | 931 int n = SkTMin(quadCnt - quads, kQuadsNumInIdxBuffer); |
934 target->drawIndexed(drawState, | 932 target->drawIndexed(drawState, |
935 hairQuadProcessor, | 933 hairQuadProcessor, |
936 kTriangles_GrPrimitiveType, | 934 kTriangles_GrPrimitiveType, |
937 kQuadNumVertices*quads, // sta
rtV | 935 kQuadNumVertices*quads, // sta
rtV |
938 0, // sta
rtI | 936 0, // sta
rtI |
939 kQuadNumVertices*n, // vCo
unt | 937 kQuadNumVertices*n, // vCo
unt |
940 kIdxsPerQuad*n, // iCo
unt | 938 kIdxsPerQuad*n, // iCo
unt |
941 &devBounds); | 939 &devBounds); |
942 quads += n; | 940 quads += n; |
943 } | 941 } |
944 } | 942 } |
945 | 943 |
946 if (conicCnt > 0) { | 944 if (conicCnt > 0) { |
947 SkAutoTUnref<GrGeometryProcessor> hairConicProcessor( | 945 SkAutoTUnref<GrGeometryProcessor> hairConicProcessor( |
948 GrConicEffect::Create(color, kHairlineAA_GrProcessorEdgeType
, *target->caps(), | 946 GrConicEffect::Create(color, kHairlineAA_GrProcessorEdgeType
, *target->caps(), |
949 newCoverage)); | 947 invert, newCoverage)); |
950 SkASSERT(hairConicProcessor); | 948 SkASSERT(hairConicProcessor); |
951 GrDrawState::AutoRestoreEffects are(drawState); | 949 GrDrawState::AutoRestoreEffects are(drawState); |
952 target->setIndexSourceToBuffer(fQuadsIndexBuffer); | 950 target->setIndexSourceToBuffer(fQuadsIndexBuffer); |
953 | 951 |
954 int conics = 0; | 952 int conics = 0; |
955 while (conics < conicCnt) { | 953 while (conics < conicCnt) { |
956 int n = SkTMin(conicCnt - conics, kQuadsNumInIdxBuffer); | 954 int n = SkTMin(conicCnt - conics, kQuadsNumInIdxBuffer); |
957 target->drawIndexed(drawState, | 955 target->drawIndexed(drawState, |
958 hairConicProcessor, | 956 hairConicProcessor, |
959 kTriangles_GrPrimitiveType, | 957 kTriangles_GrPrimitiveType, |
960 kQuadNumVertices*(quadCnt + conics), // sta
rtV | 958 kQuadNumVertices*(quadCnt + conics), // sta
rtV |
961 0, // sta
rtI | 959 0, // sta
rtI |
962 kQuadNumVertices*n, // vCo
unt | 960 kQuadNumVertices*n, // vCo
unt |
963 kIdxsPerQuad*n, // iCo
unt | 961 kIdxsPerQuad*n, // iCo
unt |
964 &devBounds); | 962 &devBounds); |
965 conics += n; | 963 conics += n; |
966 } | 964 } |
967 } | 965 } |
968 } | 966 } |
969 | 967 |
970 target->resetIndexSource(); | 968 target->resetIndexSource(); |
971 | 969 |
972 return true; | 970 return true; |
973 } | 971 } |
OLD | NEW |