summaryrefslogtreecommitdiffstats
path: root/src/jogl/native/GLDebugMessageHandler.c
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-01-11 02:11:47 +0100
committerSven Gothel <[email protected]>2014-01-11 02:11:47 +0100
commit6647b4a63866a554c738e0b7b61e6dc40a6fb511 (patch)
treeabc0c866524857b207d5beb406bc768c70c6c06a /src/jogl/native/GLDebugMessageHandler.c
parent5ef83c2b8576ccd764ffc4953eea506bd96277c3 (diff)
[Jogl|Nativewindow|Newt]Common: Align all *Common_GetJNIEnv()/_ReleaseJNIEnv() Methods and Usage / Check arguments ..
Since we still don't use inter-module native code sharing, align the JNIEnv get/release methods and usage. Most beneficary here is OSX and the GLDebugMessageHandle, both managed the JVM handle on their own - removed now. Also ensuring that *Common_init(..) is called for all modules on all platforms.
Diffstat (limited to 'src/jogl/native/GLDebugMessageHandler.c')
-rw-r--r--src/jogl/native/GLDebugMessageHandler.c95
1 files changed, 24 insertions, 71 deletions
diff --git a/src/jogl/native/GLDebugMessageHandler.c b/src/jogl/native/GLDebugMessageHandler.c
index 2e9d6033a..0aa7a01e7 100644
--- a/src/jogl/native/GLDebugMessageHandler.c
+++ b/src/jogl/native/GLDebugMessageHandler.c
@@ -49,8 +49,6 @@ JNIEXPORT jboolean JNICALL Java_jogamp_opengl_GLDebugMessageHandler_initIDs0
}
typedef struct {
- JavaVM *vm;
- int version;
jobject obj;
int extType;
} DebugHandlerType;
@@ -60,39 +58,21 @@ typedef struct {
static void GLDebugMessageARBCallback(GLenum source, GLenum type, GLuint id, GLenum severity,
GLsizei length, const GLchar *message, GLvoid *userParam) {
DebugHandlerType * handle = (DebugHandlerType*) (intptr_t) userParam;
- JavaVM *vm = handle->vm;
- int version = handle->version;
jobject obj = handle->obj;
- JNIEnv *curEnv = NULL;
- JNIEnv *newEnv = NULL;
- int envRes ;
- DBG_PRINT("GLDebugMessageARBCallback: 00 - %s, vm %p, version 0x%X, jobject %p, extType %d\n",
- message, handle->vm, handle->version, (void*)handle->obj, handle->extType);
-
- // retrieve this thread's JNIEnv curEnv - or detect it's detached
- envRes = (*vm)->GetEnv(vm, (void **) &curEnv, version) ;
- DBG_PRINT("GLDebugMessageARBCallback: 01 - JVM Env: curEnv %p, res 0x%X\n", curEnv, envRes);
- if( JNI_EDETACHED == envRes ) {
- // detached thread - attach to JVM
- if( JNI_OK != ( envRes = (*vm)->AttachCurrentThread(vm, (void**) &newEnv, NULL) ) ) {
- fprintf(stderr, "GLDebugMessageARBCallback: can't attach thread: %d\n", envRes);
- return;
- }
- curEnv = newEnv;
- DBG_PRINT("GLDebugMessageARBCallback: 02 - attached .. \n");
- } else if( JNI_OK != envRes ) {
- // oops ..
- fprintf(stderr, "GLDebugMessageARBCallback: can't GetEnv: %d\n", envRes);
+ JNIEnv *env = NULL;
+ int shallBeDetached ;
+ DBG_PRINT("GLDebugMessageARBCallback: 00 - %s, jobject %p, extType %d\n", message, (void*)handle->obj, handle->extType);
+
+ env = JoglCommon_GetJNIEnv (1 /* asDaemon */, &shallBeDetached);
+ if( NULL == env ) {
+ DBG_PRINT("GLDebugMessageARBCallback: Null JNIEnv\n");
return;
}
- (*curEnv)->CallVoidMethod(curEnv, obj, glDebugMessageARB,
+ (*env)->CallVoidMethod(env, obj, glDebugMessageARB,
(jint) source, (jint) type, (jint) id, (jint) severity,
- (*curEnv)->NewStringUTF(curEnv, message));
- if( NULL != newEnv ) {
- // detached attached thread
- (*vm)->DetachCurrentThread(vm);
- DBG_PRINT("GLDebugMessageARBCallback: 04 - detached .. \n");
- }
+ (*env)->NewStringUTF(env, message));
+ // detaching thread not required - daemon
+ // JoglCommon_ReleaseJNIEnv(shallBeDetached);
DBG_PRINT("GLDebugMessageARBCallback: 0X\n");
/**
* On Java 32bit on 64bit Windows and w/ GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB disables,
@@ -104,39 +84,21 @@ static void GLDebugMessageARBCallback(GLenum source, GLenum type, GLuint id, GLe
static void GLDebugMessageAMDCallback(GLuint id, GLenum category, GLenum severity,
GLsizei length, const GLchar *message, GLvoid *userParam) {
DebugHandlerType * handle = (DebugHandlerType*) (intptr_t) userParam;
- JavaVM *vm = handle->vm;
- int version = handle->version;
jobject obj = handle->obj;
- JNIEnv *curEnv = NULL;
- JNIEnv *newEnv = NULL;
- int envRes ;
- DBG_PRINT("GLDebugMessageAMDCallback: 00 - %s, vm %p, version 0x%X, jobject %p, extType %d\n",
- message, handle->vm, handle->version, (void*)handle->obj, handle->extType);
-
- // retrieve this thread's JNIEnv curEnv - or detect it's detached
- envRes = (*vm)->GetEnv(vm, (void **) &curEnv, version) ;
- DBG_PRINT("GLDebugMessageAMDCallback: 01 - JVM Env: curEnv %p, res 0x%X\n", curEnv, envRes);
- if( JNI_EDETACHED == envRes ) {
- // detached thread - attach to JVM
- if( JNI_OK != ( envRes = (*vm)->AttachCurrentThread(vm, (void**) &newEnv, NULL) ) ) {
- fprintf(stderr, "GLDebugMessageAMDCallback: can't attach thread: %d\n", envRes);
- return;
- }
- curEnv = newEnv;
- DBG_PRINT("GLDebugMessageAMDCallback: 02 - attached .. \n");
- } else if( JNI_OK != envRes ) {
- // oops ..
- fprintf(stderr, "GLDebugMessageAMDCallback: can't GetEnv: %d\n", envRes);
+ JNIEnv *env = NULL;
+ int shallBeDetached ;
+ DBG_PRINT("GLDebugMessageAMDCallback: 00 - %s, jobject %p, extType %d\n", message, (void*)handle->obj, handle->extType);
+
+ env = JoglCommon_GetJNIEnv (1 /* asDaemon */, &shallBeDetached);
+ if( NULL == env ) {
+ DBG_PRINT("GLDebugMessageARBCallback: Null JNIEnv\n");
return;
}
- (*curEnv)->CallVoidMethod(curEnv, obj, glDebugMessageAMD,
+ (*env)->CallVoidMethod(env, obj, glDebugMessageAMD,
(jint) id, (jint) category, (jint) severity,
- (*curEnv)->NewStringUTF(curEnv, message));
- if( NULL != newEnv ) {
- // detached attached thread
- (*vm)->DetachCurrentThread(vm);
- DBG_PRINT("GLDebugMessageAMDCallback: 04 - detached .. \n");
- }
+ (*env)->NewStringUTF(env, message));
+ // detached attached thread not required - daemon
+ // JoglCommon_ReleaseJNIEnv(shallBeDetached);
DBG_PRINT("GLDebugMessageAMDCallback: 0X\n");
/**
* On Java 32bit on 64bit Windows,
@@ -153,18 +115,10 @@ static void GLDebugMessageAMDCallback(GLuint id, GLenum category, GLenum severit
JNIEXPORT jlong JNICALL Java_jogamp_opengl_GLDebugMessageHandler_register0
(JNIEnv *env, jobject obj, jlong procAddress, jint extType)
{
- JavaVM *vm;
DebugHandlerType * handle = malloc(sizeof(DebugHandlerType));
- if(0 != (*env)->GetJavaVM(env, &vm)) {
- vm = NULL;
- JoglCommon_throwNewRuntimeException(env, "GetJavaVM failed");
- }
- handle->vm = vm;
- handle->version = (*env)->GetVersion(env);
handle->obj = (*env)->NewGlobalRef(env, obj);
handle->extType = extType;
- DBG_PRINT("GLDebugMessageHandler.register0: vm %p, version 0x%X, jobject %p, extType %d\n",
- handle->vm, handle->version, (void*)handle->obj, handle->extType);
+ DBG_PRINT("GLDebugMessageHandler.register0: jobject %p, extType %d\n", (void*)handle->obj, handle->extType);
if(jogamp_opengl_GLDebugMessageHandler_EXT_ARB == extType) {
_local_PFNGLDEBUGMESSAGECALLBACKARBPROC ptr_glDebugMessageCallbackARB;
@@ -191,8 +145,7 @@ JNIEXPORT void JNICALL Java_jogamp_opengl_GLDebugMessageHandler_unregister0
{
DebugHandlerType * handle = (DebugHandlerType*) (intptr_t) jhandle;
- DBG_PRINT("GLDebugMessageHandler.unregister0: vm %p, version 0x%X, jobject %p, extType %d\n",
- handle->vm, handle->version, (void*)handle->obj, handle->extType);
+ DBG_PRINT("GLDebugMessageHandler.unregister0: jobject %p, extType %d\n", (void*)handle->obj, handle->extType);
if(JNI_FALSE == (*env)->IsSameObject(env, obj, handle->obj)) {
JoglCommon_throwNewRuntimeException(env, "wrong handle (obj doesn't match)");