More Android cleanup:

* Formalized the interface with Java methods in SDL_android.h
* We don't need the feature system, at least right now
* Fixed waiting for the SDLMain thread
This commit is contained in:
Sam Lantinga 2011-01-12 17:53:06 -08:00
parent f9f37e83fe
commit 0fa1d9fe61
4 changed files with 99 additions and 150 deletions

View file

@ -21,6 +21,8 @@
*/
#include "SDL_config.h"
#include "SDL_android.h"
extern "C" {
#include "events/SDL_events_c.h"
#include "video/android/SDL_androidkeyboard.h"
@ -47,12 +49,8 @@ jclass mActivityInstance;
//method signatures
jmethodID midCreateGLContext;
jmethodID midFlipBuffers;
jmethodID midEnableFeature;
jmethodID midUpdateAudio;
//If we're not the active app, don't try to render
bool bRenderingEnabled = false;
//Feature IDs
static const int FEATURE_AUDIO = 1;
static const int FEATURE_ACCEL = 2;
@ -84,11 +82,9 @@ extern "C" void SDL_Android_Init(JNIEnv* env)
mActivityInstance = cls;
midCreateGLContext = mEnv->GetStaticMethodID(cls,"createGLContext","()V");
midFlipBuffers = mEnv->GetStaticMethodID(cls,"flipBuffers","()V");
midEnableFeature = mEnv->GetStaticMethodID(cls,"enableFeature","(II)V");
midUpdateAudio = mEnv->GetStaticMethodID(cls,"updateAudio","([B)V");
if(!midCreateGLContext || !midFlipBuffers || !midEnableFeature ||
!midUpdateAudio) {
if(!midCreateGLContext || !midFlipBuffers || !midUpdateAudio) {
__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Bad mids\n");
} else {
#ifdef DEBUG
@ -136,9 +132,6 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeTouch(JNIEnv* env,
extern "C" void Java_org_libsdl_app_SDLActivity_nativeQuit( JNIEnv* env,
jobject obj )
{
// Stop rendering as we're no longer in the foreground
bRenderingEnabled = false;
// Inject a SDL_QUIT event
SDL_SendQuit();
}
@ -165,32 +158,17 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel(
/*******************************************************************************
Functions called by SDL into Java
*******************************************************************************/
extern "C" void Android_CreateContext()
extern "C" void Android_JNI_CreateContext()
{
__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: sdl_create_context()\n");
bRenderingEnabled = true;
mEnv->CallStaticVoidMethod(mActivityInstance, midCreateGLContext );
mEnv->CallStaticVoidMethod(mActivityInstance, midCreateGLContext);
}
extern "C" void Android_Render()
extern "C" void Android_JNI_SwapWindow()
{
if (!bRenderingEnabled) {
return;
}
// When we get here, we've accumulated a full frame
mEnv->CallStaticVoidMethod(mActivityInstance, midFlipBuffers);
}
extern "C" void Android_EnableFeature(int featureid, bool enabled)
{
mEnv->CallStaticVoidMethod(mActivityInstance, midEnableFeature,
featureid, (int)enabled);
}
extern "C" void Android_UpdateAudioBuffer(unsigned char *buf, int len)
extern "C" void Android_JNI_UpdateAudioBuffer(unsigned char *buf, int len)
{
//Annoyingly we can't just call into Java from any thread. Because the audio
//callback is dispatched from the SDL audio thread (that wasn't made from

View file

@ -28,8 +28,7 @@
#include "SDL_audio.h"
#include "../SDL_audio_c.h"
#include "SDL_androidaudio.h"
extern void Android_UpdateAudioBuffer(unsigned char *buf, int len);
#include "../../SDL_android.h"
#include <android/log.h>
@ -94,7 +93,7 @@ AndroidAUD_GetDeviceBuf(_THIS)
// sound->len = this->hidden->mixlen; /* size of raw data pointed to above */
Android_UpdateAudioBuffer(this->hidden->mixbuf, this->hidden->mixlen);
Android_JNI_UpdateAudioBuffer(this->hidden->mixbuf, this->hidden->mixlen);
return this->hidden->mixbuf; /* is this right? */
}

View file

@ -26,57 +26,68 @@
#include "SDL_video.h"
#include "SDL_androidvideo.h"
#include "../../SDL_android.h"
#include <android/log.h>
#include <pthread.h>
/*
These things are in the JNI android support
*/
extern void Android_CreateContext();
extern void Android_Render();
/* GL functions */
int Android_GL_LoadLibrary(_THIS, const char *path){
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_LoadLibrary\n");
return 0;
int
Android_GL_LoadLibrary(_THIS, const char *path)
{
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_LoadLibrary\n");
return 0;
}
void *Android_GL_GetProcAddress(_THIS, const char *proc){
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_GetProcAddress\n");
return 0;
void *
Android_GL_GetProcAddress(_THIS, const char *proc)
{
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_GetProcAddress\n");
return 0;
}
void Android_GL_UnloadLibrary(_THIS){
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_UnloadLibrary\n");
void
Android_GL_UnloadLibrary(_THIS)
{
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_UnloadLibrary\n");
}
SDL_GLContext Android_GL_CreateContext(_THIS, SDL_Window * window){
Android_CreateContext();
return 1;
SDL_GLContext
Android_GL_CreateContext(_THIS, SDL_Window * window)
{
Android_JNI_CreateContext();
return 1;
}
int Android_GL_MakeCurrent(_THIS, SDL_Window * window,
SDL_GLContext context){
//__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_MakeCurrent\n");
return 0;
int
Android_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{
/* There's only one context, nothing to do... */
return 0;
}
int Android_GL_SetSwapInterval(_THIS, int interval){
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_SetSwapInterval\n");
return 0;
int
Android_GL_SetSwapInterval(_THIS, int interval)
{
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_SetSwapInterval\n");
return 0;
}
int Android_GL_GetSwapInterval(_THIS){
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_GetSwapInterval\n");
return 0;
int
Android_GL_GetSwapInterval(_THIS)
{
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_GetSwapInterval\n");
return 0;
}
void Android_GL_SwapWindow(_THIS, SDL_Window * window){
Android_Render();
void
Android_GL_SwapWindow(_THIS, SDL_Window * window)
{
Android_JNI_SwapWindow();
}
void Android_GL_DeleteContext(_THIS, SDL_GLContext context){
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_DeleteContext\n");
void
Android_GL_DeleteContext(_THIS, SDL_GLContext context)
{
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_DeleteContext\n");
}