| Summary: | [patch proposal] Fix SDL reporting wrong window size on resume | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Jonas Kulla <ancurio_bugzilla> |
| Component: | video | Assignee: | 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 |
||
Tossing this bug to Gabriel for review. --ryan. 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! 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).
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 Fixed, thanks! https://hg.libsdl.org/SDL/rev/82f21f6121db |
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".