From cb471feee88597a77b715a9039ef6f62ef9fd664 Mon Sep 17 00:00:00 2001 From: Kevin Rushforth Date: Wed, 16 May 2007 22:34:12 +0000 Subject: Source code changes for issue 491: Refactor platform-specific classes to use non-overlapping class names git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@842 ba19aa83-45c5-6ac9-afd3-db810772062c --- .../share/javax/media/j3d/MasterControl.java | 2 +- .../javax/media/j3d/NativeConfigTemplate3D.java | 108 ++++++++ .../share/javax/media/j3d/NativePipeline.java | 32 ++- .../share/javax/media/j3d/NativeScreenInfo.java | 69 +++++ .../javax/media/j3d/NativeConfigTemplate3D.java | 229 ----------------- .../win32/javax/media/j3d/NativeScreenInfo.java | 54 ---- .../media/j3d/Win32NativeConfigTemplate3D.java | 227 +++++++++++++++++ .../javax/media/j3d/Win32NativeScreenInfo.java | 59 +++++ .../javax/media/j3d/NativeConfigTemplate3D.java | 281 --------------------- .../x11/javax/media/j3d/NativeScreenInfo.java | 67 ----- .../javax/media/j3d/X11NativeConfigTemplate3D.java | 279 ++++++++++++++++++++ .../x11/javax/media/j3d/X11NativeScreenInfo.java | 72 ++++++ src/native/build.xml | 42 ++- src/native/d3d/NativeConfigTemplate3D.cpp | 16 +- src/native/ogl/NativeConfigTemplate3D.c | 28 +- src/native/ogl/NativeScreenInfo.c | 16 +- src/native/ogl/gldefs.h | 8 + 17 files changed, 909 insertions(+), 680 deletions(-) create mode 100644 src/classes/share/javax/media/j3d/NativeConfigTemplate3D.java create mode 100644 src/classes/share/javax/media/j3d/NativeScreenInfo.java delete mode 100644 src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java delete mode 100644 src/classes/win32/javax/media/j3d/NativeScreenInfo.java create mode 100644 src/classes/win32/javax/media/j3d/Win32NativeConfigTemplate3D.java create mode 100644 src/classes/win32/javax/media/j3d/Win32NativeScreenInfo.java delete mode 100644 src/classes/x11/javax/media/j3d/NativeConfigTemplate3D.java delete mode 100644 src/classes/x11/javax/media/j3d/NativeScreenInfo.java create mode 100644 src/classes/x11/javax/media/j3d/X11NativeConfigTemplate3D.java create mode 100644 src/classes/x11/javax/media/j3d/X11NativeScreenInfo.java (limited to 'src') 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); +} diff --git a/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java b/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java deleted file mode 100644 index f91986a..0000000 --- a/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * $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; -import java.awt.GraphicsConfiguration; -import sun.awt.Win32GraphicsDevice; -import sun.awt.Win32GraphicsConfig; -import java.awt.GraphicsConfigTemplate; - -class NativeConfigTemplate3D { - private final static boolean debug = false; - - NativeConfigTemplate3D() { - } - - // This definition should match those in solaris NativeConfigTemplate3D.java - 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; - - /** - * selects the proper visual - */ - native int - choosePixelFormat(long ctx, int screen, int[] attrList, long[] pFormatInfo); - - // Native method to free an PixelFormatInfo struct. This is static since it - // may need to be called to clean up the Canvas3D graphicsConfigTable after the - // NativeConfigTemplate3D has been disposed of. - static native void freePixelFormatInfo(long pFormatInfo); - - // Native methods to return whether a particular attribute is available - native boolean isStereoAvailable(long pFormatInfo, boolean offScreen); - native boolean isDoubleBufferAvailable(long pFormatInfo, boolean offScreen); - native boolean isSceneAntialiasingAccumAvailable(long pFormatInfo, boolean offScreen); - native boolean isSceneAntialiasingMultisampleAvailable(long pFormatInfo, boolean offScreen, int screen); - native int getStencilSize(long pFormatInfo, boolean offScreen); - - /** - * Chooses the best PixelFormat for Java 3D apps. - */ - GraphicsConfiguration - getBestConfiguration(GraphicsConfigTemplate3D template, - GraphicsConfiguration[] gc) { - - Win32GraphicsDevice gd = - (Win32GraphicsDevice)((Win32GraphicsConfig)gc[0]).getDevice(); - - /* Not ready to enforce ARB extension in J3D1.3.2, but will likely to - do so in J3D 1.4. - System.out.println("getBestConfiguration : Checking WGL ARB support\n"); - - if (!NativeScreenInfo.isWglARB()) { - Thread.dumpStack(); - System.out.println("getBestConfiguration : WGL ARB support fail\n"); - return null; - } - */ - - // holds the list of attributes to be tramslated - // for glxChooseVisual call - int attrList[] = new int[NUM_ITEMS]; - // assign template values to array - attrList[RED_SIZE] = template.getRedSize(); - attrList[GREEN_SIZE] = template.getGreenSize(); - attrList[BLUE_SIZE] = template.getBlueSize(); - - attrList[DEPTH_SIZE] = template.getDepthSize(); - attrList[DOUBLEBUFFER] = template.getDoubleBuffer(); - attrList[STEREO] = template.getStereo(); - attrList[ANTIALIASING] = template.getSceneAntialiasing(); - attrList[STENCIL_SIZE] = template.getStencilSize(); - // System.out.println("NativeConfigTemplate3D : getStencilSize " + - // attrList[STENCIL_SIZE]); - - int screen = NativeScreenInfo.getScreen(gd); - - long[] pFormatInfo = new long[1]; - - /* Deliberately set this to -1. pFormatInfo is not use in - D3D, so this value will be unchange in the case of D3D. - In the case of OGL, the return value should be 0 or a - positive valid address. - */ - pFormatInfo[0] = -1; - - int pixelFormat = choosePixelFormat(0, screen, attrList, pFormatInfo); - if (debug) { - System.out.println(" choosePixelFormat() returns " + pixelFormat); - System.out.println(" pFormatInfo is " + pFormatInfo[0]); - System.out.println(); - } - - if (pixelFormat < 0) { - // current mode don't support the minimum config - return null; - } - - // Fix to issue 104 -- - // Pass in 0 for pixel format to the AWT. - // ATI driver will lockup pixelFormat, if it is passed to AWT. - GraphicsConfiguration gc1 = Win32GraphicsConfig.getConfig(gd, 0); - - // We need to cache the GraphicsTemplate3D and the private - // pixel format info. - synchronized (Canvas3D.graphicsConfigTable) { - if (Canvas3D.graphicsConfigTable.get(gc1) == null) { - GraphicsConfigInfo gcInfo = new GraphicsConfigInfo(template); - gcInfo.setPrivateData(new Long(pFormatInfo[0])); - Canvas3D.graphicsConfigTable.put(gc1, gcInfo); - } else { - freePixelFormatInfo(pFormatInfo[0]); - } - } - - return gc1; - } - - /** - * Determine if a given GraphicsConfiguration object can be used - * by Java 3D. - */ - boolean isGraphicsConfigSupported(GraphicsConfigTemplate3D template, - GraphicsConfiguration gc) { - - Win32GraphicsDevice gd = - (Win32GraphicsDevice)((Win32GraphicsConfig) gc).getDevice(); - - /* Not ready to enforce ARB extension in J3D1.3.2, but will likely to - do so in J3D 1.4. - System.out.println("isGraphicsConfigSupported : Checking WGL ARB support\n"); - - if (!NativeScreenInfo.isWglARB()) { - Thread.dumpStack(); - System.out.println("isGraphicsConfigSupported : WGL ARB support fail\n"); - return false; - } - */ - - // holds the list of attributes to be tramslated - // for glxChooseVisual call - int attrList[] = new int[NUM_ITEMS]; - // assign template values to array - attrList[RED_SIZE] = template.getRedSize(); - attrList[GREEN_SIZE] = template.getGreenSize(); - attrList[BLUE_SIZE] = template.getBlueSize(); - - attrList[DEPTH_SIZE] = template.getDepthSize(); - attrList[DOUBLEBUFFER] = template.getDoubleBuffer(); - attrList[STEREO] = template.getStereo(); - attrList[ANTIALIASING] = template.getSceneAntialiasing(); - attrList[STENCIL_SIZE] = template.getStencilSize(); - // System.out.println("NativeConfigTemplate3D : getStencilSize " + - // attrList[STENCIL_SIZE]); - - int screen = NativeScreenInfo.getScreen(gd); - - long[] pFormatInfo = new long[1]; - - int pixelFormat = choosePixelFormat(0, screen, attrList, pFormatInfo); - if (debug) { - System.out.println(" choosePixelFormat() returns " + pixelFormat); - System.out.println(" pFormatInfo is " + pFormatInfo[0]); - System.out.println(); - } - - if (pixelFormat < 0) { - // current mode don't support the minimum config - return false; - } else - return true; - } - - - // Return whether stereo is available. - boolean hasStereo(Canvas3D c3d) { - return isStereoAvailable(c3d.fbConfig, c3d.offScreen); - } - - // Return the stencil of this canvas. - int getStencilSize(Canvas3D c3d) { - return getStencilSize(c3d.fbConfig, c3d.offScreen); - } - - // Return whether a double buffer is available. - boolean hasDoubleBuffer(Canvas3D c3d) { - return isDoubleBufferAvailable(c3d.fbConfig, c3d.offScreen); - } - - // Return whether scene antialiasing is available. - boolean hasSceneAntialiasingAccum(Canvas3D c3d) { - return isSceneAntialiasingAccumAvailable(c3d.fbConfig, c3d.offScreen); - } - - // Return whether scene antialiasing is available. - boolean hasSceneAntialiasingMultisample(Canvas3D c3d) { - GraphicsConfiguration gc = c3d.graphicsConfiguration; - - Win32GraphicsDevice gd = - (Win32GraphicsDevice)((Win32GraphicsConfig)gc).getDevice(); - int screen = NativeScreenInfo.getScreen(gd); - /* Fix to issue 77 */ - return isSceneAntialiasingMultisampleAvailable(c3d.fbConfig, c3d.offScreen, screen); - } - - // Ensure that the native libraries are loaded - static { - VirtualUniverse.loadLibraries(); - } -} diff --git a/src/classes/win32/javax/media/j3d/NativeScreenInfo.java b/src/classes/win32/javax/media/j3d/NativeScreenInfo.java deleted file mode 100644 index 61066b9..0000000 --- a/src/classes/win32/javax/media/j3d/NativeScreenInfo.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * $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; -import sun.awt.Win32GraphicsDevice; - -class NativeScreenInfo { - private static final long display = 0; // unused for Win32 - - private static boolean wglARBChecked = false; - private static boolean isWglARB; - - private static native boolean queryWglARB(); - - private NativeScreenInfo() { - throw new AssertionError("constructor should never be called"); - } - - // This method will return true if wglGetExtensionsStringARB is supported, - // else return false - static synchronized boolean isWglARB() { - - if (!wglARBChecked) { - // Query for wglGetExtensionsStringARB support. - isWglARB = queryWglARB(); - wglARBChecked = true; - } - return isWglARB; - } - - static long getDisplay() { - return display; - } - - static int getScreen(GraphicsDevice graphicsDevice) { - return ((Win32GraphicsDevice)graphicsDevice).getScreen(); - } - - // Ensure that the native libraries are loaded - static { - VirtualUniverse.loadLibraries(); - } -} diff --git a/src/classes/win32/javax/media/j3d/Win32NativeConfigTemplate3D.java b/src/classes/win32/javax/media/j3d/Win32NativeConfigTemplate3D.java new file mode 100644 index 0000000..10edfd1 --- /dev/null +++ b/src/classes/win32/javax/media/j3d/Win32NativeConfigTemplate3D.java @@ -0,0 +1,227 @@ +/* + * $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; +import java.awt.GraphicsConfiguration; +import sun.awt.Win32GraphicsDevice; +import sun.awt.Win32GraphicsConfig; +import java.awt.GraphicsConfigTemplate; + +/** + * Native config template class. A singleton instance of this class is + * created by a factory method in the base class using reflection. + */ +class Win32NativeConfigTemplate3D extends NativeConfigTemplate3D { + private final static boolean debug = false; + + Win32NativeConfigTemplate3D() { + } + + /** + * selects the proper visual + */ + native int + choosePixelFormat(long ctx, int screen, int[] attrList, long[] pFormatInfo); + + // Native method to free an PixelFormatInfo struct. This is static since it + // may need to be called to clean up the Canvas3D graphicsConfigTable after the + // Win32NativeConfigTemplate3D has been disposed of. + static native void freePixelFormatInfo(long pFormatInfo); + + // Native methods to return whether a particular attribute is available + native boolean isStereoAvailable(long pFormatInfo, boolean offScreen); + native boolean isDoubleBufferAvailable(long pFormatInfo, boolean offScreen); + native boolean isSceneAntialiasingAccumAvailable(long pFormatInfo, boolean offScreen); + native boolean isSceneAntialiasingMultisampleAvailable(long pFormatInfo, boolean offScreen, int screen); + native int getStencilSize(long pFormatInfo, boolean offScreen); + + /** + * Chooses the best PixelFormat for Java 3D apps. + */ + @Override + GraphicsConfiguration + getBestConfiguration(GraphicsConfigTemplate3D template, + GraphicsConfiguration[] gc) { + + Win32GraphicsDevice gd = + (Win32GraphicsDevice)((Win32GraphicsConfig)gc[0]).getDevice(); + + /* Not ready to enforce ARB extension in J3D1.3.2, but will likely to + do so in J3D 1.4. + System.out.println("getBestConfiguration : Checking WGL ARB support\n"); + + if (!Win32NativeScreenInfo.isWglARB()) { + Thread.dumpStack(); + System.out.println("getBestConfiguration : WGL ARB support fail\n"); + return null; + } + */ + + // holds the list of attributes to be tramslated + // for glxChooseVisual call + int attrList[] = new int[NUM_ITEMS]; + // assign template values to array + attrList[RED_SIZE] = template.getRedSize(); + attrList[GREEN_SIZE] = template.getGreenSize(); + attrList[BLUE_SIZE] = template.getBlueSize(); + + attrList[DEPTH_SIZE] = template.getDepthSize(); + attrList[DOUBLEBUFFER] = template.getDoubleBuffer(); + attrList[STEREO] = template.getStereo(); + attrList[ANTIALIASING] = template.getSceneAntialiasing(); + attrList[STENCIL_SIZE] = template.getStencilSize(); + // System.out.println("Win32NativeConfigTemplate3D : getStencilSize " + + // attrList[STENCIL_SIZE]); + + int screen = NativeScreenInfo.getNativeScreenInfo().getScreen(gd); + + long[] pFormatInfo = new long[1]; + + /* Deliberately set this to -1. pFormatInfo is not use in + D3D, so this value will be unchange in the case of D3D. + In the case of OGL, the return value should be 0 or a + positive valid address. + */ + pFormatInfo[0] = -1; + + int pixelFormat = choosePixelFormat(0, screen, attrList, pFormatInfo); + if (debug) { + System.out.println(" choosePixelFormat() returns " + pixelFormat); + System.out.println(" pFormatInfo is " + pFormatInfo[0]); + System.out.println(); + } + + if (pixelFormat < 0) { + // current mode don't support the minimum config + return null; + } + + // Fix to issue 104 -- + // Pass in 0 for pixel format to the AWT. + // ATI driver will lockup pixelFormat, if it is passed to AWT. + GraphicsConfiguration gc1 = Win32GraphicsConfig.getConfig(gd, 0); + + // We need to cache the GraphicsTemplate3D and the private + // pixel format info. + synchronized (Canvas3D.graphicsConfigTable) { + if (Canvas3D.graphicsConfigTable.get(gc1) == null) { + GraphicsConfigInfo gcInfo = new GraphicsConfigInfo(template); + gcInfo.setPrivateData(new Long(pFormatInfo[0])); + Canvas3D.graphicsConfigTable.put(gc1, gcInfo); + } else { + freePixelFormatInfo(pFormatInfo[0]); + } + } + + return gc1; + } + + /** + * Determine if a given GraphicsConfiguration object can be used + * by Java 3D. + */ + @Override + boolean isGraphicsConfigSupported(GraphicsConfigTemplate3D template, + GraphicsConfiguration gc) { + + Win32GraphicsDevice gd = + (Win32GraphicsDevice)((Win32GraphicsConfig) gc).getDevice(); + + /* Not ready to enforce ARB extension in J3D1.3.2, but will likely to + do so in J3D 1.4. + System.out.println("isGraphicsConfigSupported : Checking WGL ARB support\n"); + + if (!Win32NativeScreenInfo.isWglARB()) { + Thread.dumpStack(); + System.out.println("isGraphicsConfigSupported : WGL ARB support fail\n"); + return false; + } + */ + + // holds the list of attributes to be tramslated + // for glxChooseVisual call + int attrList[] = new int[NUM_ITEMS]; + // assign template values to array + attrList[RED_SIZE] = template.getRedSize(); + attrList[GREEN_SIZE] = template.getGreenSize(); + attrList[BLUE_SIZE] = template.getBlueSize(); + + attrList[DEPTH_SIZE] = template.getDepthSize(); + attrList[DOUBLEBUFFER] = template.getDoubleBuffer(); + attrList[STEREO] = template.getStereo(); + attrList[ANTIALIASING] = template.getSceneAntialiasing(); + attrList[STENCIL_SIZE] = template.getStencilSize(); + // System.out.println("Win32NativeConfigTemplate3D : getStencilSize " + + // attrList[STENCIL_SIZE]); + + int screen = NativeScreenInfo.getNativeScreenInfo().getScreen(gd); + + long[] pFormatInfo = new long[1]; + + int pixelFormat = choosePixelFormat(0, screen, attrList, pFormatInfo); + if (debug) { + System.out.println(" choosePixelFormat() returns " + pixelFormat); + System.out.println(" pFormatInfo is " + pFormatInfo[0]); + System.out.println(); + } + + if (pixelFormat < 0) { + // current mode don't support the minimum config + return false; + } else + return true; + } + + + // Return whether stereo is available. + @Override + boolean hasStereo(Canvas3D c3d) { + return isStereoAvailable(c3d.fbConfig, c3d.offScreen); + } + + // Return the stencil of this canvas. + @Override + int getStencilSize(Canvas3D c3d) { + return getStencilSize(c3d.fbConfig, c3d.offScreen); + } + + // Return whether a double buffer is available. + @Override + boolean hasDoubleBuffer(Canvas3D c3d) { + return isDoubleBufferAvailable(c3d.fbConfig, c3d.offScreen); + } + + // Return whether scene antialiasing is available. + @Override + boolean hasSceneAntialiasingAccum(Canvas3D c3d) { + return isSceneAntialiasingAccumAvailable(c3d.fbConfig, c3d.offScreen); + } + + // Return whether scene antialiasing is available. + @Override + boolean hasSceneAntialiasingMultisample(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + + Win32GraphicsDevice gd = + (Win32GraphicsDevice)((Win32GraphicsConfig)gc).getDevice(); + int screen = NativeScreenInfo.getNativeScreenInfo().getScreen(gd); + /* Fix to issue 77 */ + return isSceneAntialiasingMultisampleAvailable(c3d.fbConfig, c3d.offScreen, screen); + } + + // Ensure that the native libraries are loaded + static { + VirtualUniverse.loadLibraries(); + } +} diff --git a/src/classes/win32/javax/media/j3d/Win32NativeScreenInfo.java b/src/classes/win32/javax/media/j3d/Win32NativeScreenInfo.java new file mode 100644 index 0000000..0a6a105 --- /dev/null +++ b/src/classes/win32/javax/media/j3d/Win32NativeScreenInfo.java @@ -0,0 +1,59 @@ +/* + * $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; +import sun.awt.Win32GraphicsDevice; + +/** + * Native screen info class. A singleton instance of this class is created by + * a factory method in the base class using reflection. + */ +class Win32NativeScreenInfo extends NativeScreenInfo { + private static final long display = 0; // unused for Win32 + + private static boolean wglARBChecked = false; + private static boolean isWglARB; + + private static native boolean queryWglARB(); + + Win32NativeScreenInfo() { + } + + // This method will return true if wglGetExtensionsStringARB is supported, + // else return false + static synchronized boolean isWglARB() { + + if (!wglARBChecked) { + // Query for wglGetExtensionsStringARB support. + isWglARB = queryWglARB(); + wglARBChecked = true; + } + return isWglARB; + } + + @Override + long getDisplay() { + return display; + } + + @Override + int getScreen(GraphicsDevice graphicsDevice) { + return ((Win32GraphicsDevice)graphicsDevice).getScreen(); + } + + // Ensure that the native libraries are loaded + static { + VirtualUniverse.loadLibraries(); + } +} diff --git a/src/classes/x11/javax/media/j3d/NativeConfigTemplate3D.java b/src/classes/x11/javax/media/j3d/NativeConfigTemplate3D.java deleted file mode 100644 index d1d2000..0000000 --- a/src/classes/x11/javax/media/j3d/NativeConfigTemplate3D.java +++ /dev/null @@ -1,281 +0,0 @@ -/* - * $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; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsConfigTemplate; -import java.awt.Rectangle; -import sun.awt.X11GraphicsDevice; -import sun.awt.X11GraphicsConfig; - -class NativeConfigTemplate3D { - private final static boolean debug = false; - - NativeConfigTemplate3D() { - } - - // These definitions should match those in win32 NativeConfigTemplate3D.java - 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; - - // Native method to get an OpenGL visual id and a pointer to the - // GLXFBConfig structure list itself. - native int chooseOglVisual(long display, int screen, - int[] attrList, long[] fbConfig); - - // Native method to free an GLXFBConfig struct. This is static since it - // may need to be called to clean up the Canvas3D graphicsConfigTable - // after the NativeConfigTemplate3D has been disposed of. - static native void freeFBConfig(long fbConfig); - - // Native methods to return whether a particular attribute is available - native boolean isStereoAvailable(long display, int screen, int vid); - native boolean isDoubleBufferAvailable(long display, int screen, int vid); - native boolean isSceneAntialiasingAccumAvailable(long display, int screen, int vid); - native boolean isSceneAntialiasingMultisampleAvailable(long display, int screen, int vid); - native int getStencilSize(long display, int screen, int vid); - - /* - * Chooses the best FBConfig for Java 3D apps. - */ - GraphicsConfiguration getBestConfiguration(GraphicsConfigTemplate3D template, - GraphicsConfiguration[] gc) { - - X11GraphicsDevice gd = - (X11GraphicsDevice)((X11GraphicsConfig)gc[0]).getDevice(); - - if (!NativeScreenInfo.isGLX13()) { - return null; - } - - long display = NativeScreenInfo.getDisplay(); - int screen = NativeScreenInfo.getScreen(gd); - - if (debug) { - System.out.println(" NativeConfigTemplate3D: using device " + gd); - System.out.println(" display " + display + " screen " + screen); - System.out.println(" configuration count: " + gc.length); - for (int i = 0 ; i < gc.length ; i++) { - System.out.println(" visual id at index " + i + ": " + - ((X11GraphicsConfig)gc[i]).getVisual()); - } - } - - Rectangle bounds = gc[0].getBounds(); - if ((bounds.x != 0 || bounds.y != 0) && - (! VirtualUniverse.mc.xineramaDisabled)) { - // Xinerama is being used. The screen needs to be set to 0 since - // glxChooseFBConfig will not return a valid visual otherwise. - screen = 0; - if (debug) { - System.out.println(" Non-primary Xinerama screen:"); - System.out.println(" bounds = " + bounds); - System.out.println(" using screen 0 visual"); - } - } - - int[] attrList; // holds the list of attributes to be translated - // for glxChooseFBConfig call - - attrList = new int[NUM_ITEMS]; - - // assign template values to array - attrList[RED_SIZE] = template.getRedSize(); - attrList[GREEN_SIZE] = template.getGreenSize(); - attrList[BLUE_SIZE] = template.getBlueSize(); - - attrList[DEPTH_SIZE] = template.getDepthSize(); - attrList[DOUBLEBUFFER] = template.getDoubleBuffer(); - attrList[STEREO] = template.getStereo(); - attrList[ANTIALIASING] = template.getSceneAntialiasing(); - attrList[STENCIL_SIZE] = template.getStencilSize(); - // System.out.println("NativeConfigTemplate3D : getStencilSize " + - // attrList[STENCIL_SIZE]); - - long[] fbConfig = new long[1]; - int visID = chooseOglVisual(display, screen, attrList, fbConfig); - if (debug) { - System.out.println(" chooseOglVisual() returns " + visID); - System.out.println(" pointer to GLXFBConfig is " + fbConfig[0]); - System.out.println(); - } - - if (visID == 0 || fbConfig[0] == 0) { - return null; // no valid visual was found - } - - // search list of graphics configurations for config - // with matching visualId - X11GraphicsConfig gc0 = null; - for (int i = 0; i < gc.length; i++) { - if (((X11GraphicsConfig)gc[i]).getVisual() == visID) { - gc0 = (X11GraphicsConfig)gc[i]; - break; - } - } - - // Just return if we didn't find a match - if (gc0 == null) { - return null; - } - - // Create a new GraphicsConfig object based on the one we found - X11GraphicsConfig gc1 = - X11GraphicsConfig.getConfig(gd, gc0.getVisual(), - gc0.getDepth(), gc0.getColormap(), false); - - // We need to cache the GraphicsTemplate3D and the private - // fbconfig info. - synchronized (Canvas3D.graphicsConfigTable) { - if (Canvas3D.graphicsConfigTable.get(gc1) == null) { - GraphicsConfigInfo gcInfo = new GraphicsConfigInfo(template); - gcInfo.setPrivateData(new Long(fbConfig[0])); - Canvas3D.graphicsConfigTable.put(gc1, gcInfo); - } else { - freeFBConfig(fbConfig[0]); - } - } - return gc1; - } - - /* - * Determine if a given GraphicsConfiguration object can be used - * by Java 3D. - */ - boolean isGraphicsConfigSupported(GraphicsConfigTemplate3D template, - GraphicsConfiguration gc) { - - X11GraphicsDevice gd = - (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); - - if (!NativeScreenInfo.isGLX13()) { - return false; - } - - long display = NativeScreenInfo.getDisplay(); - int screen = NativeScreenInfo.getScreen(gd); - - int[] attrList; // holds the list of attributes to be tramslated - // for glxChooseVisual call - - attrList = new int[NUM_ITEMS]; - - // assign template values to array - attrList[RED_SIZE] = template.getRedSize(); - attrList[GREEN_SIZE] = template.getGreenSize(); - attrList[BLUE_SIZE] = template.getBlueSize(); - - attrList[DEPTH_SIZE] = template.getDepthSize(); - attrList[DOUBLEBUFFER] = template.getDoubleBuffer(); - attrList[STEREO] = template.getStereo(); - attrList[ANTIALIASING] = template.getSceneAntialiasing(); - attrList[STENCIL_SIZE] = template.getStencilSize(); - // System.out.println("NativeConfigTemplate3D : getStencilSize " + - // attrList[STENCIL_SIZE]); - - long[] fbConfig = new long[1]; - int visID = chooseOglVisual(display, screen, attrList, fbConfig); - - if (visID == 0 || fbConfig[0] == 0) - return false; // no valid visual was found - else - return true; - } - - - // Return whether stereo is available. - boolean hasStereo(Canvas3D c3d) { - GraphicsConfiguration gc = c3d.graphicsConfiguration; - - X11GraphicsDevice gd = - (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); - - long display = NativeScreenInfo.getDisplay(); - int screen = NativeScreenInfo.getScreen(gd); - int vid = ((X11GraphicsConfig)gc).getVisual(); - - return isStereoAvailable(display, screen, vid); - } - - // Return the stencil of this canvas. - int getStencilSize(Canvas3D c3d) { - GraphicsConfiguration gc = c3d.graphicsConfiguration; - - X11GraphicsDevice gd = - (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); - - long display = NativeScreenInfo.getDisplay(); - int screen = NativeScreenInfo.getScreen(gd); - int vid = ((X11GraphicsConfig)gc).getVisual(); - - return getStencilSize(display, screen, vid); - } - - // Return whether a double buffer is available. - boolean hasDoubleBuffer(Canvas3D c3d) { - GraphicsConfiguration gc = c3d.graphicsConfiguration; - - X11GraphicsDevice gd = - (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); - - long display = NativeScreenInfo.getDisplay(); - int screen = NativeScreenInfo.getScreen(gd); - int vid = ((X11GraphicsConfig)gc).getVisual(); - - return isDoubleBufferAvailable(display, screen, vid); - } - - // Return whether scene antialiasing is available. - boolean hasSceneAntialiasingAccum(Canvas3D c3d) { - GraphicsConfiguration gc = c3d.graphicsConfiguration; - - X11GraphicsDevice gd = - (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); - - long display = NativeScreenInfo.getDisplay(); - int screen = NativeScreenInfo.getScreen(gd); - int vid = ((X11GraphicsConfig)gc).getVisual(); - - return isSceneAntialiasingAccumAvailable(display, screen, vid); - } - - - // Return whether scene antialiasing is available. - boolean hasSceneAntialiasingMultisample(Canvas3D c3d) { - GraphicsConfiguration gc = c3d.graphicsConfiguration; - - X11GraphicsDevice gd = - (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); - - long display = NativeScreenInfo.getDisplay(); - int screen = NativeScreenInfo.getScreen(gd); - int vid = ((X11GraphicsConfig)gc).getVisual(); - - return isSceneAntialiasingMultisampleAvailable(display, screen, vid); - } - - // Ensure that the native libraries are loaded - static { - VirtualUniverse.loadLibraries(); - } -} diff --git a/src/classes/x11/javax/media/j3d/NativeScreenInfo.java b/src/classes/x11/javax/media/j3d/NativeScreenInfo.java deleted file mode 100644 index c352467..0000000 --- a/src/classes/x11/javax/media/j3d/NativeScreenInfo.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * $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; -import sun.awt.X11GraphicsDevice; - -class NativeScreenInfo { - private static long display = 0; - private static boolean glxChecked = false; - private static boolean isGLX13; - - private static native long openDisplay(); - private static native boolean queryGLX13(long display); - - private NativeScreenInfo() { - throw new AssertionError("constructor should never be called"); - } - - // Fix for issue 20. - // This method will return true if glx version is 1.3 or higher, - // else return false. - static synchronized boolean isGLX13() { - if (!glxChecked) { - // Open a new static display connection if one is not already opened. - getStaticDisplay(); - - // Query for glx1.3 support. - isGLX13 = queryGLX13(getDisplay()); - glxChecked = true; - } - - return isGLX13; - } - - private static synchronized long getStaticDisplay() { - if (display == 0) { - display = openDisplay(); - } - return display; - } - - static long getDisplay() { - // Open a new static display connection if one is not already opened - return getStaticDisplay(); - } - - static int getScreen(GraphicsDevice graphicsDevice) { - // Get the screen number - return ((X11GraphicsDevice)graphicsDevice).getScreen(); - } - - // Ensure that the native libraries are loaded - static { - VirtualUniverse.loadLibraries(); - } -} diff --git a/src/classes/x11/javax/media/j3d/X11NativeConfigTemplate3D.java b/src/classes/x11/javax/media/j3d/X11NativeConfigTemplate3D.java new file mode 100644 index 0000000..8a46d3b --- /dev/null +++ b/src/classes/x11/javax/media/j3d/X11NativeConfigTemplate3D.java @@ -0,0 +1,279 @@ +/* + * $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; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsConfigTemplate; +import java.awt.Rectangle; +import sun.awt.X11GraphicsDevice; +import sun.awt.X11GraphicsConfig; + +/** + * Native config template class. A singleton instance of this class is + * created by a factory method in the base class using reflection. + */ +class X11NativeConfigTemplate3D extends NativeConfigTemplate3D { + private final static boolean debug = false; + + X11NativeConfigTemplate3D() { + } + + // Native method to get an OpenGL visual id and a pointer to the + // GLXFBConfig structure list itself. + native int chooseOglVisual(long display, int screen, + int[] attrList, long[] fbConfig); + + // Native method to free an GLXFBConfig struct. This is static since it + // may need to be called to clean up the Canvas3D graphicsConfigTable + // after the X11NativeConfigTemplate3D has been disposed of. + static native void freeFBConfig(long fbConfig); + + // Native methods to return whether a particular attribute is available + native boolean isStereoAvailable(long display, int screen, int vid); + native boolean isDoubleBufferAvailable(long display, int screen, int vid); + native boolean isSceneAntialiasingAccumAvailable(long display, int screen, int vid); + native boolean isSceneAntialiasingMultisampleAvailable(long display, int screen, int vid); + native int getStencilSize(long display, int screen, int vid); + + /* + * Chooses the best FBConfig for Java 3D apps. + */ + @Override + GraphicsConfiguration getBestConfiguration(GraphicsConfigTemplate3D template, + GraphicsConfiguration[] gc) { + + X11GraphicsDevice gd = + (X11GraphicsDevice)((X11GraphicsConfig)gc[0]).getDevice(); + + if (!X11NativeScreenInfo.isGLX13()) { + return null; + } + + long display = NativeScreenInfo.getNativeScreenInfo().getDisplay(); + int screen = NativeScreenInfo.getNativeScreenInfo().getScreen(gd); + + if (debug) { + System.out.println(" X11NativeConfigTemplate3D: using device " + gd); + System.out.println(" display " + display + " screen " + screen); + System.out.println(" configuration count: " + gc.length); + for (int i = 0 ; i < gc.length ; i++) { + System.out.println(" visual id at index " + i + ": " + + ((X11GraphicsConfig)gc[i]).getVisual()); + } + } + + Rectangle bounds = gc[0].getBounds(); + if ((bounds.x != 0 || bounds.y != 0) && + (! VirtualUniverse.mc.xineramaDisabled)) { + // Xinerama is being used. The screen needs to be set to 0 since + // glxChooseFBConfig will not return a valid visual otherwise. + screen = 0; + if (debug) { + System.out.println(" Non-primary Xinerama screen:"); + System.out.println(" bounds = " + bounds); + System.out.println(" using screen 0 visual"); + } + } + + int[] attrList; // holds the list of attributes to be translated + // for glxChooseFBConfig call + + attrList = new int[NUM_ITEMS]; + + // assign template values to array + attrList[RED_SIZE] = template.getRedSize(); + attrList[GREEN_SIZE] = template.getGreenSize(); + attrList[BLUE_SIZE] = template.getBlueSize(); + + attrList[DEPTH_SIZE] = template.getDepthSize(); + attrList[DOUBLEBUFFER] = template.getDoubleBuffer(); + attrList[STEREO] = template.getStereo(); + attrList[ANTIALIASING] = template.getSceneAntialiasing(); + attrList[STENCIL_SIZE] = template.getStencilSize(); + // System.out.println("X11NativeConfigTemplate3D : getStencilSize " + + // attrList[STENCIL_SIZE]); + + long[] fbConfig = new long[1]; + int visID = chooseOglVisual(display, screen, attrList, fbConfig); + if (debug) { + System.out.println(" chooseOglVisual() returns " + visID); + System.out.println(" pointer to GLXFBConfig is " + fbConfig[0]); + System.out.println(); + } + + if (visID == 0 || fbConfig[0] == 0) { + return null; // no valid visual was found + } + + // search list of graphics configurations for config + // with matching visualId + X11GraphicsConfig gc0 = null; + for (int i = 0; i < gc.length; i++) { + if (((X11GraphicsConfig)gc[i]).getVisual() == visID) { + gc0 = (X11GraphicsConfig)gc[i]; + break; + } + } + + // Just return if we didn't find a match + if (gc0 == null) { + return null; + } + + // Create a new GraphicsConfig object based on the one we found + X11GraphicsConfig gc1 = + X11GraphicsConfig.getConfig(gd, gc0.getVisual(), + gc0.getDepth(), gc0.getColormap(), false); + + // We need to cache the GraphicsTemplate3D and the private + // fbconfig info. + synchronized (Canvas3D.graphicsConfigTable) { + if (Canvas3D.graphicsConfigTable.get(gc1) == null) { + GraphicsConfigInfo gcInfo = new GraphicsConfigInfo(template); + gcInfo.setPrivateData(new Long(fbConfig[0])); + Canvas3D.graphicsConfigTable.put(gc1, gcInfo); + } else { + freeFBConfig(fbConfig[0]); + } + } + return gc1; + } + + /* + * Determine if a given GraphicsConfiguration object can be used + * by Java 3D. + */ + @Override + boolean isGraphicsConfigSupported(GraphicsConfigTemplate3D template, + GraphicsConfiguration gc) { + + X11GraphicsDevice gd = + (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); + + if (!X11NativeScreenInfo.isGLX13()) { + return false; + } + + long display = NativeScreenInfo.getNativeScreenInfo().getDisplay(); + int screen = NativeScreenInfo.getNativeScreenInfo().getScreen(gd); + + int[] attrList; // holds the list of attributes to be tramslated + // for glxChooseVisual call + + attrList = new int[NUM_ITEMS]; + + // assign template values to array + attrList[RED_SIZE] = template.getRedSize(); + attrList[GREEN_SIZE] = template.getGreenSize(); + attrList[BLUE_SIZE] = template.getBlueSize(); + + attrList[DEPTH_SIZE] = template.getDepthSize(); + attrList[DOUBLEBUFFER] = template.getDoubleBuffer(); + attrList[STEREO] = template.getStereo(); + attrList[ANTIALIASING] = template.getSceneAntialiasing(); + attrList[STENCIL_SIZE] = template.getStencilSize(); + // System.out.println("X11NativeConfigTemplate3D : getStencilSize " + + // attrList[STENCIL_SIZE]); + + long[] fbConfig = new long[1]; + int visID = chooseOglVisual(display, screen, attrList, fbConfig); + + if (visID == 0 || fbConfig[0] == 0) + return false; // no valid visual was found + else + return true; + } + + + // Return whether stereo is available. + @Override + boolean hasStereo(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + + X11GraphicsDevice gd = + (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); + + long display = NativeScreenInfo.getNativeScreenInfo().getDisplay(); + int screen = NativeScreenInfo.getNativeScreenInfo().getScreen(gd); + int vid = ((X11GraphicsConfig)gc).getVisual(); + + return isStereoAvailable(display, screen, vid); + } + + // Return the stencil of this canvas. + @Override + int getStencilSize(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + + X11GraphicsDevice gd = + (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); + + long display = NativeScreenInfo.getNativeScreenInfo().getDisplay(); + int screen = NativeScreenInfo.getNativeScreenInfo().getScreen(gd); + int vid = ((X11GraphicsConfig)gc).getVisual(); + + return getStencilSize(display, screen, vid); + } + + // Return whether a double buffer is available. + @Override + boolean hasDoubleBuffer(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + + X11GraphicsDevice gd = + (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); + + long display = NativeScreenInfo.getNativeScreenInfo().getDisplay(); + int screen = NativeScreenInfo.getNativeScreenInfo().getScreen(gd); + int vid = ((X11GraphicsConfig)gc).getVisual(); + + return isDoubleBufferAvailable(display, screen, vid); + } + + // Return whether scene antialiasing is available. + @Override + boolean hasSceneAntialiasingAccum(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + + X11GraphicsDevice gd = + (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); + + long display = NativeScreenInfo.getNativeScreenInfo().getDisplay(); + int screen = NativeScreenInfo.getNativeScreenInfo().getScreen(gd); + int vid = ((X11GraphicsConfig)gc).getVisual(); + + return isSceneAntialiasingAccumAvailable(display, screen, vid); + } + + + // Return whether scene antialiasing is available. + @Override + boolean hasSceneAntialiasingMultisample(Canvas3D c3d) { + GraphicsConfiguration gc = c3d.graphicsConfiguration; + + X11GraphicsDevice gd = + (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice(); + + long display = NativeScreenInfo.getNativeScreenInfo().getDisplay(); + int screen = NativeScreenInfo.getNativeScreenInfo().getScreen(gd); + int vid = ((X11GraphicsConfig)gc).getVisual(); + + return isSceneAntialiasingMultisampleAvailable(display, screen, vid); + } + + // Ensure that the native libraries are loaded + static { + VirtualUniverse.loadLibraries(); + } +} diff --git a/src/classes/x11/javax/media/j3d/X11NativeScreenInfo.java b/src/classes/x11/javax/media/j3d/X11NativeScreenInfo.java new file mode 100644 index 0000000..bb19002 --- /dev/null +++ b/src/classes/x11/javax/media/j3d/X11NativeScreenInfo.java @@ -0,0 +1,72 @@ +/* + * $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; +import sun.awt.X11GraphicsDevice; + +/** + * Native screen info class. A singleton instance of this class is created by + * a factory method in the base class using reflection. + */ +class X11NativeScreenInfo extends NativeScreenInfo { + private static long display = 0; + private static boolean glxChecked = false; + private static boolean isGLX13; + + private static native long openDisplay(); + private static native boolean queryGLX13(long display); + + X11NativeScreenInfo() { + } + + // Fix for issue 20. + // This method will return true if glx version is 1.3 or higher, + // else return false. + static synchronized boolean isGLX13() { + if (!glxChecked) { + // Open a new static display connection if one is not already opened. + getStaticDisplay(); + + // Query for glx1.3 support. + isGLX13 = queryGLX13(getStaticDisplay()); + glxChecked = true; + } + + return isGLX13; + } + + private static synchronized long getStaticDisplay() { + if (display == 0) { + display = openDisplay(); + } + return display; + } + + @Override + long getDisplay() { + // Open a new static display connection if one is not already opened + return getStaticDisplay(); + } + + @Override + int getScreen(GraphicsDevice graphicsDevice) { + // Get the screen number + return ((X11GraphicsDevice)graphicsDevice).getScreen(); + } + + // Ensure that the native libraries are loaded + static { + VirtualUniverse.loadLibraries(); + } +} diff --git a/src/native/build.xml b/src/native/build.xml index c819ac5..76f0d25 100644 --- a/src/native/build.xml +++ b/src/native/build.xml @@ -20,37 +20,51 @@ + + + + + + + + + + + + + + @@ -58,6 +72,8 @@ + + @@ -71,43 +87,59 @@ + + + + + + + + + + + + + + + + @@ -202,8 +234,14 @@ srcfile="${javahCoreSrc}/NativePipeline.java" targetfile="${javahCoreTarget}/javax_media_j3d_NativePipeline.h"/> + + @@ -352,6 +390,8 @@ + + diff --git a/src/native/d3d/NativeConfigTemplate3D.cpp b/src/native/d3d/NativeConfigTemplate3D.cpp index b3851d2..230c35e 100644 --- a/src/native/d3d/NativeConfigTemplate3D.cpp +++ b/src/native/d3d/NativeConfigTemplate3D.cpp @@ -14,7 +14,7 @@ extern "C" JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isStereoAvailable( +jboolean JNICALL Java_javax_media_j3d_Win32NativeConfigTemplate3D_isStereoAvailable( JNIEnv *env, jobject obj, jlong pFormatInfo, @@ -26,7 +26,7 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isStereoAvailable( } extern "C" JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isDoubleBufferAvailable( +jboolean JNICALL Java_javax_media_j3d_Win32NativeConfigTemplate3D_isDoubleBufferAvailable( JNIEnv *env, jobject obj, jlong pFormatInfo, @@ -37,7 +37,7 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isDoubleBufferAvail } extern "C" JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingMultisampleAvailable( +jboolean JNICALL Java_javax_media_j3d_Win32NativeConfigTemplate3D_isSceneAntialiasingMultisampleAvailable( JNIEnv *env, jobject obj, jlong pFormatInfo, @@ -70,7 +70,7 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasing return antialiasingSupport; } extern "C" JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingAccumAvailable(JNIEnv *env, +jboolean JNICALL Java_javax_media_j3d_Win32NativeConfigTemplate3D_isSceneAntialiasingAccumAvailable(JNIEnv *env, jobject obj, jlong pFormatInfo, jboolean offScreen) @@ -81,7 +81,7 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasing extern "C" JNIEXPORT -jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_choosePixelFormat( +jint JNICALL Java_javax_media_j3d_Win32NativeConfigTemplate3D_choosePixelFormat( JNIEnv *env, jobject obj, jlong ctx, @@ -141,7 +141,7 @@ jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_choosePixelFormat( if (mx_ptr[ANTIALIASING] == REQUIRED) { - if (Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingMultisampleAvailable(env, obj, 0, JNI_TRUE, screen) == JNI_TRUE) + if (Java_javax_media_j3d_Win32NativeConfigTemplate3D_isSceneAntialiasingMultisampleAvailable(env, obj, 0, JNI_TRUE, screen) == JNI_TRUE) { retValue |= (1 << 31); } @@ -156,11 +156,11 @@ jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_choosePixelFormat( /* - * Class: javax_media_j3d_NativeConfigTemplate3D + * Class: javax_media_j3d_Win32NativeConfigTemplate3D * Method: getStencilSize * Signature: (JZ)I * */ -JNIEXPORT jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_getStencilSize +JNIEXPORT jint JNICALL Java_javax_media_j3d_Win32NativeConfigTemplate3D_getStencilSize (JNIEnv *env, jobject obj, jlong pFormatInfo, jboolean offScreen) { jlong stencilSize = pFormatInfo; diff --git a/src/native/ogl/NativeConfigTemplate3D.c b/src/native/ogl/NativeConfigTemplate3D.c index bae85db..4e1313d 100644 --- a/src/native/ogl/NativeConfigTemplate3D.c +++ b/src/native/ogl/NativeConfigTemplate3D.c @@ -335,7 +335,7 @@ GLXFBConfig *find_DB_AA_S_S_FBConfigs(jlong display, * combinations in hopes of finding an valid visual. */ JNIEXPORT -jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_chooseOglVisual( +jint JNICALL Java_javax_media_j3d_X11NativeConfigTemplate3D_chooseOglVisual( JNIEnv *env, jobject obj, jlong display, @@ -464,7 +464,7 @@ jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_chooseOglVisual( JNIEXPORT -void JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_freeFBConfig( +void JNICALL Java_javax_media_j3d_X11NativeConfigTemplate3D_freeFBConfig( JNIEnv *env, jclass class, /* this is a static native method */ jlong fbConfigListPtr) @@ -475,7 +475,7 @@ void JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_freeFBConfig( JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isStereoAvailable( +jboolean JNICALL Java_javax_media_j3d_X11NativeConfigTemplate3D_isStereoAvailable( JNIEnv *env, jobject obj, jlong display, @@ -511,7 +511,7 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isStereoAvailable( return (stereoFlag ? JNI_TRUE : JNI_FALSE); } -JNIEXPORT jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_getStencilSize( +JNIEXPORT jint JNICALL Java_javax_media_j3d_X11NativeConfigTemplate3D_getStencilSize( JNIEnv *env, jobject obj, jlong display, @@ -535,7 +535,7 @@ JNIEXPORT jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_getStencilSiz } JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isDoubleBufferAvailable( +jboolean JNICALL Java_javax_media_j3d_X11NativeConfigTemplate3D_isDoubleBufferAvailable( JNIEnv *env, jobject obj, jlong display, @@ -559,7 +559,7 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isDoubleBufferAvail } JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingAccumAvailable( +jboolean JNICALL Java_javax_media_j3d_X11NativeConfigTemplate3D_isSceneAntialiasingAccumAvailable( JNIEnv *env, jobject obj, jlong display, @@ -583,7 +583,7 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasing } JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingMultisampleAvailable( +jboolean JNICALL Java_javax_media_j3d_X11NativeConfigTemplate3D_isSceneAntialiasingMultisampleAvailable( JNIEnv *env, jobject obj, jlong display, @@ -1408,7 +1408,7 @@ PixelFormatInfo * newPixelFormatInfo(HDC hdc, jboolean usePbuffer) JNIEXPORT -jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_choosePixelFormat( +jint JNICALL Java_javax_media_j3d_Win32NativeConfigTemplate3D_choosePixelFormat( JNIEnv *env, jobject obj, jlong ctxInfo, @@ -1633,7 +1633,7 @@ jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_choosePixelFormat( JNIEXPORT -void JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_freePixelFormatInfo( +void JNICALL Java_javax_media_j3d_Win32NativeConfigTemplate3D_freePixelFormatInfo( JNIEnv *env, jclass class, /* this is a static native method */ jlong pFormatInfo) @@ -1655,7 +1655,7 @@ void JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_freePixelFormatInfo( JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isStereoAvailable( +jboolean JNICALL Java_javax_media_j3d_Win32NativeConfigTemplate3D_isStereoAvailable( JNIEnv *env, jobject obj, jlong pFormatInfo, @@ -1692,7 +1692,7 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isStereoAvailable( } -JNIEXPORT jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_getStencilSize( +JNIEXPORT jint JNICALL Java_javax_media_j3d_Win32NativeConfigTemplate3D_getStencilSize( JNIEnv *env, jobject obj, jlong pFormatInfo, @@ -1717,7 +1717,7 @@ JNIEXPORT jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_getStencilSiz JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isDoubleBufferAvailable( +jboolean JNICALL Java_javax_media_j3d_Win32NativeConfigTemplate3D_isDoubleBufferAvailable( JNIEnv *env, jobject obj, jlong pFormatInfo, @@ -1741,7 +1741,7 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isDoubleBufferAvail } JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingAccumAvailable( +jboolean JNICALL Java_javax_media_j3d_Win32NativeConfigTemplate3D_isSceneAntialiasingAccumAvailable( JNIEnv *env, jobject obj, jlong pFormatInfo, @@ -1763,7 +1763,7 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasing } JNIEXPORT -jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingMultisampleAvailable( +jboolean JNICALL Java_javax_media_j3d_Win32NativeConfigTemplate3D_isSceneAntialiasingMultisampleAvailable( JNIEnv *env, jobject obj, jlong pFormatInfo, diff --git a/src/native/ogl/NativeScreenInfo.c b/src/native/ogl/NativeScreenInfo.c index 64396de..162820e 100644 --- a/src/native/ogl/NativeScreenInfo.c +++ b/src/native/ogl/NativeScreenInfo.c @@ -40,12 +40,12 @@ /* - * Class: javax_media_j3d_NativeScreenInfo + * Class: javax_media_j3d_X11NativeScreenInfo * Method: openDisplay * Signature: ()J */ JNIEXPORT jlong JNICALL -Java_javax_media_j3d_NativeScreenInfo_openDisplay( +Java_javax_media_j3d_X11NativeScreenInfo_openDisplay( JNIEnv *env, jclass cls) { @@ -55,12 +55,12 @@ Java_javax_media_j3d_NativeScreenInfo_openDisplay( } /* - * Class: javax_media_j3d_NativeScreenInfo + * Class: javax_media_j3d_X11NativeScreenInfo * Method: getDefaultScreen * Signature: (J)I */ JNIEXPORT jint JNICALL -Java_javax_media_j3d_NativeScreenInfo_getDefaultScreen( +Java_javax_media_j3d_X11NativeScreenInfo_getDefaultScreen( JNIEnv *env, jclass cls, jlong display) @@ -70,12 +70,12 @@ Java_javax_media_j3d_NativeScreenInfo_getDefaultScreen( } /* - * Class: javax_media_j3d_NativeScreenInfo + * Class: javax_media_j3d_X11NativeScreenInfo * Method: queryGLX13 * Signature: (J)Z */ JNIEXPORT jboolean JNICALL -Java_javax_media_j3d_NativeScreenInfo_queryGLX13( +Java_javax_media_j3d_X11NativeScreenInfo_queryGLX13( JNIEnv *env, jclass cls, jlong display) @@ -141,12 +141,12 @@ extern PIXELFORMATDESCRIPTOR getDummyPFD(); extern BOOL isSupportedWGL(const char *extensions, const char *extension_string); /* - * Class: javax_media_j3d_NativeScreenInfo + * Class: javax_media_j3d_Win32NativeScreenInfo * Method: queryWglARB * Signature: (J)Z */ JNIEXPORT jboolean JNICALL -Java_javax_media_j3d_NativeScreenInfo_queryWglARB( +Java_javax_media_j3d_Win32NativeScreenInfo_queryWglARB( JNIEnv *env, jclass cls) { diff --git a/src/native/ogl/gldefs.h b/src/native/ogl/gldefs.h index edd5cdd..39ca6de 100644 --- a/src/native/ogl/gldefs.h +++ b/src/native/ogl/gldefs.h @@ -161,6 +161,14 @@ #include "javax_media_j3d_ShaderAttributeObjectRetained.h" #include "javax_media_j3d_ShaderError.h" +#ifdef WIN32 +#include "javax_media_j3d_Win32NativeConfigTemplate3D.h" +#include "javax_media_j3d_Win32NativeScreenInfo.h" +#else +#include "javax_media_j3d_X11NativeConfigTemplate3D.h" +#include "javax_media_j3d_X11NativeScreenInfo.h" +#endif + /* Used to compare floating point values close to 0.0 */ #define J3D_SMALL_FLOAT 0.00001f -- cgit v1.2.3