Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 778edc8

Browse files
csmartdalton86Skia Commit-Bot
authored andcommitted
Don't let neighboring radii in GrAAFillRRectOp get too close
Since each corner uses a different reference point, it's possible that FP rounding can cause the edges of very close radii on a common edge to accidentally overlap. This can cause a pixel to be drawn/blended more than once. This CL addresses the issue by not allowing neighboring radii on a common edge to get closer than 1/16 pixel from one another. Bug: skia:8562 Change-Id: Ifda97c9a4c3973405f86f7fc6846a4073b3ab581 Reviewed-on: https://skia-review.googlesource.com/c/173036 Commit-Queue: Chris Dalton <csmartdalton@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com>
1 parent 54bf684 commit 778edc8

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/gpu/ops/GrAAFillRRectOp.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ class GrAAFillRRectOp::Processor::Impl : public GrGLSLGeometryProcessor {
325325
v->codeAppend("float2 aa_bloatradius = axiswidths * pixellength * .5;");
326326

327327
// Identify our radii.
328-
v->codeAppend("float2 radii = float2(dot(radii_selector, radii_x), "
329-
"dot(radii_selector, radii_y));");
328+
v->codeAppend("float4 radii_and_neighbors = radii_selector"
329+
"* float4x4(radii_x, radii_y, radii_x.yxwz, radii_y.wzyx);");
330+
v->codeAppend("float2 radii = radii_and_neighbors.xy;");
331+
v->codeAppend("float2 neighbor_radii = radii_and_neighbors.zw;");
330332

331333
v->codeAppend("if (any(greaterThan(aa_bloatradius, float2(1)))) {");
332334
// The rrect is more narrow than an AA coverage ramp. We can't draw as-is
@@ -347,11 +349,14 @@ class GrAAFillRRectOp::Processor::Impl : public GrGLSLGeometryProcessor {
347349
v->codeAppend( "radius_outset = floor(abs(radius_outset)) * radius_outset;");
348350
v->codeAppend( "is_linear_coverage = 1;");
349351
v->codeAppend("} else {");
350-
// Don't let actual arc radii get smaller than a pixel.
352+
// Don't let radii get smaller than a pixel.
351353
v->codeAppend( "radii = clamp(radii, pixellength, 2 - pixellength);");
354+
v->codeAppend( "neighbor_radii = clamp(neighbor_radii, pixellength, 2 - pixellength);");
355+
// Don't let neighboring radii get closer together than 1/16 pixel.
356+
v->codeAppend( "float2 spacing = 2 - radii - neighbor_radii;");
357+
v->codeAppend( "float2 extra_pad = max(pixellength * .0625 - spacing, float2(0));");
358+
v->codeAppend( "radii -= extra_pad * .5;");
352359
v->codeAppend("}");
353-
// Bias radii slightly inward to avoid accidental overlap of geometries from fp rounding.
354-
v->codeAppend("radii -= aa_bloatradius * 1e-3;");
355360

356361
// Find our vertex position, adjusted for radii and bloated for AA. Our rect is drawn in
357362
// normalized [-1,-1,+1,+1] space.

0 commit comments

Comments
 (0)