Asynchronous SDL_ACTIVEEVENT, when you lose focus.

This commit is contained in:
pelya
2012-09-20 17:40:41 +03:00
parent 41fd185b16
commit 7d04504ee5
6 changed files with 42 additions and 32 deletions

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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();

View File

@@ -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;

View File

@@ -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

View File

@@ -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 )
{