diff options
author | Sven Gothel <[email protected]> | 2009-07-04 02:51:49 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2009-07-04 02:51:49 +0000 |
commit | 918b42027e024f3b7973463a6391db8c11d5d778 (patch) | |
tree | 1e24caa96ac94d450595e1a5a58bd7eeccb0b2f7 /src | |
parent | 7dcb2b468ee7f3453fe69642e42cf4c2a21a0989 (diff) |
Push custom loadLibrary handling down to NativeWindow NativeLibLoaderBase; X11AWTGLXGraphicsConfigurationFactory: Encapsule whole block in lock/unlock to minimize context switch
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@2021 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src')
5 files changed, 101 insertions, 188 deletions
diff --git a/src/jogl/classes/com/sun/opengl/impl/NativeLibLoader.java b/src/jogl/classes/com/sun/opengl/impl/NativeLibLoader.java index 5082f01dd..59f92e53f 100644 --- a/src/jogl/classes/com/sun/opengl/impl/NativeLibLoader.java +++ b/src/jogl/classes/com/sun/opengl/impl/NativeLibLoader.java @@ -49,8 +49,6 @@ import java.util.HashSet; import com.sun.nativewindow.impl.NativeLibLoaderBase; public class NativeLibLoader extends NativeLibLoaderBase { - protected static final boolean DEBUG = Debug.debug("NativeLibLoader"); - public static void loadNEWT() { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { @@ -106,82 +104,6 @@ public class NativeLibLoader extends NativeLibLoaderBase { }); } - //---------------------------------------------------------------------- - // Support for the new JNLPAppletLauncher - // - - private static class JOGLAction implements NativeLibLoaderBase.LoaderAction { - public void loadLibrary(String libname, String[] preload, - boolean preloadIgnoreError) { - if (null!=preload) { - for (int i=0; i<preload.length; i++) { - if(!isLoaded(preload[i])) { - try { - if(DEBUG) { - System.err.println("JOGL NativeLibLoader preload "+preload[i]); - } - loadLibraryInternal(preload[i]); - addLoaded(preload[i]); - } - catch (UnsatisfiedLinkError e) { - if(DEBUG) e.printStackTrace(); - if (!preloadIgnoreError && e.getMessage().indexOf("already loaded") < 0) { - throw e; - } - } - } - } - } - - if(DEBUG) { - System.err.println("JOGL NativeLibLoader load "+libname); - } - loadLibraryInternal(libname); - addLoaded(libname); - } - } - private static final String[] nativeOSPreload = { "nativewindow_x11" }; - private static boolean usingJNLPAppletLauncher; - private static Method jnlpLoadLibraryMethod; - - static { - NativeLibLoaderBase.setLoadingAction(new JOGLAction()); - String sunAppletLauncher = Debug.getProperty("sun.jnlp.applet.launcher", false); - usingJNLPAppletLauncher = Boolean.valueOf(sunAppletLauncher).booleanValue(); - } - - // I hate the amount of delegation currently in this class - private static void loadLibraryInternal(String libraryName) { - // Note: special-casing JAWT which is built in to the JDK - if (usingJNLPAppletLauncher && !libraryName.equals("jawt")) { - try { - if (jnlpLoadLibraryMethod == null) { - Class jnlpAppletLauncherClass = Class.forName("org.jdesktop.applet.util.JNLPAppletLauncher"); - jnlpLoadLibraryMethod = jnlpAppletLauncherClass.getDeclaredMethod("loadLibrary", new Class[] { String.class }); - } - jnlpLoadLibraryMethod.invoke(null, new Object[] { libraryName }); - } catch (Exception e) { - Throwable t = e; - if(DEBUG) t.printStackTrace(); - if (t instanceof InvocationTargetException) { - t = ((InvocationTargetException) t).getTargetException(); - } - if (t instanceof Error) - throw (Error) t; - if (t instanceof RuntimeException) { - throw (RuntimeException) t; - } - // Throw UnsatisfiedLinkError for best compatibility with System.loadLibrary() - throw (UnsatisfiedLinkError) new UnsatisfiedLinkError().initCause(e); - } - } else { - // FIXME: remove - // System.out.println("sun.boot.library.path=" + Debug.getProperty("sun.boot.library.path", false)); - System.loadLibrary(libraryName); - if(DEBUG) { - System.err.println("JOGL Loaded Native Library: "+libraryName); - } - } - } } + diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java index 604bde46b..1b92e6f86 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java @@ -84,8 +84,10 @@ public class X11AWTGLXGraphicsConfigurationFactory extends GraphicsConfiguration System.err.println("X11AWTGLXGraphicsConfigurationFactory: got "+absScreen); } + GraphicsConfiguration gc; + X11GraphicsConfiguration x11Config; + // Need the lock here, since it could be an AWT owned display connection - X11GraphicsDevice x11Device; NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); try { long displayHandle = X11SunJDKReflection.graphicsDeviceGetDisplay(device); @@ -100,42 +102,42 @@ public class X11AWTGLXGraphicsConfigurationFactory extends GraphicsConfiguration } } ((AWTGraphicsDevice)awtScreen.getDevice()).setHandle(displayHandle); - x11Device = new X11GraphicsDevice(displayHandle); - } finally { - NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); - } + X11GraphicsDevice x11Device = new X11GraphicsDevice(displayHandle); - X11GraphicsScreen x11Screen = new X11GraphicsScreen(x11Device, awtScreen.getIndex()); - if(DEBUG) { - System.err.println("X11AWTGLXGraphicsConfigurationFactory: made "+x11Screen); - } + X11GraphicsScreen x11Screen = new X11GraphicsScreen(x11Device, awtScreen.getIndex()); + if(DEBUG) { + System.err.println("X11AWTGLXGraphicsConfigurationFactory: made "+x11Screen); + } - GraphicsConfiguration gc = device.getDefaultConfiguration(); - AWTGraphicsConfiguration.setupCapabilitiesRGBABits(capabilities, gc); - if(DEBUG) { - System.err.println("AWT Colormodel compatible: "+capabilities); - } + gc = device.getDefaultConfiguration(); + AWTGraphicsConfiguration.setupCapabilitiesRGBABits(capabilities, gc); + if(DEBUG) { + System.err.println("AWT Colormodel compatible: "+capabilities); + } - X11GraphicsConfiguration x11Config = (X11GraphicsConfiguration) - GraphicsConfigurationFactory.getFactory(x11Device).chooseGraphicsConfiguration(capabilities, - chooser, - x11Screen); - if (x11Config == null) { - throw new GLException("Unable to choose a GraphicsConfiguration: "+capabilities+",\n\t"+chooser+"\n\t"+x11Screen); - } + x11Config = (X11GraphicsConfiguration) + GraphicsConfigurationFactory.getFactory(x11Device).chooseGraphicsConfiguration(capabilities, + chooser, + x11Screen); + if (x11Config == null) { + throw new GLException("Unable to choose a GraphicsConfiguration: "+capabilities+",\n\t"+chooser+"\n\t"+x11Screen); + } - long visualID = x11Config.getVisualID(); - // Now figure out which GraphicsConfiguration corresponds to this - // visual by matching the visual ID - GraphicsConfiguration[] configs = device.getConfigurations(); - for (int i = 0; i < configs.length; i++) { - GraphicsConfiguration config = configs[i]; - if (config != null) { - if (X11SunJDKReflection.graphicsConfigurationGetVisualID(config) == visualID) { - return new AWTGraphicsConfiguration(awtScreen, x11Config.getChosenCapabilities(), x11Config.getRequestedCapabilities(), - config, x11Config); + long visualID = x11Config.getVisualID(); + // Now figure out which GraphicsConfiguration corresponds to this + // visual by matching the visual ID + GraphicsConfiguration[] configs = device.getConfigurations(); + for (int i = 0; i < configs.length; i++) { + GraphicsConfiguration config = configs[i]; + if (config != null) { + if (X11SunJDKReflection.graphicsConfigurationGetVisualID(config) == visualID) { + return new AWTGraphicsConfiguration(awtScreen, x11Config.getChosenCapabilities(), x11Config.getRequestedCapabilities(), + config, x11Config); + } } } + } finally { + NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } // Either we weren't able to reflectively introspect on the // X11GraphicsConfig or something went wrong in the steps above; diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java index e1427d7be..570cf1f9d 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java @@ -70,7 +70,7 @@ public class NativeLibLoaderBase { for (int i=0; i<preload.length; i++) { if(!isLoaded(preload[i])) { try { - System.loadLibrary(preload[i]); + loadLibraryInternal(preload[i]); addLoaded(preload[i]); if(DEBUG) { System.err.println("NativeLibLoaderBase preloaded "+preload[i]); @@ -85,7 +85,7 @@ public class NativeLibLoaderBase { } } } - System.loadLibrary(libname); + loadLibraryInternal(libname); addLoaded(libname); if(DEBUG) { System.err.println("NativeLibLoaderBase loaded "+libname); @@ -135,4 +135,68 @@ public class NativeLibLoaderBase { } }); } + + + private static final Class customLauncherClass; + private static final Method customLoadLibraryMethod; + + static { + Class launcherClass = null; + Method loadLibraryMethod = null; + + if ( Debug.getBooleanProperty("sun.jnlp.applet.launcher", false) ) { + try { + launcherClass = Class.forName("org.jdesktop.applet.util.JNLPAppletLauncher"); + loadLibraryMethod = launcherClass.getDeclaredMethod("loadLibrary", new Class[] { String.class }); + } catch (Throwable t) { + if(DEBUG) { + t.printStackTrace(); + } + launcherClass = null; + loadLibraryMethod = null; + } + } + + if(null==launcherClass) { + String launcherClassName = Debug.getProperty("jnlp.launcher.class", false); + if(null!=launcherClassName) { + try { + launcherClass = Class.forName(launcherClassName); + loadLibraryMethod = launcherClass.getDeclaredMethod("loadLibrary", new Class[] { String.class }); + } catch (Throwable t) { + if(DEBUG) { + t.printStackTrace(); + } + launcherClass = null; + loadLibraryMethod = null; + } + } + } + customLauncherClass = launcherClass; + customLoadLibraryMethod = loadLibraryMethod; + } + + private static void loadLibraryInternal(String libraryName) { + // Note: special-casing JAWT which is built in to the JDK + if (null!=customLoadLibraryMethod && !libraryName.equals("jawt")) { + try { + customLoadLibraryMethod.invoke(null, new Object[] { libraryName }); + } catch (Exception e) { + Throwable t = e; + if (t instanceof InvocationTargetException) { + t = ((InvocationTargetException) t).getTargetException(); + } + if (t instanceof Error) + throw (Error) t; + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } + // Throw UnsatisfiedLinkError for best compatibility with System.loadLibrary() + throw (UnsatisfiedLinkError) new UnsatisfiedLinkError().initCause(e); + } + } else { + // System.out.println("sun.boot.library.path=" + Debug.getProperty("sun.boot.library.path", false)); + System.loadLibrary(libraryName); + } + } } diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java index 20e8cf966..af93b8c31 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java @@ -46,7 +46,7 @@ public class JAWTUtil { static { JAWTNativeLibLoader.loadAWTImpl(); - NativeLibLoaderBase.loadNativeWindow("awt"); + JAWTNativeLibLoader.loadNativeWindow("awt"); lockedStack = null; headlessMode = GraphicsEnvironment.isHeadless(); diff --git a/src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java b/src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java index 4283ef6dc..6316e750f 100644 --- a/src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java +++ b/src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java @@ -60,79 +60,4 @@ public class NativeLibLoader extends NativeLibLoaderBase { }); } - //---------------------------------------------------------------------- - // Support for the new JNLPAppletLauncher - // - - private static class NEWTAction implements NativeLibLoaderBase.LoaderAction { - public void loadLibrary(String libname, String[] preload, - boolean preloadIgnoreError) { - if (null!=preload) { - for (int i=0; i<preload.length; i++) { - if(!isLoaded(preload[i])) { - try { - if(DEBUG) { - System.err.println("NEWT NativeLibLoader preload "+preload[i]); - } - loadLibraryInternal(preload[i]); - addLoaded(preload[i]); - } - catch (UnsatisfiedLinkError e) { - if (!preloadIgnoreError && e.getMessage().indexOf("already loaded") < 0) { - throw e; - } - } - } - } - } - - if(DEBUG) { - System.err.println("NEWT NativeLibLoader load "+libname); - } - loadLibraryInternal(libname); - addLoaded(libname); - } - } - - private static boolean usingJNLPAppletLauncher; - private static Method jnlpLoadLibraryMethod; - - static { - NativeLibLoaderBase.setLoadingAction(new NEWTAction()); - String sunAppletLauncher = Debug.getProperty("sun.jnlp.applet.launcher", false); - usingJNLPAppletLauncher = Boolean.valueOf(sunAppletLauncher).booleanValue(); - } - - // I hate the amount of delegation currently in this class - private static void loadLibraryInternal(String libraryName) { - // Note: special-casing JAWT which is built in to the JDK - if (usingJNLPAppletLauncher && !libraryName.equals("jawt")) { - try { - if (jnlpLoadLibraryMethod == null) { - Class jnlpAppletLauncherClass = Class.forName("org.jdesktop.applet.util.JNLPAppletLauncher"); - jnlpLoadLibraryMethod = jnlpAppletLauncherClass.getDeclaredMethod("loadLibrary", new Class[] { String.class }); - } - jnlpLoadLibraryMethod.invoke(null, new Object[] { libraryName }); - } catch (Exception e) { - Throwable t = e; - if (t instanceof InvocationTargetException) { - t = ((InvocationTargetException) t).getTargetException(); - } - if (t instanceof Error) - throw (Error) t; - if (t instanceof RuntimeException) { - throw (RuntimeException) t; - } - // Throw UnsatisfiedLinkError for best compatibility with System.loadLibrary() - throw (UnsatisfiedLinkError) new UnsatisfiedLinkError().initCause(e); - } - } else { - // FIXME: remove - // System.out.println("sun.boot.library.path=" + Debug.getProperty("sun.boot.library.path", false)); - System.loadLibrary(libraryName); - if(DEBUG) { - System.err.println("NEWT NativeLibLoader loaded "+libraryName); - } - } - } } |