https://bugzilla.libsdl.org/show_bug.cgi?id=4577
authorSam Lantinga <slouken@libsdl.org>
Fri, 05 Apr 2019 07:51:11 -0700
changeset 12694c9410703cbdd
parent 12693 d311fcb8066a
child 12695 0c4d04572622
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
     1.1 --- a/src/video/uikit/SDL_uikitmodes.m	Fri Apr 05 09:16:30 2019 +0200
     1.2 +++ b/src/video/uikit/SDL_uikitmodes.m	Fri Apr 05 07:51:11 2019 -0700
     1.3 @@ -216,17 +216,18 @@
     1.4          availableModes = data.uiscreen.availableModes;
     1.5  #endif
     1.6  
     1.7 -#ifdef __IPHONE_8_0
     1.8 -        /* The UIScreenMode of an iPhone 6 Plus should be 1080x1920 rather than
     1.9 -         * 1242x2208 (414x736@3x), so we should use the native scale. */
    1.10 -        if ([data.uiscreen respondsToSelector:@selector(nativeScale)]) {
    1.11 -            scale = data.uiscreen.nativeScale;
    1.12 -        }
    1.13 -#endif
    1.14 -
    1.15          for (UIScreenMode *uimode in availableModes) {
    1.16              /* The size of a UIScreenMode is in pixels, but we deal exclusively
    1.17 -             * in points (except in SDL_GL_GetDrawableSize.) */
    1.18 +             * in points (except in SDL_GL_GetDrawableSize.)
    1.19 +             *
    1.20 +             * For devices such as iPhone 6/7/8 Plus, the UIScreenMode reported
    1.21 +             * by iOS is not in physical pixels of the display, but rather the
    1.22 +             * point size times the scale.  For example, on iOS 12.2 on iPhone 8
    1.23 +             * Plus the uimode.size is 1242x2208 and the uiscreen.scale is 3
    1.24 +             * thus this will give the size in points which is 414x736. The code
    1.25 +             * used to use the nativeScale, assuming UIScreenMode returned raw
    1.26 +             * physical pixels (as suggested by its documentation, but in
    1.27 +             * practice it is returning the retina pixels). */
    1.28              int w = (int)(uimode.size.width / scale);
    1.29              int h = (int)(uimode.size.height / scale);
    1.30