2022-03-15 13:29:32 +01:00
|
|
|
/*************************************************************************/
|
2022-03-23 20:46:05 +01:00
|
|
|
/* java_pandemonium_wrapper.cpp */
|
2022-03-15 13:29:32 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
#include "java_pandemonium_wrapper.h"
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
// JNIEnv is only valid within the thread it belongs to, in a multi threading environment
|
|
|
|
// we can't cache it.
|
2022-03-23 20:46:05 +01:00
|
|
|
// For Pandemonium we call most access methods from our thread and we thus get a valid JNIEnv
|
2022-03-15 13:29:32 +01:00
|
|
|
// from ThreadAndroid. For one or two we expect to pass the environment
|
|
|
|
|
|
|
|
// TODO we could probably create a base class for this...
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
PandemoniumJavaWrapper::PandemoniumJavaWrapper(JNIEnv *p_env, jobject p_activity, jobject p_pandemonium_instance) {
|
|
|
|
pandemonium_instance = p_env->NewGlobalRef(p_pandemonium_instance);
|
2022-03-15 13:29:32 +01:00
|
|
|
activity = p_env->NewGlobalRef(p_activity);
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
// get info about our Pandemonium class so we can get pointers and stuff...
|
2023-08-31 21:59:44 +02:00
|
|
|
pandemonium_class = p_env->FindClass("org/pandemoniumengine/pandemonium/Pandemonium");
|
2022-03-23 20:46:05 +01:00
|
|
|
if (pandemonium_class) {
|
|
|
|
pandemonium_class = (jclass)p_env->NewGlobalRef(pandemonium_class);
|
2022-03-15 13:29:32 +01:00
|
|
|
} else {
|
|
|
|
// this is a pretty serious fail.. bail... pointers will stay 0
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
activity_class = p_env->FindClass("android/app/Activity");
|
|
|
|
if (activity_class) {
|
|
|
|
activity_class = (jclass)p_env->NewGlobalRef(activity_class);
|
|
|
|
} else {
|
|
|
|
// this is a pretty serious fail.. bail... pointers will stay 0
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
// get some Pandemonium method pointers...
|
|
|
|
_on_video_init = p_env->GetMethodID(pandemonium_class, "onVideoInit", "()V");
|
|
|
|
_create_offscreen_gl = p_env->GetMethodID(pandemonium_class, "createOffscreenGL", "()Z");
|
|
|
|
_destroy_offscreen_gl = p_env->GetMethodID(pandemonium_class, "destroyOffscreenGL", "()V");
|
|
|
|
_set_offscreen_gl_current = p_env->GetMethodID(pandemonium_class, "setOffscreenGLCurrent", "(Z)V");
|
|
|
|
_restart = p_env->GetMethodID(pandemonium_class, "restart", "()V");
|
2023-02-07 02:44:47 +01:00
|
|
|
_finish = p_env->GetMethodID(pandemonium_class, "forceQuit", "(I)Z");
|
2022-03-23 20:46:05 +01:00
|
|
|
_set_keep_screen_on = p_env->GetMethodID(pandemonium_class, "setKeepScreenOn", "(Z)V");
|
|
|
|
_alert = p_env->GetMethodID(pandemonium_class, "alert", "(Ljava/lang/String;Ljava/lang/String;)V");
|
2023-06-15 10:21:23 +02:00
|
|
|
_enable_for_stealing_focus = p_env->GetMethodID(pandemonium_class, "enableForStealingFocus", "(I)V");
|
|
|
|
_move_window_to_foreground = p_env->GetMethodID(pandemonium_class, "moveWindowToForeground", "()V");
|
2022-03-23 20:46:05 +01:00
|
|
|
_get_GLES_version_code = p_env->GetMethodID(pandemonium_class, "getGLESVersionCode", "()I");
|
|
|
|
_get_clipboard = p_env->GetMethodID(pandemonium_class, "getClipboard", "()Ljava/lang/String;");
|
|
|
|
_set_clipboard = p_env->GetMethodID(pandemonium_class, "setClipboard", "(Ljava/lang/String;)V");
|
|
|
|
_has_clipboard = p_env->GetMethodID(pandemonium_class, "hasClipboard", "()Z");
|
|
|
|
_request_permission = p_env->GetMethodID(pandemonium_class, "requestPermission", "(Ljava/lang/String;)Z");
|
|
|
|
_request_permissions = p_env->GetMethodID(pandemonium_class, "requestPermissions", "()Z");
|
|
|
|
_get_granted_permissions = p_env->GetMethodID(pandemonium_class, "getGrantedPermissions", "()[Ljava/lang/String;");
|
|
|
|
_init_input_devices = p_env->GetMethodID(pandemonium_class, "initInputDevices", "()V");
|
|
|
|
_get_surface = p_env->GetMethodID(pandemonium_class, "getSurface", "()Landroid/view/Surface;");
|
|
|
|
_is_activity_resumed = p_env->GetMethodID(pandemonium_class, "isActivityResumed", "()Z");
|
|
|
|
_vibrate = p_env->GetMethodID(pandemonium_class, "vibrate", "(I)V");
|
|
|
|
_get_input_fallback_mapping = p_env->GetMethodID(pandemonium_class, "getInputFallbackMapping", "()Ljava/lang/String;");
|
|
|
|
_on_pandemonium_setup_completed = p_env->GetMethodID(pandemonium_class, "onPandemoniumSetupCompleted", "()V");
|
|
|
|
_on_pandemonium_main_loop_started = p_env->GetMethodID(pandemonium_class, "onPandemoniumMainLoopStarted", "()V");
|
2023-02-07 02:44:47 +01:00
|
|
|
_create_new_pandemonium_instance = p_env->GetMethodID(pandemonium_class, "createNewPandemoniumInstance", "([Ljava/lang/String;)I");
|
2022-03-28 13:21:41 +02:00
|
|
|
_request_framebuffer_swap = p_env->GetMethodID(pandemonium_class, "requestFramebufferSwap", "()V");
|
2023-08-31 21:59:44 +02:00
|
|
|
_get_render_view = p_env->GetMethodID(pandemonium_class, "getRenderView", "()Lorg/pandemoniumengine/pandemonium/PandemoniumView;");
|
2023-05-01 15:32:01 +02:00
|
|
|
_begin_benchmark_measure = p_env->GetMethodID(pandemonium_class, "beginBenchmarkMeasure", "(Ljava/lang/String;)V");
|
|
|
|
_end_benchmark_measure = p_env->GetMethodID(pandemonium_class, "endBenchmarkMeasure", "(Ljava/lang/String;)V");
|
|
|
|
_dump_benchmark = p_env->GetMethodID(pandemonium_class, "dumpBenchmark", "(Ljava/lang/String;)V");
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
// get some Activity method pointers...
|
|
|
|
_get_class_loader = p_env->GetMethodID(activity_class, "getClassLoader", "()Ljava/lang/ClassLoader;");
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
PandemoniumJavaWrapper::~PandemoniumJavaWrapper() {
|
2022-10-08 19:03:10 +02:00
|
|
|
if (pandemonium_view) {
|
|
|
|
delete pandemonium_view;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_NULL(env);
|
|
|
|
env->DeleteGlobalRef(pandemonium_instance);
|
|
|
|
env->DeleteGlobalRef(pandemonium_class);
|
|
|
|
env->DeleteGlobalRef(activity);
|
|
|
|
env->DeleteGlobalRef(activity_class);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
jobject PandemoniumJavaWrapper::get_activity() {
|
2022-03-15 13:29:32 +01:00
|
|
|
return activity;
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
jobject PandemoniumJavaWrapper::get_member_object(const char *p_name, const char *p_class, JNIEnv *p_env) {
|
|
|
|
if (pandemonium_class) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (p_env == NULL)
|
|
|
|
p_env = get_jni_env();
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(p_env == nullptr, nullptr);
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
jfieldID fid = p_env->GetStaticFieldID(pandemonium_class, p_name, p_class);
|
|
|
|
return p_env->GetStaticObjectField(pandemonium_class, fid);
|
2022-03-15 13:29:32 +01:00
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
jobject PandemoniumJavaWrapper::get_class_loader() {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_get_class_loader) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND_V(env == nullptr, nullptr);
|
|
|
|
|
|
|
|
return env->CallObjectMethod(activity, _get_class_loader);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
void PandemoniumJavaWrapper::gfx_init(bool gl2) {
|
2022-03-15 13:29:32 +01:00
|
|
|
// beats me what this once did, there was no code,
|
|
|
|
// but we're getting false if our GLES3 driver is initialised
|
|
|
|
// and true for our GLES2 driver
|
|
|
|
// Maybe we're supposed to communicate this back or store it?
|
|
|
|
}
|
|
|
|
|
2022-10-08 19:03:10 +02:00
|
|
|
PandemoniumJavaViewWrapper *PandemoniumJavaWrapper::get_pandemonium_view() {
|
|
|
|
if (pandemonium_view != nullptr) {
|
|
|
|
return pandemonium_view;
|
|
|
|
}
|
|
|
|
if (_get_render_view) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_NULL_V(env, nullptr);
|
|
|
|
jobject pandemonium_render_view = env->CallObjectMethod(pandemonium_instance, _get_render_view);
|
|
|
|
if (!env->IsSameObject(pandemonium_render_view, nullptr)) {
|
|
|
|
pandemonium_view = new PandemoniumJavaViewWrapper(pandemonium_render_view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pandemonium_view;
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
void PandemoniumJavaWrapper::on_video_init(JNIEnv *p_env) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_on_video_init) {
|
|
|
|
if (p_env == NULL)
|
|
|
|
p_env = get_jni_env();
|
|
|
|
ERR_FAIL_COND(p_env == nullptr);
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
p_env->CallVoidMethod(pandemonium_instance, _on_video_init);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
bool PandemoniumJavaWrapper::create_offscreen_gl(JNIEnv *p_env) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_create_offscreen_gl) {
|
2022-03-23 20:46:05 +01:00
|
|
|
return p_env->CallBooleanMethod(pandemonium_instance, _create_offscreen_gl);
|
2022-03-15 13:29:32 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
void PandemoniumJavaWrapper::destroy_offscreen_gl(JNIEnv *p_env) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_destroy_offscreen_gl) {
|
2022-03-23 20:46:05 +01:00
|
|
|
p_env->CallVoidMethod(pandemonium_instance, _destroy_offscreen_gl);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
void PandemoniumJavaWrapper::set_offscreen_gl_current(JNIEnv *p_env, bool p_current) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_set_offscreen_gl_current) {
|
|
|
|
if (p_env == NULL)
|
|
|
|
p_env = get_jni_env();
|
|
|
|
ERR_FAIL_COND(p_env == nullptr);
|
2022-03-23 20:46:05 +01:00
|
|
|
p_env->CallVoidMethod(pandemonium_instance, _set_offscreen_gl_current, p_current);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
void PandemoniumJavaWrapper::on_pandemonium_setup_completed(JNIEnv *p_env) {
|
|
|
|
if (_on_pandemonium_setup_completed) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (p_env == NULL) {
|
|
|
|
p_env = get_jni_env();
|
|
|
|
}
|
|
|
|
ERR_FAIL_COND(p_env == nullptr);
|
2022-03-23 20:46:05 +01:00
|
|
|
p_env->CallVoidMethod(pandemonium_instance, _on_pandemonium_setup_completed);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
void PandemoniumJavaWrapper::on_pandemonium_main_loop_started(JNIEnv *p_env) {
|
|
|
|
if (_on_pandemonium_main_loop_started) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (p_env == NULL) {
|
|
|
|
p_env = get_jni_env();
|
|
|
|
}
|
|
|
|
ERR_FAIL_COND(p_env == nullptr);
|
2022-03-23 20:46:05 +01:00
|
|
|
p_env->CallVoidMethod(pandemonium_instance, _on_pandemonium_main_loop_started);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
void PandemoniumJavaWrapper::restart(JNIEnv *p_env) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_restart) {
|
|
|
|
if (p_env == NULL)
|
|
|
|
p_env = get_jni_env();
|
|
|
|
ERR_FAIL_COND(p_env == nullptr);
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
p_env->CallVoidMethod(pandemonium_instance, _restart);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 02:44:47 +01:00
|
|
|
bool PandemoniumJavaWrapper::force_quit(JNIEnv *p_env, int p_instance_id) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_finish) {
|
2023-02-07 02:44:47 +01:00
|
|
|
if (p_env == NULL) {
|
2022-03-15 13:29:32 +01:00
|
|
|
p_env = get_jni_env();
|
2023-02-07 02:44:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_NULL_V(p_env, false);
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2023-02-07 02:44:47 +01:00
|
|
|
return p_env->CallBooleanMethod(pandemonium_instance, _finish, p_instance_id);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
2023-02-07 03:09:55 +01:00
|
|
|
|
|
|
|
return false;
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
void PandemoniumJavaWrapper::set_keep_screen_on(bool p_enabled) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_set_keep_screen_on) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND(env == nullptr);
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
env->CallVoidMethod(pandemonium_instance, _set_keep_screen_on, p_enabled);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
void PandemoniumJavaWrapper::alert(const String &p_message, const String &p_title) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_alert) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND(env == nullptr);
|
|
|
|
|
|
|
|
jstring jStrMessage = env->NewStringUTF(p_message.utf8().get_data());
|
|
|
|
jstring jStrTitle = env->NewStringUTF(p_title.utf8().get_data());
|
2022-03-23 20:46:05 +01:00
|
|
|
env->CallVoidMethod(pandemonium_instance, _alert, jStrMessage, jStrTitle);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-15 10:21:23 +02:00
|
|
|
void PandemoniumJavaWrapper::enable_for_stealing_focus(int pid) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND(env == nullptr);
|
|
|
|
|
|
|
|
if (_enable_for_stealing_focus) {
|
|
|
|
env->CallVoidMethod(pandemonium_instance, _enable_for_stealing_focus, pid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void PandemoniumJavaWrapper::move_window_to_foreground() {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND(env == nullptr);
|
|
|
|
|
|
|
|
if (_move_window_to_foreground) {
|
|
|
|
env->CallVoidMethod(pandemonium_instance, _move_window_to_foreground);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
int PandemoniumJavaWrapper::get_gles_version_code() {
|
2022-03-15 13:29:32 +01:00
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND_V(env == nullptr, 0);
|
|
|
|
|
|
|
|
if (_get_GLES_version_code) {
|
2022-03-23 20:46:05 +01:00
|
|
|
return env->CallIntMethod(pandemonium_instance, _get_GLES_version_code);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
bool PandemoniumJavaWrapper::has_get_clipboard() {
|
2022-03-15 13:29:32 +01:00
|
|
|
return _get_clipboard != 0;
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
String PandemoniumJavaWrapper::get_clipboard() {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_get_clipboard) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND_V(env == nullptr, String());
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
jstring s = (jstring)env->CallObjectMethod(pandemonium_instance, _get_clipboard);
|
2022-03-15 13:29:32 +01:00
|
|
|
return jstring_to_string(s, env);
|
|
|
|
} else {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
String PandemoniumJavaWrapper::get_input_fallback_mapping() {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_get_input_fallback_mapping) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND_V(env == nullptr, String());
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
jstring fallback_mapping = (jstring)env->CallObjectMethod(pandemonium_instance, _get_input_fallback_mapping);
|
2022-03-15 13:29:32 +01:00
|
|
|
return jstring_to_string(fallback_mapping, env);
|
|
|
|
} else {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
bool PandemoniumJavaWrapper::has_set_clipboard() {
|
2022-03-15 13:29:32 +01:00
|
|
|
return _set_clipboard != 0;
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
void PandemoniumJavaWrapper::set_clipboard(const String &p_text) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_set_clipboard) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND(env == nullptr);
|
|
|
|
|
|
|
|
jstring jStr = env->NewStringUTF(p_text.utf8().get_data());
|
2022-03-23 20:46:05 +01:00
|
|
|
env->CallVoidMethod(pandemonium_instance, _set_clipboard, jStr);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
bool PandemoniumJavaWrapper::has_has_clipboard() {
|
2022-03-15 13:29:32 +01:00
|
|
|
return _has_clipboard != 0;
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
bool PandemoniumJavaWrapper::has_clipboard() {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_has_clipboard) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND_V(env == nullptr, false);
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
return env->CallBooleanMethod(pandemonium_instance, _has_clipboard);
|
2022-03-15 13:29:32 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
bool PandemoniumJavaWrapper::request_permission(const String &p_name) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_request_permission) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND_V(env == nullptr, false);
|
|
|
|
|
|
|
|
jstring jStrName = env->NewStringUTF(p_name.utf8().get_data());
|
2022-03-23 20:46:05 +01:00
|
|
|
return env->CallBooleanMethod(pandemonium_instance, _request_permission, jStrName);
|
2022-03-15 13:29:32 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
bool PandemoniumJavaWrapper::request_permissions() {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_request_permissions) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND_V(env == nullptr, false);
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
return env->CallBooleanMethod(pandemonium_instance, _request_permissions);
|
2022-03-15 13:29:32 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
Vector<String> PandemoniumJavaWrapper::get_granted_permissions() const {
|
2022-03-15 13:29:32 +01:00
|
|
|
Vector<String> permissions_list;
|
|
|
|
if (_get_granted_permissions) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND_V(env == nullptr, permissions_list);
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
jobject permissions_object = env->CallObjectMethod(pandemonium_instance, _get_granted_permissions);
|
2022-03-15 13:29:32 +01:00
|
|
|
jobjectArray *arr = reinterpret_cast<jobjectArray *>(&permissions_object);
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
jsize len = env->GetArrayLength(*arr);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
jstring jstr = (jstring)env->GetObjectArrayElement(*arr, i);
|
|
|
|
String str = jstring_to_string(jstr, env);
|
|
|
|
permissions_list.push_back(str);
|
|
|
|
env->DeleteLocalRef(jstr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return permissions_list;
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
void PandemoniumJavaWrapper::init_input_devices() {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_init_input_devices) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND(env == nullptr);
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
env->CallVoidMethod(pandemonium_instance, _init_input_devices);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
jobject PandemoniumJavaWrapper::get_surface() {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_get_surface) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND_V(env == nullptr, nullptr);
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
return env->CallObjectMethod(pandemonium_instance, _get_surface);
|
2022-03-15 13:29:32 +01:00
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
bool PandemoniumJavaWrapper::is_activity_resumed() {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_is_activity_resumed) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND_V(env == nullptr, false);
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
return env->CallBooleanMethod(pandemonium_instance, _is_activity_resumed);
|
2022-03-15 13:29:32 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
void PandemoniumJavaWrapper::vibrate(int p_duration_ms) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (_vibrate) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND(env == nullptr);
|
|
|
|
|
2022-03-23 20:46:05 +01:00
|
|
|
env->CallVoidMethod(pandemonium_instance, _vibrate, p_duration_ms);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-22 19:35:57 +01:00
|
|
|
|
2023-02-07 02:44:47 +01:00
|
|
|
int PandemoniumJavaWrapper::create_new_pandemonium_instance(List<String> args) {
|
2022-03-23 20:46:05 +01:00
|
|
|
if (_create_new_pandemonium_instance) {
|
2022-03-22 19:35:57 +01:00
|
|
|
JNIEnv *env = get_jni_env();
|
2023-02-07 02:44:47 +01:00
|
|
|
|
|
|
|
ERR_FAIL_NULL_V(env, 0);
|
2022-03-22 19:35:57 +01:00
|
|
|
|
|
|
|
jobjectArray jargs = env->NewObjectArray(args.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));
|
|
|
|
for (int i = 0; i < args.size(); i++) {
|
|
|
|
env->SetObjectArrayElement(jargs, i, env->NewStringUTF(args[i].utf8().get_data()));
|
|
|
|
}
|
2023-02-07 02:44:47 +01:00
|
|
|
|
|
|
|
return env->CallIntMethod(pandemonium_instance, _create_new_pandemonium_instance, jargs);
|
|
|
|
} else {
|
|
|
|
return 0;
|
2022-03-22 19:35:57 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-28 13:21:41 +02:00
|
|
|
|
|
|
|
void PandemoniumJavaWrapper::request_framebuffer_swap() {
|
|
|
|
if (_request_framebuffer_swap) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND(env == nullptr);
|
|
|
|
|
|
|
|
env->CallVoidMethod(pandemonium_instance, _request_framebuffer_swap);
|
|
|
|
}
|
2023-05-01 15:32:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PandemoniumJavaWrapper::begin_benchmark_measure(const String &p_label) {
|
|
|
|
if (_begin_benchmark_measure) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_NULL(env);
|
|
|
|
jstring j_label = env->NewStringUTF(p_label.utf8().get_data());
|
|
|
|
env->CallVoidMethod(pandemonium_instance, _begin_benchmark_measure, j_label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PandemoniumJavaWrapper::end_benchmark_measure(const String &p_label) {
|
|
|
|
if (_end_benchmark_measure) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_NULL(env);
|
|
|
|
jstring j_label = env->NewStringUTF(p_label.utf8().get_data());
|
|
|
|
env->CallVoidMethod(pandemonium_instance, _end_benchmark_measure, j_label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PandemoniumJavaWrapper::dump_benchmark(const String &benchmark_file) {
|
|
|
|
if (_dump_benchmark) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_NULL(env);
|
|
|
|
jstring j_benchmark_file = env->NewStringUTF(benchmark_file.utf8().get_data());
|
|
|
|
env->CallVoidMethod(pandemonium_instance, _dump_benchmark, j_benchmark_file);
|
|
|
|
}
|
2022-03-28 13:21:41 +02:00
|
|
|
}
|