aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-08-30 03:50:31 +0200
committerSven Gothel <[email protected]>2011-08-30 03:50:31 +0200
commit9ed513e9a9616f6028084df4c650c8caf31ea49d (patch)
tree5e8ea1af38a83d2e29b0762461e594153c133953 /src/newt/classes/jogamp
parent9c64f265f4e3aaef85b7f017493e3695f46e00b3 (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/classes/jogamp')
-rw-r--r--src/newt/classes/jogamp/newt/driver/x11/X11Display.java45
-rw-r--r--src/newt/classes/jogamp/newt/driver/x11/X11Window.java8
2 files changed, 40 insertions, 13 deletions
diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Display.java b/src/newt/classes/jogamp/newt/driver/x11/X11Display.java
index 483556f82..94e5a0bcc 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/X11Display.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/X11Display.java
@@ -69,14 +69,23 @@ public class X11Display extends DisplayImpl {
if( 0 == handle ) {
throw new RuntimeException("Error creating display: "+name);
}
+ if(USE_SEPARATE_DISPLAY_FOR_EDT) {
+ edtDisplayHandle = X11Util.createDisplay(name);
+ if( 0 == edtDisplayHandle ) {
+ X11Util.closeDisplay(handle);
+ throw new RuntimeException("Error creating display(EDT): "+name);
+ }
+ } else {
+ edtDisplayHandle = handle;
+ }
try {
- CompleteDisplay0(handle);
+ CompleteDisplay0(edtDisplayHandle);
} catch(RuntimeException e) {
- X11Util.closeDisplay(handle);
+ closeNativeImpl();
throw e;
}
- if(X11Util.XINITTHREADS_ALWAYS_ENABLED && !X11Util.MULTITHREADING_BUG) {
+ if(X11Util.XINITTHREADS_ALWAYS_ENABLED) {
// Hack: Force non X11Display locking, even w/ AWT and w/o isFirstUIActionOnProcess()
aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, NativeWindowFactory.getNullToolkitLock());
} else {
@@ -86,25 +95,29 @@ public class X11Display extends DisplayImpl {
}
protected void closeNativeImpl() {
- X11Util.closeDisplay(getHandle());
+ final long handle = getHandle();
+ if(handle != edtDisplayHandle) {
+ X11Util.closeDisplay(edtDisplayHandle);
+ }
+ X11Util.closeDisplay(handle);
}
protected void dispatchMessagesNative() {
- long dpy = getHandle();
- if(0!=dpy) {
- DispatchMessages0(dpy, javaObjectAtom, windowDeleteAtom);
+ if(0 != edtDisplayHandle) {
+ DispatchMessages0(edtDisplayHandle, javaObjectAtom, windowDeleteAtom);
}
}
+ protected long getEDTHandle() { return edtDisplayHandle; }
protected long getJavaObjectAtom() { return javaObjectAtom; }
protected long getWindowDeleteAtom() { return windowDeleteAtom; }
-
+
//----------------------------------------------------------------------
// Internals only
//
private static native boolean initIDs0();
- private native void CompleteDisplay0(long handle);
+ private native void CompleteDisplay0(long handleEDT);
private native void DispatchMessages0(long display, long javaObjectAtom, long windowDeleteAtom);
@@ -113,7 +126,21 @@ public class X11Display extends DisplayImpl {
this.windowDeleteAtom=windowDeleteAtom;
}
+ /**
+ * 2011/06/14 libX11 1.4.2 and libxcb 1.7 bug 20708 - Multithreading Issues w/ OpenGL, ..
+ * https://bugs.freedesktop.org/show_bug.cgi?id=20708
+ * https://jogamp.org/bugzilla/show_bug.cgi?id=502
+ * Affects: Ubuntu 11.04, OpenSuSE 11, ..
+ * Workaround: Using a separate X11 Display connection for event dispatching (EDT)
+ */
+ private final boolean USE_SEPARATE_DISPLAY_FOR_EDT = true;
+
+ private long edtDisplayHandle;
+
+ /** X11 Window delete atom marker used on EDT */
private long windowDeleteAtom;
+
+ /** X11 Window java object property used on EDT */
private long javaObjectAtom;
}
diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
index 19a0c7626..cbb43934b 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
@@ -64,7 +64,7 @@ public class X11Window extends WindowImpl {
X11GraphicsConfiguration x11config = (X11GraphicsConfiguration) config;
long visualID = x11config.getVisualID();
long w = CreateWindow0(getParentWindowHandle(),
- display.getHandle(), screen.getIndex(), visualID,
+ display.getHandle(), display.getEDTHandle(), screen.getIndex(), visualID,
display.getJavaObjectAtom(), display.getWindowDeleteAtom(),
x, y, width, height, isUndecorated());
if (w == 0) {
@@ -78,7 +78,7 @@ public class X11Window extends WindowImpl {
if(0!=windowHandleClose && null!=getScreen() ) {
X11Display display = (X11Display) getScreen().getDisplay();
try {
- CloseWindow0(display.getHandle(), windowHandleClose,
+ CloseWindow0(display.getHandle(), display.getEDTHandle(), windowHandleClose,
display.getJavaObjectAtom(), display.getWindowDeleteAtom());
} catch (Throwable t) {
if(DEBUG_IMPLEMENTATION) {
@@ -124,10 +124,10 @@ public class X11Window extends WindowImpl {
//
protected static native boolean initIDs0();
- private native long CreateWindow0(long parentWindowHandle, long display, int screen_index,
+ private native long CreateWindow0(long parentWindowHandle, long display, long displayEDT, int screen_index,
long visualID, long javaObjectAtom, long windowDeleteAtom,
int x, int y, int width, int height, boolean undecorated);
- private native void CloseWindow0(long display, long windowHandle, long javaObjectAtom, long windowDeleteAtom);
+ private native void CloseWindow0(long display, long displayEDT, long windowHandle, long javaObjectAtom, long windowDeleteAtom);
private native void setVisible0(long display, long windowHandle, boolean visible, int x, int y, int width, int height);
private native void reconfigureWindow0(long display, int screen_index, long parentWindowHandle, long windowHandle,
int x, int y, int width, int height, boolean isVisible,