From d186f6e945fd157b219231fb3861b3b0ce10ee75 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 13 Oct 2011 17:04:17 +0200 Subject: OSX/SWT: Adding OSXUtil: RunOnMainThread(), IsMainThread() / Utilizing those for SWT access/calls Adding OSXUtil: RunOnMainThread(), IsMainThread() - Issuing a native call where the user Runnable is to be performed on the main thread - Enable query if we are on the main thread. Utilizing those for SWT access/calls - Using the above to call all SWT functions on the main thread if required (incomplete) TODO/Issues: - JOGL OSX CGL Context fails, ie expecting NS, but having CGL --- src/nativewindow/native/NativewindowCommon.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/nativewindow/native/NativewindowCommon.c') diff --git a/src/nativewindow/native/NativewindowCommon.c b/src/nativewindow/native/NativewindowCommon.c index e357045d6..b866646a6 100644 --- a/src/nativewindow/native/NativewindowCommon.c +++ b/src/nativewindow/native/NativewindowCommon.c @@ -55,3 +55,30 @@ jchar* NativewindowCommon_GetNullTerminatedStringChars(JNIEnv* env, jstring str) return strChars; } +JNIEnv* NativewindowCommon_GetJNIEnv (JavaVM * jvmHandle, int jvmVersion, int * shallBeDetached) { + JNIEnv* curEnv = NULL; + JNIEnv* newEnv = NULL; + int envRes; + + // retrieve this thread's JNIEnv curEnv - or detect it's detached + envRes = (*jvmHandle)->GetEnv(jvmHandle, (void **) &curEnv, jvmVersion) ; + if( JNI_EDETACHED == envRes ) { + // detached thread - attach to JVM + if( JNI_OK != ( envRes = (*jvmHandle)->AttachCurrentThread(jvmHandle, (void**) &newEnv, NULL) ) ) { + fprintf(stderr, "JNIEnv: can't attach thread: %d\n", envRes); + return NULL; + } + curEnv = newEnv; + } else if( JNI_OK != envRes ) { + // oops .. + fprintf(stderr, "can't GetEnv: %d\n", envRes); + return NULL; + } + if (curEnv==NULL) { + fprintf(stderr, "env is NULL\n"); + return NULL; + } + *shallBeDetached = NULL != newEnv; + return curEnv; +} + -- cgit v1.2.3