Mercurial > sdl-ios-xcode
annotate src/core/android/SDL_android.cpp @ 5255:f908e06b3c96
Fixed compiling on Windows
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 11 Feb 2011 10:13:30 -0800 |
parents | c66b2a778b7e |
children | b530ef003506 |
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" |
5227
c66b2a778b7e
Try to create an OpenGL ES 2.0 context on Android and successfully fall back to OpenGL ES 1.1 if that fails.
Sam Lantinga <slouken@libsdl.org>
parents:
5094
diff
changeset
|
23 #include "SDL_stdinc.h" |
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
|
24 |
4989 | 25 #include "SDL_android.h" |
26 | |
4980
d9fdff945ec9
A bit of cleanup in the Android driver
Sam Lantinga <slouken@libsdl.org>
parents:
4964
diff
changeset
|
27 extern "C" { |
5094 | 28 #include "../../events/SDL_events_c.h" |
29 #include "../../video/android/SDL_androidkeyboard.h" | |
30 #include "../../video/android/SDL_androidtouch.h" | |
31 #include "../../video/android/SDL_androidvideo.h" | |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
32 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
33 /* Impelemented in audio/android/SDL_androidaudio.c */ |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
34 extern void Android_RunAudioThread(); |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
35 } // C |
4980
d9fdff945ec9
A bit of cleanup in the Android driver
Sam Lantinga <slouken@libsdl.org>
parents:
4964
diff
changeset
|
36 |
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
|
37 /******************************************************************************* |
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 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
|
39 *******************************************************************************/ |
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 <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
|
41 #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
|
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 /******************************************************************************* |
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 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
|
46 *******************************************************************************/ |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
47 static JNIEnv* mEnv = NULL; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
48 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
|
49 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
50 // 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
|
51 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
|
52 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
53 // method signatures |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
54 static jmethodID midCreateGLContext; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
55 static jmethodID midFlipBuffers; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
56 static jmethodID midAudioInit; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
57 static jmethodID midAudioWriteShortBuffer; |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
58 static jmethodID midAudioWriteByteBuffer; |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
59 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
|
60 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
61 // Accelerometer data storage |
5000
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
62 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
|
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 /******************************************************************************* |
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 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
|
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 |
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 // 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
|
70 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
|
71 { |
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 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
|
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 |
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
|
75 // 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
|
76 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
|
77 { |
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 __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
|
79 |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
80 mEnv = env; |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
81 mActivityClass = cls; |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
82 |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
83 midCreateGLContext = mEnv->GetStaticMethodID(mActivityClass, |
5227
c66b2a778b7e
Try to create an OpenGL ES 2.0 context on Android and successfully fall back to OpenGL ES 1.1 if that fails.
Sam Lantinga <slouken@libsdl.org>
parents:
5094
diff
changeset
|
84 "createGLContext","(II)Z"); |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
85 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
|
86 "flipBuffers","()V"); |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
87 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
|
88 "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
|
89 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
|
90 "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
|
91 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
|
92 "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
|
93 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
|
94 "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
|
95 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
96 if(!midCreateGLContext || !midFlipBuffers || !midAudioInit || |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
97 !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit) { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
98 __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
|
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 } |
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
|
101 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
102 // Resize |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
103 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
|
104 JNIEnv* env, jclass jcls, |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
105 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
|
106 { |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
107 Android_SetScreenResolution(width, height, format); |
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 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
110 // Keydown |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
111 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
|
112 JNIEnv* env, jclass jcls, jint keycode) |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
113 { |
4980
d9fdff945ec9
A bit of cleanup in the Android driver
Sam Lantinga <slouken@libsdl.org>
parents:
4964
diff
changeset
|
114 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
|
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 |
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
|
117 // Keyup |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
118 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
|
119 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
|
120 { |
4980
d9fdff945ec9
A bit of cleanup in the Android driver
Sam Lantinga <slouken@libsdl.org>
parents:
4964
diff
changeset
|
121 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
|
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 |
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
|
124 // Touch |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
125 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
|
126 JNIEnv* env, jclass jcls, |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
127 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
|
128 { |
5001
77df56570442
Added "mouse" support for the Android touch screen
Sam Lantinga <slouken@libsdl.org>
parents:
5000
diff
changeset
|
129 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
|
130 } |
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
|
131 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
132 // 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
|
133 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
|
134 JNIEnv* env, jclass jcls, |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
135 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
|
136 { |
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[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
|
138 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
|
139 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
|
140 } |
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
|
141 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
142 // Quit |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
143 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
|
144 JNIEnv* env, jclass cls) |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
145 { |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
146 // Inject a SDL_QUIT event |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
147 SDL_SendQuit(); |
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 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
150 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
|
151 JNIEnv* env, jclass cls) |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
152 { |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
153 /* 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
|
154 mAudioEnv = env; |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
155 |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
156 Android_RunAudioThread(); |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
157 } |
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
|
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 /******************************************************************************* |
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 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
|
162 *******************************************************************************/ |
5227
c66b2a778b7e
Try to create an OpenGL ES 2.0 context on Android and successfully fall back to OpenGL ES 1.1 if that fails.
Sam Lantinga <slouken@libsdl.org>
parents:
5094
diff
changeset
|
163 extern "C" SDL_bool Android_JNI_CreateContext(int majorVersion, int minorVersion) |
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
|
164 { |
5227
c66b2a778b7e
Try to create an OpenGL ES 2.0 context on Android and successfully fall back to OpenGL ES 1.1 if that fails.
Sam Lantinga <slouken@libsdl.org>
parents:
5094
diff
changeset
|
165 if (mEnv->CallStaticBooleanMethod(mActivityClass, midCreateGLContext, majorVersion, minorVersion)) { |
c66b2a778b7e
Try to create an OpenGL ES 2.0 context on Android and successfully fall back to OpenGL ES 1.1 if that fails.
Sam Lantinga <slouken@libsdl.org>
parents:
5094
diff
changeset
|
166 return SDL_TRUE; |
c66b2a778b7e
Try to create an OpenGL ES 2.0 context on Android and successfully fall back to OpenGL ES 1.1 if that fails.
Sam Lantinga <slouken@libsdl.org>
parents:
5094
diff
changeset
|
167 } else { |
c66b2a778b7e
Try to create an OpenGL ES 2.0 context on Android and successfully fall back to OpenGL ES 1.1 if that fails.
Sam Lantinga <slouken@libsdl.org>
parents:
5094
diff
changeset
|
168 return SDL_FALSE; |
c66b2a778b7e
Try to create an OpenGL ES 2.0 context on Android and successfully fall back to OpenGL ES 1.1 if that fails.
Sam Lantinga <slouken@libsdl.org>
parents:
5094
diff
changeset
|
169 } |
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
|
170 } |
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
|
171 |
4989 | 172 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
|
173 { |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
174 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
|
175 } |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
176 |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
177 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
|
178 { |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
179 jmethodID mid; |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
180 |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
181 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
|
182 if (mid) { |
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
183 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
|
184 } |
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
|
185 } |
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
|
186 |
5000
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
187 extern "C" void Android_JNI_GetAccelerometerValues(float values[3]) |
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 int i; |
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
190 for (i = 0; i < 3; ++i) { |
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
191 values[i] = fLastAccelerometer[i]; |
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
192 } |
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
193 } |
6a10693e66c3
Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents:
4998
diff
changeset
|
194 |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
195 // |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
196 // Audio support |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
197 // |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
198 static jboolean audioBuffer16Bit = JNI_FALSE; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
199 static jboolean audioBufferStereo = JNI_FALSE; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
200 static jobject audioBuffer = NULL; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
201 static void* audioBufferPinned = NULL; |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
202 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
203 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
|
204 { |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
205 int audioBufferFrames; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
206 |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
207 __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
|
208 audioBuffer16Bit = is16Bit; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
209 audioBufferStereo = channelCount > 1; |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
210 |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
211 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
|
212 |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
213 if (audioBuffer == NULL) { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
214 __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
|
215 return 0; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
216 } |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
217 audioBuffer = mEnv->NewGlobalRef(audioBuffer); |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
218 |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
219 jboolean isCopy = JNI_FALSE; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
220 if (audioBuffer16Bit) { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
221 audioBufferPinned = mEnv->GetShortArrayElements((jshortArray)audioBuffer, &isCopy); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
222 audioBufferFrames = mEnv->GetArrayLength((jshortArray)audioBuffer); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
223 } else { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
224 audioBufferPinned = mEnv->GetByteArrayElements((jbyteArray)audioBuffer, &isCopy); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
225 audioBufferFrames = mEnv->GetArrayLength((jbyteArray)audioBuffer); |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
226 } |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
227 if (audioBufferStereo) { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
228 audioBufferFrames /= 2; |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
229 } |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
230 |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
231 return audioBufferFrames; |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
232 } |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
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_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
|
235 { |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
236 return audioBufferPinned; |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
237 } |
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
|
238 |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
239 extern "C" void Android_JNI_WriteAudioBuffer() |
4995
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
240 { |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
241 if (audioBuffer16Bit) { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
242 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
|
243 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
|
244 } else { |
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
245 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
|
246 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
|
247 } |
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
|
248 |
4996
8d7315668e35
Fixed audio buffer lifecycle and implemented audio shutdown
Sam Lantinga <slouken@libsdl.org>
parents:
4995
diff
changeset
|
249 /* 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
|
250 } |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
251 |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
252 extern "C" void Android_JNI_CloseAudioDevice() |
9f9bea41e88f
Working audio implementation contributed by Joseph Lunderville
Sam Lantinga <slouken@libsdl.org>
parents:
4989
diff
changeset
|
253 { |
4998
a514bfe6952a
The window is changed to reflect the actual screen dimensions, for now.
Sam Lantinga <slouken@libsdl.org>
parents:
4997
diff
changeset
|
254 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
|
255 |
4997
a21501393bef
Removed code from GetPrimtiveArrayCritical() experiment
Sam Lantinga <slouken@libsdl.org>
parents:
4996
diff
changeset
|
256 if (audioBuffer) { |
a21501393bef
Removed code from GetPrimtiveArrayCritical() experiment
Sam Lantinga <slouken@libsdl.org>
parents:
4996
diff
changeset
|
257 mEnv->DeleteGlobalRef(audioBuffer); |
a21501393bef
Removed code from GetPrimtiveArrayCritical() experiment
Sam Lantinga <slouken@libsdl.org>
parents:
4996
diff
changeset
|
258 audioBuffer = NULL; |
a21501393bef
Removed code from GetPrimtiveArrayCritical() experiment
Sam Lantinga <slouken@libsdl.org>
parents:
4996
diff
changeset
|
259 audioBufferPinned = NULL; |
a21501393bef
Removed code from GetPrimtiveArrayCritical() experiment
Sam Lantinga <slouken@libsdl.org>
parents:
4996
diff
changeset
|
260 } |
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
|
261 } |
4981
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
262 |
55b82067815b
Fill in the video mode with the correct screen format
Sam Lantinga <slouken@libsdl.org>
parents:
4980
diff
changeset
|
263 /* vi: set ts=4 sw=4 expandtab: */ |