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