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

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

Issue 783763002: Initial CL to move color / coverage off of drawstate (Closed) Base URL: https://skia.googlesource.com/skia.git@no-static-gp
Patch Set: bug fix 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.h » ('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 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 636
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 GrDrawTarget::AutoReleaseGeometry* arg, 647 GrDrawTarget::AutoReleaseGeometry* arg,
647 SkRect* devBounds, 648 SkRect* devBounds,
648 const SkPath& path, 649 const SkPath& path,
649 const PtArray& lines, 650 const PtArray& lines,
650 int lineCnt) { 651 int lineCnt) {
651 const SkMatrix& viewM = drawState->getViewMatrix(); 652 const SkMatrix& viewM = drawState->getViewMatrix();
652 653
653 int vertCnt = kLineSegNumVertices * lineCnt; 654 int vertCnt = kLineSegNumVertices * lineCnt;
654 655
655 size_t vstride = drawState->getGeometryProcessor()->getVertexStride(); 656 size_t vstride = drawState->getGeometryProcessor()->getVertexStride();
656 SkASSERT(vstride == sizeof(LineVertex)); 657 SkASSERT(vstride == sizeof(LineVertex));
657 if (!arg->set(target, vertCnt, vstride, 0)) { 658 if (!arg->set(target, vertCnt, vstride, 0)) {
658 return false; 659 return false;
659 } 660 }
660 661
661 LineVertex* verts = reinterpret_cast<LineVertex*>(arg->vertices()); 662 LineVertex* verts = reinterpret_cast<LineVertex*>(arg->vertices());
662 663
663 const SkMatrix* toSrc = NULL; 664 const SkMatrix* toSrc = NULL;
664 SkMatrix ivm; 665 SkMatrix ivm;
665 666
666 if (viewM.hasPerspective()) { 667 if (viewM.hasPerspective()) {
667 if (viewM.invert(&ivm)) { 668 if (viewM.invert(&ivm)) {
668 toSrc = &ivm; 669 toSrc = &ivm;
669 } 670 }
670 } 671 }
671 devBounds->set(lines.begin(), lines.count()); 672 devBounds->set(lines.begin(), lines.count());
672 for (int i = 0; i < lineCnt; ++i) { 673 for (int i = 0; i < lineCnt; ++i) {
673 add_line(&lines[2*i], toSrc, drawState->getCoverage(), &verts); 674 add_line(&lines[2*i], toSrc, coverage, &verts);
674 } 675 }
675 // All the verts computed by add_line are within sqrt(1^2 + 0.5^2) of the en d points. 676 // All the verts computed by add_line are within sqrt(1^2 + 0.5^2) of the en d points.
676 static const SkScalar kSqrtOfOneAndAQuarter = 1.118f; 677 static const SkScalar kSqrtOfOneAndAQuarter = 1.118f;
677 // Add a little extra to account for vector normalization precision. 678 // Add a little extra to account for vector normalization precision.
678 static const SkScalar kOutset = kSqrtOfOneAndAQuarter + SK_Scalar1 / 20; 679 static const SkScalar kOutset = kSqrtOfOneAndAQuarter + SK_Scalar1 / 20;
679 devBounds->outset(kOutset, kOutset); 680 devBounds->outset(kOutset, kOutset);
680 681
681 return true; 682 return true;
682 } 683 }
683 684
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 } 797 }
797 if (!first) { 798 if (!first) {
798 return tolDevBounds.contains(actualBounds); 799 return tolDevBounds.contains(actualBounds);
799 } 800 }
800 801
801 return true; 802 return true;
802 } 803 }
803 804
804 bool GrAAHairLinePathRenderer::onDrawPath(GrDrawTarget* target, 805 bool GrAAHairLinePathRenderer::onDrawPath(GrDrawTarget* target,
805 GrDrawState* drawState, 806 GrDrawState* drawState,
807 GrColor color,
806 const SkPath& path, 808 const SkPath& path,
807 const SkStrokeRec& stroke, 809 const SkStrokeRec& stroke,
808 bool antiAlias) { 810 bool antiAlias) {
809 SkScalar hairlineCoverage; 811 SkScalar hairlineCoverage;
812 uint8_t newCoverage = 0xff;
810 if (IsStrokeHairlineOrEquivalent(stroke, drawState->getViewMatrix(), 813 if (IsStrokeHairlineOrEquivalent(stroke, drawState->getViewMatrix(),
811 &hairlineCoverage)) { 814 &hairlineCoverage)) {
812 uint8_t newCoverage = SkScalarRoundToInt(hairlineCoverage * drawState->g etCoverage()); 815 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff);
813 drawState->setCoverage(newCoverage);
814 } 816 }
815 817
816 SkIRect devClipBounds; 818 SkIRect devClipBounds;
817 target->getClip()->getConservativeBounds(drawState->getRenderTarget(), &devC lipBounds); 819 target->getClip()->getConservativeBounds(drawState->getRenderTarget(), &devC lipBounds);
818 820
819 int lineCnt; 821 int lineCnt;
820 int quadCnt; 822 int quadCnt;
821 int conicCnt; 823 int conicCnt;
822 PREALLOC_PTARRAY(128) lines; 824 PREALLOC_PTARRAY(128) lines;
823 PREALLOC_PTARRAY(128) quads; 825 PREALLOC_PTARRAY(128) quads;
824 PREALLOC_PTARRAY(128) conics; 826 PREALLOC_PTARRAY(128) conics;
825 IntArray qSubdivs; 827 IntArray qSubdivs;
826 FloatArray cWeights; 828 FloatArray cWeights;
827 quadCnt = generate_lines_and_quads(path, drawState->getViewMatrix(), devClip Bounds, 829 quadCnt = generate_lines_and_quads(path, drawState->getViewMatrix(), devClip Bounds,
828 &lines, &quads, &conics, &qSubdivs, &cWei ghts); 830 &lines, &quads, &conics, &qSubdivs, &cWei ghts);
829 lineCnt = lines.count() / 2; 831 lineCnt = lines.count() / 2;
830 conicCnt = conics.count() / 3; 832 conicCnt = conics.count() / 3;
831 833
832 // do lines first 834 // do lines first
833 if (lineCnt) { 835 if (lineCnt) {
834 GrDrawTarget::AutoReleaseGeometry arg; 836 GrDrawTarget::AutoReleaseGeometry arg;
835 SkRect devBounds; 837 SkRect devBounds;
836 838
837 uint32_t gpFlags = GrDefaultGeoProcFactory::kPosition_GPType | 839 uint32_t gpFlags = GrDefaultGeoProcFactory::kPosition_GPType |
838 GrDefaultGeoProcFactory::kCoverage_GPType; 840 GrDefaultGeoProcFactory::kCoverage_GPType;
839 GrDrawState::AutoRestoreEffects are(drawState); 841 GrDrawState::AutoRestoreEffects are(drawState);
840 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(gpFlags) )->unref(); 842 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(color,
843 gpFlags,
844 newCover age))->unref();
841 845
842 if (!this->createLineGeom(target, 846 if (!this->createLineGeom(target,
843 drawState, 847 drawState,
848 newCoverage,
844 &arg, 849 &arg,
845 &devBounds, 850 &devBounds,
846 path, 851 path,
847 lines, 852 lines,
848 lineCnt)) { 853 lineCnt)) {
849 return false; 854 return false;
850 } 855 }
851 856
852 // 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
853 // perspective. 858 // perspective.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 return false; 909 return false;
905 } 910 }
906 911
907 912
908 // Check devBounds 913 // Check devBounds
909 SkASSERT(check_bounds<BezierVertex>(drawState, devBounds, arg.vertices() , 914 SkASSERT(check_bounds<BezierVertex>(drawState, devBounds, arg.vertices() ,
910 kQuadNumVertices * quadCnt + kQuadNu mVertices * conicCnt)); 915 kQuadNumVertices * quadCnt + kQuadNu mVertices * conicCnt));
911 916
912 if (quadCnt > 0) { 917 if (quadCnt > 0) {
913 GrGeometryProcessor* hairQuadProcessor = 918 GrGeometryProcessor* hairQuadProcessor =
914 GrQuadEffect::Create(kHairlineAA_GrProcessorEdgeType, *targe t->caps()); 919 GrQuadEffect::Create(color,
920 kHairlineAA_GrProcessorEdgeType,
921 *target->caps(),
922 newCoverage);
915 SkASSERT(hairQuadProcessor); 923 SkASSERT(hairQuadProcessor);
916 GrDrawState::AutoRestoreEffects are(drawState); 924 GrDrawState::AutoRestoreEffects are(drawState);
917 target->setIndexSourceToBuffer(fQuadsIndexBuffer); 925 target->setIndexSourceToBuffer(fQuadsIndexBuffer);
918 926
919 drawState->setGeometryProcessor(hairQuadProcessor)->unref(); 927 drawState->setGeometryProcessor(hairQuadProcessor)->unref();
920 int quads = 0; 928 int quads = 0;
921 while (quads < quadCnt) { 929 while (quads < quadCnt) {
922 int n = SkTMin(quadCnt - quads, kQuadsNumInIdxBuffer); 930 int n = SkTMin(quadCnt - quads, kQuadsNumInIdxBuffer);
923 target->drawIndexed(drawState, 931 target->drawIndexed(drawState,
924 kTriangles_GrPrimitiveType, 932 kTriangles_GrPrimitiveType,
925 kQuadNumVertices*quads, // sta rtV 933 kQuadNumVertices*quads, // sta rtV
926 0, // sta rtI 934 0, // sta rtI
927 kQuadNumVertices*n, // vCo unt 935 kQuadNumVertices*n, // vCo unt
928 kIdxsPerQuad*n, // iCo unt 936 kIdxsPerQuad*n, // iCo unt
929 &devBounds); 937 &devBounds);
930 quads += n; 938 quads += n;
931 } 939 }
932 } 940 }
933 941
934 if (conicCnt > 0) { 942 if (conicCnt > 0) {
935 GrDrawState::AutoRestoreEffects are(drawState); 943 GrDrawState::AutoRestoreEffects are(drawState);
936 GrGeometryProcessor* hairConicProcessor = GrConicEffect::Create( 944 GrGeometryProcessor* hairConicProcessor = GrConicEffect::Create(
937 kHairlineAA_GrProcessorEdgeType, *target->caps()); 945 color, kHairlineAA_GrProcessorEdgeType, *target->caps(), new Coverage);
938 SkASSERT(hairConicProcessor); 946 SkASSERT(hairConicProcessor);
939 947
940 drawState->setGeometryProcessor(hairConicProcessor)->unref(); 948 drawState->setGeometryProcessor(hairConicProcessor)->unref();
941 int conics = 0; 949 int conics = 0;
942 while (conics < conicCnt) { 950 while (conics < conicCnt) {
943 int n = SkTMin(conicCnt - conics, kQuadsNumInIdxBuffer); 951 int n = SkTMin(conicCnt - conics, kQuadsNumInIdxBuffer);
944 target->drawIndexed(drawState, 952 target->drawIndexed(drawState,
945 kTriangles_GrPrimitiveType, 953 kTriangles_GrPrimitiveType,
946 kQuadNumVertices*(quadCnt + conics), // sta rtV 954 kQuadNumVertices*(quadCnt + conics), // sta rtV
947 0, // sta rtI 955 0, // sta rtI
948 kQuadNumVertices*n, // vCo unt 956 kQuadNumVertices*n, // vCo unt
949 kIdxsPerQuad*n, // iCo unt 957 kIdxsPerQuad*n, // iCo unt
950 &devBounds); 958 &devBounds);
951 conics += n; 959 conics += n;
952 } 960 }
953 } 961 }
954 } 962 }
955 963
956 target->resetIndexSource(); 964 target->resetIndexSource();
957 965
958 return true; 966 return true;
959 } 967 }
OLDNEW
« no previous file with comments | « src/gpu/GrAAHairLinePathRenderer.h ('k') | src/gpu/GrAARectRenderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698