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

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

Issue 1099873002: Undo the bounds mapping of bounds for GrOvalRenderer for certain draws (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Missed mapRect Created 5 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
« no previous file with comments | « no previous file | no next file » | 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 * 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 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 /////////////////////////////////////////////////////////////////////////////// 685 ///////////////////////////////////////////////////////////////////////////////
686 686
687 class CircleBatch : public GrBatch { 687 class CircleBatch : public GrBatch {
688 public: 688 public:
689 struct Geometry { 689 struct Geometry {
690 GrColor fColor; 690 GrColor fColor;
691 SkMatrix fViewMatrix; 691 SkMatrix fViewMatrix;
692 SkScalar fInnerRadius; 692 SkScalar fInnerRadius;
693 SkScalar fOuterRadius; 693 SkScalar fOuterRadius;
694 bool fStroke; 694 bool fStroke;
695 SkRect fBounds; 695 SkRect fDevBounds;
696 }; 696 };
697 697
698 static GrBatch* Create(const Geometry& geometry) { 698 static GrBatch* Create(const Geometry& geometry) {
699 return SkNEW_ARGS(CircleBatch, (geometry)); 699 return SkNEW_ARGS(CircleBatch, (geometry));
700 } 700 }
701 701
702 const char* name() const override { return "CircleBatch"; } 702 const char* name() const override { return "CircleBatch"; }
703 703
704 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { 704 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
705 // When this is called on a batch, there is only one geometry bundle 705 // When this is called on a batch, there is only one geometry bundle
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 } 768 }
769 769
770 CircleVertex* verts = reinterpret_cast<CircleVertex*>(vertices); 770 CircleVertex* verts = reinterpret_cast<CircleVertex*>(vertices);
771 771
772 for (int i = 0; i < instanceCount; i++) { 772 for (int i = 0; i < instanceCount; i++) {
773 Geometry& args = fGeoData[i]; 773 Geometry& args = fGeoData[i];
774 774
775 SkScalar innerRadius = args.fInnerRadius; 775 SkScalar innerRadius = args.fInnerRadius;
776 SkScalar outerRadius = args.fOuterRadius; 776 SkScalar outerRadius = args.fOuterRadius;
777 777
778 const SkRect& bounds = args.fBounds; 778 const SkRect& bounds = args.fDevBounds;
779 779
780 // The inner radius in the vertex data must be specified in normaliz ed space. 780 // The inner radius in the vertex data must be specified in normaliz ed space.
781 innerRadius = innerRadius / outerRadius; 781 innerRadius = innerRadius / outerRadius;
782 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); 782 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop);
783 verts[0].fOffset = SkPoint::Make(-1, -1); 783 verts[0].fOffset = SkPoint::Make(-1, -1);
784 verts[0].fOuterRadius = outerRadius; 784 verts[0].fOuterRadius = outerRadius;
785 verts[0].fInnerRadius = innerRadius; 785 verts[0].fInnerRadius = innerRadius;
786 786
787 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); 787 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom);
788 verts[1].fOffset = SkPoint::Make(-1, 1); 788 verts[1].fOffset = SkPoint::Make(-1, 1);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 center.fX + outerRadius, 923 center.fX + outerRadius,
924 center.fY + outerRadius 924 center.fY + outerRadius
925 ); 925 );
926 926
927 CircleBatch::Geometry geometry; 927 CircleBatch::Geometry geometry;
928 geometry.fViewMatrix = viewMatrix; 928 geometry.fViewMatrix = viewMatrix;
929 geometry.fColor = color; 929 geometry.fColor = color;
930 geometry.fInnerRadius = innerRadius; 930 geometry.fInnerRadius = innerRadius;
931 geometry.fOuterRadius = outerRadius; 931 geometry.fOuterRadius = outerRadius;
932 geometry.fStroke = isStrokeOnly && innerRadius > 0; 932 geometry.fStroke = isStrokeOnly && innerRadius > 0;
933 geometry.fBounds = bounds; 933 geometry.fDevBounds = bounds;
934
935 viewMatrix.mapRect(&bounds);
936 934
937 SkAutoTUnref<GrBatch> batch(CircleBatch::Create(geometry)); 935 SkAutoTUnref<GrBatch> batch(CircleBatch::Create(geometry));
938 target->drawBatch(pipelineBuilder, batch, &bounds); 936 target->drawBatch(pipelineBuilder, batch, &bounds);
939 } 937 }
940 938
941 /////////////////////////////////////////////////////////////////////////////// 939 ///////////////////////////////////////////////////////////////////////////////
942 940
943 class EllipseBatch : public GrBatch { 941 class EllipseBatch : public GrBatch {
944 public: 942 public:
945 struct Geometry { 943 struct Geometry {
946 GrColor fColor; 944 GrColor fColor;
947 SkMatrix fViewMatrix; 945 SkMatrix fViewMatrix;
948 SkScalar fXRadius; 946 SkScalar fXRadius;
949 SkScalar fYRadius; 947 SkScalar fYRadius;
950 SkScalar fInnerXRadius; 948 SkScalar fInnerXRadius;
951 SkScalar fInnerYRadius; 949 SkScalar fInnerYRadius;
952 bool fStroke; 950 bool fStroke;
953 SkRect fBounds; 951 SkRect fDevBounds;
954 }; 952 };
955 953
956 static GrBatch* Create(const Geometry& geometry) { 954 static GrBatch* Create(const Geometry& geometry) {
957 return SkNEW_ARGS(EllipseBatch, (geometry)); 955 return SkNEW_ARGS(EllipseBatch, (geometry));
958 } 956 }
959 957
960 const char* name() const override { return "EllipseBatch"; } 958 const char* name() const override { return "EllipseBatch"; }
961 959
962 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { 960 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
963 // When this is called on a batch, there is only one geometry bundle 961 // When this is called on a batch, there is only one geometry bundle
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 1029
1032 SkScalar xRadius = args.fXRadius; 1030 SkScalar xRadius = args.fXRadius;
1033 SkScalar yRadius = args.fYRadius; 1031 SkScalar yRadius = args.fYRadius;
1034 1032
1035 // Compute the reciprocals of the radii here to save time in the sha der 1033 // Compute the reciprocals of the radii here to save time in the sha der
1036 SkScalar xRadRecip = SkScalarInvert(xRadius); 1034 SkScalar xRadRecip = SkScalarInvert(xRadius);
1037 SkScalar yRadRecip = SkScalarInvert(yRadius); 1035 SkScalar yRadRecip = SkScalarInvert(yRadius);
1038 SkScalar xInnerRadRecip = SkScalarInvert(args.fInnerXRadius); 1036 SkScalar xInnerRadRecip = SkScalarInvert(args.fInnerXRadius);
1039 SkScalar yInnerRadRecip = SkScalarInvert(args.fInnerYRadius); 1037 SkScalar yInnerRadRecip = SkScalarInvert(args.fInnerYRadius);
1040 1038
1041 const SkRect& bounds = args.fBounds; 1039 const SkRect& bounds = args.fDevBounds;
1042 1040
1043 // The inner radius in the vertex data must be specified in normaliz ed space. 1041 // The inner radius in the vertex data must be specified in normaliz ed space.
1044 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); 1042 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop);
1045 verts[0].fOffset = SkPoint::Make(-xRadius, -yRadius); 1043 verts[0].fOffset = SkPoint::Make(-xRadius, -yRadius);
1046 verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); 1044 verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip);
1047 verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip) ; 1045 verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip) ;
1048 1046
1049 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); 1047 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom);
1050 verts[1].fOffset = SkPoint::Make(-xRadius, yRadius); 1048 verts[1].fOffset = SkPoint::Make(-xRadius, yRadius);
1051 verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); 1049 verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 ); 1220 );
1223 1221
1224 EllipseBatch::Geometry geometry; 1222 EllipseBatch::Geometry geometry;
1225 geometry.fViewMatrix = viewMatrix; 1223 geometry.fViewMatrix = viewMatrix;
1226 geometry.fColor = color; 1224 geometry.fColor = color;
1227 geometry.fXRadius = xRadius; 1225 geometry.fXRadius = xRadius;
1228 geometry.fYRadius = yRadius; 1226 geometry.fYRadius = yRadius;
1229 geometry.fInnerXRadius = innerXRadius; 1227 geometry.fInnerXRadius = innerXRadius;
1230 geometry.fInnerYRadius = innerYRadius; 1228 geometry.fInnerYRadius = innerYRadius;
1231 geometry.fStroke = isStrokeOnly && innerXRadius > 0 && innerYRadius > 0; 1229 geometry.fStroke = isStrokeOnly && innerXRadius > 0 && innerYRadius > 0;
1232 geometry.fBounds = bounds; 1230 geometry.fDevBounds = bounds;
1233
1234 viewMatrix.mapRect(&bounds);
1235 1231
1236 SkAutoTUnref<GrBatch> batch(EllipseBatch::Create(geometry)); 1232 SkAutoTUnref<GrBatch> batch(EllipseBatch::Create(geometry));
1237 target->drawBatch(pipelineBuilder, batch, &bounds); 1233 target->drawBatch(pipelineBuilder, batch, &bounds);
1238 1234
1239 return true; 1235 return true;
1240 } 1236 }
1241 1237
1242 //////////////////////////////////////////////////////////////////////////////// ///////////////// 1238 //////////////////////////////////////////////////////////////////////////////// /////////////////
1243 1239
1244 class DIEllipseBatch : public GrBatch { 1240 class DIEllipseBatch : public GrBatch {
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 //////////////////////////////////////////////////////////////////////////////// /////////////////// 1631 //////////////////////////////////////////////////////////////////////////////// ///////////////////
1636 1632
1637 class RRectCircleRendererBatch : public GrBatch { 1633 class RRectCircleRendererBatch : public GrBatch {
1638 public: 1634 public:
1639 struct Geometry { 1635 struct Geometry {
1640 GrColor fColor; 1636 GrColor fColor;
1641 SkMatrix fViewMatrix; 1637 SkMatrix fViewMatrix;
1642 SkScalar fInnerRadius; 1638 SkScalar fInnerRadius;
1643 SkScalar fOuterRadius; 1639 SkScalar fOuterRadius;
1644 bool fStroke; 1640 bool fStroke;
1645 SkRect fBounds; 1641 SkRect fDevBounds;
1646 }; 1642 };
1647 1643
1648 static GrBatch* Create(const Geometry& geometry, const GrIndexBuffer* indexB uffer) { 1644 static GrBatch* Create(const Geometry& geometry, const GrIndexBuffer* indexB uffer) {
1649 return SkNEW_ARGS(RRectCircleRendererBatch, (geometry, indexBuffer)); 1645 return SkNEW_ARGS(RRectCircleRendererBatch, (geometry, indexBuffer));
1650 } 1646 }
1651 1647
1652 const char* name() const override { return "RRectCircleBatch"; } 1648 const char* name() const override { return "RRectCircleBatch"; }
1653 1649
1654 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { 1650 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
1655 // When this is called on a batch, there is only one geometry bundle 1651 // When this is called on a batch, there is only one geometry bundle
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 return; 1714 return;
1719 } 1715 }
1720 1716
1721 CircleVertex* verts = reinterpret_cast<CircleVertex*>(vertices); 1717 CircleVertex* verts = reinterpret_cast<CircleVertex*>(vertices);
1722 1718
1723 for (int i = 0; i < instanceCount; i++) { 1719 for (int i = 0; i < instanceCount; i++) {
1724 Geometry& args = fGeoData[i]; 1720 Geometry& args = fGeoData[i];
1725 1721
1726 SkScalar outerRadius = args.fOuterRadius; 1722 SkScalar outerRadius = args.fOuterRadius;
1727 1723
1728 const SkRect& bounds = args.fBounds; 1724 const SkRect& bounds = args.fDevBounds;
1729 1725
1730 SkScalar yCoords[4] = { 1726 SkScalar yCoords[4] = {
1731 bounds.fTop, 1727 bounds.fTop,
1732 bounds.fTop + outerRadius, 1728 bounds.fTop + outerRadius,
1733 bounds.fBottom - outerRadius, 1729 bounds.fBottom - outerRadius,
1734 bounds.fBottom 1730 bounds.fBottom
1735 }; 1731 };
1736 1732
1737 SkScalar yOuterRadii[4] = {-1, 0, 0, 1 }; 1733 SkScalar yOuterRadii[4] = {-1, 0, 0, 1 };
1738 // The inner radius in the vertex data must be specified in normaliz ed space. 1734 // The inner radius in the vertex data must be specified in normaliz ed space.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 class RRectEllipseRendererBatch : public GrBatch { 1840 class RRectEllipseRendererBatch : public GrBatch {
1845 public: 1841 public:
1846 struct Geometry { 1842 struct Geometry {
1847 GrColor fColor; 1843 GrColor fColor;
1848 SkMatrix fViewMatrix; 1844 SkMatrix fViewMatrix;
1849 SkScalar fXRadius; 1845 SkScalar fXRadius;
1850 SkScalar fYRadius; 1846 SkScalar fYRadius;
1851 SkScalar fInnerXRadius; 1847 SkScalar fInnerXRadius;
1852 SkScalar fInnerYRadius; 1848 SkScalar fInnerYRadius;
1853 bool fStroke; 1849 bool fStroke;
1854 SkRect fBounds; 1850 SkRect fDevBounds;
1855 }; 1851 };
1856 1852
1857 static GrBatch* Create(const Geometry& geometry, const GrIndexBuffer* indexB uffer) { 1853 static GrBatch* Create(const Geometry& geometry, const GrIndexBuffer* indexB uffer) {
1858 return SkNEW_ARGS(RRectEllipseRendererBatch, (geometry, indexBuffer)); 1854 return SkNEW_ARGS(RRectEllipseRendererBatch, (geometry, indexBuffer));
1859 } 1855 }
1860 1856
1861 const char* name() const override { return "RRectEllipseRendererBatch"; } 1857 const char* name() const override { return "RRectEllipseRendererBatch"; }
1862 1858
1863 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { 1859 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
1864 // When this is called on a batch, there is only one geometry bundle 1860 // When this is called on a batch, there is only one geometry bundle
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 // Compute the reciprocals of the radii here to save time in the sha der 1931 // Compute the reciprocals of the radii here to save time in the sha der
1936 SkScalar xRadRecip = SkScalarInvert(args.fXRadius); 1932 SkScalar xRadRecip = SkScalarInvert(args.fXRadius);
1937 SkScalar yRadRecip = SkScalarInvert(args.fYRadius); 1933 SkScalar yRadRecip = SkScalarInvert(args.fYRadius);
1938 SkScalar xInnerRadRecip = SkScalarInvert(args.fInnerXRadius); 1934 SkScalar xInnerRadRecip = SkScalarInvert(args.fInnerXRadius);
1939 SkScalar yInnerRadRecip = SkScalarInvert(args.fInnerYRadius); 1935 SkScalar yInnerRadRecip = SkScalarInvert(args.fInnerYRadius);
1940 1936
1941 // Extend the radii out half a pixel to antialias. 1937 // Extend the radii out half a pixel to antialias.
1942 SkScalar xOuterRadius = args.fXRadius + SK_ScalarHalf; 1938 SkScalar xOuterRadius = args.fXRadius + SK_ScalarHalf;
1943 SkScalar yOuterRadius = args.fYRadius + SK_ScalarHalf; 1939 SkScalar yOuterRadius = args.fYRadius + SK_ScalarHalf;
1944 1940
1945 const SkRect& bounds = args.fBounds; 1941 const SkRect& bounds = args.fDevBounds;
1946 1942
1947 SkScalar yCoords[4] = { 1943 SkScalar yCoords[4] = {
1948 bounds.fTop, 1944 bounds.fTop,
1949 bounds.fTop + yOuterRadius, 1945 bounds.fTop + yOuterRadius,
1950 bounds.fBottom - yOuterRadius, 1946 bounds.fBottom - yOuterRadius,
1951 bounds.fBottom 1947 bounds.fBottom
1952 }; 1948 };
1953 SkScalar yOuterOffsets[4] = { 1949 SkScalar yOuterOffsets[4] = {
1954 yOuterRadius, 1950 yOuterRadius,
1955 SK_ScalarNearlyZero, // we're using inversesqrt() in shader, so can't be exactly 0 1951 SK_ScalarNearlyZero, // we're using inversesqrt() in shader, so can't be exactly 0
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 2163
2168 // Expand the rect so all the pixels will be captured. 2164 // Expand the rect so all the pixels will be captured.
2169 bounds.outset(SK_ScalarHalf, SK_ScalarHalf); 2165 bounds.outset(SK_ScalarHalf, SK_ScalarHalf);
2170 2166
2171 RRectCircleRendererBatch::Geometry geometry; 2167 RRectCircleRendererBatch::Geometry geometry;
2172 geometry.fViewMatrix = viewMatrix; 2168 geometry.fViewMatrix = viewMatrix;
2173 geometry.fColor = color; 2169 geometry.fColor = color;
2174 geometry.fInnerRadius = innerRadius; 2170 geometry.fInnerRadius = innerRadius;
2175 geometry.fOuterRadius = outerRadius; 2171 geometry.fOuterRadius = outerRadius;
2176 geometry.fStroke = isStrokeOnly; 2172 geometry.fStroke = isStrokeOnly;
2177 geometry.fBounds = bounds; 2173 geometry.fDevBounds = bounds;
2178
2179 viewMatrix.mapRect(&bounds);
2180 2174
2181 SkAutoTUnref<GrBatch> batch(RRectCircleRendererBatch::Create(geometry, i ndexBuffer)); 2175 SkAutoTUnref<GrBatch> batch(RRectCircleRendererBatch::Create(geometry, i ndexBuffer));
2182 target->drawBatch(pipelineBuilder, batch, &bounds); 2176 target->drawBatch(pipelineBuilder, batch, &bounds);
2183 2177
2184 // otherwise we use the ellipse renderer 2178 // otherwise we use the ellipse renderer
2185 } else { 2179 } else {
2186 SkScalar innerXRadius = 0.0f; 2180 SkScalar innerXRadius = 0.0f;
2187 SkScalar innerYRadius = 0.0f; 2181 SkScalar innerYRadius = 0.0f;
2188 if (hasStroke) { 2182 if (hasStroke) {
2189 if (SkScalarNearlyZero(scaledStroke.length())) { 2183 if (SkScalarNearlyZero(scaledStroke.length())) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2221 bounds.outset(SK_ScalarHalf, SK_ScalarHalf); 2215 bounds.outset(SK_ScalarHalf, SK_ScalarHalf);
2222 2216
2223 RRectEllipseRendererBatch::Geometry geometry; 2217 RRectEllipseRendererBatch::Geometry geometry;
2224 geometry.fViewMatrix = viewMatrix; 2218 geometry.fViewMatrix = viewMatrix;
2225 geometry.fColor = color; 2219 geometry.fColor = color;
2226 geometry.fXRadius = xRadius; 2220 geometry.fXRadius = xRadius;
2227 geometry.fYRadius = yRadius; 2221 geometry.fYRadius = yRadius;
2228 geometry.fInnerXRadius = innerXRadius; 2222 geometry.fInnerXRadius = innerXRadius;
2229 geometry.fInnerYRadius = innerYRadius; 2223 geometry.fInnerYRadius = innerYRadius;
2230 geometry.fStroke = isStrokeOnly; 2224 geometry.fStroke = isStrokeOnly;
2231 geometry.fBounds = bounds; 2225 geometry.fDevBounds = bounds;
2232
2233 viewMatrix.mapRect(&bounds);
2234 2226
2235 SkAutoTUnref<GrBatch> batch(RRectEllipseRendererBatch::Create(geometry, indexBuffer)); 2227 SkAutoTUnref<GrBatch> batch(RRectEllipseRendererBatch::Create(geometry, indexBuffer));
2236 target->drawBatch(pipelineBuilder, batch, &bounds); 2228 target->drawBatch(pipelineBuilder, batch, &bounds);
2237 } 2229 }
2238 return true; 2230 return true;
2239 } 2231 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698