diff options
author | Sven Gothel <[email protected]> | 2011-10-13 17:04:17 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-10-13 17:04:17 +0200 |
commit | d186f6e945fd157b219231fb3861b3b0ce10ee75 (patch) | |
tree | b3851f97222cf224251956cb8ad06508c7a9d090 /src/nativewindow/native/NativewindowCommon.c | |
parent | 3fd89ccc138eddb915372cff4843f69f764048a7 (diff) |
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
Diffstat (limited to 'src/nativewindow/native/NativewindowCommon.c')
-rw-r--r-- | src/nativewindow/native/NativewindowCommon.c | 27 |
1 files changed, 27 insertions, 0 deletions
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; +} + |