ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

jni.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef _ANDROID_JNI_H_
00024 #define _ANDROID_JNI_H_
00025 
00026 #if defined(__ANDROID__)
00027 
00028 #include <jni.h>
00029 #include <semaphore.h>
00030 
00031 #include "common/fs.h"
00032 #include "common/archive.h"
00033 
00034 class OSystem_Android;
00035 
00036 class JNI {
00037 private:
00038     JNI();
00039     virtual ~JNI();
00040 
00041 public:
00042     static bool pause;
00043     static sem_t pause_sem;
00044 
00045     static int surface_changeid;
00046     static int egl_surface_width;
00047     static int egl_surface_height;
00048 
00049     static jint onLoad(JavaVM *vm);
00050 
00051     static JNIEnv *getEnv();
00052 
00053     static void attachThread();
00054     static void detachThread();
00055 
00056     static void setReadyForEvents(bool ready);
00057 
00058     static void setWindowCaption(const char *caption);
00059     static void getDPI(float *values);
00060     static void displayMessageOnOSD(const char *msg);
00061     static bool openUrl(const char *url);
00062     static bool hasTextInClipboard();
00063     static Common::String getTextFromClipboard();
00064     static bool setTextInClipboard(const Common::String &text);
00065     static bool isConnectionLimited();
00066     static void showVirtualKeyboard(bool enable);
00067     static void addSysArchivesToSearchSet(Common::SearchSet &s, int priority);
00068 
00069     static inline bool haveSurface();
00070     static inline bool swapBuffers();
00071     static bool initSurface();
00072     static void deinitSurface();
00073 
00074     static void setAudioPause();
00075     static void setAudioPlay();
00076     static void setAudioStop();
00077 
00078     static inline int writeAudio(JNIEnv *env, jbyteArray &data, int offset,
00079                                     int size);
00080 
00081 private:
00082     static JavaVM *_vm;
00083     // back pointer to (java) peer instance
00084     static jobject _jobj;
00085     static jobject _jobj_audio_track;
00086     static jobject _jobj_egl;
00087     static jobject _jobj_egl_display;
00088     static jobject _jobj_egl_surface;
00089 
00090     static Common::Archive *_asset_archive;
00091     static OSystem_Android *_system;
00092 
00093     static bool _ready_for_events;
00094 
00095     static jmethodID _MID_getDPI;
00096     static jmethodID _MID_displayMessageOnOSD;
00097     static jmethodID _MID_openUrl;
00098     static jmethodID _MID_hasTextInClipboard;
00099     static jmethodID _MID_getTextFromClipboard;
00100     static jmethodID _MID_setTextInClipboard;
00101     static jmethodID _MID_isConnectionLimited;
00102     static jmethodID _MID_setWindowCaption;
00103     static jmethodID _MID_showVirtualKeyboard;
00104     static jmethodID _MID_getSysArchives;
00105     static jmethodID _MID_initSurface;
00106     static jmethodID _MID_deinitSurface;
00107 
00108     static jmethodID _MID_EGL10_eglSwapBuffers;
00109 
00110     static jmethodID _MID_AudioTrack_flush;
00111     static jmethodID _MID_AudioTrack_pause;
00112     static jmethodID _MID_AudioTrack_play;
00113     static jmethodID _MID_AudioTrack_stop;
00114     static jmethodID _MID_AudioTrack_write;
00115 
00116     static const JNINativeMethod _natives[];
00117 
00118     static void throwByName(JNIEnv *env, const char *name, const char *msg);
00119     static void throwRuntimeException(JNIEnv *env, const char *msg);
00120 
00121     // natives for the dark side
00122     static void create(JNIEnv *env, jobject self, jobject asset_manager,
00123                         jobject egl, jobject egl_display,
00124                         jobject at, jint audio_sample_rate,
00125                         jint audio_buffer_size);
00126     static void destroy(JNIEnv *env, jobject self);
00127 
00128     static void setSurface(JNIEnv *env, jobject self, jint width, jint height);
00129     static jint main(JNIEnv *env, jobject self, jobjectArray args);
00130 
00131     static void pushEvent(JNIEnv *env, jobject self, int type, int arg1,
00132                             int arg2, int arg3, int arg4, int arg5, int arg6);
00133     static void enableZoning(JNIEnv *env, jobject self, jboolean enable);
00134 
00135     static void setPause(JNIEnv *env, jobject self, jboolean value);
00136 
00137     static jstring getCurrentCharset(JNIEnv *env, jobject self);
00138 };
00139 
00140 inline bool JNI::haveSurface() {
00141     return _jobj_egl_surface != 0;
00142 }
00143 
00144 inline bool JNI::swapBuffers() {
00145     JNIEnv *env = JNI::getEnv();
00146 
00147     return env->CallBooleanMethod(_jobj_egl, _MID_EGL10_eglSwapBuffers,
00148                                     _jobj_egl_display, _jobj_egl_surface);
00149 }
00150 
00151 inline int JNI::writeAudio(JNIEnv *env, jbyteArray &data, int offset, int size) {
00152     return env->CallIntMethod(_jobj_audio_track, _MID_AudioTrack_write, data,
00153                                 offset, size);
00154 }
00155 
00156 #endif
00157 #endif


Generated on Sat May 18 2019 05:01:06 for ResidualVM by doxygen 1.7.1
curved edge   curved edge