From 5c293c0e44c7f0e99f15a2c0d8427de175f28bd3 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Wed, 15 Jan 2025 10:41:21 +0100 Subject: [PATCH] Use AutoScaleMethod "smooth" by default for fractional scaling Currently, AutoScaleMethod "nearest" is used by default, leading to jagged image scaling results. The method "smooth" is only used on GTK with a fractional scaling value not being a multiple of 100. The reason for not using "smooth" scaling on all platform was a bug regarding icon transparency that has long been resolved. With this change, AutoScaleMethod "smooth" is used by default in fractional scaling scenarios (i.e., with deviceZoom not being an integer multiple of 100) and when using monitor-specific scaling on Windows. To still use "nearest" in these scenarios, it can be activated via system property. --- .../org/eclipse/swt/internal/DPIUtil.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java index 06804718372..fe91ef5a8c5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java @@ -79,10 +79,9 @@ private static enum AutoScaleMethod { AUTO, NEAREST, SMOOTH } *
  • "nearest": nearest-neighbor interpolation, may look jagged
  • *
  • "smooth": smooth edges, may look blurry
  • * - * The current default is to use "nearest", except on - * GTK when the deviceZoom is not an integer multiple of 100%. - * The smooth strategy currently doesn't work on Win32 and Cocoa, see - * bug 493455. + * The current default is to use "smooth" on GTK when deviceZoom is an integer + * multiple of 100% and on Windows if monitor-specific scaling is enabled, and + * "nearest" otherwise.. */ private static final String SWT_AUTOSCALE_METHOD = "swt.autoScale.method"; @@ -605,14 +604,22 @@ public static void setDeviceZoom (int nativeDeviceZoom) { DPIUtil.deviceZoom = deviceZoom; System.setProperty("org.eclipse.swt.internal.deviceZoom", Integer.toString(deviceZoom)); if (deviceZoom != 100 && autoScaleMethodSetting == AutoScaleMethod.AUTO) { - if (deviceZoom / 100 * 100 == deviceZoom || !"gtk".equals(SWT.getPlatform())) { - autoScaleMethod = AutoScaleMethod.NEAREST; - } else { + if (sholdUseSmoothScaling()) { autoScaleMethod = AutoScaleMethod.SMOOTH; + } else { + autoScaleMethod = AutoScaleMethod.NEAREST; } } } +private static boolean sholdUseSmoothScaling() { + return switch (SWT.getPlatform()) { + case "gtk" -> deviceZoom / 100 * 100 != deviceZoom; + case "win32" -> isMonitorSpecificScalingActive(); + default -> false; + }; +} + public static void setUseCairoAutoScale (boolean cairoAutoScale) { useCairoAutoScale = cairoAutoScale; }