Skip to content

Commit

Permalink
Merge pull request #18928 from ramezgerges/x11_dpi_less_than_1
Browse files Browse the repository at this point in the history
fix(x11): fix rendering when DPI scaling is less than 1
  • Loading branch information
ramezgerges authored Nov 27, 2024
2 parents 164d808 + c877936 commit d7ff587
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 33 deletions.
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),
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

0 comments on commit d7ff587

Please sign in to comment.