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

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

Issue 1483103003: Make onPrepareDraws const (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: merge Created 5 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/GrPathUtils.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 /* 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
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 771
772 // setup batch properties 772 // setup batch properties
773 fBatch.fColorIgnored = !overrides.readsColor(); 773 fBatch.fColorIgnored = !overrides.readsColor();
774 fBatch.fColor = fGeoData[0].fColor; 774 fBatch.fColor = fGeoData[0].fColor;
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) { 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 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF orCoverage,
786 this->viewMatr ix(), 786 this->viewMatr ix(),
787 this->usesLoca lCoords(), 787 this->usesLoca lCoords(),
788 this->coverage Ignored())); 788 this->coverage Ignored()));
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 target->initDraw(gp, this->pipeline()); 794 target->initDraw(gp, this->pipeline());
795 795
796 size_t vertexStride = gp->getVertexStride(); 796 size_t vertexStride = gp->getVertexStride();
797 797
798 SkASSERT(canTweakAlphaForCoverage ? 798 SkASSERT(canTweakAlphaForCoverage ?
799 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) : 799 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) :
800 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr)); 800 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr));
801 801
802 GrAAConvexTessellator tess; 802 GrAAConvexTessellator tess;
803 803
804 int instanceCount = fGeoData.count(); 804 int instanceCount = fGeoData.count();
805 805
806 for (int i = 0; i < instanceCount; i++) { 806 for (int i = 0; i < instanceCount; i++) {
807 tess.rewind(); 807 tess.rewind();
808 808
809 Geometry& args = fGeoData[i]; 809 const Geometry& args = fGeoData[i];
810 810
811 if (!tess.tessellate(args.fViewMatrix, args.fPath)) { 811 if (!tess.tessellate(args.fViewMatrix, args.fPath)) {
812 continue; 812 continue;
813 } 813 }
814 814
815 const GrVertexBuffer* vertexBuffer; 815 const GrVertexBuffer* vertexBuffer;
816 int firstVertex; 816 int firstVertex;
817 817
818 void* verts = target->makeVertexSpace(vertexStride, tess.numPts(), & vertexBuffer, 818 void* verts = target->makeVertexSpace(vertexStride, tess.numPts(), & vertexBuffer,
819 &firstVertex); 819 &firstVertex);
(...skipping 15 matching lines...) Expand all
835 835
836 GrVertices info; 836 GrVertices info;
837 info.initIndexed(kTriangles_GrPrimitiveType, 837 info.initIndexed(kTriangles_GrPrimitiveType,
838 vertexBuffer, indexBuffer, 838 vertexBuffer, indexBuffer,
839 firstVertex, firstIndex, 839 firstVertex, firstIndex,
840 tess.numPts(), tess.numIndices()); 840 tess.numPts(), tess.numIndices());
841 target->draw(info); 841 target->draw(info);
842 } 842 }
843 } 843 }
844 844
845 void onPrepareDraws(Target* target) override { 845 void onPrepareDraws(Target* target) const override {
846 #ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS 846 #ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS
847 if (this->linesOnly()) { 847 if (this->linesOnly()) {
848 this->prepareLinesOnlyDraws(target); 848 this->prepareLinesOnlyDraws(target);
849 return; 849 return;
850 } 850 }
851 #endif 851 #endif
852 852
853 int instanceCount = fGeoData.count(); 853 int instanceCount = fGeoData.count();
854 854
855 SkMatrix invert; 855 SkMatrix invert;
856 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { 856 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) {
857 SkDebugf("Could not invert viewmatrix\n"); 857 SkDebugf("Could not invert viewmatrix\n");
858 return; 858 return;
859 } 859 }
860 860
861 // Setup GrGeometryProcessor 861 // Setup GrGeometryProcessor
862 SkAutoTUnref<GrGeometryProcessor> quadProcessor( 862 SkAutoTUnref<GrGeometryProcessor> quadProcessor(
863 QuadEdgeEffect::Create(this->color(), invert, this->usesLocalCoo rds())); 863 QuadEdgeEffect::Create(this->color(), invert, this->usesLocalCoo rds()));
864 864
865 target->initDraw(quadProcessor, this->pipeline()); 865 target->initDraw(quadProcessor, this->pipeline());
866 866
867 // TODO generate all segments for all paths and use one vertex buffer 867 // TODO generate all segments for all paths and use one vertex buffer
868 for (int i = 0; i < instanceCount; i++) { 868 for (int i = 0; i < instanceCount; i++) {
869 Geometry& args = fGeoData[i]; 869 const Geometry& args = fGeoData[i];
870 870
871 // We use the fact that SkPath::transform path does subdivision base d on 871 // 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 872 // perspective. Otherwise, we apply the view matrix when copying to the
873 // segment representation. 873 // segment representation.
874 const SkMatrix* viewMatrix = &args.fViewMatrix; 874 const SkMatrix* viewMatrix = &args.fViewMatrix;
875
876 // We avoid initializing the path unless we have to
877 const SkPath* pathPtr = &args.fPath;
878 SkTLazy<SkPath> tmpPath;
875 if (viewMatrix->hasPerspective()) { 879 if (viewMatrix->hasPerspective()) {
876 args.fPath.transform(*viewMatrix); 880 SkPath* tmpPathPtr = tmpPath.init(*pathPtr);
881 tmpPathPtr->setIsVolatile(true);
882 tmpPathPtr->transform(*viewMatrix);
877 viewMatrix = &SkMatrix::I(); 883 viewMatrix = &SkMatrix::I();
884 pathPtr = tmpPathPtr;
878 } 885 }
879 886
880 int vertexCount; 887 int vertexCount;
881 int indexCount; 888 int indexCount;
882 enum { 889 enum {
883 kPreallocSegmentCnt = 512 / sizeof(Segment), 890 kPreallocSegmentCnt = 512 / sizeof(Segment),
884 kPreallocDrawCnt = 4, 891 kPreallocDrawCnt = 4,
885 }; 892 };
886 SkSTArray<kPreallocSegmentCnt, Segment, true> segments; 893 SkSTArray<kPreallocSegmentCnt, Segment, true> segments;
887 SkPoint fanPt; 894 SkPoint fanPt;
888 895
889 if (!get_segments(args.fPath, *viewMatrix, &segments, &fanPt, &verte xCount, 896 if (!get_segments(*pathPtr, *viewMatrix, &segments, &fanPt, &vertexC ount,
890 &indexCount)) { 897 &indexCount)) {
891 continue; 898 continue;
892 } 899 }
893 900
894 const GrVertexBuffer* vertexBuffer; 901 const GrVertexBuffer* vertexBuffer;
895 int firstVertex; 902 int firstVertex;
896 903
897 size_t vertexStride = quadProcessor->getVertexStride(); 904 size_t vertexStride = quadProcessor->getVertexStride();
898 QuadVertex* verts = reinterpret_cast<QuadVertex*>(target->makeVertex Space( 905 QuadVertex* verts = reinterpret_cast<QuadVertex*>(target->makeVertex Space(
899 vertexStride, vertexCount, &vertexBuffer, &firstVertex)); 906 vertexStride, vertexCount, &vertexBuffer, &firstVertex));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) { 1022 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) {
1016 AAConvexPathBatch::Geometry geometry; 1023 AAConvexPathBatch::Geometry geometry;
1017 geometry.fColor = GrRandomColor(random); 1024 geometry.fColor = GrRandomColor(random);
1018 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); 1025 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random);
1019 geometry.fPath = GrTest::TestPathConvex(random); 1026 geometry.fPath = GrTest::TestPathConvex(random);
1020 1027
1021 return AAConvexPathBatch::Create(geometry); 1028 return AAConvexPathBatch::Create(geometry);
1022 } 1029 }
1023 1030
1024 #endif 1031 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrPathUtils.h ('k') | src/gpu/batches/GrAADistanceFieldPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698