Repository navigation
Expand file tree
/
Copy pathmojoexec.c
More file actions
69 lines (59 loc) · 2.24 KB
/
Copy pathmojoexec.c
File metadata and controls
69 lines (59 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// Created by maks on 30.06.2026.
//
#include <mojoexec.h>
#include <jni.h>
#include <string.h>
#include <stdlib.h>
#include <driver_helper/nsbypass.h>
#include <dlfcn.h>
mojoexec_renderspec_t mojoexec_renderspec;
const char* mojoexec_native_dir = NULL;
char* native_egl_path = NULL;
bool egl_use_bypass = false;
static void save_jvm_string(JNIEnv* env, char** target, jstring str) {
if(*target != NULL) free(*target);
if(str == NULL) {
*target = NULL;
return;
}
const char* path = (*env)->GetStringUTFChars(env, str, NULL);
*target = strdup(path);
(*env)->ReleaseStringUTFChars(env, str, path);
}
JNIEXPORT jboolean JNICALL
Java_git_artdeell_mojoexec_MojoExec_prepareEgl(JNIEnv *env, jclass clazz, jstring egl_path,
jboolean use_bypass, jboolean use_gles,
jint gles_version) {
save_jvm_string(env, &native_egl_path, egl_path);
if(native_egl_path == NULL) return false;
if(use_bypass && !linker_ns_load(mojoexec_native_dir)) return false;
egl_use_bypass = use_bypass;
void* preload_handle = mojoexec_acq_egl_handle();
if(!preload_handle) {
printf("MojoExec: Failed to load EGL: %s\n", dlerror());
return false;
}
printf("MojoExec: Loaded EGL %s (in namespace: %i)\n", native_egl_path, egl_use_bypass);
mojoexec_renderspec.force_gles_context = use_gles;
mojoexec_renderspec.override_major_version = gles_version;
return true;
}
JNIEXPORT void JNICALL
Java_git_artdeell_mojoexec_MojoExec_setNativeLibraryDir(JNIEnv *env, jclass clazz, jstring dir) {
save_jvm_string(env, (char **) &mojoexec_native_dir, dir);
return;
}
JNIEXPORT void JNICALL
Java_git_artdeell_mojoexec_MojoExec_setDisplayParams(JNIEnv *env, jclass clazz, jint width,
jint height, jfloat hz) {
// TODO: implement setDisplayParams()
mojoexec_renderspec.disp_width = width;
mojoexec_renderspec.disp_height = height;
mojoexec_renderspec.disp_hz = hz;
}
void* mojoexec_acq_egl_handle() {
int flags = RTLD_LOCAL | RTLD_NOW;
if(egl_use_bypass) return linker_ns_dlopen(native_egl_path, flags);
else return dlopen(native_egl_path, flags);
}