Permalink
Browse files

Front: Don't stop emulation if surfaceDestroyed

If surfaceDestroyed:
- pause emulation (if not already paused)
- notify SDL that the surface has been destroyed by sending the pause signal
- unbind the previously-created EGL context and destroy the window surface

If surfaceChanged (Resume emulation):
- notify SDL that the surface is ready by sending the resume signal
- upon resume SDL will call createGLContext(Java) and re-create the EGL context (see Android_PumpEvents in SDL_androidevents.c)
- resume emulation when EGL context is ready

If surfaceChanged (Startup emulation):
- notify SDL that the surface is ready by sending the resume signal (useless)
- On SDL_SetVideoMode SDL will call createGLContext(Java) and create the EGL context
- emulation starts

If onDestroy stop emulation.

Autosave are now only performed upon exit.  The main reason for this is that savestates sometimes
failed to be executed when pausing emulation and is subsequently only performed when resuming.

SDL_ANDROID_BLOCK_ON_PAUSE must be undefined to allow the core to call SDL_PumpEvents cyclically
  • Loading branch information...
Gillou68310 committed Oct 16, 2015
1 parent 0281802 commit 756a840b0f6c08ad7f08a0554d98300080018359
@@ -23,7 +23,7 @@
#if SDL_VIDEO_DRIVER_ANDROID
/* We're going to do this by default */
-#define SDL_ANDROID_BLOCK_ON_PAUSE 1
+//#define SDL_ANDROID_BLOCK_ON_PAUSE 1
#include "SDL_androidevents.h"
#include "SDL_events.h"
@@ -56,6 +56,8 @@ typedef void (*pSdlSetScreen) (int width, int height, Uint32 format);
typedef void (*pVoidFunc) ();
typedef m64p_error (*pCoreDoCommand) (m64p_command, int, void *);
typedef int (*pFrontMain) (int argc, char* argv[]);
+typedef void (*pNativeResume) (JNIEnv* env, jclass cls);
+typedef void (*pNativePause) (JNIEnv* env, jclass cls);
// Function pointers
static pAeiInit aeiInit = NULL;
@@ -64,6 +66,8 @@ static pSdlSetScreen sdlSetScreen = NULL;
static pVoidFunc sdlMainReady = NULL;
static pCoreDoCommand coreDoCommand = NULL;
static pFrontMain frontMain = NULL;
+static pNativeResume nativeResume = NULL;
+static pNativePause nativePause = NULL;
void checkLibraryError(const char* message)
{
@@ -162,9 +166,11 @@ extern "C" DECLSPEC void SDLCALL Java_paulscode_android_mupen64plusae_jni_Native
sdlMainReady = (pVoidFunc) locateFunction(handleSDL, "SDL2", "SDL_SetMainReady");
coreDoCommand = (pCoreDoCommand) locateFunction(handleCore, "mupen64plus-core", "CoreDoCommand");
frontMain = (pFrontMain) locateFunction(handleFront, "mupen64plus-ui-console", "SDL_main");
+ nativeResume = (pNativeResume) locateFunction(handleSDL, "SDL2", "Java_org_libsdl_app_SDLActivity_nativeResume");
+ nativePause = (pNativePause) locateFunction(handleSDL, "SDL2", "Java_org_libsdl_app_SDLActivity_nativePause");
// Make sure we don't have any typos
- if (!aeiInit || !sdlInit || !sdlSetScreen || !sdlMainReady || !coreDoCommand || !frontMain)
+ if (!aeiInit || !sdlInit || !sdlSetScreen || !sdlMainReady || !coreDoCommand || !frontMain || !nativeResume || !nativePause)
{
LOGE("Could not load library functions: be sure they are named and typedef'd correctly");
}
@@ -190,6 +196,8 @@ extern "C" DECLSPEC void SDLCALL Java_paulscode_android_mupen64plusae_jni_Native
sdlMainReady = NULL;
coreDoCommand = NULL;
frontMain = NULL;
+ nativeResume = NULL;
+ nativePause = NULL;
// Close shared libraries
unloadLibrary(handleFront, "mupen64plus-ui-console");
@@ -345,3 +353,14 @@ extern "C" DECLSPEC jint Java_paulscode_android_mupen64plusae_jni_NativeExports_
if (coreDoCommand) coreDoCommand(M64CMD_CORE_STATE_QUERY, M64CORE_SAVESTATE_SLOT, &slot);
return (jint) slot;
}
+
+extern "C" DECLSPEC void Java_paulscode_android_mupen64plusae_jni_NativeExports_notifySDLSurfaceDestroyed(JNIEnv* env, jclass cls)
+{
+ if (nativePause) nativePause(env, cls);
+}
+
+extern "C" DECLSPEC void Java_paulscode_android_mupen64plusae_jni_NativeExports_notifySDLSurfaceReady(JNIEnv* env, jclass cls)
+{
+ if (nativeResume) nativeResume(env, cls);
+}
+
@@ -583,6 +583,7 @@ public void surfaceCreated( SurfaceHolder holder )
public void surfaceChanged( SurfaceHolder holder, int format, int width, int height )
{
Log.i( "GameLifecycleHandler", "surfaceChanged" );
+ NativeExports.notifySDLSurfaceReady();
mIsSurface = true;
tryRunning();
}
@@ -610,8 +611,10 @@ public void onPause()
public void surfaceDestroyed( SurfaceHolder holder )
{
Log.i( "GameLifecycleHandler", "surfaceDestroyed" );
+ NativeExports.notifySDLSurfaceDestroyed();
mIsSurface = false;
- tryStopping();
+ tryPausing();
+ mSurface.destroyGLSurface();
}
public void onStop()
@@ -622,6 +625,13 @@ public void onStop()
public void onDestroy()
{
Log.i( "GameLifecycleHandler", "onDestroy" );
+
+ // Never go directly from running to stopped; always pause (and autosave) first
+ String saveFileName = mAutoSaveManager.getAutoSaveFileName();
+ CoreInterface.pauseEmulator( true, saveFileName );
+ mAutoSaveManager.clearOldest();
+ CoreInterface.shutdownEmulator();
+
mMogaController.exit();
}
@@ -816,14 +826,15 @@ private void tryRunning()
int state = NativeExports.emuGetState();
if( isSafeToRender() && ( state != NativeConstants.EMULATOR_STATE_RUNNING ))
{
- String latestSave = mAutoSaveManager.getLatestAutoSave();
switch( state )
{
case NativeConstants.EMULATOR_STATE_UNKNOWN:
+ String latestSave = mAutoSaveManager.getLatestAutoSave();
CoreInterface.startupEmulator(latestSave);
break;
case NativeConstants.EMULATOR_STATE_PAUSED:
- CoreInterface.resumeEmulator();
+ if( mSurface.isEGLContextReady() )
+ CoreInterface.resumeEmulator();
break;
default:
break;
@@ -834,22 +845,6 @@ private void tryRunning()
private void tryPausing()
{
if( NativeExports.emuGetState() != NativeConstants.EMULATOR_STATE_PAUSED )
- {
- String saveFileName = mAutoSaveManager.getAutoSaveFileName();
-
- CoreInterface.pauseEmulator( true, saveFileName );
-
- mAutoSaveManager.clearOldest();
- }
- }
-
- private void tryStopping()
- {
- if( NativeExports.emuGetState() != NativeConstants.EMULATOR_STATE_STOPPED )
- {
- // Never go directly from running to stopped; always pause (and autosave) first
- tryPausing();
- CoreInterface.shutdownEmulator();
- }
+ CoreInterface.pauseEmulator( false, null );
}
}
Oops, something went wrong.

0 comments on commit 756a840

Please sign in to comment.