Skip to content

Commit

Permalink
Fixed missing prototypes on Android, patch from Sylvain
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Dec 2, 2016
1 parent 84c0780 commit 26f05ec
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 60 deletions.
10 changes: 5 additions & 5 deletions include/SDL_system.h
Expand Up @@ -96,7 +96,7 @@ extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled);
This returns JNIEnv*, but the prototype is void* so we don't need jni.h
*/
extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv();
extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv(void);

/**
\brief Get the SDL Activity object for the application
Expand All @@ -106,7 +106,7 @@ extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv();
It is the caller's responsibility to properly release it
(using env->Push/PopLocalFrame or manually with env->DeleteLocalRef)
*/
extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity();
extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity(void);

/**
See the official Android developer guide for more information:
Expand All @@ -121,7 +121,7 @@ extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity();
This path is unique to your application and cannot be written to
by other applications.
*/
extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath();
extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath(void);

/**
\brief Get the current state of external storage, a bitmask of these values:
Expand All @@ -130,15 +130,15 @@ extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath();
If external storage is currently unavailable, this will return 0.
*/
extern DECLSPEC int SDLCALL SDL_AndroidGetExternalStorageState();
extern DECLSPEC int SDLCALL SDL_AndroidGetExternalStorageState(void);

/**
\brief Get the path used for external storage for this application.
This path is unique to your application, but is public and can be
written to by other applications.
*/
extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath();
extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath(void);

#endif /* __ANDROID__ */

Expand Down
4 changes: 4 additions & 0 deletions src/audio/android/SDL_androidaudio.c
Expand Up @@ -215,6 +215,10 @@ void ANDROIDAUDIO_ResumeDevices(void)
}
}

#else

void ANDROIDAUDIO_ResumeDevices(void) {}
void ANDROIDAUDIO_PauseDevices(void) {}

#endif /* SDL_AUDIO_DRIVER_ANDROID */

Expand Down
3 changes: 3 additions & 0 deletions src/audio/android/SDL_androidaudio.h
Expand Up @@ -34,6 +34,9 @@ struct SDL_PrivateAudioData
int resume;
};

void ANDROIDAUDIO_ResumeDevices(void);
void ANDROIDAUDIO_PauseDevices(void);

#endif /* _SDL_androidaudio_h */

/* vi: set ts=4 sw=4 expandtab: */
168 changes: 136 additions & 32 deletions src/core/android/SDL_android.c
Expand Up @@ -42,12 +42,110 @@
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
#define LOG_TAG "SDL_android"
/* #define LOG_TAG "SDL_android" */
/* #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 LOGI(...) do {} while (0)
#define LOGE(...) do {} while (0)


#define SDL_JAVA_PREFIX org_libsdl_app
#define CONCAT1(prefix, class, function) CONCAT2(prefix, class, function)
#define CONCAT2(prefix, class, function) Java_ ## prefix ## _ ## class ## _ ## function
#define SDL_JAVA_INTERFACE(function) CONCAT1(SDL_JAVA_PREFIX, SDLActivity, function)
#define SDL_JAVA_INTERFACE_INPUT_CONNECTION(function) CONCAT1(SDL_JAVA_PREFIX, SDLInputConnection, function)


/* Java class SDLActivity */
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)(
JNIEnv* env, jclass jcls,
jstring filename);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
JNIEnv* env, jclass jcls,
jint width, jint height, jint format, jfloat rate);

JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(onNativePadDown)(
JNIEnv* env, jclass jcls,
jint device_id, jint keycode);

JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(onNativePadUp)(
JNIEnv* env, jclass jcls,
jint device_id, jint keycode);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeJoy)(
JNIEnv* env, jclass jcls,
jint device_id, jint axis, jfloat value);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeHat)(
JNIEnv* env, jclass jcls,
jint device_id, jint hat_id, jint x, jint y);

JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeAddJoystick)(
JNIEnv* env, jclass jcls,
jint device_id, jstring device_name, jint is_accelerometer,
jint nbuttons, jint naxes, jint nhats, jint nballs);

JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeRemoveJoystick)(
JNIEnv* env, jclass jcls,
jint device_id);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(
JNIEnv* env, jclass jcls);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceDestroyed)(
JNIEnv* env, jclass jcls);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyDown)(
JNIEnv* env, jclass jcls,
jint keycode);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyUp)(
JNIEnv* env, jclass jcls,
jint keycode);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyboardFocusLost)(
JNIEnv* env, jclass jcls);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeTouch)(
JNIEnv* env, jclass jcls,
jint touch_device_id_in, jint pointer_finger_id_in,
jint action, jfloat x, jfloat y, jfloat p);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeMouse)(
JNIEnv* env, jclass jcls,
jint button, jint action, jfloat x, jfloat y);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeAccel)(
JNIEnv* env, jclass jcls,
jfloat x, jfloat y, jfloat z);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)(
JNIEnv* env, jclass cls);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
JNIEnv* env, jclass cls);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
JNIEnv* env, jclass cls);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeResume)(
JNIEnv* env, jclass cls);

JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetHint)(
JNIEnv* env, jclass cls,
jstring name);

/* Java class SDLInputConnection */
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeCommitText)(
JNIEnv* env, jclass cls,
jstring text, jint newCursorPosition);

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeSetComposingText)(
JNIEnv* env, jclass cls,
jstring text, jint newCursorPosition);


/* Uncomment this to log messages entering and exiting methods in this file */
/* #define DEBUG_JNI */

Expand Down Expand Up @@ -153,7 +251,7 @@ JNIEXPORT void JNICALL SDL_Android_Init(JNIEnv* mEnv, jclass cls)
}

/* Drop file */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeDropFile(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)(
JNIEnv* env, jclass jcls,
jstring filename)
{
Expand All @@ -164,50 +262,50 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeDropFile(
}

/* Resize */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeResize(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
JNIEnv* env, jclass jcls,
jint width, jint height, jint format, jfloat rate)
{
Android_SetScreenResolution(width, height, format, rate);
}

/* Paddown */
JNIEXPORT jint JNICALL Java_org_libsdl_app_SDLActivity_onNativePadDown(
JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(onNativePadDown)(
JNIEnv* env, jclass jcls,
jint device_id, jint keycode)
{
return Android_OnPadDown(device_id, keycode);
}

/* Padup */
JNIEXPORT jint JNICALL Java_org_libsdl_app_SDLActivity_onNativePadUp(
JNIEnv* env, jclass jcls,
jint device_id, jint keycode)
JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(onNativePadUp)(
JNIEnv* env, jclass jcls,
jint device_id, jint keycode)
{
return Android_OnPadUp(device_id, keycode);
}

/* Joy */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeJoy(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeJoy)(
JNIEnv* env, jclass jcls,
jint device_id, jint axis, jfloat value)
{
Android_OnJoy(device_id, axis, value);
}

/* POV Hat */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeHat(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeHat)(
JNIEnv* env, jclass jcls,
jint device_id, jint hat_id, jint x, jint y)
{
Android_OnHat(device_id, hat_id, x, y);
}


JNIEXPORT jint JNICALL Java_org_libsdl_app_SDLActivity_nativeAddJoystick(
JNIEnv* env, jclass jcls,
jint device_id, jstring device_name, jint is_accelerometer,
jint nbuttons, jint naxes, jint nhats, jint nballs)
JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeAddJoystick)(
JNIEnv* env, jclass jcls,
jint device_id, jstring device_name, jint is_accelerometer,
jint nbuttons, jint naxes, jint nhats, jint nballs)
{
int retval;
const char *name = (*env)->GetStringUTFChars(env, device_name, NULL);
Expand All @@ -219,15 +317,16 @@ JNIEXPORT jint JNICALL Java_org_libsdl_app_SDLActivity_nativeAddJoystick(
return retval;
}

JNIEXPORT jint JNICALL Java_org_libsdl_app_SDLActivity_nativeRemoveJoystick(
JNIEnv* env, jclass jcls, jint device_id)
JNIEXPORT jint JNICALL SDL_JAVA_INTERFACE(nativeRemoveJoystick)(
JNIEnv* env, jclass jcls,
jint device_id)
{
return Android_RemoveJoystick(device_id);
}


/* Surface Created */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeSurfaceChanged(JNIEnv* env, jclass jcls)
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv* env, jclass jcls)
{
SDL_WindowData *data;
SDL_VideoDevice *_this;
Expand All @@ -253,7 +352,7 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeSurfaceChanged(JN
}

/* Surface Destroyed */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeSurfaceDestroyed(JNIEnv* env, jclass jcls)
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceDestroyed)(JNIEnv* env, jclass jcls)
{
/* We have to clear the current context and destroy the egl surface here
* Otherwise there's BAD_NATIVE_WINDOW errors coming from eglCreateWindowSurface on resume
Expand All @@ -280,21 +379,23 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeSurfaceDestroyed(
}

/* Keydown */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeKeyDown(
JNIEnv* env, jclass jcls, jint keycode)
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyDown)(
JNIEnv* env, jclass jcls,
jint keycode)
{
Android_OnKeyDown(keycode);
}

/* Keyup */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeKeyUp(
JNIEnv* env, jclass jcls, jint keycode)
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyUp)(
JNIEnv* env, jclass jcls,
jint keycode)
{
Android_OnKeyUp(keycode);
}

/* Keyboard Focus Lost */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeKeyboardFocusLost(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyboardFocusLost)(
JNIEnv* env, jclass jcls)
{
/* Calling SDL_StopTextInput will take care of hiding the keyboard and cleaning up the DummyText widget */
Expand All @@ -303,7 +404,7 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeKeyboardFocusLost


/* Touch */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeTouch(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeTouch)(
JNIEnv* env, jclass jcls,
jint touch_device_id_in, jint pointer_finger_id_in,
jint action, jfloat x, jfloat y, jfloat p)
Expand All @@ -312,15 +413,15 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeTouch(
}

/* Mouse */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeMouse(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeMouse)(
JNIEnv* env, jclass jcls,
jint button, jint action, jfloat x, jfloat y)
{
Android_OnMouse(button, action, x, y);
}

/* Accelerometer */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeAccel(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeAccel)(
JNIEnv* env, jclass jcls,
jfloat x, jfloat y, jfloat z)
{
Expand All @@ -331,14 +432,14 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeAccel(
}

/* Low memory */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeLowMemory(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)(
JNIEnv* env, jclass cls)
{
SDL_SendAppEvent(SDL_APP_LOWMEMORY);
}

/* Quit */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeQuit(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
JNIEnv* env, jclass cls)
{
/* Discard previous events. The user should have handled state storage
Expand All @@ -354,7 +455,7 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeQuit(
}

/* Pause */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativePause(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
JNIEnv* env, jclass cls)
{
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativePause()");
Expand All @@ -371,7 +472,7 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativePause(
}

/* Resume */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeResume(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeResume)(
JNIEnv* env, jclass cls)
{
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeResume()");
Expand All @@ -389,7 +490,7 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeResume(
}
}

JNIEXPORT void JNICALL Java_org_libsdl_app_SDLInputConnection_nativeCommitText(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeCommitText)(
JNIEnv* env, jclass cls,
jstring text, jint newCursorPosition)
{
Expand All @@ -400,7 +501,7 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLInputConnection_nativeCommitText(
(*env)->ReleaseStringUTFChars(env, text, utftext);
}

JNIEXPORT void JNICALL Java_org_libsdl_app_SDLInputConnection_nativeSetComposingText(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeSetComposingText)(
JNIEnv* env, jclass cls,
jstring text, jint newCursorPosition)
{
Expand All @@ -411,7 +512,10 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLInputConnection_nativeSetComposing
(*env)->ReleaseStringUTFChars(env, text, utftext);
}

JNIEXPORT jstring JNICALL Java_org_libsdl_app_SDLActivity_nativeGetHint(JNIEnv* env, jclass cls, jstring name) {
JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetHint)(
JNIEnv* env, jclass cls,
jstring name)
{
const char *utfname = (*env)->GetStringUTFChars(env, name, NULL);
const char *hint = SDL_GetHint(utfname);

Expand Down

0 comments on commit 26f05ec

Please sign in to comment.