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

Summary: SDL_GetDisplayDPI returns incorrect result on MacOS with retina screens
Product: SDL Reporter: Rokas Kupstys <rokupstys>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: icculus, sezeroz
Version: 2.0.10Keywords: target-2.0.12
Hardware: x86_64   
OS: Mac OS X (All)   

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.