diff options
3 files changed, 31 insertions, 16 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index abafabb1c..fd3c31b6d 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -42,7 +42,7 @@ package javax.media.opengl; import java.nio.IntBuffer; import java.util.HashMap; -import java.util.HashSet; +import java.util.IdentityHashMap; import java.util.Iterator; import java.util.Set; @@ -1209,12 +1209,12 @@ public abstract class GLContext { /** * @see #getDeviceVersionAvailableKey(javax.media.nativewindow.AbstractGraphicsDevice, int, int) */ - protected static /*final*/ HashMap<String, Integer> deviceVersionAvailable = new HashMap<String, Integer>(); + protected static /*final*/ IdentityHashMap<String, Integer> deviceVersionAvailable = new IdentityHashMap<String, Integer>(); /** * @see #getUniqueDeviceString(javax.media.nativewindow.AbstractGraphicsDevice) */ - private static /*final*/ HashSet<String> deviceVersionsAvailableSet = new HashSet<String>(); + private static /*final*/ IdentityHashMap<String, String> deviceVersionsAvailableSet = new IdentityHashMap<String, String>(); /** clears the device/context mappings as well as the GL/GLX proc address tables. */ protected static void shutdown() { @@ -1225,17 +1225,16 @@ public abstract class GLContext { protected static boolean getAvailableGLVersionsSet(AbstractGraphicsDevice device) { synchronized ( deviceVersionsAvailableSet ) { - return deviceVersionsAvailableSet.contains(device.getUniqueID()); + return deviceVersionsAvailableSet.containsKey(device.getUniqueID()); } } protected static void setAvailableGLVersionsSet(AbstractGraphicsDevice device) { synchronized ( deviceVersionsAvailableSet ) { - String devKey = device.getUniqueID(); - if ( deviceVersionsAvailableSet.contains(devKey) ) { + final String devKey = device.getUniqueID(); + if( null != deviceVersionsAvailableSet.put(devKey, devKey) ) { throw new InternalError("Already set: "+devKey); } - deviceVersionsAvailableSet.add(devKey); if (DEBUG) { System.err.println(getThreadName() + ": createContextARB: SET mappedVersionsAvailableSet "+devKey); System.err.println(GLContext.dumpAvailableGLVersions(null).toString()); @@ -1243,8 +1242,13 @@ public abstract class GLContext { } } + /** + * Returns a unique String object using {@link String#intern()} for the given arguments, + * which object reference itself can be used as a key. + */ protected static String getDeviceVersionAvailableKey(AbstractGraphicsDevice device, int major, int profile) { - return device.getUniqueID() + "-" + toHexString(composeBits(major, profile, 0)); + final String r = device.getUniqueID() + "-" + toHexString(composeBits(major, profile, 0)); + return r.intern(); } /** @@ -1272,10 +1276,10 @@ public abstract class GLContext { System.err.println("GLContext.mapAvailableGLVersion: "+device+": "+getGLVersion(reqMajor, 0, profile, null)+" -> "+getGLVersion(resMajor, resMinor, resCtp, null)); // Thread.dumpStack(); } - final String key = getDeviceVersionAvailableKey(device, reqMajor, profile); + final String objectKey = getDeviceVersionAvailableKey(device, reqMajor, profile); final Integer val = new Integer(composeBits(resMajor, resMinor, resCtp)); synchronized(deviceVersionAvailable) { - return deviceVersionAvailable.put( key, val ); + return deviceVersionAvailable.put( objectKey, val ); } } @@ -1315,10 +1319,10 @@ public abstract class GLContext { * @return the available GL version as encoded with {@link #composeBits(int, int, int), otherwise <code>null</code> */ protected static Integer getAvailableGLVersion(AbstractGraphicsDevice device, int reqMajor, int reqProfile) { - String key = getDeviceVersionAvailableKey(device, reqMajor, reqProfile); + final String objectKey = getDeviceVersionAvailableKey(device, reqMajor, reqProfile); Integer val; synchronized(deviceVersionAvailable) { - val = deviceVersionAvailable.get( key ); + val = deviceVersionAvailable.get( objectKey ); } return val; } diff --git a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java index 585cd1f09..ed305d49e 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java +++ b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java @@ -89,10 +89,16 @@ public interface AbstractGraphicsDevice extends Cloneable { public int getUnitID(); /** - * Returns a unique ID String of this device using {@link #getType() type}, - * {@link #getConnection() connection} and {@link #getUnitID() unitID}.<br> - * The unique ID does not reflect the instance of the device, hence the handle is not included.<br> + * Returns a unique ID object of this device using {@link #getType() type}, + * {@link #getConnection() connection} and {@link #getUnitID() unitID} as it's key components. + * <p> + * The unique ID does not reflect the instance of the device, hence the handle is not included. * The unique ID may be used as a key for semantic device mapping. + * </p> + * <p> + * The returned string object reference is unique using {@link String#intern()} + * and hence can be used as a key itself. + * </p> */ public String getUniqueID(); diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java index 66b81d7fa..0bf5c2937 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java +++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java @@ -253,7 +253,12 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice return toolkitLock; } + /** + * Returns a unique String object using {@link String#intern()} for the given arguments, + * which object reference itself can be used as a key. + */ protected static String getUniqueID(String type, String connection, int unitID) { - return (type + separator + connection + separator + unitID).intern(); + final String r = (type + separator + connection + separator + unitID).intern(); + return r.intern(); } } |