<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://jogamp.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.2"
          urlbase="https://jogamp.org/bugzilla/"
          
          maintainer="sgothel@jausoft.com"
>

    <bug>
          <bug_id>1422</bug_id>
          
          <creation_ts>2020-01-06 23:57:39 +0100</creation_ts>
          <short_desc>NEWT: Handle SWT&apos;s DPI Scaling on non native dpi scaling platforms (Linux, Windows, ..)</short_desc>
          <delta_ts>2020-02-04 14:27:01 +0100</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>3</classification_id>
          <classification>JogAmp</classification>
          <product>Newt</product>
          <component>swt</component>
          <version>2.4.1</version>
          <rep_platform>All</rep_platform>
          <op_sys>all</op_sys>
          <bug_status>VERIFIED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P4</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>1358</dependson>
    
    <dependson>1421</dependson>
          <blocked>674</blocked>
    
    <blocked>1373</blocked>
    
    <blocked>1423</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Sven Gothel">sgothel</reporter>
          <assigned_to name="Sven Gothel">sgothel</assigned_to>
          <cc>marcel.au</cc>
          
          <cf_type>DEFECT</cf_type>
          <cf_scm_refs>d671b2ab3badbcfdbe0ff57f55ff997ba7bcb060
78609202731252f0024e6330cc94c52b05c1d146
f63b94cccc71cf154a7a6d3359ceface3a683229</cf_scm_refs>
          <cf_workaround>---</cf_workaround>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>6549</commentid>
    <comment_count>0</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-01-06 23:57:39 +0100</bug_when>
    <thetext>Bug 1358 and Bug 1421 discuss the dpi scaling size (1358) 
in general and the positioning (1421) in particular for MacOS.

This bug shall discuss the mapping of SWT&apos;s dpi-scaling
to NEWT on platforms other than MacOS where it is not actually implemented
in the native toolkits: Windows and Linux GTK.
This issue is in particular for NewtCanvasSWT.

Both latter platforms may have a high level artificial dpi-scaling for 
so called unaware applications to map the 75 dpi on 150 dpi or higher.
However, this is not part of their native low level interfaces (X11 and GDI) 
as used by e.g. NEWT.

This bug entry resides in product NEWT,
as JOGL&apos;s SWT GLCanvas should be complete by now and reflect
all SWT dpi scaling API entries.

How and if we shall impose this non-native toolkit scaling in NEWT
for SWT or even expose it in general for NEWT is the question.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6550</commentid>
    <comment_count>1</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-01-07 00:00:38 +0100</bug_when>
    <thetext>Marcel found still issues on Windows and Linux re scaling,
see Bug 1421 comment 11 through Bug 1421 comment 16.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6566</commentid>
    <comment_count>2</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-01-14 09:00:35 +0100</bug_when>
    <thetext>See Marcel&apos;s on Bug 1421 comment 31</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6567</commentid>
    <comment_count>3</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-01-14 09:01:45 +0100</bug_when>
    <thetext>(In reply to Sven Gothel from comment #2)
Marcel wrote:

Just one note to the highDPI implementation on Window and Linux.

With the last built the canvas still occupies only 1/4 of the swt canvas.

I had to correct the scale at three positions where I scale up the NewtCanvasSWT:
 
int scale=(int)DPIUtil.getDeviceZoom()/100;


at the three positions where the call to newtChild.setSize(...) occurs.  I correct the implementation with:

newtChild.setSize(clientAreaWindow.width*scale, clientAreaWindow.height*scale);</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6573</commentid>
    <comment_count>4</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-01-15 06:06:22 +0100</bug_when>
    <thetext>(In reply to Sven Gothel from comment #3)
&gt; int scale=(int)DPIUtil.getDeviceZoom()/100;

It is actually &apos;float scaleFactor = DPIUtil.getDeviceZoom()/100f;&apos;

Something like this:

public static int autoScaleUp (int size) {
  final int deviceZoom = DPIUtil.getDeviceZoom();
  if (deviceZoom == 100) return size;
  float scaleFactor = deviceZoom/100f;
  return Math.round (size * scaleFactor);
}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6574</commentid>
    <comment_count>5</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-01-15 08:04:00 +0100</bug_when>
    <thetext>commit d671b2ab3badbcfdbe0ff57f55ff997ba7bcb060

Bug 1422: Emulate DPI Scaling on non-native DPI autoscale platforms (!MacOS)
 
Bug 1422 shows that it seems to be desired to emulate DPI scaling where
the native toolkit does not implmement the same.
    
On GTK, DPIUtil.mapDPIToZoom (int dpi) reads:
  double zoom = (double) dpi * 100 / 96; 
  int roundedZoom = (int) Math.round (zoom);
  return roundedZoom;
   
While having dpi calculated as: 
    
  dpi = 96 * GDK.gdk_monitor_get_scale_factor(monitor);
    
Well, this seems to exist to allow 96 dpi fixed layout to
&apos;look&apos; OK on high-dpi screens.
However, you get in trouble if you layout high-dpi aware,
i.e. using percentages etc.
    
There is one exception: If DPIUtil.useCairoAutoScale() is true, scalingFactor is 1f
and hence the scaling emulation dropped.
    
&apos;DPIUtil.setUseCairoAutoScale((sx[0]*100) == scaleFactor || OS.isGNOME);&apos;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6576</commentid>
    <comment_count>6</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-01-15 09:27:36 +0100</bug_when>
    <thetext>(In reply to Sven Gothel from comment #5)
https://jogamp.org/deployment/v2.4.0-rc-20200115/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6582</commentid>
    <comment_count>7</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-01-15 12:36:29 +0100</bug_when>
    <thetext>Marcel, please test this issue here at well as I have no system setup to do so.
Thank you.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6584</commentid>
    <comment_count>8</comment_count>
    <who name="Marcel Au">marcel.au</who>
    <bug_when>2020-01-15 13:35:20 +0100</bug_when>
    <thetext>Hello Sven,

tested on Windows. At first startup the view occupies 1/4.

When I click on the view the canvas get&apos;s resized to highdpi which is then correct.

When I change to fullscreen I see the same wrong fullscreen layout as on MacOSX (top-left coordinate of view).

After a fullscreen I also need to resize the view so that correct canvas size is applied.

When I close and reopen the perspective once again I need to resize the view.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6589</commentid>
    <comment_count>9</comment_count>
    <who name="Marcel Au">marcel.au</who>
    <bug_when>2020-01-15 15:43:56 +0100</bug_when>
    <thetext>Hello Sven,

tested on Linux Ubuntu 19.10 (VirtualBox, Display set to scale factor 2). 

The scaling has no effect like on Windows only 1/4 is covered.

View resizing and clicking on the canvas has no effect (which is different from Windows).

Fullscreen is working with the correct coordinates.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6590</commentid>
    <comment_count>10</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-01-16 01:56:27 +0100</bug_when>
    <thetext>(In reply to Marcel Au from comment #9)

commit 78609202731252f0024e6330cc94c52b05c1d146

    Bug 1422: Use own deviceZoomScaleUp(..) disregarding higher-toolkit&apos;s compensation like &apos;DPIUtil.useCairoAutoScale()&apos;
    
    We can&apos;t use DPIUtil&apos;s &apos;autoScaleUp(..)&apos; method on non-native DPI scaling platforms
    as it uses a scale-factor of 1f if the higher toolkit compensates, i.e. &apos;DPIUtil.useCairoAutoScale()&apos;.
    
    Since NEWT uses X11 and GDI directly, which are not DPI scale-aware,
    we have to drop the semnatics of &apos;DPIUtil.useCairoAutoScale()&apos;
    and merely use the actual &apos;deviceZoom&apos;.
    
    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 &apos;deviceZoomScaleUp(..)&apos;
    values for returning its size in window- and pixel-units (surface).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6591</commentid>
    <comment_count>11</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-01-16 01:56:58 +0100</bug_when>
    <thetext>(In reply to Sven Gothel from comment #10)

Our TestGLCanvasSWTNewtCanvasSWTPosInTabs unit test uses
a window shell size of 640x480 and the NewtCanvasSWT a window-unit size of around 628x424.

Testing:
- move window
- resize window
- for each GLWindow (gears + red-square):
-- fullscreen-on (focus in GLWindow and press &apos;f&apos;)
-- fullscreen-off (focus in GLWindow and press &apos;f&apos;)

+++

Debian 10 w/ KDE High-DPI &apos;natural&apos; - No Scale (100%)

SWT: Platform: gtk, Version 4930
SWT: isX11 true, isX11GTK true (GTK Version: 3.24.5)
SWT: isOSX false, isWindows false
SWT: DeviceZoom: 100, deviceZoomScalingFactor 1.0
SWT: Display.DPI Point {158, 158}; DPIUtil: autoScalingFactor 1.0 (use-swt true), useCairoAutoScale true

After creation we have a scaled up NEWT Window:
NewtCanvasSWT(0x13e39c73).Event.FOCUS_IN, Event {type=15 NewtCanvasSWT {} time=-925993934 data=null x=0 y=0 width=0 height=0 detail=0}
NewtCanvasSWT(0x13e39c73).Event.FOCUS_IN, WindowDriver[State [visible, child, repositionable, resizable]; Window[0/0 628x413 wu, 628x413 pixel] handle 0xcc0002a, surfaceHandle 0xcc0002a, children 0; ParentWindow com.jogamp.newt.swt.NewtCanvasSWT$SWTNativeWindow@1bd4fdd (handle 0xca00014)]

++++

Virtual Machine (VMM) qemu-kvm ..

Ubuntu 19.10 with Gnome WM and Gnome Settings: Display.Scale 200%

SWT: Platform: gtk, Version 4930
SWT: isX11 true, isX11GTK true (GTK Version: 3.24.12)
SWT: isOSX false, isWindows false
SWT: DeviceZoom: 200, deviceZoomScalingFactor 2.0
SWT: Display.DPI Point {96, 96}; DPIUtil: autoScalingFactor 1.0 (use-swt true), useCairoAutoScale true

After creation we have a scaled up NEWT Window:
NewtCanvasSWT(0x13e39c73).Event.FOCUS_IN, Event {type=15 NewtCanvasSWT {} time=14604810 data=null x=0 y=0 width=0 height=0 detail=0}
NewtCanvasSWT(0x13e39c73).Event.FOCUS_IN, WindowDriver[State [visible, child, repositionable, resizable]; Window[0/0 1256x848 wu, 1256x848 pixel] handle 0x2a0002a, surfaceHandle 0x2a0002a, children 0; ParentWindow com.jogamp.newt.swt.NewtCanvasSWT$SWTNativeWindow@1bd4fdd (handle 0x2800014)]


+++

Virtual Machine (VMM) qemu-kvm ..

Ubuntu 19.10 with Gnome WM and Gnome Settings: Display.Scale 100%

SWT: Platform: gtk, Version 4930
SWT: isX11 true, isX11GTK true (GTK Version: 3.24.12)
SWT: isOSX false, isWindows false
SWT: DeviceZoom: 100, deviceZoomScalingFactor 1.0
SWT: Display.DPI Point {96, 96}; DPIUtil: autoScalingFactor 1.0 (use-swt true), useCairoAutoScale true

After creation we have a scaled up NEWT Window:
NewtCanvasSWT(0x13e39c73).Event.FOCUS_IN, Event {type=15 NewtCanvasSWT {} time=15140863 data=null x=0 y=0 width=0 height=0 detail=0}
NewtCanvasSWT(0x13e39c73).Event.FOCUS_IN, WindowDriver[State [visible, child, repositionable, resizable]; Window[0/0 628x424 wu, 628x424 pixel] handle 0x2a0002a, surfaceHandle 0x2a0002a, children 0; ParentWindow com.jogamp.newt.swt.NewtCanvasSWT$SWTNativeWindow@1bd4fdd (handle 0x2800014)]
Window.focusAction() START - main, focusAction: null - windowHandle 0x2a0002a

+++</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6592</commentid>
    <comment_count>12</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-01-16 01:59:48 +0100</bug_when>
    <thetext>(In reply to Marcel Au from comment #8)

Fullscreen confusion might be related to 
&quot;NewtCanvasSWT.SWTNativeWindow needs to return the &apos;deviceZoomScaleUp(..)&apos;
values for returning its size in window- and pixel-units (surface).&quot;

which is now committed, but only active for !OSX.

Hence it might/should work for Windows now.
(How to test w/ virtual machine on Window?)

Need to check on OSX...

Build aggregation maybe tomorrow morning,
just sneaked this in after my other regular work :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6596</commentid>
    <comment_count>13</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-01-16 07:39:19 +0100</bug_when>
    <thetext>(In reply to Sven Gothel from comment #10)
commit f63b94cccc71cf154a7a6d3359ceface3a683229

    Bug 1422: NewtCanvasSWT: Handle case of !OSX &amp;&amp; DPIUtil.getScalingFactor() &gt; 1
    
    NewtCanvasSWT.SWTNativeWindow&apos;s surfaceSize in pixel units
    shall only return scaled-up windowUnits using SWTAccessor.deviceZoomScaleUp(..) for !OSX
    and potentially auto scaled-up pixelUnits to passthrough (OSX).
    
    See detailed API doc to NewtCanvasSWT.newtScaleUp(..)

+++

What a good night sleep can do to you ;-)

+++

Marcel, now I need to learn how to test this on Windows.
Either using a virtual machine .. or on metal, but w/o a high dpi screen.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6600</commentid>
    <comment_count>14</comment_count>
    <who name="Marcel Au">marcel.au</who>
    <bug_when>2020-01-16 12:13:24 +0100</bug_when>
    <thetext>Hello Sven,

with built 1502 Linux works correctly (as well as fullscreen).

On Windows still at startup the wrong coordinates. It can be mended when
I remove the boolean newtChildReady here:

https://github.com/sgothel/jogl/blob/78609202731252f0024e6330cc94c52b05c1d146/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java#L225

When removing the boolean variable the NewtCanvas is scaled correctly at startup.

Only when exiting fullscreen the newtCanvas returns to a 1/4 size so have to to resize it to apply the scale correctly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6603</commentid>
    <comment_count>15</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-01-22 09:21:54 +0100</bug_when>
    <thetext>(In reply to Sven Gothel from comment #11)
Virtual Machine (VMM) qemu-kvm ..

Windows 7 and Display Settings: Custom 200% &apos;Size of Text&apos;
Mesa 19.3.2 https://github.com/pal1000/mesa-dist-win/releases
GL_VENDOR      VMware, Inc.
GL_RENDERER    llvmpipe (LLVM 9.0, 128 bits)
GL_VERSION     3.3 (Core Profile) Mesa 19.3.2


SWT: Platform: win32, Version 4930
SWT: isX11 false, isX11GTK false (GTK Version: 0.0.0)
SWT: isOSX false, isWindows true
SWT: DeviceZoom: 200, deviceZoomScalingFactor 2.0
SWT: Display.DPI Point {96, 96}; DPIUtil: autoScalingFactor 2.0 (use-swt true), useCairoAutoScale false

+++

i.e. working on Windows as well.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6610</commentid>
    <comment_count>16</comment_count>
    <who name="Marcel Au">marcel.au</who>
    <bug_when>2020-01-22 14:18:50 +0100</bug_when>
    <thetext>Hello Sven,

I rebuilt everything on Windows. Using again the latest built (1502).

Now it seems to work on HighDPI.

For fullscreen see comment for 1423:

https://jogamp.org/bugzilla/show_bug.cgi?id=1423</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6614</commentid>
    <comment_count>17</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-02-03 02:07:21 +0100</bug_when>
    <thetext>(In reply to Marcel Au from comment #16)
Last build &lt;https://jogamp.org/deployment/v2.4.0-rc-20200202/&gt;
contains the MacOS child window fullscreen fix.

Hence this bug maybe closed now, IMHO.
We have Bug 1423 and Bug 1424 still left though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6616</commentid>
    <comment_count>18</comment_count>
    <who name="Marcel Au">marcel.au</who>
    <bug_when>2020-02-04 08:17:30 +0100</bug_when>
    <thetext>Hello Sven,

thanks. Tested and works fine on MacOSX Retina.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6620</commentid>
    <comment_count>19</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-02-04 14:26:44 +0100</bug_when>
    <thetext>see comment 17</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6621</commentid>
    <comment_count>20</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-02-04 14:27:01 +0100</bug_when>
    <thetext>see comment 18</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>