From 7d04504ee5399f7b208f043500ef02a85f27078b Mon Sep 17 00:00:00 2001 From: pelya Date: Thu, 20 Sep 2012 17:40:41 +0300 Subject: [PATCH] Asynchronous SDL_ACTIVEEVENT, when you lose focus. --- project/java/Video.java | 3 ++ .../jni/sdl-1.3/src/video/SDL_pixels.c.diff | 12 -------- .../jni/sdl-1.3/src/video/SDL_video.c.diff | 13 -------- .../src/video/android/SDL_androidinput.c | 30 +++++++++++++++++++ .../src/video/android/SDL_androidinput.h | 1 + .../src/video/android/SDL_androidvideo.c | 15 +++++----- 6 files changed, 42 insertions(+), 32 deletions(-) delete mode 100644 project/jni/sdl-1.3/src/video/SDL_pixels.c.diff delete mode 100644 project/jni/sdl-1.3/src/video/SDL_video.c.diff diff --git a/project/java/Video.java b/project/java/Video.java index fba98506d..2dd54234c 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -654,6 +654,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer private native void nativeDone(); private native void nativeGlContextLost(); public native void nativeGlContextRecreated(); + public native void nativeGlContextLostAsyncEvent(); public static native void nativeTextInput( int ascii, int unicode ); public static native void nativeTextInputFinished(); @@ -733,6 +734,7 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL { if(mRenderer.mPaused) return; mRenderer.mPaused = true; + mRenderer.nativeGlContextLostAsyncEvent(); if( mRenderer.accelerometer != null ) // For some reason it crashes here often - are we getting this event before initialization? mRenderer.accelerometer.stop(); super.onPause(); @@ -783,6 +785,7 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL { public static native void nativeHardwareMouseDetected( int detected ); public static native void nativeMouseButtonsPressed( int buttonId, int pressedState ); public static native void nativeMouseWheel(int scrollX, int scrollY); + } diff --git a/project/jni/sdl-1.3/src/video/SDL_pixels.c.diff b/project/jni/sdl-1.3/src/video/SDL_pixels.c.diff deleted file mode 100644 index 37045e055..000000000 --- a/project/jni/sdl-1.3/src/video/SDL_pixels.c.diff +++ /dev/null @@ -1,12 +0,0 @@ ---- SDL_pixels.c 2012-05-23 16:29:23.211504618 +0300 -+++ /home/pelya/src/endless_space/SDL-android/project/jni/sdl-1.3/src/video/SDL_pixels.c 2012-02-03 16:56:28.000000000 +0200 -@@ -754,6 +754,9 @@ - default: - break; - } -+#ifdef __ANDROID__ -+ if( surface->format->BytesPerPixel != 2 ) /* Avoid extra memcpy() when calling SDL_UpdateTexture() */ -+#endif - pitch = (pitch + 3) & ~3; /* 4-byte aligning */ - return (pitch); - } diff --git a/project/jni/sdl-1.3/src/video/SDL_video.c.diff b/project/jni/sdl-1.3/src/video/SDL_video.c.diff deleted file mode 100644 index c58c76cdd..000000000 --- a/project/jni/sdl-1.3/src/video/SDL_video.c.diff +++ /dev/null @@ -1,13 +0,0 @@ ---- SDL_video.c 2012-05-23 16:29:23.227504622 +0300 -+++ /home/pelya/src/endless_space/SDL-android/project/jni/sdl-1.3/src/video/SDL_video.c 2012-02-03 16:56:28.000000000 +0200 -@@ -297,6 +292,10 @@ - /* Create framebuffer data */ - data->bytes_per_pixel = SDL_BYTESPERPIXEL(*format); - data->pitch = (((window->w * data->bytes_per_pixel) + 3) & ~3); -+#ifdef __ANDROID__ -+ if( data->bytes_per_pixel == 2 ) /* Avoid extra memcpy() when calling SDL_UpdateTexture() */ -+ data->pitch = window->w * data->bytes_per_pixel; -+#endif - data->pixels = SDL_malloc(window->h * data->pitch); - if (!data->pixels) { - SDL_OutOfMemory(); diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c b/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c index a471bc241..1e14db32d 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c @@ -1507,6 +1507,14 @@ extern void SDL_ANDROID_PumpEvents() if( ev.jball.which < MAX_MULTITOUCH_POINTERS+1 && SDL_ANDROID_CurrentJoysticks[ev.jbutton.which] ) SDL_PrivateJoystickBall( SDL_ANDROID_CurrentJoysticks[ev.jball.which], ev.jball.ball, ev.jball.xrel, ev.jball.yrel ); break; +#if SDL_VERSION_ATLEAST(1,3,0) + //if( ANDROID_CurrentWindow ) + // SDL_SendWindowEvent(ANDROID_CurrentWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0); +#else + case SDL_ACTIVEEVENT: + SDL_PrivateAppActive(ev.active.gain, ev.active.state); + break; +#endif #if SDL_VERSION_ATLEAST(1,3,0) case SDL_FINGERMOTION: SDL_SendTouchMotion(0, ev.tfinger.fingerId, 0, (float)ev.tfinger.x / (float)window->w, (float)ev.tfinger.y / (float)window->h, ev.tfinger.pressure); @@ -1824,6 +1832,28 @@ extern void SDL_ANDROID_MainThreadPushMouseWheel(int x, int y) #endif } +extern void SDL_ANDROID_MainThreadPushAppActive(int active) +{ +#if SDL_VERSION_ATLEAST(1,3,0) + //if( ANDROID_CurrentWindow ) + // SDL_SendWindowEvent(ANDROID_CurrentWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0); +#else + int nextEvent = getNextEventAndLock(); + if( nextEvent == -1 ) + return; + + SDL_Event * ev = &BufferedEvents[BufferedEventsEnd]; + + ev->type = SDL_ACTIVEEVENT; + ev->active.gain = active; + ev->active.state = SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS; + + BufferedEventsEnd = nextEvent; + SDL_mutexV(BufferedEventsMutex); +#endif +} + + enum { DEFERRED_TEXT_COUNT = 256 }; static struct { int scancode; int unicode; int down; } deferredText[DEFERRED_TEXT_COUNT]; static int deferredTextIdx1 = 0; diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidinput.h b/project/jni/sdl-1.3/src/video/android/SDL_androidinput.h index 6a92df5f2..b7e813d81 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidinput.h +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidinput.h @@ -202,4 +202,5 @@ extern void SDL_ANDROID_MainThreadPushJoystickBall(int joy, int ball, int x, int extern void SDL_ANDROID_MainThreadPushText( int ascii, int unicode ); extern void SDL_android_init_keymap(SDLKey *SDL_android_keymap); extern void SDL_ANDROID_MainThreadPushMouseWheel( int x, int y ); // SDL 1.3 only +extern void SDL_ANDROID_MainThreadPushAppActive(int active); #endif diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c index eab52d9f8..1416e064b 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.c @@ -209,16 +209,17 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeGlContextLost) ( JNIEnv* env, jobject thiz if(openALPutToBackgroundCallback) openALPutToBackgroundCallback(); -#if SDL_VERSION_ATLEAST(1,3,0) - //if( ANDROID_CurrentWindow ) - // SDL_SendWindowEvent(ANDROID_CurrentWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0); -#else - SDL_PrivateAppActive(0, SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS); -#endif - SDL_ANDROID_VideoContextLost(); } +JNIEXPORT void JNICALL +JAVA_EXPORT_NAME(DemoRenderer_nativeGlContextLostAsyncEvent) ( JNIEnv* env, jobject thiz ) +{ + __android_log_print(ANDROID_LOG_INFO, "libSDL", "OpenGL context lost - sending SDL_ACTIVEEVENT"); + SDL_ANDROID_MainThreadPushAppActive(0); +} + + JNIEXPORT void JNICALL JAVA_EXPORT_NAME(DemoRenderer_nativeGlContextRecreated) ( JNIEnv* env, jobject thiz ) {