Simplify the circle outset code and add comment relating it to the shader code.
authorbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 1 Apr 2013 19:01:20 +0000 (19:01 +0000)
committerbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 1 Apr 2013 19:01:20 +0000 (19:01 +0000)
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

index 7da89bd..8bc0428 100644 (file)
@@ -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);