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 2808

Summary: [patch proposal] Fix SDL reporting wrong window size on resume
Product: SDL Reporter: Jonas Kulla <ancurio_bugzilla>
Component: videoAssignee: Gabriel Jacobo <gabomdq>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: minor    
Priority: P2 CC: amaranth72, bugzilla.libsdl, icculus
Version: HG 2.1   
Hardware: All   
OS: Android (All)   
Attachments: proposed patch
alternative workaround

Description Jonas Kulla 2014-12-07 01:47:26 UTC
Created attachment 1960 [details]
proposed patch

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

My first attempt at fixing this involved updating Android_Window->windowed inside 'Android_SetScreenResolution()', but that would mean writing fields from the Java thread that could potentially be read from by the native thread at the same time. A very low chance, but nevertheless.

Instead, I just completely disabled 'SDL_UpdateFullscreenMode()' for Android as tbh. this function makes absolutely no sense in the context of mobile screens. An even cleaner solution would be to introduce a third FULLSCREEN_* flag that indicates "don't mess with the current size in any way".
Comment 1 Ryan C. Gordon 2015-02-19 04:21:27 UTC
Tossing this bug to Gabriel for review.

--ryan.
Comment 2 Ryan C. Gordon 2015-02-19 05:22:21 UTC
Marking a large number of bugs with the "triage-2.0.4" keyword at once. Sorry if you got a lot of email from this. This is to help me sort through some bugs in regards to a 2.0.4 release. We may or may not fix this bug for 2.0.4, though!
Comment 3 matt 2015-09-13 15:49:09 UTC
Created attachment 2264 [details]
alternative workaround

I ran into this recently, worked around it by always forcing the current mode to match the resized screen resolution (patch attached).
Comment 4 Alex Szpakowski 2015-09-14 03:30:16 UTC
SDL's iOS backend code does something similar to that patch: https://hg.libsdl.org/SDL/file/c3c3cdaf37f9/src/video/uikit/SDL_uikitappdelegate.m#l385
Comment 5 Sam Lantinga 2016-10-07 22:21:39 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/82f21f6121db