Bug 535064 - [HiDPI][GTK3] Device#getDPI method returns an incorrect value on x2 scaled screen
Summary: [HiDPI][GTK3] Device#getDPI method returns an incorrect value on x2 scaled sc...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.8   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: 4.9 M2   Edit
Assignee: Sravan Kumar Lakkimsetti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 527444 534932
  Show dependency tree
 
Reported: 2018-05-24 06:37 EDT by Peter Severin CLA
Modified: 2019-04-04 04:19 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Severin CLA 2018-05-24 06:37:42 EDT
The issue was introduced in Bug 518717. See Comment 7 and following comments: https://bugs.eclipse.org/bugs/show_bug.cgi?id=518717#c7

Snippet to test the issue:

Display display = new Display();
System.out.println(display.getDPI());


The returned dpi is 192. Under the same conditions getDPI method returns 96 on Windows, and 74 on macOS. So the correct value should be 96.

This issue was introduced in 4.8 and only affects this version. I believe it's an important breakage of the API and should be fixed before the final release, or it least in the first point release. Not in 4.9.
Comment 1 Sravan Kumar Lakkimsetti CLA 2018-06-13 08:29:49 EDT
@Leo,

I am having trouble in adding optional GTK calls to GTK.java. I will create a patch tomorrow. Can you have a look?
Comment 2 Leo Ufimtsev CLA 2018-06-13 10:37:13 EDT
(In reply to Sravan Kumar Lakkimsetti from comment #1)
> @Leo,
> 
> I am having trouble in adding optional GTK calls to GTK.java. I will create
> a patch tomorrow. Can you have a look?

What do you mean by optional?

like dyanmic?
Comment 3 Eclipse Genie CLA 2018-06-14 09:19:06 EDT
New Gerrit change created: https://git.eclipse.org/r/124539
Comment 4 Sravan Kumar Lakkimsetti CLA 2018-06-14 09:19:58 EDT
(In reply to Leo Ufimtsev from comment #2)
> (In reply to Sravan Kumar Lakkimsetti from comment #1)
> > @Leo,
> > 
> > I am having trouble in adding optional GTK calls to GTK.java. I will create
> > a patch tomorrow. Can you have a look?
> 
> What do you mean by optional?
> 
> like dyanmic?

> New Gerrit change created: https://git.eclipse.org/r/124539

Can you have a look at the attached patch I am unable to build natives with this.(In reply to Eclipse Genie from comment #3)
Comment 5 Eclipse Genie CLA 2018-06-15 01:59:32 EDT
New Gerrit change created: https://git.eclipse.org/r/124573
Comment 7 Sravan Kumar Lakkimsetti CLA 2018-06-15 08:14:13 EDT
(In reply to Eclipse Genie from comment #6)
> Gerrit change https://git.eclipse.org/r/124573 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=dca6f677b85c2d83c4b6378dfcc811694796cc53

Merged to master
Comment 8 Andrey Loskutov CLA 2018-06-18 04:51:27 EDT
Sravan, can you please take a look at the fails in Platform UI Ferrit, see bug 535992? Could they be related to the changes on this bug?
Comment 9 Andrey Loskutov CLA 2018-06-18 05:02:56 EDT
(In reply to Andrey Loskutov from comment #8)
> Sravan, can you please take a look at the fails in Platform UI Ferrit, see
> bug 535992? Could they be related to the changes on this bug?

I've commented on the patch. The NaN in FontData could be from 

float size = height * screenDPI.y / dpi.y;

and this would mean we compute "0" for the screen dpi in org.eclipse.swt.graphics.Device.getScreenDPI().dpi.
Comment 10 Sravan Kumar Lakkimsetti CLA 2018-06-18 05:50:36 EDT
(In reply to Andrey Loskutov from comment #9)
> (In reply to Andrey Loskutov from comment #8)
> > Sravan, can you please take a look at the fails in Platform UI Ferrit, see
> > bug 535992? Could they be related to the changes on this bug?
> 
> I've commented on the patch. The NaN in FontData could be from 
> 
> float size = height * screenDPI.y / dpi.y;
> 
> and this would mean we compute "0" for the screen dpi in
> org.eclipse.swt.graphics.Device.getScreenDPI().dpi.

There is a case where we have this. I have a solution. I am testing it right now. If it is succesful I will push and trigger a I-build
Comment 11 Eclipse Genie CLA 2018-06-18 06:47:24 EDT
New Gerrit change created: https://git.eclipse.org/r/124666
Comment 14 Sravan Kumar Lakkimsetti CLA 2018-09-07 04:08:40 EDT
verified in 4.9M2
Comment 15 Peter Severin CLA 2018-12-07 06:08:49 EST
Hi Sravan,

I'm noticing a strange behavior of Device#getScreenDPI on my system (Ubuntu 18.04 with latest updates, and GTK version 3.22.30). The returned DPI value is {102, 102} instead of {96,96} as it should be. I've tried to debug the issue and here are the values used for DPI calculation:
widthMM=480,scaleFactor=1,monitorGeometry={0, 0, 1920, 1080}

This gives 254*1920/(480*10.0) = 101.6, value then rounded to 102.

I've tried to reproduce this issue with VirtualBox with a clean 18.04 install but couldn't. Although it's the same system, returned widthMM is different:

widthMM=503,scaleFactor=1,monitorGeometry={0, 0, 1920, 988}

Which gives 254*1920/(503*10.0) = 96.0, which is correct.

Is this a bug? Running $ xrandr --query gives
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
VGA-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 480mm x 270mm

So the 480mm value is there, but I am not sure what this means. The result is that Eclipse 4.9 and onward return and incorrect DPI value on my system.
Comment 16 Sravan Kumar Lakkimsetti CLA 2019-04-03 04:02:07 EDT
(In reply to Peter Severin from comment #15)
> Hi Sravan,
> 
> I'm noticing a strange behavior of Device#getScreenDPI on my system (Ubuntu
> 18.04 with latest updates, and GTK version 3.22.30). The returned DPI value
> is {102, 102} instead of {96,96} as it should be. I've tried to debug the
> issue and here are the values used for DPI calculation:
> widthMM=480,scaleFactor=1,monitorGeometry={0, 0, 1920, 1080}
> 
> This gives 254*1920/(480*10.0) = 101.6, value then rounded to 102.
> 
> I've tried to reproduce this issue with VirtualBox with a clean 18.04
> install but couldn't. Although it's the same system, returned widthMM is
> different:
> 
> widthMM=503,scaleFactor=1,monitorGeometry={0, 0, 1920, 988}
> 
> Which gives 254*1920/(503*10.0) = 96.0, which is correct.
> 
> Is this a bug? Running $ xrandr --query gives
> Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
> VGA-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y
> axis) 480mm x 270mm
> 
> So the 480mm value is there, but I am not sure what this means. The result
> is that Eclipse 4.9 and onward return and incorrect DPI value on my system.

We rely on GTK api to get the physical dimensions from the hardware. It would vary from screen to screen based on the physical dimensions. This is expected. 

During our hidpi implementation we quickly realized dpi calculation is not reliable. Many times the display driver doesn't have dimensions in mm in its properties then a dpi of 96 is assumed. So we rely on the scaling factor directly.
Comment 17 Peter Severin CLA 2019-04-03 04:33:30 EDT
My issue is not directly related to HiDPI and I have it in non-scaled environment too. It's just that the issue was introduced during the change in this bug. I've created a separate Bug 545953 for the issue I'm seeing.

In my use case I need the screen DPI to convert font sizes from pixels (as they are specified in WireframeSketcher) to points to get the correct text size on screen. Since font heights are specified in points I don't see how I can calculate font height without knowing the DPI.

The getDPI() method generally worked reliably before 4.9, and the issue with incorrect values only appears on GTK. All other plaforms return the DPI correctly. Are you saying that there is no fix for getDPI on GTK and I should use other means to discover screen DPI in my application?
Comment 18 Sravan Kumar Lakkimsetti CLA 2019-04-04 04:19:43 EDT
dpi by definition dots per inch. In GTK we get number of pixels width wise and length in mm. From this we calculate the dpi. 

If we look at newer monitors with full HD resolution
14 inch corresponds to 157
15 inch             to 148

With getDPI() method we are calculating this value and returning it. DPI will always depend on dimensions of the monitor.

For historical reasons windows and MAC decided to base their OS design on 96 and 72 pixels respectively. To convert this actual physical scale you'll need actual DPI. 

During the hidpi implementation we decided to go ahead with scaling factor as the DPI is very much unreliable and user controls the scaling factor using display settings.

On windows and MAC we get the dpi value using a OS call and return that value. But GTK doesnot have a call to directly get dpi. So we calculate it using the physical dimensions.

Only way forward I see (though not correct in my opinion) is to hardcode 72 and 96 for mac and windows/linux for display