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 "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 opt.getOverrideColorIfSet(&fGeoData[0].fColor); | 685 opt.getOverrideColorIfSet(&fGeoData[0].fColor); |
686 | 686 |
687 // setup batch properties | 687 // setup batch properties |
688 fBatch.fColorIgnored = !opt.readsColor(); | 688 fBatch.fColorIgnored = !opt.readsColor(); |
689 fBatch.fColor = fGeoData[0].fColor; | 689 fBatch.fColor = fGeoData[0].fColor; |
690 fBatch.fStroke = fGeoData[0].fStroke; | 690 fBatch.fStroke = fGeoData[0].fStroke; |
691 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); | 691 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); |
692 fBatch.fCoverageIgnored = !opt.readsCoverage(); | 692 fBatch.fCoverageIgnored = !opt.readsCoverage(); |
693 } | 693 } |
694 | 694 |
695 void onPrepareDraws(Target* target) override { | 695 void onPrepareDraws(Target* target) const override { |
696 SkMatrix invert; | 696 SkMatrix invert; |
697 if (!this->viewMatrix().invert(&invert)) { | 697 if (!this->viewMatrix().invert(&invert)) { |
698 return; | 698 return; |
699 } | 699 } |
700 | 700 |
701 // Setup geometry processor | 701 // Setup geometry processor |
702 SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->colo
r(), | 702 SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->colo
r(), |
703 this->stro
ke(), | 703 this->stro
ke(), |
704 invert, | 704 invert, |
705 this->uses
LocalCoords())); | 705 this->uses
LocalCoords())); |
706 | 706 |
707 target->initDraw(gp, this->pipeline()); | 707 target->initDraw(gp, this->pipeline()); |
708 | 708 |
709 int instanceCount = fGeoData.count(); | 709 int instanceCount = fGeoData.count(); |
710 size_t vertexStride = gp->getVertexStride(); | 710 size_t vertexStride = gp->getVertexStride(); |
711 SkASSERT(vertexStride == sizeof(CircleVertex)); | 711 SkASSERT(vertexStride == sizeof(CircleVertex)); |
712 QuadHelper helper; | 712 QuadHelper helper; |
713 CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(target
, vertexStride, | 713 CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(target
, vertexStride, |
714 instan
ceCount)); | 714 instan
ceCount)); |
715 if (!verts) { | 715 if (!verts) { |
716 return; | 716 return; |
717 } | 717 } |
718 | 718 |
719 for (int i = 0; i < instanceCount; i++) { | 719 for (int i = 0; i < instanceCount; i++) { |
720 Geometry& geom = fGeoData[i]; | 720 const Geometry& geom = fGeoData[i]; |
721 | 721 |
722 SkScalar innerRadius = geom.fInnerRadius; | 722 SkScalar innerRadius = geom.fInnerRadius; |
723 SkScalar outerRadius = geom.fOuterRadius; | 723 SkScalar outerRadius = geom.fOuterRadius; |
724 | 724 |
725 const SkRect& bounds = geom.fDevBounds; | 725 const SkRect& bounds = geom.fDevBounds; |
726 | 726 |
727 // The inner radius in the vertex data must be specified in normaliz
ed space. | 727 // The inner radius in the vertex data must be specified in normaliz
ed space. |
728 innerRadius = innerRadius / outerRadius; | 728 innerRadius = innerRadius / outerRadius; |
729 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); | 729 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
730 verts[0].fOffset = SkPoint::Make(-1, -1); | 730 verts[0].fOffset = SkPoint::Make(-1, -1); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 opt.getOverrideColorIfSet(&fGeoData[0].fColor); | 904 opt.getOverrideColorIfSet(&fGeoData[0].fColor); |
905 | 905 |
906 // setup batch properties | 906 // setup batch properties |
907 fBatch.fColorIgnored = !opt.readsColor(); | 907 fBatch.fColorIgnored = !opt.readsColor(); |
908 fBatch.fColor = fGeoData[0].fColor; | 908 fBatch.fColor = fGeoData[0].fColor; |
909 fBatch.fStroke = fGeoData[0].fStroke; | 909 fBatch.fStroke = fGeoData[0].fStroke; |
910 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); | 910 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); |
911 fBatch.fCoverageIgnored = !opt.readsCoverage(); | 911 fBatch.fCoverageIgnored = !opt.readsCoverage(); |
912 } | 912 } |
913 | 913 |
914 void onPrepareDraws(Target* target) override { | 914 void onPrepareDraws(Target* target) const override { |
915 SkMatrix invert; | 915 SkMatrix invert; |
916 if (!this->viewMatrix().invert(&invert)) { | 916 if (!this->viewMatrix().invert(&invert)) { |
917 return; | 917 return; |
918 } | 918 } |
919 | 919 |
920 // Setup geometry processor | 920 // Setup geometry processor |
921 SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->col
or(), | 921 SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->col
or(), |
922 this->str
oke(), | 922 this->str
oke(), |
923 invert, | 923 invert, |
924 this->use
sLocalCoords())); | 924 this->use
sLocalCoords())); |
925 | 925 |
926 target->initDraw(gp, this->pipeline()); | 926 target->initDraw(gp, this->pipeline()); |
927 | 927 |
928 int instanceCount = fGeoData.count(); | 928 int instanceCount = fGeoData.count(); |
929 QuadHelper helper; | 929 QuadHelper helper; |
930 size_t vertexStride = gp->getVertexStride(); | 930 size_t vertexStride = gp->getVertexStride(); |
931 SkASSERT(vertexStride == sizeof(EllipseVertex)); | 931 SkASSERT(vertexStride == sizeof(EllipseVertex)); |
932 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( | 932 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( |
933 helper.init(target, vertexStride, instanceCount)); | 933 helper.init(target, vertexStride, instanceCount)); |
934 if (!verts) { | 934 if (!verts) { |
935 return; | 935 return; |
936 } | 936 } |
937 | 937 |
938 for (int i = 0; i < instanceCount; i++) { | 938 for (int i = 0; i < instanceCount; i++) { |
939 Geometry& geom = fGeoData[i]; | 939 const Geometry& geom = fGeoData[i]; |
940 | 940 |
941 SkScalar xRadius = geom.fXRadius; | 941 SkScalar xRadius = geom.fXRadius; |
942 SkScalar yRadius = geom.fYRadius; | 942 SkScalar yRadius = geom.fYRadius; |
943 | 943 |
944 // Compute the reciprocals of the radii here to save time in the sha
der | 944 // Compute the reciprocals of the radii here to save time in the sha
der |
945 SkScalar xRadRecip = SkScalarInvert(xRadius); | 945 SkScalar xRadRecip = SkScalarInvert(xRadius); |
946 SkScalar yRadRecip = SkScalarInvert(yRadius); | 946 SkScalar yRadRecip = SkScalarInvert(yRadius); |
947 SkScalar xInnerRadRecip = SkScalarInvert(geom.fInnerXRadius); | 947 SkScalar xInnerRadRecip = SkScalarInvert(geom.fInnerXRadius); |
948 SkScalar yInnerRadRecip = SkScalarInvert(geom.fInnerYRadius); | 948 SkScalar yInnerRadRecip = SkScalarInvert(geom.fInnerYRadius); |
949 | 949 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1176 opt.getOverrideColorIfSet(&fGeoData[0].fColor); | 1176 opt.getOverrideColorIfSet(&fGeoData[0].fColor); |
1177 | 1177 |
1178 // setup batch properties | 1178 // setup batch properties |
1179 fBatch.fColorIgnored = !opt.readsColor(); | 1179 fBatch.fColorIgnored = !opt.readsColor(); |
1180 fBatch.fColor = fGeoData[0].fColor; | 1180 fBatch.fColor = fGeoData[0].fColor; |
1181 fBatch.fMode = fGeoData[0].fMode; | 1181 fBatch.fMode = fGeoData[0].fMode; |
1182 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); | 1182 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); |
1183 fBatch.fCoverageIgnored = !opt.readsCoverage(); | 1183 fBatch.fCoverageIgnored = !opt.readsCoverage(); |
1184 } | 1184 } |
1185 | 1185 |
1186 void onPrepareDraws(Target* target) override { | 1186 void onPrepareDraws(Target* target) const override { |
1187 // Setup geometry processor | 1187 // Setup geometry processor |
1188 SkAutoTUnref<GrGeometryProcessor> gp(DIEllipseEdgeEffect::Create(this->c
olor(), | 1188 SkAutoTUnref<GrGeometryProcessor> gp(DIEllipseEdgeEffect::Create(this->c
olor(), |
1189 this->v
iewMatrix(), | 1189 this->v
iewMatrix(), |
1190 this->m
ode(), | 1190 this->m
ode(), |
1191 this->u
sesLocalCoords())); | 1191 this->u
sesLocalCoords())); |
1192 | 1192 |
1193 target->initDraw(gp, this->pipeline()); | 1193 target->initDraw(gp, this->pipeline()); |
1194 | 1194 |
1195 int instanceCount = fGeoData.count(); | 1195 int instanceCount = fGeoData.count(); |
1196 size_t vertexStride = gp->getVertexStride(); | 1196 size_t vertexStride = gp->getVertexStride(); |
1197 SkASSERT(vertexStride == sizeof(DIEllipseVertex)); | 1197 SkASSERT(vertexStride == sizeof(DIEllipseVertex)); |
1198 QuadHelper helper; | 1198 QuadHelper helper; |
1199 DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>( | 1199 DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>( |
1200 helper.init(target, vertexStride, instanceCount)); | 1200 helper.init(target, vertexStride, instanceCount)); |
1201 if (!verts) { | 1201 if (!verts) { |
1202 return; | 1202 return; |
1203 } | 1203 } |
1204 | 1204 |
1205 for (int i = 0; i < instanceCount; i++) { | 1205 for (int i = 0; i < instanceCount; i++) { |
1206 Geometry& geom = fGeoData[i]; | 1206 const Geometry& geom = fGeoData[i]; |
1207 | 1207 |
1208 SkScalar xRadius = geom.fXRadius; | 1208 SkScalar xRadius = geom.fXRadius; |
1209 SkScalar yRadius = geom.fYRadius; | 1209 SkScalar yRadius = geom.fYRadius; |
1210 | 1210 |
1211 const SkRect& bounds = geom.fBounds; | 1211 const SkRect& bounds = geom.fBounds; |
1212 | 1212 |
1213 // This adjusts the "radius" to include the half-pixel border | 1213 // This adjusts the "radius" to include the half-pixel border |
1214 SkScalar offsetDx = geom.fGeoDx / xRadius; | 1214 SkScalar offsetDx = geom.fGeoDx / xRadius; |
1215 SkScalar offsetDy = geom.fGeoDy / yRadius; | 1215 SkScalar offsetDy = geom.fGeoDy / yRadius; |
1216 | 1216 |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1530 opt.getOverrideColorIfSet(&fGeoData[0].fColor); | 1530 opt.getOverrideColorIfSet(&fGeoData[0].fColor); |
1531 | 1531 |
1532 // setup batch properties | 1532 // setup batch properties |
1533 fBatch.fColorIgnored = !opt.readsColor(); | 1533 fBatch.fColorIgnored = !opt.readsColor(); |
1534 fBatch.fColor = fGeoData[0].fColor; | 1534 fBatch.fColor = fGeoData[0].fColor; |
1535 fBatch.fStroke = fGeoData[0].fStroke; | 1535 fBatch.fStroke = fGeoData[0].fStroke; |
1536 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); | 1536 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); |
1537 fBatch.fCoverageIgnored = !opt.readsCoverage(); | 1537 fBatch.fCoverageIgnored = !opt.readsCoverage(); |
1538 } | 1538 } |
1539 | 1539 |
1540 void onPrepareDraws(Target* target) override { | 1540 void onPrepareDraws(Target* target) const override { |
1541 // reset to device coordinates | 1541 // reset to device coordinates |
1542 SkMatrix invert; | 1542 SkMatrix invert; |
1543 if (!this->viewMatrix().invert(&invert)) { | 1543 if (!this->viewMatrix().invert(&invert)) { |
1544 SkDebugf("Failed to invert\n"); | 1544 SkDebugf("Failed to invert\n"); |
1545 return; | 1545 return; |
1546 } | 1546 } |
1547 | 1547 |
1548 // Setup geometry processor | 1548 // Setup geometry processor |
1549 SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->colo
r(), | 1549 SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->colo
r(), |
1550 this->stro
ke(), | 1550 this->stro
ke(), |
(...skipping 14 matching lines...) Expand all Loading... |
1565 InstancedHelper helper; | 1565 InstancedHelper helper; |
1566 CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(target
, | 1566 CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(target
, |
1567 kTriangles_GrPrimitiveType, vertexStride, indexBuffer, kVertsPerRRec
t, | 1567 kTriangles_GrPrimitiveType, vertexStride, indexBuffer, kVertsPerRRec
t, |
1568 indicesPerInstance, instanceCount)); | 1568 indicesPerInstance, instanceCount)); |
1569 if (!verts || !indexBuffer) { | 1569 if (!verts || !indexBuffer) { |
1570 SkDebugf("Could not allocate vertices\n"); | 1570 SkDebugf("Could not allocate vertices\n"); |
1571 return; | 1571 return; |
1572 } | 1572 } |
1573 | 1573 |
1574 for (int i = 0; i < instanceCount; i++) { | 1574 for (int i = 0; i < instanceCount; i++) { |
1575 Geometry& args = fGeoData[i]; | 1575 const Geometry& args = fGeoData[i]; |
1576 | 1576 |
1577 SkScalar outerRadius = args.fOuterRadius; | 1577 SkScalar outerRadius = args.fOuterRadius; |
1578 | 1578 |
1579 const SkRect& bounds = args.fDevBounds; | 1579 const SkRect& bounds = args.fDevBounds; |
1580 | 1580 |
1581 SkScalar yCoords[4] = { | 1581 SkScalar yCoords[4] = { |
1582 bounds.fTop, | 1582 bounds.fTop, |
1583 bounds.fTop + outerRadius, | 1583 bounds.fTop + outerRadius, |
1584 bounds.fBottom - outerRadius, | 1584 bounds.fBottom - outerRadius, |
1585 bounds.fBottom | 1585 bounds.fBottom |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 opt.getOverrideColorIfSet(&fGeoData[0].fColor); | 1709 opt.getOverrideColorIfSet(&fGeoData[0].fColor); |
1710 | 1710 |
1711 // setup batch properties | 1711 // setup batch properties |
1712 fBatch.fColorIgnored = !opt.readsColor(); | 1712 fBatch.fColorIgnored = !opt.readsColor(); |
1713 fBatch.fColor = fGeoData[0].fColor; | 1713 fBatch.fColor = fGeoData[0].fColor; |
1714 fBatch.fStroke = fGeoData[0].fStroke; | 1714 fBatch.fStroke = fGeoData[0].fStroke; |
1715 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); | 1715 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); |
1716 fBatch.fCoverageIgnored = !opt.readsCoverage(); | 1716 fBatch.fCoverageIgnored = !opt.readsCoverage(); |
1717 } | 1717 } |
1718 | 1718 |
1719 void onPrepareDraws(Target* target) override { | 1719 void onPrepareDraws(Target* target) const override { |
1720 // reset to device coordinates | 1720 // reset to device coordinates |
1721 SkMatrix invert; | 1721 SkMatrix invert; |
1722 if (!this->viewMatrix().invert(&invert)) { | 1722 if (!this->viewMatrix().invert(&invert)) { |
1723 SkDebugf("Failed to invert\n"); | 1723 SkDebugf("Failed to invert\n"); |
1724 return; | 1724 return; |
1725 } | 1725 } |
1726 | 1726 |
1727 // Setup geometry processor | 1727 // Setup geometry processor |
1728 SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->col
or(), | 1728 SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->col
or(), |
1729 this->str
oke(), | 1729 this->str
oke(), |
(...skipping 14 matching lines...) Expand all Loading... |
1744 InstancedHelper helper; | 1744 InstancedHelper helper; |
1745 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( | 1745 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( |
1746 helper.init(target, kTriangles_GrPrimitiveType, vertexStride, indexB
uffer, | 1746 helper.init(target, kTriangles_GrPrimitiveType, vertexStride, indexB
uffer, |
1747 kVertsPerRRect, indicesPerInstance, instanceCount)); | 1747 kVertsPerRRect, indicesPerInstance, instanceCount)); |
1748 if (!verts || !indexBuffer) { | 1748 if (!verts || !indexBuffer) { |
1749 SkDebugf("Could not allocate vertices\n"); | 1749 SkDebugf("Could not allocate vertices\n"); |
1750 return; | 1750 return; |
1751 } | 1751 } |
1752 | 1752 |
1753 for (int i = 0; i < instanceCount; i++) { | 1753 for (int i = 0; i < instanceCount; i++) { |
1754 Geometry& args = fGeoData[i]; | 1754 const Geometry& args = fGeoData[i]; |
1755 | 1755 |
1756 // Compute the reciprocals of the radii here to save time in the sha
der | 1756 // Compute the reciprocals of the radii here to save time in the sha
der |
1757 SkScalar xRadRecip = SkScalarInvert(args.fXRadius); | 1757 SkScalar xRadRecip = SkScalarInvert(args.fXRadius); |
1758 SkScalar yRadRecip = SkScalarInvert(args.fYRadius); | 1758 SkScalar yRadRecip = SkScalarInvert(args.fYRadius); |
1759 SkScalar xInnerRadRecip = SkScalarInvert(args.fInnerXRadius); | 1759 SkScalar xInnerRadRecip = SkScalarInvert(args.fInnerXRadius); |
1760 SkScalar yInnerRadRecip = SkScalarInvert(args.fInnerYRadius); | 1760 SkScalar yInnerRadRecip = SkScalarInvert(args.fInnerYRadius); |
1761 | 1761 |
1762 // Extend the radii out half a pixel to antialias. | 1762 // Extend the radii out half a pixel to antialias. |
1763 SkScalar xOuterRadius = args.fXRadius + SK_ScalarHalf; | 1763 SkScalar xOuterRadius = args.fXRadius + SK_ScalarHalf; |
1764 SkScalar yOuterRadius = args.fYRadius + SK_ScalarHalf; | 1764 SkScalar yOuterRadius = args.fYRadius + SK_ScalarHalf; |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2073 } | 2073 } |
2074 | 2074 |
2075 DRAW_BATCH_TEST_DEFINE(RRectBatch) { | 2075 DRAW_BATCH_TEST_DEFINE(RRectBatch) { |
2076 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 2076 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
2077 GrColor color = GrRandomColor(random); | 2077 GrColor color = GrRandomColor(random); |
2078 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 2078 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
2079 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); | 2079 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); |
2080 } | 2080 } |
2081 | 2081 |
2082 #endif | 2082 #endif |
OLD | NEW |