We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4856 - SDL_GetDisplayDPI returns incorrect result on MacOS with retina screens
Summary: SDL_GetDisplayDPI returns incorrect result on MacOS with retina screens
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.10
Hardware: x86_64 Mac OS X (All)
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.12
Depends on:
Blocks:
 
Reported: 2019-11-11 15:19 UTC by Rokas Kupstys
Modified: 2019-12-04 17:22 UTC (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 Rokas Kupstys 2019-11-11 15:19:50 UTC
On MacOS with retina screens we have double pixel density. Interesting detail is that OS reports window size in uniform units as if it was on 96 DPI display (unsure about terminology here). Simply put - whatever window size reported it will cover twice as many pixels in each dimension.

SDL_GetDisplayDPI() in this setup reports 54.5 DPI.

Correct DPI scale (which is 2.0f in this case) can be obtained form NSScreen::backingScaleFactor https://developer.apple.com/documentation/appkit/nsscreen/1388385-backingscalefactor

SDL should return 96.f * NSScreen::backingScaleFactor
Comment 1 Ryan C. Gordon 2019-12-04 17:22:59 UTC
Pushed a fix for this in https://hg.libsdl.org/SDL/rev/3b03741c0095 ...someone should check my math (should we scale before doing the diagonal DPI math, etc?), and see if there's a better way to get an NSScreen from a CGDirectDisplay, maybe, but it finds the correct scaling factor on my retina macbook.

Reopen the bug if there's still a problem, please!

--ryan.