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/GrAAConvexPathRenderer.cpp

Issue 1286043004: Make GrVertexBatch objects hold their own draws during GrDrawTarget flush (Closed) Base URL: https://skia.googlesource.com/skia.git@m
Patch Set: forward decl Created 5 years, 4 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 | « gyp/gpu.gypi ('k') | src/gpu/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 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrAAConvexPathRenderer.h" 9 #include "GrAAConvexPathRenderer.h"
10 10
11 #include "GrAAConvexTessellator.h" 11 #include "GrAAConvexTessellator.h"
12 #include "GrBatchTarget.h" 12 #include "GrBatchFlushState.h"
13 #include "GrBatchTest.h" 13 #include "GrBatchTest.h"
14 #include "GrCaps.h" 14 #include "GrCaps.h"
15 #include "GrContext.h" 15 #include "GrContext.h"
16 #include "GrDefaultGeoProcFactory.h" 16 #include "GrDefaultGeoProcFactory.h"
17 #include "GrGeometryProcessor.h" 17 #include "GrGeometryProcessor.h"
18 #include "GrInvariantOutput.h" 18 #include "GrInvariantOutput.h"
19 #include "GrPathUtils.h" 19 #include "GrPathUtils.h"
20 #include "GrProcessor.h" 20 #include "GrProcessor.h"
21 #include "GrPipelineBuilder.h" 21 #include "GrPipelineBuilder.h"
22 #include "GrStrokeInfo.h" 22 #include "GrStrokeInfo.h"
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 770
771 // setup batch properties 771 // setup batch properties
772 fBatch.fColorIgnored = !opt.readsColor(); 772 fBatch.fColorIgnored = !opt.readsColor();
773 fBatch.fColor = fGeoData[0].fColor; 773 fBatch.fColor = fGeoData[0].fColor;
774 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); 774 fBatch.fUsesLocalCoords = opt.readsLocalCoords();
775 fBatch.fCoverageIgnored = !opt.readsCoverage(); 775 fBatch.fCoverageIgnored = !opt.readsCoverage();
776 fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSe gmentMasks(); 776 fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSe gmentMasks();
777 fBatch.fCanTweakAlphaForCoverage = opt.canTweakAlphaForCoverage(); 777 fBatch.fCanTweakAlphaForCoverage = opt.canTweakAlphaForCoverage();
778 } 778 }
779 779
780 void generateGeometryLinesOnly(GrBatchTarget* batchTarget) { 780 void prepareLinesOnlyDraws(Target* target) {
781 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); 781 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
782 782
783 // Setup GrGeometryProcessor 783 // Setup GrGeometryProcessor
784 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF orCoverage, 784 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF orCoverage,
785 this->viewMatr ix(), 785 this->viewMatr ix(),
786 this->usesLoca lCoords(), 786 this->usesLoca lCoords(),
787 this->coverage Ignored())); 787 this->coverage Ignored()));
788 if (!gp) { 788 if (!gp) {
789 SkDebugf("Could not create GrGeometryProcessor\n"); 789 SkDebugf("Could not create GrGeometryProcessor\n");
790 return; 790 return;
791 } 791 }
792 792
793 batchTarget->initDraw(gp, this->pipeline()); 793 target->initDraw(gp, this->pipeline());
794 794
795 size_t vertexStride = gp->getVertexStride(); 795 size_t vertexStride = gp->getVertexStride();
796 796
797 SkASSERT(canTweakAlphaForCoverage ? 797 SkASSERT(canTweakAlphaForCoverage ?
798 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) : 798 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) :
799 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr)); 799 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr));
800 800
801 GrAAConvexTessellator tess; 801 GrAAConvexTessellator tess;
802 802
803 int instanceCount = fGeoData.count(); 803 int instanceCount = fGeoData.count();
804 804
805 for (int i = 0; i < instanceCount; i++) { 805 for (int i = 0; i < instanceCount; i++) {
806 tess.rewind(); 806 tess.rewind();
807 807
808 Geometry& args = fGeoData[i]; 808 Geometry& args = fGeoData[i];
809 809
810 if (!tess.tessellate(args.fViewMatrix, args.fPath)) { 810 if (!tess.tessellate(args.fViewMatrix, args.fPath)) {
811 continue; 811 continue;
812 } 812 }
813 813
814 const GrVertexBuffer* vertexBuffer; 814 const GrVertexBuffer* vertexBuffer;
815 int firstVertex; 815 int firstVertex;
816 816
817 void* verts = batchTarget->makeVertSpace(vertexStride, tess.numPts() , 817 void* verts = target->makeVertexSpace(vertexStride, tess.numPts(), & vertexBuffer,
818 &vertexBuffer, &firstVertex ); 818 &firstVertex);
819 if (!verts) { 819 if (!verts) {
820 SkDebugf("Could not allocate vertices\n"); 820 SkDebugf("Could not allocate vertices\n");
821 return; 821 return;
822 } 822 }
823 823
824 const GrIndexBuffer* indexBuffer; 824 const GrIndexBuffer* indexBuffer;
825 int firstIndex; 825 int firstIndex;
826 826
827 uint16_t* idxs = batchTarget->makeIndexSpace(tess.numIndices(), 827 uint16_t* idxs = target->makeIndexSpace(tess.numIndices(), &indexBuf fer, &firstIndex);
828 &indexBuffer, &firstInde x);
829 if (!idxs) { 828 if (!idxs) {
830 SkDebugf("Could not allocate indices\n"); 829 SkDebugf("Could not allocate indices\n");
831 return; 830 return;
832 } 831 }
833 832
834 extract_verts(tess, verts, vertexStride, args.fColor, idxs, canTweak AlphaForCoverage); 833 extract_verts(tess, verts, vertexStride, args.fColor, idxs, canTweak AlphaForCoverage);
835 834
836 GrVertices info; 835 GrVertices info;
837 info.initIndexed(kTriangles_GrPrimitiveType, 836 info.initIndexed(kTriangles_GrPrimitiveType,
838 vertexBuffer, indexBuffer, 837 vertexBuffer, indexBuffer,
839 firstVertex, firstIndex, 838 firstVertex, firstIndex,
840 tess.numPts(), tess.numIndices()); 839 tess.numPts(), tess.numIndices());
841 batchTarget->draw(info); 840 target->draw(info);
842 } 841 }
843 } 842 }
844 843
845 void generateGeometry(GrBatchTarget* batchTarget) override { 844 void onPrepareDraws(Target* target) override {
846 #ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS 845 #ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS
847 if (this->linesOnly()) { 846 if (this->linesOnly()) {
848 this->generateGeometryLinesOnly(batchTarget); 847 this->prepareLinesOnlyDraws(target);
849 return; 848 return;
850 } 849 }
851 #endif 850 #endif
852 851
853 int instanceCount = fGeoData.count(); 852 int instanceCount = fGeoData.count();
854 853
855 SkMatrix invert; 854 SkMatrix invert;
856 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { 855 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) {
857 SkDebugf("Could not invert viewmatrix\n"); 856 SkDebugf("Could not invert viewmatrix\n");
858 return; 857 return;
859 } 858 }
860 859
861 // Setup GrGeometryProcessor 860 // Setup GrGeometryProcessor
862 SkAutoTUnref<GrGeometryProcessor> quadProcessor( 861 SkAutoTUnref<GrGeometryProcessor> quadProcessor(
863 QuadEdgeEffect::Create(this->color(), invert, this->usesLocalCoo rds())); 862 QuadEdgeEffect::Create(this->color(), invert, this->usesLocalCoo rds()));
864 863
865 batchTarget->initDraw(quadProcessor, this->pipeline()); 864 target->initDraw(quadProcessor, this->pipeline());
866 865
867 // TODO generate all segments for all paths and use one vertex buffer 866 // TODO generate all segments for all paths and use one vertex buffer
868 for (int i = 0; i < instanceCount; i++) { 867 for (int i = 0; i < instanceCount; i++) {
869 Geometry& args = fGeoData[i]; 868 Geometry& args = fGeoData[i];
870 869
871 // We use the fact that SkPath::transform path does subdivision base d on 870 // We use the fact that SkPath::transform path does subdivision base d on
872 // perspective. Otherwise, we apply the view matrix when copying to the 871 // perspective. Otherwise, we apply the view matrix when copying to the
873 // segment representation. 872 // segment representation.
874 const SkMatrix* viewMatrix = &args.fViewMatrix; 873 const SkMatrix* viewMatrix = &args.fViewMatrix;
875 if (viewMatrix->hasPerspective()) { 874 if (viewMatrix->hasPerspective()) {
(...skipping 12 matching lines...) Expand all
888 887
889 if (!get_segments(args.fPath, *viewMatrix, &segments, &fanPt, &verte xCount, 888 if (!get_segments(args.fPath, *viewMatrix, &segments, &fanPt, &verte xCount,
890 &indexCount)) { 889 &indexCount)) {
891 continue; 890 continue;
892 } 891 }
893 892
894 const GrVertexBuffer* vertexBuffer; 893 const GrVertexBuffer* vertexBuffer;
895 int firstVertex; 894 int firstVertex;
896 895
897 size_t vertexStride = quadProcessor->getVertexStride(); 896 size_t vertexStride = quadProcessor->getVertexStride();
898 QuadVertex* verts = reinterpret_cast<QuadVertex*>(batchTarget->makeV ertSpace( 897 QuadVertex* verts = reinterpret_cast<QuadVertex*>(target->makeVertex Space(
899 vertexStride, vertexCount, &vertexBuffer, &firstVertex)); 898 vertexStride, vertexCount, &vertexBuffer, &firstVertex));
900 899
901 if (!verts) { 900 if (!verts) {
902 SkDebugf("Could not allocate vertices\n"); 901 SkDebugf("Could not allocate vertices\n");
903 return; 902 return;
904 } 903 }
905 904
906 const GrIndexBuffer* indexBuffer; 905 const GrIndexBuffer* indexBuffer;
907 int firstIndex; 906 int firstIndex;
908 907
909 uint16_t *idxs = batchTarget->makeIndexSpace(indexCount, &indexBuffe r, &firstIndex); 908 uint16_t *idxs = target->makeIndexSpace(indexCount, &indexBuffer, &f irstIndex);
910 if (!idxs) { 909 if (!idxs) {
911 SkDebugf("Could not allocate indices\n"); 910 SkDebugf("Could not allocate indices\n");
912 return; 911 return;
913 } 912 }
914 913
915 SkSTArray<kPreallocDrawCnt, Draw, true> draws; 914 SkSTArray<kPreallocDrawCnt, Draw, true> draws;
916 create_vertices(segments, fanPt, &draws, verts, idxs); 915 create_vertices(segments, fanPt, &draws, verts, idxs);
917 916
918 GrVertices vertices; 917 GrVertices vertices;
919 918
920 for (int i = 0; i < draws.count(); ++i) { 919 for (int i = 0; i < draws.count(); ++i) {
921 const Draw& draw = draws[i]; 920 const Draw& draw = draws[i];
922 vertices.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, i ndexBuffer, 921 vertices.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, i ndexBuffer,
923 firstVertex, firstIndex, draw.fVertexCnt, d raw.fIndexCnt); 922 firstVertex, firstIndex, draw.fVertexCnt, d raw.fIndexCnt);
924 batchTarget->draw(vertices); 923 target->draw(vertices);
925 firstVertex += draw.fVertexCnt; 924 firstVertex += draw.fVertexCnt;
926 firstIndex += draw.fIndexCnt; 925 firstIndex += draw.fIndexCnt;
927 } 926 }
928 } 927 }
929 } 928 }
930 929
931 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 930 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
932 931
933 private: 932 private:
934 AAConvexPathBatch(const Geometry& geometry) { 933 AAConvexPathBatch(const Geometry& geometry) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) { 1014 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) {
1016 AAConvexPathBatch::Geometry geometry; 1015 AAConvexPathBatch::Geometry geometry;
1017 geometry.fColor = GrRandomColor(random); 1016 geometry.fColor = GrRandomColor(random);
1018 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); 1017 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random);
1019 geometry.fPath = GrTest::TestPathConvex(random); 1018 geometry.fPath = GrTest::TestPathConvex(random);
1020 1019
1021 return AAConvexPathBatch::Create(geometry); 1020 return AAConvexPathBatch::Create(geometry);
1022 } 1021 }
1023 1022
1024 #endif 1023 #endif
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | src/gpu/GrAADistanceFieldPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698