diff --git a/ChangeAppSettings.sh b/ChangeAppSettings.sh index 20c03b04e..037bf215a 100755 --- a/ChangeAppSettings.sh +++ b/ChangeAppSettings.sh @@ -1,6 +1,6 @@ #!/bin/sh -CHANGE_APP_SETTINGS_VERSION=16 +CHANGE_APP_SETTINGS_VERSION=17 AUTO= if [ "X$1" = "X-a" ]; then @@ -103,6 +103,18 @@ if [ -n "$var" ] ; then fi fi +if [ "$LibSdlVersion" = "1.2" ]; then + if [ -z "$SwVideoMode" -o -z "$AUTO" ]; then + echo -n "\nApplication uses software video buffer - you're calling SDL_SetVideoMode() without SDL_HWSURFACE and without SDL_OPENGL,\nthis will allow small speed optimization (y) or (n) ($SwVideoMode): " + read var + if [ -n "$var" ] ; then + SwVideoMode="$var" + fi + fi +else + SwVideoMode=n +fi + if [ -z "$AppUsesMouse" -o -z "$AUTO" ]; then echo -n "\nApplication uses mouse (y) or (n) ($AppUsesMouse): " read var @@ -337,6 +349,7 @@ echo AppDataDownloadUrl=\"$AppDataDownloadUrl\" >> AndroidAppSettings.cfg echo SdlVideoResize=$SdlVideoResize >> AndroidAppSettings.cfg echo SdlVideoResizeKeepAspect=$SdlVideoResizeKeepAspect >> AndroidAppSettings.cfg echo NeedDepthBuffer=$NeedDepthBuffer >> AndroidAppSettings.cfg +echo SwVideoMode=$SwVideoMode >> AndroidAppSettings.cfg echo AppUsesMouse=$AppUsesMouse >> AndroidAppSettings.cfg echo AppNeedsTwoButtonMouse=$AppNeedsTwoButtonMouse >> AndroidAppSettings.cfg echo AppNeedsArrowKeys=$AppNeedsArrowKeys >> AndroidAppSettings.cfg @@ -404,6 +417,12 @@ else NeedDepthBuffer=false fi +if [ "$SwVideoMode" = "y" ] ; then + SwVideoMode=true +else + SwVideoMode=false +fi + if [ "$AppUsesMouse" = "y" ] ; then AppUsesMouse=true else @@ -511,6 +530,7 @@ cat project/src/Globals.java | \ sed "s/public static final boolean Using_SDL_1_3 = .*;/public static final boolean Using_SDL_1_3 = $UsingSdl13;/" | \ sed "s@public static String DataDownloadUrl = .*@public static String DataDownloadUrl = \"$AppDataDownloadUrl1\";@" | \ sed "s/public static boolean NeedDepthBuffer = .*;/public static boolean NeedDepthBuffer = $NeedDepthBuffer;/" | \ + sed "s/public static boolean SwVideoMode = .*;/public static boolean SwVideoMode = $SwVideoMode;/" | \ sed "s/public static boolean HorizontalOrientation = .*;/public static boolean HorizontalOrientation = $HorizontalOrientation;/" | \ sed "s/public static boolean InhibitSuspend = .*;/public static boolean InhibitSuspend = $InhibitSuspend;/" | \ sed "s/public static boolean AppUsesMouse = .*;/public static boolean AppUsesMouse = $AppUsesMouse;/" | \ diff --git a/build.sh b/build.sh index 4e4433943..abad2da29 100755 --- a/build.sh +++ b/build.sh @@ -26,6 +26,7 @@ fi cd project && env PATH=$NDKBUILDPATH nice -n19 ndk-build -j4 V=1 && \ { grep "CustomBuildScript=y" ../AndroidAppSettings.cfg > /dev/null && \ [ -`which ndk-build | grep /android-ndk-r5b/` != - ] && \ + echo Stripping libapplication.so by hand \ rm obj/local/armeabi/libapplication.so && \ cp jni/application/src/libapplication.so obj/local/armeabi && \ cp jni/application/src/libapplication.so libs/armeabi && \ diff --git a/project/java/Globals.java b/project/java/Globals.java index 1c5619ac9..a6bfe9d6a 100644 --- a/project/java/Globals.java +++ b/project/java/Globals.java @@ -17,6 +17,8 @@ class Globals { // Set this value to true if you're planning to render 3D using OpenGL - it eats some GFX resources, so disabled for 2D public static boolean NeedDepthBuffer = false; + public static boolean SwVideoMode = false; + public static boolean HorizontalOrientation = true; // prevent device from going to suspend mode @@ -101,6 +103,7 @@ class Globals { public static int TouchscreenCalibration[] = new int[4]; public static String DataDir = new String(""); public static boolean SmoothVideo = false; + public static boolean MultiThreadedVideo = false; } class LoadLibrary { diff --git a/project/java/Settings.java b/project/java/Settings.java index 87c590f23..cac733d82 100644 --- a/project/java/Settings.java +++ b/project/java/Settings.java @@ -45,7 +45,7 @@ class Settings static boolean settingsLoaded = false; static boolean settingsChanged = false; - static final int SETTINGS_FILE_VERSION = 3; + static final int SETTINGS_FILE_VERSION = 4; static void Save(final MainActivity p) { @@ -116,6 +116,7 @@ class Settings out.writeBoolean(Globals.RelativeMouseMovement); out.writeInt(Globals.RelativeMouseMovementSpeed); out.writeInt(Globals.RelativeMouseMovementAccel); + out.writeBoolean(Globals.MultiThreadedVideo); out.writeInt(Globals.OptionalDataDownload.length); for(int i = 0; i < Globals.OptionalDataDownload.length; i++) @@ -249,6 +250,7 @@ class Settings Globals.RelativeMouseMovement = settingsFile.readBoolean(); Globals.RelativeMouseMovementSpeed = settingsFile.readInt(); Globals.RelativeMouseMovementAccel = settingsFile.readInt(); + Globals.MultiThreadedVideo = settingsFile.readBoolean(); Globals.OptionalDataDownload = new boolean[settingsFile.readInt()]; for(int i = 0; i < Globals.OptionalDataDownload.length; i++) @@ -1982,6 +1984,24 @@ class Settings Globals.SmoothVideo }; + if(Globals.SwVideoMode) + { + CharSequence[] items2 = { + p.getResources().getString(R.string.pointandclick_keepaspectratio), + p.getResources().getString(R.string.pointandclick_showcreenunderfinger2), + p.getResources().getString(R.string.video_smooth), + p.getResources().getString(R.string.video_separatethread), + }; + boolean defaults2[] = { + Globals.KeepAspectRatio, + Globals.ShowScreenUnderFinger, + Globals.SmoothVideo, + Globals.MultiThreadedVideo + }; + items = items2; + defaults = defaults2; + } + if(Globals.Using_SDL_1_3) { CharSequence[] items2 = { @@ -2008,6 +2028,8 @@ class Settings Globals.ShowScreenUnderFinger = isChecked; if( item == 2 ) Globals.SmoothVideo = isChecked; + if( item == 3 ) + Globals.MultiThreadedVideo = isChecked; } }); builder.setPositiveButton(p.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() @@ -2036,6 +2058,8 @@ class Settings { if(Globals.SmoothVideo) nativeSetSmoothVideo(); + if( Globals.SwVideoMode && Globals.MultiThreadedVideo ) + nativeSetVideoMultithreaded(); if( Globals.PhoneHasTrackball ) nativeSetTrackballUsed(); if( Globals.AppUsesMouse ) @@ -2157,6 +2181,7 @@ class Settings private static native void nativeSetMultitouchUsed(); private static native void nativeSetTouchscreenKeyboardUsed(); private static native void nativeSetSmoothVideo(); + private static native void nativeSetVideoMultithreaded(); private static native void nativeSetupScreenKeyboard(int size, int theme, int nbuttonsAutoFire, int transparency); private static native void nativeSetupScreenKeyboardButtons(byte[] img); private static native void nativeInitKeymap(); diff --git a/project/java/Video.java b/project/java/Video.java index 39eeb00a6..8f873437e 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -213,7 +213,8 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer { if(Globals.AudioBufferConfig >= 2) Thread.currentThread().setPriority( (Thread.NORM_PRIORITY + Thread.MIN_PRIORITY) / 2 ); // Lower than normal nativeInit( Globals.DataDir, - Globals.CommandLine); // Calls main() and never returns, hehe - we'll call eglSwapBuffers() from native code + Globals.CommandLine, + ( Globals.SwVideoMode && Globals.MultiThreadedVideo ) ? 1 : 0 ); // Calls main() and never returns, hehe - we'll call eglSwapBuffers() from native code System.exit(0); // The main() returns here - I don't bother with deinit stuff, just terminate process } @@ -252,7 +253,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer { }; private native void nativeInitJavaCallbacks(); - private native void nativeInit(String CurrentPath, String CommandLine); + private native void nativeInit(String CurrentPath, String CommandLine, int multiThreadedVideo); private native void nativeResize(int w, int h, int keepAspectRatio); private native void nativeDone(); private native void nativeGlContextLost(); diff --git a/project/java/translations/values/strings.xml b/project/java/translations/values/strings.xml index 37f2710e7..c38f7cd1a 100644 --- a/project/java/translations/values/strings.xml +++ b/project/java/translations/values/strings.xml @@ -141,5 +141,6 @@ Video settings Smooth the video + Separate thread for video, will increase FPS on some devices diff --git a/project/jni/application/ballfield/AndroidAppSettings.cfg b/project/jni/application/ballfield/AndroidAppSettings.cfg index 5a2c3aa1c..20d179ec3 100644 --- a/project/jni/application/ballfield/AndroidAppSettings.cfg +++ b/project/jni/application/ballfield/AndroidAppSettings.cfg @@ -1,5 +1,5 @@ # The application settings for Android libSDL port -AppSettingVersion=16 +AppSettingVersion=17 LibSdlVersion=1.2 AppName="Ballfield" AppFullName=net.olofson.ballfield @@ -9,6 +9,7 @@ AppDataDownloadUrl="Game data is 1 Mb|ballfield.zip" SdlVideoResize=y SdlVideoResizeKeepAspect=n NeedDepthBuffer=n +SwVideoMode=y AppUsesMouse=y AppNeedsTwoButtonMouse=y AppNeedsArrowKeys=n diff --git a/project/jni/application/openttd/AndroidAppSettings.cfg b/project/jni/application/openttd/AndroidAppSettings.cfg index 990fd79f8..6c4dc82df 100644 --- a/project/jni/application/openttd/AndroidAppSettings.cfg +++ b/project/jni/application/openttd/AndroidAppSettings.cfg @@ -11,7 +11,7 @@ SdlVideoResizeKeepAspect=n NeedDepthBuffer=n AppUsesMouse=y AppNeedsTwoButtonMouse=y -AppNeedsArrowKeys=y +AppNeedsArrowKeys=n AppNeedsTextInput=y AppUsesJoystick=n AppHandlesJoystickSensitivity=n @@ -22,8 +22,8 @@ AppTouchscreenKeyboardKeysAmount=0 AppTouchscreenKeyboardKeysAmountAutoFire=0 RedefinedKeysScreenKb="LALT RETURN KP_PLUS KP_MINUS SPACE DELETE KP_PLUS KP_MINUS 1 2" MultiABI=n -AppVersionCode=10511 -AppVersionName="1.0.5.11" +AppVersionCode=10512 +AppVersionName="1.0.5.12" CompiledLibraries="jpeg png freetype timidity lzma lzo2" CustomBuildScript=y AppCflags='' diff --git a/project/jni/application/simplemixer/AndroidAppSettings.cfg b/project/jni/application/simplemixer/AndroidAppSettings.cfg index 6e74d794d..1b2bcaf7b 100644 --- a/project/jni/application/simplemixer/AndroidAppSettings.cfg +++ b/project/jni/application/simplemixer/AndroidAppSettings.cfg @@ -1,5 +1,5 @@ # The application settings for Android libSDL port -AppSettingVersion=16 +AppSettingVersion=17 LibSdlVersion=1.2 AppName="SDL Simple Mixer" AppFullName=net.olofson.simplemixer @@ -9,6 +9,7 @@ AppDataDownloadUrl="Game data is 1 Mb|data.zip" SdlVideoResize=y SdlVideoResizeKeepAspect=n NeedDepthBuffer=n +SwVideoMode=y AppUsesMouse=y AppNeedsTwoButtonMouse=y AppNeedsArrowKeys=n diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c index b0788cd26..ecb613f41 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c @@ -49,14 +49,12 @@ #define DEBUGOUT(...) //#define DEBUGOUT(...) __android_log_print(ANDROID_LOG_INFO, "libSDL", __VA_ARGS__) -/* Initialization/Query functions */ static int ANDROID_VideoInit(_THIS, SDL_PixelFormat *vformat); static SDL_Rect **ANDROID_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); static SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); static int ANDROID_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); static void ANDROID_VideoQuit(_THIS); -/* Hardware surface functions */ static int ANDROID_AllocHWSurface(_THIS, SDL_Surface *surface); static int ANDROID_LockHWSurface(_THIS, SDL_Surface *surface); static void ANDROID_UnlockHWSurface(_THIS, SDL_Surface *surface); @@ -69,6 +67,15 @@ static int ANDROID_FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 co static int ANDROID_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key); static int ANDROID_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 value); static void* ANDROID_GL_GetProcAddress(_THIS, const char *proc); +static void ANDROID_UpdateRects(_THIS, int numrects, SDL_Rect *rects); + +// Multithreaded video support for speed optimization +static int ANDROID_VideoInitMT(_THIS, SDL_PixelFormat *vformat); +static SDL_Surface *ANDROID_SetVideoModeMT(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); +static void ANDROID_VideoQuitMT(_THIS); +static void ANDROID_UpdateRectsMT(_THIS, int numrects, SDL_Rect *rects); +static int ANDROID_FlipHWSurfaceMT(_THIS, SDL_Surface *surface); + // Stubs to get rid of crashing in OpenGL mode // The implementation dependent data for the window manager cursor @@ -99,12 +106,6 @@ void ANDROID_WarpWMCursor(_THIS, Uint16 x, Uint16 y) //void ANDROID_MoveWMCursor(_THIS, int x, int y) { } -/* etc. */ -static void ANDROID_UpdateRects(_THIS, int numrects, SDL_Rect *rects); - - -/* Private display data */ - #define SDL_NUMMODES 12 static SDL_Rect *SDL_modelist[SDL_NUMMODES+1]; @@ -157,13 +158,13 @@ static SDL_VideoDevice *ANDROID_CreateDevice(int devindex) } /* Set the function pointers */ - device->VideoInit = ANDROID_VideoInit; + device->VideoInit = SDL_ANDROID_VideoMultithreaded ? ANDROID_VideoInitMT : ANDROID_VideoInit; device->ListModes = ANDROID_ListModes; - device->SetVideoMode = ANDROID_SetVideoMode; + device->SetVideoMode = SDL_ANDROID_VideoMultithreaded ? ANDROID_SetVideoModeMT : ANDROID_SetVideoMode; device->CreateYUVOverlay = NULL; device->SetColors = ANDROID_SetColors; - device->UpdateRects = ANDROID_UpdateRects; - device->VideoQuit = ANDROID_VideoQuit; + device->UpdateRects = SDL_ANDROID_VideoMultithreaded ? ANDROID_UpdateRectsMT : ANDROID_UpdateRects; + device->VideoQuit = SDL_ANDROID_VideoMultithreaded ? ANDROID_VideoQuitMT : ANDROID_VideoQuit; device->AllocHWSurface = ANDROID_AllocHWSurface; device->CheckHWBlit = ANDROID_CheckHWBlit; device->FillHWRect = ANDROID_FillHWRect; @@ -171,7 +172,7 @@ static SDL_VideoDevice *ANDROID_CreateDevice(int devindex) device->SetHWAlpha = ANDROID_SetHWAlpha; device->LockHWSurface = ANDROID_LockHWSurface; device->UnlockHWSurface = ANDROID_UnlockHWSurface; - device->FlipHWSurface = ANDROID_FlipHWSurface; + device->FlipHWSurface = SDL_ANDROID_VideoMultithreaded ? ANDROID_FlipHWSurfaceMT : ANDROID_FlipHWSurface; device->FreeHWSurface = ANDROID_FreeHWSurface; device->SetCaption = NULL; device->SetIcon = NULL; @@ -183,16 +184,14 @@ static SDL_VideoDevice *ANDROID_CreateDevice(int devindex) device->GL_SwapBuffers = ANDROID_GL_SwapBuffers; device->GL_GetProcAddress = ANDROID_GL_GetProcAddress; device->free = ANDROID_DeleteDevice; + device->WarpWMCursor = ANDROID_WarpWMCursor; // Stubs device->FreeWMCursor = ANDROID_FreeWMCursor; device->CreateWMCursor = ANDROID_CreateWMCursor; device->ShowWMCursor = ANDROID_ShowWMCursor; - device->WarpWMCursor = ANDROID_WarpWMCursor; - //device->MoveWMCursor = ANDROID_MoveWMCursor; glLibraryHandle = dlopen("libGLESv1_CM.so", RTLD_NOW); - __android_log_print(ANDROID_LOG_INFO, "libSDL", "dlopen(\"libGLESv1_CM.so\"): %p", glLibraryHandle); return device; } @@ -971,3 +970,164 @@ static void* ANDROID_GL_GetProcAddress(_THIS, const char *proc) //__android_log_print(ANDROID_LOG_INFO, "libSDL", "ANDROID_GL_GetProcAddress(\"%s\"): %p", proc, func); return func; }; + +// Multithreaded video - this will free up some CPU time while GPU renders video inside SDL_Flip() +enum videoThreadCmd_t { CMD_INIT, CMD_SETVIDEOMODE, CMD_QUIT, CMD_UPDATERECTS, CMD_FLIP }; +typedef struct +{ + SDL_mutex * mutex; + SDL_cond * cond; + SDL_cond * cond2; + int execute; + int threadReady; + enum videoThreadCmd_t cmd; + SDL_VideoDevice *_this; + SDL_PixelFormat *vformat; + SDL_Surface *current; + int width; + int height; + int bpp; + Uint32 flags; + + int retcode; + SDL_Surface * retcode2; +} videoThread_t; +static videoThread_t videoThread; + +extern void SDL_ANDROID_MultiThreadedVideoLoopInit(); +extern void SDL_ANDROID_MultiThreadedVideoLoop(); + +void SDL_ANDROID_MultiThreadedVideoLoopInit() +{ + videoThread.mutex = SDL_CreateMutex(); + videoThread.cond = SDL_CreateCond(); + videoThread.cond2 = SDL_CreateCond(); + videoThread.execute = 0; +} + +void SDL_ANDROID_MultiThreadedVideoLoop() +{ + while(1) + { + int signalNeeded = 0; + SDL_mutexP(videoThread.mutex); + videoThread.threadReady = 1; + SDL_CondSignal(videoThread.cond2); + SDL_CondWaitTimeout(videoThread.cond, videoThread.mutex, 10000); + if( videoThread.execute ) + { + videoThread.threadReady = 0; + switch( videoThread.cmd ) + { + case CMD_INIT: + videoThread.retcode = ANDROID_VideoInit(videoThread._this, videoThread.vformat); + break; + case CMD_SETVIDEOMODE: + videoThread.retcode2 = ANDROID_SetVideoMode(videoThread._this, videoThread.current, + videoThread.width, videoThread.height, videoThread.bpp, videoThread.flags); + break; + case CMD_QUIT: + ANDROID_VideoQuit(videoThread._this); + break; + case CMD_UPDATERECTS: + ANDROID_UpdateRects(videoThread._this, 0, NULL); + break; + case CMD_FLIP: + videoThread.retcode = ANDROID_FlipHWSurface(videoThread._this, NULL); + break; + } + videoThread.execute = 0; + signalNeeded = 1; + } + SDL_mutexV(videoThread.mutex); + if( signalNeeded ) + SDL_CondSignal(videoThread.cond2); + } +} + +int ANDROID_VideoInitMT(_THIS, SDL_PixelFormat *vformat) +{ + SDL_mutexP(videoThread.mutex); + while( ! videoThread.threadReady ) + SDL_CondWaitTimeout(videoThread.cond2, videoThread.mutex, 10000); + videoThread.cmd = CMD_INIT; + videoThread._this = this; + videoThread.vformat = vformat; + videoThread.execute = 1; + SDL_CondSignal(videoThread.cond); + while( videoThread.execute ) + SDL_CondWaitTimeout(videoThread.cond2, videoThread.mutex, 10000); + int ret = videoThread.retcode; + SDL_mutexV(videoThread.mutex); + return ret; +} + +SDL_Surface *ANDROID_SetVideoModeMT(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) +{ + if( flags & SDL_OPENGL || flags & SDL_HWSURFACE ) + { + __android_log_print(ANDROID_LOG_FATAL, "libSDL", "SDL_SetVideoMode(): cannot use multi-threaded video with SDL_OPENGL or SDL_HWSURFACE flags"); + return NULL; + } + SDL_mutexP(videoThread.mutex); + while( ! videoThread.threadReady ) + SDL_CondWaitTimeout(videoThread.cond2, videoThread.mutex, 10000); + videoThread.cmd = CMD_SETVIDEOMODE; + videoThread._this = this; + videoThread.current = current; + videoThread.width = width; + videoThread.height = height; + videoThread.bpp = bpp; + videoThread.flags = flags; + videoThread.execute = 1; + SDL_CondSignal(videoThread.cond); + while( videoThread.execute ) + SDL_CondWaitTimeout(videoThread.cond2, videoThread.mutex, 10000); + SDL_Surface * ret = videoThread.retcode2; + SDL_mutexV(videoThread.mutex); + return ret; +} + +void ANDROID_VideoQuitMT(_THIS) +{ + SDL_mutexP(videoThread.mutex); + while( ! videoThread.threadReady ) + SDL_CondWaitTimeout(videoThread.cond2, videoThread.mutex, 10000); + videoThread.cmd = CMD_QUIT; + videoThread._this = this; + videoThread.execute = 1; + SDL_CondSignal(videoThread.cond); + while( videoThread.execute ) + SDL_CondWaitTimeout(videoThread.cond2, videoThread.mutex, 10000); + SDL_mutexV(videoThread.mutex); +} + +void ANDROID_UpdateRectsMT(_THIS, int numrects, SDL_Rect *rects) +{ + SDL_mutexP(videoThread.mutex); + while( ! videoThread.threadReady ) + SDL_CondWaitTimeout(videoThread.cond2, videoThread.mutex, 10000); + videoThread.cmd = CMD_UPDATERECTS; + videoThread._this = this; + videoThread.execute = 1; + SDL_CondSignal(videoThread.cond); + while( videoThread.execute ) + SDL_CondWaitTimeout(videoThread.cond2, videoThread.mutex, 10000); + SDL_mutexV(videoThread.mutex); +} + +int ANDROID_FlipHWSurfaceMT(_THIS, SDL_Surface *surface) +{ + SDL_mutexP(videoThread.mutex); + while( ! videoThread.threadReady ) + SDL_CondWaitTimeout(videoThread.cond2, videoThread.mutex, 10000); + videoThread.cmd = CMD_FLIP; + videoThread._this = this; + videoThread.execute = 1; + SDL_CondSignal(videoThread.cond); + while( videoThread.execute ) + SDL_CondWaitTimeout(videoThread.cond2, videoThread.mutex, 10000); + int ret = videoThread.retcode; + SDL_mutexV(videoThread.mutex); + return ret; +} 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 b3d9ba413..aa489ff5f 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 @@ -603,8 +603,12 @@ void SDL_ANDROID_WarpMouse(int x, int y) } else { + SDL_ANDROID_MainThreadPushMouseMotion(x, y); + // TODO: test and enable it + /* relativeMovementX = x; relativeMovementY = y; + */ } }; 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 2438e4f47..8432eb29d 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 @@ -64,6 +64,7 @@ static jmethodID JavaShowScreenKeyboard = NULL; static int glContextLost = 0; static int showScreenKeyboardDeferred = 0; int SDL_ANDROID_SmoothVideo = 0; +int SDL_ANDROID_VideoMultithreaded = 0; static void appPutToBackgroundCallbackDefault(void) { @@ -252,3 +253,9 @@ JAVA_EXPORT_NAME(Settings_nativeSetSmoothVideo) (JNIEnv* env, jobject thiz) { SDL_ANDROID_SmoothVideo = 1; } + +JNIEXPORT void JNICALL +JAVA_EXPORT_NAME(Settings_nativeSetVideoMultithreaded) (JNIEnv* env, jobject thiz) +{ + SDL_ANDROID_VideoMultithreaded = 1; +} diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h index 036f074a7..3658d4afb 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidvideo.h @@ -39,6 +39,7 @@ extern int SDL_ANDROID_TouchscreenCalibrationHeight; extern int SDL_ANDROID_TouchscreenCalibrationX; extern int SDL_ANDROID_TouchscreenCalibrationY; extern int SDL_ANDROID_SmoothVideo; +extern int SDL_ANDROID_VideoMultithreaded; extern SDL_Surface *SDL_CurrentVideoSurface; extern SDL_Rect SDL_ANDROID_ForceClearScreenRect; extern int SDL_ANDROID_ShowScreenUnderFinger; diff --git a/project/jni/sdl_main/sdl_main.c b/project/jni/sdl_main/sdl_main.c index bb1e0891b..d4d5486c0 100644 --- a/project/jni/sdl_main/sdl_main.c +++ b/project/jni/sdl_main/sdl_main.c @@ -24,15 +24,25 @@ #define JAVA_EXPORT_NAME1(name,package) JAVA_EXPORT_NAME2(name,package) #define JAVA_EXPORT_NAME(name) JAVA_EXPORT_NAME1(name,SDL_JAVA_PACKAGE_PATH) +extern void SDL_ANDROID_MultiThreadedVideoLoopInit(); +extern void SDL_ANDROID_MultiThreadedVideoLoop(); + +static int argc = 0; +static char ** argv = NULL; + +static int threadedMain(void * unused) +{ + SDL_main( argc, argv ); + exit(0); +} + extern C_LINKAGE void -JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz, jstring jcurdir, jstring cmdline ) +JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz, jstring jcurdir, jstring cmdline, jint multiThreadedVideo ) { int i = 0; char curdir[PATH_MAX] = ""; const jbyte *jstr; const char * str = "sdl"; - int argc = 0; - char ** argv = NULL; strcpy(curdir, "/sdcard/app-data/"); strcat(curdir, SDL_CURDIR_PATH); @@ -86,8 +96,14 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz, jstring for( i = 0; i < argc; i++ ) __android_log_print(ANDROID_LOG_INFO, "libSDL", "param %d = \"%s\"", i, argv[i]); - main( argc, argv ); - + if( ! multiThreadedVideo ) + SDL_main( argc, argv ); + else + { + SDL_ANDROID_MultiThreadedVideoLoopInit(); + SDL_CreateThread(threadedMain, NULL); + SDL_ANDROID_MultiThreadedVideoLoop(); + } }; extern C_LINKAGE void @@ -101,9 +117,4 @@ JAVA_EXPORT_NAME(Settings_nativeSetEnv) ( JNIEnv* env, jobject thiz, jstring j_ (*env)->ReleaseStringUTFChars(env, j_value, value); } -#undef JAVA_EXPORT_NAME -#undef JAVA_EXPORT_NAME1 -#undef JAVA_EXPORT_NAME2 -#undef C_LINKAGE - #endif diff --git a/todo.txt b/todo.txt index 7602e97f3..d3bc02609 100644 --- a/todo.txt +++ b/todo.txt @@ -7,8 +7,6 @@ I'm not planning any more games to port. Bugs to fix =========== -- Running OpenGL SwapBuffers in a separate thread - huge speed improvement expected. - - Show/hide screen controls with longpress on Text Edit button. - Support of libjnigraphics (it will disable on-screen keyboard, only SW SDL screen surface supported)