aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java15
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java46
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/WrappedWindow.java88
3 files changed, 149 insertions, 0 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java
index 10e3f7857..863e53bde 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java
@@ -82,6 +82,21 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl
isXineramaEnabled = X11Util.XineramaIsEnabled(this);
}
+ /**
+ * Constructs a new X11GraphicsDevice corresponding to the given display connection.
+ * <p>
+ * The constructor opens the native connection and takes ownership.
+ * </p>
+ * @param displayConnection the semantic display connection name
+ * @param locker custom {@link javax.media.nativewindow.ToolkitLock}, eg to force null locking w/ private connection
+ * @see DefaultGraphicsDevice#DefaultGraphicsDevice(String, String, int, long, ToolkitLock)
+ */
+ public X11GraphicsDevice(String displayConnection, int unitID, ToolkitLock locker) {
+ super(NativeWindowFactory.TYPE_X11, displayConnection, unitID, 0, locker);
+ handleOwner = true;
+ open();
+ isXineramaEnabled = X11Util.XineramaIsEnabled(this);
+ }
private static int getDefaultScreenImpl(long dpy) {
return X11Lib.DefaultScreen(dpy);
diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
index 6962ce505..1dce05192 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
@@ -47,11 +47,15 @@ import jogamp.nativewindow.Debug;
import jogamp.nativewindow.NativeWindowFactoryImpl;
import jogamp.nativewindow.ToolkitProperties;
import jogamp.nativewindow.ResourceToolkitLock;
+import jogamp.nativewindow.WrappedWindow;
import com.jogamp.common.os.Platform;
import com.jogamp.common.util.ReflectionUtil;
+import com.jogamp.nativewindow.UpstreamSurfaceHookMutableSize;
import com.jogamp.nativewindow.awt.AWTGraphicsDevice;
import com.jogamp.nativewindow.awt.AWTGraphicsScreen;
+import com.jogamp.nativewindow.macosx.MacOSXGraphicsDevice;
+import com.jogamp.nativewindow.windows.WindowsGraphicsDevice;
import com.jogamp.nativewindow.x11.X11GraphicsDevice;
import com.jogamp.nativewindow.x11.X11GraphicsScreen;
@@ -627,4 +631,46 @@ public abstract class NativeWindowFactory {
VisualIDHolder.VID_UNDEFINED != visualID ;
}
+ /**
+ * Creates a native device type, following {@link #getNativeWindowType(boolean) getNativeWindowType(true)}.
+ * <p>
+ * The device will be opened if <code>own</code> is true, otherwise no native handle will ever be acquired.
+ * </p>
+ */
+ public static AbstractGraphicsDevice createDevice(String displayConnection, boolean own) {
+ final String nwt = NativeWindowFactory.getNativeWindowType(true);
+ if( NativeWindowFactory.TYPE_X11 == nwt ) {
+ if( own ) {
+ return new X11GraphicsDevice(displayConnection, AbstractGraphicsDevice.DEFAULT_UNIT, null /* ToolkitLock */);
+ } else {
+ return new X11GraphicsDevice(displayConnection, AbstractGraphicsDevice.DEFAULT_UNIT);
+ }
+ } else if( NativeWindowFactory.TYPE_WINDOWS == nwt ) {
+ return new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
+ } else if( NativeWindowFactory.TYPE_MACOSX == nwt ) {
+ return new MacOSXGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT);
+ }
+ throw new UnsupportedOperationException("n/a for this windowing system: "+nwt);
+ }
+
+ /**
+ * Creates a wrapped {@link NativeWindow} with given native handles and {@link AbstractGraphicsScreen}.
+ * <p>
+ * The given {@link UpstreamSurfaceHookMutableSize} maybe used to reflect resizes of the native window.
+ * </p>
+ * <p>
+ * The {@link AbstractGraphicsScreen} may be created via {@link #createScreen(AbstractGraphicsDevice, int)}.
+ * </p>
+ * <p>
+ * The {@link AbstractGraphicsScreen} may have an underlying open {@link AbstractGraphicsDevice}
+ * or a simple <i>dummy</i> instance, see {@link #createDevice(String, boolean)}.
+ * </p>
+ */
+ public static NativeWindow createWrappedWindow(AbstractGraphicsScreen aScreen, long surfaceHandle, long windowHandle,
+ UpstreamSurfaceHookMutableSize hook) {
+ final CapabilitiesImmutable caps = new Capabilities();
+ final AbstractGraphicsConfiguration config = new DefaultGraphicsConfiguration(aScreen, caps, caps);
+ return new WrappedWindow(config, surfaceHandle, hook, true, windowHandle);
+ }
+
}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/WrappedWindow.java b/src/nativewindow/classes/jogamp/nativewindow/WrappedWindow.java
new file mode 100644
index 000000000..d5a977240
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/WrappedWindow.java
@@ -0,0 +1,88 @@
+package jogamp.nativewindow;
+
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.NativeWindow;
+import javax.media.nativewindow.ProxySurface;
+import javax.media.nativewindow.UpstreamSurfaceHook;
+import javax.media.nativewindow.util.Insets;
+import javax.media.nativewindow.util.InsetsImmutable;
+import javax.media.nativewindow.util.Point;
+
+public class WrappedWindow extends WrappedSurface implements NativeWindow {
+ private final long windowHandle;
+ private final InsetsImmutable insets = new Insets(0, 0, 0, 0);
+
+ /**
+ * Utilizes a {@link UpstreamSurfaceHook.MutableSize} to hold the size information,
+ * which is being passed to the {@link ProxySurface} instance.
+ *
+ * @param cfg the {@link AbstractGraphicsConfiguration} to be used
+ * @param surfaceHandle the wrapped pre-existing native surface handle, maybe 0 if not yet determined
+ * @param initialWidth
+ * @param initialHeight
+ * @param ownsDevice <code>true</code> if this {@link ProxySurface} instance
+ * owns the {@link AbstractGraphicsConfiguration}'s {@link AbstractGraphicsDevice},
+ * otherwise <code>false</code>. Owning the device implies closing it at {@link #destroyNotify()}.
+ */
+ public WrappedWindow(AbstractGraphicsConfiguration cfg, long surfaceHandle, int initialWidth, int initialHeight, boolean ownsDevice, long windowHandle) {
+ super(cfg, surfaceHandle, initialWidth, initialHeight, ownsDevice);
+ this.windowHandle = windowHandle;
+ }
+
+ /**
+ * @param cfg the {@link AbstractGraphicsConfiguration} to be used
+ * @param surfaceHandle the wrapped pre-existing native surface handle, maybe 0 if not yet determined
+ * @param upstream the {@link UpstreamSurfaceHook} to be used
+ * @param ownsDevice <code>true</code> if this {@link ProxySurface} instance
+ * owns the {@link AbstractGraphicsConfiguration}'s {@link AbstractGraphicsDevice},
+ * otherwise <code>false</code>.
+ */
+ public WrappedWindow(AbstractGraphicsConfiguration cfg, long surfaceHandle, UpstreamSurfaceHook upstream, boolean ownsDevice, long windowHandle) {
+ super(cfg, surfaceHandle, upstream, ownsDevice);
+ this.windowHandle = windowHandle;
+ }
+
+ @Override
+ public void destroy() {
+ }
+
+ @Override
+ public NativeWindow getParent() {
+ return null;
+ }
+
+ @Override
+ public long getWindowHandle() {
+ return windowHandle;
+ }
+
+ @Override
+ public InsetsImmutable getInsets() {
+ return insets;
+ }
+
+ @Override
+ public int getX() {
+ return 0;
+ }
+
+ @Override
+ public int getY() {
+ return 0;
+ }
+
+ @Override
+ public Point getLocationOnScreen(Point point) {
+ if(null!=point) {
+ return point;
+ } else {
+ return new Point(0, 0);
+ }
+ }
+
+ @Override
+ public boolean hasFocus() {
+ return false;
+ }
+}