diff options
-rw-r--r-- | CNativeCode/jawt_misc.c | 65 | ||||
-rw-r--r-- | CNativeCode/jawt_misc.h | 5 | ||||
-rw-r--r-- | CNativeCode/jni12tools.c | 8 | ||||
-rw-r--r-- | gl4java/GLContext.java.skel | 64 |
4 files changed, 126 insertions, 16 deletions
diff --git a/CNativeCode/jawt_misc.c b/CNativeCode/jawt_misc.c index f906ba4..bdf8fe7 100644 --- a/CNativeCode/jawt_misc.c +++ b/CNativeCode/jawt_misc.c @@ -16,40 +16,93 @@ static int gds = 0; static jboolean jawtdebug = JNI_FALSE; +#ifdef _WIN32_ + static HMODULE hDLL_JAWT = 0; +#endif + +#ifdef _X11_ + static void * libHandleJAWT = 0; +#endif + + jboolean LIBAPIENTRY jawt_init (char* jawtLibName) { + #ifdef _WIN32_ - HMODULE lib = LoadLibrary(jawtLibName); - if (lib == NULL) { + + if ( hDLL_JAWT==NULL ) + hDLL_JAWT = LoadLibrary(jawtLibName); + + if ( hDLL_JAWT==NULL ) + { printf(" jawt_init: LoadLibrary failed\n"); return JNI_FALSE; } - JAWT_GetAWT_fn = (JAWT_GetAWT_fn_t*) GetProcAddress(lib, "_JAWT_GetAWT@8"); + + JAWT_GetAWT_fn = (JAWT_GetAWT_fn_t*) + GetProcAddress(hDLL_JAWT, "_JAWT_GetAWT@8"); + if (JAWT_GetAWT_fn == NULL) { printf(" jawt_init: GetProcAddress failed\n"); return JNI_FALSE; } return JNI_TRUE; + #endif #ifdef _X11_ - void* lib = dlopen(jawtLibName, RTLD_LAZY | RTLD_GLOBAL); - if (lib == NULL) { + + if ( libHandleJAWT == NULL ) + libHandleJAWT = dlopen(jawtLibName, RTLD_LAZY | RTLD_GLOBAL); + + if ( libHandleJAWT == NULL) { printf(" jawt_init: dlopen failed\n"); return JNI_FALSE; } - JAWT_GetAWT_fn = (JAWT_GetAWT_fn_t*) dlsym(lib, "JAWT_GetAWT"); + + JAWT_GetAWT_fn = (JAWT_GetAWT_fn_t*) dlsym(libHandleJAWT, "JAWT_GetAWT"); + if (JAWT_GetAWT_fn == NULL) { printf(" jawt_init: dlsym failed\n"); return JNI_FALSE; } + return JNI_TRUE; + #endif return JNI_FALSE; } +void LIBAPIENTRY +jawt_unload () +{ + +#ifdef _WIN32_ + + if ( hDLL_JAWT!=NULL ) + { + JAWT_GetAWT_fn = NULL; + FreeLibrary(hDLL_JAWT); + hDLL_JAWT = NULL; + } + +#endif + +#ifdef _X11_ + + if ( libHandleJAWT != NULL ) + { + JAWT_GetAWT_fn = NULL; + dlClose(libHandleJAWT); + libHandleJAWT = NULL; + } + +#endif + +} + jboolean LIBAPIENTRY jawt_create_offscreen (JNIEnv *env, JAWTDataHolder **ppJData, jboolean verbose) { diff --git a/CNativeCode/jawt_misc.h b/CNativeCode/jawt_misc.h index 293ffa9..4504b46 100644 --- a/CNativeCode/jawt_misc.h +++ b/CNativeCode/jawt_misc.h @@ -59,8 +59,9 @@ jboolean result; } JAWTDataHolder; - LIBAPI jboolean LIBAPIENTRY - jawt_init (char* jawtLibName); + LIBAPI jboolean LIBAPIENTRY jawt_init (char* jawtLibName); + + LIBAPI void LIBAPIENTRY jawt_unload(); LIBAPI jboolean LIBAPIENTRY jawt_create_offscreen (JNIEnv *env, JAWTDataHolder **ppJData, diff --git a/CNativeCode/jni12tools.c b/CNativeCode/jni12tools.c index 09b948a..4a13a52 100644 --- a/CNativeCode/jni12tools.c +++ b/CNativeCode/jni12tools.c @@ -1,7 +1,8 @@ #include <string.h> #include "jnitools.h" -
-#include "gltool.h"
+#include "jawt_misc.h" + +#include "gltool.h" #ifdef __BUILTIN_VA_ARG_INCR /* Special stuff for the SunOS port ... */ @@ -538,7 +539,8 @@ JNI_OnLoad(JavaVM * vm, void *reserved) JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) -{
+{ unloadGLLibrary(); + jawt_unload(); } diff --git a/gl4java/GLContext.java.skel b/gl4java/GLContext.java.skel index 1298f1c..3e11bc8 100644 --- a/gl4java/GLContext.java.skel +++ b/gl4java/GLContext.java.skel @@ -713,9 +713,17 @@ public class GLContext extends Object else + /** + * JAU - now, let's give IBM a try with awt .. + * if( jvmVersionMajor==1 && jvmVersionMinor>=3 && !isIBMJvm && !isMicrosoftJvm ) + */ + + if( jvmVersionMajor==1 && jvmVersionMinor>=3 + && !isMicrosoftJvm + ) { jniEXTsuff="13"; } @@ -847,7 +855,7 @@ public class GLContext extends Object return new Boolean(false); if (useJAWT()) { if (!loadJAWT()) { - System.err.println("ERROR while loading jawt.dll/libjawt.so"); + System.err.println("ERROR while loading [j]awt.dll/lib[j]awt.so"); return new Boolean(false); } } @@ -2186,17 +2194,63 @@ public class GLContext extends Object protected static final boolean loadJAWT() { // Locate jawt.dll/libjawt.so by looking through // java.library.path and sun.boot.library.path - String jawtName = makeLibName("jawt"); - String libpath = findInPath(System.getProperty("java.library.path"), jawtName); + String jawtName0 = makeLibName("jawt"); + String jawtName1 = makeLibName("awt"); + boolean found = false; + + String libpath = findInPath(System.getProperty("java.library.path"), jawtName0); + if (libpath == null) { - libpath = findInPath(System.getProperty("sun.boot.library.path"), jawtName); + libpath = findInPath(System.getProperty("sun.boot.library.path"), jawtName0); + } else if (gljClassDebug) { + System.err.println("Located: " + jawtName0 + ", within: java.library.path: "+ + System.getProperty("java.library.path")); + found = true; } + if (libpath == null) { - System.err.println("Unable to locate " + jawtName); + /** + * E.g. IBM's JVM + */ + if (gljClassDebug) + { + System.err.println("Unable to locate " + jawtName0); + System.err.println(" java.library.path = " + System.getProperty("java.library.path")); + System.err.println(" sun.boot.library.path = " + System.getProperty("sun.boot.library.path")); + System.err.println(" trying " + jawtName1); + } + + libpath = findInPath(System.getProperty("java.library.path"), jawtName1); + } else if (gljClassDebug && !found) { + System.err.println("Located: " + jawtName0 + ", within: sun.boot.library.path: "+ + System.getProperty("sun.boot.library.path")); + found = true; + } + + if (libpath == null) { + libpath = findInPath(System.getProperty("java.library.path"), jawtName1); + } + + if (libpath == null) { + libpath = findInPath(System.getProperty("sun.boot.library.path"), jawtName1); + } else if (gljClassDebug && !found) { + System.err.println("Located: " + jawtName1 + ", within: java.library.path: "+ + System.getProperty("java.library.path")); + found = true; + } + + if (libpath == null) { + System.err.println("Unable to locate neither " + jawtName0 + + " nor " + jawtName1 ); System.err.println(" java.library.path = " + System.getProperty("java.library.path")); System.err.println(" sun.boot.library.path = " + System.getProperty("sun.boot.library.path")); return false; + } else if (gljClassDebug && !found) { + System.err.println("Located: " + jawtName0 + ", within: sun.boot.library.path: "+ + System.getProperty("sun.boot.library.path")); + found = true; } + return loadJAWT0(libpath); } |