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

Side by Side Diff: src/gpu/batches/GrAAConvexPathRenderer.cpp

Issue 2041113004: sk_sp for gpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reserve correctly. Created 4 years, 6 months 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/SkGrPriv.h ('k') | src/gpu/batches/GrAADistanceFieldPathRenderer.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 2012 Google Inc. 2 * Copyright 2012 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 "GrAAConvexPathRenderer.h" 8 #include "GrAAConvexPathRenderer.h"
9 9
10 #include "GrAAConvexTessellator.h" 10 #include "GrAAConvexTessellator.h"
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 * distance with negative being inside, positive outside. The edge is specified in 519 * distance with negative being inside, positive outside. The edge is specified in
520 * window space (y-down). If either the third or fourth component of the interpo lated 520 * window space (y-down). If either the third or fourth component of the interpo lated
521 * vertex coord is > 0 then the pixel is considered outside the edge. This is us ed to 521 * vertex coord is > 0 then the pixel is considered outside the edge. This is us ed to
522 * attempt to trim to a portion of the infinite quad. 522 * attempt to trim to a portion of the infinite quad.
523 * Requires shader derivative instruction support. 523 * Requires shader derivative instruction support.
524 */ 524 */
525 525
526 class QuadEdgeEffect : public GrGeometryProcessor { 526 class QuadEdgeEffect : public GrGeometryProcessor {
527 public: 527 public:
528 528
529 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& localMatri x, 529 static sk_sp<GrGeometryProcessor> Make(GrColor color, const SkMatrix& localM atrix,
530 bool usesLocalCoords) { 530 bool usesLocalCoords) {
531 return new QuadEdgeEffect(color, localMatrix, usesLocalCoords); 531 return sk_sp<GrGeometryProcessor>(new QuadEdgeEffect(color, localMatrix, usesLocalCoords));
532 } 532 }
533 533
534 virtual ~QuadEdgeEffect() {} 534 virtual ~QuadEdgeEffect() {}
535 535
536 const char* name() const override { return "QuadEdge"; } 536 const char* name() const override { return "QuadEdge"; }
537 537
538 const Attribute* inPosition() const { return fInPosition; } 538 const Attribute* inPosition() const { return fInPosition; }
539 const Attribute* inQuadEdge() const { return fInQuadEdge; } 539 const Attribute* inQuadEdge() const { return fInQuadEdge; }
540 GrColor color() const { return fColor; } 540 GrColor color() const { return fColor; }
541 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } 541 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 SkMatrix fLocalMatrix; 662 SkMatrix fLocalMatrix;
663 bool fUsesLocalCoords; 663 bool fUsesLocalCoords;
664 664
665 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; 665 GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
666 666
667 typedef GrGeometryProcessor INHERITED; 667 typedef GrGeometryProcessor INHERITED;
668 }; 668 };
669 669
670 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(QuadEdgeEffect); 670 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(QuadEdgeEffect);
671 671
672 const GrGeometryProcessor* QuadEdgeEffect::TestCreate(GrProcessorTestData* d) { 672 sk_sp<GrGeometryProcessor> QuadEdgeEffect::TestCreate(GrProcessorTestData* d) {
673 // Doesn't work without derivative instructions. 673 // Doesn't work without derivative instructions.
674 return d->fCaps->shaderCaps()->shaderDerivativeSupport() ? 674 return d->fCaps->shaderCaps()->shaderDerivativeSupport() ?
675 QuadEdgeEffect::Create(GrRandomColor(d->fRandom), 675 QuadEdgeEffect::Make(GrRandomColor(d->fRandom),
676 GrTest::TestMatrix(d->fRandom), 676 GrTest::TestMatrix(d->fRandom),
677 d->fRandom->nextBool()) : nullptr; 677 d->fRandom->nextBool()) : nullptr;
678 } 678 }
679 679
680 /////////////////////////////////////////////////////////////////////////////// 680 ///////////////////////////////////////////////////////////////////////////////
681 681
682 bool GrAAConvexPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { 682 bool GrAAConvexPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
683 return (args.fShaderCaps->shaderDerivativeSupport() && args.fAntiAlias && 683 return (args.fShaderCaps->shaderDerivativeSupport() && args.fAntiAlias &&
684 args.fStyle->isSimpleFill() && !args.fPath->isInverseFillType() && 684 args.fStyle->isSimpleFill() && !args.fPath->isInverseFillType() &&
685 args.fPath->isConvex()); 685 args.fPath->isConvex());
686 } 686 }
687 687
(...skipping 23 matching lines...) Expand all
711 *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor) ) = 711 *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor) ) =
712 tess.coverage(i); 712 tess.coverage(i);
713 } 713 }
714 } 714 }
715 715
716 for (int i = 0; i < tess.numIndices(); ++i) { 716 for (int i = 0; i < tess.numIndices(); ++i) {
717 idxs[i] = tess.index(i); 717 idxs[i] = tess.index(i);
718 } 718 }
719 } 719 }
720 720
721 static const GrGeometryProcessor* create_fill_gp(bool tweakAlphaForCoverage, 721 static sk_sp<GrGeometryProcessor> create_fill_gp(bool tweakAlphaForCoverage,
722 const SkMatrix& viewMatrix, 722 const SkMatrix& viewMatrix,
723 bool usesLocalCoords, 723 bool usesLocalCoords,
724 bool coverageIgnored) { 724 bool coverageIgnored) {
725 using namespace GrDefaultGeoProcFactory; 725 using namespace GrDefaultGeoProcFactory;
726 726
727 Color color(Color::kAttribute_Type); 727 Color color(Color::kAttribute_Type);
728 Coverage::Type coverageType; 728 Coverage::Type coverageType;
729 // TODO remove coverage if coverage is ignored 729 // TODO remove coverage if coverage is ignored
730 /*if (coverageIgnored) { 730 /*if (coverageIgnored) {
731 coverageType = Coverage::kNone_Type; 731 coverageType = Coverage::kNone_Type;
732 } else*/ if (tweakAlphaForCoverage) { 732 } else*/ if (tweakAlphaForCoverage) {
733 coverageType = Coverage::kSolid_Type; 733 coverageType = Coverage::kSolid_Type;
734 } else { 734 } else {
735 coverageType = Coverage::kAttribute_Type; 735 coverageType = Coverage::kAttribute_Type;
736 } 736 }
737 Coverage coverage(coverageType); 737 Coverage coverage(coverageType);
738 LocalCoords localCoords(usesLocalCoords ? LocalCoords::kUsePosition_Type : 738 LocalCoords localCoords(usesLocalCoords ? LocalCoords::kUsePosition_Type :
739 LocalCoords::kUnused_Type); 739 LocalCoords::kUnused_Type);
740 return CreateForDeviceSpace(color, coverage, localCoords, viewMatrix); 740 return MakeForDeviceSpace(color, coverage, localCoords, viewMatrix);
741 } 741 }
742 742
743 class AAConvexPathBatch : public GrVertexBatch { 743 class AAConvexPathBatch : public GrVertexBatch {
744 public: 744 public:
745 DEFINE_BATCH_CLASS_ID 745 DEFINE_BATCH_CLASS_ID
746 struct Geometry { 746 struct Geometry {
747 GrColor fColor; 747 GrColor fColor;
748 SkMatrix fViewMatrix; 748 SkMatrix fViewMatrix;
749 SkPath fPath; 749 SkPath fPath;
750 }; 750 };
(...skipping 24 matching lines...) Expand all
775 fBatch.fUsesLocalCoords = overrides.readsLocalCoords(); 775 fBatch.fUsesLocalCoords = overrides.readsLocalCoords();
776 fBatch.fCoverageIgnored = !overrides.readsCoverage(); 776 fBatch.fCoverageIgnored = !overrides.readsCoverage();
777 fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSe gmentMasks(); 777 fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSe gmentMasks();
778 fBatch.fCanTweakAlphaForCoverage = overrides.canTweakAlphaForCoverage(); 778 fBatch.fCanTweakAlphaForCoverage = overrides.canTweakAlphaForCoverage();
779 } 779 }
780 780
781 void prepareLinesOnlyDraws(Target* target) const { 781 void prepareLinesOnlyDraws(Target* target) const {
782 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); 782 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
783 783
784 // Setup GrGeometryProcessor 784 // Setup GrGeometryProcessor
785 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF orCoverage, 785 sk_sp<GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaForCoverage,
786 this->viewMatr ix(), 786 this->viewMatrix(),
787 this->usesLoca lCoords(), 787 this->usesLocalCoords(),
788 this->coverage Ignored())); 788 this->coverageIgnored()));
789 if (!gp) { 789 if (!gp) {
790 SkDebugf("Could not create GrGeometryProcessor\n"); 790 SkDebugf("Could not create GrGeometryProcessor\n");
791 return; 791 return;
792 } 792 }
793 793
794 size_t vertexStride = gp->getVertexStride(); 794 size_t vertexStride = gp->getVertexStride();
795 795
796 SkASSERT(canTweakAlphaForCoverage ? 796 SkASSERT(canTweakAlphaForCoverage ?
797 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) : 797 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) :
798 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr)); 798 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr));
(...skipping 30 matching lines...) Expand all
829 return; 829 return;
830 } 830 }
831 831
832 extract_verts(tess, verts, vertexStride, args.fColor, idxs, canTweak AlphaForCoverage); 832 extract_verts(tess, verts, vertexStride, args.fColor, idxs, canTweak AlphaForCoverage);
833 833
834 GrMesh mesh; 834 GrMesh mesh;
835 mesh.initIndexed(kTriangles_GrPrimitiveType, 835 mesh.initIndexed(kTriangles_GrPrimitiveType,
836 vertexBuffer, indexBuffer, 836 vertexBuffer, indexBuffer,
837 firstVertex, firstIndex, 837 firstVertex, firstIndex,
838 tess.numPts(), tess.numIndices()); 838 tess.numPts(), tess.numIndices());
839 target->draw(gp, mesh); 839 target->draw(gp.get(), mesh);
840 } 840 }
841 } 841 }
842 842
843 void onPrepareDraws(Target* target) const override { 843 void onPrepareDraws(Target* target) const override {
844 #ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS 844 #ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS
845 if (this->linesOnly()) { 845 if (this->linesOnly()) {
846 this->prepareLinesOnlyDraws(target); 846 this->prepareLinesOnlyDraws(target);
847 return; 847 return;
848 } 848 }
849 #endif 849 #endif
850 850
851 int instanceCount = fGeoData.count(); 851 int instanceCount = fGeoData.count();
852 852
853 SkMatrix invert; 853 SkMatrix invert;
854 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { 854 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) {
855 SkDebugf("Could not invert viewmatrix\n"); 855 SkDebugf("Could not invert viewmatrix\n");
856 return; 856 return;
857 } 857 }
858 858
859 // Setup GrGeometryProcessor 859 // Setup GrGeometryProcessor
860 SkAutoTUnref<GrGeometryProcessor> quadProcessor( 860 sk_sp<GrGeometryProcessor> quadProcessor(
861 QuadEdgeEffect::Create(this->color(), invert, this->usesLocalCoo rds())); 861 QuadEdgeEffect::Make(this->color(), invert, this->usesLocalCoord s()));
862 862
863 // TODO generate all segments for all paths and use one vertex buffer 863 // TODO generate all segments for all paths and use one vertex buffer
864 for (int i = 0; i < instanceCount; i++) { 864 for (int i = 0; i < instanceCount; i++) {
865 const Geometry& args = fGeoData[i]; 865 const Geometry& args = fGeoData[i];
866 866
867 // We use the fact that SkPath::transform path does subdivision base d on 867 // We use the fact that SkPath::transform path does subdivision base d on
868 // perspective. Otherwise, we apply the view matrix when copying to the 868 // perspective. Otherwise, we apply the view matrix when copying to the
869 // segment representation. 869 // segment representation.
870 const SkMatrix* viewMatrix = &args.fViewMatrix; 870 const SkMatrix* viewMatrix = &args.fViewMatrix;
871 871
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 917
918 SkSTArray<kPreallocDrawCnt, Draw, true> draws; 918 SkSTArray<kPreallocDrawCnt, Draw, true> draws;
919 create_vertices(segments, fanPt, &draws, verts, idxs); 919 create_vertices(segments, fanPt, &draws, verts, idxs);
920 920
921 GrMesh mesh; 921 GrMesh mesh;
922 922
923 for (int j = 0; j < draws.count(); ++j) { 923 for (int j = 0; j < draws.count(); ++j) {
924 const Draw& draw = draws[j]; 924 const Draw& draw = draws[j];
925 mesh.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, index Buffer, 925 mesh.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, index Buffer,
926 firstVertex, firstIndex, draw.fVertexCnt, draw. fIndexCnt); 926 firstVertex, firstIndex, draw.fVertexCnt, draw. fIndexCnt);
927 target->draw(quadProcessor, mesh); 927 target->draw(quadProcessor.get(), mesh);
928 firstVertex += draw.fVertexCnt; 928 firstVertex += draw.fVertexCnt;
929 firstIndex += draw.fIndexCnt; 929 firstIndex += draw.fIndexCnt;
930 } 930 }
931 } 931 }
932 } 932 }
933 933
934 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 934 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
935 935
936 AAConvexPathBatch(const Geometry& geometry) : INHERITED(ClassID()) { 936 AAConvexPathBatch(const Geometry& geometry) : INHERITED(ClassID()) {
937 fGeoData.push_back(geometry); 937 fGeoData.push_back(geometry);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) { 1026 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) {
1027 AAConvexPathBatch::Geometry geometry; 1027 AAConvexPathBatch::Geometry geometry;
1028 geometry.fColor = GrRandomColor(random); 1028 geometry.fColor = GrRandomColor(random);
1029 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); 1029 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random);
1030 geometry.fPath = GrTest::TestPathConvex(random); 1030 geometry.fPath = GrTest::TestPathConvex(random);
1031 1031
1032 return AAConvexPathBatch::Create(geometry); 1032 return AAConvexPathBatch::Create(geometry);
1033 } 1033 }
1034 1034
1035 #endif 1035 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGrPriv.h ('k') | src/gpu/batches/GrAADistanceFieldPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698