aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt')
-rw-r--r--src/newt/classes/com/jogamp/newt/opengl/GLWindow.java2
-rw-r--r--src/newt/classes/jogamp/newt/DisplayImpl.java14
-rw-r--r--src/newt/classes/jogamp/newt/driver/x11/X11Display.java45
-rw-r--r--src/newt/classes/jogamp/newt/driver/x11/X11Window.java8
-rw-r--r--src/newt/native/X11Window.c42
5 files changed, 74 insertions, 37 deletions
diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
index f477cd3fc..e0776f58d 100644
--- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
+++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
@@ -124,6 +124,8 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer, FPSC
* with the given GLCapabilities.
* <P>
* The resulting GLWindow owns the Window, Screen and Device, ie it will be destructed.
+ * <P>
+ * The default display connection will be used and reused if already in process.
*/
public static GLWindow create(GLCapabilitiesImmutable caps) {
return new GLWindow(NewtFactory.createWindow(caps));
diff --git a/src/newt/classes/jogamp/newt/DisplayImpl.java b/src/newt/classes/jogamp/newt/DisplayImpl.java
index dc07bd180..4154059e2 100644
--- a/src/newt/classes/jogamp/newt/DisplayImpl.java
+++ b/src/newt/classes/jogamp/newt/DisplayImpl.java
@@ -51,10 +51,10 @@ public abstract class DisplayImpl extends Display {
private static int serialno = 1;
- private static Class getDisplayClass(String type)
+ private static Class<?> getDisplayClass(String type)
throws ClassNotFoundException
{
- Class displayClass = NewtFactory.getCustomClass(type, "Display");
+ Class<?> displayClass = NewtFactory.getCustomClass(type, "Display");
if(null==displayClass) {
if (NativeWindowFactory.TYPE_ANDROID.equals(type)) {
displayClass = Class.forName("jogamp.newt.driver.android.AndroidDisplay");
@@ -78,7 +78,7 @@ public abstract class DisplayImpl extends Display {
/** Make sure to reuse a Display with the same name */
public static Display create(String type, String name, final long handle, boolean reuse) {
try {
- Class displayClass = getDisplayClass(type);
+ Class<?> displayClass = getDisplayClass(type);
DisplayImpl display = (DisplayImpl) displayClass.newInstance();
name = display.validateDisplayName(name, handle);
synchronized(displayList) {
@@ -354,7 +354,7 @@ public abstract class DisplayImpl extends Display {
protected abstract void dispatchMessagesNative();
private Object eventsLock = new Object();
- private ArrayList/*<NEWTEvent>*/ events = new ArrayList();
+ private ArrayList<NEWTEventTask> events = new ArrayList<NEWTEventTask>();
private volatile boolean haveEvents = false;
class DispatchMessagesRunnable implements Runnable {
@@ -384,21 +384,21 @@ public abstract class DisplayImpl extends Display {
if(0==refCount) return; // no screens
if(null==getGraphicsDevice()) return; // no native device
- ArrayList/*<NEWTEvent>*/ _events = null;
+ ArrayList<NEWTEventTask> _events = null;
if(haveEvents) { // volatile: ok
synchronized(eventsLock) {
if(haveEvents) {
// swap events list to free ASAP
_events = events;
- events = new ArrayList();
+ events = new ArrayList<NEWTEventTask>();
haveEvents = false;
}
eventsLock.notifyAll();
}
if( null != _events ) {
for (int i=0; i < _events.size(); i++) {
- dispatchMessage((NEWTEventTask) _events.get(i));
+ dispatchMessage(_events.get(i));
}
}
}
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,
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);