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:
parent
f9f37e83fe
commit
0fa1d9fe61
4 changed files with 99 additions and 150 deletions
|
@ -30,14 +30,6 @@ public class SDLActivity extends Activity {
|
||||||
|
|
||||||
// Audio
|
// Audio
|
||||||
private static AudioTrack mAudioTrack;
|
private static AudioTrack mAudioTrack;
|
||||||
private static boolean bAudioIsEnabled;
|
|
||||||
|
|
||||||
// Sensors
|
|
||||||
private static boolean bAccelIsEnabled;
|
|
||||||
|
|
||||||
// feature IDs. Must match up on the C side as well.
|
|
||||||
private static int FEATURE_AUDIO = 1;
|
|
||||||
private static int FEATURE_ACCEL = 2;
|
|
||||||
|
|
||||||
// Load the .so
|
// Load the .so
|
||||||
static {
|
static {
|
||||||
|
@ -47,6 +39,7 @@ public class SDLActivity extends Activity {
|
||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
//Log.v("SDL", "onCreate()");
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// So we can call stuff from static callbacks
|
// So we can call stuff from static callbacks
|
||||||
|
@ -57,44 +50,16 @@ public class SDLActivity extends Activity {
|
||||||
setContentView(mSurface);
|
setContentView(mSurface);
|
||||||
SurfaceHolder holder = mSurface.getHolder();
|
SurfaceHolder holder = mSurface.getHolder();
|
||||||
holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
|
holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Audio
|
|
||||||
public static boolean initAudio(){
|
|
||||||
|
|
||||||
// blah. Hardcoded things are bad. FIXME when we have more sound stuff
|
|
||||||
// working properly.
|
|
||||||
mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
|
|
||||||
11025,
|
|
||||||
AudioFormat.CHANNEL_CONFIGURATION_MONO,
|
|
||||||
AudioFormat.ENCODING_PCM_8BIT,
|
|
||||||
2048,
|
|
||||||
AudioTrack.MODE_STREAM);
|
|
||||||
bAudioIsEnabled = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Accel
|
|
||||||
public static boolean initAccel(){
|
|
||||||
mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
|
|
||||||
bAccelIsEnabled = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean closeAccel(){
|
|
||||||
mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, false);
|
|
||||||
bAccelIsEnabled = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
|
//Log.v("SDL", "onPause()");
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
|
//Log.v("SDL", "onResume()");
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +87,14 @@ public class SDLActivity extends Activity {
|
||||||
public static void updateAudio(byte [] buf) {
|
public static void updateAudio(byte [] buf) {
|
||||||
|
|
||||||
if(mAudioTrack == null) {
|
if(mAudioTrack == null) {
|
||||||
return;
|
// Hardcoded things are bad. FIXME when we have more sound stuff
|
||||||
|
// working properly.
|
||||||
|
mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
|
||||||
|
11025,
|
||||||
|
AudioFormat.CHANNEL_CONFIGURATION_MONO,
|
||||||
|
AudioFormat.ENCODING_PCM_8BIT,
|
||||||
|
2048,
|
||||||
|
AudioTrack.MODE_STREAM);
|
||||||
}
|
}
|
||||||
|
|
||||||
mAudioTrack.write(buf, 0, buf.length);
|
mAudioTrack.write(buf, 0, buf.length);
|
||||||
|
@ -131,29 +103,6 @@ public class SDLActivity extends Activity {
|
||||||
Log.v("SDL", "Played some audio");
|
Log.v("SDL", "Played some audio");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void enableFeature(int featureid, int enabled) {
|
|
||||||
Log.v("SDL","Feature " + featureid + " = " + enabled);
|
|
||||||
|
|
||||||
// Yuck. This is all horribly inelegent. If it gets to more than a few
|
|
||||||
// 'features' I'll rip this out and make something nicer, I promise :)
|
|
||||||
if(featureid == FEATURE_AUDIO){
|
|
||||||
if(enabled == 1){
|
|
||||||
initAudio();
|
|
||||||
}else{
|
|
||||||
// We don't have one of these yet...
|
|
||||||
//closeAudio();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(featureid == FEATURE_ACCEL){
|
|
||||||
if(enabled == 1){
|
|
||||||
initAccel();
|
|
||||||
}else{
|
|
||||||
closeAccel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -164,7 +113,7 @@ class SDLMain implements Runnable {
|
||||||
// Runs SDL_main()
|
// Runs SDL_main()
|
||||||
SDLActivity.nativeInit();
|
SDLActivity.nativeInit();
|
||||||
|
|
||||||
Log.v("SDL","SDL thread terminated");
|
//Log.v("SDL", "SDL thread terminated");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,28 +154,39 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
||||||
|
|
||||||
// Called when we have a valid drawing surface
|
// Called when we have a valid drawing surface
|
||||||
public void surfaceCreated(SurfaceHolder holder) {
|
public void surfaceCreated(SurfaceHolder holder) {
|
||||||
|
//Log.v("SDL", "surfaceCreated()");
|
||||||
|
|
||||||
|
enableSensor(Sensor.TYPE_ACCELEROMETER, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when we lose the surface
|
// Called when we lose the surface
|
||||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||||
|
//Log.v("SDL", "surfaceDestroyed()");
|
||||||
|
|
||||||
// Send a quit message to the application
|
// Send a quit message to the application
|
||||||
SDLActivity.nativeQuit();
|
SDLActivity.nativeQuit();
|
||||||
|
|
||||||
// Now wait for the SDL thread to quit
|
// Now wait for the SDL thread to quit
|
||||||
if (mSDLThread != null) {
|
if (mSDLThread != null) {
|
||||||
|
//synchronized (mSDLThread) {
|
||||||
try {
|
try {
|
||||||
mSDLThread.wait();
|
mSDLThread.join();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
Log.v("SDL", "Problem stopping thread: " + e);
|
Log.v("SDL", "Problem stopping thread: " + e);
|
||||||
}
|
}
|
||||||
|
//}
|
||||||
|
mSDLThread = null;
|
||||||
|
|
||||||
|
//Log.v("SDL", "Finished waiting for SDL thread");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enableSensor(Sensor.TYPE_ACCELEROMETER, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the surface is resized
|
// Called when the surface is resized
|
||||||
public void surfaceChanged(SurfaceHolder holder,
|
public void surfaceChanged(SurfaceHolder holder,
|
||||||
int format, int width, int height) {
|
int format, int width, int height) {
|
||||||
Log.v("SDL","Surface resized");
|
//Log.v("SDL", "surfaceChanged()");
|
||||||
|
|
||||||
int sdlFormat = 0;
|
int sdlFormat = 0;
|
||||||
switch (format) {
|
switch (format) {
|
||||||
|
@ -328,7 +288,6 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
||||||
public void flipEGL() {
|
public void flipEGL() {
|
||||||
try {
|
try {
|
||||||
EGL10 egl = (EGL10)EGLContext.getEGL();
|
EGL10 egl = (EGL10)EGLContext.getEGL();
|
||||||
GL10 gl = (GL10)mEGLContext.getGL();
|
|
||||||
|
|
||||||
egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null);
|
egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null);
|
||||||
|
|
||||||
|
@ -351,10 +310,12 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
||||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||||
|
|
||||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||||
|
//Log.v("SDL", "key down: " + keyCode);
|
||||||
SDLActivity.onNativeKeyDown(keyCode);
|
SDLActivity.onNativeKeyDown(keyCode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (event.getAction() == KeyEvent.ACTION_UP) {
|
else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||||
|
//Log.v("SDL", "key up: " + keyCode);
|
||||||
SDLActivity.onNativeKeyUp(keyCode);
|
SDLActivity.onNativeKeyUp(keyCode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
*/
|
*/
|
||||||
#include "SDL_config.h"
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#include "SDL_android.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "events/SDL_events_c.h"
|
#include "events/SDL_events_c.h"
|
||||||
#include "video/android/SDL_androidkeyboard.h"
|
#include "video/android/SDL_androidkeyboard.h"
|
||||||
|
@ -47,12 +49,8 @@ jclass mActivityInstance;
|
||||||
//method signatures
|
//method signatures
|
||||||
jmethodID midCreateGLContext;
|
jmethodID midCreateGLContext;
|
||||||
jmethodID midFlipBuffers;
|
jmethodID midFlipBuffers;
|
||||||
jmethodID midEnableFeature;
|
|
||||||
jmethodID midUpdateAudio;
|
jmethodID midUpdateAudio;
|
||||||
|
|
||||||
//If we're not the active app, don't try to render
|
|
||||||
bool bRenderingEnabled = false;
|
|
||||||
|
|
||||||
//Feature IDs
|
//Feature IDs
|
||||||
static const int FEATURE_AUDIO = 1;
|
static const int FEATURE_AUDIO = 1;
|
||||||
static const int FEATURE_ACCEL = 2;
|
static const int FEATURE_ACCEL = 2;
|
||||||
|
@ -84,11 +82,9 @@ extern "C" void SDL_Android_Init(JNIEnv* env)
|
||||||
mActivityInstance = cls;
|
mActivityInstance = cls;
|
||||||
midCreateGLContext = mEnv->GetStaticMethodID(cls,"createGLContext","()V");
|
midCreateGLContext = mEnv->GetStaticMethodID(cls,"createGLContext","()V");
|
||||||
midFlipBuffers = mEnv->GetStaticMethodID(cls,"flipBuffers","()V");
|
midFlipBuffers = mEnv->GetStaticMethodID(cls,"flipBuffers","()V");
|
||||||
midEnableFeature = mEnv->GetStaticMethodID(cls,"enableFeature","(II)V");
|
|
||||||
midUpdateAudio = mEnv->GetStaticMethodID(cls,"updateAudio","([B)V");
|
midUpdateAudio = mEnv->GetStaticMethodID(cls,"updateAudio","([B)V");
|
||||||
|
|
||||||
if(!midCreateGLContext || !midFlipBuffers || !midEnableFeature ||
|
if(!midCreateGLContext || !midFlipBuffers || !midUpdateAudio) {
|
||||||
!midUpdateAudio) {
|
|
||||||
__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Bad mids\n");
|
__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Bad mids\n");
|
||||||
} else {
|
} else {
|
||||||
#ifdef DEBUG
|
#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,
|
extern "C" void Java_org_libsdl_app_SDLActivity_nativeQuit( JNIEnv* env,
|
||||||
jobject obj )
|
jobject obj )
|
||||||
{
|
{
|
||||||
// Stop rendering as we're no longer in the foreground
|
|
||||||
bRenderingEnabled = false;
|
|
||||||
|
|
||||||
// Inject a SDL_QUIT event
|
// Inject a SDL_QUIT event
|
||||||
SDL_SendQuit();
|
SDL_SendQuit();
|
||||||
}
|
}
|
||||||
|
@ -165,32 +158,17 @@ extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel(
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
Functions called by SDL into Java
|
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);
|
mEnv->CallStaticVoidMethod(mActivityInstance, midFlipBuffers);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void Android_EnableFeature(int featureid, bool enabled)
|
extern "C" void Android_JNI_UpdateAudioBuffer(unsigned char *buf, int len)
|
||||||
{
|
|
||||||
mEnv->CallStaticVoidMethod(mActivityInstance, midEnableFeature,
|
|
||||||
featureid, (int)enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void Android_UpdateAudioBuffer(unsigned char *buf, int len)
|
|
||||||
{
|
{
|
||||||
//Annoyingly we can't just call into Java from any thread. Because the audio
|
//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
|
//callback is dispatched from the SDL audio thread (that wasn't made from
|
||||||
|
|
|
@ -28,8 +28,7 @@
|
||||||
#include "SDL_audio.h"
|
#include "SDL_audio.h"
|
||||||
#include "../SDL_audio_c.h"
|
#include "../SDL_audio_c.h"
|
||||||
#include "SDL_androidaudio.h"
|
#include "SDL_androidaudio.h"
|
||||||
|
#include "../../SDL_android.h"
|
||||||
extern void Android_UpdateAudioBuffer(unsigned char *buf, int len);
|
|
||||||
|
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
|
||||||
|
@ -94,7 +93,7 @@ AndroidAUD_GetDeviceBuf(_THIS)
|
||||||
// sound->len = this->hidden->mixlen; /* size of raw data pointed to above */
|
// 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? */
|
return this->hidden->mixbuf; /* is this right? */
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,57 +26,68 @@
|
||||||
#include "SDL_video.h"
|
#include "SDL_video.h"
|
||||||
|
|
||||||
#include "SDL_androidvideo.h"
|
#include "SDL_androidvideo.h"
|
||||||
|
#include "../../SDL_android.h"
|
||||||
|
|
||||||
#include <android/log.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 */
|
/* GL functions */
|
||||||
int Android_GL_LoadLibrary(_THIS, const char *path){
|
int
|
||||||
|
Android_GL_LoadLibrary(_THIS, const char *path)
|
||||||
|
{
|
||||||
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_LoadLibrary\n");
|
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_LoadLibrary\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *Android_GL_GetProcAddress(_THIS, const char *proc){
|
void *
|
||||||
|
Android_GL_GetProcAddress(_THIS, const char *proc)
|
||||||
|
{
|
||||||
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_GetProcAddress\n");
|
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_GetProcAddress\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Android_GL_UnloadLibrary(_THIS){
|
void
|
||||||
|
Android_GL_UnloadLibrary(_THIS)
|
||||||
|
{
|
||||||
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_UnloadLibrary\n");
|
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_UnloadLibrary\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GLContext Android_GL_CreateContext(_THIS, SDL_Window * window){
|
SDL_GLContext
|
||||||
Android_CreateContext();
|
Android_GL_CreateContext(_THIS, SDL_Window * window)
|
||||||
|
{
|
||||||
|
Android_JNI_CreateContext();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Android_GL_MakeCurrent(_THIS, SDL_Window * window,
|
int
|
||||||
SDL_GLContext context){
|
Android_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
|
||||||
//__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_MakeCurrent\n");
|
{
|
||||||
|
/* There's only one context, nothing to do... */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Android_GL_SetSwapInterval(_THIS, int interval){
|
int
|
||||||
|
Android_GL_SetSwapInterval(_THIS, int interval)
|
||||||
|
{
|
||||||
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_SetSwapInterval\n");
|
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_SetSwapInterval\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Android_GL_GetSwapInterval(_THIS){
|
int
|
||||||
|
Android_GL_GetSwapInterval(_THIS)
|
||||||
|
{
|
||||||
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_GetSwapInterval\n");
|
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_GetSwapInterval\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Android_GL_SwapWindow(_THIS, SDL_Window * window){
|
void
|
||||||
Android_Render();
|
Android_GL_SwapWindow(_THIS, SDL_Window * window)
|
||||||
|
{
|
||||||
|
Android_JNI_SwapWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Android_GL_DeleteContext(_THIS, SDL_GLContext context){
|
void
|
||||||
|
Android_GL_DeleteContext(_THIS, SDL_GLContext context)
|
||||||
|
{
|
||||||
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_DeleteContext\n");
|
__android_log_print(ANDROID_LOG_INFO, "SDL", "[STUB] GL_DeleteContext\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue