diff options
author | Kenneth Russel <[email protected]> | 2005-05-11 23:05:59 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2005-05-11 23:05:59 +0000 |
commit | bdc312ed2999ea985873632027fd3152d2f0ca74 (patch) | |
tree | 0e587f4b3da7ec40898a987e104084b326474ea0 | |
parent | 2ad4957d5c3ada540b56177a9c1ce0295dbeecff (diff) |
Added more locking of AWT around GLX commands during X11 visual
selection to fix problems seen on Solaris/x86
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@270 232f8b59-042b-4e1e-8c03-345bb8c30851
-rw-r--r-- | src/net/java/games/jogl/impl/x11/X11GLContext.java | 15 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/x11/X11GLContextFactory.java | 66 |
2 files changed, 53 insertions, 28 deletions
diff --git a/src/net/java/games/jogl/impl/x11/X11GLContext.java b/src/net/java/games/jogl/impl/x11/X11GLContext.java index 4709691f8..023777680 100644 --- a/src/net/java/games/jogl/impl/x11/X11GLContext.java +++ b/src/net/java/games/jogl/impl/x11/X11GLContext.java @@ -47,7 +47,6 @@ import net.java.games.jogl.*; import net.java.games.jogl.impl.*; public abstract class X11GLContext extends GLContext { - private static JAWT jawt; protected long display; protected long drawable; protected long visualID; @@ -310,15 +309,7 @@ public abstract class X11GLContext extends GLContext { // protected JAWT getJAWT() { - if (jawt == null) { - JAWT j = new JAWT(); - j.version(JAWTFactory.JAWT_VERSION_1_4); - if (!JAWTFactory.JAWT_GetAWT(j)) { - throw new RuntimeException("Unable to initialize JAWT"); - } - jawt = j; - } - return jawt; + return X11GLContextFactory.getJAWT(); } protected XVisualInfo chooseVisual() { @@ -412,10 +403,10 @@ public abstract class X11GLContext extends GLContext { // These synchronization primitives prevent the AWT from making // requests from the X server asynchronously to this code. protected void lockAWT() { - getJAWT().Lock(); + X11GLContextFactory.lockAWT(); } protected void unlockAWT() { - getJAWT().Unlock(); + X11GLContextFactory.unlockAWT(); } } diff --git a/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java b/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java index 3582d51d9..6245ae6d4 100644 --- a/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java +++ b/src/net/java/games/jogl/impl/x11/X11GLContextFactory.java @@ -61,23 +61,30 @@ public class X11GLContextFactory extends GLContextFactory { // system's selection to the chooser as a hint int[] attribs = glCapabilities2AttribList(capabilities, isMultisampleAvailable()); - long display = getDisplayConnection(); - XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs); + XVisualInfo[] infos = null; + GLCapabilities[] caps = null; int recommendedIndex = -1; - int[] count = new int[1]; - XVisualInfo template = new XVisualInfo(); - template.screen(screen); - XVisualInfo[] infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count); - if (infos == null) { - throw new GLException("Error while enumerating available XVisualInfos"); - } - GLCapabilities[] caps = new GLCapabilities[infos.length]; - for (int i = 0; i < infos.length; i++) { - caps[i] = xvi2GLCapabilities(display, infos[i]); - // Attempt to find the visual chosen by glXChooseVisual - if (recommendedVis != null && recommendedVis.visualid() == infos[i].visualid()) { - recommendedIndex = i; + lockAWT(); + try { + long display = getDisplayConnection(); + XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs); + int[] count = new int[1]; + XVisualInfo template = new XVisualInfo(); + template.screen(screen); + infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count); + if (infos == null) { + throw new GLException("Error while enumerating available XVisualInfos"); + } + caps = new GLCapabilities[infos.length]; + for (int i = 0; i < infos.length; i++) { + caps[i] = xvi2GLCapabilities(display, infos[i]); + // Attempt to find the visual chosen by glXChooseVisual + if (recommendedVis != null && recommendedVis.visualid() == infos[i].visualid()) { + recommendedIndex = i; + } } + } finally { + unlockAWT(); } int chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); if (chosen < 0 || chosen >= caps.length) { @@ -205,11 +212,38 @@ public class X11GLContextFactory extends GLContextFactory { return res; } + // JAWT access + private static JAWT jawt; + public static JAWT getJAWT() { + if (jawt == null) { + JAWT j = new JAWT(); + j.version(JAWTFactory.JAWT_VERSION_1_4); + if (!JAWTFactory.JAWT_GetAWT(j)) { + throw new RuntimeException("Unable to initialize JAWT"); + } + jawt = j; + } + return jawt; + } + + public static void lockAWT() { + getJAWT().Lock(); + } + + public static void unlockAWT() { + getJAWT().Unlock(); + } + // Display connection for use by visual selection algorithm and by all offscreen surfaces private static long staticDisplay; public static long getDisplayConnection() { if (staticDisplay == 0) { - staticDisplay = GLX.XOpenDisplay(null); + lockAWT(); + try { + staticDisplay = GLX.XOpenDisplay(null); + } finally { + unlockAWT(); + } if (staticDisplay == 0) { throw new GLException("Unable to open default display, needed for visual selection and offscreen surface handling"); } |