The window is changed to reflect the actual screen dimensions, for now.
Implemented SDL_SetWindowTitle(), which turned out to be fairly complex
1.1 --- a/android-project/src/org/libsdl/app/SDLActivity.java Thu Jan 13 12:36:59 2011 -0800
1.2 +++ b/android-project/src/org/libsdl/app/SDLActivity.java Thu Jan 13 15:10:17 2011 -0800
1.3 @@ -67,6 +67,25 @@
1.4 super.onResume();
1.5 }
1.6
1.7 + // Messages from the SDLMain thread
1.8 + static int COMMAND_CHANGE_TITLE = 1;
1.9 +
1.10 + // Handler for the messages
1.11 + Handler commandHandler = new Handler() {
1.12 + public void handleMessage(Message msg) {
1.13 + if (msg.arg1 == COMMAND_CHANGE_TITLE) {
1.14 + setTitle((String)msg.obj);
1.15 + }
1.16 + }
1.17 + };
1.18 +
1.19 + // Send a message from the SDLMain thread
1.20 + void sendCommand(int command, Object data) {
1.21 + Message msg = commandHandler.obtainMessage();
1.22 + msg.arg1 = command;
1.23 + msg.obj = data;
1.24 + commandHandler.sendMessage(msg);
1.25 + }
1.26
1.27 // C functions we call
1.28 public static native void nativeInit();
1.29 @@ -81,7 +100,8 @@
1.30
1.31
1.32 // Java functions called from C
1.33 - private static void createGLContext() {
1.34 +
1.35 + public static void createGLContext() {
1.36 mSurface.initEGL();
1.37 }
1.38
1.39 @@ -89,6 +109,11 @@
1.40 mSurface.flipEGL();
1.41 }
1.42
1.43 + public static void setActivityTitle(String title) {
1.44 + // Called from SDLMain() thread and can't directly affect the view
1.45 + mSingleton.sendCommand(COMMAND_CHANGE_TITLE, title);
1.46 + }
1.47 +
1.48 // Audio
1.49 private static Object buf;
1.50
1.51 @@ -177,7 +202,7 @@
1.52 }
1.53 mAudioThread = null;
1.54
1.55 - Log.v("SDL", "Finished waiting for audio thread");
1.56 + //Log.v("SDL", "Finished waiting for audio thread");
1.57 }
1.58
1.59 if (mAudioTrack != null) {
2.1 --- a/src/SDL_android.cpp Thu Jan 13 12:36:59 2011 -0800
2.2 +++ b/src/SDL_android.cpp Thu Jan 13 15:10:17 2011 -0800
2.3 @@ -42,12 +42,11 @@
2.4 /*******************************************************************************
2.5 Globals
2.6 *******************************************************************************/
2.7 -static JavaVM* mVM = NULL;
2.8 static JNIEnv* mEnv = NULL;
2.9 static JNIEnv* mAudioEnv = NULL;
2.10
2.11 // Main activity
2.12 -static jclass mActivityInstance;
2.13 +static jclass mActivityClass;
2.14
2.15 // method signatures
2.16 static jmethodID midCreateGLContext;
2.17 @@ -68,26 +67,29 @@
2.18 // Library init
2.19 extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
2.20 {
2.21 - mVM = vm;
2.22 -
2.23 return JNI_VERSION_1_4;
2.24 }
2.25
2.26 // Called before SDL_main() to initialize JNI bindings
2.27 -extern "C" void SDL_Android_Init(JNIEnv* env)
2.28 +extern "C" void SDL_Android_Init(JNIEnv* env, jclass cls)
2.29 {
2.30 - mEnv = env;
2.31 -
2.32 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init()");
2.33
2.34 - jclass cls = mEnv->FindClass ("org/libsdl/app/SDLActivity");
2.35 - mActivityInstance = cls;
2.36 - midCreateGLContext = mEnv->GetStaticMethodID(cls,"createGLContext","()V");
2.37 - midFlipBuffers = mEnv->GetStaticMethodID(cls,"flipBuffers","()V");
2.38 - midAudioInit = mEnv->GetStaticMethodID(cls, "audioInit", "(IZZI)Ljava/lang/Object;");
2.39 - midAudioWriteShortBuffer = mEnv->GetStaticMethodID(cls, "audioWriteShortBuffer", "([S)V");
2.40 - midAudioWriteByteBuffer = mEnv->GetStaticMethodID(cls, "audioWriteByteBuffer", "([B)V");
2.41 - midAudioQuit = mEnv->GetStaticMethodID(cls, "audioQuit", "()V");
2.42 + mEnv = env;
2.43 + mActivityClass = cls;
2.44 +
2.45 + midCreateGLContext = mEnv->GetStaticMethodID(mActivityClass,
2.46 + "createGLContext","()V");
2.47 + midFlipBuffers = mEnv->GetStaticMethodID(mActivityClass,
2.48 + "flipBuffers","()V");
2.49 + midAudioInit = mEnv->GetStaticMethodID(mActivityClass,
2.50 + "audioInit", "(IZZI)Ljava/lang/Object;");
2.51 + midAudioWriteShortBuffer = mEnv->GetStaticMethodID(mActivityClass,
2.52 + "audioWriteShortBuffer", "([S)V");
2.53 + midAudioWriteByteBuffer = mEnv->GetStaticMethodID(mActivityClass,
2.54 + "audioWriteByteBuffer", "([B)V");
2.55 + midAudioQuit = mEnv->GetStaticMethodID(mActivityClass,
2.56 + "audioQuit", "()V");
2.57
2.58 if(!midCreateGLContext || !midFlipBuffers || !midAudioInit ||
2.59 !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit) {
2.60 @@ -97,7 +99,7 @@
2.61
2.62 // Resize
2.63 extern "C" void Java_org_libsdl_app_SDLActivity_onNativeResize(
2.64 - JNIEnv* env, jobject obj,
2.65 + JNIEnv* env, jclass jcls,
2.66 jint width, jint height, jint format)
2.67 {
2.68 Android_SetScreenResolution(width, height, format);
2.69 @@ -105,21 +107,21 @@
2.70
2.71 // Keydown
2.72 extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyDown(
2.73 - JNIEnv* env, jobject obj, jint keycode)
2.74 + JNIEnv* env, jclass jcls, jint keycode)
2.75 {
2.76 Android_OnKeyDown(keycode);
2.77 }
2.78
2.79 // Keyup
2.80 extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyUp(
2.81 - JNIEnv* env, jobject obj, jint keycode)
2.82 + JNIEnv* env, jclass jcls, jint keycode)
2.83 {
2.84 Android_OnKeyUp(keycode);
2.85 }
2.86
2.87 // Touch
2.88 extern "C" void Java_org_libsdl_app_SDLActivity_onNativeTouch(
2.89 - JNIEnv* env, jobject obj,
2.90 + JNIEnv* env, jclass jcls,
2.91 jint action, jfloat x, jfloat y, jfloat p)
2.92 {
2.93 #ifdef DEBUG
2.94 @@ -133,7 +135,7 @@
2.95
2.96 // Accelerometer
2.97 extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel(
2.98 - JNIEnv* env, jobject obj,
2.99 + JNIEnv* env, jclass jcls,
2.100 jfloat x, jfloat y, jfloat z)
2.101 {
2.102 fLastAccelerometer[0] = x;
2.103 @@ -143,16 +145,18 @@
2.104
2.105 // Quit
2.106 extern "C" void Java_org_libsdl_app_SDLActivity_nativeQuit(
2.107 - JNIEnv* env, jobject obj)
2.108 + JNIEnv* env, jclass cls)
2.109 {
2.110 // Inject a SDL_QUIT event
2.111 SDL_SendQuit();
2.112 }
2.113
2.114 extern "C" void Java_org_libsdl_app_SDLActivity_nativeRunAudioThread(
2.115 - JNIEnv* env)
2.116 + JNIEnv* env, jclass cls)
2.117 {
2.118 - mVM->AttachCurrentThread(&mAudioEnv, NULL);
2.119 + /* This is the audio thread, with a different environment */
2.120 + mAudioEnv = env;
2.121 +
2.122 Android_RunAudioThread();
2.123 }
2.124
2.125 @@ -162,12 +166,22 @@
2.126 *******************************************************************************/
2.127 extern "C" void Android_JNI_CreateContext()
2.128 {
2.129 - mEnv->CallStaticVoidMethod(mActivityInstance, midCreateGLContext);
2.130 + mEnv->CallStaticVoidMethod(mActivityClass, midCreateGLContext);
2.131 }
2.132
2.133 extern "C" void Android_JNI_SwapWindow()
2.134 {
2.135 - mEnv->CallStaticVoidMethod(mActivityInstance, midFlipBuffers);
2.136 + mEnv->CallStaticVoidMethod(mActivityClass, midFlipBuffers);
2.137 +}
2.138 +
2.139 +extern "C" void Android_JNI_SetActivityTitle(const char *title)
2.140 +{
2.141 + jmethodID mid;
2.142 +
2.143 + mid = mEnv->GetStaticMethodID(mActivityClass,"setActivityTitle","(Ljava/lang/String;)V");
2.144 + if (mid) {
2.145 + mEnv->CallStaticVoidMethod(mActivityClass, mid, mEnv->NewStringUTF(title));
2.146 + }
2.147 }
2.148
2.149 //
2.150 @@ -186,7 +200,7 @@
2.151 audioBuffer16Bit = is16Bit;
2.152 audioBufferStereo = channelCount > 1;
2.153
2.154 - audioBuffer = mEnv->CallStaticObjectMethod(mActivityInstance, midAudioInit, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames);
2.155 + audioBuffer = mEnv->CallStaticObjectMethod(mActivityClass, midAudioInit, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames);
2.156
2.157 if (audioBuffer == NULL) {
2.158 __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: didn't get back a good audio buffer!");
2.159 @@ -218,10 +232,10 @@
2.160 {
2.161 if (audioBuffer16Bit) {
2.162 mAudioEnv->ReleaseShortArrayElements((jshortArray)audioBuffer, (jshort *)audioBufferPinned, JNI_COMMIT);
2.163 - mAudioEnv->CallStaticVoidMethod(mActivityInstance, midAudioWriteShortBuffer, (jshortArray)audioBuffer);
2.164 + mAudioEnv->CallStaticVoidMethod(mActivityClass, midAudioWriteShortBuffer, (jshortArray)audioBuffer);
2.165 } else {
2.166 mAudioEnv->ReleaseByteArrayElements((jbyteArray)audioBuffer, (jbyte *)audioBufferPinned, JNI_COMMIT);
2.167 - mAudioEnv->CallStaticVoidMethod(mActivityInstance, midAudioWriteByteBuffer, (jbyteArray)audioBuffer);
2.168 + mAudioEnv->CallStaticVoidMethod(mActivityClass, midAudioWriteByteBuffer, (jbyteArray)audioBuffer);
2.169 }
2.170
2.171 /* JNI_COMMIT means the changes are committed to the VM but the buffer remains pinned */
2.172 @@ -229,7 +243,7 @@
2.173
2.174 extern "C" void Android_JNI_CloseAudioDevice()
2.175 {
2.176 - mEnv->CallStaticVoidMethod(mActivityInstance, midAudioQuit);
2.177 + mEnv->CallStaticVoidMethod(mActivityClass, midAudioQuit);
2.178
2.179 if (audioBuffer) {
2.180 mEnv->DeleteGlobalRef(audioBuffer);
3.1 --- a/src/SDL_android.h Thu Jan 13 12:36:59 2011 -0800
3.2 +++ b/src/SDL_android.h Thu Jan 13 15:10:17 2011 -0800
3.3 @@ -31,6 +31,7 @@
3.4 /* Interface from the SDL library into the Android Java activity */
3.5 void Android_JNI_CreateContext();
3.6 void Android_JNI_SwapWindow();
3.7 +void Android_JNI_SetActivityTitle(const char *title);
3.8
3.9 // Audio support
3.10 int Android_JNI_OpenAudioDevice(int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames);
4.1 --- a/src/main/android/SDL_android_main.cpp Thu Jan 13 12:36:59 2011 -0800
4.2 +++ b/src/main/android/SDL_android_main.cpp Thu Jan 13 15:10:17 2011 -0800
4.3 @@ -8,7 +8,7 @@
4.4 #include <jni.h>
4.5
4.6 // Called before SDL_main() to initialize JNI bindings in SDL library
4.7 -extern "C" void SDL_Android_Init(JNIEnv* env);
4.8 +extern "C" void SDL_Android_Init(JNIEnv* env, jclass cls);
4.9
4.10 // Library init
4.11 extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
4.12 @@ -17,10 +17,10 @@
4.13 }
4.14
4.15 // Start up the SDL app
4.16 -extern "C" void Java_org_libsdl_app_SDLActivity_nativeInit( JNIEnv* env, jobject obj )
4.17 +extern "C" void Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobject obj)
4.18 {
4.19 /* This interface could expand with ABI negotiation, calbacks, etc. */
4.20 - SDL_Android_Init(env);
4.21 + SDL_Android_Init(env, cls);
4.22
4.23 /* Run the application code! */
4.24 char *argv[2];
5.1 --- a/src/video/android/SDL_androidvideo.c Thu Jan 13 12:36:59 2011 -0800
5.2 +++ b/src/video/android/SDL_androidvideo.c Thu Jan 13 15:10:17 2011 -0800
5.3 @@ -33,6 +33,7 @@
5.4 #include "SDL_androidvideo.h"
5.5 #include "SDL_androidevents.h"
5.6 #include "SDL_androidkeyboard.h"
5.7 +#include "SDL_androidwindow.h"
5.8
5.9 #define ANDROID_VID_DRIVER_NAME "Android"
5.10
5.11 @@ -58,9 +59,9 @@
5.12
5.13 // These are filled in with real values in Android_SetScreenResolution on
5.14 // init (before SDL_main())
5.15 -static Uint32 iScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
5.16 -static int iScreenWidth = 0;
5.17 -static int iScreenHeight = 0;
5.18 +int Android_ScreenWidth = 0;
5.19 +int Android_ScreenHeight = 0;
5.20 +Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
5.21
5.22
5.23 static int
5.24 @@ -96,6 +97,10 @@
5.25 device->VideoQuit = Android_VideoQuit;
5.26 device->PumpEvents = Android_PumpEvents;
5.27
5.28 + device->CreateWindow = Android_CreateWindow;
5.29 + device->SetWindowTitle = Android_SetWindowTitle;
5.30 + device->DestroyWindow = Android_DestroyWindow;
5.31 +
5.32 device->free = Android_DeleteDevice;
5.33
5.34 /* GL pointers */
5.35 @@ -123,9 +128,9 @@
5.36 {
5.37 SDL_DisplayMode mode;
5.38
5.39 - mode.format = iScreenFormat;
5.40 - mode.w = iScreenWidth;
5.41 - mode.h = iScreenHeight;
5.42 + mode.format = Android_ScreenFormat;
5.43 + mode.w = Android_ScreenWidth;
5.44 + mode.h = Android_ScreenHeight;
5.45 mode.refresh_rate = 0;
5.46 mode.driverdata = NULL;
5.47 if (SDL_AddBasicVideoDisplay(&mode) < 0) {
5.48 @@ -146,12 +151,13 @@
5.49 {
5.50 }
5.51
5.52 +/* This function gets called before VideoInit() */
5.53 void
5.54 Android_SetScreenResolution(int width, int height, Uint32 format)
5.55 {
5.56 - iScreenWidth = width;
5.57 - iScreenHeight = height;
5.58 - iScreenFormat = format;
5.59 + Android_ScreenWidth = width;
5.60 + Android_ScreenHeight = height;
5.61 + Android_ScreenFormat = format;
5.62 }
5.63
5.64 /* vi: set ts=4 sw=4 expandtab: */
6.1 --- a/src/video/android/SDL_androidvideo.h Thu Jan 13 12:36:59 2011 -0800
6.2 +++ b/src/video/android/SDL_androidvideo.h Thu Jan 13 15:10:17 2011 -0800
6.3 @@ -29,6 +29,12 @@
6.4 /* Called by the JNI layer when the screen changes size or format */
6.5 extern void Android_SetScreenResolution(int width, int height, Uint32 format);
6.6
6.7 +/* Private display data */
6.8 +
6.9 +extern int Android_ScreenWidth;
6.10 +extern int Android_ScreenHeight;
6.11 +extern Uint32 Android_ScreenFormat;
6.12 +
6.13 #endif /* _SDL_androidvideo_h */
6.14
6.15 /* vi: set ts=4 sw=4 expandtab: */
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/src/video/android/SDL_androidwindow.c Thu Jan 13 15:10:17 2011 -0800
7.3 @@ -0,0 +1,52 @@
7.4 +/*
7.5 + SDL - Simple DirectMedia Layer
7.6 + Copyright (C) 1997-2010 Sam Lantinga
7.7 +
7.8 + This library is free software; you can redistribute it and/or
7.9 + modify it under the terms of the GNU Lesser General Public
7.10 + License as published by the Free Software Foundation; either
7.11 + version 2.1 of the License, or (at your option) any later version.
7.12 +
7.13 + This library is distributed in the hope that it will be useful,
7.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
7.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7.16 + Lesser General Public License for more details.
7.17 +
7.18 + You should have received a copy of the GNU Lesser General Public
7.19 + License along with this library; if not, write to the Free Software
7.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7.21 +
7.22 + Sam Lantinga
7.23 + slouken@libsdl.org
7.24 +*/
7.25 +#include "SDL_config.h"
7.26 +
7.27 +#include "../SDL_sysvideo.h"
7.28 +
7.29 +#include "SDL_androidvideo.h"
7.30 +#include "SDL_androidwindow.h"
7.31 +
7.32 +int
7.33 +Android_CreateWindow(_THIS, SDL_Window * window)
7.34 +{
7.35 + /* Adjust the window data to match the screen */
7.36 + window->x = 0;
7.37 + window->y = 0;
7.38 + window->w = Android_ScreenWidth;
7.39 + window->h = Android_ScreenHeight;
7.40 +
7.41 + return 0;
7.42 +}
7.43 +
7.44 +void
7.45 +Android_SetWindowTitle(_THIS, SDL_Window * window)
7.46 +{
7.47 + Android_JNI_SetActivityTitle(window->title);
7.48 +}
7.49 +
7.50 +void
7.51 +Android_DestroyWindow(_THIS, SDL_Window * window)
7.52 +{
7.53 +}
7.54 +
7.55 +/* vi: set ts=4 sw=4 expandtab: */
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/src/video/android/SDL_androidwindow.h Thu Jan 13 15:10:17 2011 -0800
8.3 @@ -0,0 +1,33 @@
8.4 +/*
8.5 + SDL - Simple DirectMedia Layer
8.6 + Copyright (C) 1997-2010 Sam Lantinga
8.7 +
8.8 + This library is free software; you can redistribute it and/or
8.9 + modify it under the terms of the GNU Lesser General Public
8.10 + License as published by the Free Software Foundation; either
8.11 + version 2.1 of the License, or (at your option) any later version.
8.12 +
8.13 + This library is distributed in the hope that it will be useful,
8.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
8.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8.16 + Lesser General Public License for more details.
8.17 +
8.18 + You should have received a copy of the GNU Lesser General Public
8.19 + License along with this library; if not, write to the Free Software
8.20 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
8.21 +
8.22 + Sam Lantinga
8.23 + slouken@libsdl.org
8.24 +*/
8.25 +#include "SDL_config.h"
8.26 +
8.27 +#ifndef _SDL_androidwindow_h
8.28 +#define _SDL_androidwindow_h
8.29 +
8.30 +extern int Android_CreateWindow(_THIS, SDL_Window * window);
8.31 +extern void Android_SetWindowTitle(_THIS, SDL_Window * window);
8.32 +extern void Android_DestroyWindow(_THIS, SDL_Window * window);
8.33 +
8.34 +#endif /* _SDL_androidwindow_h */
8.35 +
8.36 +/* vi: set ts=4 sw=4 expandtab: */