diff --git a/gl-dri-natives/pom.xml b/gl-dri-natives/pom.xml index d748892..29e8fd2 100644 --- a/gl-dri-natives/pom.xml +++ b/gl-dri-natives/pom.xml @@ -9,7 +9,26 @@ openrs2-gl-dri-natives - jar + nar OpenRS2 GL DRI Natives + + + + + com.github.maven-nar + nar-maven-plugin + + + + + shared + dl + + + + + + + diff --git a/gl-dri-natives/src/main/c/jaggl_dri.c b/gl-dri-natives/src/main/c/jaggl_dri.c new file mode 100644 index 0000000..520d4e4 --- /dev/null +++ b/gl-dri-natives/src/main/c/jaggl_dri.c @@ -0,0 +1,29 @@ +#include "jaggl_X11_dri.h" + +#include +#include + +static void *jaggl_dri_handle; + +JNIEXPORT jboolean JNICALL Java_jaggl_X11_dri_open(JNIEnv *env, jclass cls, jstring path) { + if (jaggl_dri_handle) { + dlclose(jaggl_dri_handle); + jaggl_dri_handle = NULL; + } + + const char *path_str = (*env)->GetStringUTFChars(env, path, NULL); + jaggl_dri_handle = dlopen(path_str, RTLD_LAZY | RTLD_GLOBAL); + (*env)->ReleaseStringUTFChars(env, path, path_str); + + return jaggl_dri_handle != NULL; +} + +JNIEXPORT jboolean JNICALL Java_jaggl_X11_dri_close(JNIEnv *env, jclass cls) { + if (jaggl_dri_handle) { + dlclose(jaggl_dri_handle); + jaggl_dri_handle = NULL; + return JNI_TRUE; + } + + return JNI_FALSE; +}