mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
app/internal/window: [Android] remove JNI_OnLoad JNI callback
There can only be one JNI_OnLoad callback per JNI library, and the Gio program may need it for its own purposes. Gio only used JNI_OnLoad for explicitly registering native methods. Switch to implicit name based registration and get rid of JNI_OnLoad. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -4,101 +4,6 @@
|
|||||||
#include "os_android.h"
|
#include "os_android.h"
|
||||||
#include "_cgo_export.h"
|
#include "_cgo_export.h"
|
||||||
|
|
||||||
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
|
||||||
JNIEnv *env;
|
|
||||||
if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
jclass viewClass = (*env)->FindClass(env, "org/gioui/GioView");
|
|
||||||
if (viewClass == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const JNINativeMethod methods[] = {
|
|
||||||
{
|
|
||||||
.name = "runGoMain",
|
|
||||||
.signature = "([BLandroid/content/Context;)V",
|
|
||||||
.fnPtr = runGoMain
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "onCreateView",
|
|
||||||
.signature = "(Lorg/gioui/GioView;)J",
|
|
||||||
.fnPtr = onCreateView
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "onDestroyView",
|
|
||||||
.signature = "(J)V",
|
|
||||||
.fnPtr = onDestroyView
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "onStartView",
|
|
||||||
.signature = "(J)V",
|
|
||||||
.fnPtr = onStartView
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "onStopView",
|
|
||||||
.signature = "(J)V",
|
|
||||||
.fnPtr = onStopView
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "onSurfaceDestroyed",
|
|
||||||
.signature = "(J)V",
|
|
||||||
.fnPtr = onSurfaceDestroyed
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "onSurfaceChanged",
|
|
||||||
.signature = "(JLandroid/view/Surface;)V",
|
|
||||||
.fnPtr = onSurfaceChanged
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "onConfigurationChanged",
|
|
||||||
.signature = "(J)V",
|
|
||||||
.fnPtr = onConfigurationChanged
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "onWindowInsets",
|
|
||||||
.signature = "(JIIII)V",
|
|
||||||
.fnPtr = onWindowInsets
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "onLowMemory",
|
|
||||||
.signature = "()V",
|
|
||||||
.fnPtr = onLowMemory
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "onTouchEvent",
|
|
||||||
.signature = "(JIIIFFIJ)V",
|
|
||||||
.fnPtr = onTouchEvent
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "onKeyEvent",
|
|
||||||
.signature = "(JIIJ)V",
|
|
||||||
.fnPtr = onKeyEvent
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "onFrameCallback",
|
|
||||||
.signature = "(JJ)V",
|
|
||||||
.fnPtr = onFrameCallback
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "onBack",
|
|
||||||
.signature = "(J)Z",
|
|
||||||
.fnPtr = onBack
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "onFocusChange",
|
|
||||||
.signature = "(JZ)V",
|
|
||||||
.fnPtr = onFocusChange
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if ((*env)->RegisterNatives(env, viewClass, methods, sizeof(methods)/sizeof(methods[0])) != 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return JNI_VERSION_1_6;
|
|
||||||
}
|
|
||||||
|
|
||||||
jint gio_jni_GetEnv(JavaVM *vm, JNIEnv **env, jint version) {
|
jint gio_jni_GetEnv(JavaVM *vm, JNIEnv **env, jint version) {
|
||||||
return (*vm)->GetEnv(vm, (void **)env, version);
|
return (*vm)->GetEnv(vm, (void **)env, version);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ func jniGetStaticMethodID(env *C.JNIEnv, class C.jclass, method, sig string) C.j
|
|||||||
return C.gio_jni_GetStaticMethodID(env, class, m, s)
|
return C.gio_jni_GetStaticMethodID(env, class, m, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export runGoMain
|
//export Java_org_gioui_GioView_runGoMain
|
||||||
func runGoMain(env *C.JNIEnv, class C.jclass, jdataDir C.jbyteArray, context C.jobject) {
|
func Java_org_gioui_GioView_runGoMain(env *C.JNIEnv, class C.jclass, jdataDir C.jbyteArray, context C.jobject) {
|
||||||
if res := C.gio_jni_GetJavaVM(env, &theJVM); res != 0 {
|
if res := C.gio_jni_GetJavaVM(env, &theJVM); res != 0 {
|
||||||
panic("gio: GetJavaVM failed")
|
panic("gio: GetJavaVM failed")
|
||||||
}
|
}
|
||||||
@@ -116,8 +116,8 @@ func GetDataDir() string {
|
|||||||
return <-dataDirChan
|
return <-dataDirChan
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onCreateView
|
//export Java_org_gioui_GioView_onCreateView
|
||||||
func onCreateView(env *C.JNIEnv, class C.jclass, view C.jobject) C.jlong {
|
func Java_org_gioui_GioView_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)
|
||||||
w := &window{
|
w := &window{
|
||||||
view: view,
|
view: view,
|
||||||
@@ -139,8 +139,8 @@ func onCreateView(env *C.JNIEnv, class C.jclass, view C.jobject) C.jlong {
|
|||||||
return handle
|
return handle
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onDestroyView
|
//export Java_org_gioui_GioView_onDestroyView
|
||||||
func onDestroyView(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
func Java_org_gioui_GioView_onDestroyView(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
||||||
w := views[handle]
|
w := views[handle]
|
||||||
w.callbacks.SetDriver(nil)
|
w.callbacks.SetDriver(nil)
|
||||||
delete(views, handle)
|
delete(views, handle)
|
||||||
@@ -148,15 +148,15 @@ func onDestroyView(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
|||||||
w.view = 0
|
w.view = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onStopView
|
//export Java_org_gioui_GioView_onStopView
|
||||||
func onStopView(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
func Java_org_gioui_GioView_onStopView(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
||||||
w := views[handle]
|
w := views[handle]
|
||||||
w.started = false
|
w.started = false
|
||||||
w.setStage(system.StagePaused)
|
w.setStage(system.StagePaused)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onStartView
|
//export Java_org_gioui_GioView_onStartView
|
||||||
func onStartView(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
func Java_org_gioui_GioView_onStartView(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
||||||
w := views[handle]
|
w := views[handle]
|
||||||
w.started = true
|
w.started = true
|
||||||
if w.aNativeWindow() != nil {
|
if w.aNativeWindow() != nil {
|
||||||
@@ -164,8 +164,8 @@ func onStartView(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onSurfaceDestroyed
|
//export Java_org_gioui_GioView_onSurfaceDestroyed
|
||||||
func onSurfaceDestroyed(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
func Java_org_gioui_GioView_onSurfaceDestroyed(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
||||||
w := views[handle]
|
w := views[handle]
|
||||||
w.mu.Lock()
|
w.mu.Lock()
|
||||||
w.win = nil
|
w.win = nil
|
||||||
@@ -173,8 +173,8 @@ func onSurfaceDestroyed(env *C.JNIEnv, class C.jclass, handle C.jlong) {
|
|||||||
w.setStage(system.StagePaused)
|
w.setStage(system.StagePaused)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onSurfaceChanged
|
//export Java_org_gioui_GioView_onSurfaceChanged
|
||||||
func onSurfaceChanged(env *C.JNIEnv, class C.jclass, handle C.jlong, surf C.jobject) {
|
func Java_org_gioui_GioView_onSurfaceChanged(env *C.JNIEnv, class C.jclass, handle C.jlong, surf C.jobject) {
|
||||||
w := views[handle]
|
w := views[handle]
|
||||||
w.mu.Lock()
|
w.mu.Lock()
|
||||||
w.win = C.ANativeWindow_fromSurface(env, surf)
|
w.win = C.ANativeWindow_fromSurface(env, surf)
|
||||||
@@ -184,14 +184,14 @@ func onSurfaceChanged(env *C.JNIEnv, class C.jclass, handle C.jlong, surf C.jobj
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onLowMemory
|
//export Java_org_gioui_GioView_onLowMemory
|
||||||
func onLowMemory() {
|
func Java_org_gioui_GioView_onLowMemory() {
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
debug.FreeOSMemory()
|
debug.FreeOSMemory()
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onConfigurationChanged
|
//export Java_org_gioui_GioView_onConfigurationChanged
|
||||||
func onConfigurationChanged(env *C.JNIEnv, class C.jclass, view C.jlong) {
|
func Java_org_gioui_GioView_onConfigurationChanged(env *C.JNIEnv, class C.jclass, view C.jlong) {
|
||||||
w := views[view]
|
w := views[view]
|
||||||
w.loadConfig(env, class)
|
w.loadConfig(env, class)
|
||||||
if w.stage >= system.StageRunning {
|
if w.stage >= system.StageRunning {
|
||||||
@@ -199,8 +199,8 @@ func onConfigurationChanged(env *C.JNIEnv, class C.jclass, view C.jlong) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onFrameCallback
|
//export Java_org_gioui_GioView_onFrameCallback
|
||||||
func onFrameCallback(env *C.JNIEnv, class C.jclass, view C.jlong, nanos C.jlong) {
|
func Java_org_gioui_GioView_onFrameCallback(env *C.JNIEnv, class C.jclass, view C.jlong, nanos C.jlong) {
|
||||||
w, exist := views[view]
|
w, exist := views[view]
|
||||||
if !exist {
|
if !exist {
|
||||||
return
|
return
|
||||||
@@ -219,8 +219,8 @@ func onFrameCallback(env *C.JNIEnv, class C.jclass, view C.jlong, nanos C.jlong)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onBack
|
//export Java_org_gioui_GioView_onBack
|
||||||
func onBack(env *C.JNIEnv, class C.jclass, view C.jlong) C.jboolean {
|
func Java_org_gioui_GioView_onBack(env *C.JNIEnv, class C.jclass, view C.jlong) C.jboolean {
|
||||||
w := views[view]
|
w := views[view]
|
||||||
ev := &system.CommandEvent{Type: system.CommandBack}
|
ev := &system.CommandEvent{Type: system.CommandBack}
|
||||||
w.callbacks.Event(ev)
|
w.callbacks.Event(ev)
|
||||||
@@ -230,14 +230,14 @@ func onBack(env *C.JNIEnv, class C.jclass, view C.jlong) C.jboolean {
|
|||||||
return C.JNI_FALSE
|
return C.JNI_FALSE
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onFocusChange
|
//export Java_org_gioui_GioView_onFocusChange
|
||||||
func onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean) {
|
func Java_org_gioui_GioView_onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean) {
|
||||||
w := views[view]
|
w := views[view]
|
||||||
w.callbacks.Event(key.FocusEvent{Focus: focus == C.JNI_TRUE})
|
w.callbacks.Event(key.FocusEvent{Focus: focus == C.JNI_TRUE})
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onWindowInsets
|
//export Java_org_gioui_GioView_onWindowInsets
|
||||||
func onWindowInsets(env *C.JNIEnv, class C.jclass, view C.jlong, top, right, bottom, left C.jint) {
|
func Java_org_gioui_GioView_onWindowInsets(env *C.JNIEnv, class C.jclass, view C.jlong, top, right, bottom, left C.jint) {
|
||||||
w := views[view]
|
w := views[view]
|
||||||
w.insets = system.Insets{
|
w.insets = system.Insets{
|
||||||
Top: unit.Px(float32(top)),
|
Top: unit.Px(float32(top)),
|
||||||
@@ -383,8 +383,8 @@ func convertKeyCode(code C.jint) (string, bool) {
|
|||||||
return n, true
|
return n, true
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onKeyEvent
|
//export Java_org_gioui_GioView_onKeyEvent
|
||||||
func onKeyEvent(env *C.JNIEnv, class C.jclass, handle C.jlong, keyCode, r C.jint, t C.jlong) {
|
func Java_org_gioui_GioView_onKeyEvent(env *C.JNIEnv, class C.jclass, handle C.jlong, keyCode, r C.jint, t C.jlong) {
|
||||||
w := views[handle]
|
w := views[handle]
|
||||||
if n, ok := convertKeyCode(keyCode); ok {
|
if n, ok := convertKeyCode(keyCode); ok {
|
||||||
w.callbacks.Event(key.Event{Name: n})
|
w.callbacks.Event(key.Event{Name: n})
|
||||||
@@ -394,8 +394,8 @@ func onKeyEvent(env *C.JNIEnv, class C.jclass, handle C.jlong, keyCode, r C.jint
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//export onTouchEvent
|
//export Java_org_gioui_GioView_onTouchEvent
|
||||||
func onTouchEvent(env *C.JNIEnv, class C.jclass, handle C.jlong, action, pointerID, tool C.jint, x, y C.jfloat, jbtns C.jint, t C.jlong) {
|
func Java_org_gioui_GioView_onTouchEvent(env *C.JNIEnv, class C.jclass, handle C.jlong, action, pointerID, tool C.jint, x, y C.jfloat, jbtns C.jint, t C.jlong) {
|
||||||
w := views[handle]
|
w := views[handle]
|
||||||
var typ pointer.Type
|
var typ pointer.Type
|
||||||
switch action {
|
switch action {
|
||||||
|
|||||||
Reference in New Issue
Block a user