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

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

Issue 2106953009: Fix bug where ovals' AA exceed bounds by .5 pixel (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: In addition to the past change, also outset/expand relevant variables/bounds Created 4 years, 5 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 "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 813
814 // Compute the reciprocals of the radii here to save time in the sha der 814 // Compute the reciprocals of the radii here to save time in the sha der
815 SkScalar xRadRecip = SkScalarInvert(xRadius); 815 SkScalar xRadRecip = SkScalarInvert(xRadius);
816 SkScalar yRadRecip = SkScalarInvert(yRadius); 816 SkScalar yRadRecip = SkScalarInvert(yRadius);
817 SkScalar xInnerRadRecip = SkScalarInvert(geom.fInnerXRadius); 817 SkScalar xInnerRadRecip = SkScalarInvert(geom.fInnerXRadius);
818 SkScalar yInnerRadRecip = SkScalarInvert(geom.fInnerYRadius); 818 SkScalar yInnerRadRecip = SkScalarInvert(geom.fInnerYRadius);
819 819
820 const SkRect& bounds = geom.fDevBounds; 820 const SkRect& bounds = geom.fDevBounds;
821 821
822 // The inner radius in the vertex data must be specified in normaliz ed space. 822 // The inner radius in the vertex data must be specified in normaliz ed space.
823 // fOffsets are expanded from xxRadii to include the half-pixel anti aliasing width.
823 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); 824 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop);
824 verts[0].fColor = color; 825 verts[0].fColor = color;
825 verts[0].fOffset = SkPoint::Make(-xRadius, -yRadius); 826 verts[0].fOffset = SkPoint::Make(-xRadius - SK_ScalarHalf, -yRadius - SK_ScalarHalf);
jvanverth1 2016/06/30 18:00:06 I suggest creating two variables, like xMaxOffset
vjiaoblack 2016/06/30 18:41:17 Done.
826 verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); 827 verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip);
827 verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip) ; 828 verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip) ;
828 829
829 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); 830 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom);
830 verts[1].fColor = color; 831 verts[1].fColor = color;
831 verts[1].fOffset = SkPoint::Make(-xRadius, yRadius); 832 verts[1].fOffset = SkPoint::Make(-xRadius - SK_ScalarHalf, yRadius + SK_ScalarHalf);
832 verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); 833 verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip);
833 verts[1].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip) ; 834 verts[1].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip) ;
834 835
835 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); 836 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom);
836 verts[2].fColor = color; 837 verts[2].fColor = color;
837 verts[2].fOffset = SkPoint::Make(xRadius, yRadius); 838 verts[2].fOffset = SkPoint::Make(xRadius + SK_ScalarHalf, yRadius + SK_ScalarHalf);
838 verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); 839 verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip);
839 verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip) ; 840 verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip) ;
840 841
841 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); 842 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop);
842 verts[3].fColor = color; 843 verts[3].fColor = color;
843 verts[3].fOffset = SkPoint::Make(xRadius, -yRadius); 844 verts[3].fOffset = SkPoint::Make(xRadius + SK_ScalarHalf, -yRadius - SK_ScalarHalf);
844 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); 845 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip);
845 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip) ; 846 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip) ;
846 847
847 verts += kVerticesPerQuad; 848 verts += kVerticesPerQuad;
848 } 849 }
849 helper.recordDraw(target, gp); 850 helper.recordDraw(target, gp);
850 } 851 }
851 852
852 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { 853 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
853 EllipseBatch* that = t->cast<EllipseBatch>(); 854 EllipseBatch* that = t->cast<EllipseBatch>();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 // this is legit only if scale & translation (which should be the case a t the moment) 932 // this is legit only if scale & translation (which should be the case a t the moment)
932 if (isStrokeOnly) { 933 if (isStrokeOnly) {
933 innerXRadius = xRadius - scaledStroke.fX; 934 innerXRadius = xRadius - scaledStroke.fX;
934 innerYRadius = yRadius - scaledStroke.fY; 935 innerYRadius = yRadius - scaledStroke.fY;
935 } 936 }
936 937
937 xRadius += scaledStroke.fX; 938 xRadius += scaledStroke.fX;
938 yRadius += scaledStroke.fY; 939 yRadius += scaledStroke.fY;
939 } 940 }
940 941
941 // We've extended the outer x radius out half a pixel to antialias. 942 // We've extended the outer x radius out half a pixel to antialias.
jvanverth1 2016/06/30 18:00:06 I would delete all these lines.
vjiaoblack 2016/06/30 18:41:17 Done.
942 // This will also expand the rect so all the pixels will be captured. 943 // This will also expand the rect so all the pixels will be captured.
943 // TODO: Consider if we should use sqrt(2)/2 instead 944 // TODO: Consider if we should use sqrt(2)/2 instead
944 xRadius += SK_ScalarHalf; 945 // xRadius += SK_ScalarHalf;
945 yRadius += SK_ScalarHalf; 946 // yRadius += SK_ScalarHalf;
946 947
947 EllipseBatch::Geometry geometry; 948 EllipseBatch::Geometry geometry;
948 geometry.fColor = color; 949 geometry.fColor = color;
949 geometry.fXRadius = xRadius; 950 geometry.fXRadius = xRadius;
950 geometry.fYRadius = yRadius; 951 geometry.fYRadius = yRadius;
951 geometry.fInnerXRadius = innerXRadius; 952 geometry.fInnerXRadius = innerXRadius;
952 geometry.fInnerYRadius = innerYRadius; 953 geometry.fInnerYRadius = innerYRadius;
953 geometry.fDevBounds = SkRect::MakeLTRB(center.fX - xRadius, center.fY - yRad ius, 954 geometry.fDevBounds = SkRect::MakeLTRB(center.fX - xRadius, center.fY - yRad ius,
954 center.fX + xRadius, center.fY + yRad ius); 955 center.fX + xRadius, center.fY + yRad ius);
955 956
957 // outset bounds to include half-pixel width antialiasing.
958 geometry.fDevBounds.outset(SK_ScalarHalf, SK_ScalarHalf);
959
956 return new EllipseBatch(geometry, viewMatrix, 960 return new EllipseBatch(geometry, viewMatrix,
957 isStrokeOnly && innerXRadius > 0 && innerYRadius > 0 ); 961 isStrokeOnly && innerXRadius > 0 && innerYRadius > 0 );
958 } 962 }
959 963
960 GrDrawBatch* GrOvalRenderer::CreateEllipseBatch(GrColor color, 964 GrDrawBatch* GrOvalRenderer::CreateEllipseBatch(GrColor color,
961 const SkMatrix& viewMatrix, 965 const SkMatrix& viewMatrix,
962 const SkRect& ellipse, 966 const SkRect& ellipse,
963 const SkStrokeRec& stroke) { 967 const SkStrokeRec& stroke) {
964 return create_ellipse_batch(color, viewMatrix, ellipse, stroke); 968 return create_ellipse_batch(color, viewMatrix, ellipse, stroke);
965 } 969 }
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 } 1721 }
1718 1722
1719 DRAW_BATCH_TEST_DEFINE(RRectBatch) { 1723 DRAW_BATCH_TEST_DEFINE(RRectBatch) {
1720 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); 1724 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random);
1721 GrColor color = GrRandomColor(random); 1725 GrColor color = GrRandomColor(random);
1722 const SkRRect& rrect = GrTest::TestRRectSimple(random); 1726 const SkRRect& rrect = GrTest::TestRRectSimple(random);
1723 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom)); 1727 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom));
1724 } 1728 }
1725 1729
1726 #endif 1730 #endif
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