diff options
author | Sven Gothel <[email protected]> | 2010-11-15 03:53:22 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-11-15 03:53:22 +0100 |
commit | 35d1c40fe89311f88c7303930e172adcc5d6853a (patch) | |
tree | 383f74cbd782f32d194b7f893a5365fa86093ac7 /src/nativewindow/classes/javax/media | |
parent | 2c1a870f56f54df3e96d68e3d5dadee0bcae7cb5 (diff) |
NativeWindow AbstractGraphicsDevice: Add 'unitID' attribute and getUniqueID()
Preparation to support multiple devices on one machine,
hence adding the unitID a unique ID/index of the associated GPU, or GPU affinity.
Adding getUniqueID() to return a cached semantic unique string id for the device.
This was removed from the temp. impl in JOGL's GLContext, added unitID.
All other changes just adapt to the above.
Diffstat (limited to 'src/nativewindow/classes/javax/media')
12 files changed, 99 insertions, 68 deletions
diff --git a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java index c6911bac8..83b437612 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java +++ b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java @@ -51,6 +51,9 @@ public interface AbstractGraphicsDevice extends Cloneable { /** Dummy connection value for an external connection where no native support for multiple devices is available */ public static String EXTERNAL_CONNECTION = "excon"; + /** Default unit id for the 1st device: 0 */ + public static int DEFAULT_UNIT = 0; + /** * Returns the type of the underlying subsystem, ie * NativeWindowFactory.TYPE_KD, NativeWindowFactory.TYPE_X11, .. @@ -59,14 +62,36 @@ public interface AbstractGraphicsDevice extends Cloneable { /** * Returns the semantic GraphicsDevice connection.<br> - * On platforms supporting multiple devices, local or network, - * the implementation shall return a unique name.<br> - * On X11 for example, the <code>DISPLAY</code> connection string, - * eg. <code>:0.0</code>, could be returned.<br> + * On platforms supporting remote devices, eg via tcp/ip network, + * the implementation shall return a unique name for each remote address.<br> + * On X11 for example, the connection string should be as the following example.<br> + * <ul> + * <li><code>:0.0</code> for a local connection</li> + * <li><code>remote.host.net:0.0</code> for a remote connection</li> + * </ul> + * + * To support multiple local device, see {@link #getUnitID()}. */ public String getConnection(); /** + * Returns the graphics device <code>unit ID</code>.<br> + * The <code>unit ID</code> support multiple graphics device configurations + * on a local machine.<br> + * To support remote device, see {@link #getConnection()}. + * @return + */ + 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> + * The unique ID may be used as a key for semantic device mapping. + */ + public String getUniqueID(); + + /** * Returns the native handle of the underlying native device, * if such thing exist. */ diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java index f28d254ab..cb367f939 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java +++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java @@ -36,8 +36,11 @@ package javax.media.nativewindow; import com.jogamp.nativewindow.impl.NativeWindowFactoryImpl; public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice { + private static final String separator = "_"; private String type; protected String connection; + protected int unitID; + protected String uniqueID; protected long handle; protected ToolkitLock toolkitLock; @@ -46,9 +49,11 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice * gathered via {@link NativeWindowFactory#createDefaultToolkitLock()}. * @param type */ - public DefaultGraphicsDevice(String type, String connection) { + public DefaultGraphicsDevice(String type, String connection, int unitID) { this.type = type; this.connection = connection; + this.unitID = unitID; + this.uniqueID = getUniqueID(type, connection, unitID); this.handle = 0; setToolkitLock( NativeWindowFactory.getDefaultToolkitLock(type) ); } @@ -59,9 +64,11 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice * @param type * @param handle */ - public DefaultGraphicsDevice(String type, String connection, long handle) { + public DefaultGraphicsDevice(String type, String connection, int unitID, long handle) { this.type = type; this.connection = connection; + this.unitID = unitID; + this.uniqueID = getUniqueID(type, connection, unitID); this.handle = handle; setToolkitLock( NativeWindowFactory.createDefaultToolkitLock(type, handle) ); } @@ -72,9 +79,11 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice * @param handle * @param locker */ - public DefaultGraphicsDevice(String type, String connection, long handle, ToolkitLock locker) { + public DefaultGraphicsDevice(String type, String connection, int unitID, long handle, ToolkitLock locker) { this.type = type; this.connection = connection; + this.unitID = unitID; + this.uniqueID = getUniqueID(type, connection, unitID); this.handle = handle; setToolkitLock( locker ); } @@ -95,6 +104,14 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice return connection; } + public final int getUnitID() { + return unitID; + } + + public final String getUniqueID() { + return uniqueID; + } + public final long getHandle() { return handle; } @@ -126,7 +143,7 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice } public String toString() { - return getClass().toString()+"[type "+getType()+", connection "+getConnection()+", handle 0x"+Long.toHexString(getHandle())+"]"; + return getClass().toString()+"[type "+getType()+", connection "+getConnection()+", unitID "+getUnitID()+", handle 0x"+Long.toHexString(getHandle())+"]"; } /** @@ -148,4 +165,8 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice public final ToolkitLock getToolkitLock() { return toolkitLock; } + + protected static String getUniqueID(String type, String connection, int unitID) { + return (type + separator + connection + separator + unitID).intern(); + } } diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java index 893b0ddd2..065385ae3 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java +++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java @@ -41,12 +41,8 @@ public class DefaultGraphicsScreen implements Cloneable, AbstractGraphicsScreen this.idx = idx; } - public static AbstractGraphicsScreen createScreenDevice(String connection,int screenIdx) { - return new DefaultGraphicsScreen(new DefaultGraphicsDevice(NativeWindowFactory.TYPE_DEFAULT, connection), screenIdx); - } - - public static AbstractGraphicsScreen createDefault() { - return createScreenDevice(AbstractGraphicsDevice.DEFAULT_CONNECTION, 0); + public static AbstractGraphicsScreen createDefault(String type) { + return new DefaultGraphicsScreen(new DefaultGraphicsDevice(type, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT), 0); } public Object clone() { diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java index 49b398b6f..a36440873 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java @@ -245,6 +245,18 @@ public abstract class NativeWindowFactory { return useCustom?nativeWindowingTypeCustom:nativeWindowingTypePure; } + /** Don't know if we shall add this factory here .. + public static AbstractGraphicsDevice createGraphicsDevice(String type, String connection, int unitID, long handle, ToolkitLock locker) { + if(type.equals(TYPE_EGL)) { + return new + } else if(type.equals(TYPE_X11)) { + } else if(type.equals(TYPE_WINDOWS)) { + } else if(type.equals(TYPE_MACOSX)) { + } else if(type.equals(TYPE_AWT)) { + } else if(type.equals(TYPE_DEFAULT)) { + } + } */ + /** Sets the default NativeWindowFactory. */ public static void setDefaultFactory(NativeWindowFactory factory) { defaultFactory = factory; diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java index f56248e67..6aafc8549 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java @@ -84,13 +84,13 @@ public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration imple awtGraphicsDevice = awtGfxConfig.getDevice(); if(null!=awtGraphicsDevice) { // Create Device/Screen - awtDevice = new AWTGraphicsDevice(awtGraphicsDevice); + awtDevice = new AWTGraphicsDevice(awtGraphicsDevice, AbstractGraphicsDevice.DEFAULT_UNIT); awtScreen = new AWTGraphicsScreen(awtDevice); } } if(null==awtScreen) { // use defaults since no native peer is available yet - awtScreen = (AWTGraphicsScreen) AWTGraphicsScreen.createScreenDevice(-1); + awtScreen = (AWTGraphicsScreen) AWTGraphicsScreen.createScreenDevice(-1, AbstractGraphicsDevice.DEFAULT_UNIT); awtDevice = (AWTGraphicsDevice) awtScreen.getDevice(); awtGraphicsDevice = awtDevice.getGraphicsDevice(); } diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java index e1d7c84f1..cc4cd464f 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java @@ -51,17 +51,18 @@ public class AWTGraphicsDevice extends DefaultGraphicsDevice implements Cloneabl private GraphicsDevice device; private String subType; - protected AWTGraphicsDevice(GraphicsDevice device) { - super(NativeWindowFactory.TYPE_AWT, device.getIDstring()); + protected AWTGraphicsDevice(GraphicsDevice device, int unitID) { + super(NativeWindowFactory.TYPE_AWT, device.getIDstring(), unitID); this.device = device; this.subType = null; } - public static AbstractGraphicsDevice createDevice(GraphicsDevice awtDevice) { + public static AbstractGraphicsDevice createDevice(GraphicsDevice awtDevice, int unitID) { if(null==awtDevice) { awtDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + unitID = AbstractGraphicsDevice.DEFAULT_UNIT; } - return new AWTGraphicsDevice(awtDevice); + return new AWTGraphicsDevice(awtDevice, unitID); } public Object clone() { @@ -90,7 +91,7 @@ public class AWTGraphicsDevice extends DefaultGraphicsDevice implements Cloneabl } public String toString() { - return getClass().toString()+"[type "+getType()+"[subType "+getSubType()+"], connection "+getConnection()+", awtDevice "+device+", handle 0x"+Long.toHexString(getHandle())+"]"; + return getClass().toString()+"[type "+getType()+"[subType "+getSubType()+"], connection "+getConnection()+", unitID "+getUnitID()+", awtDevice "+device+", handle 0x"+Long.toHexString(getHandle())+"]"; } } diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java index 6cbf2ee71..383dcae80 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java @@ -43,7 +43,6 @@ import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import javax.media.nativewindow.*; import javax.media.nativewindow.AbstractGraphicsDevice; -import com.jogamp.nativewindow.impl.*; /** A wrapper for an AWT GraphicsDevice (screen) allowing it to be handled in a toolkit-independent manner. */ @@ -74,18 +73,18 @@ public class AWTGraphicsScreen extends DefaultGraphicsScreen implements Cloneabl return -1; } - public static AbstractGraphicsScreen createScreenDevice(GraphicsDevice awtDevice) { - AWTGraphicsDevice device = (AWTGraphicsDevice) AWTGraphicsDevice.createDevice(awtDevice); + public static AbstractGraphicsScreen createScreenDevice(GraphicsDevice awtDevice, int unitID) { + AWTGraphicsDevice device = (AWTGraphicsDevice) AWTGraphicsDevice.createDevice(awtDevice, unitID); return new AWTGraphicsScreen(device); } - public static AbstractGraphicsScreen createScreenDevice(int index) { + public static AbstractGraphicsScreen createScreenDevice(int index, int unitID) { GraphicsDevice awtDevice = getScreenDevice(index); - return createScreenDevice(awtDevice); + return createScreenDevice(awtDevice, unitID); } public static AbstractGraphicsScreen createDefault() { - return createScreenDevice(-1); + return createScreenDevice(-1, AbstractGraphicsDevice.DEFAULT_UNIT); } public Object clone() { diff --git a/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java index 2fca915a0..7bd27fdba 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java +++ b/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java @@ -40,18 +40,15 @@ import javax.media.nativewindow.*; public class EGLGraphicsDevice extends DefaultGraphicsDevice implements Cloneable { /** * Note that this is not an open connection, ie no native display handle exist. - * This constructor exist to setup a default device connection.<br> - * FIXME:<br> - * find out the EGL semantics of a device connection {@link javax.media.nativewindow.AbstractGraphicsDevice#getConnection()} - * to actually use multiple devices. + * This constructor exist to setup a default device connection/unit.<br> */ - public EGLGraphicsDevice(String connection) { - super(NativeWindowFactory.TYPE_EGL, connection); + public EGLGraphicsDevice(int unitID) { + super(NativeWindowFactory.TYPE_EGL, AbstractGraphicsDevice.DEFAULT_CONNECTION, unitID); } /** Constructs a new EGLGraphicsDevice corresponding to the given EGL display handle. */ - public EGLGraphicsDevice(long eglDisplay) { - super(NativeWindowFactory.TYPE_EGL, AbstractGraphicsDevice.DEFAULT_CONNECTION, eglDisplay); + public EGLGraphicsDevice(long eglDisplay, int unitID) { + super(NativeWindowFactory.TYPE_EGL, AbstractGraphicsDevice.DEFAULT_CONNECTION, unitID, eglDisplay); } public Object clone() { diff --git a/src/nativewindow/classes/javax/media/nativewindow/macosx/MacOSXGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/macosx/MacOSXGraphicsDevice.java index b7dbf0d6a..02c63758f 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/macosx/MacOSXGraphicsDevice.java +++ b/src/nativewindow/classes/javax/media/nativewindow/macosx/MacOSXGraphicsDevice.java @@ -38,20 +38,9 @@ import javax.media.nativewindow.*; */ public class MacOSXGraphicsDevice extends DefaultGraphicsDevice implements Cloneable { - /** - * Note that this is not an open connection, ie no native display handle exist. - * This constructor exist to setup a default device connection.<br> - * FIXME:<br> - * find out the EGL semantics of a device connection {@link javax.media.nativewindow.AbstractGraphicsDevice#getConnection()} - * to actually use multiple devices. - */ - public MacOSXGraphicsDevice(String connection) { - super(NativeWindowFactory.TYPE_MACOSX, connection); - } - /** Constructs a new MacOSXGraphicsDevice */ - public MacOSXGraphicsDevice() { - super(NativeWindowFactory.TYPE_MACOSX, AbstractGraphicsDevice.DEFAULT_CONNECTION); + public MacOSXGraphicsDevice(int unitID) { + super(NativeWindowFactory.TYPE_MACOSX, AbstractGraphicsDevice.DEFAULT_CONNECTION, unitID); } public Object clone() { diff --git a/src/nativewindow/classes/javax/media/nativewindow/windows/WindowsGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/windows/WindowsGraphicsDevice.java index fe11ba937..d5e32381b 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/windows/WindowsGraphicsDevice.java +++ b/src/nativewindow/classes/javax/media/nativewindow/windows/WindowsGraphicsDevice.java @@ -38,20 +38,9 @@ import javax.media.nativewindow.*; * Encapsulates a graphics device on Windows platforms.<br> */ public class WindowsGraphicsDevice extends DefaultGraphicsDevice implements Cloneable { - /** - * Note that this is not an open connection, ie no native display handle exist. - * This constructor exist to setup a default device connection.<br> - * FIXME:<br> - * find out the Windows semantics of a device connection {@link javax.media.nativewindow.AbstractGraphicsDevice#getConnection()} - * to actually use multiple devices. - */ - public WindowsGraphicsDevice(String connection) { - super(NativeWindowFactory.TYPE_WINDOWS, connection); - } - /** Constructs a new WindowsGraphicsDevice */ - public WindowsGraphicsDevice() { - super(NativeWindowFactory.TYPE_WINDOWS, AbstractGraphicsDevice.DEFAULT_CONNECTION); + public WindowsGraphicsDevice(int unitID) { + super(NativeWindowFactory.TYPE_WINDOWS, AbstractGraphicsDevice.DEFAULT_CONNECTION, unitID); } public Object clone() { diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java index dfbe8c6dd..31e03f8f1 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java +++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java @@ -46,15 +46,16 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl * Note that this is not an open connection, ie no native display handle exist. * This constructor exist to setup a default device connection. */ - public X11GraphicsDevice(String connection) { - super(NativeWindowFactory.TYPE_X11, connection); + public X11GraphicsDevice(String connection, int unitID) { + super(NativeWindowFactory.TYPE_X11, connection, unitID); } /** Constructs a new X11GraphicsDevice corresponding to the given native display handle and default * {@link javax.media.nativewindow.ToolkitLock} via {@link NativeWindowFactory#createDefaultToolkitLock(java.lang.String, long)}. */ - public X11GraphicsDevice(long display) { - super(NativeWindowFactory.TYPE_X11, X11Util.XDisplayString(display), display); + public X11GraphicsDevice(long display, int unitID) { + // FIXME: derive unitID from connection could be buggy, one DISPLAY for all screens for example.. + super(NativeWindowFactory.TYPE_X11, X11Util.XDisplayString(display), unitID, display); if(0==display) { throw new NativeWindowException("null display"); } @@ -64,8 +65,8 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl * @param display the Display connection * @param locker custom {@link javax.media.nativewindow.ToolkitLock}, eg to force null locking in NEWT */ - public X11GraphicsDevice(long display, ToolkitLock locker) { - super(NativeWindowFactory.TYPE_X11, X11Util.XDisplayString(display), display, locker); + public X11GraphicsDevice(long display, int unitID, ToolkitLock locker) { + super(NativeWindowFactory.TYPE_X11, X11Util.XDisplayString(display), unitID, display, locker); if(0==display) { throw new NativeWindowException("null display"); } @@ -79,6 +80,7 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl closeDisplay = close; } public boolean close() { + // FIXME: shall we respect the unitID ? if(closeDisplay && 0 != handle) { X11Util.closeDisplay(handle); handle = 0; diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java index dca0d1de3..9de3baa51 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java +++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java @@ -50,7 +50,7 @@ public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneabl public static AbstractGraphicsScreen createScreenDevice(long display, int screenIdx) { if(0==display) throw new NativeWindowException("display is null"); - return new X11GraphicsScreen(new X11GraphicsDevice(display), screenIdx); + return new X11GraphicsScreen(new X11GraphicsDevice(display, AbstractGraphicsDevice.DEFAULT_UNIT), screenIdx); } public long getDefaultVisualID() { |