From 1ef1e79b9358216314b7069b1b8fa91e224624e2 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 26 Apr 2021 17:28:47 +0200 Subject: [PATCH] GL backend: Fix round corner clip radius Rendering tests/cases/examples/rectangle_clip.60 shows a border radius for the clipped area that's not identical with the border radius of the inner edge of the rectangle stroke. It appears that the stroke's inner radius is not exactly the difference of the line (border) width but rather scaled by kappa. --- sixtyfps_runtime/rendering_backends/gl/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sixtyfps_runtime/rendering_backends/gl/lib.rs b/sixtyfps_runtime/rendering_backends/gl/lib.rs index 1eda91914..910a4f90b 100644 --- a/sixtyfps_runtime/rendering_backends/gl/lib.rs +++ b/sixtyfps_runtime/rendering_backends/gl/lib.rs @@ -46,6 +46,8 @@ type CanvasRc = Rc>>; pub const DEFAULT_FONT_SIZE: f32 = 12.; pub const DEFAULT_FONT_WEIGHT: i32 = 400; // CSS normal +const KAPPA90: f32 = 0.5522847493; + #[derive(PartialEq, Eq, Hash, Debug)] enum ImageCacheKey { Path(String), @@ -1075,8 +1077,12 @@ impl ItemRenderer for GLItemRenderer { // adjust_rect_and_border_for_inner_drawing adjusts the rect so that for drawing it // would be entirely an *inner* border. However for clipping we want the rect that's // entirely inside, hence the doubling of the width and consequently radius adjustment. - border_width *= self.scale_factor * 2.; - radius *= self.scale_factor * 0.75; + radius -= border_width * KAPPA90; + border_width *= 2.; + + // Convert from logical to physical pixels + border_width *= self.scale_factor; + radius *= self.scale_factor; clip_rect *= self.scale_factor; adjust_rect_and_border_for_inner_drawing(&mut clip_rect, &mut border_width);