Mercurial > sdl-ios-xcode
annotate src/SDL_android.cpp @ 5037:c8f11c4ced7d
Raw input is no longer used. Yay!
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 19 Jan 2011 13:44:44 -0800 |
parents | 77df56570442 |
children |
rev | line source |
---|---|
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2010 Sam Lantinga |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
4989 | 24 #include "SDL_android.h" |
25 | |
4980
d9fdff945ec9
A bit of cleanup in the Android driver
Sam Lantinga <slouken@libsdl.org>
parents:
4964
diff
changeset
|
26 extern "C" { |
d9fdff945ec9
A bit of cleanup in the Android driver
Sam Lantinga <slouken@libsdl.org>
parents:
4964
diff
changeset
|
27 #include "events/SDL_events_c.h" |
d9fdff945ec9
A bit of cleanup in the Android driver
Sam Lantinga <slouken@libsdl.org>
parents:
4964
diff
changeset
|
28 #include "video/android/SDL_androidkeyboard.h" |
5001
77df56570442
Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents:
5000
diff
changeset
|
29 #include "video/android/SDL_androidtouch.h" |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
30 #include "video/android/SDL_androidvideo.h" |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
31 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
32 /* Impelemented in audio/android/SDL_androidaudio.c */ |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
33 extern void Android_RunAudioThread(); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
34 } // C |
4980
d9fdff945ec9
A bit of cleanup in the Android driver
Sam Lantinga <slouken@libsdl.org>
parents:
4964
diff
changeset
|
35 |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 /******************************************************************************* |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 This file links the Java side of Android with libsdl |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 *******************************************************************************/ |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 #include <jni.h> |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 #include <android/log.h> |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 /******************************************************************************* |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 Globals |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 *******************************************************************************/ |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
46 static JNIEnv* mEnv = NULL; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
47 static JNIEnv* mAudioEnv = NULL; |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
49 // Main activity |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
50 static jclass mActivityClass; |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
52 // method signatures |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
53 static jmethodID midCreateGLContext; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
54 static jmethodID midFlipBuffers; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
55 static jmethodID midAudioInit; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
56 static jmethodID midAudioWriteShortBuffer; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
57 static jmethodID midAudioWriteByteBuffer; |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
58 static jmethodID midAudioQuit; |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
60 // Accelerometer data storage |
5000
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
61 static float fLastAccelerometer[3]; |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 /******************************************************************************* |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 Functions called by JNI |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 *******************************************************************************/ |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 // Library init |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 { |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 return JNI_VERSION_1_4; |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 } |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 // Called before SDL_main() to initialize JNI bindings |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
75 extern "C" void SDL_Android_Init(JNIEnv* env, jclass cls) |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 { |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 __android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init()"); |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
79 mEnv = env; |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
80 mActivityClass = cls; |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
81 |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
82 midCreateGLContext = mEnv->GetStaticMethodID(mActivityClass, |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
83 "createGLContext","()V"); |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
84 midFlipBuffers = mEnv->GetStaticMethodID(mActivityClass, |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
85 "flipBuffers","()V"); |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
86 midAudioInit = mEnv->GetStaticMethodID(mActivityClass, |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
87 "audioInit", "(IZZI)Ljava/lang/Object;"); |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
88 midAudioWriteShortBuffer = mEnv->GetStaticMethodID(mActivityClass, |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
89 "audioWriteShortBuffer", "([S)V"); |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
90 midAudioWriteByteBuffer = mEnv->GetStaticMethodID(mActivityClass, |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
91 "audioWriteByteBuffer", "([B)V"); |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
92 midAudioQuit = mEnv->GetStaticMethodID(mActivityClass, |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
93 "audioQuit", "()V"); |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
95 if(!midCreateGLContext || !midFlipBuffers || !midAudioInit || |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
96 !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit) { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
97 __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly"); |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 } |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 } |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
101 // Resize |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
102 extern "C" void Java_org_libsdl_app_SDLActivity_onNativeResize( |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
103 JNIEnv* env, jclass jcls, |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
104 jint width, jint height, jint format) |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 { |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
106 Android_SetScreenResolution(width, height, format); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
107 } |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
108 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
109 // Keydown |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
110 extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyDown( |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
111 JNIEnv* env, jclass jcls, jint keycode) |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
112 { |
4980
d9fdff945ec9
A bit of cleanup in the Android driver
Sam Lantinga <slouken@libsdl.org>
parents:
4964
diff
changeset
|
113 Android_OnKeyDown(keycode); |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 } |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 // Keyup |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
117 extern "C" void Java_org_libsdl_app_SDLActivity_onNativeKeyUp( |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
118 JNIEnv* env, jclass jcls, jint keycode) |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 { |
4980
d9fdff945ec9
A bit of cleanup in the Android driver
Sam Lantinga <slouken@libsdl.org>
parents:
4964
diff
changeset
|
120 Android_OnKeyUp(keycode); |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 } |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 // Touch |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
124 extern "C" void Java_org_libsdl_app_SDLActivity_onNativeTouch( |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
125 JNIEnv* env, jclass jcls, |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
126 jint action, jfloat x, jfloat y, jfloat p) |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 { |
5001
77df56570442
Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents:
5000
diff
changeset
|
128 Android_OnTouch(action, x, y, p); |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 } |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
131 // Accelerometer |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel( |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
133 JNIEnv* env, jclass jcls, |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
134 jfloat x, jfloat y, jfloat z) |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 { |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 fLastAccelerometer[0] = x; |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 fLastAccelerometer[1] = y; |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 fLastAccelerometer[2] = z; |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 } |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
141 // Quit |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
142 extern "C" void Java_org_libsdl_app_SDLActivity_nativeQuit( |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
143 JNIEnv* env, jclass cls) |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
144 { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
145 // Inject a SDL_QUIT event |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
146 SDL_SendQuit(); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
147 } |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
148 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
149 extern "C" void Java_org_libsdl_app_SDLActivity_nativeRunAudioThread( |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
150 JNIEnv* env, jclass cls) |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
151 { |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
152 /* This is the audio thread, with a different environment */ |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
153 mAudioEnv = env; |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
154 |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
155 Android_RunAudioThread(); |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
156 } |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 /******************************************************************************* |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 Functions called by SDL into Java |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 *******************************************************************************/ |
4989 | 162 extern "C" void Android_JNI_CreateContext() |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 { |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
164 mEnv->CallStaticVoidMethod(mActivityClass, midCreateGLContext); |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 } |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 |
4989 | 167 extern "C" void Android_JNI_SwapWindow() |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 { |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
169 mEnv->CallStaticVoidMethod(mActivityClass, midFlipBuffers); |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
170 } |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
171 |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
172 extern "C" void Android_JNI_SetActivityTitle(const char *title) |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
173 { |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
174 jmethodID mid; |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
175 |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
176 mid = mEnv->GetStaticMethodID(mActivityClass,"setActivityTitle","(Ljava/lang/String;)V"); |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
177 if (mid) { |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
178 mEnv->CallStaticVoidMethod(mActivityClass, mid, mEnv->NewStringUTF(title)); |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
179 } |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 } |
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 |
5000
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
182 extern "C" void Android_JNI_GetAccelerometerValues(float values[3]) |
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
183 { |
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
184 int i; |
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
185 for (i = 0; i < 3; ++i) { |
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
186 values[i] = fLastAccelerometer[i]; |
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
187 } |
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
188 } |
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
189 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
190 // |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
191 // Audio support |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
192 // |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
193 static jboolean audioBuffer16Bit = JNI_FALSE; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
194 static jboolean audioBufferStereo = JNI_FALSE; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
195 static jobject audioBuffer = NULL; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
196 static void* audioBufferPinned = NULL; |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
197 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
198 extern "C" int Android_JNI_OpenAudioDevice(int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames) |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
199 { |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
200 int audioBufferFrames; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
201 |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
202 __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device"); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
203 audioBuffer16Bit = is16Bit; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
204 audioBufferStereo = channelCount > 1; |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
205 |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
206 audioBuffer = mEnv->CallStaticObjectMethod(mActivityClass, midAudioInit, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames); |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
207 |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
208 if (audioBuffer == NULL) { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
209 __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: didn't get back a good audio buffer!"); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
210 return 0; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
211 } |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
212 audioBuffer = mEnv->NewGlobalRef(audioBuffer); |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
213 |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
214 jboolean isCopy = JNI_FALSE; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
215 if (audioBuffer16Bit) { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
216 audioBufferPinned = mEnv->GetShortArrayElements((jshortArray)audioBuffer, &isCopy); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
217 audioBufferFrames = mEnv->GetArrayLength((jshortArray)audioBuffer); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
218 } else { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
219 audioBufferPinned = mEnv->GetByteArrayElements((jbyteArray)audioBuffer, &isCopy); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
220 audioBufferFrames = mEnv->GetArrayLength((jbyteArray)audioBuffer); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
221 } |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
222 if (audioBufferStereo) { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
223 audioBufferFrames /= 2; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
224 } |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
225 |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
226 return audioBufferFrames; |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
227 } |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
228 |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
229 extern "C" void * Android_JNI_GetAudioBuffer() |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 { |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
231 return audioBufferPinned; |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
232 } |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
234 extern "C" void Android_JNI_WriteAudioBuffer() |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
235 { |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
236 if (audioBuffer16Bit) { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
237 mAudioEnv->ReleaseShortArrayElements((jshortArray)audioBuffer, (jshort *)audioBufferPinned, JNI_COMMIT); |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
238 mAudioEnv->CallStaticVoidMethod(mActivityClass, midAudioWriteShortBuffer, (jshortArray)audioBuffer); |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
239 } else { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
240 mAudioEnv->ReleaseByteArrayElements((jbyteArray)audioBuffer, (jbyte *)audioBufferPinned, JNI_COMMIT); |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
241 mAudioEnv->CallStaticVoidMethod(mActivityClass, midAudioWriteByteBuffer, (jbyteArray)audioBuffer); |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
242 } |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
244 /* JNI_COMMIT means the changes are committed to the VM but the buffer remains pinned */ |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
245 } |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
246 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
247 extern "C" void Android_JNI_CloseAudioDevice() |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
248 { |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
249 mEnv->CallStaticVoidMethod(mActivityClass, midAudioQuit); |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 |
4997
a21501393bef
Removed code from GetPrimtiveArrayCritical() experiment
Sam Lantinga <slouken@libsdl.org>
parents:
4996
diff
changeset
|
251 if (audioBuffer) { |
a21501393bef
Removed code from GetPrimtiveArrayCritical() experiment
Sam Lantinga <slouken@libsdl.org>
parents:
4996
diff
changeset
|
252 mEnv->DeleteGlobalRef(audioBuffer); |
a21501393bef
Removed code from GetPrimtiveArrayCritical() experiment
Sam Lantinga <slouken@libsdl.org>
parents:
4996
diff
changeset
|
253 audioBuffer = NULL; |
a21501393bef
Removed code from GetPrimtiveArrayCritical() experiment
Sam Lantinga <slouken@libsdl.org>
parents:
4996
diff
changeset
|
254 audioBufferPinned = NULL; |
a21501393bef
Removed code from GetPrimtiveArrayCritical() experiment
Sam Lantinga <slouken@libsdl.org>
parents:
4996
diff
changeset
|
255 } |
4964
6c645018741e
Build the SDL library as a shared object on Android, so it will work correctly with SDL_image and SDL_ttf.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 } |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
257 |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
258 /* vi: set ts=4 sw=4 expandtab: */ |