From 78609202731252f0024e6330cc94c52b05c1d146 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Thu, 16 Jan 2020 01:37:21 +0100
Subject: Bug 1422: Use own deviceZoomScaleUp(..) disregarding higher-toolkit's
 compensation like 'DPIUtil.useCairoAutoScale()'

We can't use DPIUtil's 'autoScaleUp(..)' method on non-native DPI scaling platforms
as it uses a scale-factor of 1f if the higher toolkit compensates, i.e. 'DPIUtil.useCairoAutoScale()'.

Since NEWT uses X11 and GDI directly, which are not DPI scale-aware,
we have to drop the semnatics of 'DPIUtil.useCairoAutoScale()'
and merely use the actual 'deviceZoom'.

This was proposed by Marcel Au in the first place.
At least I understand these semantics by now.

+++

Additionally NewtCanvasSWT.SWTNativeWindow needs to return the 'deviceZoomScaleUp(..)'
values for returning its size in window- and pixel-units (surface).
---
 .../classes/com/jogamp/newt/swt/NewtCanvasSWT.java | 28 ++++++++++++++++------
 1 file changed, 21 insertions(+), 7 deletions(-)

(limited to 'src/newt/classes/com/jogamp')

diff --git a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java
index 0e58b389d..3bcf4fdab 100644
--- a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java
+++ b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java
@@ -179,8 +179,12 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC
     /**
      * Set's the NEWT {@link Window}'s size using {@link Window#setSize(int, int)}.
      * <p>
-     * For all non-native DPI autoscale platforms, it utilizes {@link SWTAccessor#autoScaleUp(Point)}
-     * by multiplying the given {@link Rectangle} size to emulate DPI scaling, see Bug 1422.
+     * For all non-native DPI autoscale platforms method uses {@link SWTAccessor#deviceZoomScaleUp(Point)},
+     * which multiplies the given {@link Rectangle} size with {@link SWTAccessor#getDeviceZoomScalingFactor()}
+     * to emulate DPI scaling, see Bug 1422.
+     * </p>
+     * <p>
+     * Otherwise this method uses the given {@link Rectangle} as-is.
      * </p>
      * <p>
      * Currently native DPI autoscale platforms are
@@ -193,12 +197,22 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC
      */
     private final void setNewtChildSize(final Rectangle r) {
         if( !SWTAccessor.isOSX ) {
-            final Point p = SWTAccessor.autoScaleUp(new Point(r.width, r.height));
+            final Point p = SWTAccessor.deviceZoomScaleUp(new Point(r.width, r.height));
             newtChild.setSize(p.getX(), p.getY());
         } else {
             newtChild.setSize(r.width, r.height);
         }
     }
+    /**
+     * See {@link #setNewtChildSize(Rectangle)}
+     */
+    private final int newtScaleUp(final int v) {
+        if( !SWTAccessor.isOSX ) {
+            return SWTAccessor.deviceZoomScaleUp(v);
+        } else {
+            return v;
+        }
+    }
     private final Listener swtListener = new Listener () {
         @Override
         public void handleEvent (final Event event) {
@@ -642,12 +656,12 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC
 
         @Override
         public int getWidth() {
-            return clientAreaWindow.width;
+            return newtScaleUp(clientAreaWindow.width);
         }
 
         @Override
         public int getHeight() {
-            return clientAreaWindow.height;
+            return newtScaleUp(clientAreaWindow.height);
         }
 
         @Override
@@ -666,12 +680,12 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC
 
         @Override
         public int getSurfaceWidth() {
-            return clientAreaPixels.width;
+            return newtScaleUp(clientAreaPixels.width);
         }
 
         @Override
         public int getSurfaceHeight() {
-            return clientAreaPixels.height;
+            return newtScaleUp(clientAreaPixels.height);
         }
 
         @Override
-- 
cgit v1.2.3