Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(x11): fix rendering when DPI scaling is less than 1 #18928

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 6 additions & 31 deletions src/Uno.UI.Runtime.Skia.X11/X11DisplayInformationExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,16 @@ 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);

_details = new(
(uint)X11Helper.XWidthOfScreen(screen),
(uint)X11Helper.XHeightOfScreen(screen),
flooredScale * DisplayInformation.BaseDpi,
flooredScale,
(ResolutionScale)(int)(flooredScale * 100.0),
(float)(rawScale * DisplayInformation.BaseDpi),
jeromelaban marked this conversation as resolved.
Show resolved Hide resolved
rawScale,
(ResolutionScale)(int)(rawScale * 100),
Math.Sqrt(widthInInches * widthInInches + heightInInches * heightInInches)
);
}
Expand All @@ -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
Expand Down Expand Up @@ -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 <x|y>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
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI.Runtime.Skia.X11/X11OpenGLRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI.Runtime.Skia.X11/X11SoftwareRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Loading