Skip to content

Commit

Permalink
fix: Ensure fractional DPI is avoided in HW GTK renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Nov 13, 2023
1 parent 729be33 commit edcf4e5
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public float LogicalDpi
var nativeWindow = window.Window;
if (nativeWindow is not null)
{
_dpi = _dpiHelper.GetNativeDpi();
_dpi = GetNativeDpi();
}
}

Expand All @@ -72,7 +72,24 @@ public float LogicalDpi

private void OnDpiChanged(object? sender, EventArgs args)
{
_dpi = _dpiHelper.GetNativeDpi();
_dpi = GetNativeDpi();
_displayInformation.NotifyDpiChanged();
}

private float GetNativeDpi()
{
var dpi = _dpiHelper.GetNativeDpi();

if (GtkHost.Current?.RenderSurfaceType == RenderSurfaceType.Software)
{
// Software rendering is not affected by fractional DPI.
return dpi;
}

// We need to make sure that in case of fractional DPI, we use the nearest whole DPI instead,
// otherwise we get GuardBand related rendering issues.
var fractionalDpi = dpi / DisplayInformation.BaseDpi;
var wholeDpi = Math.Max(1.0, float.Floor(fractionalDpi));
return wholeDpi * DisplayInformation.BaseDpi;
}
}

0 comments on commit edcf4e5

Please sign in to comment.