diff options
Diffstat (limited to 'src/classes/share')
4 files changed, 193 insertions, 18 deletions
diff --git a/src/classes/share/javax/media/j3d/MasterControl.java b/src/classes/share/javax/media/j3d/MasterControl.java index c503697..f1f1687 100644 --- a/src/classes/share/javax/media/j3d/MasterControl.java +++ b/src/classes/share/javax/media/j3d/MasterControl.java @@ -1253,7 +1253,7 @@ class MasterControl { * Returns whether we are running on Windows * TODO: most code that cares about this should move into the pipeline */ - final boolean isWindows() { + static final boolean isWindows() { return isWindowsOs; } diff --git a/src/classes/share/javax/media/j3d/NativeConfigTemplate3D.java b/src/classes/share/javax/media/j3d/NativeConfigTemplate3D.java new file mode 100644 index 0000000..d16c0a2 --- /dev/null +++ b/src/classes/share/javax/media/j3d/NativeConfigTemplate3D.java @@ -0,0 +1,108 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +import java.awt.GraphicsConfiguration; + +/** + * Native config template class. A singleton instance of the appropriate + * concrete subclass is created by a factory method using reflection. + */ +abstract class NativeConfigTemplate3D { + // These definitions are used by both the X11 and Win32 subclasses + final static int RED_SIZE = 0; + final static int GREEN_SIZE = 1; + final static int BLUE_SIZE = 2; + final static int ALPHA_SIZE = 3; + final static int ACCUM_BUFFER = 4; + final static int DEPTH_SIZE = 5; + final static int DOUBLEBUFFER = 6; + final static int STEREO = 7; + final static int ANTIALIASING = 8; + final static int STENCIL_SIZE = 9; + final static int NUM_ITEMS = 10; + + private static final String x11ClassName = "javax.media.j3d.X11NativeConfigTemplate3D"; + private static final String win32ClassName = "javax.media.j3d.Win32NativeConfigTemplate3D"; + + // The singleton instance of this class + private static NativeConfigTemplate3D nativeConfigTemplate3D = null; + + protected NativeConfigTemplate3D() { + } + + // This method is called exactly once by the initialization method of + // the NativePipeline class + synchronized static void createNativeConfigTemplate3D() { + String className; + if (MasterControl.isWindows()) { + className = win32ClassName; + } else { + className = x11ClassName; + } + + final String templateClassName = className; + nativeConfigTemplate3D = (NativeConfigTemplate3D) + java.security.AccessController.doPrivileged(new + java.security.PrivilegedAction() { + public Object run() { + try { + Class templateClass = Class.forName(templateClassName); + return templateClass.newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }); + } + + static NativeConfigTemplate3D getNativeConfigTemplate3D() { + return nativeConfigTemplate3D; + } + + + /* + * Chooses the best FBConfig for Java 3D apps. + */ + abstract GraphicsConfiguration getBestConfiguration(GraphicsConfigTemplate3D template, + GraphicsConfiguration[] gc); + + /* + * Determine if a given GraphicsConfiguration object can be used + * by Java 3D. + */ + abstract boolean isGraphicsConfigSupported(GraphicsConfigTemplate3D template, + GraphicsConfiguration gc); + + + // Return whether stereo is available. + abstract boolean hasStereo(Canvas3D c3d); + + // Return the stencil of this canvas. + abstract int getStencilSize(Canvas3D c3d); + + // Return whether a double buffer is available. + abstract boolean hasDoubleBuffer(Canvas3D c3d); + + // Return whether scene antialiasing is available. + abstract boolean hasSceneAntialiasingAccum(Canvas3D c3d); + + + // Return whether scene antialiasing is available. + abstract boolean hasSceneAntialiasingMultisample(Canvas3D c3d); + + // Ensure that the native libraries are loaded + static { + VirtualUniverse.loadLibraries(); + } +} diff --git a/src/classes/share/javax/media/j3d/NativePipeline.java b/src/classes/share/javax/media/j3d/NativePipeline.java index d8341df..0ac3b73 100644 --- a/src/classes/share/javax/media/j3d/NativePipeline.java +++ b/src/classes/share/javax/media/j3d/NativePipeline.java @@ -43,13 +43,6 @@ class NativePipeline extends Pipeline { private boolean cgLibraryAvailable = false; private boolean glslLibraryAvailable = false; - /** - * The platform dependent template. Since there is no - * template-specific instance data in the NativeConfigTemplate3D - * class, we can create one statically. - */ - private static NativeConfigTemplate3D nativeTemplate = new NativeConfigTemplate3D(); - // Flag indicating that the ogl-chk library has been loaded private static boolean oglChkLibraryLoaded = false; @@ -86,7 +79,7 @@ class NativePipeline extends Pipeline { */ void initialize(Pipeline.Type pipelineType) { super.initialize(pipelineType); - + // This works around a native load library bug try { java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit(); @@ -106,6 +99,11 @@ class NativePipeline extends Pipeline { default: assert false; // Should never get here } + + // Create the singleton, OS-dependent NativeConfigTemplate3D and + // NativeScreenInfo objects. + NativeConfigTemplate3D.createNativeConfigTemplate3D(); + NativeScreenInfo.createNativeScreenInfo(); } /** @@ -3263,42 +3261,42 @@ class NativePipeline extends Pipeline { // Get best graphics config from pipeline GraphicsConfiguration getBestConfiguration(GraphicsConfigTemplate3D gct, GraphicsConfiguration[] gc) { - return nativeTemplate.getBestConfiguration(gct, gc); + return NativeConfigTemplate3D.getNativeConfigTemplate3D().getBestConfiguration(gct, gc); } // Determine whether specified graphics config is supported by pipeline boolean isGraphicsConfigSupported(GraphicsConfigTemplate3D gct, GraphicsConfiguration gc) { - return nativeTemplate.isGraphicsConfigSupported(gct, gc); + return NativeConfigTemplate3D.getNativeConfigTemplate3D().isGraphicsConfigSupported(gct, gc); } // Methods to get actual capabilities from Canvas3D boolean hasDoubleBuffer(Canvas3D cv) { - return nativeTemplate.hasDoubleBuffer(cv); + return NativeConfigTemplate3D.getNativeConfigTemplate3D().hasDoubleBuffer(cv); } boolean hasStereo(Canvas3D cv) { - return nativeTemplate.hasStereo(cv); + return NativeConfigTemplate3D.getNativeConfigTemplate3D().hasStereo(cv); } int getStencilSize(Canvas3D cv) { - return nativeTemplate.getStencilSize(cv); + return NativeConfigTemplate3D.getNativeConfigTemplate3D().getStencilSize(cv); } boolean hasSceneAntialiasingMultisample(Canvas3D cv) { - return nativeTemplate.hasSceneAntialiasingMultisample(cv); + return NativeConfigTemplate3D.getNativeConfigTemplate3D().hasSceneAntialiasingMultisample(cv); } boolean hasSceneAntialiasingAccum(Canvas3D cv) { - return nativeTemplate.hasSceneAntialiasingAccum(cv); + return NativeConfigTemplate3D.getNativeConfigTemplate3D().hasSceneAntialiasingAccum(cv); } // Methods to get native WS display and screen long getDisplay() { - return NativeScreenInfo.getDisplay(); + return NativeScreenInfo.getNativeScreenInfo().getDisplay(); } int getScreen(GraphicsDevice graphicsDevice) { - return NativeScreenInfo.getScreen(graphicsDevice); + return NativeScreenInfo.getNativeScreenInfo().getScreen(graphicsDevice); } // --------------------------------------------------------------------- diff --git a/src/classes/share/javax/media/j3d/NativeScreenInfo.java b/src/classes/share/javax/media/j3d/NativeScreenInfo.java new file mode 100644 index 0000000..94502f4 --- /dev/null +++ b/src/classes/share/javax/media/j3d/NativeScreenInfo.java @@ -0,0 +1,69 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +import java.awt.GraphicsDevice; + +/** + * Native screen info class. A singleton instance of the appropriate + * concrete subclass is created by a factory method using reflection. + */ +abstract class NativeScreenInfo { + private static final String x11ClassName = "javax.media.j3d.X11NativeScreenInfo"; + private static final String win32ClassName = "javax.media.j3d.Win32NativeScreenInfo"; + + // The singleton instance of this class + private static NativeScreenInfo nativeScreenInfo = null; + + protected NativeScreenInfo() { + } + + // This method is called exactly once by the initialization method of + // the NativePipeline class + synchronized static void createNativeScreenInfo() { + String className; + if (MasterControl.isWindows()) { + className = win32ClassName; + } else { + className = x11ClassName; + } + + final String scrInfoClassName = className; + nativeScreenInfo = (NativeScreenInfo) + java.security.AccessController.doPrivileged(new + java.security.PrivilegedAction() { + public Object run() { + try { + Class scrInfoClass = Class.forName(scrInfoClassName); + return scrInfoClass.newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }); + } + + static NativeScreenInfo getNativeScreenInfo() { + return nativeScreenInfo; + } + + /** + * Get the display handle + */ + abstract long getDisplay(); + + /** + * Get the screen number for the given graphics device + */ + abstract int getScreen(GraphicsDevice graphicsDevice); +} |