From 58e30fe8649deb1ffc5bda3627945228b028c439 Mon Sep 17 00:00:00 2001 From: "bsalomon@google.com" Date: Mon, 1 Apr 2013 19:01:20 +0000 Subject: [PATCH] Simplify the circle outset code and add comment relating it to the shader code. Review URL: https://codereview.chromium.org/13165012 git-svn-id: http://skia.googlecode.com/svn/trunk@8463 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/gpu/GrOvalRenderer.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp index 7da89bd..8bc0428 100644 --- a/src/gpu/GrOvalRenderer.cpp +++ b/src/gpu/GrOvalRenderer.cpp @@ -130,19 +130,24 @@ void GrOvalRenderer::drawCircle(GrDrawTarget* target, } } + // The radii are outset for two reasons. First, it allows the shader to simply perform + // clamp(distance-to-center - radius, 0, 1). Second, the outer radius is used to compute the + // verts of the bounding box that is rendered and the outset ensures the box will cover all + // pixels partially covered by the circle. + outerRadius += SK_ScalarHalf; + innerRadius -= SK_ScalarHalf; + for (int i = 0; i < 4; ++i) { verts[i].fCenter = center; - verts[i].fOuterRadius = outerRadius + 0.5f; - verts[i].fInnerRadius = innerRadius - 0.5f; + verts[i].fOuterRadius = outerRadius; + verts[i].fInnerRadius = innerRadius; } - // We've extended the outer radius out half a pixel to antialias. - // Expand the drawn rect here so all the pixels will be captured. SkRect bounds = SkRect::MakeLTRB( - center.fX - outerRadius - SK_ScalarHalf, - center.fY - outerRadius - SK_ScalarHalf, - center.fX + outerRadius + SK_ScalarHalf, - center.fY + outerRadius + SK_ScalarHalf + center.fX - outerRadius, + center.fY - outerRadius, + center.fX + outerRadius, + center.fY + outerRadius ); verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); -- 2.7.4