diff options
Diffstat (limited to 'src/nativewindow/classes')
3 files changed, 11 insertions, 62 deletions
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java index 38d0fb73d..acd55a823 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java @@ -39,28 +39,11 @@ import javax.media.nativewindow.*; import com.sun.nativewindow.impl.*; /** - * Contains a thread safe X11 utility to retrieve tread local display connection,<br> + * Contains a thread safe X11 utility to retrieve thread local display connection,<br> * as well as the static global discplay connection.<br> * - * The TLS variant is thread safe per se, but has the memory leak risk on applications - * heavily utilizing runnables on a new thread.<br> - * - * The static variant is more nice to resources, but involves the default toolkit - * locking mechanism, which invocation you have to provide as shown below.<br> - * <PRE> - NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); - try { - long displayHandle = X11Util.getStaticDefaultDisplay(); - ... - } finally { - NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); - } - * </PRE><br> - * - * We will use the TLS variant, where a long term display connection is being used, - * ie in JOGL's <code>X11AWTGLXGraphicsConfigurationFactory</code>, - * on all other situations where we just query some X11 attributes, - * the locked static variant shall be used instead.<br> + * The TLS variant is thread safe per se, but be aware of the memory leak risk + * where an application heavily utilizing this class on temporary new threads.<br> */ public class X11Util { private static final boolean DEBUG = Debug.debug("X11Util"); @@ -73,43 +56,13 @@ public class X11Util { private static ThreadLocal currentDisplayAssociation = new ThreadLocal(); - private static volatile long staticDefaultDisplay=0; - private static boolean staticDefaultDisplayXineramaEnable=false; - - private static long fetchStaticDefaultDisplay() { - if(0==staticDefaultDisplay) { - synchronized (X11Util.class) { - if(0==staticDefaultDisplay) { - NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); - try { - staticDefaultDisplay = X11Lib.XOpenDisplay(null); - if(0==staticDefaultDisplay) { - throw new NativeWindowException("Unable to create a static default display connection"); - } - staticDefaultDisplayXineramaEnable = X11Lib.XineramaEnabled(staticDefaultDisplay); - } finally { - NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); - } - } - } - } - return staticDefaultDisplay; - } - - /** Returns the global static default display connection, read the toolkit lock/unlock - * requirements {@link X11Util above} for synchronization. */ - public static long getStaticDefaultDisplay() { - return fetchStaticDefaultDisplay(); - } - /** Returns the global static default display connection, read the toolkit lock/unlock * requirements {@link X11Util above} for synchronization. */ - public static boolean isXineramaEnabledOnStaticDefaultDisplay() { - fetchStaticDefaultDisplay(); - return staticDefaultDisplayXineramaEnable; + public static boolean isXineramaEnabledOnThreadLocalDefaultDisplay() { + long dpy = getThreadLocalDefaultDisplay(); + return X11Lib.XineramaEnabled(dpy); } - /** Returns this thread current default display. */ public static long getThreadLocalDefaultDisplay() { Long dpyL = (Long) currentDisplayAssociation.get(); diff --git a/src/nativewindow/classes/javax/media/nativewindow/ToolkitLock.java b/src/nativewindow/classes/javax/media/nativewindow/ToolkitLock.java index 27e59d8c8..6f83896fa 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/ToolkitLock.java +++ b/src/nativewindow/classes/javax/media/nativewindow/ToolkitLock.java @@ -47,8 +47,9 @@ package javax.media.nativewindow; <PRE> NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); try { - long displayHandle = X11Util.getStaticDefaultDisplay(); - ... + long displayHandle = X11Util.getThreadLocalDefaultDisplay(); + ... some code dealing with shared resources + ... ie the window surface } finally { NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java index f434050f2..03121dfaa 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java +++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java @@ -74,13 +74,8 @@ public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneabl } private static int fetchScreen(int screen) { - NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); - try { - if(!com.sun.nativewindow.impl.x11.X11Util.isXineramaEnabledOnStaticDefaultDisplay()) { - return screen; - } - } finally { - NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); + if(!com.sun.nativewindow.impl.x11.X11Util.isXineramaEnabledOnThreadLocalDefaultDisplay()) { + return screen; } return 0; } |