Removed dependency to stdbool.h in implementation file for Android.

This reduced mixing of different types in the file (bool, jboolean, SDL_bool).
This commit is contained in:
Philipp Wiesemann 2014-12-10 21:20:41 +01:00
parent d99911544f
commit 0f87761bf3

View file

@ -44,8 +44,8 @@
#define LOG_TAG "SDL_android" #define LOG_TAG "SDL_android"
/* #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) */ /* #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) */
/* #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) */ /* #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) */
#define LOGI(...) do {} while (false) #define LOGI(...) do {} while (0)
#define LOGE(...) do {} while (false) #define LOGE(...) do {} while (0)
/* Uncomment this to log messages entering and exiting methods in this file */ /* Uncomment this to log messages entering and exiting methods in this file */
/* #define DEBUG_JNI */ /* #define DEBUG_JNI */
@ -57,7 +57,6 @@ static void Android_JNI_ThreadDestroyed(void*);
*******************************************************************************/ *******************************************************************************/
#include <jni.h> #include <jni.h>
#include <android/log.h> #include <android/log.h>
#include <stdbool.h>
/******************************************************************************* /*******************************************************************************
@ -80,7 +79,7 @@ static jmethodID midPollInputDevices;
/* Accelerometer data storage */ /* Accelerometer data storage */
static float fLastAccelerometer[3]; static float fLastAccelerometer[3];
static bool bHasNewData; static SDL_bool bHasNewData;
/******************************************************************************* /*******************************************************************************
Functions called by JNI Functions called by JNI
@ -132,7 +131,7 @@ JNIEXPORT void JNICALL SDL_Android_Init(JNIEnv* mEnv, jclass cls)
midPollInputDevices = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, midPollInputDevices = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
"pollInputDevices", "()V"); "pollInputDevices", "()V");
bHasNewData = false; bHasNewData = SDL_FALSE;
if(!midGetNativeSurface || !midFlipBuffers || !midAudioInit || if(!midGetNativeSurface || !midFlipBuffers || !midAudioInit ||
!midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit || !midPollInputDevices) { !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit || !midPollInputDevices) {
@ -302,7 +301,7 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeAccel(
fLastAccelerometer[0] = x; fLastAccelerometer[0] = x;
fLastAccelerometer[1] = y; fLastAccelerometer[1] = y;
fLastAccelerometer[2] = z; fLastAccelerometer[2] = z;
bHasNewData = true; bHasNewData = SDL_TRUE;
} }
/* Low memory */ /* Low memory */
@ -487,7 +486,7 @@ SDL_bool Android_JNI_GetAccelerometerValues(float values[3])
for (i = 0; i < 3; ++i) { for (i = 0; i < 3; ++i) {
values[i] = fLastAccelerometer[i]; values[i] = fLastAccelerometer[i];
} }
bHasNewData = false; bHasNewData = SDL_FALSE;
retval = SDL_TRUE; retval = SDL_TRUE;
} }
@ -647,7 +646,7 @@ void Android_JNI_CloseAudioDevice()
/* Test for an exception and call SDL_SetError with its detail if one occurs */ /* Test for an exception and call SDL_SetError with its detail if one occurs */
/* If the parameter silent is truthy then SDL_SetError() will not be called. */ /* If the parameter silent is truthy then SDL_SetError() will not be called. */
static bool Android_JNI_ExceptionOccurred(bool silent) static SDL_bool Android_JNI_ExceptionOccurred(SDL_bool silent)
{ {
SDL_assert(LocalReferenceHolder_IsActive()); SDL_assert(LocalReferenceHolder_IsActive());
JNIEnv *mEnv = Android_JNI_GetEnv(); JNIEnv *mEnv = Android_JNI_GetEnv();
@ -681,10 +680,10 @@ static bool Android_JNI_ExceptionOccurred(bool silent)
(*mEnv)->ReleaseStringUTFChars(mEnv, exceptionName, exceptionNameUTF8); (*mEnv)->ReleaseStringUTFChars(mEnv, exceptionName, exceptionNameUTF8);
} }
return true; return SDL_TRUE;
} }
return false; return SDL_FALSE;
} }
static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx) static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
@ -728,19 +727,19 @@ static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
*/ */
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, assetManager), "openFd", "(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;"); mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, assetManager), "openFd", "(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;");
inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString); inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString);
if (Android_JNI_ExceptionOccurred(true)) { if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
goto fallback; goto fallback;
} }
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getStartOffset", "()J"); mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getStartOffset", "()J");
ctx->hidden.androidio.offset = (*mEnv)->CallLongMethod(mEnv, inputStream, mid); ctx->hidden.androidio.offset = (*mEnv)->CallLongMethod(mEnv, inputStream, mid);
if (Android_JNI_ExceptionOccurred(true)) { if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
goto fallback; goto fallback;
} }
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getDeclaredLength", "()J"); mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getDeclaredLength", "()J");
ctx->hidden.androidio.size = (*mEnv)->CallLongMethod(mEnv, inputStream, mid); ctx->hidden.androidio.size = (*mEnv)->CallLongMethod(mEnv, inputStream, mid);
if (Android_JNI_ExceptionOccurred(true)) { if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
goto fallback; goto fallback;
} }
@ -754,7 +753,7 @@ static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
/* Seek to the correct offset in the file. */ /* Seek to the correct offset in the file. */
lseek(ctx->hidden.androidio.fd, (off_t)ctx->hidden.androidio.offset, SEEK_SET); lseek(ctx->hidden.androidio.fd, (off_t)ctx->hidden.androidio.offset, SEEK_SET);
if (false) { if (0) {
fallback: fallback:
/* Disabled log message because of spam on the Nexus 7 */ /* Disabled log message because of spam on the Nexus 7 */
/* __android_log_print(ANDROID_LOG_DEBUG, "SDL", "Falling back to legacy InputStream method for opening file"); */ /* __android_log_print(ANDROID_LOG_DEBUG, "SDL", "Falling back to legacy InputStream method for opening file"); */
@ -766,13 +765,13 @@ fallback:
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, assetManager), mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, assetManager),
"open", "(Ljava/lang/String;I)Ljava/io/InputStream;"); "open", "(Ljava/lang/String;I)Ljava/io/InputStream;");
inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString, 1 /* ACCESS_RANDOM */); inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString, 1 /* ACCESS_RANDOM */);
if (Android_JNI_ExceptionOccurred(false)) { if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
// Try fallback to APK Extension files // Try fallback to APK Extension files
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, context), mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, context),
"openAPKExtensionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;"); "openAPKExtensionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
inputStream = (*mEnv)->CallObjectMethod(mEnv, context, mid, fileNameJString); inputStream = (*mEnv)->CallObjectMethod(mEnv, context, mid, fileNameJString);
if (Android_JNI_ExceptionOccurred(false)) { if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
goto failure; goto failure;
} }
} }
@ -790,7 +789,7 @@ fallback:
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream),
"available", "()I"); "available", "()I");
ctx->hidden.androidio.size = (long)(*mEnv)->CallIntMethod(mEnv, inputStream, mid); ctx->hidden.androidio.size = (long)(*mEnv)->CallIntMethod(mEnv, inputStream, mid);
if (Android_JNI_ExceptionOccurred(false)) { if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
goto failure; goto failure;
} }
@ -801,7 +800,7 @@ fallback:
"(Ljava/io/InputStream;)Ljava/nio/channels/ReadableByteChannel;"); "(Ljava/io/InputStream;)Ljava/nio/channels/ReadableByteChannel;");
readableByteChannel = (*mEnv)->CallStaticObjectMethod( readableByteChannel = (*mEnv)->CallStaticObjectMethod(
mEnv, channels, mid, inputStream); mEnv, channels, mid, inputStream);
if (Android_JNI_ExceptionOccurred(false)) { if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
goto failure; goto failure;
} }
@ -814,7 +813,7 @@ fallback:
ctx->hidden.androidio.readMethod = mid; ctx->hidden.androidio.readMethod = mid;
} }
if (false) { if (0) {
failure: failure:
result = -1; result = -1;
@ -907,7 +906,7 @@ size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
/* result = readableByteChannel.read(...); */ /* result = readableByteChannel.read(...); */
int result = (*mEnv)->CallIntMethod(mEnv, readableByteChannel, readMethod, byteBuffer); int result = (*mEnv)->CallIntMethod(mEnv, readableByteChannel, readMethod, byteBuffer);
if (Android_JNI_ExceptionOccurred(false)) { if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
LocalReferenceHolder_Cleanup(&refs); LocalReferenceHolder_Cleanup(&refs);
return 0; return 0;
} }
@ -932,7 +931,7 @@ size_t Android_JNI_FileWrite(SDL_RWops* ctx, const void* buffer,
return 0; return 0;
} }
static int Internal_Android_JNI_FileClose(SDL_RWops* ctx, bool release) static int Internal_Android_JNI_FileClose(SDL_RWops* ctx, SDL_bool release)
{ {
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__); struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
@ -955,7 +954,7 @@ static int Internal_Android_JNI_FileClose(SDL_RWops* ctx, bool release)
"close", "()V"); "close", "()V");
(*mEnv)->CallVoidMethod(mEnv, inputStream, mid); (*mEnv)->CallVoidMethod(mEnv, inputStream, mid);
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.assetFileDescriptorRef); (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.assetFileDescriptorRef);
if (Android_JNI_ExceptionOccurred(false)) { if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
result = -1; result = -1;
} }
} }
@ -968,7 +967,7 @@ static int Internal_Android_JNI_FileClose(SDL_RWops* ctx, bool release)
(*mEnv)->CallVoidMethod(mEnv, inputStream, mid); (*mEnv)->CallVoidMethod(mEnv, inputStream, mid);
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.inputStreamRef); (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.inputStreamRef);
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.readableByteChannelRef); (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.readableByteChannelRef);
if (Android_JNI_ExceptionOccurred(false)) { if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
result = -1; result = -1;
} }
} }
@ -1059,7 +1058,7 @@ Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence)
} else if (movement < 0) { } else if (movement < 0) {
/* We can't seek backwards so we have to reopen the file and seek */ /* We can't seek backwards so we have to reopen the file and seek */
/* forwards which obviously isn't very efficient */ /* forwards which obviously isn't very efficient */
Internal_Android_JNI_FileClose(ctx, false); Internal_Android_JNI_FileClose(ctx, SDL_FALSE);
Internal_Android_JNI_FileOpen(ctx); Internal_Android_JNI_FileOpen(ctx);
Android_JNI_FileSeek(ctx, newPosition, RW_SEEK_SET); Android_JNI_FileSeek(ctx, newPosition, RW_SEEK_SET);
} }
@ -1071,7 +1070,7 @@ Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence)
int Android_JNI_FileClose(SDL_RWops* ctx) int Android_JNI_FileClose(SDL_RWops* ctx)
{ {
return Internal_Android_JNI_FileClose(ctx, true); return Internal_Android_JNI_FileClose(ctx, SDL_TRUE);
} }
/* returns a new global reference which needs to be released later */ /* returns a new global reference which needs to be released later */