Bug 545953 - Device#getDPI method can return incorrect values
Summary: Device#getDPI method can return incorrect values
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.9   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: 4.14 M1   Edit
Assignee: Eric Williams CLA
QA Contact:
URL:
Whiteboard: RHT
Keywords: triaged
: 542649 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-03-30 05:17 EDT by Peter Severin CLA
Modified: 2019-12-23 06:33 EST (History)
2 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 2019-03-30 05:17:48 EDT
Since the fix for Bug 535064 there is an issue with Device#getDPI method that can under some unclear conditions return an incorrect DPI. Since my comment in the original bug went unnoticed I'm creating a new bug to raise this issue.

Here's my comment in the original bug:

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.

"xrdb -query | grep dpi" gives the correct DPI as follows:
Xft.dpi:	96
Comment 1 Peter Severin CLA 2019-03-30 09:05:44 EDT
And I have a client with an even more extreme case. The output of "xrandr --query" on their machine gives:

Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
eDP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 344mm x 194mm

And "xrdb -query | grep dpi":

Xft.dpi:    96 


This means that the system has the dpi of 96, but the algorithm used by SWT calculates the DPI as round(254*1920/(344*10.0)) = 142, which is way off.

A need an urgent solution for this issue.
Comment 2 Eric Williams CLA 2019-03-30 11:32:20 EDT
Thanks for raising this issue, we'll investigate for 4.12.
Comment 3 Eric Williams CLA 2019-05-08 09:16:07 EDT
Unfortunately we have run out of time for 4.12, will investigate for 2019-09.
Comment 4 Eric Williams CLA 2019-08-23 15:46:06 EDT
*Sigh* sorry, I didn't manage to get to this one in time. It's on the list for first thing in 4.14.
Comment 5 Eric Williams CLA 2019-09-05 11:44:54 EDT
So it seems like algorithm for the screen DPI is inaccurate, which I can tweak. May I ask what you are using the returned DPI value for?
Comment 6 Peter Severin CLA 2019-09-09 09:01:52 EDT
Eric, in WireframeSketcher text sizes are specified in pixels, to ensure that the size doesn't change between devices with different DPIs. When creating SWT Font objects I need to calculate the size in points (FontData#setHeight). So I am using the DPI value of the screen to transform pixel sizes to points.
Comment 7 Eric Williams CLA 2019-09-09 09:27:17 EDT
(In reply to Peter Severin from comment #6)
> Eric, in WireframeSketcher text sizes are specified in pixels, to ensure
> that the size doesn't change between devices with different DPIs. When
> creating SWT Font objects I need to calculate the size in points
> (FontData#setHeight). So I am using the DPI value of the screen to transform
> pixel sizes to points.

Okay, I just wanted to check. I spoke to the upstream GTK devs about this subject and they pointed out many different ways to get DPI. It seems the SWT use case is the DPI for text/image scaling, which can sometimes be different than "generic screen DPI".

I'll propose a patch for 4.14.
Comment 8 Eclipse Genie CLA 2019-09-09 12:07:50 EDT
New Gerrit change created: https://git.eclipse.org/r/149192
Comment 10 Eric Williams CLA 2019-09-11 10:33:04 EDT
(In reply to Eclipse Genie from comment #9)
> Gerrit change https://git.eclipse.org/r/149192 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=f1cec2dde6ea77ca066ebe3a405f7ced98098903

In master now.
Comment 11 Eclipse Genie CLA 2019-09-11 13:28:17 EDT
New Gerrit change created: https://git.eclipse.org/r/149369
Comment 13 Eric Williams CLA 2019-09-26 15:02:03 EDT
*** Bug 542649 has been marked as a duplicate of this bug. ***
Comment 14 Eric Williams CLA 2019-10-08 13:34:46 EDT
Verified in I20191008-0600.