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 --- .../javax/media/j3d/NativeConfigTemplate3D.java | 229 --------------------- .../win32/javax/media/j3d/NativeScreenInfo.java | 54 ----- .../media/j3d/Win32NativeConfigTemplate3D.java | 227 ++++++++++++++++++++ .../javax/media/j3d/Win32NativeScreenInfo.java | 59 ++++++ 4 files changed, 286 insertions(+), 283 deletions(-) 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 (limited to 'src/classes/win32') 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(); + } +} -- cgit v1.2.3