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

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

Issue 2110903002: Hide more GrBatch Geometry structs. (Closed) Base URL: https://chromium.googlesource.com/skia.git@aabloat
Patch Set: Address comments Created 4 years, 5 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 | « no previous file | 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 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 MakeForDeviceSpace(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 AAConvexPathBatch(GrColor color, const SkMatrix& viewMatrix, const SkPath& p ath)
747 GrColor fColor; 747 : INHERITED(ClassID()) {
748 SkMatrix fViewMatrix; 748 fGeoData.emplace_back(Geometry{color, viewMatrix, path});
749 SkPath fPath; 749 // compute bounds
750 }; 750 fBounds = path.getBounds();
751 751 viewMatrix.mapRect(&fBounds);
752 static GrDrawBatch* Create(const Geometry& geometry) { return new AAConvexPa thBatch(geometry); } 752 }
753 753
754 const char* name() const override { return "AAConvexBatch"; } 754 const char* name() const override { return "AAConvexBatch"; }
755 755
756 void computePipelineOptimizations(GrInitInvariantOutput* color, 756 void computePipelineOptimizations(GrInitInvariantOutput* color,
757 GrInitInvariantOutput* coverage, 757 GrInitInvariantOutput* coverage,
758 GrBatchToXPOverrides* overrides) const ove rride { 758 GrBatchToXPOverrides* overrides) const ove rride {
759 // When this is called on a batch, there is only one geometry bundle 759 // When this is called on a batch, there is only one geometry bundle
760 color->setKnownFourComponents(fGeoData[0].fColor); 760 color->setKnownFourComponents(fGeoData[0].fColor);
761 coverage->setUnknownSingleComponent(); 761 coverage->setUnknownSingleComponent();
762 } 762 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.get(), 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; }
935
936 AAConvexPathBatch(const Geometry& geometry) : INHERITED(ClassID()) {
937 fGeoData.push_back(geometry);
938
939 // compute bounds
940 fBounds = geometry.fPath.getBounds();
941 geometry.fViewMatrix.mapRect(&fBounds);
942 }
943
944 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { 934 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
945 AAConvexPathBatch* that = t->cast<AAConvexPathBatch>(); 935 AAConvexPathBatch* that = t->cast<AAConvexPathBatch>();
946 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(), 936 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(),
947 that->bounds(), caps)) { 937 that->bounds(), caps)) {
948 return false; 938 return false;
949 } 939 }
950 940
951 if (this->color() != that->color()) { 941 if (this->color() != that->color()) {
952 return false; 942 return false;
953 } 943 }
954 944
955 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); 945 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords());
956 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi ewMatrix())) { 946 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi ewMatrix())) {
957 return false; 947 return false;
958 } 948 }
959 949
960 if (this->linesOnly() != that->linesOnly()) { 950 if (this->linesOnly() != that->linesOnly()) {
961 return false; 951 return false;
962 } 952 }
963 953
964 // In the event of two batches, one who can tweak, one who cannot, we ju st fall back to 954 // In the event of two batches, one who can tweak, one who cannot, we ju st fall back to
965 // not tweaking 955 // not tweaking
966 if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage() ) { 956 if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage() ) {
967 fBatch.fCanTweakAlphaForCoverage = false; 957 fBatch.fCanTweakAlphaForCoverage = false;
968 } 958 }
969 959
970 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ; 960 fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin());
971 this->joinBounds(that->bounds()); 961 this->joinBounds(that->bounds());
972 return true; 962 return true;
973 } 963 }
974 964
975 GrColor color() const { return fBatch.fColor; } 965 GrColor color() const { return fBatch.fColor; }
976 bool linesOnly() const { return fBatch.fLinesOnly; } 966 bool linesOnly() const { return fBatch.fLinesOnly; }
977 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } 967 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
978 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover age; } 968 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover age; }
979 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } 969 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; }
980 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } 970 bool coverageIgnored() const { return fBatch.fCoverageIgnored; }
981 971
982 struct BatchTracker { 972 struct BatchTracker {
983 GrColor fColor; 973 GrColor fColor;
984 bool fUsesLocalCoords; 974 bool fUsesLocalCoords;
985 bool fColorIgnored; 975 bool fColorIgnored;
986 bool fCoverageIgnored; 976 bool fCoverageIgnored;
987 bool fLinesOnly; 977 bool fLinesOnly;
988 bool fCanTweakAlphaForCoverage; 978 bool fCanTweakAlphaForCoverage;
989 }; 979 };
990 980
981 struct Geometry {
982 GrColor fColor;
983 SkMatrix fViewMatrix;
984 SkPath fPath;
985 };
986
991 BatchTracker fBatch; 987 BatchTracker fBatch;
992 SkSTArray<1, Geometry, true> fGeoData; 988 SkSTArray<1, Geometry, true> fGeoData;
993 989
994 typedef GrVertexBatch INHERITED; 990 typedef GrVertexBatch INHERITED;
995 }; 991 };
996 992
997 bool GrAAConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { 993 bool GrAAConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
998 GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), 994 GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(),
999 "GrAAConvexPathRenderer::onDrawPath"); 995 "GrAAConvexPathRenderer::onDrawPath");
1000 SkASSERT(!args.fDrawContext->isUnifiedMultisampled()); 996 SkASSERT(!args.fDrawContext->isUnifiedMultisampled());
1001 SkASSERT(!args.fShape->isEmpty()); 997 SkASSERT(!args.fShape->isEmpty());
1002 998
1003 AAConvexPathBatch::Geometry geometry; 999 SkPath path;
1004 geometry.fColor = args.fColor; 1000 args.fShape->asPath(&path);
1005 geometry.fViewMatrix = *args.fViewMatrix;
1006 args.fShape->asPath(&geometry.fPath);
1007 1001
1008 SkAutoTUnref<GrDrawBatch> batch(AAConvexPathBatch::Create(geometry)); 1002 SkAutoTUnref<GrDrawBatch> batch(new AAConvexPathBatch(args.fColor, *args.fVi ewMatrix, path));
1009 1003
1010 GrPipelineBuilder pipelineBuilder(*args.fPaint); 1004 GrPipelineBuilder pipelineBuilder(*args.fPaint);
1011 pipelineBuilder.setUserStencil(args.fUserStencilSettings); 1005 pipelineBuilder.setUserStencil(args.fUserStencilSettings);
1012 1006
1013 args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); 1007 args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch);
1014 1008
1015 return true; 1009 return true;
1016 1010
1017 } 1011 }
1018 1012
1019 //////////////////////////////////////////////////////////////////////////////// /////////////////// 1013 //////////////////////////////////////////////////////////////////////////////// ///////////////////
1020 1014
1021 #ifdef GR_TEST_UTILS 1015 #ifdef GR_TEST_UTILS
1022 1016
1023 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) { 1017 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) {
1024 AAConvexPathBatch::Geometry geometry; 1018 GrColor color = GrRandomColor(random);
1025 geometry.fColor = GrRandomColor(random); 1019 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random);
1026 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); 1020 SkPath path = GrTest::TestPathConvex(random);
1027 geometry.fPath = GrTest::TestPathConvex(random);
1028 1021
1029 return AAConvexPathBatch::Create(geometry); 1022 return new AAConvexPathBatch(color, viewMatrix, path);
1030 } 1023 }
1031 1024
1032 #endif 1025 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/batches/GrAADistanceFieldPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698