scummvm/backends/platform/android/jni-android.h

176 lines
5.5 KiB
C
Raw Normal View History

2011-02-23 22:44:33 +01:00
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
2011-02-23 22:44:33 +01:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2011-02-23 22:44:33 +01:00
* GNU General Public License for more details.
*
2011-02-23 22:44:33 +01:00
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef _ANDROID_JNI_H_
#define _ANDROID_JNI_H_
#if defined(__ANDROID__)
#include <jni.h>
#include <semaphore.h>
2011-02-23 22:44:33 +01:00
2011-02-24 00:45:41 +01:00
#include "common/fs.h"
#include "common/archive.h"
#include "common/array.h"
#include "common/ustr.h"
2020-05-11 01:51:42 +02:00
#include "engines/engine.h"
2011-02-23 22:44:33 +01:00
class OSystem_Android;
class JNI {
2011-02-24 00:45:41 +01:00
private:
JNI();
virtual ~JNI();
2011-02-23 22:44:33 +01:00
public:
static bool pause;
static sem_t pause_sem;
static int surface_changeid;
static int egl_surface_width;
static int egl_surface_height;
2011-02-23 22:44:33 +01:00
static jint onLoad(JavaVM *vm);
static JNIEnv *getEnv();
static void attachThread();
static void detachThread();
static void setReadyForEvents(bool ready);
static void setWindowCaption(const Common::String &caption);
static void getDPI(float *values);
2020-08-19 14:32:55 +05:30
static void displayMessageOnOSD(const Common::U32String &msg);
static bool openUrl(const Common::String &url);
2018-10-02 14:57:48 +01:00
static bool hasTextInClipboard();
static Common::U32String getTextFromClipboard();
static bool setTextInClipboard(const Common::U32String &text);
static bool isConnectionLimited();
2011-02-24 00:45:41 +01:00
static void showVirtualKeyboard(bool enable);
static void showKeyboardControl(bool enable);
2011-02-24 00:45:41 +01:00
static void addSysArchivesToSearchSet(Common::SearchSet &s, int priority);
static char *convertEncoding(const char *to, const char *from, const char *string, size_t length);
2011-02-24 00:45:41 +01:00
static inline bool haveSurface();
static inline bool swapBuffers();
static bool initSurface();
static void deinitSurface();
2011-02-23 22:44:33 +01:00
static void setAudioPause();
static void setAudioPlay();
static void setAudioStop();
static inline int writeAudio(JNIEnv *env, jbyteArray &data, int offset,
int size);
static Common::Array<Common::String> getAllStorageLocations();
static bool createDirectoryWithSAF(const Common::String &dirPath);
static Common::String createFileWithSAF(const Common::String &filePath);
static void closeFileWithSAF(const Common::String &hackyFilename);
2011-02-23 22:44:33 +01:00
private:
static JavaVM *_vm;
// back pointer to (java) peer instance
static jobject _jobj;
static jobject _jobj_audio_track;
static jobject _jobj_egl;
static jobject _jobj_egl_display;
static jobject _jobj_egl_surface;
2011-02-24 00:45:41 +01:00
static Common::Archive *_asset_archive;
2011-02-23 22:44:33 +01:00
static OSystem_Android *_system;
static bool _ready_for_events;
static jmethodID _MID_getDPI;
2011-02-24 00:45:41 +01:00
static jmethodID _MID_displayMessageOnOSD;
2016-07-15 19:18:19 +06:00
static jmethodID _MID_openUrl;
2018-10-02 14:57:48 +01:00
static jmethodID _MID_hasTextInClipboard;
static jmethodID _MID_getTextFromClipboard;
static jmethodID _MID_setTextInClipboard;
static jmethodID _MID_isConnectionLimited;
2011-02-24 00:45:41 +01:00
static jmethodID _MID_setWindowCaption;
static jmethodID _MID_showVirtualKeyboard;
static jmethodID _MID_showKeyboardControl;
2011-02-24 00:45:41 +01:00
static jmethodID _MID_getSysArchives;
static jmethodID _MID_convertEncoding;
static jmethodID _MID_getAllStorageLocations;
static jmethodID _MID_initSurface;
static jmethodID _MID_deinitSurface;
static jmethodID _MID_createDirectoryWithSAF;
static jmethodID _MID_createFileWithSAF;
static jmethodID _MID_closeFileWithSAF;
2011-02-24 00:45:41 +01:00
static jmethodID _MID_EGL10_eglSwapBuffers;
static jmethodID _MID_AudioTrack_flush;
static jmethodID _MID_AudioTrack_pause;
static jmethodID _MID_AudioTrack_play;
static jmethodID _MID_AudioTrack_stop;
static jmethodID _MID_AudioTrack_write;
2011-02-23 22:44:33 +01:00
static const JNINativeMethod _natives[];
static void throwByName(JNIEnv *env, const char *name, const char *msg);
static void throwRuntimeException(JNIEnv *env, const char *msg);
2011-02-23 22:44:33 +01:00
// natives for the dark side
static void create(JNIEnv *env, jobject self, jobject asset_manager,
jobject egl, jobject egl_display,
jobject at, jint audio_sample_rate,
jint audio_buffer_size);
2011-02-23 22:44:33 +01:00
static void destroy(JNIEnv *env, jobject self);
static void setSurface(JNIEnv *env, jobject self, jint width, jint height);
2011-02-23 22:44:33 +01:00
static jint main(JNIEnv *env, jobject self, jobjectArray args);
static void pushEvent(JNIEnv *env, jobject self, int type, int arg1,
int arg2, int arg3, int arg4, int arg5, int arg6);
static void setPause(JNIEnv *env, jobject self, jboolean value);
2018-10-02 14:57:48 +01:00
static jstring convertToJString(JNIEnv *env, const Common::String &str, const Common::String &from);
static Common::String convertFromJString(JNIEnv *env, const jstring &jstr, const Common::String &to);
2020-05-11 00:24:10 +02:00
static PauseToken _pauseToken;
2011-02-23 22:44:33 +01:00
};
inline bool JNI::haveSurface() {
return _jobj_egl_surface != 0;
}
inline bool JNI::swapBuffers() {
2011-02-24 00:45:41 +01:00
JNIEnv *env = JNI::getEnv();
return env->CallBooleanMethod(_jobj_egl, _MID_EGL10_eglSwapBuffers,
_jobj_egl_display, _jobj_egl_surface);
2011-02-24 00:45:41 +01:00
}
inline int JNI::writeAudio(JNIEnv *env, jbyteArray &data, int offset, int size) {
2011-03-03 11:20:37 +01:00
return env->CallIntMethod(_jobj_audio_track, _MID_AudioTrack_write, data,
offset, size);
}
2011-02-23 22:44:33 +01:00
#endif
#endif