Added compatibility mode to SDL, for misbehaving apps that don't call SDL_Flip()

This commit is contained in:
pelya
2011-07-06 11:49:01 +03:00
parent 3027c3a0ae
commit bbf90a959b
8 changed files with 80 additions and 14 deletions

View File

@@ -126,15 +126,29 @@ fi
fi
if [ "$LibSdlVersion" = "1.2" ]; then
if [ -z "$SwVideoMode" -o -z "$AUTO" ]; then
echo
echo "Application uses software video buffer - you're calling SDL_SetVideoMode() without SDL_HWSURFACE and without SDL_OPENGL,"
echo -n "this will allow small speed optimization (y) or (n) ($SwVideoMode): "
read var
if [ -n "$var" ] ; then
SwVideoMode="$var"
CHANGED=1
if [ -z "$CompatibilityHacks" -o -z "$AUTO" ]; then
echo
echo "Application does not call SDL_Flip() or SDL_UpdateRects() appropriately, or draws from non-main thread -"
echo -n "enabling the compatibility mode will force screen update every halfsecond (y) or (n) ($CompatibilityHacks): "
read var
if [ -n "$var" ] ; then
CompatibilityHacks="$var"
CHANGED=1
fi
fi
if [ "$CompatibilityHacks" = y ]; then
SwVideoMode=y
else
if [ -z "$SwVideoMode" -o -z "$AUTO" ]; then
echo
echo "Application uses software video buffer - you're calling SDL_SetVideoMode() without SDL_HWSURFACE and without SDL_OPENGL,"
echo -n "this will allow small speed optimization (y) or (n) ($SwVideoMode): "
read var
if [ -n "$var" ] ; then
SwVideoMode="$var"
CHANGED=1
fi
fi
fi
else
SwVideoMode=n
@@ -300,7 +314,7 @@ if [ -n "$var" ] ; then
fi
fi
if [ -z "$HiddenMenuOptions" -o -z "$AUTO" ]; then
if [ -z "$AUTO" ]; then
echo
echo "Menu items to hide from startup menu, available menu items:"
echo `grep 'extends Menu' project/java/Settings.java | sed 's/.* class \(.*\) extends .*/\1/'`
@@ -313,6 +327,22 @@ if [ -n "$var" ] ; then
fi
fi
FirstStartMenuOptionsDefault='(AppUsesMouse ? new Settings.DisplaySizeConfig(true) : new Settings.DummyMenu()), new Settings.OptionalDownloadConfig(true)'
if [ -z "$AUTO" ]; then
echo
echo "Menu items to show at startup - this is Java code snippet, leave empty for default"
echo $FirstStartMenuOptionsDefault
echo "Available menu items:"
echo `grep 'extends Menu' project/java/Settings.java | sed 's/.* class \(.*\) extends .*/new Settings.\1(), /'`
echo "Current value: " "$FirstStartMenuOptions"
echo -n ": "
read var
if [ -n "$var" ] ; then
FirstStartMenuOptions="$var"
CHANGED=1
fi
fi
if [ -z "$MultiABI" -o -z "$AUTO" ]; then
echo
echo "Enable multi-ABI binary, with hardware FPU support - "
@@ -450,6 +480,7 @@ echo SdlVideoResize=$SdlVideoResize >> AndroidAppSettings.cfg
echo SdlVideoResizeKeepAspect=$SdlVideoResizeKeepAspect >> AndroidAppSettings.cfg
echo NeedDepthBuffer=$NeedDepthBuffer >> AndroidAppSettings.cfg
echo SwVideoMode=$SwVideoMode >> AndroidAppSettings.cfg
echo CompatibilityHacks=$CompatibilityHacks >> AndroidAppSettings.cfg
echo AppUsesMouse=$AppUsesMouse >> AndroidAppSettings.cfg
echo AppNeedsTwoButtonMouse=$AppNeedsTwoButtonMouse >> AndroidAppSettings.cfg
echo AppNeedsArrowKeys=$AppNeedsArrowKeys >> AndroidAppSettings.cfg
@@ -464,6 +495,7 @@ echo AppTouchscreenKeyboardKeysAmountAutoFire=$AppTouchscreenKeyboardKeysAmountA
echo RedefinedKeysScreenKb=\"$RedefinedKeysScreenKb\" >> AndroidAppSettings.cfg
echo StartupMenuButtonTimeout=$StartupMenuButtonTimeout >> AndroidAppSettings.cfg
echo HiddenMenuOptions=\'$HiddenMenuOptions\' >> AndroidAppSettings.cfg
echo FirstStartMenuOptions=\'$FirstStartMenuOptions\' >> AndroidAppSettings.cfg
echo MultiABI=$MultiABI >> AndroidAppSettings.cfg
echo AppVersionCode=$AppVersionCode >> AndroidAppSettings.cfg
echo AppVersionName=\"$AppVersionName\" >> AndroidAppSettings.cfg
@@ -525,6 +557,12 @@ else
SwVideoMode=false
fi
if [ "$CompatibilityHacks" = "y" ] ; then
CompatibilityHacks=true
else
CompatibilityHacks=false
fi
if [ "$AppUsesMouse" = "y" ] ; then
AppUsesMouse=true
else
@@ -611,6 +649,10 @@ for F in $HiddenMenuOptions; do
HiddenMenuOptions1="$HiddenMenuOptions1 new Settings.$F(),"
done
if [ -z "$FirstStartMenuOptions" ]; then
FirstStartMenuOptions="$FirstStartMenuOptionsDefault"
fi
ReadmeText="`echo $ReadmeText | sed 's/\"/\\\\\\\\\"/g' | sed 's/[&%]//g'`"
echo Patching project/AndroidManifest.xml
@@ -638,6 +680,7 @@ cat project/src/Globals.java | \
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 CompatibilityHacks = .*;/public static boolean CompatibilityHacks = $CompatibilityHacks;/" | \
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;/" | \
@@ -652,6 +695,7 @@ cat project/src/Globals.java | \
sed "s/public static int AppTouchscreenKeyboardKeysAmountAutoFire = .*;/public static int AppTouchscreenKeyboardKeysAmountAutoFire = $AppTouchscreenKeyboardKeysAmountAutoFire;/" | \
sed "s/public static int StartupMenuButtonTimeout = .*;/public static int StartupMenuButtonTimeout = $StartupMenuButtonTimeout;/" | \
sed "s/public static Settings.Menu HiddenMenuOptions .*;/public static Settings.Menu HiddenMenuOptions [] = { $HiddenMenuOptions1 };/" | \
sed "s@public static Settings.Menu FirstStartMenuOptions .*;@public static Settings.Menu FirstStartMenuOptions [] = { $FirstStartMenuOptions };@" | \
sed "s%public static String ReadmeText = .*%public static String ReadmeText = \"$ReadmeText\".replace(\"^\",\"\\\n\");%" | \
sed "s%public static String CommandLine = .*%public static String CommandLine = \"$AppCmdline\";%" | \
sed "s/public static String AppLibraries.*/public static String AppLibraries[] = { $LibrariesToLoad };/" > \

View File

@@ -34,6 +34,7 @@ class Globals {
public static String DataDownloadUrl = "Data files are 2 Mb|https://sourceforge.net/projects/libsdl-android/files/CommanderGenius/commandergenius-data.zip/download^High-quality GFX and music - 40 Mb|https://sourceforge.net/projects/libsdl-android/files/CommanderGenius/commandergenius-hqp.zip/download";
public static boolean NeedDepthBuffer = false;
public static boolean SwVideoMode = false;
public static boolean CompatibilityHacks = false;
public static boolean HorizontalOrientation = true;
public static boolean InhibitSuspend = false;
public static String ReadmeText = "^You may press \"Home\" now - the data will be downloaded in background".replace("^","\n");
@@ -50,7 +51,6 @@ class Globals {
public static int AppTouchscreenKeyboardKeysAmountAutoFire = 1;
public static int StartupMenuButtonTimeout = 3000;
public static Settings.Menu HiddenMenuOptions [] = {};
// Not configurable yet through ChangeAppSettings.sh
public static Settings.Menu FirstStartMenuOptions [] = { (AppUsesMouse ? new Settings.DisplaySizeConfig(true) : new Settings.DummyMenu()), new Settings.OptionalDownloadConfig(true) };
// Phone-specific config, modified by user in "Change phone config" startup dialog, TODO: move this to settings

View File

@@ -2240,7 +2240,7 @@ class Settings
Globals.SmoothVideo
};
if(Globals.SwVideoMode)
if(Globals.SwVideoMode && !Globals.CompatibilityHacks)
{
CharSequence[] items2 = {
p.getResources().getString(R.string.pointandclick_keepaspectratio),
@@ -2315,6 +2315,12 @@ class Settings
{
if(Globals.SmoothVideo)
nativeSetSmoothVideo();
if( Globals.CompatibilityHacks )
{
Globals.MultiThreadedVideo = true;
Globals.SwVideoMode = true;
nativeSetCompatibilityHacks();
}
if( Globals.SwVideoMode && Globals.MultiThreadedVideo )
nativeSetVideoMultithreaded();
if( Globals.PhoneHasTrackball )
@@ -2438,6 +2444,7 @@ class Settings
private static native void nativeSetMultitouchUsed();
private static native void nativeSetTouchscreenKeyboardUsed();
private static native void nativeSetSmoothVideo();
private static native void nativeSetCompatibilityHacks();
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);

View File

@@ -308,9 +308,10 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
// Tweak video thread priority, if user selected big audio buffer
if(Globals.AudioBufferConfig >= 2)
Thread.currentThread().setPriority( (Thread.NORM_PRIORITY + Thread.MIN_PRIORITY) / 2 ); // Lower than normal
// Calls main() and never returns, hehe - we'll call eglSwapBuffers() from native code
nativeInit( Globals.DataDir,
Globals.CommandLine,
( Globals.SwVideoMode && Globals.MultiThreadedVideo ) ? 1 : 0 ); // Calls main() and never returns, hehe - we'll call eglSwapBuffers() from native code
( (Globals.SwVideoMode && Globals.MultiThreadedVideo) || Globals.CompatibilityHacks ) ? 1 : 0 );
System.exit(0); // The main() returns here - I don't bother with deinit stuff, just terminate process
}

View File

@@ -1 +1 @@
grafx2
milkytracker

View File

@@ -1028,10 +1028,11 @@ void SDL_ANDROID_MultiThreadedVideoLoop()
{
int signalNeeded = 0;
int swapBuffersNeeded = 0;
int ret;
SDL_mutexP(videoThread.mutex);
videoThread.threadReady = 1;
SDL_CondSignal(videoThread.cond2);
SDL_CondWaitTimeout(videoThread.cond, videoThread.mutex, 1000);
ret = SDL_CondWaitTimeout(videoThread.cond, videoThread.mutex, SDL_ANDROID_CompatibilityHacks ? 400 : 1000);
if( videoThread.execute )
{
videoThread.threadReady = 0;
@@ -1059,6 +1060,11 @@ void SDL_ANDROID_MultiThreadedVideoLoop()
videoThread.execute = 0;
signalNeeded = 1;
}
else if( SDL_ANDROID_CompatibilityHacks && ret == SDL_MUTEX_TIMEDOUT && SDL_CurrentVideoSurface )
{
ANDROID_FlipHWSurfaceInternal();
swapBuffersNeeded = 1;
}
SDL_mutexV(videoThread.mutex);
if( signalNeeded )
SDL_CondSignal(videoThread.cond2);

View File

@@ -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_CompatibilityHacks = 0;
static void appPutToBackgroundCallbackDefault(void)
{
@@ -299,3 +300,9 @@ JAVA_EXPORT_NAME(Settings_nativeSetVideoMultithreaded) (JNIEnv* env, jobject thi
{
SDL_ANDROID_VideoMultithreaded = 1;
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetCompatibilityHacks) (JNIEnv* env, jobject thiz)
{
SDL_ANDROID_CompatibilityHacks = 1;
}

View File

@@ -40,6 +40,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_CompatibilityHacks;
extern void SDL_ANDROID_TextInputInit(char * buffer, int len);
extern void SDL_ANDROID_TextInputFinished();
extern SDL_Surface *SDL_CurrentVideoSurface;