summaryrefslogtreecommitdiffstats
path: root/src/classes/linux
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/linux')
-rw-r--r--src/classes/linux/javax/media/j3d/J3dGraphicsConfig.java43
-rw-r--r--src/classes/linux/javax/media/j3d/NativeConfigTemplate3D.java252
-rw-r--r--src/classes/linux/javax/media/j3d/NativeScreenInfo.java60
-rw-r--r--src/classes/linux/javax/media/j3d/NativeWSInfo.java64
4 files changed, 419 insertions, 0 deletions
diff --git a/src/classes/linux/javax/media/j3d/J3dGraphicsConfig.java b/src/classes/linux/javax/media/j3d/J3dGraphicsConfig.java
new file mode 100644
index 0000000..9a4bb27
--- /dev/null
+++ b/src/classes/linux/javax/media/j3d/J3dGraphicsConfig.java
@@ -0,0 +1,43 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+/*
+ * Portions of this code were derived from work done by the Blackdown
+ * group (www.blackdown.org), who did the initial Linux implementation
+ * of the Java 3D API.
+ */
+
+package javax.media.j3d;
+
+import sun.awt.*;
+import java.awt.*;
+
+class J3dGraphicsConfig {
+
+ static native boolean isValidVisualID(long display, int vid);
+
+ J3dGraphicsConfig(GraphicsDevice gd, int pixelFormat) {
+ // a dummy class which this constructor should
+ // never invoke under Linux
+ }
+
+ static boolean isValidPixelFormat(GraphicsConfiguration gc) {
+ return isValidVisualID(NativeScreenInfo.getStaticDisplay(),
+ ((X11GraphicsConfig) gc).getVisual());
+ }
+
+ static boolean isValidConfig(GraphicsConfiguration gc) {
+ // Check to see if a valid visInfo pointer has been cached.
+ Object visInfoObject = Canvas3D.visInfoTable.get(gc);
+ return (visInfoObject != null) && (visInfoObject instanceof Long);
+ }
+}
diff --git a/src/classes/linux/javax/media/j3d/NativeConfigTemplate3D.java b/src/classes/linux/javax/media/j3d/NativeConfigTemplate3D.java
new file mode 100644
index 0000000..e5b18f7
--- /dev/null
+++ b/src/classes/linux/javax/media/j3d/NativeConfigTemplate3D.java
@@ -0,0 +1,252 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+/*
+ * Portions of this code were derived from work done by the Blackdown
+ * group (www.blackdown.org), who did the initial Linux implementation
+ * of the Java 3D API.
+ */
+
+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() {
+ VirtualUniverse.createMC();
+ }
+
+ /*
+ * This definition 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 NUM_ITEMS = 9;
+
+ // Native method to get an OpenGL visual id and a pointer to the
+ // XVisualInfo struct itself.
+ native int chooseOglVisual(long display, int screen,
+ int[] attrList, long[] visInfo);
+
+ // Native method to free an XVisualInfo struct. This is static since it
+ // may need to be called to clean up the Canvas3D visInfoTable after the
+ // NativeConfigTemplate3D has been disposed of.
+ static native void freeVisual(long visInfo);
+
+ // 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 isSceneAntialiasingMultiSamplesAvailable(long display, int screen, int vid);
+
+
+ /*
+ * Chooses the best visual for Java 3D apps.
+ */
+ GraphicsConfiguration
+ getBestConfiguration(GraphicsConfigTemplate3D template,
+ GraphicsConfiguration[] gc) {
+
+ X11GraphicsDevice gd =
+ (X11GraphicsDevice)((X11GraphicsConfig)gc[0]).getDevice();
+
+ NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd);
+
+ long display = nativeScreenInfo.getDisplay();
+ int screen = nativeScreenInfo.getScreen();
+
+ 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
+ // glxChooseVisual 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 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();
+
+ long[] visInfo = new long[1];
+ int visID = chooseOglVisual(display, screen, attrList, visInfo);
+ if (debug) {
+ System.out.println(" chooseOglVisual() returns " + visID);
+ System.out.println(" pointer to XVisualInfo is " + visInfo[0]);
+ System.out.println();
+ }
+
+ if (visID == 0 || visInfo[0] == 0) {
+ return null; // no valid visual was found
+ }
+
+ // search list of graphics configurations for config
+ // with matching visualId
+ GraphicsConfiguration gc1 = null;
+ for (int i = 0; i < gc.length; i++)
+ if (((X11GraphicsConfig)gc[i]).getVisual() == visID) {
+ gc1 = gc[i];
+ break;
+ }
+
+ // TODO: This may or may not be needed for Linux
+ // To support disabling Solaris OpenGL Xinerama mode, we need to cache
+ // the pointer to the actual XVisualInfo that glXChooseVisual()
+ // returns, since this is not cached with X11GraphicsConfig and there
+ // are no public constructors to allow us to extend it.
+ synchronized (Canvas3D.visInfoTable) {
+ if (Canvas3D.visInfoTable.get(gc1) == null)
+ Canvas3D.visInfoTable.put(gc1, new Long(visInfo[0]));
+ else
+ freeVisual(visInfo[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();
+
+ NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd);
+
+ long display = nativeScreenInfo.getDisplay();
+ int screen = nativeScreenInfo.getScreen();
+
+ 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();
+
+ long[] visInfo = new long[1];
+ int visID = chooseOglVisual(display, screen, attrList, visInfo);
+
+ if (visID == 0 || visInfo[0] == 0)
+ return false; // no valid visual was found
+ else
+ return true;
+ }
+
+
+ // Return whether stereo is available.
+ boolean hasStereo(GraphicsConfiguration gc) {
+ X11GraphicsDevice gd =
+ (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice();
+ NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd);
+
+ long display = nativeScreenInfo.getDisplay();
+ int screen = nativeScreenInfo.getScreen();
+ int vid = ((X11GraphicsConfig)gc).getVisual();
+
+ return isStereoAvailable(display, screen, vid);
+ }
+
+ // Return whether a double buffer is available.
+ boolean hasDoubleBuffer(GraphicsConfiguration gc) {
+ X11GraphicsDevice gd =
+ (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice();
+ NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd);
+
+ long display = nativeScreenInfo.getDisplay();
+ int screen = nativeScreenInfo.getScreen();
+ int vid = ((X11GraphicsConfig)gc).getVisual();
+
+ return isDoubleBufferAvailable(display, screen, vid);
+ }
+
+ // Return whether scene antialiasing is available.
+ boolean hasSceneAntialiasingAccum(GraphicsConfiguration gc) {
+ X11GraphicsDevice gd =
+ (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice();
+ NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd);
+
+ long display = nativeScreenInfo.getDisplay();
+ int screen = nativeScreenInfo.getScreen();
+ int vid = ((X11GraphicsConfig)gc).getVisual();
+
+ return isSceneAntialiasingAccumAvailable(display, screen, vid);
+ }
+
+
+ // Return whether scene antialiasing is available.
+ boolean hasSceneAntialiasingMultiSamples(GraphicsConfiguration gc) {
+ X11GraphicsDevice gd =
+ (X11GraphicsDevice)((X11GraphicsConfig)gc).getDevice();
+ NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd);
+
+ long display = nativeScreenInfo.getDisplay();
+ int screen = nativeScreenInfo.getScreen();
+ int vid = ((X11GraphicsConfig)gc).getVisual();
+
+ return isSceneAntialiasingMultiSamplesAvailable(display, screen, vid);
+ }
+
+ // Ensure that the native libraries are loaded
+ static {
+ VirtualUniverse.loadLibraries();
+ }
+}
diff --git a/src/classes/linux/javax/media/j3d/NativeScreenInfo.java b/src/classes/linux/javax/media/j3d/NativeScreenInfo.java
new file mode 100644
index 0000000..2579f1f
--- /dev/null
+++ b/src/classes/linux/javax/media/j3d/NativeScreenInfo.java
@@ -0,0 +1,60 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+/*
+ * Portions of this code were derived from work done by the Blackdown
+ * group (www.blackdown.org), who did the initial Linux implementation
+ * of the Java 3D API.
+ */
+
+package javax.media.j3d;
+
+import java.awt.GraphicsDevice;
+import sun.awt.X11GraphicsDevice;
+
+class NativeScreenInfo {
+ private int screen;
+ private static long display = 0;
+
+ private native static long openDisplay();
+ private native static int getDefaultScreen(long display);
+
+ synchronized static long getStaticDisplay() {
+ if (display == 0) {
+ display = openDisplay();
+ }
+ return display;
+ }
+
+ NativeScreenInfo(GraphicsDevice graphicsDevice) {
+ VirtualUniverse.createMC();
+ // Open a new static display connection if one is not already opened
+ getStaticDisplay();
+
+ // Get the screen number
+ screen = ((X11GraphicsDevice)graphicsDevice).getScreen();
+ }
+
+ long getDisplay() {
+ return display;
+ }
+
+ int getScreen() {
+ return screen;
+ }
+
+
+ // Ensure that the native libraries are loaded
+ static {
+ VirtualUniverse.loadLibraries();
+ }
+}
diff --git a/src/classes/linux/javax/media/j3d/NativeWSInfo.java b/src/classes/linux/javax/media/j3d/NativeWSInfo.java
new file mode 100644
index 0000000..ab47f3a
--- /dev/null
+++ b/src/classes/linux/javax/media/j3d/NativeWSInfo.java
@@ -0,0 +1,64 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+/*
+ * Portions of this code were derived from work done by the Blackdown
+ * group (www.blackdown.org), who did the initial Linux implementation
+ * of the Java 3D API.
+ */
+
+package javax.media.j3d;
+
+import java.awt.*;
+import java.awt.event.*;
+import sun.awt.*;
+import java.lang.reflect.Method;
+
+class NativeWSInfo {
+
+ //X11DrawingSurface xds;
+ Object xds;
+
+ void getCanvasWSParameters(Canvas3D canvas) {
+ try {
+ Class x11DSclass = Class.forName("sun.awt.X11DrawingSurface");
+ Method getDrawable = x11DSclass.getDeclaredMethod("getDrawable", null );
+ Method getVisualID = x11DSclass.getDeclaredMethod("getVisualID", null );
+
+ //canvas.window = xds.getDrawable();
+ //canvas.vid = xds.getVisualID();
+
+ canvas.window = ((Integer)getDrawable.invoke( xds, null )).intValue();
+ canvas.vid = ((Integer)getVisualID.invoke( xds, null )).intValue();
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+
+ void getWSDrawingSurface( Object dsi) {
+ try {
+ //xds = (X11DrawingSurface)dsi.getSurface();
+ Class drawingSurfaceInfoClass = Class.forName("sun.awt.DrawingSurfaceInfo");
+ Method getSurface = drawingSurfaceInfoClass.getDeclaredMethod( "getSurface", null);
+
+ //xds = dsi.getSurface();
+ xds = getSurface.invoke( dsi, null );
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+
+ int getCanvasVid(GraphicsConfiguration gcfg) {
+ return (((X11GraphicsConfig)gcfg).getVisual());
+ }
+}
+