aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes/com/jogamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/nativewindow/classes/com/jogamp')
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/MutableGraphicsConfiguration.java43
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/WrappedSurface.java74
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsConfiguration.java174
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsDevice.java77
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsScreen.java92
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTWindowClosingProtocol.java139
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java489
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/egl/EGLGraphicsDevice.java60
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/macosx/MacOSXGraphicsDevice.java50
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java265
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/windows/WindowsGraphicsDevice.java54
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsConfiguration.java81
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java103
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsScreen.java77
14 files changed, 1778 insertions, 0 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/MutableGraphicsConfiguration.java b/src/nativewindow/classes/com/jogamp/nativewindow/MutableGraphicsConfiguration.java
new file mode 100644
index 000000000..ee3ab73ba
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/MutableGraphicsConfiguration.java
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2011 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package jogamp.nativewindow;
+
+import javax.media.nativewindow.AbstractGraphicsScreen;
+import javax.media.nativewindow.CapabilitiesImmutable;
+import javax.media.nativewindow.DefaultGraphicsConfiguration;
+
+public class MutableGraphicsConfiguration extends DefaultGraphicsConfiguration {
+ public MutableGraphicsConfiguration(AbstractGraphicsScreen screen,
+ CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested) {
+ super(screen, capsChosen, capsRequested);
+ }
+
+ public void setChosenCapabilities(CapabilitiesImmutable caps) {
+ super.setChosenCapabilities(caps);
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/WrappedSurface.java b/src/nativewindow/classes/com/jogamp/nativewindow/WrappedSurface.java
new file mode 100644
index 000000000..074fab563
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/WrappedSurface.java
@@ -0,0 +1,74 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package jogamp.nativewindow;
+
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.ProxySurface;
+import javax.media.nativewindow.SurfaceChangeable;
+
+
+public class WrappedSurface extends ProxySurface implements SurfaceChangeable {
+ protected long surfaceHandle;
+
+ public WrappedSurface(AbstractGraphicsConfiguration cfg) {
+ this(cfg, 0);
+ }
+
+ public WrappedSurface(AbstractGraphicsConfiguration cfg, long handle) {
+ super(cfg);
+ surfaceHandle=handle;
+ }
+
+ protected final void invalidateImpl() {
+ surfaceHandle = 0;
+ }
+
+ public long getSurfaceHandle() {
+ return surfaceHandle;
+ }
+
+ public void setSurfaceHandle(long surfaceHandle) {
+ this.surfaceHandle=surfaceHandle;
+ }
+
+ protected int lockSurfaceImpl() {
+ return LOCK_SUCCESS;
+ }
+
+ protected void unlockSurfaceImpl() {
+ }
+
+ public String toString() {
+ return "WrappedSurface[config " + getPrivateGraphicsConfiguration()+
+ ", displayHandle 0x" + Long.toHexString(getDisplayHandle()) +
+ ", surfaceHandle 0x" + Long.toHexString(getSurfaceHandle()) +
+ ", size " + getWidth() + "x" + getHeight() +
+ ", surfaceLock "+surfaceLock+"]";
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsConfiguration.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsConfiguration.java
new file mode 100644
index 000000000..45a3db838
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsConfiguration.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package javax.media.nativewindow.awt;
+
+import javax.media.nativewindow.*;
+
+import java.awt.Component;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.image.ColorModel;
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+
+import jogamp.nativewindow.Debug;
+
+/** A wrapper for an AWT GraphicsConfiguration allowing it to be
+ handled in a toolkit-independent manner. */
+
+public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration implements Cloneable {
+ private GraphicsConfiguration config;
+ AbstractGraphicsConfiguration encapsulated;
+
+ public AWTGraphicsConfiguration(AWTGraphicsScreen screen,
+ CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested,
+ GraphicsConfiguration config, AbstractGraphicsConfiguration encapsulated) {
+ super(screen, capsChosen, capsRequested);
+ this.config = config;
+ this.encapsulated=encapsulated;
+ }
+
+ private AWTGraphicsConfiguration(AWTGraphicsScreen screen, CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested,
+ GraphicsConfiguration config) {
+ super(screen, capsChosen, capsRequested);
+ this.config = config;
+ this.encapsulated=null;
+ }
+
+ /**
+ * @param capsChosen if null, <code>capsRequested</code> is copied and aligned
+ * with the graphics Capabilities of the AWT Component to produce the chosen Capabilities.
+ * Otherwise the <code>capsChosen</code> is used.
+ */
+ public static AWTGraphicsConfiguration create(Component awtComp, CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested) {
+ final GraphicsConfiguration awtGfxConfig = awtComp.getGraphicsConfiguration();
+ if(null==awtGfxConfig) {
+ throw new NativeWindowException("AWTGraphicsConfiguration.create: Null AWT GraphicsConfiguration @ "+awtComp);
+ }
+ final GraphicsDevice awtGraphicsDevice = awtGfxConfig.getDevice();
+ if(null==awtGraphicsDevice) {
+ throw new NativeWindowException("AWTGraphicsConfiguration.create: Null AWT GraphicsDevice @ "+awtGfxConfig);
+ }
+
+ // Create Device/Screen
+ final AWTGraphicsDevice awtDevice = new AWTGraphicsDevice(awtGraphicsDevice, AbstractGraphicsDevice.DEFAULT_UNIT);
+ final AWTGraphicsScreen awtScreen = new AWTGraphicsScreen(awtDevice);
+
+ if(null==capsChosen) {
+ GraphicsConfiguration gc = awtGraphicsDevice.getDefaultConfiguration();
+ capsChosen = AWTGraphicsConfiguration.setupCapabilitiesRGBABits(capsRequested, gc);
+ }
+ final GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(awtDevice);
+ final AbstractGraphicsConfiguration config = factory.chooseGraphicsConfiguration(capsChosen, capsRequested, null, awtScreen);
+ if(config instanceof AWTGraphicsConfiguration) {
+ return (AWTGraphicsConfiguration) config;
+ }
+ // System.err.println("Info: AWTGraphicsConfiguration.create: Expected AWTGraphicsConfiguration got: "+config.getClass()+" w/ factory "+factory.getClass()+" - Unable to encapsulate native GraphicsConfiguration.");
+ return new AWTGraphicsConfiguration(awtScreen, capsChosen, capsRequested, awtGfxConfig);
+ }
+
+ // open access to superclass method
+ public void setChosenCapabilities(CapabilitiesImmutable capsChosen) {
+ super.setChosenCapabilities(capsChosen);
+ }
+
+ @Override
+ public Object clone() {
+ return super.clone();
+ }
+
+ /** Return the AWT {@link GraphicsConfiguration}. */
+ public GraphicsConfiguration getAWTGraphicsConfiguration() {
+ return config;
+ }
+
+ @Override
+ public AbstractGraphicsConfiguration getNativeGraphicsConfiguration() {
+ return (null!=encapsulated)?encapsulated:this;
+ }
+
+ /**
+ * Sets up the Capabilities' RGBA size based on the given GraphicsConfiguration's ColorModel.
+ *
+ * @param capabilities the Capabilities object whose red, green, blue, and alpha bits will be set
+ * @param gc the GraphicsConfiguration from which to derive the RGBA bit depths
+ * @return the passed Capabilities
+ */
+ public static CapabilitiesImmutable setupCapabilitiesRGBABits(CapabilitiesImmutable capabilitiesIn, GraphicsConfiguration gc) {
+ Capabilities capabilities = (Capabilities) capabilitiesIn.cloneMutable();
+
+ ColorModel cm = gc.getColorModel();
+ if(null==cm) {
+ throw new NativeWindowException("Could not determine AWT ColorModel");
+ }
+ int cmBitsPerPixel = cm.getPixelSize();
+ int bitsPerPixel = 0;
+ int[] bitesPerComponent = cm.getComponentSize();
+ if(bitesPerComponent.length>=3) {
+ capabilities.setRedBits(bitesPerComponent[0]);
+ bitsPerPixel += bitesPerComponent[0];
+ capabilities.setGreenBits(bitesPerComponent[1]);
+ bitsPerPixel += bitesPerComponent[1];
+ capabilities.setBlueBits(bitesPerComponent[2]);
+ bitsPerPixel += bitesPerComponent[2];
+ }
+ if(bitesPerComponent.length>=4) {
+ capabilities.setAlphaBits(bitesPerComponent[3]);
+ bitsPerPixel += bitesPerComponent[3];
+ } else {
+ capabilities.setAlphaBits(0);
+ }
+ if(Debug.debugAll()) {
+ if(cmBitsPerPixel!=bitsPerPixel) {
+ System.err.println("AWT Colormodel bits per components/pixel mismatch: "+bitsPerPixel+" != "+cmBitsPerPixel);
+ }
+ }
+ return capabilities;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName()+"[" + getScreen() +
+ ",\n\tchosen " + capabilitiesChosen+
+ ",\n\trequested " + capabilitiesRequested+
+ ",\n\t" + config +
+ ",\n\tencapsulated "+encapsulated+"]";
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsDevice.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsDevice.java
new file mode 100644
index 000000000..8ebe37626
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsDevice.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package javax.media.nativewindow.awt;
+
+import javax.media.nativewindow.*;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+
+/** A wrapper for an AWT GraphicsDevice allowing it to be
+ handled in a toolkit-independent manner. */
+public class AWTGraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
+ private GraphicsDevice device;
+
+ public AWTGraphicsDevice(GraphicsDevice device, int unitID) {
+ super(NativeWindowFactory.TYPE_AWT, device.getIDstring(), unitID);
+ this.device = device;
+ }
+
+ public static AWTGraphicsDevice createDefault() {
+ GraphicsDevice awtDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ return new AWTGraphicsDevice(awtDevice, AbstractGraphicsDevice.DEFAULT_UNIT);
+ }
+
+ @Override
+ public Object clone() {
+ return super.clone();
+ }
+
+ public GraphicsDevice getGraphicsDevice() {
+ return device;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName()+"[type "+getType()+", connection "+getConnection()+", unitID "+getUnitID()+", awtDevice "+device+", handle 0x"+Long.toHexString(getHandle())+"]";
+ }
+}
+
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsScreen.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsScreen.java
new file mode 100644
index 000000000..2978d7868
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsScreen.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package javax.media.nativewindow.awt;
+
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import javax.media.nativewindow.*;
+
+/** A wrapper for an AWT GraphicsDevice (screen) allowing it to be
+ handled in a toolkit-independent manner. */
+
+public class AWTGraphicsScreen extends DefaultGraphicsScreen implements Cloneable {
+
+ public AWTGraphicsScreen(AWTGraphicsDevice device) {
+ super(device, findScreenIndex(device.getGraphicsDevice()));
+ }
+
+ public static GraphicsDevice getScreenDevice(int index) {
+ if(index<0) return null;
+ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ GraphicsDevice[] gs = ge.getScreenDevices();
+ if(index<gs.length) {
+ return gs[index];
+ }
+ return null;
+ }
+
+ public static int findScreenIndex(GraphicsDevice awtDevice) {
+ if(null==awtDevice) return -1;
+ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ GraphicsDevice[] gs = ge.getScreenDevices();
+ for (int j = 0; j < gs.length; j++) {
+ if(gs[j] == awtDevice) return j;
+ }
+ return -1;
+ }
+
+ public static AbstractGraphicsScreen createScreenDevice(GraphicsDevice awtDevice, int unitID) {
+ return new AWTGraphicsScreen(new AWTGraphicsDevice(awtDevice, unitID));
+ }
+
+ public static AbstractGraphicsScreen createScreenDevice(int index, int unitID) {
+ return createScreenDevice(getScreenDevice(index), unitID);
+ }
+
+ public static AbstractGraphicsScreen createDefault() {
+ return new AWTGraphicsScreen(AWTGraphicsDevice.createDefault());
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+}
+
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTWindowClosingProtocol.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTWindowClosingProtocol.java
new file mode 100644
index 000000000..e7db942e4
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTWindowClosingProtocol.java
@@ -0,0 +1,139 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package javax.media.nativewindow.awt;
+
+import java.awt.Component;
+import java.awt.Window;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+import javax.media.nativewindow.WindowClosingProtocol;
+import jogamp.nativewindow.awt.AWTMisc;
+
+public class AWTWindowClosingProtocol implements WindowClosingProtocol {
+
+ private Component comp;
+ private Runnable closingOperation;
+ private volatile boolean closingListenerSet = false;
+ private Object closingListenerLock = new Object();
+ private int defaultCloseOperation = DISPOSE_ON_CLOSE;
+ private boolean defaultCloseOperationSetByUser = false;
+
+ public AWTWindowClosingProtocol(Component comp, Runnable closingOperation) {
+ this.comp = comp;
+ this.closingOperation = closingOperation;
+ }
+
+ class WindowClosingAdapter extends WindowAdapter {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ int op = AWTWindowClosingProtocol.this.getDefaultCloseOperation();
+
+ if( DISPOSE_ON_CLOSE == op ) {
+ // we have to issue this call right away,
+ // otherwise the window gets destroyed
+ closingOperation.run();
+ }
+ }
+ }
+ WindowListener windowClosingAdapter = new WindowClosingAdapter();
+
+ final boolean addClosingListenerImpl() {
+ Window w = AWTMisc.getWindow(comp);
+ if(null!=w) {
+ w.addWindowListener(windowClosingAdapter);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Adds this closing listener to the components Window if exist and only one time.<br>
+ * Hence you may call this method every time to ensure it has been set,
+ * ie in case the Window parent is not available yet.
+ *
+ * @return
+ */
+ public final boolean addClosingListenerOneShot() {
+ if(!closingListenerSet) { // volatile: ok
+ synchronized(closingListenerLock) {
+ if(!closingListenerSet) {
+ closingListenerSet=addClosingListenerImpl();
+ return closingListenerSet;
+ }
+ }
+ }
+ return false;
+ }
+
+ public final boolean removeClosingListener() {
+ if(closingListenerSet) { // volatile: ok
+ synchronized(closingListenerLock) {
+ if(closingListenerSet) {
+ Window w = AWTMisc.getWindow(comp);
+ if(null!=w) {
+ w.removeWindowListener(windowClosingAdapter);
+ closingListenerSet = false;
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @return the user set close operation if set by {@link #setDefaultCloseOperation(int) setDefaultCloseOperation(int)},
+ * otherwise return the AWT/Swing close operation value translated to
+ * a {@link WindowClosingProtocol} value .
+ */
+ public final int getDefaultCloseOperation() {
+ int op = -1;
+ synchronized(closingListenerLock) {
+ if(defaultCloseOperationSetByUser) {
+ op = defaultCloseOperation;
+ }
+ }
+ if(0 <= op) {
+ return op;
+ }
+ // User didn't determine the behavior, use underlying AWT behavior
+ return AWTMisc.getNWClosingOperation(comp);
+ }
+
+ public final int setDefaultCloseOperation(int op) {
+ synchronized(closingListenerLock) {
+ int _op = defaultCloseOperation;
+ defaultCloseOperation = op;
+ defaultCloseOperationSetByUser = true;
+ return _op;
+ }
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
new file mode 100644
index 000000000..863b336fc
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
@@ -0,0 +1,489 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ */
+
+package jogamp.nativewindow.jawt;
+
+import com.jogamp.common.util.locks.LockFactory;
+import com.jogamp.common.util.locks.RecursiveLock;
+
+import java.awt.Component;
+import java.awt.Container;
+import java.applet.Applet;
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.NativeWindow;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.OffscreenLayerOption;
+import javax.media.nativewindow.OffscreenLayerSurface;
+import javax.media.nativewindow.SurfaceUpdatedListener;
+import javax.media.nativewindow.awt.AWTGraphicsConfiguration;
+import javax.media.nativewindow.util.Insets;
+import javax.media.nativewindow.util.InsetsImmutable;
+import javax.media.nativewindow.util.Point;
+import javax.media.nativewindow.util.Rectangle;
+import javax.media.nativewindow.util.RectangleImmutable;
+
+import jogamp.nativewindow.SurfaceUpdatedHelper;
+
+public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, OffscreenLayerOption {
+ protected static final boolean DEBUG = JAWTUtil.DEBUG;
+
+ // user properties
+ protected boolean shallUseOffscreenLayer = false;
+
+ // lifetime: forever
+ protected Component component;
+ private AWTGraphicsConfiguration config; // control access due to delegation
+ private SurfaceUpdatedHelper surfaceUpdatedHelper = new SurfaceUpdatedHelper();
+ private RecursiveLock surfaceLock = LockFactory.createRecursiveLock();
+
+ // lifetime: valid after lock but may change with each 1st lock, purges after invalidate
+ private boolean isApplet;
+ private JAWT jawt;
+ private boolean isOffscreenLayerSurface;
+ protected long drawable;
+ protected Rectangle bounds;
+ protected Insets insets;
+
+ private long drawable_old;
+
+ /**
+ * Constructed by {@link jogamp.nativewindow.NativeWindowFactoryImpl#getNativeWindow(Object, AbstractGraphicsConfiguration)}
+ * via this platform's specialization (X11, OSX, Windows, ..).
+ *
+ * @param comp
+ * @param config
+ */
+ protected JAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
+ if (config == null) {
+ throw new NativeWindowException("Error: AbstractGraphicsConfiguration is null");
+ }
+ if(! ( config instanceof AWTGraphicsConfiguration ) ) {
+ throw new NativeWindowException("Error: AbstractGraphicsConfiguration is not an AWTGraphicsConfiguration: "+config);
+ }
+ this.config = (AWTGraphicsConfiguration) config;
+ init((Component)comp);
+ }
+
+ private void init(Component windowObject) throws NativeWindowException {
+ invalidate();
+ this.component = windowObject;
+ this.isApplet = false;
+ }
+
+ public void setShallUseOffscreenLayer(boolean v) {
+ shallUseOffscreenLayer = v;
+ }
+
+ public final boolean getShallUseOffscreenLayer() {
+ return shallUseOffscreenLayer;
+ }
+
+ public final boolean isOffscreenLayerSurfaceEnabled() {
+ return isOffscreenLayerSurface;
+ }
+
+ protected synchronized void invalidate() {
+ invalidateNative();
+ jawt = null;
+ isOffscreenLayerSurface = false;
+ drawable= 0;
+ drawable_old = 0;
+ bounds = new Rectangle();
+ insets = new Insets();
+ }
+ protected abstract void invalidateNative();
+
+ protected final void updateBounds(JAWT_Rectangle jawtBounds) {
+ bounds.setX(jawtBounds.getX());
+ bounds.setY(jawtBounds.getY());
+ bounds.setWidth(jawtBounds.getWidth());
+ bounds.setHeight(jawtBounds.getHeight());
+
+ if(component instanceof Container) {
+ java.awt.Insets contInsets = ((Container)component).getInsets();
+ insets.setLeftWidth(contInsets.left);
+ insets.setRightWidth(contInsets.right);
+ insets.setTopHeight(contInsets.top);
+ insets.setBottomHeight(contInsets.bottom);
+ }
+ }
+
+ /** @return the JAWT_DrawingSurfaceInfo's (JAWT_Rectangle) bounds, updated with lock */
+ public final RectangleImmutable getBounds() { return bounds; }
+
+ public final InsetsImmutable getInsets() { return insets; }
+
+ public final Component getAWTComponent() {
+ return component;
+ }
+
+ /**
+ * Returns true if the AWT component is parented to an {@link java.applet.Applet},
+ * otherwise false. This information is valid only after {@link #lockSurface()}.
+ */
+ public final boolean isApplet() {
+ return isApplet;
+ }
+
+ /** Returns the underlying JAWT instance created @ {@link #lockSurface()}. */
+ public final JAWT getJAWT() {
+ return jawt;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void attachSurfaceLayer(final long layerHandle) throws NativeWindowException {
+ if( !isOffscreenLayerSurfaceEnabled() ) {
+ throw new NativeWindowException("Not an offscreen layer surface");
+ }
+ int lockRes = lockSurface();
+ if (NativeSurface.LOCK_SURFACE_NOT_READY >= lockRes) {
+ throw new NativeWindowException("Could not lock (offscreen layer): "+this);
+ }
+ try {
+ if(DEBUG) {
+ System.err.println("JAWTWindow.attachSurfaceHandle(): 0x"+Long.toHexString(layerHandle));
+ }
+ attachSurfaceLayerImpl(layerHandle);
+ } finally {
+ unlockSurface();
+ }
+ }
+ protected abstract void attachSurfaceLayerImpl(final long layerHandle);
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void detachSurfaceLayer(final long layerHandle) throws NativeWindowException {
+ if( !isOffscreenLayerSurfaceEnabled() ) {
+ throw new java.lang.UnsupportedOperationException("Not an offscreen layer surface");
+ }
+ int lockRes = lockSurface();
+ if (NativeSurface.LOCK_SURFACE_NOT_READY >= lockRes) {
+ throw new NativeWindowException("Could not lock (offscreen layer): "+this);
+ }
+ try {
+ if(DEBUG) {
+ System.err.println("JAWTWindow.detachSurfaceHandle(): 0x"+Long.toHexString(layerHandle));
+ }
+ detachSurfaceLayerImpl(layerHandle);
+ } finally {
+ unlockSurface();
+ }
+ }
+ protected abstract void detachSurfaceLayerImpl(final long layerHandle);
+
+ //
+ // SurfaceUpdateListener
+ //
+
+ public void addSurfaceUpdatedListener(SurfaceUpdatedListener l) {
+ surfaceUpdatedHelper.addSurfaceUpdatedListener(l);
+ }
+
+ public void addSurfaceUpdatedListener(int index, SurfaceUpdatedListener l) throws IndexOutOfBoundsException {
+ surfaceUpdatedHelper.addSurfaceUpdatedListener(index, l);
+ }
+
+ public void removeSurfaceUpdatedListener(SurfaceUpdatedListener l) {
+ surfaceUpdatedHelper.removeSurfaceUpdatedListener(l);
+ }
+
+ public void surfaceUpdated(Object updater, NativeSurface ns, long when) {
+ surfaceUpdatedHelper.surfaceUpdated(updater, ns, when);
+ }
+
+ //
+ // NativeSurface
+ //
+
+ private void determineIfApplet() {
+ Component c = component;
+ while(!isApplet && null != c) {
+ isApplet = c instanceof Applet;
+ c = c.getParent();
+ }
+ }
+
+ /**
+ * If JAWT offscreen layer is supported,
+ * implementation shall respect {@link #getShallUseOffscreenLayer()}
+ * and may respect {@link #isApplet()}.
+ *
+ * @return The JAWT instance reflecting offscreen layer support, etc.
+ *
+ * @throws NativeWindowException
+ */
+ protected abstract JAWT fetchJAWTImpl() throws NativeWindowException;
+ protected abstract int lockSurfaceImpl() throws NativeWindowException;
+
+ protected void dumpJAWTInfo() {
+ if(null != jawt) {
+ System.err.println("JAWT version: 0x"+Integer.toHexString(jawt.getCachedVersion())+
+ ", CA_LAYER: "+ JAWTUtil.isJAWTUsingOffscreenLayer(jawt)+
+ ", isLayeredSurface "+isOffscreenLayerSurfaceEnabled()+", bounds "+bounds+", insets "+insets);
+ } else {
+ System.err.println("JAWT n/a, bounds "+bounds+", insets "+insets);
+ }
+ // Thread.dumpStack();
+ }
+
+ public final int lockSurface() throws NativeWindowException {
+ surfaceLock.lock();
+ int res = surfaceLock.getHoldCount() == 1 ? LOCK_SURFACE_NOT_READY : LOCK_SUCCESS; // new lock ?
+
+ if ( LOCK_SURFACE_NOT_READY == res ) {
+ determineIfApplet();
+ try {
+ final AbstractGraphicsDevice adevice = getGraphicsConfiguration().getScreen().getDevice();
+ adevice.lock();
+ try {
+ jawt = fetchJAWTImpl();
+ isOffscreenLayerSurface = JAWTUtil.isJAWTUsingOffscreenLayer(jawt);
+ res = lockSurfaceImpl();
+ if(LOCK_SUCCESS == res && drawable_old != drawable) {
+ res = LOCK_SURFACE_CHANGED;
+ if(DEBUG) {
+ System.err.println("JAWTWindow: surface change 0x"+Long.toHexString(drawable_old)+" -> 0x"+Long.toHexString(drawable));
+ // Thread.dumpStack();
+ }
+ }
+ } finally {
+ if (LOCK_SURFACE_NOT_READY >= res) {
+ adevice.unlock();
+ }
+ }
+ } finally {
+ if (LOCK_SURFACE_NOT_READY >= res) {
+ surfaceLock.unlock();
+ }
+ }
+ }
+ return res;
+ }
+
+ protected abstract void unlockSurfaceImpl() throws NativeWindowException;
+
+ public final void unlockSurface() {
+ surfaceLock.validateLocked();
+ drawable_old = drawable;
+
+ if (surfaceLock.getHoldCount() == 1) {
+ final AbstractGraphicsDevice adevice = getGraphicsConfiguration().getScreen().getDevice();
+ try {
+ unlockSurfaceImpl();
+ } finally {
+ adevice.unlock();
+ }
+ }
+ surfaceLock.unlock();
+ }
+
+ public final boolean isSurfaceLockedByOtherThread() {
+ return surfaceLock.isLockedByOtherThread();
+ }
+
+ public final boolean isSurfaceLocked() {
+ return surfaceLock.isLocked();
+ }
+
+ public final Thread getSurfaceLockOwner() {
+ return surfaceLock.getOwner();
+ }
+
+ public boolean surfaceSwap() {
+ return false;
+ }
+
+ public long getSurfaceHandle() {
+ return drawable;
+ }
+
+ public final AWTGraphicsConfiguration getPrivateGraphicsConfiguration() {
+ return config;
+ }
+
+ public final AbstractGraphicsConfiguration getGraphicsConfiguration() {
+ return config.getNativeGraphicsConfiguration();
+ }
+
+ public final long getDisplayHandle() {
+ return getGraphicsConfiguration().getScreen().getDevice().getHandle();
+ }
+
+ public final int getScreenIndex() {
+ return getGraphicsConfiguration().getScreen().getIndex();
+ }
+
+ public int getWidth() {
+ return component.getWidth();
+ }
+
+ public int getHeight() {
+ return component.getHeight();
+ }
+
+ //
+ // NativeWindow
+ //
+
+ public synchronized void destroy() {
+ invalidate();
+ component = null; // don't dispose the AWT component, since we are merely an immutable uplink
+ }
+
+ public final NativeWindow getParent() {
+ return null;
+ }
+
+ public long getWindowHandle() {
+ return drawable;
+ }
+
+ public final int getX() {
+ return component.getX();
+ }
+
+ public final int getY() {
+ return component.getY();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * <p>
+ * This JAWT default implementation is currently still using
+ * a blocking implementation. It first attempts to retrieve the location
+ * via a native implementation. If this fails, it tries the blocking AWT implementation.
+ * If the latter fails due to an external AWT tree-lock, the non block
+ * implementation {@link #getLocationOnScreenNonBlocking(Point, Component)} is being used.
+ * The latter simply traverse up to the AWT component tree and sums the rel. position.
+ * We have to determine whether the latter is good enough for all cases,
+ * currently only OS X utilizes the non blocking method per default.
+ * </p>
+ */
+ public Point getLocationOnScreen(Point storage) {
+ Point los = getLocationOnScreenNative(storage);
+ if(null == los) {
+ if(!Thread.holdsLock(component.getTreeLock())) {
+ // avoid deadlock ..
+ if(DEBUG) {
+ System.err.println("Warning: JAWT Lock hold, but not the AWT tree lock: "+this);
+ Thread.dumpStack();
+ }
+ return getLocationOnScreenNonBlocking(storage, component);
+ }
+ java.awt.Point awtLOS = component.getLocationOnScreen();
+ if(null!=storage) {
+ los = storage.translate(awtLOS.x, awtLOS.y);
+ } else {
+ los = new Point(awtLOS.x, awtLOS.y);
+ }
+ }
+ return los;
+ }
+
+ protected Point getLocationOnScreenNative(Point storage) {
+ int lockRes = lockSurface();
+ if(LOCK_SURFACE_NOT_READY == lockRes) {
+ if(DEBUG) {
+ System.err.println("Warning: JAWT Lock couldn't be acquired: "+this);
+ Thread.dumpStack();
+ }
+ return null;
+ }
+ try {
+ Point d = getLocationOnScreenNativeImpl(0, 0);
+ if(null!=d) {
+ if(null!=storage) {
+ storage.translate(d.getX(),d.getY());
+ return storage;
+ }
+ }
+ return d;
+ } finally {
+ unlockSurface();
+ }
+ }
+ protected abstract Point getLocationOnScreenNativeImpl(int x, int y);
+
+ protected static Point getLocationOnScreenNonBlocking(Point storage, Component comp) {
+ int x = 0;
+ int y = 0;
+ while(null != comp) {
+ x += comp.getX();
+ y += comp.getY();
+ comp = comp.getParent();
+ }
+ if(null!=storage) {
+ storage.translate(x, y);
+ return storage;
+ }
+ return new Point(x, y);
+ }
+
+ public boolean hasFocus() {
+ return component.hasFocus();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("JAWT-Window["+
+ "windowHandle 0x"+Long.toHexString(getWindowHandle())+
+ ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+
+ ", bounds "+bounds+", insets "+insets+
+ ", shallUseOffscreenLayer "+shallUseOffscreenLayer+", isOffscreenLayerSurface "+isOffscreenLayerSurface);
+ if(null!=component) {
+ sb.append(", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+
+ ", visible "+component.isVisible());
+ } else {
+ sb.append(", component NULL");
+ }
+ sb.append(", lockedExt "+isSurfaceLockedByOtherThread()+
+ ",\n\tconfig "+getPrivateGraphicsConfiguration()+
+ ",\n\tawtComponent "+getAWTComponent()+
+ ",\n\tsurfaceLock "+surfaceLock+"]");
+
+ return sb.toString();
+ }
+
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/egl/EGLGraphicsDevice.java b/src/nativewindow/classes/com/jogamp/nativewindow/egl/EGLGraphicsDevice.java
new file mode 100644
index 000000000..2dfd9f0ee
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/egl/EGLGraphicsDevice.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package javax.media.nativewindow.egl;
+
+import javax.media.nativewindow.*;
+
+/** Encapsulates a graphics device on EGL platforms.
+ */
+
+public class EGLGraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
+ boolean closeDisplay = false;
+
+ /**
+ * Note that this is not an open connection, ie no native display handle exist.
+ * This constructor exist to setup a default device connection/unit.<br>
+ */
+ public EGLGraphicsDevice(String connection, int unitID) {
+ super(NativeWindowFactory.TYPE_EGL, connection, unitID);
+ }
+
+ /** Constructs a new EGLGraphicsDevice corresponding to the given EGL display handle. */
+ public EGLGraphicsDevice(long eglDisplay, String connection, int unitID) {
+ super(NativeWindowFactory.TYPE_EGL, connection, unitID, eglDisplay);
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+}
+
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/macosx/MacOSXGraphicsDevice.java b/src/nativewindow/classes/com/jogamp/nativewindow/macosx/MacOSXGraphicsDevice.java
new file mode 100644
index 000000000..02c63758f
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/macosx/MacOSXGraphicsDevice.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package javax.media.nativewindow.macosx;
+
+import javax.media.nativewindow.*;
+
+/** Encapsulates a graphics device on MacOSX platforms.
+ */
+
+public class MacOSXGraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
+ /** Constructs a new MacOSXGraphicsDevice */
+ public MacOSXGraphicsDevice(int unitID) {
+ super(NativeWindowFactory.TYPE_MACOSX, AbstractGraphicsDevice.DEFAULT_CONNECTION, unitID);
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+}
+
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java
new file mode 100644
index 000000000..aab1556da
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java
@@ -0,0 +1,265 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package jogamp.nativewindow.swt;
+
+import com.jogamp.common.os.Platform;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.eclipse.swt.graphics.GCData;
+import org.eclipse.swt.widgets.Control;
+
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.nativewindow.windows.WindowsGraphicsDevice;
+import javax.media.nativewindow.x11.X11GraphicsDevice;
+import com.jogamp.common.util.ReflectionUtil;
+import javax.media.nativewindow.macosx.MacOSXGraphicsDevice;
+
+import jogamp.nativewindow.macosx.OSXUtil;
+
+public class SWTAccessor {
+ static final Field swt_control_handle;
+ static final boolean swt_uses_long_handles;
+
+ // X11/GTK, Windows/GDI, ..
+ static final String str_handle = "handle";
+
+ // OSX/Cocoa
+ static final String str_view = "view"; // OSX
+ static final String str_id = "id"; // OSX
+ // static final String str_NSView = "org.eclipse.swt.internal.cocoa.NSView";
+
+ static final Method swt_control_internal_new_GC;
+ static final Method swt_control_internal_dispose_GC;
+ static final String str_internal_new_GC = "internal_new_GC";
+ static final String str_internal_dispose_GC = "internal_dispose_GC";
+
+ static final String str_OS_gtk_class = "org.eclipse.swt.internal.gtk.OS";
+ static final Class<?> OS_gtk_class;
+ static final Method OS_gtk_widget_realize;
+ static final Method OS_gtk_widget_unrealize;
+ static final Method OS_GTK_WIDGET_WINDOW;
+ static final Method OS_gdk_x11_drawable_get_xdisplay;
+ static final Method OS_gdk_x11_drawable_get_xid;
+ static final String str_gtk_widget_realize = "gtk_widget_realize";
+ static final String str_gtk_widget_unrealize = "gtk_widget_unrealize";
+ static final String str_GTK_WIDGET_WINDOW = "GTK_WIDGET_WINDOW";
+ static final String str_gdk_x11_drawable_get_xdisplay = "gdk_x11_drawable_get_xdisplay";
+ static final String str_gdk_x11_drawable_get_xid = "gdk_x11_drawable_get_xid";
+
+ static {
+ Field f = null;
+
+ if(NativeWindowFactory.TYPE_MACOSX != NativeWindowFactory.getNativeWindowType(false) ) {
+ try {
+ f = Control.class.getField(str_handle);
+ } catch (Exception ex) {
+ throw new NativeWindowException(ex);
+ }
+ }
+ swt_control_handle = f; // maybe null !
+
+ boolean ulh;
+ if (null != swt_control_handle) {
+ ulh = swt_control_handle.getGenericType().toString().equals(long.class.toString());
+ } else {
+ ulh = Platform.is64Bit();
+ }
+ swt_uses_long_handles = ulh;
+ // System.err.println("SWT long handles: " + swt_uses_long_handles);
+ // System.err.println("Platform 64bit: "+Platform.is64Bit());
+
+ Method m=null;
+ try {
+ m = ReflectionUtil.getMethod(Control.class, str_internal_new_GC, new Class[] { GCData.class });
+ } catch (Exception ex) {
+ throw new NativeWindowException(ex);
+ }
+ swt_control_internal_new_GC = m;
+
+ try {
+ if(swt_uses_long_handles) {
+ m = Control.class.getDeclaredMethod(str_internal_dispose_GC, new Class[] { long.class, GCData.class });
+ } else {
+ m = Control.class.getDeclaredMethod(str_internal_dispose_GC, new Class[] { int.class, GCData.class });
+ }
+ } catch (NoSuchMethodException ex) {
+ throw new NativeWindowException(ex);
+ }
+ swt_control_internal_dispose_GC = m;
+
+ Class<?> c=null;
+ Method m1=null, m2=null, m3=null, m4=null, m5=null;
+ Class<?> handleType = swt_uses_long_handles ? long.class : int.class ;
+ if( NativeWindowFactory.TYPE_X11 == NativeWindowFactory.getNativeWindowType(false) ) {
+ try {
+ c = ReflectionUtil.getClass(str_OS_gtk_class, false, SWTAccessor.class.getClassLoader());
+ m1 = c.getDeclaredMethod(str_gtk_widget_realize, handleType);
+ m2 = c.getDeclaredMethod(str_gtk_widget_unrealize, handleType);
+ m3 = c.getDeclaredMethod(str_GTK_WIDGET_WINDOW, handleType);
+ m4 = c.getDeclaredMethod(str_gdk_x11_drawable_get_xdisplay, handleType);
+ m5 = c.getDeclaredMethod(str_gdk_x11_drawable_get_xid, handleType);
+ } catch (Exception ex) { throw new NativeWindowException(ex); }
+ }
+ OS_gtk_class = c;
+ OS_gtk_widget_realize = m1;
+ OS_gtk_widget_unrealize = m2;
+ OS_GTK_WIDGET_WINDOW = m3;
+ OS_gdk_x11_drawable_get_xdisplay = m4;
+ OS_gdk_x11_drawable_get_xid = m5;
+ }
+
+ static Object getIntOrLong(long arg) {
+ if(swt_uses_long_handles) {
+ return new Long(arg);
+ }
+ return new Integer((int) arg);
+ }
+
+ static void callStaticMethodL2V(Method m, long arg) {
+ ReflectionUtil.callMethod(null, m, new Object[] { getIntOrLong(arg) });
+ }
+
+ static long callStaticMethodL2L(Method m, long arg) {
+ Object o = ReflectionUtil.callMethod(null, m, new Object[] { getIntOrLong(arg) });
+ if(o instanceof Number) {
+ return ((Number)o).longValue();
+ } else {
+ throw new InternalError("SWT method "+m.getName()+" didn't return int or long but "+o.getClass());
+ }
+ }
+
+ public static boolean isUsingLongHandles() {
+ return swt_uses_long_handles;
+ }
+
+ public static long getHandle(Control swtControl) {
+ long h = 0;
+ if(NativeWindowFactory.TYPE_MACOSX == NativeWindowFactory.getNativeWindowType(false) ) {
+ try {
+ Field fView = Control.class.getField(str_view);
+ Object view = fView.get(swtControl);
+ Field fId = view.getClass().getField(str_id);
+ return fId.getLong(view);
+ } catch (Exception ex) {
+ throw new NativeWindowException(ex);
+ }
+ }
+
+ try {
+ h = swt_control_handle.getLong(swtControl);
+ } catch (Exception ex) {
+ throw new NativeWindowException(ex);
+ }
+ return h;
+ }
+
+ public static void setRealized(final Control swtControl, final boolean realize) {
+ final long handle = getHandle(swtControl);
+
+ if(null != OS_gtk_class) {
+ invoke(true, new Runnable() {
+ public void run() {
+ if(realize) {
+ callStaticMethodL2V(OS_gtk_widget_realize, handle);
+ } else {
+ callStaticMethodL2V(OS_gtk_widget_unrealize, handle);
+ }
+ }
+ });
+ }
+ }
+
+ public static AbstractGraphicsDevice getDevice(Control swtControl) {
+ long handle = getHandle(swtControl);
+ if( null != OS_gtk_class ) {
+ long widgedHandle = callStaticMethodL2L(OS_GTK_WIDGET_WINDOW, handle);
+ long displayHandle = callStaticMethodL2L(OS_gdk_x11_drawable_get_xdisplay, widgedHandle);
+ // FIXME: May think about creating a private non-shared X11 Display handle, like we use to for AWT
+ // to avoid locking problems !
+ return new X11GraphicsDevice(displayHandle, AbstractGraphicsDevice.DEFAULT_UNIT, false);
+ }
+ if( NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(false) ) {
+ return new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
+ }
+ if( NativeWindowFactory.TYPE_MACOSX == NativeWindowFactory.getNativeWindowType(false) ) {
+ return new MacOSXGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT);
+ }
+ throw new UnsupportedOperationException("n/a for this windowing system: "+NativeWindowFactory.getNativeWindowType(false));
+ }
+
+ public static long getWindowHandle(Control swtControl) {
+ long handle = getHandle(swtControl);
+ if( null != OS_gtk_class ) {
+ long widgedHandle = callStaticMethodL2L(OS_GTK_WIDGET_WINDOW, handle);
+ return callStaticMethodL2L(OS_gdk_x11_drawable_get_xid, widgedHandle);
+ }
+ if( NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(false) ||
+ NativeWindowFactory.TYPE_MACOSX == NativeWindowFactory.getNativeWindowType(false) ) {
+ return handle;
+ }
+ throw new UnsupportedOperationException("n/a for this windowing system: "+NativeWindowFactory.getNativeWindowType(false));
+ }
+
+ public static long newGC(final Control swtControl, final GCData gcData) {
+ final Object[] o = new Object[1];
+ invoke(true, new Runnable() {
+ public void run() {
+ o[0] = ReflectionUtil.callMethod(swtControl, swt_control_internal_new_GC, new Object[] { gcData });
+ }
+ });
+ if(o[0] instanceof Number) {
+ return ((Number)o[0]).longValue();
+ } else {
+ throw new InternalError("SWT internal_new_GC did not return int or long but "+o[0].getClass());
+ }
+ }
+
+ public static void disposeGC(final Control swtControl, final long gc, final GCData gcData) {
+ invoke(true, new Runnable() {
+ public void run() {
+ if(swt_uses_long_handles) {
+ ReflectionUtil.callMethod(swtControl, swt_control_internal_dispose_GC, new Object[] { new Long(gc), gcData });
+ } else {
+ ReflectionUtil.callMethod(swtControl, swt_control_internal_dispose_GC, new Object[] { new Integer((int)gc), gcData });
+ }
+ }
+ });
+ }
+
+ public static void invoke(boolean wait, Runnable runnable) {
+ if(Platform.OS_TYPE == Platform.OSType.MACOS) {
+ OSXUtil.RunOnMainThread(wait, runnable);
+ } else {
+ runnable.run();
+ }
+ }
+
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/windows/WindowsGraphicsDevice.java b/src/nativewindow/classes/com/jogamp/nativewindow/windows/WindowsGraphicsDevice.java
new file mode 100644
index 000000000..5d0129e0d
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/windows/WindowsGraphicsDevice.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package javax.media.nativewindow.windows;
+
+import javax.media.nativewindow.*;
+
+/**
+ * Encapsulates a graphics device on Windows platforms.<br>
+ */
+public class WindowsGraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
+ /** Constructs a new WindowsGraphicsDevice */
+ public WindowsGraphicsDevice(int unitID) {
+ this(AbstractGraphicsDevice.DEFAULT_CONNECTION, unitID);
+ }
+
+ public WindowsGraphicsDevice(String connection, int unitID) {
+ super(NativeWindowFactory.TYPE_WINDOWS, connection, unitID);
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+}
+
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsConfiguration.java b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsConfiguration.java
new file mode 100644
index 000000000..74439336d
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsConfiguration.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package javax.media.nativewindow.x11;
+
+import javax.media.nativewindow.CapabilitiesImmutable;
+
+import jogamp.nativewindow.MutableGraphicsConfiguration;
+import jogamp.nativewindow.x11.XVisualInfo;
+
+/** Encapsulates a graphics configuration, or OpenGL pixel format, on
+ X11 platforms. Objects of this type are returned from {@link
+ javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration
+ GraphicsConfigurationFactory.chooseGraphicsConfiguration()} on X11
+ platforms when toolkits other than the AWT are being used. */
+
+public class X11GraphicsConfiguration extends MutableGraphicsConfiguration implements Cloneable {
+ private XVisualInfo info;
+
+ public X11GraphicsConfiguration(X11GraphicsScreen screen,
+ CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested,
+ XVisualInfo info) {
+ super(screen, capsChosen, capsRequested);
+ this.info = info;
+ }
+
+ @Override
+ public Object clone() {
+ return super.clone();
+ }
+
+ public XVisualInfo getXVisualInfo() {
+ return info;
+ }
+
+ protected void setXVisualInfo(XVisualInfo info) {
+ this.info = info;
+ }
+
+ public long getVisualID() {
+ return (null!=info)?info.getVisualid():0;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName()+"["+getScreen()+", visualID 0x" + Long.toHexString(getVisualID()) +
+ ",\n\tchosen " + capabilitiesChosen+
+ ",\n\trequested " + capabilitiesRequested+
+ "]";
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java
new file mode 100644
index 000000000..73c8cfd52
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package javax.media.nativewindow.x11;
+
+import jogamp.nativewindow.Debug;
+import jogamp.nativewindow.x11.X11Lib;
+import jogamp.nativewindow.x11.X11Util;
+import javax.media.nativewindow.DefaultGraphicsDevice;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.nativewindow.ToolkitLock;
+
+/** Encapsulates a graphics device on X11 platforms.
+ */
+
+public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
+ public static final boolean DEBUG = Debug.debug("GraphicsDevice");
+ final boolean closeDisplay;
+
+ /** Constructs a new X11GraphicsDevice corresponding to the given connection and default
+ * {@link javax.media.nativewindow.ToolkitLock} via {@link NativeWindowFactory#getDefaultToolkitLock(String)}.<br>
+ * Note that this is not an open connection, ie no native display handle exist.
+ * This constructor exist to setup a default device connection.
+ * @see DefaultGraphicsDevice#DefaultGraphicsDevice(String, String, int)
+ */
+ public X11GraphicsDevice(String connection, int unitID) {
+ super(NativeWindowFactory.TYPE_X11, connection, unitID);
+ closeDisplay = false;
+ }
+
+ /** Constructs a new X11GraphicsDevice corresponding to the given native display handle and default
+ * {@link javax.media.nativewindow.ToolkitLock} via {@link NativeWindowFactory#createDefaultToolkitLock(String, long)}.
+ * @see DefaultGraphicsDevice#DefaultGraphicsDevice(String, String, int, long)
+ */
+ public X11GraphicsDevice(long display, int unitID, boolean owner) {
+ // FIXME: derive unitID from connection could be buggy, one DISPLAY for all screens for example..
+ super(NativeWindowFactory.TYPE_X11, X11Lib.XDisplayString(display), unitID, display);
+ if(0==display) {
+ throw new NativeWindowException("null display");
+ }
+ closeDisplay = owner;
+ }
+
+ /**
+ * @param display the Display connection
+ * @param locker custom {@link javax.media.nativewindow.ToolkitLock}, eg to force null locking in NEWT
+ * @see DefaultGraphicsDevice#DefaultGraphicsDevice(String, String, int, long, ToolkitLock)
+ */
+ public X11GraphicsDevice(long display, int unitID, ToolkitLock locker, boolean owner) {
+ super(NativeWindowFactory.TYPE_X11, X11Lib.XDisplayString(display), unitID, display, locker);
+ if(0==display) {
+ throw new NativeWindowException("null display");
+ }
+ closeDisplay = owner;
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+
+ public boolean close() {
+ // FIXME: shall we respect the unitID ?
+ if(closeDisplay && 0 != handle) {
+ if(DEBUG) {
+ System.err.println(Thread.currentThread().getName() + " - X11GraphicsDevice.close(): "+this);
+ }
+ X11Util.closeDisplay(handle);
+ }
+ return super.close();
+ }
+}
+
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsScreen.java b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsScreen.java
new file mode 100644
index 000000000..ed59861ca
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsScreen.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package javax.media.nativewindow.x11;
+
+import javax.media.nativewindow.*;
+
+import jogamp.nativewindow.x11.X11Lib;
+import jogamp.nativewindow.x11.X11Util;
+
+/** Encapsulates a screen index on X11
+ platforms. Objects of this type are passed to {@link
+ javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration
+ GraphicsConfigurationFactory.chooseGraphicsConfiguration()} on X11
+ platforms when toolkits other than the AWT are being used. */
+
+public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneable {
+
+ /** Constructs a new X11GraphicsScreen corresponding to the given native screen index. */
+ public X11GraphicsScreen(X11GraphicsDevice device, int screen) {
+ super(device, fetchScreen(device, screen));
+ }
+
+ public static AbstractGraphicsScreen createScreenDevice(long display, int screenIdx, boolean owner) {
+ if(0==display) throw new NativeWindowException("display is null");
+ return new X11GraphicsScreen(new X11GraphicsDevice(display, AbstractGraphicsDevice.DEFAULT_UNIT, owner), screenIdx);
+ }
+
+ public long getDefaultVisualID() {
+ // It still could be an AWT hold handle ..
+ long display = getDevice().getHandle();
+ int scrnIdx = X11Lib.DefaultScreen(display);
+ return X11Lib.DefaultVisualID(display, scrnIdx);
+ }
+
+ private static int fetchScreen(X11GraphicsDevice device, int screen) {
+ // It still could be an AWT hold handle ..
+ if(X11Util.XineramaIsEnabled(device.getHandle())) {
+ screen = 0; // Xinerama -> 1 screen
+ }
+ return screen;
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+}