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 5431 - [Patch] SDL_Metal_GetDrawableSize is inaccurate for high dpi displays if a Metal view has not already been created
Summary: [Patch] SDL_Metal_GetDrawableSize is inaccurate for high dpi displays if a Me...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.15
Hardware: x86 macOS 10.15
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-01 15:36 UTC by Caleb Cornett
Modified: 2021-01-11 22:31 UTC (History)
1 user (show)

See Also:


Attachments
Patch for the described issue (1.47 KB, patch)
2021-01-01 15:36 UTC, Caleb Cornett
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Caleb Cornett 2021-01-01 15:36:03 UTC
Created attachment 4623 [details]
Patch for the described issue

For a window created with SDL_WINDOW_ALLOW_HIGHDPI, SDL_GL_GetDrawableSize will return the high-dpi drawable size even before any GL context creation happens. But SDL_Metal_GetDrawableSize will return the size of the window if the Metal view has not been created. This is confusing and inconsistent behavior.

An easy way to test this is to build testgl2 and testvulkan on macOS with the SDL_WINDOW_ALLOW_HIGHDPI flag enabled during window creation. The GL2 program will report a drawable size of 2x window width and 2x window height, while the Vulkan program will report the window size.

This patch addresses the issue by falling back to using the content view dimensions if no Metal view exists in the window. (The code for this was taken directly from Cocoa_GL_GetDrawableSize.) With this change, the testvulkan behavior matches that of testgl2.

Note that I haven't tested for this issue on UIKit. It's possible a similar change will need to be made there too.
Comment 1 Sam Lantinga 2021-01-02 18:11:36 UTC
Patch added, thanks!
https://hg.libsdl.org/SDL/rev/f5dd3691b36c
Comment 2 Alex Szpakowski 2021-01-11 22:31:03 UTC
*** Bug 5459 has been marked as a duplicate of this bug. ***