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

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: adding test to ignore 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
« no previous file with comments | « src/gpu/GrAAHairLinePathRenderer.h ('k') | src/gpu/GrAARectRenderer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 SkASSERT(vstride == sizeof(LineVertex));
666 658 if (!arg->set(target, vertCnt, vstride, 0)) {
667 if (!arg->set(target, vertCnt, drawState->getVertexStride(), 0)) {
668 return false; 659 return false;
669 } 660 }
670 661
671 LineVertex* verts = reinterpret_cast<LineVertex*>(arg->vertices()); 662 LineVertex* verts = reinterpret_cast<LineVertex*>(arg->vertices());
672 663
673 const SkMatrix* toSrc = NULL; 664 const SkMatrix* toSrc = NULL;
674 SkMatrix ivm; 665 SkMatrix ivm;
675 666
676 if (viewM.hasPerspective()) { 667 if (viewM.hasPerspective()) {
677 if (viewM.invert(&ivm)) { 668 if (viewM.invert(&ivm)) {
(...skipping 16 matching lines...) Expand all
694 bool GrAAHairLinePathRenderer::createBezierGeom(GrDrawTarget* target, 685 bool GrAAHairLinePathRenderer::createBezierGeom(GrDrawTarget* target,
695 GrDrawState* drawState, 686 GrDrawState* drawState,
696 GrDrawTarget::AutoReleaseGeometr y* arg, 687 GrDrawTarget::AutoReleaseGeometr y* arg,
697 SkRect* devBounds, 688 SkRect* devBounds,
698 const SkPath& path, 689 const SkPath& path,
699 const PtArray& quads, 690 const PtArray& quads,
700 int quadCnt, 691 int quadCnt,
701 const PtArray& conics, 692 const PtArray& conics,
702 int conicCnt, 693 int conicCnt,
703 const IntArray& qSubdivs, 694 const IntArray& qSubdivs,
704 const FloatArray& cWeights) { 695 const FloatArray& cWeights,
696 size_t vertexStride) {
705 const SkMatrix& viewM = drawState->getViewMatrix(); 697 const SkMatrix& viewM = drawState->getViewMatrix();
706 698
707 int vertCnt = kQuadNumVertices * quadCnt + kQuadNumVertices * conicCnt; 699 int vertCnt = kQuadNumVertices * quadCnt + kQuadNumVertices * conicCnt;
708 700
709 int vAttribCnt = SK_ARRAY_COUNT(gHairlineBezierAttribs); 701 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; 702 return false;
714 } 703 }
715 704
716 BezierVertex* verts = reinterpret_cast<BezierVertex*>(arg->vertices()); 705 BezierVertex* verts = reinterpret_cast<BezierVertex*>(arg->vertices());
717 706
718 const SkMatrix* toDevice = NULL; 707 const SkMatrix* toDevice = NULL;
719 const SkMatrix* toSrc = NULL; 708 const SkMatrix* toSrc = NULL;
720 SkMatrix ivm; 709 SkMatrix ivm;
721 710
722 if (viewM.hasPerspective()) { 711 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, 828 quadCnt = generate_lines_and_quads(path, drawState->getViewMatrix(), devClip Bounds,
840 &lines, &quads, &conics, &qSubdivs, &cWei ghts); 829 &lines, &quads, &conics, &qSubdivs, &cWei ghts);
841 lineCnt = lines.count() / 2; 830 lineCnt = lines.count() / 2;
842 conicCnt = conics.count() / 3; 831 conicCnt = conics.count() / 3;
843 832
844 // do lines first 833 // do lines first
845 if (lineCnt) { 834 if (lineCnt) {
846 GrDrawTarget::AutoReleaseGeometry arg; 835 GrDrawTarget::AutoReleaseGeometry arg;
847 SkRect devBounds; 836 SkRect devBounds;
848 837
838 uint32_t gpFlags = GrDefaultGeoProcFactory::kPosition_GPType |
839 GrDefaultGeoProcFactory::kCoverage_GPType;
840 GrDrawState::AutoRestoreEffects are(drawState);
841 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(gpFlags) )->unref();
842
849 if (!this->createLineGeom(target, 843 if (!this->createLineGeom(target,
850 drawState, 844 drawState,
851 &arg, 845 &arg,
852 &devBounds, 846 &devBounds,
853 path, 847 path,
854 lines, 848 lines,
855 lineCnt)) { 849 lineCnt)) {
856 return false; 850 return false;
857 } 851 }
858 852
859 // createLineGeom transforms the geometry to device space when the matri x does not have 853 // createLineGeom transforms the geometry to device space when the matri x does not have
860 // perspective. 854 // perspective.
861 GrDrawState::AutoViewMatrixRestore avmr; 855 GrDrawState::AutoViewMatrixRestore avmr;
862 if (!drawState->getViewMatrix().hasPerspective() && !avmr.setIdentity(dr awState)) { 856 if (!drawState->getViewMatrix().hasPerspective() && !avmr.setIdentity(dr awState)) {
863 return false; 857 return false;
864 } 858 }
865 859
866 // Check devBounds 860 // Check devBounds
867 SkASSERT(check_bounds<LineVertex>(drawState, devBounds, arg.vertices(), 861 SkASSERT(check_bounds<LineVertex>(drawState, devBounds, arg.vertices(),
868 kLineSegNumVertices * lineCnt)); 862 kLineSegNumVertices * lineCnt));
869 863
870 { 864 {
871 GrDrawState::AutoRestoreEffects are(drawState);
872 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(fals e))->unref();
873 target->setIndexSourceToBuffer(fLinesIndexBuffer); 865 target->setIndexSourceToBuffer(fLinesIndexBuffer);
874 int lines = 0; 866 int lines = 0;
875 while (lines < lineCnt) { 867 while (lines < lineCnt) {
876 int n = SkTMin(lineCnt - lines, kLineSegsNumInIdxBuffer); 868 int n = SkTMin(lineCnt - lines, kLineSegsNumInIdxBuffer);
877 target->drawIndexed(drawState, 869 target->drawIndexed(drawState,
878 kTriangles_GrPrimitiveType, 870 kTriangles_GrPrimitiveType,
879 kLineSegNumVertices*lines, // startV 871 kLineSegNumVertices*lines, // startV
880 0, // startI 872 0, // startI
881 kLineSegNumVertices*n, // vCount 873 kLineSegNumVertices*n, // vCount
882 kIdxsPerLineSeg*n, // iCount 874 kIdxsPerLineSeg*n, // iCount
(...skipping 11 matching lines...) Expand all
894 if (!this->createBezierGeom(target, 886 if (!this->createBezierGeom(target,
895 drawState, 887 drawState,
896 &arg, 888 &arg,
897 &devBounds, 889 &devBounds,
898 path, 890 path,
899 quads, 891 quads,
900 quadCnt, 892 quadCnt,
901 conics, 893 conics,
902 conicCnt, 894 conicCnt,
903 qSubdivs, 895 qSubdivs,
904 cWeights)) { 896 cWeights,
897 sizeof(BezierVertex))) {
905 return false; 898 return false;
906 } 899 }
907 900
908 // createGeom transforms the geometry to device space when the matrix do es not have 901 // createGeom transforms the geometry to device space when the matrix do es not have
909 // perspective. 902 // perspective.
910 GrDrawState::AutoViewMatrixRestore avmr; 903 GrDrawState::AutoViewMatrixRestore avmr;
911 if (!drawState->getViewMatrix().hasPerspective() && !avmr.setIdentity(dr awState)) { 904 if (!drawState->getViewMatrix().hasPerspective() && !avmr.setIdentity(dr awState)) {
912 return false; 905 return false;
913 } 906 }
914 907
915 908
916 // Check devBounds 909 // Check devBounds
917 SkASSERT(check_bounds<BezierVertex>(drawState, devBounds, arg.vertices() , 910 SkASSERT(check_bounds<BezierVertex>(drawState, devBounds, arg.vertices() ,
918 kQuadNumVertices * quadCnt + kQuadNu mVertices * conicCnt)); 911 kQuadNumVertices * quadCnt + kQuadNu mVertices * conicCnt));
919 912
920 if (quadCnt > 0) { 913 if (quadCnt > 0) {
921 GrGeometryProcessor* hairQuadProcessor = 914 GrGeometryProcessor* hairQuadProcessor =
922 GrQuadEffect::Create(kHairlineAA_GrProcessorEdgeType, *targe t->caps()); 915 GrQuadEffect::Create(kHairlineAA_GrProcessorEdgeType, *targe t->caps());
923 SkASSERT(hairQuadProcessor); 916 SkASSERT(hairQuadProcessor);
924 GrDrawState::AutoRestoreEffects are(drawState); 917 GrDrawState::AutoRestoreEffects are(drawState);
925 target->setIndexSourceToBuffer(fQuadsIndexBuffer); 918 target->setIndexSourceToBuffer(fQuadsIndexBuffer);
919
926 drawState->setGeometryProcessor(hairQuadProcessor)->unref(); 920 drawState->setGeometryProcessor(hairQuadProcessor)->unref();
927 int quads = 0; 921 int quads = 0;
928 while (quads < quadCnt) { 922 while (quads < quadCnt) {
929 int n = SkTMin(quadCnt - quads, kQuadsNumInIdxBuffer); 923 int n = SkTMin(quadCnt - quads, kQuadsNumInIdxBuffer);
930 target->drawIndexed(drawState, 924 target->drawIndexed(drawState,
931 kTriangles_GrPrimitiveType, 925 kTriangles_GrPrimitiveType,
932 kQuadNumVertices*quads, // sta rtV 926 kQuadNumVertices*quads, // sta rtV
933 0, // sta rtI 927 0, // sta rtI
934 kQuadNumVertices*n, // vCo unt 928 kQuadNumVertices*n, // vCo unt
935 kIdxsPerQuad*n, // iCo unt 929 kIdxsPerQuad*n, // iCo unt
936 &devBounds); 930 &devBounds);
937 quads += n; 931 quads += n;
938 } 932 }
939 } 933 }
940 934
941 if (conicCnt > 0) { 935 if (conicCnt > 0) {
942 GrDrawState::AutoRestoreEffects are(drawState); 936 GrDrawState::AutoRestoreEffects are(drawState);
943 GrGeometryProcessor* hairConicProcessor = GrConicEffect::Create( 937 GrGeometryProcessor* hairConicProcessor = GrConicEffect::Create(
944 kHairlineAA_GrProcessorEdgeType, *target->caps()); 938 kHairlineAA_GrProcessorEdgeType, *target->caps());
945 SkASSERT(hairConicProcessor); 939 SkASSERT(hairConicProcessor);
940
946 drawState->setGeometryProcessor(hairConicProcessor)->unref(); 941 drawState->setGeometryProcessor(hairConicProcessor)->unref();
947 int conics = 0; 942 int conics = 0;
948 while (conics < conicCnt) { 943 while (conics < conicCnt) {
949 int n = SkTMin(conicCnt - conics, kQuadsNumInIdxBuffer); 944 int n = SkTMin(conicCnt - conics, kQuadsNumInIdxBuffer);
950 target->drawIndexed(drawState, 945 target->drawIndexed(drawState,
951 kTriangles_GrPrimitiveType, 946 kTriangles_GrPrimitiveType,
952 kQuadNumVertices*(quadCnt + conics), // sta rtV 947 kQuadNumVertices*(quadCnt + conics), // sta rtV
953 0, // sta rtI 948 0, // sta rtI
954 kQuadNumVertices*n, // vCo unt 949 kQuadNumVertices*n, // vCo unt
955 kIdxsPerQuad*n, // iCo unt 950 kIdxsPerQuad*n, // iCo unt
956 &devBounds); 951 &devBounds);
957 conics += n; 952 conics += n;
958 } 953 }
959 } 954 }
960 } 955 }
961 956
962 target->resetIndexSource(); 957 target->resetIndexSource();
963 958
964 return true; 959 return true;
965 } 960 }
OLDNEW
« no previous file with comments | « src/gpu/GrAAHairLinePathRenderer.h ('k') | src/gpu/GrAARectRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698