diff options
author | Sven Gothel <[email protected]> | 2011-08-30 03:50:31 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-08-30 03:50:31 +0200 |
commit | 9ed513e9a9616f6028084df4c650c8caf31ea49d (patch) | |
tree | 5e8ea1af38a83d2e29b0762461e594153c133953 /src/newt/native/X11Window.c | |
parent | 9c64f265f4e3aaef85b7f017493e3695f46e00b3 (diff) |
Workaround (Fix) for Bug 502: Multithreading issue w/ libX11 1.4.2 and libxcb 1.7 bug 20708
See https://jogamp.org/bugzilla/show_bug.cgi?id=502
Since the libX11/xcb code doesn't seem to be fixed anytime soon
a better usable workaround is required than using a system property
to enable 'over locking'.
It turns out that the race condition is related to the parallel
X11 Display connection usage of GLX/OpenGL and event dispatching.
This workaround utilizes 2 X11 Display handles, one for windowing/OpenGL
and one for event dispatching.
This approach allows us to cont. multithreading use w/o locking the display
and works on both implementations, the old bug-free libX11 and the 'new' buggy one.
Downside is the little resource overhead of the 2nd X11 Display connection .. well.
- Removes the property: 'nativewindow.x11.mt-bug'
Diffstat (limited to 'src/newt/native/X11Window.c')
-rw-r--r-- | src/newt/native/X11Window.c | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index e0efac6e5..fc949b318 100644 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -301,7 +301,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_X11Display_CompleteDisplay0 NewtCommon_FatalError(env, "invalid display connection.."); } - javaObjectAtom = (jlong) XInternAtom(dpy, "JOGL_JAVA_OBJECT", False); + javaObjectAtom = (jlong) XInternAtom(dpy, "NEWT_JAVA_OBJECT", False); if(None==javaObjectAtom) { NewtCommon_throwNewRuntimeException(env, "could not create Atom JOGL_JAVA_OBJECT, bail out!"); return; @@ -559,7 +559,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_X11Display_DispatchMessages0 return ; } - // DBG_PRINT( "X11: DispatchMessages dpy %p, win %p, Event %d\n", (void*)dpy, (void*)evt.xany.window, evt.type); + DBG_PRINT( "X11: DispatchMessages dpy %p, win %p, Event %d\n", (void*)dpy, (void*)evt.xany.window, evt.type); displayDispatchErrorHandlerEnable(1, env); @@ -1270,13 +1270,15 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_X11Window_initIDs0 * Signature: (JJIJIIII)J */ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_X11Window_CreateWindow0 - (JNIEnv *env, jobject obj, jlong parent, jlong display, jint screen_index, + (JNIEnv *env, jobject obj, jlong parent, jlong display, jlong displayEDT, jint screen_index, jlong visualID, jlong javaObjectAtom, jlong windowDeleteAtom, jint x, jint y, jint width, jint height, jboolean undecorated) { Display * dpy = (Display *)(intptr_t)display; + Display * dpyEDT = (Display *)(intptr_t)displayEDT; + Atom wm_delete_atom = (Atom)windowDeleteAtom; int scrn_idx = (int)screen_index; Window windowParent = (Window) parent; Window window = 0; @@ -1291,7 +1293,6 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_X11Window_CreateWindow0 int n; Screen* scrn; - Atom wm_delete_atom; if(dpy==NULL) { NewtCommon_FatalError(env, "invalid display connection.."); @@ -1342,7 +1343,7 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_X11Window_CreateWindow0 } attrMask = ( CWBackingStore | CWBackingPlanes | CWBackingPixel | CWBackPixmap | - CWBorderPixel | CWColormap | CWOverrideRedirect | CWEventMask ) ; + CWBorderPixel | CWColormap | CWOverrideRedirect /* | CWEventMask */ ) ; memset(&xswa, 0, sizeof(xswa)); xswa.override_redirect = False; // use the window manager, always @@ -1351,9 +1352,7 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_X11Window_CreateWindow0 xswa.backing_store=NotUseful; /* NotUseful, WhenMapped, Always */ xswa.backing_planes=0; /* planes to be preserved if possible */ xswa.backing_pixel=0; /* value to use in restoring planes */ - xswa.event_mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask ; - xswa.event_mask |= KeyPressMask | KeyReleaseMask ; - xswa.event_mask |= FocusChangeMask | SubstructureNotifyMask | StructureNotifyMask | ExposureMask ; + xswa.event_mask = 0; /* using XSelectInput on EDT below */ xswa.colormap = XCreateColormap(dpy, windowParent, @@ -1376,14 +1375,22 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_X11Window_CreateWindow0 return 0; } - wm_delete_atom = (Atom)windowDeleteAtom; - XSetWMProtocols(dpy, window, &wm_delete_atom, 1); - - setJavaWindowProperty(env, dpy, window, javaObjectAtom, (*env)->NewGlobalRef(env, obj)); - NewtWindows_setDecorations(dpy, window, ( JNI_TRUE == undecorated ) ? False : True ); XSync(dpy, False); + XSetWMProtocols(dpyEDT, window, &wm_delete_atom, 1); + setJavaWindowProperty(env, dpyEDT, window, javaObjectAtom, (*env)->NewGlobalRef(env, obj)); + + { + long xevent_mask = 0; + xevent_mask |= ButtonPressMask | ButtonReleaseMask | PointerMotionMask ; + xevent_mask |= KeyPressMask | KeyReleaseMask ; + xevent_mask |= FocusChangeMask | SubstructureNotifyMask | StructureNotifyMask | ExposureMask ; + + XSelectInput(dpyEDT, window, xevent_mask); + } + XSync(dpyEDT, False); + DBG_PRINT( "X11: [CreateWindow] created window %p on display %p\n", (void*)window, dpy); return (jlong) window; } @@ -1394,9 +1401,10 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_X11Window_CreateWindow0 * Signature: (JJ)V */ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_X11Window_CloseWindow0 - (JNIEnv *env, jobject obj, jlong display, jlong window, jlong javaObjectAtom, jlong wmDeleteAtom) + (JNIEnv *env, jobject obj, jlong display, jlong displayEDT, jlong window, jlong javaObjectAtom, jlong wmDeleteAtom) { Display * dpy = (Display *) (intptr_t) display; + Display * dpyEDT = (Display *) (intptr_t) displayEDT; Window w = (Window)window; jobject jwindow; @@ -1406,7 +1414,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_X11Window_CloseWindow0 DBG_PRINT( "X11: CloseWindow START dpy %p, win %p\n", (void*)dpy, (void*)w); - jwindow = getJavaWindowProperty(env, dpy, w, javaObjectAtom, True); + jwindow = getJavaWindowProperty(env, dpyEDT, w, javaObjectAtom, True); if(NULL==jwindow) { NewtCommon_throwNewRuntimeException(env, "could not fetch Java Window object, bail out!"); return; @@ -1417,11 +1425,11 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_X11Window_CloseWindow0 } XSync(dpy, False); - XSelectInput(dpy, w, 0); + XSelectInput(dpyEDT, w, 0); XUnmapWindow(dpy, w); // Drain all events related to this window .. - Java_jogamp_newt_driver_x11_X11Display_DispatchMessages0(env, obj, display, javaObjectAtom, wmDeleteAtom); + Java_jogamp_newt_driver_x11_X11Display_DispatchMessages0(env, obj, displayEDT, javaObjectAtom, wmDeleteAtom); XDestroyWindow(dpy, w); XSync(dpy, False); |