ScummVM API documentation
jni-android.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef _ANDROID_JNI_H_
23#define _ANDROID_JNI_H_
24
25#include <jni.h>
26#include <semaphore.h>
27#include <pthread.h>
28
29#include "common/fs.h"
30#include "common/archive.h"
31#include "common/array.h"
32#include "common/ustr.h"
33
34namespace Graphics {
35 struct Surface;
36}
37
38class OSystem_Android;
39
40class JNI {
41private:
42 JNI();
43 virtual ~JNI();
44
45public:
46 static bool assets_updated;
47
48 static bool pause;
49 static sem_t pause_sem;
50
51 static int surface_changeid;
52 static int egl_surface_width;
53 static int egl_surface_height;
54 static int egl_bits_per_pixel;
55
56 static bool virt_keyboard_state;
57
58 static int32 gestures_insets[4];
59 static int32 cutout_insets[4];
60
61 static jint onLoad(JavaVM *vm);
62
63 static inline JNIEnv *getEnv() {
64 JNIEnv *env = (JNIEnv*) pthread_getspecific(_env_tls);
65 if (env != nullptr) {
66 return env;
67 }
68
69 return fetchEnv();
70 }
71
72 static void attachThread();
73 static void detachThread();
74
75 static void setReadyForEvents(bool ready);
76 static void wakeupForQuit();
77
78 static void setWindowCaption(const Common::U32String &caption);
79
83 typedef float DPIValues[3];
84 static void getDPI(DPIValues &values);
85 static void displayMessageOnOSD(const Common::U32String &msg);
86 static bool openUrl(const Common::String &url);
87 static bool hasTextInClipboard();
88 static Common::U32String getTextFromClipboard();
89 static bool setTextInClipboard(const Common::U32String &text);
90 static bool isConnectionLimited();
91 static void showVirtualKeyboard(bool enable);
92 static void showOnScreenControls(int enableMask);
93 static void setTouchMode(int touchMode);
94 static int getTouchMode();
95 static void setOrientation(int touchMode);
96 static void addSysArchivesToSearchSet(Common::SearchSet &s, int priority);
97 static Common::String getScummVMBasePath();
98 static Common::String getScummVMAssetsPath();
99 static Common::String getScummVMConfigPath();
100 static Common::String getScummVMLogPath();
101 static jint getAndroidSDKVersionId();
102 static void setCurrentGame(const Common::String &target);
103 static void notifyHTTPService(int localPort, bool minimal);
104 static jobject getTTSManager();
105 static Common::Array<Common::String> getMIDIDevices();
106 static jobject openMIDIDevice(int deviceId, int *port);
107
108 static inline bool haveSurface();
109 static inline bool swapBuffers();
110 static bool initSurface();
111 static void deinitSurface();
112 static int eglVersion() {
113 if (_egl_version) {
114 return _egl_version;
115 }
116 return fetchEGLVersion();
117 }
118
119 static Common::Array<Common::String> getAllStorageLocations();
120
121 static jobject getNewSAFTree(bool writable, const Common::String &initURI, const Common::String &prompt);
122 static Common::Array<jobject> getSAFTrees();
123 static jobject findSAFTree(const Common::String &name);
124
125 static int exportBackup(const Common::U32String &prompt);
126 static int importBackup(const Common::U32String &prompt, const Common::String &path);
127
128 static jstring convertToJString(JNIEnv *env, const Common::U32String &str);
129 static Common::U32String convertFromJString(JNIEnv *env, const jstring &jstr);
130private:
131 static pthread_key_t _env_tls;
132
133 static JavaVM *_vm;
134 // back pointer to (java) peer instance
135 static jobject _jobj;
136 static jobject _jobj_egl;
137 static jobject _jobj_egl_display;
138 static jobject _jobj_egl_surface;
139 // cached EGL version
140 static int _egl_version;
141
142 static Common::Archive *_asset_archive;
143 static OSystem_Android *_system;
144
145 static bool _ready_for_events;
146
147 static jmethodID _MID_getDPI;
148 static jmethodID _MID_displayMessageOnOSD;
149 static jmethodID _MID_openUrl;
150 static jmethodID _MID_hasTextInClipboard;
151 static jmethodID _MID_getTextFromClipboard;
152 static jmethodID _MID_setTextInClipboard;
153 static jmethodID _MID_isConnectionLimited;
154 static jmethodID _MID_setWindowCaption;
155 static jmethodID _MID_showVirtualKeyboard;
156 static jmethodID _MID_showOnScreenControls;
157 static jmethodID _MID_setTouchMode;
158 static jmethodID _MID_getTouchMode;
159 static jmethodID _MID_setOrientation;
160 static jmethodID _MID_getScummVMBasePath;
161 static jmethodID _MID_getScummVMConfigPath;
162 static jmethodID _MID_getScummVMLogPath;
163 static jmethodID _MID_setCurrentGame;
164 static jmethodID _MID_notifyHTTPService;
165 static jmethodID _MID_getTTSManager;
166 static jmethodID _MID_getMIDIDevices;
167 static jmethodID _MID_openMIDIDevice;
168 static jmethodID _MID_getSysArchives;
169 static jmethodID _MID_getAllStorageLocations;
170 static jmethodID _MID_initSurface;
171 static jmethodID _MID_deinitSurface;
172 static jmethodID _MID_eglVersion;
173 static jmethodID _MID_getNewSAFTree;
174 static jmethodID _MID_getSAFTrees;
175 static jmethodID _MID_findSAFTree;
176 static jmethodID _MID_exportBackup;
177 static jmethodID _MID_importBackup;
178
179 static jmethodID _MID_EGL10_eglSwapBuffers;
180
181 static const JNINativeMethod _natives[];
182
183 static void throwByName(JNIEnv *env, const char *name, const char *msg);
184 static void throwRuntimeException(JNIEnv *env, const char *msg);
185
186 // natives for the dark side
187 static void create(JNIEnv *env, jobject self, jobject asset_manager,
188 jobject egl, jobject egl_display,
189 jboolean assets_updated_);
190 static void destroy(JNIEnv *env, jobject self);
191
192 static void setSurface(JNIEnv *env, jobject self, jint width, jint height, jint bpp);
193 static jint main(JNIEnv *env, jobject self, jobjectArray args);
194
195 static void pushEvent(JNIEnv *env, jobject self, int type, int arg1,
196 int arg2, int arg3, int arg4, int arg5, int arg6);
197 static void updateTouch(JNIEnv *env, jobject self, int action, int ptr, int x, int y);
198 static void setupTouchMode(JNIEnv *env, jobject self, jint oldValue, jint newValue);
199 static void syncVirtkeyboardState(JNIEnv *env, jobject self, jboolean newState);
200 static void setPause(JNIEnv *env, jobject self, jboolean value);
201
202 static void systemInsetsUpdated(JNIEnv *env, jobject self, jintArray gestureInsets, jintArray systemInsets, jintArray cutoutInsets);
203
204 static void setDefaultAudioValues(JNIEnv *env, jclass clazz, jint sampleRate, jint framesPerBurst);
205 static void notifyAudioDisconnect(JNIEnv *env, jclass clazz);
206
207 static jstring getNativeVersionInfo(JNIEnv *env, jobject self);
208
209 static JNIEnv *fetchEnv();
210 static int fetchEGLVersion();
211};
212
213inline bool JNI::haveSurface() {
214 return _jobj_egl_surface != 0;
215}
216
217inline bool JNI::swapBuffers() {
218 JNIEnv *env = JNI::getEnv();
219
220 return env->CallBooleanMethod(_jobj_egl, _MID_EGL10_eglSwapBuffers,
221 _jobj_egl_display, _jobj_egl_surface);
222}
223
224#endif
Definition: archive.h:141
Definition: archive.h:330
Definition: str.h:59
Definition: ustr.h:57
Definition: jni-android.h:40
float DPIValues[3]
Definition: jni-android.h:83
Definition: android.h:98
Definition: formatinfo.h:28