mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 09:25:38 +00:00
app/internal/window: don't rely on JNI_OnCreate for getting the JavaVM
We're about to remove the global JNI_OnLoad constructor, and the JavaVM singleton is just as easily fetched from a Java JNI callback. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -10,8 +10,6 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
setJVM(vm);
|
|
||||||
|
|
||||||
jclass viewClass = (*env)->FindClass(env, "org/gioui/GioView");
|
jclass viewClass = (*env)->FindClass(env, "org/gioui/GioView");
|
||||||
if (viewClass == NULL) {
|
if (viewClass == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -105,6 +103,10 @@ jint gio_jni_GetEnv(JavaVM *vm, JNIEnv **env, jint version) {
|
|||||||
return (*vm)->GetEnv(vm, (void **)env, version);
|
return (*vm)->GetEnv(vm, (void **)env, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jint gio_jni_GetJavaVM(JNIEnv *env, JavaVM **jvm) {
|
||||||
|
return (*env)->GetJavaVM(env, jvm);
|
||||||
|
}
|
||||||
|
|
||||||
jint gio_jni_AttachCurrentThread(JavaVM *vm, JNIEnv **p_env, void *thr_args) {
|
jint gio_jni_AttachCurrentThread(JavaVM *vm, JNIEnv **p_env, void *thr_args) {
|
||||||
return (*vm)->AttachCurrentThread(vm, p_env, thr_args);
|
return (*vm)->AttachCurrentThread(vm, p_env, thr_args);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,9 @@ func jniGetStaticMethodID(env *C.JNIEnv, class C.jclass, method, sig string) C.j
|
|||||||
|
|
||||||
//export runGoMain
|
//export runGoMain
|
||||||
func runGoMain(env *C.JNIEnv, class C.jclass, jdataDir C.jbyteArray, context C.jobject) {
|
func runGoMain(env *C.JNIEnv, class C.jclass, jdataDir C.jbyteArray, context C.jobject) {
|
||||||
|
if res := C.gio_jni_GetJavaVM(env, &theJVM); res != 0 {
|
||||||
|
panic("gio: GetJavaVM failed")
|
||||||
|
}
|
||||||
dirBytes := C.gio_jni_GetByteArrayElements(env, jdataDir)
|
dirBytes := C.gio_jni_GetByteArrayElements(env, jdataDir)
|
||||||
if dirBytes == nil {
|
if dirBytes == nil {
|
||||||
panic("runGoMain: GetByteArrayElements failed")
|
panic("runGoMain: GetByteArrayElements failed")
|
||||||
@@ -113,11 +116,6 @@ func GetDataDir() string {
|
|||||||
return <-dataDirChan
|
return <-dataDirChan
|
||||||
}
|
}
|
||||||
|
|
||||||
//export setJVM
|
|
||||||
func setJVM(vm *C.JavaVM) {
|
|
||||||
theJVM = vm
|
|
||||||
}
|
|
||||||
|
|
||||||
//export onCreateView
|
//export onCreateView
|
||||||
func onCreateView(env *C.JNIEnv, class C.jclass, view C.jobject) C.jlong {
|
func onCreateView(env *C.JNIEnv, class C.jclass, view C.jobject) C.jlong {
|
||||||
view = C.gio_jni_NewGlobalRef(env, view)
|
view = C.gio_jni_NewGlobalRef(env, view)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// SPDX-License-Identifier: Unlicense OR MIT
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
__attribute__ ((visibility ("hidden"))) jint gio_jni_GetEnv(JavaVM *vm, JNIEnv **env, jint version);
|
__attribute__ ((visibility ("hidden"))) jint gio_jni_GetEnv(JavaVM *vm, JNIEnv **env, jint version);
|
||||||
|
__attribute__ ((visibility ("hidden"))) jint gio_jni_GetJavaVM(JNIEnv *env, JavaVM **jvm);
|
||||||
__attribute__ ((visibility ("hidden"))) jint gio_jni_AttachCurrentThread(JavaVM *vm, JNIEnv **p_env, void *thr_args);
|
__attribute__ ((visibility ("hidden"))) jint gio_jni_AttachCurrentThread(JavaVM *vm, JNIEnv **p_env, void *thr_args);
|
||||||
__attribute__ ((visibility ("hidden"))) jint gio_jni_DetachCurrentThread(JavaVM *vm);
|
__attribute__ ((visibility ("hidden"))) jint gio_jni_DetachCurrentThread(JavaVM *vm);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user