diff options
Diffstat (limited to 'src/classes/win32')
4 files changed, 326 insertions, 0 deletions
diff --git a/src/classes/win32/javax/media/j3d/J3dGraphicsConfig.java b/src/classes/win32/javax/media/j3d/J3dGraphicsConfig.java new file mode 100644 index 0000000..1a2ecfd --- /dev/null +++ b/src/classes/win32/javax/media/j3d/J3dGraphicsConfig.java @@ -0,0 +1,41 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +import sun.awt.Win32GraphicsConfig; +import java.awt.*; + +class J3dGraphicsConfig extends Win32GraphicsConfig { + + private int pixelFormat; + + J3dGraphicsConfig(GraphicsDevice gd, int pixelFormat) + { + super(gd, pixelFormat); + this.pixelFormat = pixelFormat; + } + + static boolean isValidPixelFormat(GraphicsConfiguration gc) { + return (gc instanceof J3dGraphicsConfig); + } + + static boolean isValidConfig(GraphicsConfiguration gc) { + return isValidPixelFormat(gc); + } + + int getPixelFormat() { + return pixelFormat; + } + + +} diff --git a/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java b/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java new file mode 100644 index 0000000..997aaee --- /dev/null +++ b/src/classes/win32/javax/media/j3d/NativeConfigTemplate3D.java @@ -0,0 +1,175 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2004 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 { + + NativeConfigTemplate3D() { + VirtualUniverse.createMC(); + } + + // 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 NUM_ITEMS = 9; + + /** + * selects the proper visual + */ + native int + choosePixelFormat(long ctx, int screen, int[] attrList); + + // Native methods to return whether a particular attribute is available + native boolean isStereoAvailable(long ctx, long display, int screen, int pixelFormat); + native boolean isDoubleBufferAvailable(long ctx, long display, int screen, int pixelFormat); + native boolean isSceneAntialiasingAccumAvailable(long ctx, long display, int screen, int pixelFormat); + native boolean isSceneAntialiasingMultiSamplesAvailable(long ctx, long display, int screen, int pixelFormat); + + /** + * Chooses the best PixelFormat for Java 3D apps. + */ + GraphicsConfiguration + getBestConfiguration(GraphicsConfigTemplate3D template, + GraphicsConfiguration[] gc) { + + Win32GraphicsDevice gd = + (Win32GraphicsDevice)((Win32GraphicsConfig)gc[0]).getDevice(); + + // 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(); + NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); + int screen = nativeScreenInfo.getScreen(); + int pixelFormat = choosePixelFormat(0, screen, attrList); + if (pixelFormat == -1) { + // current mode don't support the minimum config + return null; + } + return new J3dGraphicsConfig(gd, pixelFormat); + } + + /** + * Determine if a given GraphicsConfiguration object can be used + * by Java 3D. + */ + boolean isGraphicsConfigSupported(GraphicsConfigTemplate3D template, + GraphicsConfiguration gc) { + + Win32GraphicsDevice gd = + (Win32GraphicsDevice)((Win32GraphicsConfig) gc).getDevice(); + + // 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(); + + NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); + int screen = nativeScreenInfo.getScreen(); + + int pixelFormat = choosePixelFormat(0, screen, attrList); + + if (pixelFormat == -1) { + // current mode don't support the minimum config + return false; + } else return true; + } + + + // Return whether stereo is available. + boolean hasStereo(GraphicsConfiguration gc) { + Win32GraphicsDevice gd = + (Win32GraphicsDevice)((Win32GraphicsConfig)gc).getDevice(); + NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); + + int display = nativeScreenInfo.getDisplay(); + int screen = nativeScreenInfo.getScreen(); + // Temporary until Win32 GraphicsConfig stuff complete + int pixelFormat = ((J3dGraphicsConfig) gc).getPixelFormat(); + + return isStereoAvailable(0, display, screen, pixelFormat); + } + + // Return whether a double buffer is available. + boolean hasDoubleBuffer(GraphicsConfiguration gc) { + Win32GraphicsDevice gd = + (Win32GraphicsDevice)((Win32GraphicsConfig)gc).getDevice(); + NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); + int display = nativeScreenInfo.getDisplay(); + int screen = nativeScreenInfo.getScreen(); + // Temporary until Win32 GraphicsConfig stuff complete + int pixelFormat = ((J3dGraphicsConfig) gc).getPixelFormat(); + + return isDoubleBufferAvailable(0, display, screen, pixelFormat); + } + + // Return whether scene antialiasing is available. + boolean hasSceneAntialiasingAccum(GraphicsConfiguration gc) { + Win32GraphicsDevice gd = + (Win32GraphicsDevice)((Win32GraphicsConfig)gc).getDevice(); + NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); + int display = nativeScreenInfo.getDisplay(); + int screen = nativeScreenInfo.getScreen(); + // Temporary until Win32 GraphicsConfig stuff complete + int pixelFormat = ((J3dGraphicsConfig) gc).getPixelFormat(); + + return isSceneAntialiasingAccumAvailable(0, display, screen, pixelFormat); + } + + // Return whether scene antialiasing is available. + boolean hasSceneAntialiasingMultiSamples(GraphicsConfiguration gc) { + Win32GraphicsDevice gd = + (Win32GraphicsDevice)((Win32GraphicsConfig)gc).getDevice(); + NativeScreenInfo nativeScreenInfo = new NativeScreenInfo(gd); + int display = nativeScreenInfo.getDisplay(); + int screen = nativeScreenInfo.getScreen(); + // Temporary until Win32 GraphicsConfig stuff complete + int pixelFormat = ((J3dGraphicsConfig) gc).getPixelFormat(); + + return isSceneAntialiasingMultiSamplesAvailable(0, display, screen, pixelFormat); + } + + // 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 new file mode 100644 index 0000000..43ee7e5 --- /dev/null +++ b/src/classes/win32/javax/media/j3d/NativeScreenInfo.java @@ -0,0 +1,41 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2004 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 int display = 0; + private int screen = 0; + + NativeScreenInfo(GraphicsDevice graphicsDevice) { + // Get the screen number + screen = ((sun.awt.Win32GraphicsDevice)graphicsDevice).getScreen(); + display = screen; + } + + int getDisplay() { + return display; + } + + int getScreen() { + return screen; + } + + + // Ensure that the native libraries are loaded + static { + VirtualUniverse.loadLibraries(); + } +} diff --git a/src/classes/win32/javax/media/j3d/NativeWSInfo.java b/src/classes/win32/javax/media/j3d/NativeWSInfo.java new file mode 100644 index 0000000..e8a7317 --- /dev/null +++ b/src/classes/win32/javax/media/j3d/NativeWSInfo.java @@ -0,0 +1,69 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. + * + * Use is subject to license terms. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package javax.media.j3d; + +import java.awt.*; +import java.awt.event.*; +import sun.awt.*; +import java.lang.reflect.Method; + +class NativeWSInfo { + + //Win32DrawingSurface wds; + Object wds; + + void getCanvasWSParameters(Canvas3D canvas) { + //canvas.window = wds.getHDC(); + try { + Class win32DSclass = Class.forName("sun.awt.Win32DrawingSurface"); + Method getHDC = win32DSclass.getDeclaredMethod("getHDC", null ); + + canvas.window = ((Integer)getHDC.invoke( wds, null )).intValue(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + void getWSDrawingSurface(Object dsi) { + //wds = (Win32DrawingSurface)dsi.getSurface(); + int hwnd =0; + + try { + Class drawingSurfaceInfoClass = Class.forName("sun.awt.DrawingSurfaceInfo"); + Method getSurface = drawingSurfaceInfoClass.getDeclaredMethod( "getSurface", null); + + wds = getSurface.invoke( dsi, null ); + + Class win32DSclass = Class.forName("sun.awt.Win32DrawingSurface"); + Method getHWnd = win32DSclass.getDeclaredMethod("getHWnd", null ); + hwnd = ((Integer)getHWnd.invoke( wds, null )).intValue(); + } catch( Exception e ) { + e.printStackTrace(); + } + + // note: dsi lock is called from the caller of this method + // Workaround for bug 4169320 + //dsi.lock(); + //subclass(wds.getHWnd()); + subclass(hwnd); + //dsi.unlock(); + } + + // Used in workaround for bug 4169320: Resizing a Java 3D canvas + // on Win95 crashes the application + private native void subclass(int hWnd); + + int getCanvasVid(GraphicsConfiguration gcfg) { + return ((J3dGraphicsConfig) gcfg).getPixelFormat(); + } +} |