From b6f33a6870a34fd4e9f142d1e1418330c8d51f9c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 5 Apr 2019 07:51:11 -0700 Subject: [PATCH] https://bugzilla.libsdl.org/show_bug.cgi?id=4577 SDL_GetWindowDisplayMode was returning an incorrect result on iPhone Plus devices (tested on iOS 12.1/12.2). The problem was that the value returned by UIScreenMode was assumed to be the physical pixels on the display, rather than the scaled retina pixels. The fix is to use the scale returned by UIScreen.scale rather than the nativeScale. --- src/video/uikit/SDL_uikitmodes.m | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/video/uikit/SDL_uikitmodes.m b/src/video/uikit/SDL_uikitmodes.m index 7a572a3d2ef4d..be34b0691fe30 100644 --- a/src/video/uikit/SDL_uikitmodes.m +++ b/src/video/uikit/SDL_uikitmodes.m @@ -216,17 +216,18 @@ @implementation SDL_DisplayModeData availableModes = data.uiscreen.availableModes; #endif -#ifdef __IPHONE_8_0 - /* The UIScreenMode of an iPhone 6 Plus should be 1080x1920 rather than - * 1242x2208 (414x736@3x), so we should use the native scale. */ - if ([data.uiscreen respondsToSelector:@selector(nativeScale)]) { - scale = data.uiscreen.nativeScale; - } -#endif - for (UIScreenMode *uimode in availableModes) { /* The size of a UIScreenMode is in pixels, but we deal exclusively - * in points (except in SDL_GL_GetDrawableSize.) */ + * in points (except in SDL_GL_GetDrawableSize.) + * + * For devices such as iPhone 6/7/8 Plus, the UIScreenMode reported + * by iOS is not in physical pixels of the display, but rather the + * point size times the scale. For example, on iOS 12.2 on iPhone 8 + * Plus the uimode.size is 1242x2208 and the uiscreen.scale is 3 + * thus this will give the size in points which is 414x736. The code + * used to use the nativeScale, assuming UIScreenMode returned raw + * physical pixels (as suggested by its documentation, but in + * practice it is returning the retina pixels). */ int w = (int)(uimode.size.width / scale); int h = (int)(uimode.size.height / scale);