Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Change our fullscreen wait logic to only wait if we need to. (thanks …
…Rachel!)
  • Loading branch information
slouken committed Oct 22, 2018
1 parent e6068b5 commit d7fa112
Showing 1 changed file with 48 additions and 8 deletions.
56 changes: 48 additions & 8 deletions android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
Expand Up @@ -645,15 +645,54 @@ boolean sendCommand(int command, Object data) {
msg.obj = data;
boolean result = commandHandler.sendMessage(msg);

// Ensure we don't return until the resize has actually happened,
// or 250ms have passed.
if (command == COMMAND_CHANGE_WINDOW_STYLE) {
synchronized(SDLActivity.getContext()) {
try {
SDLActivity.getContext().wait(250);
if ((Build.VERSION.SDK_INT >= 19) && (command == COMMAND_CHANGE_WINDOW_STYLE)) {
// Ensure we don't return until the resize has actually happened,
// or 500ms have passed.

boolean bShouldWait = false;

if (data instanceof Integer) {
// Let's figure out if we're already laid out fullscreen or not.
Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
android.util.DisplayMetrics realMetrics = new android.util.DisplayMetrics();
display.getRealMetrics( realMetrics );

boolean bFullscreenLayout = ((realMetrics.widthPixels == mSurface.getWidth()) &&
(realMetrics.heightPixels == mSurface.getHeight()));

if (((Integer)data).intValue() == 1) {
// If we aren't laid out fullscreen or actively in fullscreen mode already, we're going
// to change size and should wait for surfaceChanged() before we return, so the size
// is right back in native code. If we're already laid out fullscreen, though, we're
// not going to change size even if we change decor modes, so we shouldn't wait for
// surfaceChanged() -- which may not even happen -- and should return immediately.
bShouldWait = !bFullscreenLayout;
}
else {
// If we're laid out fullscreen (even if the status bar and nav bar are present),
// or are actively in fullscreen, we're going to change size and should wait for
// surfaceChanged before we return, so the size is right back in native code.
bShouldWait = bFullscreenLayout;
}
catch (InterruptedException ie) {
ie.printStackTrace();
}

if (bShouldWait) {
// We'll wait for the surfaceChanged() method, which will notify us
// when called. That way, we know our current size is really the
// size we need, instead of grabbing a size that's still got
// the navigation and/or status bars before they're hidden.
//
// We'll wait for up to half a second, because some devices
// take a surprisingly long time for the surface resize, but
// then we'll just give up and return.
//
synchronized(SDLActivity.getContext()) {
try {
SDLActivity.getContext().wait(500);
}
catch (InterruptedException ie) {
ie.printStackTrace();
}
}
}
}
Expand Down Expand Up @@ -1595,6 +1634,7 @@ public void surfaceChanged(SurfaceHolder holder,
catch ( java.lang.Throwable throwable ) {}

synchronized(SDLActivity.getContext()) {
// In case we're waiting on a size change after going fullscreen, send a notification.
SDLActivity.getContext().notifyAll();
}

Expand Down

0 comments on commit d7fa112

Please sign in to comment.