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 3131

Summary: [Patch] Android screen resolution change (e.g. immersive mode) produces wrong window size
Product: SDL Reporter: Magnus Bjerke Vik <mbvett>
Component: videoAssignee: 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

Description Magnus Bjerke Vik 2015-09-27 16:09:59 UTC
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.
Comment 1 Magnus Bjerke Vik 2015-09-28 12:11:36 UTC
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.
Comment 2 Magnus Bjerke Vik 2015-09-28 12:28:13 UTC
(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.
Comment 3 Sam Lantinga 2016-10-01 21:18:54 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/f7d8e9d871c5