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

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

Issue 13165012: Simplify the circle outset code and add comment relating it to the shader code. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 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 | Annotate | Revision Log
« 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 "effects/GrCircleEdgeEffect.h" 10 #include "effects/GrCircleEdgeEffect.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } else { 123 } else {
124 halfWidth = SkScalarHalf(strokeWidth); 124 halfWidth = SkScalarHalf(strokeWidth);
125 } 125 }
126 126
127 outerRadius += halfWidth; 127 outerRadius += halfWidth;
128 if (isStroked) { 128 if (isStroked) {
129 innerRadius = SkMaxScalar(0, radius - halfWidth); 129 innerRadius = SkMaxScalar(0, radius - halfWidth);
130 } 130 }
131 } 131 }
132 132
133 // The radii are outset for two reasons. First, it allows the shader to simp ly perform
134 // clamp(distance-to-center - radius, 0, 1). Second, the outer radius is use d to compute the
135 // verts of the bounding box that is rendered and the outset ensures the box will cover all
136 // pixels partially covered by the circle.
137 outerRadius += SK_ScalarHalf;
138 innerRadius -= SK_ScalarHalf;
139
133 for (int i = 0; i < 4; ++i) { 140 for (int i = 0; i < 4; ++i) {
134 verts[i].fCenter = center; 141 verts[i].fCenter = center;
135 verts[i].fOuterRadius = outerRadius + 0.5f; 142 verts[i].fOuterRadius = outerRadius;
136 verts[i].fInnerRadius = innerRadius - 0.5f; 143 verts[i].fInnerRadius = innerRadius;
137 } 144 }
138 145
139 // We've extended the outer radius out half a pixel to antialias.
140 // Expand the drawn rect here so all the pixels will be captured.
141 SkRect bounds = SkRect::MakeLTRB( 146 SkRect bounds = SkRect::MakeLTRB(
142 center.fX - outerRadius - SK_ScalarHalf, 147 center.fX - outerRadius,
143 center.fY - outerRadius - SK_ScalarHalf, 148 center.fY - outerRadius,
144 center.fX + outerRadius + SK_ScalarHalf, 149 center.fX + outerRadius,
145 center.fY + outerRadius + SK_ScalarHalf 150 center.fY + outerRadius
146 ); 151 );
147 152
148 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop); 153 verts[0].fPos = SkPoint::Make(bounds.fLeft, bounds.fTop);
149 verts[1].fPos = SkPoint::Make(bounds.fRight, bounds.fTop); 154 verts[1].fPos = SkPoint::Make(bounds.fRight, bounds.fTop);
150 verts[2].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom); 155 verts[2].fPos = SkPoint::Make(bounds.fLeft, bounds.fBottom);
151 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom); 156 verts[3].fPos = SkPoint::Make(bounds.fRight, bounds.fBottom);
152 157
153 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds); 158 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds);
154 } 159 }
155 160
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 T += center.fY - SK_ScalarHalf; 270 T += center.fY - SK_ScalarHalf;
266 B += center.fY + SK_ScalarHalf; 271 B += center.fY + SK_ScalarHalf;
267 272
268 verts[0].fPos = SkPoint::Make(L, T); 273 verts[0].fPos = SkPoint::Make(L, T);
269 verts[1].fPos = SkPoint::Make(R, T); 274 verts[1].fPos = SkPoint::Make(R, T);
270 verts[2].fPos = SkPoint::Make(L, B); 275 verts[2].fPos = SkPoint::Make(L, B);
271 verts[3].fPos = SkPoint::Make(R, B); 276 verts[3].fPos = SkPoint::Make(R, B);
272 277
273 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4); 278 target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4);
274 } 279 }
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