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

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

Issue 1835283002: Simplify GrDrawBatch uploads and token uage. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: comments updated Created 4 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "GrOvalRenderer.h" 8 #include "GrOvalRenderer.h"
9 9
10 #include "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 600
601 void onPrepareDraws(Target* target) const override { 601 void onPrepareDraws(Target* target) const override {
602 SkMatrix localMatrix; 602 SkMatrix localMatrix;
603 if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) { 603 if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) {
604 return; 604 return;
605 } 605 }
606 606
607 // Setup geometry processor 607 // Setup geometry processor
608 SkAutoTUnref<GrGeometryProcessor> gp(new CircleGeometryProcessor(fStroke d, localMatrix)); 608 SkAutoTUnref<GrGeometryProcessor> gp(new CircleGeometryProcessor(fStroke d, localMatrix));
609 609
610 target->initDraw(gp);
611
612 int instanceCount = fGeoData.count(); 610 int instanceCount = fGeoData.count();
613 size_t vertexStride = gp->getVertexStride(); 611 size_t vertexStride = gp->getVertexStride();
614 SkASSERT(vertexStride == sizeof(CircleVertex)); 612 SkASSERT(vertexStride == sizeof(CircleVertex));
615 QuadHelper helper; 613 QuadHelper helper;
616 CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(target , vertexStride, 614 CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(target , vertexStride,
617 instan ceCount)); 615 instan ceCount));
618 if (!verts) { 616 if (!verts) {
619 return; 617 return;
620 } 618 }
621 619
(...skipping 27 matching lines...) Expand all
649 verts[2].fInnerRadius = innerRadius; 647 verts[2].fInnerRadius = innerRadius;
650 648
651 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); 649 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop);
652 verts[3].fColor = color; 650 verts[3].fColor = color;
653 verts[3].fOffset = SkPoint::Make(1, -1); 651 verts[3].fOffset = SkPoint::Make(1, -1);
654 verts[3].fOuterRadius = outerRadius; 652 verts[3].fOuterRadius = outerRadius;
655 verts[3].fInnerRadius = innerRadius; 653 verts[3].fInnerRadius = innerRadius;
656 654
657 verts += kVerticesPerQuad; 655 verts += kVerticesPerQuad;
658 } 656 }
659 helper.recordDraw(target); 657 helper.recordDraw(target, gp);
660 } 658 }
661 659
662 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { 660 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
663 CircleBatch* that = t->cast<CircleBatch>(); 661 CircleBatch* that = t->cast<CircleBatch>();
664 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(), 662 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(),
665 that->bounds(), caps)) { 663 that->bounds(), caps)) {
666 return false; 664 return false;
667 } 665 }
668 666
669 if (this->fStroked != that->fStroked) { 667 if (this->fStroked != that->fStroked) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 784
787 void onPrepareDraws(Target* target) const override { 785 void onPrepareDraws(Target* target) const override {
788 SkMatrix localMatrix; 786 SkMatrix localMatrix;
789 if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) { 787 if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) {
790 return; 788 return;
791 } 789 }
792 790
793 // Setup geometry processor 791 // Setup geometry processor
794 SkAutoTUnref<GrGeometryProcessor> gp(new EllipseGeometryProcessor(fStrok ed, localMatrix)); 792 SkAutoTUnref<GrGeometryProcessor> gp(new EllipseGeometryProcessor(fStrok ed, localMatrix));
795 793
796 target->initDraw(gp);
797
798 int instanceCount = fGeoData.count(); 794 int instanceCount = fGeoData.count();
799 QuadHelper helper; 795 QuadHelper helper;
800 size_t vertexStride = gp->getVertexStride(); 796 size_t vertexStride = gp->getVertexStride();
801 SkASSERT(vertexStride == sizeof(EllipseVertex)); 797 SkASSERT(vertexStride == sizeof(EllipseVertex));
802 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( 798 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(
803 helper.init(target, vertexStride, instanceCount)); 799 helper.init(target, vertexStride, instanceCount));
804 if (!verts) { 800 if (!verts) {
805 return; 801 return;
806 } 802 }
807 803
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip) ; 836 verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip) ;
841 837
842 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); 838 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop);
843 verts[3].fColor = color; 839 verts[3].fColor = color;
844 verts[3].fOffset = SkPoint::Make(xRadius, -yRadius); 840 verts[3].fOffset = SkPoint::Make(xRadius, -yRadius);
845 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); 841 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip);
846 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip) ; 842 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip) ;
847 843
848 verts += kVerticesPerQuad; 844 verts += kVerticesPerQuad;
849 } 845 }
850 helper.recordDraw(target); 846 helper.recordDraw(target, gp);
851 } 847 }
852 848
853 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { 849 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
854 EllipseBatch* that = t->cast<EllipseBatch>(); 850 EllipseBatch* that = t->cast<EllipseBatch>();
855 851
856 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(), 852 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(),
857 that->bounds(), caps)) { 853 that->bounds(), caps)) {
858 return false; 854 return false;
859 } 855 }
860 856
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 // Handle any overrides that affect our GP. 1000 // Handle any overrides that affect our GP.
1005 overrides.getOverrideColorIfSet(&fGeoData[0].fColor); 1001 overrides.getOverrideColorIfSet(&fGeoData[0].fColor);
1006 fUsesLocalCoords = overrides.readsLocalCoords(); 1002 fUsesLocalCoords = overrides.readsLocalCoords();
1007 } 1003 }
1008 1004
1009 void onPrepareDraws(Target* target) const override { 1005 void onPrepareDraws(Target* target) const override {
1010 // Setup geometry processor 1006 // Setup geometry processor
1011 SkAutoTUnref<GrGeometryProcessor> gp(new DIEllipseGeometryProcessor(this ->viewMatrix(), 1007 SkAutoTUnref<GrGeometryProcessor> gp(new DIEllipseGeometryProcessor(this ->viewMatrix(),
1012 this ->style())); 1008 this ->style()));
1013 1009
1014 target->initDraw(gp);
1015
1016 int instanceCount = fGeoData.count(); 1010 int instanceCount = fGeoData.count();
1017 size_t vertexStride = gp->getVertexStride(); 1011 size_t vertexStride = gp->getVertexStride();
1018 SkASSERT(vertexStride == sizeof(DIEllipseVertex)); 1012 SkASSERT(vertexStride == sizeof(DIEllipseVertex));
1019 QuadHelper helper; 1013 QuadHelper helper;
1020 DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>( 1014 DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>(
1021 helper.init(target, vertexStride, instanceCount)); 1015 helper.init(target, vertexStride, instanceCount));
1022 if (!verts) { 1016 if (!verts) {
1023 return; 1017 return;
1024 } 1018 }
1025 1019
(...skipping 28 matching lines...) Expand all
1054 verts[2].fOuterOffset = SkPoint::Make(1.0f + offsetDx, 1.0f + offset Dy); 1048 verts[2].fOuterOffset = SkPoint::Make(1.0f + offsetDx, 1.0f + offset Dy);
1055 verts[2].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, innerR atioY + offsetDy); 1049 verts[2].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, innerR atioY + offsetDy);
1056 1050
1057 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); 1051 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop);
1058 verts[3].fColor = color; 1052 verts[3].fColor = color;
1059 verts[3].fOuterOffset = SkPoint::Make(1.0f + offsetDx, -1.0f - offse tDy); 1053 verts[3].fOuterOffset = SkPoint::Make(1.0f + offsetDx, -1.0f - offse tDy);
1060 verts[3].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, -inner RatioY - offsetDy); 1054 verts[3].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, -inner RatioY - offsetDy);
1061 1055
1062 verts += kVerticesPerQuad; 1056 verts += kVerticesPerQuad;
1063 } 1057 }
1064 helper.recordDraw(target); 1058 helper.recordDraw(target, gp);
1065 } 1059 }
1066 1060
1067 DIEllipseBatch(const Geometry& geometry, const SkRect& bounds) : INHERITED(C lassID()) { 1061 DIEllipseBatch(const Geometry& geometry, const SkRect& bounds) : INHERITED(C lassID()) {
1068 fGeoData.push_back(geometry); 1062 fGeoData.push_back(geometry);
1069 1063
1070 this->setBounds(bounds); 1064 this->setBounds(bounds);
1071 } 1065 }
1072 1066
1073 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { 1067 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
1074 DIEllipseBatch* that = t->cast<DIEllipseBatch>(); 1068 DIEllipseBatch* that = t->cast<DIEllipseBatch>();
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 void onPrepareDraws(Target* target) const override { 1265 void onPrepareDraws(Target* target) const override {
1272 // Invert the view matrix as a local matrix (if any other processors req uire coords). 1266 // Invert the view matrix as a local matrix (if any other processors req uire coords).
1273 SkMatrix localMatrix; 1267 SkMatrix localMatrix;
1274 if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) { 1268 if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) {
1275 return; 1269 return;
1276 } 1270 }
1277 1271
1278 // Setup geometry processor 1272 // Setup geometry processor
1279 SkAutoTUnref<GrGeometryProcessor> gp(new CircleGeometryProcessor(fStroke d, localMatrix)); 1273 SkAutoTUnref<GrGeometryProcessor> gp(new CircleGeometryProcessor(fStroke d, localMatrix));
1280 1274
1281 target->initDraw(gp);
1282
1283 int instanceCount = fGeoData.count(); 1275 int instanceCount = fGeoData.count();
1284 size_t vertexStride = gp->getVertexStride(); 1276 size_t vertexStride = gp->getVertexStride();
1285 SkASSERT(vertexStride == sizeof(CircleVertex)); 1277 SkASSERT(vertexStride == sizeof(CircleVertex));
1286 1278
1287 // drop out the middle quad if we're stroked 1279 // drop out the middle quad if we're stroked
1288 int indicesPerInstance = fStroked ? kIndicesPerStrokeRRect : kIndicesPer RRect; 1280 int indicesPerInstance = fStroked ? kIndicesPerStrokeRRect : kIndicesPer RRect;
1289 SkAutoTUnref<const GrBuffer> indexBuffer( 1281 SkAutoTUnref<const GrBuffer> indexBuffer(
1290 ref_rrect_index_buffer(fStroked, target->resourceProvider())); 1282 ref_rrect_index_buffer(fStroked, target->resourceProvider()));
1291 1283
1292 InstancedHelper helper; 1284 InstancedHelper helper;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 1332
1341 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); 1333 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]);
1342 verts->fColor = color; 1334 verts->fColor = color;
1343 verts->fOffset = SkPoint::Make(1, yOuterRadii[i]); 1335 verts->fOffset = SkPoint::Make(1, yOuterRadii[i]);
1344 verts->fOuterRadius = outerRadius; 1336 verts->fOuterRadius = outerRadius;
1345 verts->fInnerRadius = innerRadius; 1337 verts->fInnerRadius = innerRadius;
1346 verts++; 1338 verts++;
1347 } 1339 }
1348 } 1340 }
1349 1341
1350 helper.recordDraw(target); 1342 helper.recordDraw(target, gp);
1351 } 1343 }
1352 1344
1353 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { 1345 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
1354 RRectCircleRendererBatch* that = t->cast<RRectCircleRendererBatch>(); 1346 RRectCircleRendererBatch* that = t->cast<RRectCircleRendererBatch>();
1355 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(), 1347 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(),
1356 that->bounds(), caps)) { 1348 that->bounds(), caps)) {
1357 return false; 1349 return false;
1358 } 1350 }
1359 1351
1360 if (fStroked != that->fStroked) { 1352 if (fStroked != that->fStroked) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 1411
1420 void onPrepareDraws(Target* target) const override { 1412 void onPrepareDraws(Target* target) const override {
1421 SkMatrix localMatrix; 1413 SkMatrix localMatrix;
1422 if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) { 1414 if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) {
1423 return; 1415 return;
1424 } 1416 }
1425 1417
1426 // Setup geometry processor 1418 // Setup geometry processor
1427 SkAutoTUnref<GrGeometryProcessor> gp(new EllipseGeometryProcessor(fStrok ed, localMatrix)); 1419 SkAutoTUnref<GrGeometryProcessor> gp(new EllipseGeometryProcessor(fStrok ed, localMatrix));
1428 1420
1429 target->initDraw(gp);
1430
1431 int instanceCount = fGeoData.count(); 1421 int instanceCount = fGeoData.count();
1432 size_t vertexStride = gp->getVertexStride(); 1422 size_t vertexStride = gp->getVertexStride();
1433 SkASSERT(vertexStride == sizeof(EllipseVertex)); 1423 SkASSERT(vertexStride == sizeof(EllipseVertex));
1434 1424
1435 // drop out the middle quad if we're stroked 1425 // drop out the middle quad if we're stroked
1436 int indicesPerInstance = fStroked ? kIndicesPerStrokeRRect : kIndicesPer RRect; 1426 int indicesPerInstance = fStroked ? kIndicesPerStrokeRRect : kIndicesPer RRect;
1437 SkAutoTUnref<const GrBuffer> indexBuffer( 1427 SkAutoTUnref<const GrBuffer> indexBuffer(
1438 ref_rrect_index_buffer(fStroked, target->resourceProvider())); 1428 ref_rrect_index_buffer(fStroked, target->resourceProvider()));
1439 1429
1440 InstancedHelper helper; 1430 InstancedHelper helper;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 verts++; 1489 verts++;
1500 1490
1501 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); 1491 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]);
1502 verts->fColor = color; 1492 verts->fColor = color;
1503 verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); 1493 verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]);
1504 verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); 1494 verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip);
1505 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadReci p); 1495 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadReci p);
1506 verts++; 1496 verts++;
1507 } 1497 }
1508 } 1498 }
1509 helper.recordDraw(target); 1499 helper.recordDraw(target, gp);
1510 } 1500 }
1511 1501
1512 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { 1502 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
1513 RRectEllipseRendererBatch* that = t->cast<RRectEllipseRendererBatch>(); 1503 RRectEllipseRendererBatch* that = t->cast<RRectEllipseRendererBatch>();
1514 1504
1515 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(), 1505 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(),
1516 that->bounds(), caps)) { 1506 that->bounds(), caps)) {
1517 return false; 1507 return false;
1518 } 1508 }
1519 1509
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 } 1714 }
1725 1715
1726 DRAW_BATCH_TEST_DEFINE(RRectBatch) { 1716 DRAW_BATCH_TEST_DEFINE(RRectBatch) {
1727 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); 1717 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random);
1728 GrColor color = GrRandomColor(random); 1718 GrColor color = GrRandomColor(random);
1729 const SkRRect& rrect = GrTest::TestRRectSimple(random); 1719 const SkRRect& rrect = GrTest::TestRRectSimple(random);
1730 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom)); 1720 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom));
1731 } 1721 }
1732 1722
1733 #endif 1723 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698