| Summary: | [Patch] Android screen resolution change (e.g. immersive mode) produces wrong window size | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Magnus Bjerke Vik <mbvett> |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | HG 2.0 | ||
| Hardware: | All | ||
| OS: | Android (All) | ||
| Attachments: | Patch to fix issue | ||
I originally tested this on Nexus 5 where I haven't encountered the issues since the patch. I just tested it on Nexus 4 where the patch apparently did not fix the issue. I'll look more into the issue and probably create a new patch at a later time. (In reply to Magnus Bjerke Vik from comment #1) > I originally tested this on Nexus 5 where I haven't encountered the issues > since the patch. I just tested it on Nexus 4 where the patch apparently did > not fix the issue. I'll look more into the issue and probably create a new > patch at a later time. We were using the wrong version. Sorry for the spam update. It is now confirmed to be working on Nexus 4 as well. Fixed, thanks! https://hg.libsdl.org/SDL/rev/f7d8e9d871c5 |
Created attachment 2276 [details] Patch to fix issue When the screen resolution of the Android Activity changes, the dimensions in SDL_WINDOWEVENT_RESIZED is not changed. A change in resolution can be caused by entering or exiting immersive mode. The case I encountered this was when entering immersive mode in Activity::onWindowFocusChanged. If (and this varies a lot) Activity::surfaceChanged, as a cause of immersive mode, is called after SDL_VideoInit, but before SDL_CreateWindow, the desktop_mode resolution will not be changed to the proper values. Then, when the window is created with SDL_CreateWindow, it will create a resize event with the old resolution. This is because SDL_GetWindowDisplayMode sets the mode (fullscreen_mode) equal to the desktop_mode of SDL_GetDisplayForWindow, where the old values still are. To resolve this issue, I made sure that the desktop_mode is updated each time Activity::surfaceChanged is called, by adding it to the Android_SetScreenResolution function. Then SDL_GetDisplayForWindow returns the correct values. There are two things I'm still a bit unsure if is OK or a problem. The first one is that I assume that display 0 is the correct display. The second is that Android_SetScreenResolution is called by the Java main thread, which is a different thread from where e.g. SDL_VideoInit is called. The comment above the function was invalid since it also can be called after, so I removed it.