From c8779363386a275e2c9747ac02bd8e86ea17bea7 Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Tue, 26 Nov 2024 18:03:23 +0200 Subject: [PATCH] fix(x11): fix rendering when DPI scaling is less than 1 --- .../X11DisplayInformationExtension.cs | 37 +++---------------- .../X11OpenGLRenderer.cs | 2 +- .../X11SoftwareRenderer.cs | 2 +- 3 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/Uno.UI.Runtime.Skia.X11/X11DisplayInformationExtension.cs b/src/Uno.UI.Runtime.Skia.X11/X11DisplayInformationExtension.cs index 31a960e88a66..3acb0db554b0 100644 --- a/src/Uno.UI.Runtime.Skia.X11/X11DisplayInformationExtension.cs +++ b/src/Uno.UI.Runtime.Skia.X11/X11DisplayInformationExtension.cs @@ -229,8 +229,6 @@ internal void UpdateDetails() var rawScale = _scaleOverride ?? (TryGetXResource(XftDotdpi, out var xrdbScaling) ? xrdbScaling.Value : dpi / DisplayInformation.BaseDpi); - var flooredScale = FloorScale(rawScale); - // This returns very incorrect numbers as far as I've tested. var widthInInches = (uint)Math.Round(X11Helper.XWidthMMOfScreen(screen) / InchesToMilliMeters); var heightInInches = (uint)Math.Round(X11Helper.XHeightMMOfScreen(screen) / InchesToMilliMeters); @@ -238,9 +236,9 @@ internal void UpdateDetails() _details = new( (uint)X11Helper.XWidthOfScreen(screen), (uint)X11Helper.XHeightOfScreen(screen), - flooredScale * DisplayInformation.BaseDpi, - flooredScale, - (ResolutionScale)(int)(flooredScale * 100.0), + (float)(rawScale * DisplayInformation.BaseDpi), + rawScale, + (ResolutionScale)(int)(rawScale * 100), Math.Sqrt(widthInInches * widthInInches + heightInInches * heightInInches) ); } @@ -266,28 +264,6 @@ public uint ScreenWidthInRawPixels public void StartDpiChanged() { } public void StopDpiChanged() { } - private static float FloorScale(double rawDpi) - => rawDpi switch - { - >= 5.00f => 5.00f, - >= 4.50f => 4.50f, - >= 4.00f => 4.00f, - >= 3.50f => 3.50f, - >= 3.00f => 3.00f, - >= 2.50f => 2.50f, - >= 2.25f => 2.25f, - >= 2.00f => 2.00f, - >= 1.80f => 1.80f, - >= 1.75f => 1.75f, - >= 1.60f => 1.60f, - >= 1.50f => 1.50f, - >= 1.40f => 1.40f, - >= 1.25f => 1.25f, - >= 1.20f => 1.20f, - >= 1.00f => 1.00f, - _ => 1.00f, - }; - private bool TryGetXResource(string resourceName, [NotNullWhen(true)] out double? scaling) { // For some reason, querying the resources with a preexisting display yields outdated values, so @@ -472,14 +448,13 @@ private bool TryGetXResource(string resourceName, [NotNullWhen(true)] out double // With XRandR, we don't use the xScaling and yScaling values, since the server will "stretch" the window to // the required scaling. We don't need to do any scale by Scaling ourselves. var rawScale = _scaleOverride ?? (TryGetXResource(XftDotdpi, out var xrdbScaling) ? xrdbScaling.Value : 1); - var flooredScale = FloorScale(rawScale); return new DisplayInformationDetails( rawWidth, rawHeight, - flooredScale * DisplayInformation.BaseDpi, - flooredScale, - (ResolutionScale)(FloorScale(flooredScale) * 100), + (float)(rawScale * DisplayInformation.BaseDpi), + rawScale, + (ResolutionScale)(rawScale * 100), Math.Sqrt(outputInfo->mm_width * outputInfo->mm_width + outputInfo->mm_height * outputInfo->mm_height) / InchesToMilliMeters ); } diff --git a/src/Uno.UI.Runtime.Skia.X11/X11OpenGLRenderer.cs b/src/Uno.UI.Runtime.Skia.X11/X11OpenGLRenderer.cs index c0ef1d82c2a6..186096006e59 100644 --- a/src/Uno.UI.Runtime.Skia.X11/X11OpenGLRenderer.cs +++ b/src/Uno.UI.Runtime.Skia.X11/X11OpenGLRenderer.cs @@ -99,7 +99,7 @@ void IX11Renderer.Render() var scale = _host.RootElement?.XamlRoot is { } root ? root.RasterizationScale : 1; - _surface.Canvas.Scale((int)scale); + _surface.Canvas.Scale((float)scale); if (_host.RootElement?.Visual is { } rootVisual) { diff --git a/src/Uno.UI.Runtime.Skia.X11/X11SoftwareRenderer.cs b/src/Uno.UI.Runtime.Skia.X11/X11SoftwareRenderer.cs index 17a65e9ac347..715c18f3c778 100644 --- a/src/Uno.UI.Runtime.Skia.X11/X11SoftwareRenderer.cs +++ b/src/Uno.UI.Runtime.Skia.X11/X11SoftwareRenderer.cs @@ -74,7 +74,7 @@ void IX11Renderer.Render() var scale = host.RootElement?.XamlRoot is { } root ? root.RasterizationScale : 1; - canvas.Scale((int)scale); + canvas.Scale((float)scale); if (host.RootElement?.Visual is { } rootVisual) {