Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: src/gpu/GrAAHairLinePathRenderer.cpp

Issue 761563002: First step to moving vertex attributes to the geometryProcessor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more cleanup Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 } 635 }
636 } 636 }
637 637
638 *vert += kLineSegNumVertices; 638 *vert += kLineSegNumVertices;
639 } 639 }
640 640
641 } 641 }
642 642
643 /////////////////////////////////////////////////////////////////////////////// 643 ///////////////////////////////////////////////////////////////////////////////
644 644
645 namespace {
646 // position + edge
647 extern const GrVertexAttrib gHairlineBezierAttribs[] = {
648 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind ing},
649 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexA ttribBinding}
650 };
651 };
652
653 bool GrAAHairLinePathRenderer::createLineGeom(GrDrawTarget* target, 645 bool GrAAHairLinePathRenderer::createLineGeom(GrDrawTarget* target,
654 GrDrawState* drawState, 646 GrDrawState* drawState,
655 GrDrawTarget::AutoReleaseGeometry* arg, 647 GrDrawTarget::AutoReleaseGeometry* arg,
656 SkRect* devBounds, 648 SkRect* devBounds,
657 const SkPath& path, 649 const SkPath& path,
658 const PtArray& lines, 650 const PtArray& lines,
659 int lineCnt) { 651 int lineCnt) {
660 const SkMatrix& viewM = drawState->getViewMatrix(); 652 const SkMatrix& viewM = drawState->getViewMatrix();
661 653
662 int vertCnt = kLineSegNumVertices * lineCnt; 654 int vertCnt = kLineSegNumVertices * lineCnt;
663 655
664 GrDefaultGeoProcFactory::SetAttribs(drawState, GrDefaultGeoProcFactory::kPos ition_GPType | 656 size_t vstride = drawState->getGeometryProcessor()->getVertexStride();
665 GrDefaultGeoProcFactory::kCov erage_GPType); 657 if (!arg->set(target, vertCnt, vstride, 0)) {
666
667 if (!arg->set(target, vertCnt, drawState->getVertexStride(), 0)) {
668 return false; 658 return false;
669 } 659 }
670 660
671 LineVertex* verts = reinterpret_cast<LineVertex*>(arg->vertices()); 661 LineVertex* verts = reinterpret_cast<LineVertex*>(arg->vertices());
672 662
673 const SkMatrix* toSrc = NULL; 663 const SkMatrix* toSrc = NULL;
674 SkMatrix ivm; 664 SkMatrix ivm;
675 665
676 if (viewM.hasPerspective()) { 666 if (viewM.hasPerspective()) {
677 if (viewM.invert(&ivm)) { 667 if (viewM.invert(&ivm)) {
(...skipping 16 matching lines...) Expand all
694 bool GrAAHairLinePathRenderer::createBezierGeom(GrDrawTarget* target, 684 bool GrAAHairLinePathRenderer::createBezierGeom(GrDrawTarget* target,
695 GrDrawState* drawState, 685 GrDrawState* drawState,
696 GrDrawTarget::AutoReleaseGeometr y* arg, 686 GrDrawTarget::AutoReleaseGeometr y* arg,
697 SkRect* devBounds, 687 SkRect* devBounds,
698 const SkPath& path, 688 const SkPath& path,
699 const PtArray& quads, 689 const PtArray& quads,
700 int quadCnt, 690 int quadCnt,
701 const PtArray& conics, 691 const PtArray& conics,
702 int conicCnt, 692 int conicCnt,
703 const IntArray& qSubdivs, 693 const IntArray& qSubdivs,
704 const FloatArray& cWeights) { 694 const FloatArray& cWeights,
695 size_t vertexStride) {
705 const SkMatrix& viewM = drawState->getViewMatrix(); 696 const SkMatrix& viewM = drawState->getViewMatrix();
706 697
707 int vertCnt = kQuadNumVertices * quadCnt + kQuadNumVertices * conicCnt; 698 int vertCnt = kQuadNumVertices * quadCnt + kQuadNumVertices * conicCnt;
708 699
709 int vAttribCnt = SK_ARRAY_COUNT(gHairlineBezierAttribs); 700 if (!arg->set(target, vertCnt, vertexStride, 0)) {
710 drawState->setVertexAttribs<gHairlineBezierAttribs>(vAttribCnt, sizeof(Bezie rVertex));
711
712 if (!arg->set(target, vertCnt, drawState->getVertexStride(), 0)) {
713 return false; 701 return false;
714 } 702 }
715 703
716 BezierVertex* verts = reinterpret_cast<BezierVertex*>(arg->vertices()); 704 BezierVertex* verts = reinterpret_cast<BezierVertex*>(arg->vertices());
717 705
718 const SkMatrix* toDevice = NULL; 706 const SkMatrix* toDevice = NULL;
719 const SkMatrix* toSrc = NULL; 707 const SkMatrix* toSrc = NULL;
720 SkMatrix ivm; 708 SkMatrix ivm;
721 709
722 if (viewM.hasPerspective()) { 710 if (viewM.hasPerspective()) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 quadCnt = generate_lines_and_quads(path, drawState->getViewMatrix(), devClip Bounds, 827 quadCnt = generate_lines_and_quads(path, drawState->getViewMatrix(), devClip Bounds,
840 &lines, &quads, &conics, &qSubdivs, &cWei ghts); 828 &lines, &quads, &conics, &qSubdivs, &cWei ghts);
841 lineCnt = lines.count() / 2; 829 lineCnt = lines.count() / 2;
842 conicCnt = conics.count() / 3; 830 conicCnt = conics.count() / 3;
843 831
844 // do lines first 832 // do lines first
845 if (lineCnt) { 833 if (lineCnt) {
846 GrDrawTarget::AutoReleaseGeometry arg; 834 GrDrawTarget::AutoReleaseGeometry arg;
847 SkRect devBounds; 835 SkRect devBounds;
848 836
837 uint32_t gpFlags = GrDefaultGeoProcFactory::kPosition_GPType |
838 GrDefaultGeoProcFactory::kCoverage_GPType;
839 GrDrawState::AutoRestoreEffects are(drawState);
840 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(gpFlags) )->unref();
841
849 if (!this->createLineGeom(target, 842 if (!this->createLineGeom(target,
850 drawState, 843 drawState,
851 &arg, 844 &arg,
852 &devBounds, 845 &devBounds,
853 path, 846 path,
854 lines, 847 lines,
855 lineCnt)) { 848 lineCnt)) {
856 return false; 849 return false;
857 } 850 }
858 851
859 // createLineGeom transforms the geometry to device space when the matri x does not have 852 // createLineGeom transforms the geometry to device space when the matri x does not have
860 // perspective. 853 // perspective.
861 GrDrawState::AutoViewMatrixRestore avmr; 854 GrDrawState::AutoViewMatrixRestore avmr;
862 if (!drawState->getViewMatrix().hasPerspective() && !avmr.setIdentity(dr awState)) { 855 if (!drawState->getViewMatrix().hasPerspective() && !avmr.setIdentity(dr awState)) {
863 return false; 856 return false;
864 } 857 }
865 858
866 // Check devBounds 859 // Check devBounds
867 SkASSERT(check_bounds<LineVertex>(drawState, devBounds, arg.vertices(), 860 SkASSERT(check_bounds<LineVertex>(drawState, devBounds, arg.vertices(),
868 kLineSegNumVertices * lineCnt)); 861 kLineSegNumVertices * lineCnt));
869 862
870 { 863 {
871 GrDrawState::AutoRestoreEffects are(drawState);
872 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(fals e))->unref();
873 target->setIndexSourceToBuffer(fLinesIndexBuffer); 864 target->setIndexSourceToBuffer(fLinesIndexBuffer);
874 int lines = 0; 865 int lines = 0;
875 while (lines < lineCnt) { 866 while (lines < lineCnt) {
876 int n = SkTMin(lineCnt - lines, kLineSegsNumInIdxBuffer); 867 int n = SkTMin(lineCnt - lines, kLineSegsNumInIdxBuffer);
877 target->drawIndexed(drawState, 868 target->drawIndexed(drawState,
878 kTriangles_GrPrimitiveType, 869 kTriangles_GrPrimitiveType,
879 kLineSegNumVertices*lines, // startV 870 kLineSegNumVertices*lines, // startV
880 0, // startI 871 0, // startI
881 kLineSegNumVertices*n, // vCount 872 kLineSegNumVertices*n, // vCount
882 kIdxsPerLineSeg*n, // iCount 873 kIdxsPerLineSeg*n, // iCount
(...skipping 11 matching lines...) Expand all
894 if (!this->createBezierGeom(target, 885 if (!this->createBezierGeom(target,
895 drawState, 886 drawState,
896 &arg, 887 &arg,
897 &devBounds, 888 &devBounds,
898 path, 889 path,
899 quads, 890 quads,
900 quadCnt, 891 quadCnt,
901 conics, 892 conics,
902 conicCnt, 893 conicCnt,
903 qSubdivs, 894 qSubdivs,
904 cWeights)) { 895 cWeights,
896 sizeof(BezierVertex))) {
905 return false; 897 return false;
906 } 898 }
907 899
908 // createGeom transforms the geometry to device space when the matrix do es not have 900 // createGeom transforms the geometry to device space when the matrix do es not have
909 // perspective. 901 // perspective.
910 GrDrawState::AutoViewMatrixRestore avmr; 902 GrDrawState::AutoViewMatrixRestore avmr;
911 if (!drawState->getViewMatrix().hasPerspective() && !avmr.setIdentity(dr awState)) { 903 if (!drawState->getViewMatrix().hasPerspective() && !avmr.setIdentity(dr awState)) {
912 return false; 904 return false;
913 } 905 }
914 906
915 907
916 // Check devBounds 908 // Check devBounds
917 SkASSERT(check_bounds<BezierVertex>(drawState, devBounds, arg.vertices() , 909 SkASSERT(check_bounds<BezierVertex>(drawState, devBounds, arg.vertices() ,
918 kQuadNumVertices * quadCnt + kQuadNu mVertices * conicCnt)); 910 kQuadNumVertices * quadCnt + kQuadNu mVertices * conicCnt));
919 911
920 if (quadCnt > 0) { 912 if (quadCnt > 0) {
921 GrGeometryProcessor* hairQuadProcessor = 913 GrGeometryProcessor* hairQuadProcessor =
922 GrQuadEffect::Create(kHairlineAA_GrProcessorEdgeType, *targe t->caps()); 914 GrQuadEffect::Create(kHairlineAA_GrProcessorEdgeType, *targe t->caps());
923 SkASSERT(hairQuadProcessor); 915 SkASSERT(hairQuadProcessor);
924 GrDrawState::AutoRestoreEffects are(drawState); 916 GrDrawState::AutoRestoreEffects are(drawState);
925 target->setIndexSourceToBuffer(fQuadsIndexBuffer); 917 target->setIndexSourceToBuffer(fQuadsIndexBuffer);
918
926 drawState->setGeometryProcessor(hairQuadProcessor)->unref(); 919 drawState->setGeometryProcessor(hairQuadProcessor)->unref();
927 int quads = 0; 920 int quads = 0;
928 while (quads < quadCnt) { 921 while (quads < quadCnt) {
929 int n = SkTMin(quadCnt - quads, kQuadsNumInIdxBuffer); 922 int n = SkTMin(quadCnt - quads, kQuadsNumInIdxBuffer);
930 target->drawIndexed(drawState, 923 target->drawIndexed(drawState,
931 kTriangles_GrPrimitiveType, 924 kTriangles_GrPrimitiveType,
932 kQuadNumVertices*quads, // sta rtV 925 kQuadNumVertices*quads, // sta rtV
933 0, // sta rtI 926 0, // sta rtI
934 kQuadNumVertices*n, // vCo unt 927 kQuadNumVertices*n, // vCo unt
935 kIdxsPerQuad*n, // iCo unt 928 kIdxsPerQuad*n, // iCo unt
936 &devBounds); 929 &devBounds);
937 quads += n; 930 quads += n;
938 } 931 }
939 } 932 }
940 933
941 if (conicCnt > 0) { 934 if (conicCnt > 0) {
942 GrDrawState::AutoRestoreEffects are(drawState); 935 GrDrawState::AutoRestoreEffects are(drawState);
943 GrGeometryProcessor* hairConicProcessor = GrConicEffect::Create( 936 GrGeometryProcessor* hairConicProcessor = GrConicEffect::Create(
944 kHairlineAA_GrProcessorEdgeType, *target->caps()); 937 kHairlineAA_GrProcessorEdgeType, *target->caps());
945 SkASSERT(hairConicProcessor); 938 SkASSERT(hairConicProcessor);
939
946 drawState->setGeometryProcessor(hairConicProcessor)->unref(); 940 drawState->setGeometryProcessor(hairConicProcessor)->unref();
947 int conics = 0; 941 int conics = 0;
948 while (conics < conicCnt) { 942 while (conics < conicCnt) {
949 int n = SkTMin(conicCnt - conics, kQuadsNumInIdxBuffer); 943 int n = SkTMin(conicCnt - conics, kQuadsNumInIdxBuffer);
950 target->drawIndexed(drawState, 944 target->drawIndexed(drawState,
951 kTriangles_GrPrimitiveType, 945 kTriangles_GrPrimitiveType,
952 kQuadNumVertices*(quadCnt + conics), // sta rtV 946 kQuadNumVertices*(quadCnt + conics), // sta rtV
953 0, // sta rtI 947 0, // sta rtI
954 kQuadNumVertices*n, // vCo unt 948 kQuadNumVertices*n, // vCo unt
955 kIdxsPerQuad*n, // iCo unt 949 kIdxsPerQuad*n, // iCo unt
956 &devBounds); 950 &devBounds);
957 conics += n; 951 conics += n;
958 } 952 }
959 } 953 }
960 } 954 }
961 955
962 target->resetIndexSource(); 956 target->resetIndexSource();
963 957
964 return true; 958 return true;
965 } 959 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698