Fixed bug 2808 - Fix SDL reporting wrong window size on resume
authorSam Lantinga <slouken@libsdl.org>
Fri, 07 Oct 2016 15:21:19 -0700
changeset 1047582f21f6121db
parent 10474 e723c663ba58
child 10476 612fbaee8e3c
Fixed bug 2808 - Fix SDL reporting wrong window size on resume

Jonas Kulla

At startup time, the single android window is assigned a "windowed" (window->windowed.{w,h}) size based on the current orientation of the mobile device; this size is never updated throughout the lifetime of the app.

This becomes problematic when the app is paused and then resumed in an orientation that it did not start up in. Eventually, 'SDL_OnWindowRestored()' is called, which calls 'SDL_UpdateFullscreenMode()'. This function is very problematic because it is written with a desktop monitor in mind: it tries to find a matching display mode for the windowed size, doesn't find any, and finally applies the windowed size as the fullscreen one. In the end, the windowed size is reported in a RESIZED event, which doesn't correspond to the actual surface size.

To see this in action: Start an orientation aware SDL app in eg. portrait mode, suspend the app, put the device into landscape orientation and resume the app. It will erroneously render in portrait mode (until the device is rotated again).
src/video/android/SDL_androidvideo.c
     1.1 --- a/src/video/android/SDL_androidvideo.c	Fri Oct 07 15:08:37 2016 -0700
     1.2 +++ b/src/video/android/SDL_androidvideo.c	Fri Oct 07 15:21:19 2016 -0700
     1.3 @@ -220,6 +220,15 @@
     1.4  
     1.5      if (Android_Window) {
     1.6          SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, width, height);
     1.7 +
     1.8 +        /* Force the current mode to match the resize otherwise the SDL_WINDOWEVENT_RESTORED event
     1.9 +         * will fall back to the old mode */
    1.10 +        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(Android_Window);
    1.11 +
    1.12 +        display->current_mode.format = format;
    1.13 +        display->current_mode.w = width;
    1.14 +        display->current_mode.h = height;
    1.15 +        display->current_mode.refresh_rate = rate;
    1.16      }
    1.17  }
    1.18