diff options
author | Kevin Rushforth <[email protected]> | 2007-05-29 23:18:14 +0000 |
---|---|---|
committer | Kevin Rushforth <[email protected]> | 2007-05-29 23:18:14 +0000 |
commit | 40268679118ccce888ddba29f23512535dd06b19 (patch) | |
tree | 2b8324ca93974f3c32454e7424ec139fa41943e1 /src | |
parent | 77b3a9d13e07c8fb1b9c78a3a9cd19aed14917cc (diff) |
Issue 257: added hooks for JNLPAppletLauncher, a new still-to-be-defined generalization of JOGLAppletLauncher
git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@846 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src')
-rw-r--r-- | src/classes/share/javax/media/j3d/MasterControl.java | 16 | ||||
-rw-r--r-- | src/classes/share/javax/media/j3d/NativePipeline.java | 134 | ||||
-rw-r--r-- | src/classes/share/javax/media/j3d/Pipeline.java | 44 |
3 files changed, 110 insertions, 84 deletions
diff --git a/src/classes/share/javax/media/j3d/MasterControl.java b/src/classes/share/javax/media/j3d/MasterControl.java index f1f1687..dbb79ac 100644 --- a/src/classes/share/javax/media/j3d/MasterControl.java +++ b/src/classes/share/javax/media/j3d/MasterControl.java @@ -86,6 +86,10 @@ class MasterControl { // Flag indicating that the rendering pipeline libraries are loaded private static boolean librariesLoaded = false; + // Issue 257: flag indicating that we are running in "appletLauncher" mode + // and should use JNLPAppletLauncher to load any native libraries + private static boolean appletLauncher = false; + /** * reference to MasterControl thread */ @@ -856,6 +860,10 @@ class MasterControl { boolean isWindowsVista = isWindowsOs && osName.indexOf("vista") != -1; boolean is64Bit = (sunArchDataModel != null) && sunArchDataModel.equals("64"); + // Issue 257: check to see if the sun.applet.launcher property is set to true + String sunAppletLauncher = getProperty("sun.applet.launcher"); + appletLauncher = Boolean.valueOf(sunAppletLauncher); + if (isCoreLoggable(Level.CONFIG)) { StringBuffer strBuf = new StringBuffer(); strBuf.append("MasterControl.loadLibraries()\n"). @@ -1258,6 +1266,14 @@ class MasterControl { } /** + * Returns a flag indicating whether the sun.jnlp.applet.launcher system + * property is set to true. + */ + static boolean isAppletLauncher() { + return appletLauncher; + } + + /** * This method increments and returns the next time value * timeLock must get before this procedure is invoked */ diff --git a/src/classes/share/javax/media/j3d/NativePipeline.java b/src/classes/share/javax/media/j3d/NativePipeline.java index 0ac3b73..94d5ff4 100644 --- a/src/classes/share/javax/media/j3d/NativePipeline.java +++ b/src/classes/share/javax/media/j3d/NativePipeline.java @@ -15,6 +15,8 @@ package javax.media.j3d; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.io.File; +import java.lang.reflect.Method; +import java.security.AccessController; import java.util.ArrayList; /** @@ -52,12 +54,12 @@ class NativePipeline extends Pipeline { static String getSupportedOglVendor() { if (!oglChkLibraryLoaded) { try { - loadLibrary("j3dcore-ogl-chk"); - } catch (RuntimeException ex) { - System.err.println(ex); + loadLibrary("j3dcore-ogl-chk", true); + } catch (Exception ex) { + MasterControl.getCoreLogger().severe(ex.toString()); return null; } catch (Error ex) { - System.err.println(ex); + MasterControl.getCoreLogger().severe(ex.toString()); return null; } oglChkLibraryLoaded = true; @@ -101,29 +103,46 @@ class NativePipeline extends Pipeline { } // Create the singleton, OS-dependent NativeConfigTemplate3D and - // NativeScreenInfo objects. + // NativeScreenInfo objects. NativeConfigTemplate3D.createNativeConfigTemplate3D(); NativeScreenInfo.createNativeScreenInfo(); } - + /** * Load all of the required libraries */ void loadLibraries(int globalShadingLanguage) { - // Load the native JAWT library - loadLibrary("jawt"); - + // Load the native JAWT library as a workaround for a problem whereby + // the native libraries can't find it in some cases. + // Issue 257: ignore UnsatisfiedLinkError exception as a result of + // trying to load the library more than once. Try to continue in + // all cases if the load library fails, since it is just a workaround + // for a native bug. + try { + loadLibrary("jawt", false); + } catch (UnsatisfiedLinkError ex) { + if (ex.getMessage().indexOf("already loaded") == -1) { + // If it failed for a reason other than already being + // loaded, log the error. In either case, we will continue + MasterControl.getCoreLogger().severe(ex.toString()); + } + } catch (Error ex) { + MasterControl.getCoreLogger().severe(ex.toString()); + } catch (Exception ex) { + MasterControl.getCoreLogger().severe(ex.toString()); + } + // Load the native rendering library String libraryName = libPrefix + "-" + rendererName; - loadLibrary(libraryName); - + loadLibrary(libraryName, true); + // Check whether the Cg library is available if (globalShadingLanguage == Shader.SHADING_LANGUAGE_CG) { String cgLibraryName = libPrefix + "-" + rendererName + "-cg"; String[] libpath = setupLibPath(cgLibraryName); cgLibraryAvailable = loadNativeCgLibrary(libpath); } - + // Check whether the GLSL library is available if (globalShadingLanguage == Shader.SHADING_LANGUAGE_GLSL) { if (getPipelineType() == Pipeline.Type.NATIVE_OGL) { @@ -151,17 +170,30 @@ class NativePipeline extends Pipeline { } /** - * Load the specified native library. + * Load the specified native library. If we are running in "appletLauncher" + * mode, we will use JNLPAppletLauncher to load the native library. + * Otherwise, we will use System.loadLibrary(). */ - private static void loadLibrary(String libName) { - final String libraryName = libName; - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - System.loadLibrary(libraryName); - return null; - } - }); + private static void loadLibrary(final String libName, boolean allowAppletLauncher) { + // Issue 257: Call JNLPAppletLauncher to load native libraries if needed + final boolean useAppletLauncher = allowAppletLauncher && MasterControl.isAppletLauncher(); + AccessController.doPrivileged( + new java.security.PrivilegedAction() { + public Object run() { + try { + if (useAppletLauncher) { + Class jnlpAppletLauncherClass = Class.forName("com.sun.applet.util.JNLPAppletLauncher"); + Method loadLibraryMethod = jnlpAppletLauncherClass.getDeclaredMethod("loadLibrary", String.class); + loadLibraryMethod.invoke(null, libName); + } else { + System.loadLibrary(libName); + } + } catch (Exception ex) { + throw new RuntimeException(ex); + } + return null; + } + }); } /** @@ -174,40 +206,40 @@ class NativePipeline extends Pipeline { private String[] setupLibPath(String libName) { final String libraryName = libName; return (String[]) - java.security.AccessController.doPrivileged( + AccessController.doPrivileged( new java.security.PrivilegedAction() { - public Object run() { - ArrayList pathList = new ArrayList(); - - String filename = System.mapLibraryName(libraryName); - for (int n = 0; n < systemPathProps.length; n++) { - String pathString = System.getProperty(systemPathProps[n]); - boolean done = false; - int posStart = 0; - while (!done) { - int posEnd = pathString.indexOf(File.pathSeparator, posStart); - if (posEnd == -1) { - posEnd = pathString.length(); - done = true; + public Object run() { + ArrayList pathList = new ArrayList(); + + String filename = System.mapLibraryName(libraryName); + for (int n = 0; n < systemPathProps.length; n++) { + String pathString = System.getProperty(systemPathProps[n]); + boolean done = false; + int posStart = 0; + while (!done) { + int posEnd = pathString.indexOf(File.pathSeparator, posStart); + if (posEnd == -1) { + posEnd = pathString.length(); + done = true; + } + String pathDir = pathString.substring(posStart, posEnd); + File pathFile = new File(pathDir, filename); + if (pathFile.exists()) { + pathList.add(pathFile.getAbsolutePath()); + } + + posStart = posEnd + 1; + } } - String pathDir = pathString.substring(posStart, posEnd); - File pathFile = new File(pathDir, filename); - if (pathFile.exists()) { - pathList.add(pathFile.getAbsolutePath()); + + // If no absolute path names exist, add in the relative library name + if (pathList.size() == 0) { + pathList.add(filename); } - posStart = posEnd + 1; + return (String[])pathList.toArray(new String[0]); } - } - - // If no absolute path names exist, add in the relative library name - if (pathList.size() == 0) { - pathList.add(filename); - } - - return (String[])pathList.toArray(new String[0]); - } - }); + }); } // Method to verify whether the native Cg library is available diff --git a/src/classes/share/javax/media/j3d/Pipeline.java b/src/classes/share/javax/media/j3d/Pipeline.java index a9f5743..f9871fd 100644 --- a/src/classes/share/javax/media/j3d/Pipeline.java +++ b/src/classes/share/javax/media/j3d/Pipeline.java @@ -14,7 +14,6 @@ package javax.media.j3d; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; -import java.lang.reflect.Method; /** * Abstract pipeline class for rendering pipeline methods. All rendering @@ -56,8 +55,18 @@ abstract class Pipeline { * on Windows. We will use D3D if OpenGL is unavailable or undesirable. */ static boolean useNativeOgl(boolean isWindowsVista, boolean nativeOglRequested) { + // Get the OpenGL vendor string. - String vendorString = getSupportedOglVendor(); + String vendorString; + try { + vendorString = NativePipeline.getSupportedOglVendor(); + } catch (Exception ex) { + MasterControl.getCoreLogger().severe(ex.toString()); + return false; + } catch (Error ex) { + MasterControl.getCoreLogger().severe(ex.toString()); + return false; + } // A null vendor string means OpenGL 1.2+ support unavailable. if (vendorString == null) { @@ -72,37 +81,6 @@ abstract class Pipeline { // Check OS type and vendor string to see whether OGL is preferred return preferOgl(isWindowsVista, vendorString); } - - /** - * Wrapper method that calls the corresponding NativePipeline method via - * reflection. We use reflection to avoid initializing the NativePipeline - * class uless we are actually going to call it. - */ - private static String getSupportedOglVendor() { - try { - Method nativeMethod = (Method) - java.security.AccessController.doPrivileged(new - java.security.PrivilegedAction() { - public Object run() { - try { - Class pipelineClass = Class.forName(CLASSNAME_NATIVE); - return pipelineClass.getDeclaredMethod("getSupportedOglVendor"); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - }); - - String vendorString = (String) nativeMethod.invoke(null); - return vendorString; - } catch (Exception ex) { - System.err.println(ex); - } catch (Error ex) { - System.err.println(ex); - } - - return null; - } // Returns a flag inticating whether the specified vendor prefers OpenGL. private static boolean preferOgl(boolean isWindowsVista, String vendorString) { |