diff -r 7c37af802e63 android-project/src/org/libsdl/app/SDLActivity.java --- a/android-project/src/org/libsdl/app/SDLActivity.java dom jun 03 17:34:18 2012 -0300 +++ b/android-project/src/org/libsdl/app/SDLActivity.java lun jun 18 22:08:08 2012 -0300 @@ -68,17 +68,17 @@ } // Events - protected void onPause() { + /*protected void onPause() { Log.v("SDL", "onPause()"); super.onPause(); - SDLActivity.nativePause(); + // Don't call SDLActivity.nativePause(); here, it will be called by SDLSurface::surfaceDestroyed } protected void onResume() { Log.v("SDL", "onResume()"); super.onResume(); - SDLActivity.nativeResume(); - } + // Don't call SDLActivity.nativeResume(); here, it will be called via SDLSurface::surfaceChanged->SDLActivity::startApp + }*/ protected void onDestroy() { super.onDestroy(); @@ -249,12 +249,14 @@ return false; } - if (!egl.eglMakeCurrent(SDLActivity.mEGLDisplay, surface, surface, SDLActivity.mEGLContext)) { - Log.e("SDL", "Old EGL Context doesnt work, trying with a new one"); - createEGLContext(); + if (egl.eglGetCurrentContext() != SDLActivity.mEGLContext) { if (!egl.eglMakeCurrent(SDLActivity.mEGLDisplay, surface, surface, SDLActivity.mEGLContext)) { - Log.e("SDL", "Failed making EGL Context current"); - return false; + Log.e("SDL", "Old EGL Context doesnt work, trying with a new one"); + createEGLContext(); + if (!egl.eglMakeCurrent(SDLActivity.mEGLDisplay, surface, surface, SDLActivity.mEGLContext)) { + Log.e("SDL", "Failed making EGL Context current"); + return false; + } } } SDLActivity.mEGLSurface = surface; @@ -426,7 +428,6 @@ public void surfaceCreated(SurfaceHolder holder) { Log.v("SDL", "surfaceCreated()"); holder.setType(SurfaceHolder.SURFACE_TYPE_GPU); - SDLActivity.createEGLSurface(); enableSensor(Sensor.TYPE_ACCELEROMETER, true); } diff -r 7c37af802e63 src/core/android/SDL_android.cpp --- a/src/core/android/SDL_android.cpp dom jun 03 17:34:18 2012 -0300 +++ b/src/core/android/SDL_android.cpp lun jun 18 22:08:08 2012 -0300 @@ -176,6 +176,7 @@ JNIEnv* env, jclass cls) { if (Android_Window) { + if (!SDL_SemValue(Android_PauseSem)) SDL_SemPost(Android_PauseSem); SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); } @@ -186,6 +187,7 @@ JNIEnv* env, jclass cls) { if (Android_Window) { + if (!SDL_SemValue(Android_ResumeSem)) SDL_SemPost(Android_ResumeSem); SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESTORED, 0, 0); } diff -r 7c37af802e63 src/video/android/SDL_androidevents.c --- a/src/video/android/SDL_androidevents.c dom jun 03 17:34:18 2012 -0300 +++ b/src/video/android/SDL_androidevents.c lun jun 18 22:08:08 2012 -0300 @@ -27,7 +27,26 @@ void Android_PumpEvents(_THIS) { + static int isPaused = 0; /* No polling necessary */ + + if (isPaused) { +#if SDL_ANDROID_BLOCK_ON_PAUSE + if(SDL_SemWait(Android_ResumeSem) == 0) { +#else + if(SDL_SemTryWait(Android_ResumeSem) == 0) { +#endif + isPaused = 0; + /* TODO: Should we double check if we are on the same thread as the one that made the original GL context?*/ + SDL_GL_CreateContext(Android_Window); + } + } + else { + if(SDL_SemTryWait(Android_PauseSem) == 0) { + /* If we fall in here, the system is/was paused */ + isPaused = 1; + } + } } #endif /* SDL_VIDEO_DRIVER_ANDROID */ diff -r 7c37af802e63 src/video/android/SDL_androidvideo.c --- a/src/video/android/SDL_androidvideo.c dom jun 03 17:34:18 2012 -0300 +++ b/src/video/android/SDL_androidvideo.c lun jun 18 22:08:08 2012 -0300 @@ -64,6 +64,7 @@ int Android_ScreenWidth = 0; int Android_ScreenHeight = 0; Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN; +SDL_sem *Android_PauseSem = NULL, *Android_ResumeSem = NULL; /* Currently only one window */ SDL_Window *Android_Window = NULL; diff -r 7c37af802e63 src/video/android/SDL_androidvideo.h --- a/src/video/android/SDL_androidvideo.h dom jun 03 17:34:18 2012 -0300 +++ b/src/video/android/SDL_androidvideo.h lun jun 18 22:08:08 2012 -0300 @@ -23,6 +23,7 @@ #ifndef _SDL_androidvideo_h #define _SDL_androidvideo_h +#include "SDL_mutex.h" #include "../SDL_sysvideo.h" /* Called by the JNI layer when the screen changes size or format */ @@ -33,8 +34,10 @@ extern int Android_ScreenWidth; extern int Android_ScreenHeight; extern Uint32 Android_ScreenFormat; +extern SDL_sem *Android_PauseSem, *Android_ResumeSem; extern SDL_Window *Android_Window; + #endif /* _SDL_androidvideo_h */ /* vi: set ts=4 sw=4 expandtab: */ diff -r 7c37af802e63 src/video/android/SDL_androidwindow.c --- a/src/video/android/SDL_androidwindow.c dom jun 03 17:34:18 2012 -0300 +++ b/src/video/android/SDL_androidwindow.c lun jun 18 22:08:08 2012 -0300 @@ -35,6 +35,8 @@ return -1; } Android_Window = window; + Android_PauseSem = SDL_CreateSemaphore(0); + Android_ResumeSem = SDL_CreateSemaphore(0); /* Adjust the window data to match the screen */ window->x = 0; @@ -62,6 +64,10 @@ { if (window == Android_Window) { Android_Window = NULL; + if (Android_PauseSem) SDL_DestroySemaphore(Android_PauseSem); + if (Android_ResumeSem) SDL_DestroySemaphore(Android_ResumeSem); + Android_PauseSem = NULL; + Android_ResumeSem = NULL; } }