OLD | NEW |
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 "GrBatch.h" | 10 #include "GrBatch.h" |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch | 737 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
738 // everywhere we can remove this nastiness | 738 // everywhere we can remove this nastiness |
739 GrPipelineInfo init; | 739 GrPipelineInfo init; |
740 init.fColorIgnored = fBatch.fColorIgnored; | 740 init.fColorIgnored = fBatch.fColorIgnored; |
741 init.fOverrideColor = GrColor_ILLEGAL; | 741 init.fOverrideColor = GrColor_ILLEGAL; |
742 init.fCoverageIgnored = fBatch.fCoverageIgnored; | 742 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
743 init.fUsesLocalCoords = this->usesLocalCoords(); | 743 init.fUsesLocalCoords = this->usesLocalCoords(); |
744 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); | 744 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
745 | 745 |
746 int instanceCount = fGeoData.count(); | 746 int instanceCount = fGeoData.count(); |
747 int vertexCount = kVertsPerCircle * instanceCount; | |
748 size_t vertexStride = gp->getVertexStride(); | 747 size_t vertexStride = gp->getVertexStride(); |
749 SkASSERT(vertexStride == sizeof(CircleVertex)); | 748 SkASSERT(vertexStride == sizeof(CircleVertex)); |
750 | 749 QuadHelper helper; |
751 SkAutoTUnref<const GrIndexBuffer> indexBuffer( | 750 CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(batchT
arget, vertexStride, |
752 batchTarget->resourceProvider()->refQuadIndexBuffer()); | 751 instan
ceCount)); |
753 const GrVertexBuffer* vertexBuffer; | 752 if (!verts) { |
754 int firstVertex; | |
755 | |
756 void *vertices = batchTarget->vertexPool()->makeSpace(vertexStride, | |
757 vertexCount, | |
758 &vertexBuffer, | |
759 &firstVertex); | |
760 | |
761 if (!vertices || !indexBuffer) { | |
762 SkDebugf("Could not allocate buffers\n"); | |
763 return; | 753 return; |
764 } | 754 } |
765 | 755 |
766 CircleVertex* verts = reinterpret_cast<CircleVertex*>(vertices); | 756 for (int i = 0; i < instanceCount; i++) { |
| 757 Geometry& geom = fGeoData[i]; |
767 | 758 |
768 for (int i = 0; i < instanceCount; i++) { | 759 SkScalar innerRadius = geom.fInnerRadius; |
769 Geometry& args = fGeoData[i]; | 760 SkScalar outerRadius = geom.fOuterRadius; |
770 | 761 |
771 SkScalar innerRadius = args.fInnerRadius; | 762 const SkRect& bounds = geom.fDevBounds; |
772 SkScalar outerRadius = args.fOuterRadius; | |
773 | |
774 const SkRect& bounds = args.fDevBounds; | |
775 | 763 |
776 // The inner radius in the vertex data must be specified in normaliz
ed space. | 764 // The inner radius in the vertex data must be specified in normaliz
ed space. |
777 innerRadius = innerRadius / outerRadius; | 765 innerRadius = innerRadius / outerRadius; |
778 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); | 766 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
779 verts[0].fOffset = SkPoint::Make(-1, -1); | 767 verts[0].fOffset = SkPoint::Make(-1, -1); |
780 verts[0].fOuterRadius = outerRadius; | 768 verts[0].fOuterRadius = outerRadius; |
781 verts[0].fInnerRadius = innerRadius; | 769 verts[0].fInnerRadius = innerRadius; |
782 | 770 |
783 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); | 771 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
784 verts[1].fOffset = SkPoint::Make(-1, 1); | 772 verts[1].fOffset = SkPoint::Make(-1, 1); |
785 verts[1].fOuterRadius = outerRadius; | 773 verts[1].fOuterRadius = outerRadius; |
786 verts[1].fInnerRadius = innerRadius; | 774 verts[1].fInnerRadius = innerRadius; |
787 | 775 |
788 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); | 776 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
789 verts[2].fOffset = SkPoint::Make(1, 1); | 777 verts[2].fOffset = SkPoint::Make(1, 1); |
790 verts[2].fOuterRadius = outerRadius; | 778 verts[2].fOuterRadius = outerRadius; |
791 verts[2].fInnerRadius = innerRadius; | 779 verts[2].fInnerRadius = innerRadius; |
792 | 780 |
793 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); | 781 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
794 verts[3].fOffset = SkPoint::Make(1, -1); | 782 verts[3].fOffset = SkPoint::Make(1, -1); |
795 verts[3].fOuterRadius = outerRadius; | 783 verts[3].fOuterRadius = outerRadius; |
796 verts[3].fInnerRadius = innerRadius; | 784 verts[3].fInnerRadius = innerRadius; |
797 | 785 |
798 verts += kVertsPerCircle; | 786 verts += kVerticesPerQuad; |
799 } | 787 } |
800 | 788 helper.issueDraws(batchTarget); |
801 GrDrawTarget::DrawInfo drawInfo; | |
802 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); | |
803 drawInfo.setStartVertex(0); | |
804 drawInfo.setStartIndex(0); | |
805 drawInfo.setVerticesPerInstance(kVertsPerCircle); | |
806 drawInfo.setIndicesPerInstance(kIndicesPerCircle); | |
807 drawInfo.adjustStartVertex(firstVertex); | |
808 drawInfo.setVertexBuffer(vertexBuffer); | |
809 drawInfo.setIndexBuffer(indexBuffer); | |
810 | |
811 int maxInstancesPerDraw = indexBuffer->maxQuads(); | |
812 | |
813 while (instanceCount) { | |
814 drawInfo.setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw)
); | |
815 drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.vertices
PerInstance()); | |
816 drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPe
rInstance()); | |
817 | |
818 batchTarget->draw(drawInfo); | |
819 | |
820 drawInfo.setStartVertex(drawInfo.startVertex() + drawInfo.vertexCoun
t()); | |
821 instanceCount -= drawInfo.instanceCount(); | |
822 } | |
823 } | 789 } |
824 | 790 |
825 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 791 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
826 | 792 |
827 private: | 793 private: |
828 CircleBatch(const Geometry& geometry) { | 794 CircleBatch(const Geometry& geometry) { |
829 this->initClassID<CircleBatch>(); | 795 this->initClassID<CircleBatch>(); |
830 fGeoData.push_back(geometry); | 796 fGeoData.push_back(geometry); |
831 | 797 |
832 this->setBounds(geometry.fDevBounds); | 798 this->setBounds(geometry.fDevBounds); |
(...skipping 27 matching lines...) Expand all Loading... |
860 bool stroke() const { return fBatch.fStroke; } | 826 bool stroke() const { return fBatch.fStroke; } |
861 | 827 |
862 struct BatchTracker { | 828 struct BatchTracker { |
863 GrColor fColor; | 829 GrColor fColor; |
864 bool fStroke; | 830 bool fStroke; |
865 bool fUsesLocalCoords; | 831 bool fUsesLocalCoords; |
866 bool fColorIgnored; | 832 bool fColorIgnored; |
867 bool fCoverageIgnored; | 833 bool fCoverageIgnored; |
868 }; | 834 }; |
869 | 835 |
870 static const int kVertsPerCircle = 4; | |
871 static const int kIndicesPerCircle = 6; | |
872 | |
873 BatchTracker fBatch; | 836 BatchTracker fBatch; |
874 SkSTArray<1, Geometry, true> fGeoData; | 837 SkSTArray<1, Geometry, true> fGeoData; |
875 }; | 838 }; |
876 | 839 |
877 static GrBatch* create_circle_batch(GrColor color, | 840 static GrBatch* create_circle_batch(GrColor color, |
878 const SkMatrix& viewMatrix, | 841 const SkMatrix& viewMatrix, |
879 bool useCoverageAA, | 842 bool useCoverageAA, |
880 const SkRect& circle, | 843 const SkRect& circle, |
881 const SkStrokeRec& stroke, | 844 const SkStrokeRec& stroke, |
882 SkRect* bounds) { | 845 SkRect* bounds) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch | 965 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
1003 // everywhere we can remove this nastiness | 966 // everywhere we can remove this nastiness |
1004 GrPipelineInfo init; | 967 GrPipelineInfo init; |
1005 init.fColorIgnored = fBatch.fColorIgnored; | 968 init.fColorIgnored = fBatch.fColorIgnored; |
1006 init.fOverrideColor = GrColor_ILLEGAL; | 969 init.fOverrideColor = GrColor_ILLEGAL; |
1007 init.fCoverageIgnored = fBatch.fCoverageIgnored; | 970 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
1008 init.fUsesLocalCoords = this->usesLocalCoords(); | 971 init.fUsesLocalCoords = this->usesLocalCoords(); |
1009 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); | 972 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
1010 | 973 |
1011 int instanceCount = fGeoData.count(); | 974 int instanceCount = fGeoData.count(); |
1012 int vertexCount = kVertsPerEllipse * instanceCount; | 975 QuadHelper helper; |
1013 size_t vertexStride = gp->getVertexStride(); | 976 size_t vertexStride = gp->getVertexStride(); |
1014 SkASSERT(vertexStride == sizeof(EllipseVertex)); | 977 SkASSERT(vertexStride == sizeof(EllipseVertex)); |
1015 | 978 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( |
1016 const GrVertexBuffer* vertexBuffer; | 979 helper.init(batchTarget, vertexStride, instanceCount)); |
1017 SkAutoTUnref<const GrIndexBuffer> indexBuffer( | 980 if (!verts) { |
1018 batchTarget->resourceProvider()->refQuadIndexBuffer()); | |
1019 int firstVertex; | |
1020 | |
1021 void *vertices = batchTarget->vertexPool()->makeSpace(vertexStride, | |
1022 vertexCount, | |
1023 &vertexBuffer, | |
1024 &firstVertex); | |
1025 | |
1026 if (!vertices || !indexBuffer) { | |
1027 SkDebugf("Could not allocate buffers\n"); | |
1028 return; | 981 return; |
1029 } | 982 } |
1030 | 983 |
1031 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(vertices); | 984 for (int i = 0; i < instanceCount; i++) { |
| 985 Geometry& geom = fGeoData[i]; |
1032 | 986 |
1033 for (int i = 0; i < instanceCount; i++) { | 987 SkScalar xRadius = geom.fXRadius; |
1034 Geometry& args = fGeoData[i]; | 988 SkScalar yRadius = geom.fYRadius; |
1035 | |
1036 SkScalar xRadius = args.fXRadius; | |
1037 SkScalar yRadius = args.fYRadius; | |
1038 | 989 |
1039 // Compute the reciprocals of the radii here to save time in the sha
der | 990 // Compute the reciprocals of the radii here to save time in the sha
der |
1040 SkScalar xRadRecip = SkScalarInvert(xRadius); | 991 SkScalar xRadRecip = SkScalarInvert(xRadius); |
1041 SkScalar yRadRecip = SkScalarInvert(yRadius); | 992 SkScalar yRadRecip = SkScalarInvert(yRadius); |
1042 SkScalar xInnerRadRecip = SkScalarInvert(args.fInnerXRadius); | 993 SkScalar xInnerRadRecip = SkScalarInvert(geom.fInnerXRadius); |
1043 SkScalar yInnerRadRecip = SkScalarInvert(args.fInnerYRadius); | 994 SkScalar yInnerRadRecip = SkScalarInvert(geom.fInnerYRadius); |
1044 | 995 |
1045 const SkRect& bounds = args.fDevBounds; | 996 const SkRect& bounds = geom.fDevBounds; |
1046 | 997 |
1047 // The inner radius in the vertex data must be specified in normaliz
ed space. | 998 // The inner radius in the vertex data must be specified in normaliz
ed space. |
1048 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); | 999 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
1049 verts[0].fOffset = SkPoint::Make(-xRadius, -yRadius); | 1000 verts[0].fOffset = SkPoint::Make(-xRadius, -yRadius); |
1050 verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 1001 verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
1051 verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; | 1002 verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; |
1052 | 1003 |
1053 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); | 1004 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
1054 verts[1].fOffset = SkPoint::Make(-xRadius, yRadius); | 1005 verts[1].fOffset = SkPoint::Make(-xRadius, yRadius); |
1055 verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 1006 verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
1056 verts[1].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; | 1007 verts[1].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; |
1057 | 1008 |
1058 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); | 1009 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
1059 verts[2].fOffset = SkPoint::Make(xRadius, yRadius); | 1010 verts[2].fOffset = SkPoint::Make(xRadius, yRadius); |
1060 verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 1011 verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
1061 verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; | 1012 verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; |
1062 | 1013 |
1063 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); | 1014 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
1064 verts[3].fOffset = SkPoint::Make(xRadius, -yRadius); | 1015 verts[3].fOffset = SkPoint::Make(xRadius, -yRadius); |
1065 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 1016 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
1066 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; | 1017 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; |
1067 | 1018 |
1068 verts += kVertsPerEllipse; | 1019 verts += kVerticesPerQuad; |
1069 } | 1020 } |
1070 | 1021 helper.issueDraws(batchTarget); |
1071 GrDrawTarget::DrawInfo drawInfo; | |
1072 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); | |
1073 drawInfo.setStartVertex(0); | |
1074 drawInfo.setStartIndex(0); | |
1075 drawInfo.setVerticesPerInstance(kVertsPerEllipse); | |
1076 drawInfo.setIndicesPerInstance(kIndicesPerEllipse); | |
1077 drawInfo.adjustStartVertex(firstVertex); | |
1078 drawInfo.setVertexBuffer(vertexBuffer); | |
1079 drawInfo.setIndexBuffer(indexBuffer); | |
1080 | |
1081 int maxInstancesPerDraw = indexBuffer->maxQuads(); | |
1082 | |
1083 while (instanceCount) { | |
1084 drawInfo.setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw)
); | |
1085 drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.vertices
PerInstance()); | |
1086 drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPe
rInstance()); | |
1087 | |
1088 batchTarget->draw(drawInfo); | |
1089 | |
1090 drawInfo.setStartVertex(drawInfo.startVertex() + drawInfo.vertexCoun
t()); | |
1091 instanceCount -= drawInfo.instanceCount(); | |
1092 } | |
1093 } | 1022 } |
1094 | 1023 |
1095 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 1024 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
1096 | 1025 |
1097 private: | 1026 private: |
1098 EllipseBatch(const Geometry& geometry) { | 1027 EllipseBatch(const Geometry& geometry) { |
1099 this->initClassID<EllipseBatch>(); | 1028 this->initClassID<EllipseBatch>(); |
1100 fGeoData.push_back(geometry); | 1029 fGeoData.push_back(geometry); |
1101 | 1030 |
1102 this->setBounds(geometry.fDevBounds); | 1031 this->setBounds(geometry.fDevBounds); |
(...skipping 27 matching lines...) Expand all Loading... |
1130 bool stroke() const { return fBatch.fStroke; } | 1059 bool stroke() const { return fBatch.fStroke; } |
1131 | 1060 |
1132 struct BatchTracker { | 1061 struct BatchTracker { |
1133 GrColor fColor; | 1062 GrColor fColor; |
1134 bool fStroke; | 1063 bool fStroke; |
1135 bool fUsesLocalCoords; | 1064 bool fUsesLocalCoords; |
1136 bool fColorIgnored; | 1065 bool fColorIgnored; |
1137 bool fCoverageIgnored; | 1066 bool fCoverageIgnored; |
1138 }; | 1067 }; |
1139 | 1068 |
1140 static const int kVertsPerEllipse = 4; | |
1141 static const int kIndicesPerEllipse = 6; | |
1142 | |
1143 BatchTracker fBatch; | 1069 BatchTracker fBatch; |
1144 SkSTArray<1, Geometry, true> fGeoData; | 1070 SkSTArray<1, Geometry, true> fGeoData; |
1145 }; | 1071 }; |
1146 | 1072 |
1147 static GrBatch* create_ellipse_batch(GrColor color, | 1073 static GrBatch* create_ellipse_batch(GrColor color, |
1148 const SkMatrix& viewMatrix, | 1074 const SkMatrix& viewMatrix, |
1149 bool useCoverageAA, | 1075 bool useCoverageAA, |
1150 const SkRect& ellipse, | 1076 const SkRect& ellipse, |
1151 const SkStrokeRec& stroke, | 1077 const SkStrokeRec& stroke, |
1152 SkRect* bounds) { | 1078 SkRect* bounds) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 // TODO this is hacky, but the only way we have to initialize the GP is
to use the | 1236 // TODO this is hacky, but the only way we have to initialize the GP is
to use the |
1311 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch | 1237 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
1312 // everywhere we can remove this nastiness | 1238 // everywhere we can remove this nastiness |
1313 GrPipelineInfo init; | 1239 GrPipelineInfo init; |
1314 init.fColorIgnored = fBatch.fColorIgnored; | 1240 init.fColorIgnored = fBatch.fColorIgnored; |
1315 init.fOverrideColor = GrColor_ILLEGAL; | 1241 init.fOverrideColor = GrColor_ILLEGAL; |
1316 init.fCoverageIgnored = fBatch.fCoverageIgnored; | 1242 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
1317 init.fUsesLocalCoords = this->usesLocalCoords(); | 1243 init.fUsesLocalCoords = this->usesLocalCoords(); |
1318 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); | 1244 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
1319 | 1245 |
1320 SkAutoTUnref<const GrIndexBuffer> indexBuffer( | |
1321 batchTarget->resourceProvider()->refQuadIndexBuffer()); | |
1322 | |
1323 int instanceCount = fGeoData.count(); | 1246 int instanceCount = fGeoData.count(); |
1324 int vertexCount = kVertsPerEllipse * instanceCount; | |
1325 size_t vertexStride = gp->getVertexStride(); | 1247 size_t vertexStride = gp->getVertexStride(); |
1326 SkASSERT(vertexStride == sizeof(DIEllipseVertex)); | 1248 SkASSERT(vertexStride == sizeof(DIEllipseVertex)); |
1327 const GrVertexBuffer* vertexBuffer; | 1249 QuadHelper helper; |
1328 int firstVertex; | 1250 DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>( |
1329 void *vertices = batchTarget->vertexPool()->makeSpace(vertexStride, | 1251 helper.init(batchTarget, vertexStride, instanceCount)); |
1330 vertexCount, | 1252 if (!verts) { |
1331 &vertexBuffer, | |
1332 &firstVertex); | |
1333 | |
1334 if (!vertices || !indexBuffer) { | |
1335 SkDebugf("Could not allocate buffers\n"); | |
1336 return; | 1253 return; |
1337 } | 1254 } |
1338 | 1255 |
1339 DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>(vertices); | 1256 for (int i = 0; i < instanceCount; i++) { |
| 1257 Geometry& geom = fGeoData[i]; |
1340 | 1258 |
1341 for (int i = 0; i < instanceCount; i++) { | 1259 SkScalar xRadius = geom.fXRadius; |
1342 Geometry& args = fGeoData[i]; | 1260 SkScalar yRadius = geom.fYRadius; |
1343 | 1261 |
1344 SkScalar xRadius = args.fXRadius; | 1262 const SkRect& bounds = geom.fBounds; |
1345 SkScalar yRadius = args.fYRadius; | |
1346 | |
1347 const SkRect& bounds = args.fBounds; | |
1348 | 1263 |
1349 // This adjusts the "radius" to include the half-pixel border | 1264 // This adjusts the "radius" to include the half-pixel border |
1350 SkScalar offsetDx = SkScalarDiv(args.fGeoDx, xRadius); | 1265 SkScalar offsetDx = SkScalarDiv(geom.fGeoDx, xRadius); |
1351 SkScalar offsetDy = SkScalarDiv(args.fGeoDy, yRadius); | 1266 SkScalar offsetDy = SkScalarDiv(geom.fGeoDy, yRadius); |
1352 | 1267 |
1353 SkScalar innerRatioX = SkScalarDiv(xRadius, args.fInnerXRadius); | 1268 SkScalar innerRatioX = SkScalarDiv(xRadius, geom.fInnerXRadius); |
1354 SkScalar innerRatioY = SkScalarDiv(yRadius, args.fInnerYRadius); | 1269 SkScalar innerRatioY = SkScalarDiv(yRadius, geom.fInnerYRadius); |
1355 | 1270 |
1356 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); | 1271 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
1357 verts[0].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, -1.0f - offs
etDy); | 1272 verts[0].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, -1.0f - offs
etDy); |
1358 verts[0].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, -inne
rRatioY - offsetDy); | 1273 verts[0].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, -inne
rRatioY - offsetDy); |
1359 | 1274 |
1360 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); | 1275 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
1361 verts[1].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, 1.0f + offse
tDy); | 1276 verts[1].fOuterOffset = SkPoint::Make(-1.0f - offsetDx, 1.0f + offse
tDy); |
1362 verts[1].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, inner
RatioY + offsetDy); | 1277 verts[1].fInnerOffset = SkPoint::Make(-innerRatioX - offsetDx, inner
RatioY + offsetDy); |
1363 | 1278 |
1364 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); | 1279 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
1365 verts[2].fOuterOffset = SkPoint::Make(1.0f + offsetDx, 1.0f + offset
Dy); | 1280 verts[2].fOuterOffset = SkPoint::Make(1.0f + offsetDx, 1.0f + offset
Dy); |
1366 verts[2].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, innerR
atioY + offsetDy); | 1281 verts[2].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, innerR
atioY + offsetDy); |
1367 | 1282 |
1368 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); | 1283 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
1369 verts[3].fOuterOffset = SkPoint::Make(1.0f + offsetDx, -1.0f - offse
tDy); | 1284 verts[3].fOuterOffset = SkPoint::Make(1.0f + offsetDx, -1.0f - offse
tDy); |
1370 verts[3].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, -inner
RatioY - offsetDy); | 1285 verts[3].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, -inner
RatioY - offsetDy); |
1371 | 1286 |
1372 verts += kVertsPerEllipse; | 1287 verts += kVerticesPerQuad; |
1373 } | 1288 } |
1374 | 1289 helper.issueDraws(batchTarget); |
1375 GrDrawTarget::DrawInfo drawInfo; | |
1376 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); | |
1377 drawInfo.setStartVertex(0); | |
1378 drawInfo.setStartIndex(0); | |
1379 drawInfo.setVerticesPerInstance(kVertsPerEllipse); | |
1380 drawInfo.setIndicesPerInstance(kIndicesPerEllipse); | |
1381 drawInfo.adjustStartVertex(firstVertex); | |
1382 drawInfo.setVertexBuffer(vertexBuffer); | |
1383 drawInfo.setIndexBuffer(indexBuffer); | |
1384 | |
1385 int maxInstancesPerDraw = indexBuffer->maxQuads(); | |
1386 | |
1387 while (instanceCount) { | |
1388 drawInfo.setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw)
); | |
1389 drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.vertices
PerInstance()); | |
1390 drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPe
rInstance()); | |
1391 | |
1392 batchTarget->draw(drawInfo); | |
1393 | |
1394 drawInfo.setStartVertex(drawInfo.startVertex() + drawInfo.vertexCoun
t()); | |
1395 instanceCount -= drawInfo.instanceCount(); | |
1396 } | |
1397 } | 1290 } |
1398 | 1291 |
1399 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 1292 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
1400 | 1293 |
1401 private: | 1294 private: |
1402 DIEllipseBatch(const Geometry& geometry, const SkRect& bounds) { | 1295 DIEllipseBatch(const Geometry& geometry, const SkRect& bounds) { |
1403 this->initClassID<DIEllipseBatch>(); | 1296 this->initClassID<DIEllipseBatch>(); |
1404 fGeoData.push_back(geometry); | 1297 fGeoData.push_back(geometry); |
1405 | 1298 |
1406 this->setBounds(bounds); | 1299 this->setBounds(bounds); |
(...skipping 27 matching lines...) Expand all Loading... |
1434 DIEllipseEdgeEffect::Mode mode() const { return fBatch.fMode; } | 1327 DIEllipseEdgeEffect::Mode mode() const { return fBatch.fMode; } |
1435 | 1328 |
1436 struct BatchTracker { | 1329 struct BatchTracker { |
1437 GrColor fColor; | 1330 GrColor fColor; |
1438 DIEllipseEdgeEffect::Mode fMode; | 1331 DIEllipseEdgeEffect::Mode fMode; |
1439 bool fUsesLocalCoords; | 1332 bool fUsesLocalCoords; |
1440 bool fColorIgnored; | 1333 bool fColorIgnored; |
1441 bool fCoverageIgnored; | 1334 bool fCoverageIgnored; |
1442 }; | 1335 }; |
1443 | 1336 |
1444 static const int kVertsPerEllipse = 4; | |
1445 static const int kIndicesPerEllipse = 6; | |
1446 | |
1447 BatchTracker fBatch; | 1337 BatchTracker fBatch; |
1448 SkSTArray<1, Geometry, true> fGeoData; | 1338 SkSTArray<1, Geometry, true> fGeoData; |
1449 }; | 1339 }; |
1450 | 1340 |
1451 static GrBatch* create_diellipse_batch(GrColor color, | 1341 static GrBatch* create_diellipse_batch(GrColor color, |
1452 const SkMatrix& viewMatrix, | 1342 const SkMatrix& viewMatrix, |
1453 bool useCoverageAA, | 1343 bool useCoverageAA, |
1454 const SkRect& ellipse, | 1344 const SkRect& ellipse, |
1455 const SkStrokeRec& stroke, | 1345 const SkStrokeRec& stroke, |
1456 SkRect* bounds) { | 1346 SkRect* bounds) { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1715 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch | 1605 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
1716 // everywhere we can remove this nastiness | 1606 // everywhere we can remove this nastiness |
1717 GrPipelineInfo init; | 1607 GrPipelineInfo init; |
1718 init.fColorIgnored = fBatch.fColorIgnored; | 1608 init.fColorIgnored = fBatch.fColorIgnored; |
1719 init.fOverrideColor = GrColor_ILLEGAL; | 1609 init.fOverrideColor = GrColor_ILLEGAL; |
1720 init.fCoverageIgnored = fBatch.fCoverageIgnored; | 1610 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
1721 init.fUsesLocalCoords = this->usesLocalCoords(); | 1611 init.fUsesLocalCoords = this->usesLocalCoords(); |
1722 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); | 1612 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
1723 | 1613 |
1724 int instanceCount = fGeoData.count(); | 1614 int instanceCount = fGeoData.count(); |
1725 int vertexCount = kVertsPerRRect * instanceCount; | |
1726 size_t vertexStride = gp->getVertexStride(); | 1615 size_t vertexStride = gp->getVertexStride(); |
1727 SkASSERT(vertexStride == sizeof(CircleVertex)); | 1616 SkASSERT(vertexStride == sizeof(CircleVertex)); |
1728 | 1617 |
1729 const GrVertexBuffer* vertexBuffer; | 1618 // drop out the middle quad if we're stroked |
| 1619 int indicesPerInstance = this->stroke() ? kIndicesPerStrokeRRect : kIndi
cesPerRRect; |
1730 SkAutoTUnref<const GrIndexBuffer> indexBuffer( | 1620 SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
1731 ref_rrect_index_buffer(this->stroke(), batchTarget->resourceProvider
())); | 1621 ref_rrect_index_buffer(this->stroke(), batchTarget->resourceProvider
())); |
1732 int firstVertex; | |
1733 | 1622 |
1734 void *vertices = batchTarget->vertexPool()->makeSpace(vertexStride, | 1623 InstancedHelper helper; |
1735 vertexCount, | 1624 CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(batchT
arget, |
1736 &vertexBuffer, | 1625 vertexStride, indexBuffer, kVertsPerRRect, indicesPerInstance, insta
nceCount)); |
1737 &firstVertex); | 1626 if (!verts || !indexBuffer) { |
1738 | |
1739 if (!vertices || !indexBuffer) { | |
1740 SkDebugf("Could not allocate vertices\n"); | 1627 SkDebugf("Could not allocate vertices\n"); |
1741 return; | 1628 return; |
1742 } | 1629 } |
1743 | 1630 |
1744 CircleVertex* verts = reinterpret_cast<CircleVertex*>(vertices); | |
1745 | |
1746 for (int i = 0; i < instanceCount; i++) { | 1631 for (int i = 0; i < instanceCount; i++) { |
1747 Geometry& args = fGeoData[i]; | 1632 Geometry& args = fGeoData[i]; |
1748 | 1633 |
1749 SkScalar outerRadius = args.fOuterRadius; | 1634 SkScalar outerRadius = args.fOuterRadius; |
1750 | 1635 |
1751 const SkRect& bounds = args.fDevBounds; | 1636 const SkRect& bounds = args.fDevBounds; |
1752 | 1637 |
1753 SkScalar yCoords[4] = { | 1638 SkScalar yCoords[4] = { |
1754 bounds.fTop, | 1639 bounds.fTop, |
1755 bounds.fTop + outerRadius, | 1640 bounds.fTop + outerRadius, |
(...skipping 24 matching lines...) Expand all Loading... |
1780 verts++; | 1665 verts++; |
1781 | 1666 |
1782 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); | 1667 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); |
1783 verts->fOffset = SkPoint::Make(1, yOuterRadii[i]); | 1668 verts->fOffset = SkPoint::Make(1, yOuterRadii[i]); |
1784 verts->fOuterRadius = outerRadius; | 1669 verts->fOuterRadius = outerRadius; |
1785 verts->fInnerRadius = innerRadius; | 1670 verts->fInnerRadius = innerRadius; |
1786 verts++; | 1671 verts++; |
1787 } | 1672 } |
1788 } | 1673 } |
1789 | 1674 |
1790 // drop out the middle quad if we're stroked | 1675 helper.issueDraws(batchTarget); |
1791 int indexCnt = this->stroke() ? SK_ARRAY_COUNT(gRRectIndices) - 6 : | |
1792 SK_ARRAY_COUNT(gRRectIndices); | |
1793 | |
1794 GrDrawTarget::DrawInfo drawInfo; | |
1795 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); | |
1796 drawInfo.setStartVertex(0); | |
1797 drawInfo.setStartIndex(0); | |
1798 drawInfo.setVerticesPerInstance(kVertsPerRRect); | |
1799 drawInfo.setIndicesPerInstance(indexCnt); | |
1800 drawInfo.adjustStartVertex(firstVertex); | |
1801 drawInfo.setVertexBuffer(vertexBuffer); | |
1802 drawInfo.setIndexBuffer(indexBuffer); | |
1803 | |
1804 int maxInstancesPerDraw = kNumRRectsInIndexBuffer; | |
1805 | |
1806 while (instanceCount) { | |
1807 drawInfo.setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw)
); | |
1808 drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.vertices
PerInstance()); | |
1809 drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPe
rInstance()); | |
1810 | |
1811 batchTarget->draw(drawInfo); | |
1812 | |
1813 drawInfo.setStartVertex(drawInfo.startVertex() + drawInfo.vertexCoun
t()); | |
1814 instanceCount -= drawInfo.instanceCount(); | |
1815 } | |
1816 } | 1676 } |
1817 | 1677 |
1818 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 1678 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
1819 | 1679 |
1820 private: | 1680 private: |
1821 RRectCircleRendererBatch(const Geometry& geometry) { | 1681 RRectCircleRendererBatch(const Geometry& geometry) { |
1822 this->initClassID<RRectCircleRendererBatch>(); | 1682 this->initClassID<RRectCircleRendererBatch>(); |
1823 fGeoData.push_back(geometry); | 1683 fGeoData.push_back(geometry); |
1824 | 1684 |
1825 this->setBounds(geometry.fDevBounds); | 1685 this->setBounds(geometry.fDevBounds); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1926 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch | 1786 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
1927 // everywhere we can remove this nastiness | 1787 // everywhere we can remove this nastiness |
1928 GrPipelineInfo init; | 1788 GrPipelineInfo init; |
1929 init.fColorIgnored = fBatch.fColorIgnored; | 1789 init.fColorIgnored = fBatch.fColorIgnored; |
1930 init.fOverrideColor = GrColor_ILLEGAL; | 1790 init.fOverrideColor = GrColor_ILLEGAL; |
1931 init.fCoverageIgnored = fBatch.fCoverageIgnored; | 1791 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
1932 init.fUsesLocalCoords = this->usesLocalCoords(); | 1792 init.fUsesLocalCoords = this->usesLocalCoords(); |
1933 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); | 1793 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
1934 | 1794 |
1935 int instanceCount = fGeoData.count(); | 1795 int instanceCount = fGeoData.count(); |
1936 int vertexCount = kVertsPerRRect * instanceCount; | |
1937 size_t vertexStride = gp->getVertexStride(); | 1796 size_t vertexStride = gp->getVertexStride(); |
1938 SkASSERT(vertexStride == sizeof(EllipseVertex)); | 1797 SkASSERT(vertexStride == sizeof(EllipseVertex)); |
1939 | 1798 |
1940 const GrVertexBuffer* vertexBuffer; | 1799 // drop out the middle quad if we're stroked |
| 1800 int indicesPerInstance = this->stroke() ? kIndicesPerStrokeRRect : kIndi
cesPerRRect; |
1941 SkAutoTUnref<const GrIndexBuffer> indexBuffer( | 1801 SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
1942 ref_rrect_index_buffer(this->stroke(), batchTarget->resourceProvider
())); | 1802 ref_rrect_index_buffer(this->stroke(), batchTarget->resourceProvider
())); |
1943 int firstVertex; | |
1944 | 1803 |
1945 void *vertices = batchTarget->vertexPool()->makeSpace(vertexStride, | 1804 InstancedHelper helper; |
1946 vertexCount, | 1805 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( |
1947 &vertexBuffer, | 1806 helper.init(batchTarget, vertexStride, indexBuffer, kVertsPerRRect,
indicesPerInstance, |
1948 &firstVertex); | 1807 instanceCount)); |
1949 | 1808 if (!verts || !indexBuffer) { |
1950 if (!vertices || !indexBuffer) { | |
1951 SkDebugf("Could not allocate vertices\n"); | 1809 SkDebugf("Could not allocate vertices\n"); |
1952 return; | 1810 return; |
1953 } | 1811 } |
1954 | 1812 |
1955 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(vertices); | |
1956 | |
1957 for (int i = 0; i < instanceCount; i++) { | 1813 for (int i = 0; i < instanceCount; i++) { |
1958 Geometry& args = fGeoData[i]; | 1814 Geometry& args = fGeoData[i]; |
1959 | 1815 |
1960 // Compute the reciprocals of the radii here to save time in the sha
der | 1816 // Compute the reciprocals of the radii here to save time in the sha
der |
1961 SkScalar xRadRecip = SkScalarInvert(args.fXRadius); | 1817 SkScalar xRadRecip = SkScalarInvert(args.fXRadius); |
1962 SkScalar yRadRecip = SkScalarInvert(args.fYRadius); | 1818 SkScalar yRadRecip = SkScalarInvert(args.fYRadius); |
1963 SkScalar xInnerRadRecip = SkScalarInvert(args.fInnerXRadius); | 1819 SkScalar xInnerRadRecip = SkScalarInvert(args.fInnerXRadius); |
1964 SkScalar yInnerRadRecip = SkScalarInvert(args.fInnerYRadius); | 1820 SkScalar yInnerRadRecip = SkScalarInvert(args.fInnerYRadius); |
1965 | 1821 |
1966 // Extend the radii out half a pixel to antialias. | 1822 // Extend the radii out half a pixel to antialias. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2001 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadReci
p); | 1857 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadReci
p); |
2002 verts++; | 1858 verts++; |
2003 | 1859 |
2004 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); | 1860 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); |
2005 verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); | 1861 verts->fOffset = SkPoint::Make(xOuterRadius, yOuterOffsets[i]); |
2006 verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 1862 verts->fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
2007 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadReci
p); | 1863 verts->fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadReci
p); |
2008 verts++; | 1864 verts++; |
2009 } | 1865 } |
2010 } | 1866 } |
2011 | 1867 helper.issueDraws(batchTarget); |
2012 // drop out the middle quad if we're stroked | |
2013 int indexCnt = this->stroke() ? SK_ARRAY_COUNT(gRRectIndices) - 6 : | |
2014 SK_ARRAY_COUNT(gRRectIndices); | |
2015 | |
2016 GrDrawTarget::DrawInfo drawInfo; | |
2017 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); | |
2018 drawInfo.setStartVertex(0); | |
2019 drawInfo.setStartIndex(0); | |
2020 drawInfo.setVerticesPerInstance(kVertsPerRRect); | |
2021 drawInfo.setIndicesPerInstance(indexCnt); | |
2022 drawInfo.adjustStartVertex(firstVertex); | |
2023 drawInfo.setVertexBuffer(vertexBuffer); | |
2024 drawInfo.setIndexBuffer(indexBuffer); | |
2025 | |
2026 int maxInstancesPerDraw = kNumRRectsInIndexBuffer; | |
2027 | |
2028 while (instanceCount) { | |
2029 drawInfo.setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw)
); | |
2030 drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.vertices
PerInstance()); | |
2031 drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPe
rInstance()); | |
2032 | |
2033 batchTarget->draw(drawInfo); | |
2034 | |
2035 drawInfo.setStartVertex(drawInfo.startVertex() + drawInfo.vertexCoun
t()); | |
2036 instanceCount -= drawInfo.instanceCount(); | |
2037 } | |
2038 } | 1868 } |
2039 | 1869 |
2040 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 1870 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
2041 | 1871 |
2042 private: | 1872 private: |
2043 RRectEllipseRendererBatch(const Geometry& geometry) { | 1873 RRectEllipseRendererBatch(const Geometry& geometry) { |
2044 this->initClassID<RRectEllipseRendererBatch>(); | 1874 this->initClassID<RRectEllipseRendererBatch>(); |
2045 fGeoData.push_back(geometry); | 1875 fGeoData.push_back(geometry); |
2046 | 1876 |
2047 this->setBounds(geometry.fDevBounds); | 1877 this->setBounds(geometry.fDevBounds); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2315 BATCH_TEST_DEFINE(RRectBatch) { | 2145 BATCH_TEST_DEFINE(RRectBatch) { |
2316 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 2146 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
2317 GrColor color = GrRandomColor(random); | 2147 GrColor color = GrRandomColor(random); |
2318 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 2148 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
2319 | 2149 |
2320 SkRect bounds; | 2150 SkRect bounds; |
2321 return create_rrect_batch(color, viewMatrix, rrect, random_strokerec(random)
, &bounds); | 2151 return create_rrect_batch(color, viewMatrix, rrect, random_strokerec(random)
, &bounds); |
2322 } | 2152 } |
2323 | 2153 |
2324 #endif | 2154 #endif |
OLD | NEW |