-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Fix scaling factor for high-dpi displays #83631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix scaling factor for high-dpi displays #83631
Conversation
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
Apologies, it's my first time contributing. Feel free to change what this points against. The code in question hasn't changed in many years so it shouldn't matter |
|
Hi @rachel-bousfield, welcome to CleverRaven! We see that this is your first time commenting here. Check out how development works and be sure to follow the code of conduct! We hope to see you around! |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
Tested to confirm this works on Linux both with and without outdated (pre 2022) versions of SDL2 |
|
Hi @rachel-bousfield, welcome to CleverRaven! We see that this is your first time commenting here. Check out how development works and be sure to follow the code of conduct! We hope to see you around! |
Co-authored-by: ehughsbaird <[email protected]>
Summary
Bugfixes "Fix the scaling factor for high-dpi displays."
Purpose of change
The number of pixels returned by
SDL_GetWindowSizedo not take into account dpi scaling, like on Apple Retina displays. Thankfully SDL 2.26 (Nov 2022) provides aSDL_GetWindowSizeInPixelsfor accounting for exactly this.Additionally, even in full screen mode the dimensions of
SDL_DisplayModeare incorrect due toSDL_GetDesktopDisplayModesimilarly not factoring in dpi scale.Describe the solution
Switch to
SDL_GetWindowSizeInPixelsand implement a newget_display_scalefunction for measuring the dpi scaling ratios. The measurement creates a small, hidden window to quickly measure the horizontal and vertical stretch necessary to account for dpi. On failure the return values are 1x, ensuring no logical change.Describe alternatives you've considered
One could perhaps imagine a larger refactor where we always perform window measurements, but even in this case we'd want precisely the same affordance provided by
get_display_scale. This keeps things minimal and known to not break other platforms.Testing
I've tested this on my MacBook in each mode, though given it's backend agnostic it should work cross-platform. A friend has also on Windows and I'll soon be on Linux with an intentionally out-dated SDL version too.
EDIT: Confirmed it works on Linux with and without old versions of SDL (pre 2022)
Additional context
None