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

Summary: [Patch] SDL_Metal_GetDrawableSize is inaccurate for high dpi displays if a Metal view has not already been created
Product: SDL Reporter: Caleb Cornett <spydog>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: flibitijibibo
Version: 2.0.15   
Hardware: x86   
OS: macOS 10.15   
Attachments: Patch for the described issue

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. ***