From 78b4918b207e16b967e8335fb8ec1b31c706c507 Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Mon, 2 Feb 2015 02:38:55 +0100
Subject: Bug 682 - Relocating javax.media.opengl.* -> com.jogamp.opengl.*
(Part 2)
Relocation javax.media.nativewindow.* -> com.jogamp.nativewindow.*
Relocation javax.media.opengl.* -> com.jogamp.opengl.*
---
.../AbstractGraphicsConfiguration.java | 81 +++
.../nativewindow/AbstractGraphicsDevice.java | 166 +++++
.../nativewindow/AbstractGraphicsScreen.java | 57 ++
.../com/jogamp/nativewindow/Capabilities.java | 414 ++++++++++++
.../jogamp/nativewindow/CapabilitiesChooser.java | 70 ++
.../jogamp/nativewindow/CapabilitiesImmutable.java | 139 ++++
.../nativewindow/DefaultCapabilitiesChooser.java | 172 +++++
.../nativewindow/DefaultGraphicsConfiguration.java | 134 ++++
.../jogamp/nativewindow/DefaultGraphicsDevice.java | 253 +++++++
.../jogamp/nativewindow/DefaultGraphicsScreen.java | 71 ++
.../nativewindow/GraphicsConfigurationFactory.java | 435 ++++++++++++
.../com/jogamp/nativewindow/MutableSurface.java | 44 ++
.../com/jogamp/nativewindow/NativeSurface.java | 238 +++++++
.../jogamp/nativewindow/NativeSurfaceHolder.java | 41 ++
.../com/jogamp/nativewindow/NativeWindow.java | 204 ++++++
.../jogamp/nativewindow/NativeWindowException.java | 68 ++
.../jogamp/nativewindow/NativeWindowFactory.java | 716 ++++++++++++++++++++
.../jogamp/nativewindow/OffscreenLayerOption.java | 61 ++
.../jogamp/nativewindow/OffscreenLayerSurface.java | 86 +++
.../com/jogamp/nativewindow/ProxySurface.java | 135 ++++
.../com/jogamp/nativewindow/ScalableSurface.java | 107 +++
.../nativewindow/SurfaceUpdatedListener.java | 51 ++
.../com/jogamp/nativewindow/ToolkitLock.java | 78 +++
.../jogamp/nativewindow/UpstreamSurfaceHook.java | 66 ++
.../com/jogamp/nativewindow/VisualIDHolder.java | 136 ++++
.../jogamp/nativewindow/WindowClosingProtocol.java | 73 ++
.../classes/com/jogamp/nativewindow/package.html | 101 +++
.../com/jogamp/nativewindow/util/Dimension.java | 128 ++++
.../nativewindow/util/DimensionImmutable.java | 68 ++
.../com/jogamp/nativewindow/util/Insets.java | 136 ++++
.../jogamp/nativewindow/util/InsetsImmutable.java | 71 ++
.../com/jogamp/nativewindow/util/PixelFormat.java | 739 +++++++++++++++++++++
.../jogamp/nativewindow/util/PixelFormatUtil.java | 600 +++++++++++++++++
.../jogamp/nativewindow/util/PixelRectangle.java | 194 ++++++
.../com/jogamp/nativewindow/util/Point.java | 190 ++++++
.../jogamp/nativewindow/util/PointImmutable.java | 63 ++
.../com/jogamp/nativewindow/util/Rectangle.java | 237 +++++++
.../nativewindow/util/RectangleImmutable.java | 87 +++
.../com/jogamp/nativewindow/util/SurfaceSize.java | 113 ++++
39 files changed, 6823 insertions(+)
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsConfiguration.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsDevice.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsScreen.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/Capabilities.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/CapabilitiesChooser.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/CapabilitiesImmutable.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/DefaultCapabilitiesChooser.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsConfiguration.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsDevice.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsScreen.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/GraphicsConfigurationFactory.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/MutableSurface.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/NativeSurface.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/NativeSurfaceHolder.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/NativeWindow.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowException.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/OffscreenLayerOption.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/OffscreenLayerSurface.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/ProxySurface.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/ScalableSurface.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/SurfaceUpdatedListener.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/ToolkitLock.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/UpstreamSurfaceHook.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/VisualIDHolder.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/WindowClosingProtocol.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/package.html
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/util/Dimension.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/util/DimensionImmutable.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/util/Insets.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/util/InsetsImmutable.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/util/PixelFormat.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/util/PixelFormatUtil.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/util/PixelRectangle.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/util/Point.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/util/PointImmutable.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/util/RectangleImmutable.java
create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/util/SurfaceSize.java
(limited to 'src/nativewindow/classes/com/jogamp/nativewindow')
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsConfiguration.java b/src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsConfiguration.java
new file mode 100644
index 000000000..684f1f86a
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsConfiguration.java
@@ -0,0 +1,81 @@
+/*
+ * 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 com.jogamp.nativewindow;
+
+/** A marker interface describing a graphics configuration, visual, or
+ pixel format in a toolkit-independent manner. */
+public interface AbstractGraphicsConfiguration extends VisualIDHolder, Cloneable {
+ public Object clone();
+
+ /**
+ * Return the screen this graphics configuration is valid for
+ */
+ public AbstractGraphicsScreen getScreen();
+
+ /**
+ * Return the capabilities reflecting this graphics configuration,
+ * which may differ from the capabilities used to choose this configuration.
+ *
+ * @return An immutable instance of the Capabilities to avoid mutation by
+ * the user.
+ */
+ public CapabilitiesImmutable getChosenCapabilities();
+
+ /**
+ * Return the capabilities used to choose this graphics configuration.
+ *
+ * These may be used to reconfigure the NativeWindow in case
+ * the device changes in a multiple screen environment.
+ *
+ * @return An immutable instance of the Capabilities to avoid mutation by
+ * the user.
+ */
+ public CapabilitiesImmutable getRequestedCapabilities();
+
+ /**
+ * In case the implementation utilizes a delegation pattern to wrap abstract toolkits,
+ * this method shall return the native {@link AbstractGraphicsConfiguration},
+ * otherwise this instance.
+ * @see NativeSurface#getGraphicsConfiguration()
+ */
+ public AbstractGraphicsConfiguration getNativeGraphicsConfiguration();
+}
+
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsDevice.java b/src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsDevice.java
new file mode 100644
index 000000000..7b630b1ea
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsDevice.java
@@ -0,0 +1,166 @@
+/*
+ * 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 com.jogamp.nativewindow;
+
+import jogamp.nativewindow.Debug;
+
+/** A interface describing a graphics device in a
+ toolkit-independent manner.
+ */
+public interface AbstractGraphicsDevice extends Cloneable {
+ public static final boolean DEBUG = Debug.debug("GraphicsDevice");
+
+ /** Dummy connection value for a default connection where no native support for multiple devices is available */
+ public static String DEFAULT_CONNECTION = "decon";
+
+ /** 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;
+
+ public Object clone();
+
+ /**
+ * Returns the type of the underlying subsystem, ie
+ * NativeWindowFactory.TYPE_KD, NativeWindowFactory.TYPE_X11, ..
+ */
+ public String getType();
+
+ /**
+ * Returns the semantic GraphicsDevice connection.
+ * On platforms supporting remote devices, eg via tcp/ip network,
+ * the implementation shall return a unique name for each remote address.
+ * On X11 for example, the connection string should be as the following example.
+ *
+ *
:0.0 for a local connection
+ *
remote.host.net:0.0 for a remote connection
+ *
+ *
+ * To support multiple local device, see {@link #getUnitID()}.
+ */
+ public String getConnection();
+
+ /**
+ * Returns the graphics device unit ID.
+ * The unit ID support multiple graphics device configurations
+ * on a local machine.
+ * To support remote device, see {@link #getConnection()}.
+ * @return
+ */
+ public int getUnitID();
+
+ /**
+ * Returns a unique ID object of this device using {@link #getType() type},
+ * {@link #getConnection() connection} and {@link #getUnitID() unitID} as it's key components.
+ *
+ * The unique ID does not reflect the instance of the device, hence the handle is not included.
+ * The unique ID may be used as a key for semantic device mapping.
+ *
+ *
+ * The returned string object reference is unique using {@link String#intern()}
+ * and hence can be used as a key itself.
+ *
+ */
+ public String getUniqueID();
+
+ /**
+ * Returns the native handle of the underlying native device,
+ * if such thing exist.
+ */
+ public long getHandle();
+
+ /**
+ * Optionally locking the device, utilizing eg {@link com.jogamp.nativewindow.ToolkitLock#lock()}.
+ * The lock implementation must be recursive.
+ */
+ public void lock();
+
+ /**
+ * Optionally unlocking the device, utilizing eg {@link com.jogamp.nativewindow.ToolkitLock#unlock()}.
+ * The lock implementation must be recursive.
+ *
+ * @throws RuntimeException in case the lock is not acquired by this thread.
+ */
+ public void unlock();
+
+ /**
+ * @throws RuntimeException if current thread does not hold the lock
+ */
+ public void validateLocked() throws RuntimeException;
+
+ /**
+ * Optionally [re]opening the device if handle is null.
+ *
+ * The default implementation is a NOP.
+ *
+ *
+ * Example implementations like {@link com.jogamp.nativewindow.x11.X11GraphicsDevice}
+ * or {@link com.jogamp.nativewindow.egl.EGLGraphicsDevice}
+ * issue the native open operation in case handle is null.
+ *
+ *
+ * @return true if the handle was null and opening was successful, otherwise false.
+ */
+ public boolean open();
+
+ /**
+ * Optionally closing the device if handle is not null.
+ *
+ * The default implementation {@link ToolkitLock#dispose() dispose} it's {@link ToolkitLock} and sets the handle to null.
+ *
+ *
+ * Example implementations like {@link com.jogamp.nativewindow.x11.X11GraphicsDevice}
+ * or {@link com.jogamp.nativewindow.egl.EGLGraphicsDevice}
+ * issue the native close operation or skip it depending on the {@link #isHandleOwner() handles's ownership}.
+ *
+ *
+ * @return true if the handle was not null and closing was successful, otherwise false.
+ */
+ public boolean close();
+
+ /**
+ * @return true if instance owns the handle to issue {@link #close()}, otherwise false.
+ */
+ public boolean isHandleOwner();
+
+ public void clearHandleOwner();
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsScreen.java b/src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsScreen.java
new file mode 100644
index 000000000..7767cf9e4
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsScreen.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2005 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.
+ *
+ * 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 com.jogamp.nativewindow;
+
+/** A interface describing a graphics screen in a
+ toolkit-independent manner.
+ */
+
+public interface AbstractGraphicsScreen extends Cloneable {
+ public Object clone();
+
+ /**
+ * Return the device this graphics configuration is valid for
+ */
+ public AbstractGraphicsDevice getDevice();
+
+ /** Returns the screen index this graphics screen is valid for
+ */
+ public int getIndex();
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/Capabilities.java b/src/nativewindow/classes/com/jogamp/nativewindow/Capabilities.java
new file mode 100644
index 000000000..fa172b201
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/Capabilities.java
@@ -0,0 +1,414 @@
+/*
+ * 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.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.jogamp.nativewindow;
+
+/** Specifies a set of capabilities that a window's rendering context
+ must support, such as color depth per channel. It currently
+ contains the minimal number of routines which allow configuration
+ on all supported window systems. */
+public class Capabilities implements CapabilitiesImmutable, Cloneable {
+ protected final static String na_str = "----" ;
+
+ private int redBits = 8;
+ private int greenBits = 8;
+ private int blueBits = 8;
+ private int alphaBits = 0;
+
+ // Support for transparent windows containing OpenGL content
+ private boolean backgroundOpaque = true;
+ private int transparentValueRed = 0;
+ private int transparentValueGreen = 0;
+ private int transparentValueBlue = 0;
+ private int transparentValueAlpha = 0;
+
+ // Switch for on- or offscreen
+ private boolean onscreen = true;
+
+ // offscreen bitmap mode
+ private boolean isBitmap = false;
+
+ /** Creates a Capabilities object. All attributes are in a default
+ state.
+ */
+ public Capabilities() {}
+
+ @Override
+ public Object cloneMutable() {
+ return clone();
+ }
+
+ @Override
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (final CloneNotSupportedException e) {
+ throw new NativeWindowException(e);
+ }
+ }
+
+ /**
+ * Copies all {@link Capabilities} values
+ * from source into this instance.
+ * @return this instance
+ */
+ public Capabilities copyFrom(final CapabilitiesImmutable other) {
+ redBits = other.getRedBits();
+ greenBits = other.getGreenBits();
+ blueBits = other.getBlueBits();
+ alphaBits = other.getAlphaBits();
+ backgroundOpaque = other.isBackgroundOpaque();
+ onscreen = other.isOnscreen();
+ isBitmap = other.isBitmap();
+ transparentValueRed = other.getTransparentRedValue();
+ transparentValueGreen = other.getTransparentGreenValue();
+ transparentValueBlue = other.getTransparentBlueValue();
+ transparentValueAlpha = other.getTransparentAlphaValue();
+ return this;
+ }
+
+ @Override
+ public int hashCode() {
+ // 31 * x == (x << 5) - x
+ int hash = 31 + this.redBits;
+ hash = ((hash << 5) - hash) + ( this.onscreen ? 1 : 0 );
+ hash = ((hash << 5) - hash) + ( this.isBitmap ? 1 : 0 );
+ hash = ((hash << 5) - hash) + this.greenBits;
+ hash = ((hash << 5) - hash) + this.blueBits;
+ hash = ((hash << 5) - hash) + this.alphaBits;
+ hash = ((hash << 5) - hash) + ( this.backgroundOpaque ? 1 : 0 );
+ hash = ((hash << 5) - hash) + this.transparentValueRed;
+ hash = ((hash << 5) - hash) + this.transparentValueGreen;
+ hash = ((hash << 5) - hash) + this.transparentValueBlue;
+ hash = ((hash << 5) - hash) + this.transparentValueAlpha;
+ return hash;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if(this == obj) { return true; }
+ if(!(obj instanceof CapabilitiesImmutable)) {
+ return false;
+ }
+ final CapabilitiesImmutable other = (CapabilitiesImmutable)obj;
+ boolean res = other.getRedBits()==redBits &&
+ other.getGreenBits()==greenBits &&
+ other.getBlueBits()==blueBits &&
+ other.getAlphaBits()==alphaBits &&
+ other.isBackgroundOpaque()==backgroundOpaque &&
+ other.isOnscreen()==onscreen &&
+ other.isBitmap()==isBitmap;
+ if(res && !backgroundOpaque) {
+ res = other.getTransparentRedValue()==transparentValueRed &&
+ other.getTransparentGreenValue()==transparentValueGreen &&
+ other.getTransparentBlueValue()==transparentValueBlue &&
+ other.getTransparentAlphaValue()==transparentValueAlpha;
+ }
+
+ return res;
+ }
+
+ /**
+ * Comparing RGBA values only
+ **/
+ @Override
+ public int compareTo(final CapabilitiesImmutable caps) {
+ /**
+ if ( ! ( o instanceof CapabilitiesImmutable ) ) {
+ Class> c = (null != o) ? o.getClass() : null ;
+ throw new ClassCastException("Not a CapabilitiesImmutable object, but " + c);
+ }
+ final CapabilitiesImmutable caps = (CapabilitiesImmutable) o; */
+
+ final int rgba = redBits * greenBits * blueBits * ( alphaBits + 1 );
+
+ final int xrgba = caps.getRedBits() * caps.getGreenBits() * caps.getBlueBits() * ( caps.getAlphaBits() + 1 );
+
+ if(rgba > xrgba) {
+ return 1;
+ } else if(rgba < xrgba) {
+ return -1;
+ }
+
+ return 0; // they are equal: RGBA
+ }
+
+ @Override
+ public int getVisualID(final VIDType type) throws NativeWindowException {
+ switch(type) {
+ case INTRINSIC:
+ case NATIVE:
+ return VisualIDHolder.VID_UNDEFINED;
+ default:
+ throw new NativeWindowException("Invalid type <"+type+">");
+ }
+ }
+
+ @Override
+ public final int getRedBits() {
+ return redBits;
+ }
+
+ /** Sets the number of bits requested for the color buffer's red
+ component. On some systems only the color depth, which is the
+ sum of the red, green, and blue bits, is considered. */
+ public void setRedBits(final int redBits) {
+ this.redBits = redBits;
+ }
+
+ @Override
+ public final int getGreenBits() {
+ return greenBits;
+ }
+
+ /** Sets the number of bits requested for the color buffer's green
+ component. On some systems only the color depth, which is the
+ sum of the red, green, and blue bits, is considered. */
+ public void setGreenBits(final int greenBits) {
+ this.greenBits = greenBits;
+ }
+
+ @Override
+ public final int getBlueBits() {
+ return blueBits;
+ }
+
+ /** Sets the number of bits requested for the color buffer's blue
+ component. On some systems only the color depth, which is the
+ sum of the red, green, and blue bits, is considered. */
+ public void setBlueBits(final int blueBits) {
+ this.blueBits = blueBits;
+ }
+
+ @Override
+ public final int getAlphaBits() {
+ return alphaBits;
+ }
+
+ /**
+ * Sets the number of bits requested for the color buffer's alpha
+ * component. On some systems only the color depth, which is the
+ * sum of the red, green, and blue bits, is considered.
+ *
+ * Note: If alpha bits are zero, they are set to one
+ * by {@link #setBackgroundOpaque(boolean)} and it's OpenGL specialization GLCapabilities::setSampleBuffers(boolean).
+ * Ensure to call this method after the above to ensure a zero value.
+ * The above automated settings takes into account, that the user calls this method to request alpha bits,
+ * not to reflect a current state. Nevertheless if this is the case - call it at last.
+ *
+ */
+ public void setAlphaBits(final int alphaBits) {
+ this.alphaBits = alphaBits;
+ }
+
+ /**
+ * Sets whether the surface shall be opaque or translucent.
+ *
+ * Platform implementations may need an alpha component in the surface (eg. Windows),
+ * or expect pre-multiplied alpha values (eg. X11/XRender).
+ * To unify the experience, this method also invokes {@link #setAlphaBits(int) setAlphaBits(1)}
+ * if {@link #getAlphaBits()} == 0.
+ * Please note that in case alpha is required on the platform the
+ * clear color shall have an alpha lower than 1.0 to allow anything shining through.
+ *
+ *
+ * Mind that translucency may cause a performance penalty
+ * due to the composite work required by the window manager.
+ *
+ */
+ public void setBackgroundOpaque(final boolean opaque) {
+ backgroundOpaque = opaque;
+ if(!opaque && getAlphaBits()==0) {
+ setAlphaBits(1);
+ }
+ }
+
+ @Override
+ public final boolean isBackgroundOpaque() {
+ return backgroundOpaque;
+ }
+
+ /**
+ * Sets whether the surface shall be on- or offscreen.
+ *
+ * Defaults to true.
+ *
+ *
+ * If requesting an offscreen surface without further selection of it's mode,
+ * e.g. FBO, Pbuffer or {@link #setBitmap(boolean) bitmap},
+ * the implementation will choose the best available offscreen mode.
+ *
+ * If enabled this method also invokes {@link #setOnscreen(int) setOnscreen(false)}.
+ *
+ *
+ * Defaults to false.
+ *
+ *
+ * Requesting offscreen bitmap mode disables the offscreen auto selection.
+ *
+ */
+ public void setBitmap(final boolean enable) {
+ if(enable) {
+ setOnscreen(false);
+ }
+ isBitmap = enable;
+ }
+
+ @Override
+ public boolean isBitmap() {
+ return isBitmap;
+ }
+
+ @Override
+ public final int getTransparentRedValue() { return transparentValueRed; }
+
+ @Override
+ public final int getTransparentGreenValue() { return transparentValueGreen; }
+
+ @Override
+ public final int getTransparentBlueValue() { return transparentValueBlue; }
+
+ @Override
+ public final int getTransparentAlphaValue() { return transparentValueAlpha; }
+
+ /** Sets the transparent red value for the frame buffer configuration,
+ ranging from 0 to the maximum frame buffer value for red.
+ This value is ignored if {@link #isBackgroundOpaque()} equals true.
+ It defaults to half of the frambuffer value for red.
+ A value of -1 is interpreted as any value. */
+ public void setTransparentRedValue(final int transValueRed) { transparentValueRed=transValueRed; }
+
+ /** Sets the transparent green value for the frame buffer configuration,
+ ranging from 0 to the maximum frame buffer value for green.
+ This value is ignored if {@link #isBackgroundOpaque()} equals true.
+ It defaults to half of the frambuffer value for green.
+ A value of -1 is interpreted as any value. */
+ public void setTransparentGreenValue(final int transValueGreen) { transparentValueGreen=transValueGreen; }
+
+ /** Sets the transparent blue value for the frame buffer configuration,
+ ranging from 0 to the maximum frame buffer value for blue.
+ This value is ignored if {@link #isBackgroundOpaque()} equals true.
+ It defaults to half of the frambuffer value for blue.
+ A value of -1 is interpreted as any value. */
+ public void setTransparentBlueValue(final int transValueBlue) { transparentValueBlue=transValueBlue; }
+
+ /** Sets the transparent alpha value for the frame buffer configuration,
+ ranging from 0 to the maximum frame buffer value for alpha.
+ This value is ignored if {@link #isBackgroundOpaque()} equals true.
+ It defaults to half of the frambuffer value for alpha.
+ A value of -1 is interpreted as any value. */
+ public void setTransparentAlphaValue(final int transValueAlpha) { transparentValueAlpha=transValueAlpha; }
+
+ @Override
+ public StringBuilder toString(final StringBuilder sink) {
+ return toString(sink, true);
+ }
+
+ /** Returns a textual representation of this Capabilities
+ object. */
+ @Override
+ public String toString() {
+ final StringBuilder msg = new StringBuilder();
+ msg.append("Caps[");
+ toString(msg);
+ msg.append("]");
+ return msg.toString();
+ }
+
+ /** Return a textual representation of this object's on/off screen state. Use the given StringBuilder [optional]. */
+ protected StringBuilder onoffScreenToString(StringBuilder sink) {
+ if(null == sink) {
+ sink = new StringBuilder();
+ }
+ if(onscreen) {
+ sink.append("on-scr");
+ } else {
+ sink.append("offscr[");
+ }
+ if(isBitmap) {
+ sink.append("bitmap");
+ } else if(onscreen) {
+ sink.append("."); // no additional off-screen modes besides on-screen
+ } else {
+ sink.append("auto-cfg"); // auto-config off-screen mode
+ }
+ sink.append("]");
+
+ return sink;
+ }
+
+ /** Element separator */
+ protected static final String ESEP = "/";
+ /** Component separator */
+ protected static final String CSEP = ", ";
+
+ protected StringBuilder toString(StringBuilder sink, final boolean withOnOffScreen) {
+ if(null == sink) {
+ sink = new StringBuilder();
+ }
+ sink.append("rgba ").append(redBits).append(ESEP).append(greenBits).append(ESEP).append(blueBits).append(ESEP).append(alphaBits);
+ if(backgroundOpaque) {
+ sink.append(", opaque");
+ } else {
+ sink.append(", trans-rgba 0x").append(toHexString(transparentValueRed)).append(ESEP).append(toHexString(transparentValueGreen)).append(ESEP).append(toHexString(transparentValueBlue)).append(ESEP).append(toHexString(transparentValueAlpha));
+ }
+ if(withOnOffScreen) {
+ sink.append(CSEP);
+ onoffScreenToString(sink);
+ }
+ return sink;
+ }
+
+ protected final String toHexString(final int val) { return Integer.toHexString(val); }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/CapabilitiesChooser.java b/src/nativewindow/classes/com/jogamp/nativewindow/CapabilitiesChooser.java
new file mode 100644
index 000000000..c33ff5a3f
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/CapabilitiesChooser.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * 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 com.jogamp.nativewindow;
+
+import java.util.List;
+
+/** Provides a mechanism by which applications can customize the
+ window type selection for a given {@link Capabilities}.
+ Developers can implement this interface and pass an instance into
+ the method {@link GraphicsConfigurationFactory#chooseGraphicsConfiguration}; the chooser
+ will be called at window creation time. */
+
+public interface CapabilitiesChooser {
+ /** Chooses the index (0..available.length - 1) of the {@link
+ Capabilities} most closely matching the desired one from the
+ list of all supported. Some of the entries in the
+ available array may be null; the chooser must
+ ignore these. The windowSystemRecommendedChoice
+ parameter may be provided to the chooser by the underlying
+ window system; if this index is valid, it is recommended, but
+ not necessarily required, that the chooser select that entry.
+
+
Note: this method is called automatically by the
+ {@link GraphicsConfigurationFactory#chooseGraphicsConfiguration} method
+ when an instance of this class is passed in to it.
+ It should generally not be
+ invoked by users directly, unless it is desired to delegate the
+ choice to some other CapabilitiesChooser object.
+ */
+ public int chooseCapabilities(CapabilitiesImmutable desired,
+ List extends CapabilitiesImmutable> available,
+ int windowSystemRecommendedChoice);
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/CapabilitiesImmutable.java b/src/nativewindow/classes/com/jogamp/nativewindow/CapabilitiesImmutable.java
new file mode 100644
index 000000000..780d537b8
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/CapabilitiesImmutable.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 com.jogamp.nativewindow;
+
+import com.jogamp.common.type.WriteCloneable;
+
+/**
+ * Specifies an immutable set of capabilities that a window's rendering context
+ * must support, such as color depth per channel.
+ *
+ * @see com.jogamp.nativewindow.Capabilities
+ */
+public interface CapabilitiesImmutable extends VisualIDHolder, WriteCloneable, Comparable {
+
+ /**
+ * Returns the number of bits for the color buffer's red
+ * component. On some systems only the color depth, which is the sum of the
+ * red, green, and blue bits, is considered.
+ */
+ int getRedBits();
+
+ /**
+ * Returns the number of bits for the color buffer's green
+ * component. On some systems only the color depth, which is the sum of the
+ * red, green, and blue bits, is considered.
+ */
+ int getGreenBits();
+
+ /**
+ * Returns the number of bits for the color buffer's blue
+ * component. On some systems only the color depth, which is the sum of the
+ * red, green, and blue bits, is considered.
+ */
+ int getBlueBits();
+
+ /**
+ * Returns the number of bits for the color buffer's alpha
+ * component. On some systems only the color depth, which is the sum of the
+ * red, green, and blue bits, is considered.
+ */
+ int getAlphaBits();
+
+ /**
+ * Returns whether an opaque or translucent surface is requested, supported or chosen.
+ *
+ * Default is true, i.e. opaque.
+ *
+ */
+ boolean isBackgroundOpaque();
+
+ /**
+ * Returns whether an on- or offscreen surface is requested, available or chosen.
+ *
+ * Default is true, i.e. onscreen.
+ *
+ *
+ * Mind that an capabilities intance w/ available semantics
+ * may show onscreen, but also the offscreen modes FBO, Pbuffer or {@link #setBitmap(boolean) bitmap}.
+ * This is valid, since one native configuration maybe used for either functionality.
+ *
+ */
+ boolean isOnscreen();
+
+ /**
+ * Returns whether bitmap offscreen mode is requested, available or chosen.
+ *
+ * Default is false.
+ *
+ *
+ * For chosen capabilities, only the selected offscreen surface is set to true.
+ *
+ */
+ boolean isBitmap();
+
+ /**
+ * Gets the transparent red value for the frame buffer configuration. This
+ * value is undefined if; equals true.
+ */
+ int getTransparentRedValue();
+
+ /**
+ * Gets the transparent green value for the frame buffer configuration. This
+ * value is undefined if; equals true.
+ */
+ int getTransparentGreenValue();
+
+ /**
+ * Gets the transparent blue value for the frame buffer configuration. This
+ * value is undefined if; equals true.
+ */
+ int getTransparentBlueValue();
+
+ /**
+ * Gets the transparent alpha value for the frame buffer configuration. This
+ * value is undefined if; equals true.
+ */
+ int getTransparentAlphaValue();
+
+ /** Equality over the immutable attributes of both objects */
+ @Override
+ boolean equals(Object obj);
+
+ /** hash code over the immutable attributes of both objects */
+ @Override
+ int hashCode();
+
+ /** Return a textual representation of this object. Use the given StringBuilder [optional]. */
+ StringBuilder toString(StringBuilder sink);
+
+ /** Returns a textual representation of this object. */
+ @Override
+ String toString();
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/DefaultCapabilitiesChooser.java b/src/nativewindow/classes/com/jogamp/nativewindow/DefaultCapabilitiesChooser.java
new file mode 100644
index 000000000..33c3f8458
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/DefaultCapabilitiesChooser.java
@@ -0,0 +1,172 @@
+/*
+ * 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.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.jogamp.nativewindow;
+
+import java.util.List;
+
+import com.jogamp.common.util.PropertyAccess;
+
+import jogamp.nativewindow.Debug;
+
+/**
The default implementation of the {@link
+ CapabilitiesChooser} interface, which provides consistent visual
+ selection behavior across platforms. The precise algorithm is
+ deliberately left loosely specified. Some properties are:
+
+
Attempts to match as closely as possible the given
+ Capabilities, but will select one with fewer capabilities (i.e.,
+ lower color depth) if necessary.
+
+
If there is no exact match, prefers a more-capable visual to
+ a less-capable one.
+
+
If there is more than one exact match, chooses an arbitrary
+ one.
+
+
If a valid windowSystemRecommendedChoice parameter is
+ supplied, chooses that instead of using the cross-platform code.
+
+
+*/
+
+public class DefaultCapabilitiesChooser implements CapabilitiesChooser {
+ private static final boolean DEBUG;
+
+ static {
+ Debug.initSingleton();
+ DEBUG = PropertyAccess.isPropertyDefined("nativewindow.debug.CapabilitiesChooser", true);
+ }
+
+ private final static int NO_SCORE = -9999999;
+ private final static int COLOR_MISMATCH_PENALTY_SCALE = 36;
+
+ @Override
+ public int chooseCapabilities(final CapabilitiesImmutable desired,
+ final List extends CapabilitiesImmutable> available,
+ final int windowSystemRecommendedChoice) {
+ if (DEBUG) {
+ System.err.println("Desired: " + desired);
+ for (int i = 0; i < available.size(); i++) {
+ System.err.println("Available " + i + ": " + available.get(i));
+ }
+ System.err.println("Window system's recommended choice: " + windowSystemRecommendedChoice);
+ }
+ final int availnum = available.size();
+
+ if (windowSystemRecommendedChoice >= 0 &&
+ windowSystemRecommendedChoice < availnum &&
+ null != available.get(windowSystemRecommendedChoice)) {
+ if (DEBUG) {
+ System.err.println("Choosing window system's recommended choice of " + windowSystemRecommendedChoice);
+ System.err.println(available.get(windowSystemRecommendedChoice));
+ }
+ return windowSystemRecommendedChoice;
+ }
+
+ // Create score array
+ final int[] scores = new int[availnum];
+ for (int i = 0; i < availnum; i++) {
+ scores[i] = NO_SCORE;
+ }
+ // Compute score for each
+ for (int i = 0; i < availnum; i++) {
+ final CapabilitiesImmutable cur = available.get(i);
+ if (cur == null) {
+ continue;
+ }
+ if (desired.isOnscreen() && !cur.isOnscreen()) {
+ continue; // requested onscreen, but n/a
+ }
+
+ int score = 0;
+ // Compute difference in color depth
+ score += (COLOR_MISMATCH_PENALTY_SCALE *
+ ((cur.getRedBits() + cur.getGreenBits() + cur.getBlueBits() + cur.getAlphaBits()) -
+ (desired.getRedBits() + desired.getGreenBits() + desired.getBlueBits() + desired.getAlphaBits())));
+ scores[i] = score;
+ }
+
+ if (DEBUG) {
+ System.err.print("Scores: [");
+ for (int i = 0; i < availnum; i++) {
+ if (i > 0) {
+ System.err.print(",");
+ }
+ System.err.print(" " + scores[i]);
+ }
+ System.err.println(" ]");
+ }
+
+ // Ready to select. Choose score closest to 0.
+ int scoreClosestToZero = NO_SCORE;
+ int chosenIndex = -1;
+ for (int i = 0; i < availnum; i++) {
+ final int score = scores[i];
+ if (score == NO_SCORE) {
+ continue;
+ }
+ // Don't substitute a positive score for a smaller negative score
+ if ((scoreClosestToZero == NO_SCORE) ||
+ (Math.abs(score) < Math.abs(scoreClosestToZero) &&
+ ((sign(scoreClosestToZero) < 0) || (sign(score) > 0)))) {
+ scoreClosestToZero = score;
+ chosenIndex = i;
+ }
+ }
+ if (chosenIndex < 0) {
+ throw new NativeWindowException("Unable to select one of the provided Capabilities");
+ }
+ if (DEBUG) {
+ System.err.println("Chosen index: " + chosenIndex);
+ System.err.println("Chosen capabilities:");
+ System.err.println(available.get(chosenIndex));
+ }
+
+ return chosenIndex;
+ }
+
+ private static int sign(final int score) {
+ if (score < 0) {
+ return -1;
+ }
+ return 1;
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsConfiguration.java b/src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsConfiguration.java
new file mode 100644
index 000000000..d20a6824d
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsConfiguration.java
@@ -0,0 +1,134 @@
+/*
+ * 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 com.jogamp.nativewindow;
+
+import jogamp.nativewindow.Debug;
+
+public class DefaultGraphicsConfiguration implements Cloneable, AbstractGraphicsConfiguration {
+ protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration");
+
+ private AbstractGraphicsScreen screen;
+ protected CapabilitiesImmutable capabilitiesChosen;
+ protected CapabilitiesImmutable capabilitiesRequested;
+
+ public DefaultGraphicsConfiguration(final AbstractGraphicsScreen screen,
+ final CapabilitiesImmutable capsChosen, final CapabilitiesImmutable capsRequested) {
+ if(null == screen) {
+ throw new IllegalArgumentException("Null screen");
+ }
+ if(null == capsChosen) {
+ throw new IllegalArgumentException("Null chosen caps");
+ }
+ if(null == capsRequested) {
+ throw new IllegalArgumentException("Null requested caps");
+ }
+ this.screen = screen;
+ this.capabilitiesChosen = capsChosen;
+ this.capabilitiesRequested = capsRequested;
+ }
+
+ @Override
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (final CloneNotSupportedException e) {
+ throw new NativeWindowException(e);
+ }
+ }
+
+ @Override
+ final public AbstractGraphicsScreen getScreen() {
+ return screen;
+ }
+
+ @Override
+ final public CapabilitiesImmutable getChosenCapabilities() {
+ return capabilitiesChosen;
+ }
+
+ @Override
+ final public CapabilitiesImmutable getRequestedCapabilities() {
+ return capabilitiesRequested;
+ }
+
+ @Override
+ public AbstractGraphicsConfiguration getNativeGraphicsConfiguration() {
+ return this;
+ }
+
+ @Override
+ final public int getVisualID(final VIDType type) throws NativeWindowException {
+ return capabilitiesChosen.getVisualID(type);
+ }
+
+ /**
+ * Set the capabilities to a new value.
+ *
+ *
+ * The use case for setting the Capabilities at a later time is
+ * a change or re-validation of capabilities.
+ *
+ * the use case for setting a new screen at a later time is
+ * a change of the graphics device in a multi-screen environment.
+ *
+ */
+ protected void setScreen(final AbstractGraphicsScreen screen) {
+ this.screen = screen;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName()+"[" + screen +
+ ",\n\tchosen " + capabilitiesChosen+
+ ",\n\trequested " + capabilitiesRequested+
+ "]";
+ }
+
+ public static String toHexString(final int val) {
+ return "0x"+Integer.toHexString(val);
+ }
+
+ public static String toHexString(final long val) {
+ return "0x"+Long.toHexString(val);
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsDevice.java b/src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsDevice.java
new file mode 100644
index 000000000..070b6bb28
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsDevice.java
@@ -0,0 +1,253 @@
+/*
+ * 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 com.jogamp.nativewindow;
+
+import jogamp.nativewindow.NativeWindowFactoryImpl;
+
+public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice {
+ private static final String separator = "_";
+ private final String type;
+ protected final String connection;
+ protected final int unitID;
+ protected final String uniqueID;
+ protected long handle;
+ protected ToolkitLock toolkitLock;
+
+ /**
+ * Create an instance with the system default {@link ToolkitLock},
+ * gathered via {@link NativeWindowFactory#getDefaultToolkitLock(String)}.
+ * @param type
+ */
+ public DefaultGraphicsDevice(final String type, final String connection, final int unitID) {
+ this(type, connection, unitID, 0, NativeWindowFactory.getDefaultToolkitLock(type));
+ }
+
+ /**
+ * Create an instance with the system default {@link ToolkitLock}.
+ * gathered via {@link NativeWindowFactory#getDefaultToolkitLock(String, long)}.
+ * @param type
+ * @param handle
+ */
+ public DefaultGraphicsDevice(final String type, final String connection, final int unitID, final long handle) {
+ this(type, connection, unitID, handle, NativeWindowFactory.getDefaultToolkitLock(type, handle));
+ }
+
+ /**
+ * Create an instance with the given {@link ToolkitLock} instance, or null {@link ToolkitLock} if null.
+ * @param type
+ * @param handle
+ * @param locker if null, a non blocking null lock is used.
+ */
+ public DefaultGraphicsDevice(final String type, final String connection, final int unitID, final long handle, final ToolkitLock locker) {
+ this.type = type;
+ this.connection = connection;
+ this.unitID = unitID;
+ this.uniqueID = getUniqueID(type, connection, unitID);
+ this.handle = handle;
+ this.toolkitLock = null != locker ? locker : NativeWindowFactoryImpl.getNullToolkitLock();
+ }
+
+ @Override
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (final CloneNotSupportedException e) {
+ throw new NativeWindowException(e);
+ }
+ }
+
+ @Override
+ public final String getType() {
+ return type;
+ }
+
+ @Override
+ public final String getConnection() {
+ return connection;
+ }
+
+ @Override
+ public final int getUnitID() {
+ return unitID;
+ }
+
+ @Override
+ public final String getUniqueID() {
+ return uniqueID;
+ }
+
+ @Override
+ public final long getHandle() {
+ return handle;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Locking is perfomed via delegation to {@link ToolkitLock#lock()}, {@link ToolkitLock#unlock()}.
+ *
+ * Locking is perfomed via delegation to {@link ToolkitLock#lock()}, {@link ToolkitLock#unlock()}.
+ *
+ *
+ * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long)
+ * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long, com.jogamp.nativewindow.ToolkitLock)
+ */
+ @Override
+ public final void unlock() {
+ toolkitLock.unlock();
+ }
+
+ @Override
+ public boolean open() {
+ return false;
+ }
+
+ @Override
+ public boolean close() {
+ toolkitLock.dispose();
+ if(0 != handle) {
+ handle = 0;
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isHandleOwner() {
+ return false;
+ }
+
+ @Override
+ public void clearHandleOwner() {
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName()+"[type "+getType()+", connection "+getConnection()+", unitID "+getUnitID()+", handle 0x"+Long.toHexString(getHandle())+", owner "+isHandleOwner()+", "+toolkitLock+"]";
+ }
+
+ /**
+ * Set the native handle of the underlying native device
+ * and return the previous one.
+ */
+ protected final long setHandle(final long newHandle) {
+ final long oldHandle = handle;
+ handle = newHandle;
+ return oldHandle;
+ }
+
+ protected Object getHandleOwnership() {
+ return null;
+ }
+ protected Object setHandleOwnership(final Object newOwnership) {
+ return null;
+ }
+
+ public static final void swapDeviceHandleAndOwnership(final DefaultGraphicsDevice aDevice1, final DefaultGraphicsDevice aDevice2) {
+ aDevice1.lock();
+ try {
+ aDevice2.lock();
+ try {
+ final long aDevice1Handle = aDevice1.getHandle();
+ final long aDevice2Handle = aDevice2.setHandle(aDevice1Handle);
+ aDevice1.setHandle(aDevice2Handle);
+ final Object aOwnership1 = aDevice1.getHandleOwnership();
+ final Object aOwnership2 = aDevice2.setHandleOwnership(aOwnership1);
+ aDevice1.setHandleOwnership(aOwnership2);
+ } finally {
+ aDevice2.unlock();
+ }
+ } finally {
+ aDevice1.unlock();
+ }
+ }
+
+ /**
+ * Set the internal ToolkitLock, which is used within the
+ * {@link #lock()} and {@link #unlock()} implementation.
+ *
+ *
+ * The current ToolkitLock is being locked/unlocked while swapping the reference,
+ * ensuring no concurrent access can occur during the swap.
+ *
+ *
+ * @param locker the ToolkitLock, if null, {@link jogamp.nativewindow.NullToolkitLock} is being used
+ * @return the previous ToolkitLock instance
+ */
+ protected ToolkitLock setToolkitLock(final ToolkitLock locker) {
+ final ToolkitLock _toolkitLock = toolkitLock;
+ _toolkitLock.lock();
+ try {
+ toolkitLock = ( null == locker ) ? NativeWindowFactoryImpl.getNullToolkitLock() : locker ;
+ } finally {
+ _toolkitLock.unlock();
+ }
+ return _toolkitLock;
+ }
+
+ /**
+ * @return the used ToolkitLock
+ *
+ * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long)
+ * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long, com.jogamp.nativewindow.ToolkitLock)
+ */
+ public final ToolkitLock getToolkitLock() {
+ return toolkitLock;
+ }
+
+ /**
+ * Returns a unique String object using {@link String#intern()} for the given arguments,
+ * which object reference itself can be used as a key.
+ */
+ private static String getUniqueID(final String type, final String connection, final int unitID) {
+ return (type + separator + connection + separator + unitID).intern();
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsScreen.java b/src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsScreen.java
new file mode 100644
index 000000000..63c79af55
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsScreen.java
@@ -0,0 +1,71 @@
+/*
+ * 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 com.jogamp.nativewindow;
+
+public class DefaultGraphicsScreen implements Cloneable, AbstractGraphicsScreen {
+ private final AbstractGraphicsDevice device;
+ private final int idx;
+
+ public DefaultGraphicsScreen(final AbstractGraphicsDevice device, final int idx) {
+ this.device = device;
+ this.idx = idx;
+ }
+
+ public static AbstractGraphicsScreen createDefault(final String type) {
+ return new DefaultGraphicsScreen(new DefaultGraphicsDevice(type, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT), 0);
+ }
+
+ @Override
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (final CloneNotSupportedException e) {
+ throw new NativeWindowException(e);
+ }
+ }
+
+ @Override
+ public AbstractGraphicsDevice getDevice() {
+ return device;
+ }
+
+ @Override
+ public int getIndex() {
+ return idx;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName()+"["+device+", idx "+idx+"]";
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/GraphicsConfigurationFactory.java
new file mode 100644
index 000000000..929af054e
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/GraphicsConfigurationFactory.java
@@ -0,0 +1,435 @@
+/*
+ * Copyright (c) 2008-2009 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 com.jogamp.nativewindow;
+
+import com.jogamp.common.ExceptionUtils;
+import com.jogamp.common.util.ReflectionUtil;
+
+import jogamp.nativewindow.Debug;
+import jogamp.nativewindow.DefaultGraphicsConfigurationFactoryImpl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Provides the mechanism by which the graphics configuration for a
+ * window can be chosen before the window is created. The graphics
+ * configuration decides parameters related to hardware accelerated rendering such
+ * as the OpenGL pixel format.
+ * On some window systems (EGL/OpenKODE and X11 in particular) it is necessary to
+ * choose the graphics configuration early at window creation time.
+ * Note that the selection of the graphics configuration is an algorithm which does not have
+ * strong dependencies on the particular Java window toolkit in use
+ * (e.g., AWT) and therefore it is strongly desirable to factor this
+ * functionality out of the core {@link NativeWindowFactory} so that
+ * new window toolkits can replace just the {@link
+ * NativeWindowFactory} and reuse the graphics configuration selection
+ * algorithm provided by, for example, an OpenGL binding.
+ */
+
+public abstract class GraphicsConfigurationFactory {
+ protected static final boolean DEBUG;
+
+ private static class DeviceCapsType {
+ public final Class> deviceType;
+ public final Class> capsType;
+ private final int hash32;
+
+ public DeviceCapsType(final Class> deviceType, final Class> capsType) {
+ this.deviceType = deviceType;
+ this.capsType = capsType;
+
+ // 31 * x == (x << 5) - x
+ int hash32 = 31 + deviceType.hashCode();
+ hash32 = ((hash32 << 5) - hash32) + capsType.hashCode();
+ this.hash32 = hash32;
+ }
+
+ @Override
+ public final int hashCode() {
+ return hash32;
+ }
+
+ @Override
+ public final boolean equals(final Object obj) {
+ if(this == obj) { return true; }
+ if (obj instanceof DeviceCapsType) {
+ final DeviceCapsType dct = (DeviceCapsType)obj;
+ return deviceType == dct.deviceType && capsType == dct.capsType;
+ }
+ return false;
+ }
+
+ @Override
+ public final String toString() {
+ return "DeviceCapsType["+deviceType.getName()+", "+capsType.getName()+"]";
+ }
+
+ }
+
+ private static final Map registeredFactories;
+ private static final DeviceCapsType defaultDeviceCapsType;
+ static boolean initialized = false;
+
+ static {
+ DEBUG = Debug.debug("GraphicsConfiguration");
+ if(DEBUG) {
+ System.err.println(Thread.currentThread().getName()+" - Info: GraphicsConfigurationFactory.");
+ // Thread.dumpStack();
+ }
+ registeredFactories = Collections.synchronizedMap(new HashMap());
+ defaultDeviceCapsType = new DeviceCapsType(AbstractGraphicsDevice.class, CapabilitiesImmutable.class);
+ }
+
+ public static synchronized void initSingleton() {
+ if(!initialized) {
+ initialized = true;
+
+ if(DEBUG) {
+ System.err.println(Thread.currentThread().getName()+" - GraphicsConfigurationFactory.initSingleton()");
+ }
+
+ // Register the default no-op factory for arbitrary
+ // AbstractGraphicsDevice implementations, including
+ // AWTGraphicsDevice instances -- the OpenGL binding will take
+ // care of handling AWTGraphicsDevices on X11 platforms (as
+ // well as X11GraphicsDevices in non-AWT situations)
+ registerFactory(defaultDeviceCapsType.deviceType, defaultDeviceCapsType.capsType, new DefaultGraphicsConfigurationFactoryImpl());
+
+ if (NativeWindowFactory.TYPE_X11 == NativeWindowFactory.getNativeWindowType(true)) {
+ try {
+ ReflectionUtil.callStaticMethod("jogamp.nativewindow.x11.X11GraphicsConfigurationFactory",
+ "registerFactory", null, null, GraphicsConfigurationFactory.class.getClassLoader());
+ } catch (final Exception e) {
+ throw new RuntimeException(e);
+ }
+ if(NativeWindowFactory.isAWTAvailable()) {
+ try {
+ ReflectionUtil.callStaticMethod("jogamp.nativewindow.x11.awt.X11AWTGraphicsConfigurationFactory",
+ "registerFactory", null, null, GraphicsConfigurationFactory.class.getClassLoader());
+ } catch (final Exception e) { /* n/a */ }
+ }
+ }
+ }
+ }
+
+ public static synchronized void shutdown() {
+ if(initialized) {
+ initialized = false;
+ if(DEBUG) {
+ System.err.println(Thread.currentThread().getName()+" - GraphicsConfigurationFactory.shutdown()");
+ }
+ registeredFactories.clear();
+ }
+ }
+
+ protected static String getThreadName() {
+ return Thread.currentThread().getName();
+ }
+
+ protected static String toHexString(final int val) {
+ return "0x" + Integer.toHexString(val);
+ }
+
+ protected static String toHexString(final long val) {
+ return "0x" + Long.toHexString(val);
+ }
+
+ /** Creates a new NativeWindowFactory instance. End users do not
+ need to call this method. */
+ protected GraphicsConfigurationFactory() {
+ }
+
+ /**
+ * Returns the graphics configuration factory for use with the
+ * given device and capability.
+ *
+ * @see #getFactory(Class, Class)
+ */
+ public static GraphicsConfigurationFactory getFactory(final AbstractGraphicsDevice device, final CapabilitiesImmutable caps) {
+ if (device == null) {
+ throw new IllegalArgumentException("null device");
+ }
+ if (caps == null) {
+ throw new IllegalArgumentException("null caps");
+ }
+ return getFactory(device.getClass(), caps.getClass());
+ }
+
+ /**
+ * Returns the graphics configuration factory for use with the
+ * given device and capability class.
+ *
+ * Note: Registered device types maybe classes or interfaces, where capabilities types are interfaces only.
+ *
+ *
+ *
+ * Pseudo code for finding a suitable factory is:
+ *
+ For-All devT := getTopDownDeviceTypes(deviceType)
+ For-All capsT := getTopDownCapabilitiesTypes(capabilitiesType)
+ f = factory.get(devT, capsT);
+ if(f) { return f; }
+ end
+ end
+ *
+ *
+ *
+ * @param deviceType the minimum capabilities class type accepted, must implement or extend {@link AbstractGraphicsDevice}
+ * @param capabilitiesType the minimum capabilities class type accepted, must implement or extend {@link CapabilitiesImmutable}
+ *
+ * @throws IllegalArgumentException if the deviceType does not implement {@link AbstractGraphicsDevice} or
+ * capabilitiesType does not implement {@link CapabilitiesImmutable}
+ */
+ public static GraphicsConfigurationFactory getFactory(final Class> deviceType, final Class> capabilitiesType)
+ throws IllegalArgumentException, NativeWindowException
+ {
+ if (!(defaultDeviceCapsType.deviceType.isAssignableFrom(deviceType))) {
+ throw new IllegalArgumentException("Given class must implement AbstractGraphicsDevice");
+ }
+ if (!(defaultDeviceCapsType.capsType.isAssignableFrom(capabilitiesType))) {
+ throw new IllegalArgumentException("Given capabilities class must implement CapabilitiesImmutable");
+ }
+ if(DEBUG) {
+ ExceptionUtils.dumpStack(System.err);
+ System.err.println("GraphicsConfigurationFactory.getFactory: "+deviceType.getName()+", "+capabilitiesType.getName());
+ dumpFactories();
+ }
+
+ final List> deviceTypes = getAllAssignableClassesFrom(defaultDeviceCapsType.deviceType, deviceType, false);
+ if(DEBUG) {
+ System.err.println("GraphicsConfigurationFactory.getFactory() deviceTypes: " + deviceTypes);
+ }
+ final List> capabilitiesTypes = getAllAssignableClassesFrom(defaultDeviceCapsType.capsType, capabilitiesType, true);
+ if(DEBUG) {
+ System.err.println("GraphicsConfigurationFactory.getFactory() capabilitiesTypes: " + capabilitiesTypes);
+ }
+ for(int j=0; j interfaceDevice = deviceTypes.get(j);
+ for(int i=0; i interfaceCaps = capabilitiesTypes.get(i);
+ final DeviceCapsType dct = new DeviceCapsType(interfaceDevice, interfaceCaps);
+ final GraphicsConfigurationFactory factory = registeredFactories.get(dct);
+ if (factory != null) {
+ if(DEBUG) {
+ System.err.println("GraphicsConfigurationFactory.getFactory() found "+dct+" -> "+factory);
+ }
+ return factory;
+ }
+ }
+ }
+ // Return the default
+ final GraphicsConfigurationFactory factory = registeredFactories.get(defaultDeviceCapsType);
+ if(DEBUG) {
+ System.err.println("GraphicsConfigurationFactory.getFactory() DEFAULT "+defaultDeviceCapsType+" -> "+factory);
+ }
+ return factory;
+ }
+ private static ArrayList> getAllAssignableClassesFrom(final Class> superClassOrInterface, final Class> fromClass, final boolean interfacesOnly) {
+ // Using a todo list avoiding a recursive loop!
+ final ArrayList> inspectClasses = new ArrayList>();
+ final ArrayList> resolvedInterfaces = new ArrayList>();
+ inspectClasses.add(fromClass);
+ for(int j=0; j clazz = inspectClasses.get(j);
+ getAllAssignableClassesFrom(superClassOrInterface, clazz, interfacesOnly, resolvedInterfaces, inspectClasses);
+ }
+ return resolvedInterfaces;
+ }
+ private static void getAllAssignableClassesFrom(final Class> superClassOrInterface, final Class> fromClass, final boolean interfacesOnly, final List> resolvedInterfaces, final List> inspectClasses) {
+ final ArrayList> types = new ArrayList>();
+ if( superClassOrInterface.isAssignableFrom(fromClass) && !resolvedInterfaces.contains(fromClass)) {
+ if( !interfacesOnly || fromClass.isInterface() ) {
+ types.add(fromClass);
+ }
+ }
+ types.addAll(Arrays.asList(fromClass.getInterfaces()));
+
+ for(int i=0; i iface = types.get(i);
+ if( superClassOrInterface.isAssignableFrom(iface) && !resolvedInterfaces.contains(iface) ) {
+ resolvedInterfaces.add(iface);
+ if( !superClassOrInterface.equals(iface) && !inspectClasses.contains(iface) ) {
+ inspectClasses.add(iface); // safe add to todo list, avoiding a recursive nature
+ }
+ }
+ }
+ final Class> parentClass = fromClass.getSuperclass();
+ if( null != parentClass && superClassOrInterface.isAssignableFrom(parentClass) && !inspectClasses.contains(parentClass) ) {
+ inspectClasses.add(parentClass); // safe add to todo list, avoiding a recursive nature
+ }
+ }
+ private static void dumpFactories() {
+ final Set dcts = registeredFactories.keySet();
+ int i=0;
+ for(final Iterator iter = dcts.iterator(); iter.hasNext(); ) {
+ final DeviceCapsType dct = iter.next();
+ System.err.println("Factory #"+i+": "+dct+" -> "+registeredFactories.get(dct));
+ i++;
+ }
+ }
+
+ /**
+ * Registers a GraphicsConfigurationFactory handling
+ * the given graphics device and capability class.
+ *
+ * This does not need to be called by end users, only implementors of new
+ * GraphicsConfigurationFactory subclasses.
+ *
+ *
+ *
+ * Note: Registered device types maybe classes or interfaces, where capabilities types are interfaces only.
+ *
+ *
+ *
See {@link #getFactory(Class, Class)} for a description of the find algorithm.
+ *
+ * @param deviceType the minimum capabilities class type accepted, must implement or extend interface {@link AbstractGraphicsDevice}
+ * @param capabilitiesType the minimum capabilities class type accepted, must extend interface {@link CapabilitiesImmutable}
+ * @return the previous registered factory, or null if none
+ * @throws IllegalArgumentException if the given class does not implement AbstractGraphicsDevice
+ */
+ protected static GraphicsConfigurationFactory registerFactory(final Class> abstractGraphicsDeviceImplementor, final Class> capabilitiesType, final GraphicsConfigurationFactory factory)
+ throws IllegalArgumentException
+ {
+ if (!(defaultDeviceCapsType.deviceType.isAssignableFrom(abstractGraphicsDeviceImplementor))) {
+ throw new IllegalArgumentException("Given device class must implement AbstractGraphicsDevice");
+ }
+ if (!(defaultDeviceCapsType.capsType.isAssignableFrom(capabilitiesType))) {
+ throw new IllegalArgumentException("Given capabilities class must implement CapabilitiesImmutable");
+ }
+ final DeviceCapsType dct = new DeviceCapsType(abstractGraphicsDeviceImplementor, capabilitiesType);
+ final GraphicsConfigurationFactory prevFactory;
+ if(null == factory) {
+ prevFactory = registeredFactories.remove(dct);
+ if(DEBUG) {
+ System.err.println("GraphicsConfigurationFactory.registerFactory() remove "+dct+
+ ", deleting: "+prevFactory);
+ }
+ } else {
+ prevFactory = registeredFactories.put(dct, factory);
+ if(DEBUG) {
+ System.err.println("GraphicsConfigurationFactory.registerFactory() put "+dct+" -> "+factory+
+ ", overridding: "+prevFactory);
+ }
+ }
+ return prevFactory;
+ }
+
+ /**
+ *
Selects a graphics configuration on the specified graphics
+ * device compatible with the supplied {@link Capabilities}. Some
+ * platforms (e.g.: X11, EGL, KD) require the graphics configuration
+ * to be specified when the native window is created.
+ * These architectures have seperated their device, screen, window and drawable
+ * context and hence are capable of quering the capabilities for each screen.
+ * A fully established window is not required.
+ *
+ *
Other platforms (e.g. Windows, MacOSX) don't offer the mentioned seperation
+ * and hence need a fully established window and it's drawable.
+ * Here the validation of the capabilities is performed later.
+ * In this case, the AbstractGraphicsConfiguration implementation
+ * must allow an overwrite of the Capabilites, for example
+ * {@link DefaultGraphicsConfiguration#setChosenCapabilities DefaultGraphicsConfiguration.setChosenCapabilities(..)}.
+ *
+ *
+ *
+ * This method is mainly intended to be both used and implemented by the
+ * OpenGL binding.
+ *
+ *
The concrete data type of the passed graphics device and
+ * returned graphics configuration must be specified in the
+ * documentation binding this particular API to the underlying
+ * window toolkit. The Reference Implementation accepts {@link
+ * com.jogamp.nativewindow.awt.AWTGraphicsDevice AWTGraphicsDevice} objects and returns {@link
+ * com.jogamp.nativewindow.awt.AWTGraphicsConfiguration AWTGraphicsConfiguration} objects. On
+ * X11 platforms where the AWT is not in use, it also accepts
+ * {@link com.jogamp.nativewindow.x11.X11GraphicsDevice
+ * X11GraphicsDevice} objects and returns {@link
+ * com.jogamp.nativewindow.x11.X11GraphicsConfiguration
+ * X11GraphicsConfiguration} objects.
+ *
+ * @param capsChosen the intermediate chosen capabilities to be refined by this implementation, may be equal to capsRequested
+ * @param capsRequested the original requested capabilities
+ * @param chooser the choosing implementation
+ * @param screen the referring Screen
+ * @param nativeVisualID if not {@link VisualIDHolder#VID_UNDEFINED} it reflects a pre-chosen visualID of the native platform's windowing system.
+ * @return the complete GraphicsConfiguration
+ *
+ * @throws IllegalArgumentException if the data type of the passed
+ * AbstractGraphicsDevice is not supported by this
+ * NativeWindowFactory.
+ * @throws NativeWindowException if any window system-specific errors caused
+ * the selection of the graphics configuration to fail.
+ *
+ * @see com.jogamp.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen)
+ * @see com.jogamp.nativewindow.DefaultGraphicsConfiguration#setChosenCapabilities(Capabilities caps)
+ */
+ public final AbstractGraphicsConfiguration
+ chooseGraphicsConfiguration(final CapabilitiesImmutable capsChosen, final CapabilitiesImmutable capsRequested,
+ final CapabilitiesChooser chooser,
+ final AbstractGraphicsScreen screen, final int nativeVisualID)
+ throws IllegalArgumentException, NativeWindowException {
+ if(null==capsChosen) {
+ throw new NativeWindowException("Chosen Capabilities are null");
+ }
+ if(null==capsRequested) {
+ throw new NativeWindowException("Requested Capabilities are null");
+ }
+ if(null==screen) {
+ throw new NativeWindowException("Screen is null");
+ }
+ final AbstractGraphicsDevice device = screen.getDevice();
+ if(null==device) {
+ throw new NativeWindowException("Screen's Device is null");
+ }
+ device.lock();
+ try {
+ return chooseGraphicsConfigurationImpl(capsChosen, capsRequested, chooser, screen, nativeVisualID);
+ } finally {
+ device.unlock();
+ }
+ }
+
+ protected abstract AbstractGraphicsConfiguration
+ chooseGraphicsConfigurationImpl(CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested,
+ CapabilitiesChooser chooser, AbstractGraphicsScreen screen, int nativeVisualID)
+ throws IllegalArgumentException, NativeWindowException;
+
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/MutableSurface.java b/src/nativewindow/classes/com/jogamp/nativewindow/MutableSurface.java
new file mode 100644
index 000000000..7686f270b
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/MutableSurface.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright 2012 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 com.jogamp.nativewindow;
+
+/**
+ * Provides a {@link NativeSurface} with a mutable surfaceHandle
+ * via {@link #setSurfaceHandle(long)}.
+ *
+ * @see NativeSurface
+ */
+public interface MutableSurface extends NativeSurface {
+
+ /**
+ * Sets the surface handle which is created outside of this implementation.
+ */
+ public void setSurfaceHandle(long surfaceHandle);
+}
+
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/NativeSurface.java b/src/nativewindow/classes/com/jogamp/nativewindow/NativeSurface.java
new file mode 100644
index 000000000..ce0699c56
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/NativeSurface.java
@@ -0,0 +1,238 @@
+/**
+ * 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 com.jogamp.nativewindow;
+
+/**
+ * Provides low-level information required for
+ * hardware-accelerated rendering using a surface in a platform-independent manner.
+ *
+ * All values of this interface are represented in pixel units, if not stated otherwise.
+ * See {@link NativeWindow}.
+ *
+ *
+ * A NativeSurface created for a particular on- or offscreen component is
+ * expected to have the same lifetime as that component. As long as
+ * the component is alive and realized/visible, NativeSurface must be able
+ * provide information such as the surface handle while it is locked.
+ *
+ */
+public interface NativeSurface extends SurfaceUpdatedListener {
+ /** Unlocked state, {@value}. */
+ public static final int LOCK_SURFACE_UNLOCKED = 0;
+
+ /** Returned by {@link #lockSurface()} if the surface is not ready to be locked, {@value}. */
+ public static final int LOCK_SURFACE_NOT_READY = 1;
+
+ /** Returned by {@link #lockSurface()} if the surface is locked, but has changed, {@value}. */
+ public static final int LOCK_SURFACE_CHANGED = 2;
+
+ /** Returned by {@link #lockSurface()} if the surface is locked, and is unchanged, {@value}. */
+ public static final int LOCK_SUCCESS = 3;
+
+ /**
+ * Lock the surface of this native window.
+ *
+ * The surface handle shall be valid after a successfull call,
+ * ie return a value other than {@link #LOCK_SURFACE_UNLOCKED} and {@link #LOCK_SURFACE_NOT_READY},
+ * which is
+ *
+ * boolean ok = LOCK_SURFACE_NOT_READY < lockSurface();
+ *
+ *
+ *
+ * The caller may need to take care of the result {@link #LOCK_SURFACE_CHANGED},
+ * where the surface handle is valid but has changed.
+ *
+ *
+ * This call is blocking until the surface has been locked
+ * or a timeout is reached. The latter will throw a runtime exception.
+ *
+ *
+ * This call allows recursion from the same thread.
+ *
+ *
+ * The implementation may want to aquire the
+ * application level {@link com.jogamp.common.util.locks.RecursiveLock}
+ * first before proceeding with a native surface lock.
+ *
+ *
+ * The implementation shall also invoke {@link AbstractGraphicsDevice#lock()}
+ * for the initial lock (recursive count zero).
+ *
+ *
+ * @return {@link #LOCK_SUCCESS}, {@link #LOCK_SURFACE_CHANGED} or {@link #LOCK_SURFACE_NOT_READY}.
+ *
+ * @throws RuntimeException after timeout when waiting for the surface lock
+ * @throws NativeWindowException if native locking failed, maybe platform related
+ *
+ * @see com.jogamp.common.util.locks.RecursiveLock
+ */
+ public int lockSurface() throws NativeWindowException, RuntimeException;
+
+ /**
+ * Unlock the surface of this native window
+ *
+ * Shall not modify the surface handle, see {@link #lockSurface()}
+ *
+ * The implementation shall also invoke {@link AbstractGraphicsDevice#unlock()}
+ * for the final unlock (recursive count zero).
+ *
+ * The implementation shall be fail safe, i.e. tolerant in case the native resources
+ * are already released / unlocked. In this case the implementation shall simply ignore the call.
+ *
+ * @see #lockSurface
+ * @see com.jogamp.common.util.locks.RecursiveLock
+ */
+ public void unlockSurface();
+
+ /**
+ * Query if surface is locked by another thread, i.e. not the current one.
+ *
+ * Convenient shortcut for:
+ *
+ * final Thread o = getSurfaceLockOwner();
+ * if( null != o && Thread.currentThread() != o ) { .. }
+ *
+ */
+ public boolean isSurfaceLockedByOtherThread();
+
+ /**
+ * Return the locking owner's Thread, or null if not locked.
+ */
+ public Thread getSurfaceLockOwner();
+
+ /**
+ * Provide a mechanism to utilize custom (pre-) swap surface
+ * code. This method is called before the render toolkit (e.g. JOGL)
+ * swaps the buffer/surface if double buffering is enabled.
+ *
+ * The implementation may itself apply the swapping,
+ * in which case true shall be returned.
+ *
+ *
+ * @return true if this method completed swapping the surface,
+ * otherwise false, in which case eg the GLDrawable
+ * implementation has to swap the code.
+ */
+ public boolean surfaceSwap();
+
+ /** Appends the given {@link SurfaceUpdatedListener} to the end of the list. */
+ public void addSurfaceUpdatedListener(SurfaceUpdatedListener l);
+
+ /**
+ * Inserts the given {@link SurfaceUpdatedListener} at the
+ * specified position in the list.
+ *
+ * @param index Position where the listener will be inserted.
+ * Should be within (0 <= index && index <= size()).
+ * An index value of -1 is interpreted as the end of the list, size().
+ * @param l The listener object to be inserted
+ * @throws IndexOutOfBoundsException If the index is not within (0 <= index && index <= size()), or -1
+ */
+ public void addSurfaceUpdatedListener(int index, SurfaceUpdatedListener l) throws IndexOutOfBoundsException;
+
+ /** Remove the specified {@link SurfaceUpdatedListener} from the list. */
+ public void removeSurfaceUpdatedListener(SurfaceUpdatedListener l);
+
+ /**
+ * Returns the handle to the surface for this NativeSurface.
+ *
+ * The surface handle should be set/update by {@link #lockSurface()},
+ * where {@link #unlockSurface()} is not allowed to modify it.
+ * After {@link #unlockSurface()} it is no more guaranteed
+ * that the surface handle is still valid.
+ *
+ * The surface handle shall reflect the platform one
+ * for all drawable surface operations, e.g. opengl, swap-buffer.
+ *
+ * On X11 this returns an entity of type Window,
+ * since there is no differentiation of surface and window there.
+ * On Microsoft Windows this returns an entity of type HDC.
+ */
+ public long getSurfaceHandle();
+
+ /**
+ * Returns the width of the client area excluding insets (window decorations) in pixel units.
+ * @return width of the client area in pixel units
+ * @see NativeWindow#getWidth()
+ * @see #convertToWindowUnits(int[])
+ */
+ public int getSurfaceWidth();
+
+ /**
+ * Returns the height of the client area excluding insets (window decorations) in pixel units.
+ * @return height of the client area in pixel units
+ * @see NativeWindow#getHeight()
+ * @see #convertToWindowUnits(int[])
+ */
+ public int getSurfaceHeight();
+
+ /**
+ * Converts the given pixel units into window units in place.
+ * @param pixelUnitsAndResult int[2] storage holding the pixel units for the x- and y-coord to convert
+ * and the resulting values.
+ * @return result int[2] storage pixelUnitsAndResult for chaining holding the converted values
+ * @see ScalableSurface
+ */
+ public int[] convertToWindowUnits(final int[] pixelUnitsAndResult);
+
+ /**
+ * Converts the given window units into pixel units in place.
+ * @param windowUnitsAndResult int[2] storage holding the window units for the x- and y-coord to convert
+ * and the resulting values.
+ * @return result int[2] storage windowUnitsAndResult for chaining holding the converted values
+ * @see ScalableSurface
+ */
+ public int[] convertToPixelUnits(final int[] windowUnitsAndResult);
+
+ /**
+ * Returns the graphics configuration corresponding to this window.
+ *
+ * In case the implementation utilizes a delegation pattern to wrap abstract toolkits,
+ * this method shall return the native {@link AbstractGraphicsConfiguration} via {@link AbstractGraphicsConfiguration#getNativeGraphicsConfiguration()}.
+ *
+ * @see AbstractGraphicsConfiguration#getNativeGraphicsConfiguration()
+ * @see com.jogamp.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen)
+ */
+ public AbstractGraphicsConfiguration getGraphicsConfiguration();
+
+ /**
+ * Convenience: Get display handle from
+ * AbstractGraphicsConfiguration . AbstractGraphicsScreen . AbstractGraphicsDevice
+ */
+ public long getDisplayHandle();
+
+ /**
+ * Convenience: Get display handle from
+ * AbstractGraphicsConfiguration . AbstractGraphicsScreen
+ */
+ public int getScreenIndex();
+
+}
+
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/NativeSurfaceHolder.java b/src/nativewindow/classes/com/jogamp/nativewindow/NativeSurfaceHolder.java
new file mode 100644
index 000000000..667f5d8af
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/NativeSurfaceHolder.java
@@ -0,0 +1,41 @@
+/**
+ * Copyright 2014 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 com.jogamp.nativewindow;
+
+/**
+ * Accessor interface for implementing classes with ownership of a {@link NativeSurface}
+ * via an is-a or has-a relation.
+ */
+public interface NativeSurfaceHolder {
+ /**
+ * Returns the associated {@link NativeSurface} of this {@link NativeSurfaceHolder}.
+ */
+ public NativeSurface getNativeSurface();
+}
+
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindow.java
new file mode 100644
index 000000000..1a2d212da
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindow.java
@@ -0,0 +1,204 @@
+/*
+ * 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.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.jogamp.nativewindow;
+
+import com.jogamp.nativewindow.util.InsetsImmutable;
+import com.jogamp.nativewindow.util.Point;
+
+/**
+ * Extend the {@link NativeSurface} interface with windowing
+ * information such as {@link #getWindowHandle() window-handle},
+ * {@link #getWidth() window-size} and {@link #getX() window-position}.
+ *
+ * All values of this interface are represented in window units, if not stated otherwise.
+ * See {@link NativeSurface}.
+ *
Abstract screen space has it's origin in the top-left corner, and may not be at 0/0.
+ *
Window origin is in it's top-left corner, see {@link #getX()} and {@link #getY()}.
+ *
Window client-area excludes {@link #getInsets() insets}, i.e. window decoration.
+ *
Window origin is relative to it's parent window if exist, or the screen position (top-level).
+ *
+ *
+ *
+ * A window toolkit such as the AWT may either implement this interface
+ * directly with one of its components, or provide and register an
+ * implementation of {@link NativeWindowFactory NativeWindowFactory}
+ * which can create NativeWindow objects for its components.
+ *
+ * Returns this instance, which is-a {@link NativeSurface}.
+ *
+ */
+ @Override
+ public NativeSurface getNativeSurface();
+
+ /**
+ * Destroys this window incl. releasing all related resources.
+ */
+ public void destroy();
+
+ /**
+ * @return The parent NativeWindow, or null if this NativeWindow is top level.
+ */
+ public NativeWindow getParent();
+
+ /**
+ * Returns the window handle for this NativeWindow.
+ *
+ * The window handle shall reflect the platform one
+ * for all window related operations, e.g. open, close, resize.
+ *
+ * On X11 this returns an entity of type Window.
+ * On Microsoft Windows this returns an entity of type HWND.
+ */
+ public long getWindowHandle();
+
+ /**
+ * Returns the insets defined as the width and height of the window decoration
+ * on the left, right, top and bottom in window units.
+ *
+ * Insets are zero if the window is undecorated, including child windows.
+ *
+ *
+ *
+ * Insets are available only after the native window has been created,
+ * ie. the native window has been made visible.
+ *
+ * The top-level window area's top-left corner is located at
+ *
+ *
+ * @return insets
+ */
+ public InsetsImmutable getInsets();
+
+ /** Returns the current x position of this window, relative to it's parent. */
+
+ /**
+ * Returns the x position of the top-left corner
+ * of the client area relative to it's parent in window units.
+ *
+ * If no parent exist (top-level window), this coordinate equals the screen coordinate.
+ *
+ *
+ * Since the position reflects the client area, it does not include the insets.
+ *
+ * @see #getInsets()
+ * @see #getLocationOnScreen(Point)
+ */
+ public int getX();
+
+ /**
+ * Returns the current y position of the top-left corner
+ * of the client area relative to it's parent in window units.
+ *
+ * If no parent exist (top-level window), this coordinate equals the screen coordinate.
+ *
+ *
+ * Since the position reflects the client area, it does not include the insets.
+ *
+ * @see #getInsets()
+ * @see #getLocationOnScreen(Point)
+ */
+ public int getY();
+
+ /**
+ * Returns the width of the client area excluding insets (window decorations) in window units.
+ * @return width of the client area in window units
+ * @see NativeSurface#getSurfaceWidth()
+ */
+ public int getWidth();
+
+ /**
+ * Returns the height of the client area excluding insets (window decorations) in window units.
+ * @return height of the client area in window units
+ * @see NativeSurface#getSurfaceHeight()
+ */
+ public int getHeight();
+
+ /**
+ * Returns the window's top-left client-area position in the screen.
+ *
+ * If {@link Point} is not null, it is translated about the resulting screen position
+ * and returned.
+ *
+ * Since the position reflects the client area, it does not include the insets.
+ *
+ * @param point Optional {@link Point} storage.
+ * If not null, null, it is translated about the resulting screen position
+ * and returned.
+ * @see #getX()
+ * @see #getY()
+ * @see #getInsets()
+ */
+ public Point getLocationOnScreen(Point point);
+
+ /** Returns true if this native window owns the focus, otherwise false. */
+ boolean hasFocus();
+
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowException.java b/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowException.java
new file mode 100644
index 000000000..8f841e7ea
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowException.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2003 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.
+ *
+ * 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 com.jogamp.nativewindow;
+
+/** A generic exception for OpenGL errors used throughout the binding
+ as a substitute for {@link RuntimeException}. */
+
+public class NativeWindowException extends RuntimeException {
+ /** Constructs a NativeWindowException object. */
+ public NativeWindowException() {
+ super();
+ }
+
+ /** Constructs a NativeWindowException object with the specified detail
+ message. */
+ public NativeWindowException(final String message) {
+ super(message);
+ }
+
+ /** Constructs a NativeWindowException object with the specified detail
+ message and root cause. */
+ public NativeWindowException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ /** Constructs a NativeWindowException object with the specified root
+ cause. */
+ public NativeWindowException(final Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java
new file mode 100644
index 000000000..cba3a9214
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java
@@ -0,0 +1,716 @@
+/*
+ * Copyright (c) 2008-2009 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 com.jogamp.nativewindow;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.jogamp.nativewindow.util.PointImmutable;
+
+import jogamp.common.os.PlatformPropsImpl;
+import jogamp.nativewindow.Debug;
+import jogamp.nativewindow.NativeWindowFactoryImpl;
+import jogamp.nativewindow.ToolkitProperties;
+import jogamp.nativewindow.ResourceToolkitLock;
+import jogamp.nativewindow.WrappedWindow;
+import jogamp.nativewindow.macosx.OSXUtil;
+import jogamp.nativewindow.windows.GDIUtil;
+import jogamp.nativewindow.x11.X11Lib;
+
+import com.jogamp.common.os.Platform;
+import com.jogamp.common.util.PropertyAccess;
+import com.jogamp.common.util.ReflectionUtil;
+import com.jogamp.nativewindow.UpstreamWindowHookMutableSizePos;
+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;
+
+/** Provides a pluggable mechanism for arbitrary window toolkits to
+ adapt their components to the {@link NativeWindow} interface,
+ which provides a platform-independent mechanism of accessing the
+ information required to perform operations like
+ hardware-accelerated rendering using the OpenGL API. */
+
+public abstract class NativeWindowFactory {
+ protected static final boolean DEBUG;
+
+ /** OpenKODE/EGL type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}.*/
+ public static final String TYPE_EGL = ".egl".intern();
+
+ /** Microsoft Windows type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}. */
+ public static final String TYPE_WINDOWS = ".windows".intern();
+
+ /** X11 type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}. */
+ public static final String TYPE_X11 = ".x11".intern();
+
+ /** Broadcom VC IV/EGL type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}. */
+ public static final String TYPE_BCM_VC_IV = ".bcm.vc.iv".intern();
+
+ /** Android/EGL type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}.*/
+ public static final String TYPE_ANDROID = ".android".intern();
+
+ /** Mac OS X type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}. */
+ public static final String TYPE_MACOSX = ".macosx".intern();
+
+ /** Generic AWT type, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}. */
+ public static final String TYPE_AWT = ".awt".intern();
+
+ /** Generic DEFAULT type, where platform implementation don't care, as retrieved with {@link #getNativeWindowType(boolean)}. String is canonical via {@link String#intern()}. */
+ public static final String TYPE_DEFAULT = ".default".intern();
+
+ private static final String nativeWindowingTypePure; // canonical String via String.intern()
+ private static final String nativeWindowingTypeCustom; // canonical String via String.intern()
+
+ private static NativeWindowFactory defaultFactory;
+ private static Map, NativeWindowFactory> registeredFactories;
+
+ private static Class> nativeWindowClass;
+ private static boolean isAWTAvailable;
+
+ private static final String JAWTUtilClassName = "jogamp.nativewindow.jawt.JAWTUtil" ;
+ /** {@link jogamp.nativewindow.x11.X11Util} implements {@link ToolkitProperties}. */
+ private static final String X11UtilClassName = "jogamp.nativewindow.x11.X11Util";
+ /** {@link jogamp.nativewindow.macosx.OSXUtil} implements {@link ToolkitProperties}. */
+ private static final String OSXUtilClassName = "jogamp.nativewindow.macosx.OSXUtil";
+ /** {@link jogamp.nativewindow.windows.GDIUtil} implements {@link ToolkitProperties}. */
+ private static final String GDIClassName = "jogamp.nativewindow.windows.GDIUtil";
+
+ private static ToolkitLock jawtUtilJAWTToolkitLock;
+
+ private static boolean requiresToolkitLock;
+ private static boolean desktopHasThreadingIssues;
+
+ // Shutdown hook mechanism for the factory
+ private static volatile boolean isJVMShuttingDown = false;
+ private static final List customShutdownHooks = new ArrayList();
+
+ /** Creates a new NativeWindowFactory instance. End users do not
+ need to call this method. */
+ protected NativeWindowFactory() {
+ }
+
+ private static final boolean guessBroadcomVCIV() {
+ return AccessController.doPrivileged(new PrivilegedAction() {
+ private final File vcliblocation = new File(
+ "/opt/vc/lib/libbcm_host.so");
+ @Override
+ public Boolean run() {
+ if ( vcliblocation.isFile() ) {
+ return Boolean.TRUE;
+ }
+ return Boolean.FALSE;
+ }
+ } ).booleanValue();
+ }
+
+ private static String _getNativeWindowingType() {
+ switch(PlatformPropsImpl.OS_TYPE) {
+ case ANDROID:
+ return TYPE_ANDROID;
+ case MACOS:
+ return TYPE_MACOSX;
+ case WINDOWS:
+ return TYPE_WINDOWS;
+ case OPENKODE:
+ return TYPE_EGL;
+
+ case LINUX:
+ case FREEBSD:
+ case SUNOS:
+ case HPUX:
+ default:
+ if( guessBroadcomVCIV() ) {
+ return TYPE_BCM_VC_IV;
+ }
+ return TYPE_X11;
+ }
+ }
+
+ static {
+ final boolean[] _DEBUG = new boolean[] { false };
+ final String[] _tmp = new String[] { null };
+
+ AccessController.doPrivileged(new PrivilegedAction