From 5c720fb3d9171886ef3f994a82aa4e0dc68f47b7 Mon Sep 17 00:00:00 2001 From: pelya Date: Mon, 6 Aug 2012 17:05:40 +0300 Subject: [PATCH] Force SW video mode in SDL_SetVideoMode() if enabled in AndroidAppSettings.cfg --- ChangeAppSettings.sh | 4 +--- project/java/Settings.java | 3 +++ project/jni/SettingsTemplate.mk | 2 +- .../jni/application/ballfield/ballfield.cpp | 17 +++----------- .../commandergenius/commandergenius | 2 +- project/jni/application/openarena/engine | 2 +- .../src/video/android/SDL_androidvideo-1.2.c | 22 ++++++++++++++----- .../src/video/android/SDL_androidvideo.c | 7 ++++++ .../src/video/android/SDL_androidvideo.h | 1 + project/jni/stdout-test/Android.mk | 8 ------- project/jni/stdout-test/stdout-test.c | 18 --------------- 11 files changed, 35 insertions(+), 51 deletions(-) delete mode 100644 project/jni/stdout-test/Android.mk delete mode 100644 project/jni/stdout-test/stdout-test.c diff --git a/ChangeAppSettings.sh b/ChangeAppSettings.sh index d929b9b36..6609767d5 100755 --- a/ChangeAppSettings.sh +++ b/ChangeAppSettings.sh @@ -870,7 +870,7 @@ mv -f project/src/Globals.java.1 project/src/Globals.java echo Patching project/jni/Settings.mk echo '# DO NOT EDIT THIS FILE - it is automatically generated, edit file SettingsTemplate.mk' > project/jni/Settings.mk cat project/jni/SettingsTemplate.mk | \ - sed "s/APP_MODULES := .*/APP_MODULES := application sdl-$LibSdlVersion sdl_main stlport jpeg png ogg flac vorbis freetype stdout-test $CompiledLibraries/" | \ + sed "s/APP_MODULES := .*/APP_MODULES := application sdl-$LibSdlVersion sdl_main stlport jpeg png ogg flac vorbis freetype $CompiledLibraries/" | \ sed "s/APP_ABI := .*/APP_ABI := $MultiABI/" | \ sed "s/SDL_JAVA_PACKAGE_PATH := .*/SDL_JAVA_PACKAGE_PATH := $AppFullNameUnderscored/" | \ sed "s^SDL_CURDIR_PATH := .*^SDL_CURDIR_PATH := $DataPath^" | \ @@ -905,7 +905,6 @@ rm -rf project/$OUT/local/*/libsdl_*.so rm -rf project/$OUT/local/*/objs*/sdl-*/src/*/android rm -rf project/$OUT/local/*/objs*/sdl-*/src/video/SDL_video.o rm -rf project/$OUT/local/*/objs*/sdl-*/SDL_renderer_gles.o -rm -rf project/$OUT/local/*/libsdl_fake_stdout.a project/$OUT/local/*/objs*/sdl_fake_stdout/* rm -rf project/$OUT/local/*/objs*/sdl_* # Do not rebuild several huge libraries that do not depend on SDL version for LIB in freetype intl jpeg png lua mad stlport tremor xerces xml2; do @@ -924,7 +923,6 @@ rm -f project/assets/* if [ -d "project/jni/application/src/AndroidData" ] ; then echo Copying asset files cp project/jni/application/src/AndroidData/* project/assets/ - ln -s ../libs/armeabi/stdout-test project/assets/ for F in project/assets/*; do if [ `cat $F | wc -c` -gt 1000000 ] ; then echo "The file $F is bigger than 1 megabyte - splitting it into smaller chunks" diff --git a/project/java/Settings.java b/project/java/Settings.java index 35bc15c2d..0529274f0 100644 --- a/project/java/Settings.java +++ b/project/java/Settings.java @@ -2417,6 +2417,8 @@ class Settings Globals.SwVideoMode = true; nativeSetCompatibilityHacks(); } + if( Globals.SwVideoMode ) + nativeSetVideoForceSoftwareMode(); if( Globals.SwVideoMode && Globals.MultiThreadedVideo ) nativeSetVideoMultithreaded(); if( Globals.PhoneHasTrackball ) @@ -2557,6 +2559,7 @@ class Settings private static native void nativeSetVideoDepth(int bpp, int gles2); private static native void nativeSetCompatibilityHacks(); private static native void nativeSetVideoMultithreaded(); + private static native void nativeSetVideoForceSoftwareMode(); private static native void nativeSetupScreenKeyboard(int size, int drawsize, int theme, int nbuttonsAutoFire, int transparency); private static native void nativeSetupScreenKeyboardButtons(byte[] img); private static native void nativeInitKeymap(); diff --git a/project/jni/SettingsTemplate.mk b/project/jni/SettingsTemplate.mk index ea3b42331..2b41aa3a6 100644 --- a/project/jni/SettingsTemplate.mk +++ b/project/jni/SettingsTemplate.mk @@ -3,7 +3,7 @@ APP_MODULES := application sdl-1.2 sdl_main stlport jpeg png ogg flac vorbis freetype tremor ogg # To filter out static libs from all libs in makefile -APP_AVAILABLE_STATIC_LIBS := jpeg png tremor freetype xerces ogg tremor vorbis flac sdl_fake_stdout boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_signals boost_system boost_thread +APP_AVAILABLE_STATIC_LIBS := jpeg png tremor freetype xerces ogg tremor vorbis flac boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_signals boost_system boost_thread APP_ABI := armeabi diff --git a/project/jni/application/ballfield/ballfield.cpp b/project/jni/application/ballfield/ballfield.cpp index 8bfef80f8..cac0f0376 100644 --- a/project/jni/application/ballfield/ballfield.cpp +++ b/project/jni/application/ballfield/ballfield.cpp @@ -9,8 +9,6 @@ * software, or work derived from it, under other terms. */ -#include -#include #include #include #include @@ -25,7 +23,7 @@ ----------------------------------------------------------*/ #define SCREEN_W 320 -#define SCREEN_H 240 +#define SCREEN_H 200 #define BALLS 300 @@ -411,12 +409,6 @@ void tiled_back(SDL_Surface *back, SDL_Surface *screen, int xo, int yo) main() ----------------------------------------------------------*/ -extern "C" void unaligned_test(unsigned * data, unsigned * target); -extern "C" unsigned val0, val1, val2, val3, val4; - -unsigned val0 = 0x01234567, val1, val2, val3; - - int main(int argc, char* argv[]) { ballfield_t *balls; @@ -425,7 +417,7 @@ int main(int argc, char* argv[]) SDL_Surface *back, *logo, *font, *font_hex; SDL_Event event; int bpp = 16, - flags = 0, + flags = SDL_HWSURFACE, alpha = 1; int x_offs = 0, y_offs = 0; long tick, @@ -677,8 +669,5 @@ int main(int argc, char* argv[]) SDL_FreeSurface(back); SDL_FreeSurface(logo); SDL_FreeSurface(font); - std::ostringstream os; - os << "lalala" << std::endl << "more text" << std::endl; - std::cout << os.str() << std::endl << "text text" << std::endl; - exit(0); + return 0; } diff --git a/project/jni/application/commandergenius/commandergenius b/project/jni/application/commandergenius/commandergenius index 023025901..d4ef5612e 160000 --- a/project/jni/application/commandergenius/commandergenius +++ b/project/jni/application/commandergenius/commandergenius @@ -1 +1 @@ -Subproject commit 023025901a1d96a46d826791bf9cf264ddf5c9ee +Subproject commit d4ef5612e979b11b07e4b35c0f683a2a8aefb19a diff --git a/project/jni/application/openarena/engine b/project/jni/application/openarena/engine index cea3164ad..ed71ad5bf 160000 --- a/project/jni/application/openarena/engine +++ b/project/jni/application/openarena/engine @@ -1 +1 @@ -Subproject commit cea3164adfe13c53b3849985a1b29780efe5cef3 +Subproject commit ed71ad5bf967c535f368b68b1044ca28ce5d28f4 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 7aaefd448..5ff27936b 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 @@ -307,12 +307,21 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, return NULL; } + if( SDL_ANDROID_VideoForceSoftwareMode ) + { + if( flags & SDL_HWSURFACE ) + __android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_SetVideoMode(): application requested hardware video mode - forcing software video mode"); + if( flags & SDL_OPENGL ) + __android_log_print(ANDROID_LOG_INFO, "libSDL", "Error: application requested OpenGL context - SDL will ignore this. Set SwVideoMode=n inside AndroidAppSettings.cfg to enable OpenGL inside SDL."); + flags = (flags & SDL_FULLSCREEN) | (flags & SDL_DOUBLEBUF); + } + sdl_opengl = (flags & SDL_OPENGL) ? 1 : 0; SDL_ANDROID_sFakeWindowWidth = width; SDL_ANDROID_sFakeWindowHeight = height; - current->flags = (flags & SDL_FULLSCREEN) | (flags & SDL_OPENGL) | SDL_DOUBLEBUF | ( flags & SDL_HWSURFACE ); + current->flags = (flags & SDL_FULLSCREEN) | (flags & SDL_OPENGL) | SDL_DOUBLEBUF | (flags & SDL_HWSURFACE); current->w = width; current->h = height; current->pitch = SDL_ANDROID_sFakeWindowWidth * SDL_ANDROID_BYTESPERPIXEL; @@ -456,7 +465,13 @@ static int ANDROID_AllocHWSurface(_THIS, SDL_Surface *surface) } if ( ! (surface->w && surface->h) ) - return(-1); + return -1; + + if( SDL_ANDROID_VideoForceSoftwareMode ) + { + //__android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_SetVideoMode(): ignoring application attempt to allocate HW surface"); + return -1; + } DEBUGOUT("ANDROID_AllocHWSurface() surface %p w %d h %d", surface, surface->w, surface->h); Uint32 format = PixelFormatEnumColorkey; // 1-bit alpha for color key, every surface will have colorkey so it's easier for us @@ -514,7 +529,6 @@ static int ANDROID_AllocHWSurface(_THIS, SDL_Surface *surface) surface->flags |= SDL_HWSURFACE | SDL_HWACCEL; - HwSurfaceCount++; DEBUGOUT("ANDROID_AllocHWSurface() in HwSurfaceCount %d HwSurfaceList %p", HwSurfaceCount, HwSurfaceList); HwSurfaceList = SDL_realloc( HwSurfaceList, HwSurfaceCount * sizeof(SDL_Surface *) ); @@ -554,9 +568,7 @@ static void ANDROID_FreeHWSurface(_THIS, SDL_Surface *surface) } } if( i != -1 ) - { SDL_SetError("ANDROID_FreeHWSurface: cannot find freed HW surface in HwSurfaceList array"); - } } static int ANDROID_LockHWSurface(_THIS, SDL_Surface *surface) 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 2ca6d31c8..4271c3bb0 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 @@ -67,6 +67,7 @@ static const char * showScreenKeyboardOldText = ""; static int showScreenKeyboardSendBackspace = 0; int SDL_ANDROID_SmoothVideo = 0; int SDL_ANDROID_VideoMultithreaded = 0; +int SDL_ANDROID_VideoForceSoftwareMode = 0; int SDL_ANDROID_CompatibilityHacks = 0; int SDL_ANDROID_BYTESPERPIXEL = 2; int SDL_ANDROID_BITSPERPIXEL = 16; @@ -324,6 +325,12 @@ JAVA_EXPORT_NAME(Settings_nativeSetVideoMultithreaded) (JNIEnv* env, jobject thi SDL_ANDROID_VideoMultithreaded = 1; } +JNIEXPORT void JNICALL +JAVA_EXPORT_NAME(Settings_nativeSetVideoForceSoftwareMode) (JNIEnv* env, jobject thiz) +{ + SDL_ANDROID_VideoForceSoftwareMode = 1; +} + JNIEXPORT void JNICALL JAVA_EXPORT_NAME(Settings_nativeSetCompatibilityHacks) (JNIEnv* env, jobject thiz) { 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 25473d936..bca181dce 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 @@ -42,6 +42,7 @@ extern int SDL_ANDROID_TouchscreenCalibrationX; extern int SDL_ANDROID_TouchscreenCalibrationY; extern int SDL_ANDROID_SmoothVideo; extern int SDL_ANDROID_VideoMultithreaded; +extern int SDL_ANDROID_VideoForceSoftwareMode; extern int SDL_ANDROID_CompatibilityHacks; extern int SDL_ANDROID_ShowMouseCursor; extern int SDL_ANDROID_UseGles2; diff --git a/project/jni/stdout-test/Android.mk b/project/jni/stdout-test/Android.mk deleted file mode 100644 index 930359ae9..000000000 --- a/project/jni/stdout-test/Android.mk +++ /dev/null @@ -1,8 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := stdout-test -LOCAL_SRC_FILES = stdout-test.c - -include $(BUILD_EXECUTABLE) diff --git a/project/jni/stdout-test/stdout-test.c b/project/jni/stdout-test/stdout-test.c deleted file mode 100644 index 4eae1d302..000000000 --- a/project/jni/stdout-test/stdout-test.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include - -extern int main(int argc, char *argv[]); - -int main(int argc, char *argv[]) -{ - // Numerous Telechips devices will crash this simple Posix-compatibility test - printf("printf()\n"); - fprintf(stdout, "fprintf(stdout)\n"); - fflush(stdout); - fprintf(stderr, "fprintf(stderr)\n"); - fflush(stderr); - write(STDOUT_FILENO, "write(1)\n", strlen("write(1)\n")); - write(STDERR_FILENO, "write(2)\n", strlen("write(2)\n")); - return 42; -}