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 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 SkScalar yRadius = geom.fYRadius; | 812 SkScalar yRadius = geom.fYRadius; |
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 // fOffsets are expanded from xyRadii to include the half-pixel anti
aliasing width. |
| 823 SkScalar xMaxOffset = xRadius + SK_ScalarHalf; |
| 824 SkScalar yMaxOffset = yRadius + SK_ScalarHalf; |
| 825 |
822 // The inner radius in the vertex data must be specified in normaliz
ed space. | 826 // The inner radius in the vertex data must be specified in normaliz
ed space. |
823 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); | 827 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); |
824 verts[0].fColor = color; | 828 verts[0].fColor = color; |
825 verts[0].fOffset = SkPoint::Make(-xRadius, -yRadius); | 829 verts[0].fOffset = SkPoint::Make(-xMaxOffset, -yMaxOffset); |
826 verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 830 verts[0].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
827 verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; | 831 verts[0].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; |
828 | 832 |
829 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); | 833 verts[1].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); |
830 verts[1].fColor = color; | 834 verts[1].fColor = color; |
831 verts[1].fOffset = SkPoint::Make(-xRadius, yRadius); | 835 verts[1].fOffset = SkPoint::Make(-xMaxOffset, yMaxOffset); |
832 verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 836 verts[1].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
833 verts[1].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; | 837 verts[1].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; |
834 | 838 |
835 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); | 839 verts[2].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); |
836 verts[2].fColor = color; | 840 verts[2].fColor = color; |
837 verts[2].fOffset = SkPoint::Make(xRadius, yRadius); | 841 verts[2].fOffset = SkPoint::Make(xMaxOffset, yMaxOffset); |
838 verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 842 verts[2].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
839 verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; | 843 verts[2].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; |
840 | 844 |
841 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); | 845 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); |
842 verts[3].fColor = color; | 846 verts[3].fColor = color; |
843 verts[3].fOffset = SkPoint::Make(xRadius, -yRadius); | 847 verts[3].fOffset = SkPoint::Make(xMaxOffset, -yMaxOffset); |
844 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); | 848 verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip); |
845 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; | 849 verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip)
; |
846 | 850 |
847 verts += kVerticesPerQuad; | 851 verts += kVerticesPerQuad; |
848 } | 852 } |
849 helper.recordDraw(target, gp); | 853 helper.recordDraw(target, gp); |
850 } | 854 } |
851 | 855 |
852 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 856 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
853 EllipseBatch* that = t->cast<EllipseBatch>(); | 857 EllipseBatch* that = t->cast<EllipseBatch>(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 // this is legit only if scale & translation (which should be the case a
t the moment) | 935 // this is legit only if scale & translation (which should be the case a
t the moment) |
932 if (isStrokeOnly) { | 936 if (isStrokeOnly) { |
933 innerXRadius = xRadius - scaledStroke.fX; | 937 innerXRadius = xRadius - scaledStroke.fX; |
934 innerYRadius = yRadius - scaledStroke.fY; | 938 innerYRadius = yRadius - scaledStroke.fY; |
935 } | 939 } |
936 | 940 |
937 xRadius += scaledStroke.fX; | 941 xRadius += scaledStroke.fX; |
938 yRadius += scaledStroke.fY; | 942 yRadius += scaledStroke.fY; |
939 } | 943 } |
940 | 944 |
941 // We've extended the outer x radius out half a pixel to antialias. | |
942 // 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 xRadius += SK_ScalarHalf; | |
945 yRadius += SK_ScalarHalf; | |
946 | |
947 EllipseBatch::Geometry geometry; | 945 EllipseBatch::Geometry geometry; |
948 geometry.fColor = color; | 946 geometry.fColor = color; |
949 geometry.fXRadius = xRadius; | 947 geometry.fXRadius = xRadius; |
950 geometry.fYRadius = yRadius; | 948 geometry.fYRadius = yRadius; |
951 geometry.fInnerXRadius = innerXRadius; | 949 geometry.fInnerXRadius = innerXRadius; |
952 geometry.fInnerYRadius = innerYRadius; | 950 geometry.fInnerYRadius = innerYRadius; |
953 geometry.fDevBounds = SkRect::MakeLTRB(center.fX - xRadius, center.fY - yRad
ius, | 951 geometry.fDevBounds = SkRect::MakeLTRB(center.fX - xRadius, center.fY - yRad
ius, |
954 center.fX + xRadius, center.fY + yRad
ius); | 952 center.fX + xRadius, center.fY + yRad
ius); |
955 | 953 |
| 954 // outset bounds to include half-pixel width antialiasing. |
| 955 geometry.fDevBounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 956 |
956 return new EllipseBatch(geometry, viewMatrix, | 957 return new EllipseBatch(geometry, viewMatrix, |
957 isStrokeOnly && innerXRadius > 0 && innerYRadius > 0
); | 958 isStrokeOnly && innerXRadius > 0 && innerYRadius > 0
); |
958 } | 959 } |
959 | 960 |
960 GrDrawBatch* GrOvalRenderer::CreateEllipseBatch(GrColor color, | 961 GrDrawBatch* GrOvalRenderer::CreateEllipseBatch(GrColor color, |
961 const SkMatrix& viewMatrix, | 962 const SkMatrix& viewMatrix, |
962 const SkRect& ellipse, | 963 const SkRect& ellipse, |
963 const SkStrokeRec& stroke) { | 964 const SkStrokeRec& stroke) { |
964 return create_ellipse_batch(color, viewMatrix, ellipse, stroke); | 965 return create_ellipse_batch(color, viewMatrix, ellipse, stroke); |
965 } | 966 } |
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1717 } | 1718 } |
1718 | 1719 |
1719 DRAW_BATCH_TEST_DEFINE(RRectBatch) { | 1720 DRAW_BATCH_TEST_DEFINE(RRectBatch) { |
1720 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 1721 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
1721 GrColor color = GrRandomColor(random); | 1722 GrColor color = GrRandomColor(random); |
1722 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 1723 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
1723 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); | 1724 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); |
1724 } | 1725 } |
1725 | 1726 |
1726 #endif | 1727 #endif |
OLD | NEW |