diff options
author | Kenneth Russel <[email protected]> | 2005-11-09 20:11:30 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2005-11-09 20:11:30 +0000 |
commit | dba4677caf231ac26c70518a3e82651b0e01c8f2 (patch) | |
tree | 53b494a55ff1c4a00c6d2bd1dbb3e4b7e66b8b5e /src/classes/com/sun/opengl/impl/x11 | |
parent | 23e6684c5ae7047f39620e861b607db2f761799d (diff) |
Refactored JOGL's use of the JAWT to enable it to be more lazily
loaded. Separated out AWT-specific native code into a new jogl_awt
native library on all platforms. Added a static helper method to the
JAWT class to fetch the JAWT which is now called by all users. Added a
new NativeLibLoader entry point to load the native code for the AWT
implementation. Renamed the X11 platform's "lockAWT" and "unlockAWT"
methods to "lockToolkit" and "unlockToolkit", respectively. In order
to change this behavior only two methods in X11GLDrawableFactory need
to be overridden. (During the writing of this checkin comment it was
noted that these methods are currently static, but that will be fixed
in a subsequent checkin.) Added the new jogl_awt native library to the
the "dist" target's error checking code. Tested on Windows; more
testing, including build testing, is needed on other platforms.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@429 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/opengl/impl/x11')
9 files changed, 57 insertions, 79 deletions
diff --git a/src/classes/com/sun/opengl/impl/x11/X11ExternalGLContext.java b/src/classes/com/sun/opengl/impl/x11/X11ExternalGLContext.java index 4d329ba24..411f7c89f 100755 --- a/src/classes/com/sun/opengl/impl/x11/X11ExternalGLContext.java +++ b/src/classes/com/sun/opengl/impl/x11/X11ExternalGLContext.java @@ -48,11 +48,11 @@ public class X11ExternalGLContext extends X11GLContext { public X11ExternalGLContext() { super(null, null); - lockAWT(); + lockToolkit(); try { context = GLX.glXGetCurrentContext(); } finally { - unlockAWT(); + unlockToolkit(); } GLContextShareSet.contextCreated(this); resetGLFunctionAvailability(); diff --git a/src/classes/com/sun/opengl/impl/x11/X11ExternalGLDrawable.java b/src/classes/com/sun/opengl/impl/x11/X11ExternalGLDrawable.java index 371930013..96e1d0034 100755 --- a/src/classes/com/sun/opengl/impl/x11/X11ExternalGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/x11/X11ExternalGLDrawable.java @@ -50,7 +50,7 @@ public class X11ExternalGLDrawable extends X11GLDrawable { public X11ExternalGLDrawable() { super(null, null, null); - lockAWT(); + lockToolkit(); try { display = GLX.glXGetCurrentDisplay(); drawable = GLX.glXGetCurrentDrawable(); @@ -72,7 +72,7 @@ public class X11ExternalGLDrawable extends X11GLDrawable { GLX.glXQueryContext(display, context, GLX.GLX_SCREEN, val, 0); screen = val[0]; } finally { - unlockAWT(); + unlockToolkit(); } } @@ -113,7 +113,7 @@ public class X11ExternalGLDrawable extends X11GLDrawable { // Note that we have to completely override makeCurrentImpl // because the underlying makeCurrent call differs from the norm - lockAWT(); + lockToolkit(); try { boolean created = false; if (context == 0) { @@ -144,18 +144,18 @@ public class X11ExternalGLDrawable extends X11GLDrawable { } return CONTEXT_CURRENT; } finally { - unlockAWT(); + unlockToolkit(); } } protected void releaseImpl() throws GLException { - lockAWT(); + lockToolkit(); try { if (!GLX.glXMakeContextCurrent(drawable.getDisplay(), 0, 0, 0)) { throw new GLException("Error freeing OpenGL context"); } } finally { - unlockAWT(); + unlockToolkit(); } } diff --git a/src/classes/com/sun/opengl/impl/x11/X11GLContext.java b/src/classes/com/sun/opengl/impl/x11/X11GLContext.java index ed9736f22..f8d35edd4 100644 --- a/src/classes/com/sun/opengl/impl/x11/X11GLContext.java +++ b/src/classes/com/sun/opengl/impl/x11/X11GLContext.java @@ -164,7 +164,7 @@ public abstract class X11GLContext extends GLContextImpl { } protected void destroyImpl() throws GLException { - lockAWT(); + lockToolkit(); if (context != 0) { GLX.glXDestroyContext(mostRecentDisplay, context); if (DEBUG) { @@ -174,7 +174,7 @@ public abstract class X11GLContext extends GLContextImpl { mostRecentDisplay = 0; GLContextShareSet.contextDestroyed(this); } - unlockAWT(); + unlockToolkit(); } public boolean isCreated() { @@ -208,7 +208,7 @@ public abstract class X11GLContext extends GLContextImpl { glXQueryExtensionsStringInitialized = true; } if (glXQueryExtensionsStringAvailable) { - lockAWT(); + lockToolkit(); try { String ret = GLX.glXQueryExtensionsString(drawable.getDisplay(), GLX.DefaultScreen(drawable.getDisplay())); if (DEBUG) { @@ -216,7 +216,7 @@ public abstract class X11GLContext extends GLContextImpl { } return ret; } finally { - unlockAWT(); + unlockToolkit(); } } else { return ""; @@ -291,11 +291,11 @@ public abstract class X11GLContext extends GLContextImpl { // These synchronization primitives prevent the AWT from making // requests from the X server asynchronously to this code. - protected void lockAWT() { - X11GLDrawableFactory.lockAWT(); + protected void lockToolkit() { + X11GLDrawableFactory.lockToolkit(); } - protected void unlockAWT() { - X11GLDrawableFactory.unlockAWT(); + protected void unlockToolkit() { + X11GLDrawableFactory.unlockToolkit(); } } diff --git a/src/classes/com/sun/opengl/impl/x11/X11GLDrawable.java b/src/classes/com/sun/opengl/impl/x11/X11GLDrawable.java index 343931965..bfa467b10 100644 --- a/src/classes/com/sun/opengl/impl/x11/X11GLDrawable.java +++ b/src/classes/com/sun/opengl/impl/x11/X11GLDrawable.java @@ -103,9 +103,9 @@ public abstract class X11GLDrawable extends GLDrawableImpl { XVisualInfo template = XVisualInfo.create(); // FIXME: probably not 64-bit clean template.visualid((int) visualID); - lockAWT(); + lockToolkit(); XVisualInfo[] infos = GLX.XGetVisualInfo(display, GLX.VisualIDMask, template, count, 0); - unlockAWT(); + unlockToolkit(); if (infos == null || infos.length == 0) { throw new GLException("Error while getting XVisualInfo for visual ID " + visualID); } @@ -126,7 +126,7 @@ public abstract class X11GLDrawable extends GLDrawableImpl { template.screen(screen); XVisualInfo[] infos = null; GLCapabilities[] caps = null; - lockAWT(); + lockToolkit(); try { infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count, 0); if (infos == null) { @@ -137,7 +137,7 @@ public abstract class X11GLDrawable extends GLDrawableImpl { caps[i] = X11GLDrawableFactory.xvi2GLCapabilities(display, infos[i]); } } finally { - unlockAWT(); + unlockToolkit(); } int chosen = chooser.chooseCapabilities(capabilities, caps, -1); if (chosen < 0 || chosen >= caps.length) { @@ -162,11 +162,11 @@ public abstract class X11GLDrawable extends GLDrawableImpl { // These synchronization primitives prevent the AWT from making // requests from the X server asynchronously to this code. - protected void lockAWT() { - X11GLDrawableFactory.lockAWT(); + protected void lockToolkit() { + X11GLDrawableFactory.lockToolkit(); } - protected void unlockAWT() { - X11GLDrawableFactory.unlockAWT(); + protected void unlockToolkit() { + X11GLDrawableFactory.unlockToolkit(); } } diff --git a/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java b/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java index 38d63f04d..90f5b9fe5 100644 --- a/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java +++ b/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java @@ -56,7 +56,7 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl { private static boolean isLinuxAMD64; static { - NativeLibLoader.load(); + NativeLibLoader.loadCore(); AccessController.doPrivileged(new PrivilegedAction() { public Object run() { @@ -100,7 +100,7 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl { XVisualInfo[] infos = null; GLCapabilities[] caps = null; int recommendedIndex = -1; - lockAWT(); + lockToolkit(); try { long display = getDisplayConnection(); XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs, 0); @@ -120,7 +120,7 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl { } } } finally { - unlockAWT(); + unlockToolkit(); } int chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); if (chosen < 0 || chosen >= caps.length) { @@ -180,7 +180,7 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl { Runnable r = new Runnable() { public void run() { long display = getDisplayConnection(); - lockAWT(); + lockToolkit(); try { int[] major = new int[1]; int[] minor = new int[1]; @@ -207,7 +207,7 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl { pbufferSupportInitialized = true; } finally { - unlockAWT(); + unlockToolkit(); } } }; @@ -343,48 +343,34 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl { return res; } - // JAWT access - private static JAWT jawt; - public static JAWT getJAWT() { - if (jawt == null) { - JAWT j = JAWT.create(); - 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() { + public static void lockToolkit() { if (!Java2D.isOGLPipelineActive() || !Java2D.isQueueFlusherThread()) { - getJAWT().Lock(); + JAWT.getJAWT().Lock(); } } - public static void unlockAWT() { + public static void unlockToolkit() { if (!Java2D.isOGLPipelineActive() || !Java2D.isQueueFlusherThread()) { - getJAWT().Unlock(); + JAWT.getJAWT().Unlock(); } } - public void lockAWTForJava2D() { - lockAWT(); + public void lockToolkitForJava2D() { + lockToolkit(); } - public void unlockAWTForJava2D() { - unlockAWT(); + public void unlockToolkitForJava2D() { + unlockToolkit(); } // Display connection for use by visual selection algorithm and by all offscreen surfaces private static long staticDisplay; public static long getDisplayConnection() { if (staticDisplay == 0) { - lockAWT(); + lockToolkit(); try { staticDisplay = GLX.XOpenDisplay(null); } finally { - unlockAWT(); + unlockToolkit(); } if (staticDisplay == 0) { throw new GLException("Unable to open default display, needed for visual selection and offscreen surface handling"); diff --git a/src/classes/com/sun/opengl/impl/x11/X11OffscreenGLDrawable.java b/src/classes/com/sun/opengl/impl/x11/X11OffscreenGLDrawable.java index 2d7dedd7f..5370860c6 100644 --- a/src/classes/com/sun/opengl/impl/x11/X11OffscreenGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/x11/X11OffscreenGLDrawable.java @@ -80,7 +80,7 @@ public class X11OffscreenGLDrawable extends X11GLDrawable { XVisualInfo vis = chooseVisual(false); int bitsPerPixel = vis.depth(); - lockAWT(); + lockToolkit(); try { int screen = GLX.DefaultScreen(display); pixmap = GLX.XCreatePixmap(display, (int) GLX.RootWindow(display, screen), width, height, bitsPerPixel); @@ -100,7 +100,7 @@ public class X11OffscreenGLDrawable extends X11GLDrawable { ", display " + toHexString(display)); } } finally { - unlockAWT(); + unlockToolkit(); } } @@ -113,7 +113,7 @@ public class X11OffscreenGLDrawable extends X11GLDrawable { } // Must destroy pixmap and GLXPixmap - lockAWT(); + lockToolkit(); if (DEBUG) { long cur = GLX.glXGetCurrentContext(); @@ -130,7 +130,7 @@ public class X11OffscreenGLDrawable extends X11GLDrawable { GLX.glXDestroyGLXPixmap(display, drawable); GLX.XFreePixmap(display, pixmap); - unlockAWT(); + unlockToolkit(); drawable = 0; pixmap = 0; display = 0; diff --git a/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLDrawable.java b/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLDrawable.java index 49000fc14..810de42c5 100644 --- a/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLDrawable.java @@ -91,7 +91,7 @@ public class X11OnscreenGLDrawable extends X11GLDrawable { } public void swapBuffers() throws GLException { - lockAWT(); + lockToolkit(); try { boolean didLock = false; @@ -109,7 +109,7 @@ public class X11OnscreenGLDrawable extends X11GLDrawable { unlockSurface(); } } finally { - unlockAWT(); + unlockToolkit(); } } @@ -120,7 +120,7 @@ public class X11OnscreenGLDrawable extends X11GLDrawable { if (drawable != 0) { throw new GLException("Surface already locked"); } - ds = getJAWT().GetDrawingSurface(component); + ds = JAWT.getJAWT().GetDrawingSurface(component); if (ds == null) { // Widget not yet realized return LOCK_SURFACE_NOT_READY; @@ -142,7 +142,7 @@ public class X11OnscreenGLDrawable extends X11GLDrawable { if (dsi == null) { // Widget not yet realized ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); + JAWT.getJAWT().FreeDrawingSurface(ds); ds = null; return LOCK_SURFACE_NOT_READY; } @@ -154,7 +154,7 @@ public class X11OnscreenGLDrawable extends X11GLDrawable { // Widget not yet realized ds.FreeDrawingSurfaceInfo(dsi); ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); + JAWT.getJAWT().FreeDrawingSurface(ds); ds = null; dsi = null; x11dsi = null; @@ -172,7 +172,7 @@ public class X11OnscreenGLDrawable extends X11GLDrawable { } ds.FreeDrawingSurfaceInfo(dsi); ds.Unlock(); - getJAWT().FreeDrawingSurface(ds); + JAWT.getJAWT().FreeDrawingSurface(ds); ds = null; dsi = null; x11dsi = null; @@ -180,12 +180,4 @@ public class X11OnscreenGLDrawable extends X11GLDrawable { drawable = 0; visualID = 0; } - - //---------------------------------------------------------------------- - // Internals only below this point - // - - private JAWT getJAWT() { - return X11GLDrawableFactory.getJAWT(); - } } diff --git a/src/classes/com/sun/opengl/impl/x11/X11PbufferGLContext.java b/src/classes/com/sun/opengl/impl/x11/X11PbufferGLContext.java index 0cb945de7..3b0d51f13 100644 --- a/src/classes/com/sun/opengl/impl/x11/X11PbufferGLContext.java +++ b/src/classes/com/sun/opengl/impl/x11/X11PbufferGLContext.java @@ -72,7 +72,7 @@ public class X11PbufferGLContext extends X11GLContext { // Note that we have to completely override makeCurrentImpl // because the underlying makeCurrent call differs for pbuffers - lockAWT(); + lockToolkit(); try { boolean created = false; if (context == 0) { @@ -103,18 +103,18 @@ public class X11PbufferGLContext extends X11GLContext { } return CONTEXT_CURRENT; } finally { - unlockAWT(); + unlockToolkit(); } } protected void releaseImpl() throws GLException { - lockAWT(); + lockToolkit(); try { if (!GLX.glXMakeContextCurrent(drawable.getDisplay(), 0, 0, 0)) { throw new GLException("Error freeing OpenGL context"); } } finally { - unlockAWT(); + unlockToolkit(); } } diff --git a/src/classes/com/sun/opengl/impl/x11/X11PbufferGLDrawable.java b/src/classes/com/sun/opengl/impl/x11/X11PbufferGLDrawable.java index 2a1248405..85df39267 100644 --- a/src/classes/com/sun/opengl/impl/x11/X11PbufferGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/x11/X11PbufferGLDrawable.java @@ -78,11 +78,11 @@ public class X11PbufferGLDrawable extends X11GLDrawable { } public void destroy() { - lockAWT(); + lockToolkit(); if (drawable != 0) { GLX.glXDestroyPbuffer(display, drawable); } - unlockAWT(); + unlockToolkit(); display = 0; } @@ -100,7 +100,7 @@ public class X11PbufferGLDrawable extends X11GLDrawable { } public void createPbuffer(long display) { - lockAWT(); + lockToolkit(); try { if (display == 0) { throw new GLException("Null display"); @@ -241,7 +241,7 @@ public class X11PbufferGLDrawable extends X11GLDrawable { System.err.println("Created pbuffer " + width + " x " + height); } } finally { - unlockAWT(); + unlockToolkit(); } } |