From 7ae0f2df39692e82d7955dbcd09c35c36382726c Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 25 Nov 2011 00:26:23 +0100 Subject: NativeWindow X11GraphicsDevice: Pass 'owner' for close-display operation @ constructor --- .../javax/media/nativewindow/x11/X11GraphicsDevice.java | 15 ++++++--------- .../javax/media/nativewindow/x11/X11GraphicsScreen.java | 4 ++-- .../classes/jogamp/nativewindow/swt/SWTAccessor.java | 4 +++- 3 files changed, 11 insertions(+), 12 deletions(-) (limited to 'src/nativewindow/classes') 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)}.
@@ -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); -- cgit v1.2.3