Repository navigation
Expand file tree
/
Copy pathmojoexec.c
More file actions
64 lines (55 loc) · 2.07 KB
/
Copy pathmojoexec.c
File metadata and controls
64 lines (55 loc) · 2.07 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
//
// 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>
#include "utils.h"
#include "paths.h"
mojoexec_renderspec_t mojoexec_renderspec;
const char* mojoexec_native_dir = NULL;
char* native_egl_path = NULL;
bool egl_use_bypass = false;
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 && !get_primary_namespace()) 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 (mojoexec namespace: %b)\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) {
struct android_namespace_t* ns = get_primary_namespace();
if(ns == NULL) return NULL;
return linker_ns_dlopen(ns, native_egl_path, flags);
}
else return dlopen(native_egl_path, flags);
}