From 7ae0f2df39692e82d7955dbcd09c35c36382726c Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Fri, 25 Nov 2011 00:26:23 +0100
Subject: NativeWindow X11GraphicsDevice: Pass 'owner' for close-display
 operation @ constructor

---
 .../jogamp/opengl/x11/glx/X11ExternalGLXContext.java      |  2 +-
 .../jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java     |  2 +-
 .../javax/media/nativewindow/x11/X11GraphicsDevice.java   | 15 ++++++---------
 .../javax/media/nativewindow/x11/X11GraphicsScreen.java   |  4 ++--
 .../classes/jogamp/nativewindow/swt/SWTAccessor.java      |  4 +++-
 src/newt/classes/jogamp/newt/driver/x11/X11Display.java   |  9 ++-------
 6 files changed, 15 insertions(+), 21 deletions(-)

(limited to 'src')

diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java
index d0d9929a0..e79c8b66c 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java
@@ -72,7 +72,7 @@ public class X11ExternalGLXContext extends X11GLXContext {
     }
     int[] val = new int[1];
     GLX.glXQueryContext(display, ctx, GLX.GLX_SCREEN, val, 0);
-    X11GraphicsScreen x11Screen = (X11GraphicsScreen) X11GraphicsScreen.createScreenDevice(display, val[0]);
+    X11GraphicsScreen x11Screen = (X11GraphicsScreen) X11GraphicsScreen.createScreenDevice(display, val[0], false);
 
     GLX.glXQueryContext(display, ctx, GLX.GLX_FBCONFIG_ID, val, 0);
     X11GLXGraphicsConfiguration cfg = null;
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java
index c3d2530f2..ca30fde3b 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java
@@ -66,7 +66,7 @@ public class X11ExternalGLXDrawable extends X11GLXDrawable {
     }
     int[] val = new int[1];
     GLX.glXQueryContext(display, context, GLX.GLX_SCREEN, val, 0);
-    X11GraphicsScreen x11Screen = (X11GraphicsScreen) X11GraphicsScreen.createScreenDevice(display, val[0]);
+    X11GraphicsScreen x11Screen = (X11GraphicsScreen) X11GraphicsScreen.createScreenDevice(display, val[0], false);
 
     GLX.glXQueryContext(display, context, GLX.GLX_FBCONFIG_ID, val, 0);
     X11GLXGraphicsConfiguration cfg = X11GLXGraphicsConfiguration.create(glp, x11Screen, val[0]);
diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java
index 317d3f3e9..b39fdb767 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java
@@ -44,7 +44,7 @@ import javax.media.nativewindow.ToolkitLock;
 
 public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
     public static final boolean DEBUG = Debug.debug("GraphicsDevice");
-    boolean closeDisplay = false;
+    final boolean closeDisplay;
 
     /** Constructs a new X11GraphicsDevice corresponding to the given connection and default
      *  {@link javax.media.nativewindow.ToolkitLock} via {@link NativeWindowFactory#getDefaultToolkitLock(String)}.<br>
@@ -54,18 +54,20 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl
      */
     public X11GraphicsDevice(String connection, int unitID) {
         super(NativeWindowFactory.TYPE_X11, connection, unitID);
+        closeDisplay = false;
     }
 
     /** Constructs a new X11GraphicsDevice corresponding to the given native display handle and default
      *  {@link javax.media.nativewindow.ToolkitLock} via {@link NativeWindowFactory#createDefaultToolkitLock(String, long)}.
      *  @see DefaultGraphicsDevice#DefaultGraphicsDevice(String, String, int, long)
      */
-    public X11GraphicsDevice(long display, int unitID) {
+    public X11GraphicsDevice(long display, int unitID, boolean owner) {
         // FIXME: derive unitID from connection could be buggy, one DISPLAY for all screens for example..
         super(NativeWindowFactory.TYPE_X11, X11Util.XDisplayString(display), unitID, display);
         if(0==display) {
             throw new NativeWindowException("null display");
         }
+        closeDisplay = owner;
     }
 
     /**
@@ -73,23 +75,18 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl
      * @param locker custom {@link javax.media.nativewindow.ToolkitLock}, eg to force null locking in NEWT
      * @see DefaultGraphicsDevice#DefaultGraphicsDevice(String, String, int, long, ToolkitLock)
      */
-    public X11GraphicsDevice(long display, int unitID, ToolkitLock locker) {
+    public X11GraphicsDevice(long display, int unitID, ToolkitLock locker, boolean owner) {
         super(NativeWindowFactory.TYPE_X11, X11Util.XDisplayString(display), unitID, display, locker);
         if(0==display) {
             throw new NativeWindowException("null display");
         }
+        closeDisplay = owner;
     }
 
     public Object clone() {
       return super.clone();
     }
 
-    public void setCloseDisplay(boolean close) {
-        closeDisplay = close;
-        if(DEBUG && close) {
-            System.err.println(Thread.currentThread().getName() + " - X11GraphicsDevice.setCloseDisplay(true): "+this);
-        }
-    }
     public boolean close() {
         // FIXME: shall we respect the unitID ?
         if(closeDisplay && 0 != handle) {
diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java
index ffe84cb6d..62b202463 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java
@@ -48,9 +48,9 @@ public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneabl
         super(device, fetchScreen(device, screen));
     }
 
-    public static AbstractGraphicsScreen createScreenDevice(long display, int screenIdx) {
+    public static AbstractGraphicsScreen createScreenDevice(long display, int screenIdx, boolean owner) {
         if(0==display) throw new NativeWindowException("display is null");
-        return new X11GraphicsScreen(new X11GraphicsDevice(display, AbstractGraphicsDevice.DEFAULT_UNIT), screenIdx);
+        return new X11GraphicsScreen(new X11GraphicsDevice(display, AbstractGraphicsDevice.DEFAULT_UNIT, owner), screenIdx);
     }
 
     public long getDefaultVisualID() {
diff --git a/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java b/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java
index 1ad909897..aab1556da 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java
@@ -202,7 +202,9 @@ public class SWTAccessor {
         if( null != OS_gtk_class ) {
             long widgedHandle = callStaticMethodL2L(OS_GTK_WIDGET_WINDOW, handle);
             long displayHandle = callStaticMethodL2L(OS_gdk_x11_drawable_get_xdisplay, widgedHandle);
-            return new X11GraphicsDevice(displayHandle, AbstractGraphicsDevice.DEFAULT_UNIT);
+            // FIXME: May think about creating a private non-shared X11 Display handle, like we use to for AWT
+            //        to avoid locking problems !
+            return new X11GraphicsDevice(displayHandle, AbstractGraphicsDevice.DEFAULT_UNIT, false);
         }
         if( NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(false) ) {
             return new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Display.java b/src/newt/classes/jogamp/newt/driver/x11/X11Display.java
index b9a32c7de..78d828415 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/X11Display.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/X11Display.java
@@ -85,13 +85,8 @@ public class X11Display extends DisplayImpl {
             throw e;
         }
         
-        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 {
-            // Proper: Use AWT/X11Display locking w/ AWT and X11Display locking only w/o isFirstUIActionOnProcess()
-            aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT);
-        }
+        // We use a private non-shared X11 Display instance for EDT window operations and one for exposed animation, eg. OpenGL 
+        aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, NativeWindowFactory.getNullToolkitLock(), false);
     }
 
     protected void closeNativeImpl() {
-- 
cgit v1.2.3