author | koda |
Tue, 21 Jan 2014 22:43:06 +0100 | |
changeset 10017 | de822cd3df3a |
parent 7185 | 92a045156255 |
permissions | -rw-r--r-- |
5337 | 1 |
/* |
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
2 |
Simple DirectMedia Layer |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
3 |
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org> |
5337 | 4 |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
5 |
This software is provided 'as-is', without any express or implied |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
6 |
warranty. In no event will the authors be held liable for any damages |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
7 |
arising from the use of this software. |
5337 | 8 |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
9 |
Permission is granted to anyone to use this software for any purpose, |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
10 |
including commercial applications, and to alter it and redistribute it |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
11 |
freely, subject to the following restrictions: |
5337 | 12 |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
13 |
1. The origin of this software must not be misrepresented; you must not |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
14 |
claim that you wrote the original software. If you use this software |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
15 |
in a product, an acknowledgment in the product documentation would be |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
16 |
appreciated but is not required. |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
17 |
2. Altered source versions must be plainly marked as such, and must not be |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
18 |
misrepresented as being the original software. |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
19 |
3. This notice may not be removed or altered from any source distribution. |
5337 | 20 |
*/ |
21 |
#include "SDL_config.h" |
|
22 |
#include "SDL_stdinc.h" |
|
23 |
||
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
24 |
#ifdef __ANDROID__ |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
25 |
|
5337 | 26 |
#include "SDL_android.h" |
27 |
||
28 |
extern "C" { |
|
29 |
#include "../../events/SDL_events_c.h" |
|
30 |
#include "../../video/android/SDL_androidkeyboard.h" |
|
31 |
#include "../../video/android/SDL_androidtouch.h" |
|
32 |
#include "../../video/android/SDL_androidvideo.h" |
|
33 |
||
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
34 |
#include <android/log.h> |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
35 |
#define LOG_TAG "SDL_android" |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
36 |
//#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
37 |
//#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
38 |
#define LOGI(...) do {} while (false) |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
39 |
#define LOGE(...) do {} while (false) |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
40 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
41 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
42 |
/* Implemented in audio/android/SDL_androidaudio.c */ |
5337 | 43 |
extern void Android_RunAudioThread(); |
44 |
} // C |
|
45 |
||
46 |
/******************************************************************************* |
|
47 |
This file links the Java side of Android with libsdl |
|
48 |
*******************************************************************************/ |
|
49 |
#include <jni.h> |
|
50 |
#include <android/log.h> |
|
51 |
||
52 |
||
53 |
/******************************************************************************* |
|
54 |
Globals |
|
55 |
*******************************************************************************/ |
|
56 |
static JNIEnv* mEnv = NULL; |
|
57 |
static JNIEnv* mAudioEnv = NULL; |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
58 |
static JavaVM* mJavaVM; |
5337 | 59 |
|
60 |
// Main activity |
|
61 |
static jclass mActivityClass; |
|
62 |
||
63 |
// method signatures |
|
64 |
static jmethodID midCreateGLContext; |
|
65 |
static jmethodID midFlipBuffers; |
|
66 |
static jmethodID midAudioInit; |
|
67 |
static jmethodID midAudioWriteShortBuffer; |
|
68 |
static jmethodID midAudioWriteByteBuffer; |
|
69 |
static jmethodID midAudioQuit; |
|
70 |
||
71 |
// Accelerometer data storage |
|
72 |
static float fLastAccelerometer[3]; |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
73 |
static bool bHasNewData; |
5337 | 74 |
|
75 |
/******************************************************************************* |
|
76 |
Functions called by JNI |
|
77 |
*******************************************************************************/ |
|
78 |
||
79 |
// Library init |
|
80 |
extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) |
|
81 |
{ |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
82 |
JNIEnv *env; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
83 |
mJavaVM = vm; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
84 |
LOGI("JNI_OnLoad called"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
85 |
if (mJavaVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
86 |
LOGE("Failed to get the environment using GetEnv()"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
87 |
return -1; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
88 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
89 |
|
5337 | 90 |
return JNI_VERSION_1_4; |
91 |
} |
|
92 |
||
93 |
// Called before SDL_main() to initialize JNI bindings |
|
94 |
extern "C" void SDL_Android_Init(JNIEnv* env, jclass cls) |
|
95 |
{ |
|
96 |
__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init()"); |
|
97 |
||
98 |
mEnv = env; |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
99 |
mActivityClass = (jclass)env->NewGlobalRef(cls); |
5337 | 100 |
|
101 |
midCreateGLContext = mEnv->GetStaticMethodID(mActivityClass, |
|
102 |
"createGLContext","(II)Z"); |
|
103 |
midFlipBuffers = mEnv->GetStaticMethodID(mActivityClass, |
|
104 |
"flipBuffers","()V"); |
|
10017 | 105 |
midAudioInit = mEnv->GetStaticMethodID(mActivityClass, |
5337 | 106 |
"audioInit", "(IZZI)Ljava/lang/Object;"); |
107 |
midAudioWriteShortBuffer = mEnv->GetStaticMethodID(mActivityClass, |
|
108 |
"audioWriteShortBuffer", "([S)V"); |
|
109 |
midAudioWriteByteBuffer = mEnv->GetStaticMethodID(mActivityClass, |
|
110 |
"audioWriteByteBuffer", "([B)V"); |
|
111 |
midAudioQuit = mEnv->GetStaticMethodID(mActivityClass, |
|
112 |
"audioQuit", "()V"); |
|
113 |
||
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
114 |
bHasNewData = false; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
115 |
|
5337 | 116 |
if(!midCreateGLContext || !midFlipBuffers || !midAudioInit || |
117 |
!midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit) { |
|
118 |
__android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly"); |
|
119 |
} |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
120 |
__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL_Android_Init() finished!"); |
5337 | 121 |
} |
122 |
||
123 |
// Resize |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
5540
diff
changeset
|
124 |
extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_onNativeResize( |
5337 | 125 |
JNIEnv* env, jclass jcls, |
126 |
jint width, jint height, jint format) |
|
127 |
{ |
|
128 |
Android_SetScreenResolution(width, height, format); |
|
129 |
} |
|
130 |
||
131 |
// Keydown |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
5540
diff
changeset
|
132 |
extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_onNativeKeyDown( |
5337 | 133 |
JNIEnv* env, jclass jcls, jint keycode) |
134 |
{ |
|
135 |
Android_OnKeyDown(keycode); |
|
136 |
} |
|
137 |
||
138 |
// Keyup |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
5540
diff
changeset
|
139 |
extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_onNativeKeyUp( |
5337 | 140 |
JNIEnv* env, jclass jcls, jint keycode) |
141 |
{ |
|
142 |
Android_OnKeyUp(keycode); |
|
143 |
} |
|
144 |
||
145 |
// Touch |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
5540
diff
changeset
|
146 |
extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_onNativeTouch( |
5337 | 147 |
JNIEnv* env, jclass jcls, |
6328 | 148 |
jint touch_device_id_in, jint pointer_finger_id_in, |
149 |
jint action, jfloat x, jfloat y, jfloat p) |
|
5337 | 150 |
{ |
6328 | 151 |
Android_OnTouch(touch_device_id_in, pointer_finger_id_in, action, x, y, p); |
5337 | 152 |
} |
153 |
||
154 |
// Accelerometer |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
5540
diff
changeset
|
155 |
extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_onNativeAccel( |
5337 | 156 |
JNIEnv* env, jclass jcls, |
157 |
jfloat x, jfloat y, jfloat z) |
|
158 |
{ |
|
159 |
fLastAccelerometer[0] = x; |
|
160 |
fLastAccelerometer[1] = y; |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
161 |
fLastAccelerometer[2] = z; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
162 |
bHasNewData = true; |
5337 | 163 |
} |
164 |
||
165 |
// Quit |
|
6047
10011f051f9c
Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
5540
diff
changeset
|
166 |
extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_nativeQuit( |
5337 | 167 |
JNIEnv* env, jclass cls) |
10017 | 168 |
{ |
5337 | 169 |
// Inject a SDL_QUIT event |
170 |
SDL_SendQuit(); |
|
171 |
} |
|
172 |
||
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
173 |
// Pause |
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6592
diff
changeset
|
174 |
extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_nativePause( |
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
175 |
JNIEnv* env, jclass cls) |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
176 |
{ |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
177 |
if (Android_Window) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
178 |
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
179 |
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
180 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
181 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
182 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
183 |
// Resume |
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6592
diff
changeset
|
184 |
extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_nativeResume( |
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
185 |
JNIEnv* env, jclass cls) |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
186 |
{ |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
187 |
if (Android_Window) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
188 |
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
189 |
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESTORED, 0, 0); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
190 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
191 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
192 |
|
6597
814683bbd230
added TARDIS to minimal data dir, changed a couple of org_libsdl_app to org_hedgewars_hedgeroid in SDL_android.cpp and updated SDLActivity.java
Xeli
parents:
6592
diff
changeset
|
193 |
extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_nativeRunAudioThread( |
5337 | 194 |
JNIEnv* env, jclass cls) |
195 |
{ |
|
196 |
/* This is the audio thread, with a different environment */ |
|
197 |
mAudioEnv = env; |
|
198 |
||
199 |
Android_RunAudioThread(); |
|
200 |
} |
|
201 |
||
202 |
||
203 |
/******************************************************************************* |
|
204 |
Functions called by SDL into Java |
|
205 |
*******************************************************************************/ |
|
206 |
extern "C" SDL_bool Android_JNI_CreateContext(int majorVersion, int minorVersion) |
|
207 |
{ |
|
208 |
if (mEnv->CallStaticBooleanMethod(mActivityClass, midCreateGLContext, majorVersion, minorVersion)) { |
|
209 |
return SDL_TRUE; |
|
210 |
} else { |
|
211 |
return SDL_FALSE; |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
extern "C" void Android_JNI_SwapWindow() |
|
216 |
{ |
|
10017 | 217 |
mEnv->CallStaticVoidMethod(mActivityClass, midFlipBuffers); |
5337 | 218 |
} |
219 |
||
220 |
extern "C" void Android_JNI_SetActivityTitle(const char *title) |
|
221 |
{ |
|
222 |
jmethodID mid; |
|
223 |
||
224 |
mid = mEnv->GetStaticMethodID(mActivityClass,"setActivityTitle","(Ljava/lang/String;)V"); |
|
225 |
if (mid) { |
|
226 |
mEnv->CallStaticVoidMethod(mActivityClass, mid, mEnv->NewStringUTF(title)); |
|
227 |
} |
|
228 |
} |
|
229 |
||
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
230 |
extern "C" SDL_bool Android_JNI_GetAccelerometerValues(float values[3]) |
5337 | 231 |
{ |
232 |
int i; |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
233 |
SDL_bool retval = SDL_FALSE; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
234 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
235 |
if (bHasNewData) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
236 |
for (i = 0; i < 3; ++i) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
237 |
values[i] = fLastAccelerometer[i]; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
238 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
239 |
bHasNewData = false; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
240 |
retval = SDL_TRUE; |
5337 | 241 |
} |
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
242 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
243 |
return retval; |
5337 | 244 |
} |
245 |
||
246 |
// |
|
247 |
// Audio support |
|
248 |
// |
|
249 |
static jboolean audioBuffer16Bit = JNI_FALSE; |
|
250 |
static jboolean audioBufferStereo = JNI_FALSE; |
|
251 |
static jobject audioBuffer = NULL; |
|
252 |
static void* audioBufferPinned = NULL; |
|
253 |
||
254 |
extern "C" int Android_JNI_OpenAudioDevice(int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames) |
|
255 |
{ |
|
256 |
int audioBufferFrames; |
|
257 |
||
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
258 |
int status; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
259 |
JNIEnv *env; |
10017 | 260 |
static bool isAttached = false; |
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
261 |
status = mJavaVM->GetEnv((void **) &env, JNI_VERSION_1_4); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
262 |
if(status < 0) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
263 |
LOGE("callback_handler: failed to get JNI environment, assuming native thread"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
264 |
status = mJavaVM->AttachCurrentThread(&env, NULL); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
265 |
if(status < 0) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
266 |
LOGE("callback_handler: failed to attach current thread"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
267 |
return 0; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
268 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
269 |
isAttached = true; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
270 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
271 |
|
10017 | 272 |
|
5337 | 273 |
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device"); |
274 |
audioBuffer16Bit = is16Bit; |
|
275 |
audioBufferStereo = channelCount > 1; |
|
276 |
||
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
277 |
audioBuffer = env->CallStaticObjectMethod(mActivityClass, midAudioInit, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames); |
5337 | 278 |
|
279 |
if (audioBuffer == NULL) { |
|
280 |
__android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: didn't get back a good audio buffer!"); |
|
281 |
return 0; |
|
282 |
} |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
283 |
audioBuffer = env->NewGlobalRef(audioBuffer); |
5337 | 284 |
|
285 |
jboolean isCopy = JNI_FALSE; |
|
286 |
if (audioBuffer16Bit) { |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
287 |
audioBufferPinned = env->GetShortArrayElements((jshortArray)audioBuffer, &isCopy); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
288 |
audioBufferFrames = env->GetArrayLength((jshortArray)audioBuffer); |
5337 | 289 |
} else { |
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
290 |
audioBufferPinned = env->GetByteArrayElements((jbyteArray)audioBuffer, &isCopy); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
291 |
audioBufferFrames = env->GetArrayLength((jbyteArray)audioBuffer); |
5337 | 292 |
} |
293 |
if (audioBufferStereo) { |
|
294 |
audioBufferFrames /= 2; |
|
295 |
} |
|
10017 | 296 |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
297 |
if (isAttached) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
298 |
mJavaVM->DetachCurrentThread(); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
299 |
} |
5337 | 300 |
|
301 |
return audioBufferFrames; |
|
302 |
} |
|
303 |
||
304 |
extern "C" void * Android_JNI_GetAudioBuffer() |
|
305 |
{ |
|
306 |
return audioBufferPinned; |
|
307 |
} |
|
308 |
||
309 |
extern "C" void Android_JNI_WriteAudioBuffer() |
|
310 |
{ |
|
311 |
if (audioBuffer16Bit) { |
|
312 |
mAudioEnv->ReleaseShortArrayElements((jshortArray)audioBuffer, (jshort *)audioBufferPinned, JNI_COMMIT); |
|
313 |
mAudioEnv->CallStaticVoidMethod(mActivityClass, midAudioWriteShortBuffer, (jshortArray)audioBuffer); |
|
314 |
} else { |
|
315 |
mAudioEnv->ReleaseByteArrayElements((jbyteArray)audioBuffer, (jbyte *)audioBufferPinned, JNI_COMMIT); |
|
316 |
mAudioEnv->CallStaticVoidMethod(mActivityClass, midAudioWriteByteBuffer, (jbyteArray)audioBuffer); |
|
317 |
} |
|
318 |
||
319 |
/* JNI_COMMIT means the changes are committed to the VM but the buffer remains pinned */ |
|
320 |
} |
|
321 |
||
322 |
extern "C" void Android_JNI_CloseAudioDevice() |
|
323 |
{ |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
324 |
int status; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
325 |
JNIEnv *env; |
10017 | 326 |
static bool isAttached = false; |
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
327 |
status = mJavaVM->GetEnv((void **) &env, JNI_VERSION_1_4); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
328 |
if(status < 0) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
329 |
LOGE("callback_handler: failed to get JNI environment, assuming native thread"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
330 |
status = mJavaVM->AttachCurrentThread(&env, NULL); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
331 |
if(status < 0) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
332 |
LOGE("callback_handler: failed to attach current thread"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
333 |
return; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
334 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
335 |
isAttached = true; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
336 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
337 |
|
10017 | 338 |
env->CallStaticVoidMethod(mActivityClass, midAudioQuit); |
5337 | 339 |
|
340 |
if (audioBuffer) { |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
341 |
env->DeleteGlobalRef(audioBuffer); |
5337 | 342 |
audioBuffer = NULL; |
343 |
audioBufferPinned = NULL; |
|
344 |
} |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
345 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
346 |
if (isAttached) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
347 |
mJavaVM->DetachCurrentThread(); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
348 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
349 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
350 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
351 |
// Test for an exception and call SDL_SetError with its detail if one occurs |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
352 |
static bool Android_JNI_ExceptionOccurred() |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
353 |
{ |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
354 |
jthrowable exception = mEnv->ExceptionOccurred(); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
355 |
if (exception != NULL) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
356 |
jmethodID mid; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
357 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
358 |
// Until this happens most JNI operations have undefined behaviour |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
359 |
mEnv->ExceptionClear(); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
360 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
361 |
jclass exceptionClass = mEnv->GetObjectClass(exception); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
362 |
jclass classClass = mEnv->FindClass("java/lang/Class"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
363 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
364 |
mid = mEnv->GetMethodID(classClass, "getName", "()Ljava/lang/String;"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
365 |
jstring exceptionName = (jstring)mEnv->CallObjectMethod(exceptionClass, mid); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
366 |
const char* exceptionNameUTF8 = mEnv->GetStringUTFChars(exceptionName, 0); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
367 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
368 |
mid = mEnv->GetMethodID(exceptionClass, "getMessage", "()Ljava/lang/String;"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
369 |
jstring exceptionMessage = (jstring)mEnv->CallObjectMethod(exception, mid); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
370 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
371 |
if (exceptionMessage != NULL) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
372 |
const char* exceptionMessageUTF8 = mEnv->GetStringUTFChars( |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
373 |
exceptionMessage, 0); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
374 |
SDL_SetError("%s: %s", exceptionNameUTF8, exceptionMessageUTF8); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
375 |
mEnv->ReleaseStringUTFChars(exceptionMessage, exceptionMessageUTF8); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
376 |
mEnv->DeleteLocalRef(exceptionMessage); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
377 |
} else { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
378 |
SDL_SetError("%s", exceptionNameUTF8); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
379 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
380 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
381 |
mEnv->ReleaseStringUTFChars(exceptionName, exceptionNameUTF8); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
382 |
mEnv->DeleteLocalRef(exceptionName); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
383 |
mEnv->DeleteLocalRef(classClass); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
384 |
mEnv->DeleteLocalRef(exceptionClass); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
385 |
mEnv->DeleteLocalRef(exception); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
386 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
387 |
return true; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
388 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
389 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
390 |
return false; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
391 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
392 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
393 |
static int Android_JNI_FileOpen(SDL_RWops* ctx) |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
394 |
{ |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
395 |
int result = 0; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
396 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
397 |
jmethodID mid; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
398 |
jobject context; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
399 |
jobject assetManager; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
400 |
jobject inputStream; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
401 |
jclass channels; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
402 |
jobject readableByteChannel; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
403 |
jstring fileNameJString; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
404 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
405 |
bool allocatedLocalFrame = false; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
406 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
407 |
if (mEnv->PushLocalFrame(16) < 0) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
408 |
SDL_SetError("Failed to allocate enough JVM local references"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
409 |
goto failure; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
410 |
} else { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
411 |
allocatedLocalFrame = true; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
412 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
413 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
414 |
fileNameJString = (jstring)ctx->hidden.androidio.fileName; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
415 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
416 |
// context = SDLActivity.getContext(); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
417 |
mid = mEnv->GetStaticMethodID(mActivityClass, |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
418 |
"getContext","()Landroid/content/Context;"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
419 |
context = mEnv->CallStaticObjectMethod(mActivityClass, mid); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
420 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
421 |
// assetManager = context.getAssets(); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
422 |
mid = mEnv->GetMethodID(mEnv->GetObjectClass(context), |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
423 |
"getAssets", "()Landroid/content/res/AssetManager;"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
424 |
assetManager = mEnv->CallObjectMethod(context, mid); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
425 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
426 |
// inputStream = assetManager.open(<filename>); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
427 |
mid = mEnv->GetMethodID(mEnv->GetObjectClass(assetManager), |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
428 |
"open", "(Ljava/lang/String;)Ljava/io/InputStream;"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
429 |
inputStream = mEnv->CallObjectMethod(assetManager, mid, fileNameJString); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
430 |
if (Android_JNI_ExceptionOccurred()) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
431 |
goto failure; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
432 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
433 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
434 |
ctx->hidden.androidio.inputStream = inputStream; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
435 |
ctx->hidden.androidio.inputStreamRef = mEnv->NewGlobalRef(inputStream); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
436 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
437 |
// Despite all the visible documentation on [Asset]InputStream claiming |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
438 |
// that the .available() method is not guaranteed to return the entire file |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
439 |
// size, comments in <sdk>/samples/<ver>/ApiDemos/src/com/example/ ... |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
440 |
// android/apis/content/ReadAsset.java imply that Android's |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
441 |
// AssetInputStream.available() /will/ always return the total file size |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
442 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
443 |
// size = inputStream.available(); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
444 |
mid = mEnv->GetMethodID(mEnv->GetObjectClass(inputStream), |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
445 |
"available", "()I"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
446 |
ctx->hidden.androidio.size = mEnv->CallIntMethod(inputStream, mid); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
447 |
if (Android_JNI_ExceptionOccurred()) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
448 |
goto failure; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
449 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
450 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
451 |
// readableByteChannel = Channels.newChannel(inputStream); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
452 |
channels = mEnv->FindClass("java/nio/channels/Channels"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
453 |
mid = mEnv->GetStaticMethodID(channels, |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
454 |
"newChannel", |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
455 |
"(Ljava/io/InputStream;)Ljava/nio/channels/ReadableByteChannel;"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
456 |
readableByteChannel = mEnv->CallStaticObjectMethod( |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
457 |
channels, mid, inputStream); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
458 |
if (Android_JNI_ExceptionOccurred()) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
459 |
goto failure; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
460 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
461 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
462 |
ctx->hidden.androidio.readableByteChannel = readableByteChannel; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
463 |
ctx->hidden.androidio.readableByteChannelRef = |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
464 |
mEnv->NewGlobalRef(readableByteChannel); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
465 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
466 |
// Store .read id for reading purposes |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
467 |
mid = mEnv->GetMethodID(mEnv->GetObjectClass(readableByteChannel), |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
468 |
"read", "(Ljava/nio/ByteBuffer;)I"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
469 |
ctx->hidden.androidio.readMethod = mid; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
470 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
471 |
ctx->hidden.androidio.position = 0; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
472 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
473 |
if (false) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
474 |
failure: |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
475 |
result = -1; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
476 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
477 |
mEnv->DeleteGlobalRef((jobject)ctx->hidden.androidio.fileNameRef); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
478 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
479 |
if(ctx->hidden.androidio.inputStreamRef != NULL) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
480 |
mEnv->DeleteGlobalRef((jobject)ctx->hidden.androidio.inputStreamRef); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
481 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
482 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
483 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
484 |
if (allocatedLocalFrame) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
485 |
mEnv->PopLocalFrame(NULL); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
486 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
487 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
488 |
return result; |
5337 | 489 |
} |
490 |
||
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
491 |
extern "C" int Android_JNI_FileOpen(SDL_RWops* ctx, |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
492 |
const char* fileName, const char*) |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
493 |
{ |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
494 |
if (!ctx) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
495 |
return -1; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
496 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
497 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
498 |
jstring fileNameJString = mEnv->NewStringUTF(fileName); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
499 |
ctx->hidden.androidio.fileName = fileNameJString; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
500 |
ctx->hidden.androidio.fileNameRef = mEnv->NewGlobalRef(fileNameJString); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
501 |
ctx->hidden.androidio.inputStreamRef = NULL; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
502 |
mEnv->DeleteLocalRef(fileNameJString); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
503 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
504 |
return Android_JNI_FileOpen(ctx); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
505 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
506 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
507 |
extern "C" size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer, |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
508 |
size_t size, size_t maxnum) |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
509 |
{ |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
510 |
int bytesRemaining = size * maxnum; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
511 |
int bytesRead = 0; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
512 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
513 |
jobject readableByteChannel = (jobject)ctx->hidden.androidio.readableByteChannel; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
514 |
jmethodID readMethod = (jmethodID)ctx->hidden.androidio.readMethod; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
515 |
jobject byteBuffer = mEnv->NewDirectByteBuffer(buffer, bytesRemaining); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
516 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
517 |
while (bytesRemaining > 0) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
518 |
// result = readableByteChannel.read(...); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
519 |
int result = mEnv->CallIntMethod(readableByteChannel, readMethod, byteBuffer); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
520 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
521 |
if (Android_JNI_ExceptionOccurred()) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
522 |
mEnv->DeleteLocalRef(byteBuffer); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
523 |
return 0; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
524 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
525 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
526 |
if (result < 0) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
527 |
break; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
528 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
529 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
530 |
bytesRemaining -= result; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
531 |
bytesRead += result; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
532 |
ctx->hidden.androidio.position += result; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
533 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
534 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
535 |
mEnv->DeleteLocalRef(byteBuffer); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
536 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
537 |
return bytesRead / size; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
538 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
539 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
540 |
extern "C" size_t Android_JNI_FileWrite(SDL_RWops* ctx, const void* buffer, |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
541 |
size_t size, size_t num) |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
542 |
{ |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
543 |
SDL_SetError("Cannot write to Android package filesystem"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
544 |
return 0; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
545 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
546 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
547 |
static int Android_JNI_FileClose(SDL_RWops* ctx, bool release) |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
548 |
{ |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
549 |
int result = 0; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
550 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
551 |
if (ctx) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
552 |
if (release) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
553 |
mEnv->DeleteGlobalRef((jobject)ctx->hidden.androidio.fileNameRef); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
554 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
555 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
556 |
jobject inputStream = (jobject)ctx->hidden.androidio.inputStream; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
557 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
558 |
// inputStream.close(); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
559 |
jmethodID mid = mEnv->GetMethodID(mEnv->GetObjectClass(inputStream), |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
560 |
"close", "()V"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
561 |
mEnv->CallVoidMethod(inputStream, mid); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
562 |
mEnv->DeleteGlobalRef((jobject)ctx->hidden.androidio.inputStreamRef); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
563 |
mEnv->DeleteGlobalRef((jobject)ctx->hidden.androidio.readableByteChannelRef); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
564 |
if (Android_JNI_ExceptionOccurred()) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
565 |
result = -1; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
566 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
567 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
568 |
if (release) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
569 |
SDL_FreeRW(ctx); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
570 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
571 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
572 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
573 |
return result; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
574 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
575 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
576 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
577 |
extern "C" long Android_JNI_FileSeek(SDL_RWops* ctx, long offset, int whence) |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
578 |
{ |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
579 |
long newPosition; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
580 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
581 |
switch (whence) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
582 |
case RW_SEEK_SET: |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
583 |
newPosition = offset; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
584 |
break; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
585 |
case RW_SEEK_CUR: |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
586 |
newPosition = ctx->hidden.androidio.position + offset; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
587 |
break; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
588 |
case RW_SEEK_END: |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
589 |
newPosition = ctx->hidden.androidio.size + offset; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
590 |
break; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
591 |
default: |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
592 |
SDL_SetError("Unknown value for 'whence'"); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
593 |
return -1; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
594 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
595 |
if (newPosition < 0) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
596 |
newPosition = 0; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
597 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
598 |
if (newPosition > ctx->hidden.androidio.size) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
599 |
newPosition = ctx->hidden.androidio.size; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
600 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
601 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
602 |
long movement = newPosition - ctx->hidden.androidio.position; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
603 |
jobject inputStream = (jobject)ctx->hidden.androidio.inputStream; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
604 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
605 |
if (movement > 0) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
606 |
unsigned char buffer[1024]; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
607 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
608 |
// The easy case where we're seeking forwards |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
609 |
while (movement > 0) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
610 |
long amount = (long) sizeof (buffer); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
611 |
if (amount > movement) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
612 |
amount = movement; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
613 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
614 |
size_t result = Android_JNI_FileRead(ctx, buffer, 1, amount); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
615 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
616 |
if (result <= 0) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
617 |
// Failed to read/skip the required amount, so fail |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
618 |
return -1; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
619 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
620 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
621 |
movement -= result; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
622 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
623 |
} else if (movement < 0) { |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
624 |
// We can't seek backwards so we have to reopen the file and seek |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
625 |
// forwards which obviously isn't very efficient |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
626 |
Android_JNI_FileClose(ctx, false); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
627 |
Android_JNI_FileOpen(ctx); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
628 |
Android_JNI_FileSeek(ctx, newPosition, RW_SEEK_SET); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
629 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
630 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
631 |
ctx->hidden.androidio.position = newPosition; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
632 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
633 |
return ctx->hidden.androidio.position; |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
634 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
635 |
|
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
636 |
extern "C" int Android_JNI_FileClose(SDL_RWops* ctx) |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
637 |
{ |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
638 |
return Android_JNI_FileClose(ctx, true); |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
639 |
} |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
640 |
|
7185
92a045156255
Android: first attempt at using the density call from java
Xeli
parents:
7167
diff
changeset
|
641 |
extern "C" int Android_JNI_getDensity(){ |
7167
0b3b306f129a
Android: added a callback to java to determine dpi/dip how much we should scale the ui
Xeli
parents:
6597
diff
changeset
|
642 |
jmethodID mid; |
7185
92a045156255
Android: first attempt at using the density call from java
Xeli
parents:
7167
diff
changeset
|
643 |
jint density; |
7167
0b3b306f129a
Android: added a callback to java to determine dpi/dip how much we should scale the ui
Xeli
parents:
6597
diff
changeset
|
644 |
//SDLActivity.getDensity() |
7185
92a045156255
Android: first attempt at using the density call from java
Xeli
parents:
7167
diff
changeset
|
645 |
mid = mEnv->GetStaticMethodID(mActivityClass, "getDensity", "()I"); |
92a045156255
Android: first attempt at using the density call from java
Xeli
parents:
7167
diff
changeset
|
646 |
if(!mid) return 160; |
7167
0b3b306f129a
Android: added a callback to java to determine dpi/dip how much we should scale the ui
Xeli
parents:
6597
diff
changeset
|
647 |
density = mEnv->CallStaticFloatMethod(mActivityClass, mid); |
0b3b306f129a
Android: added a callback to java to determine dpi/dip how much we should scale the ui
Xeli
parents:
6597
diff
changeset
|
648 |
return density; |
0b3b306f129a
Android: added a callback to java to determine dpi/dip how much we should scale the ui
Xeli
parents:
6597
diff
changeset
|
649 |
|
0b3b306f129a
Android: added a callback to java to determine dpi/dip how much we should scale the ui
Xeli
parents:
6597
diff
changeset
|
650 |
} |
0b3b306f129a
Android: added a callback to java to determine dpi/dip how much we should scale the ui
Xeli
parents:
6597
diff
changeset
|
651 |
|
6592
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
652 |
#endif /* __ANDROID__ */ |
cf12f07d6f24
update the core/android/SDL_android.cpp fix some includes in Android.mks, use a different host to download some libs, sdl doesn't have up to date tarballs..
Xeli
parents:
6328
diff
changeset
|
653 |
|
5337 | 654 |
/* vi: set ts=4 sw=4 expandtab: */ |