summaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/DefaultGraphicsConfigurationFactoryImpl.java (renamed from src/nativewindow/classes/com/jogamp/nativewindow/impl/GraphicsConfigurationFactoryImpl.java)2
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java1
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/ProxySurface.java19
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/awt/AWTMisc.java96
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTUtil.java30
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/Win32SunJDKReflection.java117
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11SunJDKReflection.java24
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/windows/RegisteredClass.java44
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/windows/RegisteredClassFactory.java133
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java3
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/Capabilities.java60
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java4
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/CapabilitiesImmutable.java3
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java34
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java22
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java3
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java4
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java24
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java151
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/WindowClosingProtocol.java66
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java3
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java3
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/awt/AWTWindowClosingProtocol.java138
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java4
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java13
-rw-r--r--src/nativewindow/native/NativewindowCommon.c57
-rw-r--r--src/nativewindow/native/NativewindowCommon.h15
-rw-r--r--src/nativewindow/native/windows/GDImisc.c204
-rw-r--r--src/nativewindow/native/x11/Xmisc.c82
29 files changed, 1127 insertions, 232 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/GraphicsConfigurationFactoryImpl.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/DefaultGraphicsConfigurationFactoryImpl.java
index c53f4c88b..f77454fac 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/GraphicsConfigurationFactoryImpl.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/DefaultGraphicsConfigurationFactoryImpl.java
@@ -35,7 +35,7 @@ package com.jogamp.nativewindow.impl;
import javax.media.nativewindow.*;
-public class GraphicsConfigurationFactoryImpl extends GraphicsConfigurationFactory {
+public class DefaultGraphicsConfigurationFactoryImpl extends GraphicsConfigurationFactory {
protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl(
CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested, CapabilitiesChooser chooser, AbstractGraphicsScreen screen) {
return new DefaultGraphicsConfiguration(screen, capsChosen, capsRequested);
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java
index 34f5d6267..860be6f95 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java
@@ -34,7 +34,6 @@ package com.jogamp.nativewindow.impl;
import com.jogamp.common.util.*;
import java.lang.reflect.*;
-import java.security.*;
import javax.media.nativewindow.*;
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/ProxySurface.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/ProxySurface.java
index de766acbf..e0ad95e1f 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/ProxySurface.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/ProxySurface.java
@@ -47,14 +47,21 @@ import com.jogamp.common.util.locks.RecursiveLock;
public class ProxySurface implements NativeSurface, SurfaceChangeable {
private RecursiveLock recurLock = new RecursiveLock();
- protected int width, height, scrnIndex;
- protected long surfaceHandle, displayHandle;
protected AbstractGraphicsConfiguration config;
+ protected long displayHandle;
+ protected long surfaceHandle;
+ protected int scrnIndex;
+ protected int width, height;
public ProxySurface(AbstractGraphicsConfiguration cfg) {
+ this(cfg, 0);
+ }
+
+ public ProxySurface(AbstractGraphicsConfiguration cfg, long handle) {
invalidate();
config = cfg;
displayHandle=cfg.getScreen().getDevice().getHandle();
+ surfaceHandle=handle;
scrnIndex=cfg.getScreen().getIndex();
}
@@ -96,6 +103,14 @@ public class ProxySurface implements NativeSurface, SurfaceChangeable {
recurLock.unlock();
}
+ public final void validateSurfaceLocked() {
+ recurLock.validateLocked();
+ }
+
+ public final int getSurfaceRecursionCount() {
+ return recurLock.getRecursionCount();
+ }
+
public final boolean isSurfaceLockedByOtherThread() {
return recurLock.isLockedByOtherThread();
}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/awt/AWTMisc.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/awt/AWTMisc.java
new file mode 100644
index 000000000..c61ae5531
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/awt/AWTMisc.java
@@ -0,0 +1,96 @@
+/**
+ * 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.impl.awt;
+
+import java.awt.Window;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Frame;
+import javax.swing.JFrame;
+import javax.swing.WindowConstants;
+
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.WindowClosingProtocol;
+import javax.swing.MenuSelectionManager;
+
+public class AWTMisc {
+
+ public static final JFrame getJFrame(Component c) {
+ while (c != null && !(c instanceof JFrame)) {
+ c = c.getParent();
+ }
+ return (JFrame) c;
+ }
+
+ public static final Frame getFrame(Component c) {
+ while (c != null && !(c instanceof Frame)) {
+ c = c.getParent();
+ }
+ return (Frame) c;
+ }
+
+ public static final Window getWindow(Component c) {
+ while (c != null && !(c instanceof Window)) {
+ c = c.getParent();
+ }
+ return (Window) c;
+ }
+
+ public static final Container getContainer(Component c) {
+ while (c != null && !(c instanceof Container)) {
+ c = c.getParent();
+ }
+ return (Container) c;
+ }
+
+ /**
+ * Issue this when your non AWT toolkit gains focus to clear AWT menu path
+ */
+ public static final void clearAWTMenus() {
+ MenuSelectionManager.defaultManager().clearSelectedPath();
+ }
+
+ public final static int AWT2NWClosingOperation(int awtClosingOperation) {
+ switch (awtClosingOperation) {
+ case WindowConstants.DISPOSE_ON_CLOSE:
+ case WindowConstants.EXIT_ON_CLOSE:
+ return WindowClosingProtocol.DISPOSE_ON_CLOSE;
+ case WindowConstants.DO_NOTHING_ON_CLOSE:
+ case WindowConstants.HIDE_ON_CLOSE:
+ return WindowClosingProtocol.DO_NOTHING_ON_CLOSE;
+ default:
+ throw new NativeWindowException("Unhandled AWT Closing Operation: " + awtClosingOperation);
+ }
+ }
+
+ public final static int getNWClosingOperation(Component c) {
+ JFrame jf = getJFrame(c);
+ int op = (null != jf) ? jf.getDefaultCloseOperation() : WindowConstants.DO_NOTHING_ON_CLOSE ;
+ return AWT2NWClosingOperation(op);
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTUtil.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTUtil.java
index 9f120e9ab..0c6fc3f55 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTUtil.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTUtil.java
@@ -1,5 +1,6 @@
/*
* 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
@@ -37,13 +38,17 @@
package com.jogamp.nativewindow.impl.jawt;
import com.jogamp.nativewindow.impl.*;
+import java.awt.EventQueue;
import javax.media.nativewindow.*;
import java.awt.GraphicsEnvironment;
+import java.awt.Toolkit;
import java.lang.reflect.*;
import java.security.*;
+import java.util.ArrayList;
+import java.util.Map;
public class JAWTUtil {
protected static final boolean DEBUG = Debug.debug("JAWT");
@@ -110,10 +115,35 @@ public class JAWTUtil {
jawtToolkitLock = new JAWTToolkitLock();
+ // trigger native AWT toolkit / properties initialization
+ Map desktophints = null;
+ try {
+ if(EventQueue.isDispatchThread()) {
+ desktophints = (Map)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints"));
+ } else {
+ final ArrayList desktophintsBucket = new ArrayList(1);
+ EventQueue.invokeAndWait(new Runnable() {
+ public void run() {
+ Map _desktophints = (Map)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints"));
+ if(null!=_desktophints) {
+ desktophintsBucket.add(_desktophints);
+ }
+ }
+ });
+ desktophints = ( desktophintsBucket.size() > 0 ) ? (Map)desktophintsBucket.get(0) : null ;
+ }
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ } catch (InvocationTargetException ex) {
+ ex.printStackTrace();
+ }
+
if (DEBUG) {
System.err.println("JAWTUtil: Has sun.awt.SunToolkit.awtLock/awtUnlock " + hasSunToolkitAWTLock);
System.err.println("JAWTUtil: Has Java2D " + j2dExist);
System.err.println("JAWTUtil: Is headless " + headlessMode);
+ int hints = ( null != desktophints ) ? desktophints.size() : 0 ;
+ System.err.println("JAWTUtil: AWT Desktop hints " + hints);
}
}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/Win32SunJDKReflection.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/Win32SunJDKReflection.java
new file mode 100644
index 000000000..05d31a40e
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/Win32SunJDKReflection.java
@@ -0,0 +1,117 @@
+/*
+ * 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.impl.jawt.windows;
+
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.awt.AWTGraphicsConfiguration;
+
+/** This class encapsulates the reflection routines necessary to peek
+ inside a few data structures in the AWT implementation on X11 for
+ the purposes of correctly enumerating the available visuals. */
+
+public class Win32SunJDKReflection {
+ private static Class win32GraphicsDeviceClass;
+ private static Class win32GraphicsConfigClass;
+ private static Method win32GraphicsConfigGetConfigMethod;
+ private static Method win32GraphicsConfigGetVisualMethod;
+ private static boolean initted;
+
+ static {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ try {
+ win32GraphicsDeviceClass = Class.forName("sun.awt.Win32GraphicsDevice");
+ win32GraphicsConfigClass = Class.forName("sun.awt.Win32GraphicsConfig");
+ win32GraphicsConfigGetConfigMethod = win32GraphicsConfigClass.getDeclaredMethod("getConfig", new Class[] { win32GraphicsDeviceClass, int.class });
+ win32GraphicsConfigGetConfigMethod.setAccessible(true);
+ win32GraphicsConfigGetVisualMethod = win32GraphicsConfigClass.getDeclaredMethod("getVisual", new Class[] {});
+ win32GraphicsConfigGetVisualMethod.setAccessible(true);
+ initted = true;
+ } catch (Exception e) {
+ // Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5
+ }
+ return null;
+ }
+ });
+ }
+
+ public static GraphicsConfiguration graphicsConfigurationGet(GraphicsDevice device, int pfdID) {
+ if (!initted) {
+ return null;
+ }
+
+ try {
+ return (GraphicsConfiguration) win32GraphicsConfigGetConfigMethod.invoke(null, new Object[] { device, new Integer(pfdID) });
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static int graphicsConfigurationGetPixelFormatID(AbstractGraphicsConfiguration config) {
+ try {
+ if (config instanceof AWTGraphicsConfiguration) {
+ return graphicsConfigurationGetPixelFormatID(((AWTGraphicsConfiguration) config).getGraphicsConfiguration());
+ }
+ return 0;
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ public static int graphicsConfigurationGetPixelFormatID(GraphicsConfiguration config) {
+ if (!initted) {
+ return 0;
+ }
+
+ try {
+ return ((Integer) win32GraphicsConfigGetVisualMethod.invoke(config, null)).intValue();
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11SunJDKReflection.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11SunJDKReflection.java
index 081975afb..b4a99624c 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11SunJDKReflection.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11SunJDKReflection.java
@@ -1,5 +1,6 @@
/*
* 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
@@ -39,12 +40,12 @@
package com.jogamp.nativewindow.impl.jawt.x11;
-import com.jogamp.nativewindow.impl.x11.*;
-
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
-import java.lang.reflect.*;
-import java.security.*;
+
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.awt.AWTGraphicsConfiguration;
@@ -55,7 +56,6 @@ import javax.media.nativewindow.awt.AWTGraphicsConfiguration;
public class X11SunJDKReflection {
private static Class x11GraphicsDeviceClass;
- private static Method x11GraphicsDeviceGetScreenMethod;
private static Method x11GraphicsDeviceGetDisplayMethod;
private static Class x11GraphicsConfigClass;
private static Method x11GraphicsConfigGetVisualMethod;
@@ -66,8 +66,6 @@ public class X11SunJDKReflection {
public Object run() {
try {
x11GraphicsDeviceClass = Class.forName("sun.awt.X11GraphicsDevice");
- x11GraphicsDeviceGetScreenMethod = x11GraphicsDeviceClass.getDeclaredMethod("getScreen", new Class[] {});
- x11GraphicsDeviceGetScreenMethod.setAccessible(true);
x11GraphicsDeviceGetDisplayMethod = x11GraphicsDeviceClass.getDeclaredMethod("getDisplay", new Class[] {});
x11GraphicsDeviceGetDisplayMethod.setAccessible(true);
@@ -83,18 +81,6 @@ public class X11SunJDKReflection {
});
}
- public static int graphicsDeviceGetScreen(GraphicsDevice device) {
- if (!initted) {
- return 0;
- }
-
- try {
- return ((Integer) x11GraphicsDeviceGetScreenMethod.invoke(device, null)).intValue();
- } catch (Exception e) {
- return 0;
- }
- }
-
public static long graphicsDeviceGetDisplay(GraphicsDevice device) {
if (!initted) {
return 0;
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/windows/RegisteredClass.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/windows/RegisteredClass.java
new file mode 100644
index 000000000..a30a81948
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/windows/RegisteredClass.java
@@ -0,0 +1,44 @@
+/**
+ * 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.impl.windows;
+
+public class RegisteredClass {
+ long hInstance;
+ String className;
+
+ RegisteredClass(long hInst, String name) {
+ hInstance = hInst;
+ className = name;
+ }
+
+ public final long getHandle() { return hInstance; }
+ public final String getName() { return className; }
+
+ public final String toString() { return "RegisteredClass[handle 0x"+Long.toHexString(hInstance)+", "+className+"]"; }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/windows/RegisteredClassFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/windows/RegisteredClassFactory.java
new file mode 100644
index 000000000..d04640747
--- /dev/null
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/windows/RegisteredClassFactory.java
@@ -0,0 +1,133 @@
+/**
+ * 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.impl.windows;
+
+import com.jogamp.nativewindow.impl.Debug;
+import java.util.ArrayList;
+import javax.media.nativewindow.NativeWindowException;
+
+public class RegisteredClassFactory {
+ static final boolean DEBUG = Debug.debug("RegisteredClass");
+ private static ArrayList sharedClasses = new ArrayList();
+ private String classBaseName;
+ long wndProc;
+
+ private RegisteredClass sharedClass = null;
+ private int classIter = 0;
+ private int sharedRefCount = 0;
+ private Object sync = new Object();
+
+ /**
+ * Intended for a JVM shutdown hook, hence little synchronization
+ */
+ public static void shutdownSharedClasses() {
+ synchronized(sharedClasses) {
+ for(int i=0; i<sharedClasses.size(); i++) {
+ RegisteredClass sc = (RegisteredClass) sharedClasses.get(i);
+ GDI.DestroyWindowClass(sc.getHandle(), sc.getName());
+ if(DEBUG) {
+ System.err.println("RegisteredClassFactory shutdownSharedClasses "+i+"/"+sharedClasses.size()+": "+sc);
+ }
+ }
+ sharedClasses.clear();
+ }
+ }
+
+ public RegisteredClassFactory(String classBaseName, long wndProc) {
+ this.classBaseName = classBaseName;
+ this.wndProc = wndProc;
+ }
+
+ public RegisteredClass getSharedClass() throws NativeWindowException {
+ synchronized(sync) {
+ if( 0 == sharedRefCount ) {
+ if( null != sharedClass ) {
+ throw new InternalError("Error ("+sharedRefCount+"): SharedClass not null: "+sharedClass);
+ }
+ long hInstance = GDI.GetApplicationHandle();
+ if( 0 == hInstance ) {
+ throw new NativeWindowException("Error: Null ModuleHandle for Application");
+ }
+ String clazzName = null;
+ boolean registered = false;
+ while ( !registered && Integer.MAX_VALUE >= classIter ) {
+ // Retry with next clazz name, this could happen if more than one JVM is running
+ clazzName = classBaseName + classIter;
+ classIter++;
+ registered = GDI.CreateWindowClass(hInstance, clazzName, wndProc);
+ }
+ if( !registered ) {
+ throw new NativeWindowException("Error: Could not create WindowClass: "+clazzName);
+ }
+ sharedClass = new RegisteredClass(hInstance, clazzName);
+ synchronized(sharedClasses) {
+ sharedClasses.add(sharedClass);
+ }
+ if(DEBUG) {
+ System.err.println("RegisteredClassFactory getSharedClass ("+sharedRefCount+") initialized: "+sharedClass);
+ }
+ } else if ( null == sharedClass ) {
+ throw new InternalError("Error ("+sharedRefCount+"): SharedClass is null");
+ }
+ sharedRefCount++;
+ }
+ return sharedClass;
+ }
+
+ public void releaseSharedClass() {
+ synchronized(sync) {
+ if( 0 == sharedRefCount ) {
+ if( null != sharedClass ) {
+ throw new InternalError("Error ("+sharedRefCount+"): SharedClass not null: "+sharedClass);
+ }
+ return;
+ }
+ sharedRefCount--;
+ if( null == sharedClass ) {
+ throw new InternalError("Error ("+sharedRefCount+"): SharedClass is null");
+ }
+ if( 0 == sharedRefCount ) {
+ GDI.DestroyWindowClass(sharedClass.getHandle(), sharedClass.getName());
+ synchronized(sharedClasses) {
+ sharedClasses.remove(sharedClass);
+ }
+ if(DEBUG) {
+ System.err.println("RegisteredClassFactory releaseSharedClass ("+sharedRefCount+") released: "+sharedClass);
+ }
+ sharedClass = null;
+ sharedRefCount = 0;
+ classIter = 0;
+ }
+ }
+ }
+
+ public int getSharedRefCount() {
+ return sharedRefCount;
+ }
+}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java
index f3b7f4a4e..c56f632d8 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java
@@ -34,10 +34,11 @@
package com.jogamp.nativewindow.impl.x11;
import com.jogamp.common.util.LongObjectHashMap;
+import com.jogamp.nativewindow.impl.Debug;
+import com.jogamp.nativewindow.impl.NWJNILibLoader;
import javax.media.nativewindow.*;
-import com.jogamp.nativewindow.impl.*;
import java.nio.Buffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
diff --git a/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java
index e844c4f3e..79d69c703 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java
@@ -44,7 +44,7 @@ package javax.media.nativewindow;
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 {
+public class Capabilities implements CapabilitiesImmutable, Cloneable, Comparable {
private int redBits = 8;
private int greenBits = 8;
private int blueBits = 8;
@@ -114,6 +114,30 @@ public class Capabilities implements CapabilitiesImmutable, Cloneable {
return res;
}
+ /** comparing RGBA values only */
+ public int compareTo(Object o) {
+ if ( ! ( o instanceof Capabilities ) ) {
+ Class c = (null != o) ? o.getClass() : null ;
+ throw new ClassCastException("Not a Capabilities object: " + c);
+ }
+
+ final Capabilities caps = (Capabilities) o;
+
+ final int a = ( alphaBits > 0 ) ? alphaBits : 1;
+ final int rgba = redBits * greenBits * blueBits * a;
+
+ final int xa = ( caps.alphaBits ) > 0 ? caps.alphaBits : 1;
+ final int xrgba = caps.redBits * caps.greenBits * caps.blueBits * xa;
+
+ if(rgba > xrgba) {
+ return 1;
+ } else if(rgba < xrgba) {
+ return -1;
+ }
+
+ return 0; // they are equal: RGBA
+ }
+
/** Returns 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. */
@@ -274,25 +298,31 @@ public class Capabilities implements CapabilitiesImmutable, Cloneable {
A value of -1 is interpreted as any value. */
public void setTransparentAlphaValue(int transValueAlpha) { transparentValueAlpha=transValueAlpha; }
+ public StringBuffer toString(StringBuffer sink) {
+ if(null == sink) {
+ sink = new StringBuffer();
+ }
+ if(onscreen) {
+ sink.append("on-scr");
+ } else {
+ sink.append("offscr");
+ }
+ sink.append(", rgba ").append(redBits).append("/").append(greenBits).append("/").append(blueBits).append("/").append(alphaBits);
+ if(backgroundOpaque) {
+ sink.append(", opaque");
+ } else {
+ sink.append(", trans-rgba 0x").append(Integer.toHexString(transparentValueRed)).append("/").append(Integer.toHexString(transparentValueGreen)).append("/").append(Integer.toHexString(transparentValueBlue)).append("/").append(Integer.toHexString(transparentValueAlpha));
+ }
+ return sink;
+ }
/** Returns a textual representation of this Capabilities
object. */
public String toString() {
StringBuffer msg = new StringBuffer();
- msg.append("Capabilities[");
- msg.append("Onscreen: "+ onscreen +
- ", Red: " + redBits +
- ", Green: " + greenBits +
- ", Blue: " + blueBits +
- ", Alpha: " + alphaBits +
- ", Opaque: " + backgroundOpaque);
- if(!backgroundOpaque) {
- msg.append(", Transparent RGBA: [0x"+ Integer.toHexString(transparentValueRed)+
- " 0x"+ Integer.toHexString(transparentValueGreen)+
- " 0x"+ Integer.toHexString(transparentValueBlue)+
- " 0x"+ Integer.toHexString(transparentValueAlpha)+"] ");
- }
- msg.append("]");
+ msg.append("Caps[");
+ toString(msg);
+ msg.append("]");
return msg.toString();
}
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java
index 94b0f68af..a306363dc 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java
@@ -39,6 +39,8 @@
package javax.media.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
@@ -63,6 +65,6 @@ public interface CapabilitiesChooser {
choice to some other CapabilitiesChooser object.
*/
public int chooseCapabilities(CapabilitiesImmutable desired,
- CapabilitiesImmutable[] available,
+ List /*<CapabilitiesImmutable>*/ available,
int windowSystemRecommendedChoice);
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesImmutable.java b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesImmutable.java
index 72828b9f0..3aae8c8fb 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesImmutable.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesImmutable.java
@@ -109,6 +109,9 @@ public interface CapabilitiesImmutable extends WriteCloneable {
/** hash code over the immutable attributes of both objects */
int hashCode();
+ /** Return a textual representation of this object. Use the given StringBuffer [optional]. */
+ StringBuffer toString(StringBuffer sink);
+
/** Returns a textual representation of this object. */
String toString();
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java
index 856c29420..b43db8292 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java
@@ -1,5 +1,6 @@
/*
* 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
@@ -39,6 +40,8 @@
package javax.media.nativewindow;
+import java.util.List;
+
/** <P> The default implementation of the {@link
CapabilitiesChooser} interface, which provides consistent visual
selection behavior across platforms. The precise algorithm is
@@ -63,37 +66,38 @@ package javax.media.nativewindow;
public class DefaultCapabilitiesChooser implements CapabilitiesChooser {
private static final boolean DEBUG = false; // FIXME: Debug.debug("DefaultCapabilitiesChooser");
- public int chooseCapabilities(CapabilitiesImmutable desired,
- CapabilitiesImmutable[] available,
- int windowSystemRecommendedChoice) {
+ public int chooseCapabilities(final CapabilitiesImmutable desired,
+ final List /*<CapabilitiesImmutable>*/ available,
+ final int windowSystemRecommendedChoice) {
if (DEBUG) {
System.err.println("Desired: " + desired);
- for (int i = 0; i < available.length; i++) {
- System.err.println("Available " + i + ": " + available[i]);
+ 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 < available.length &&
- available[windowSystemRecommendedChoice] != null) {
+ windowSystemRecommendedChoice < availnum &&
+ null != available.get(windowSystemRecommendedChoice)) {
if (DEBUG) {
System.err.println("Choosing window system's recommended choice of " + windowSystemRecommendedChoice);
- System.err.println(available[windowSystemRecommendedChoice]);
+ System.err.println(available.get(windowSystemRecommendedChoice));
}
return windowSystemRecommendedChoice;
}
// Create score array
- int[] scores = new int[available.length];
+ int[] scores = new int[availnum];
int NO_SCORE = -9999999;
int COLOR_MISMATCH_PENALTY_SCALE = 36;
- for (int i = 0; i < scores.length; i++) {
+ for (int i = 0; i < availnum; i++) {
scores[i] = NO_SCORE;
}
// Compute score for each
- for (int i = 0; i < scores.length; i++) {
- CapabilitiesImmutable cur = available[i];
+ for (int i = 0; i < availnum; i++) {
+ CapabilitiesImmutable cur = (CapabilitiesImmutable) available.get(i);
if (cur == null) {
continue;
}
@@ -107,7 +111,7 @@ public class DefaultCapabilitiesChooser implements CapabilitiesChooser {
if (DEBUG) {
System.err.print("Scores: [");
- for (int i = 0; i < available.length; i++) {
+ for (int i = 0; i < availnum; i++) {
if (i > 0) {
System.err.print(",");
}
@@ -119,7 +123,7 @@ public class DefaultCapabilitiesChooser implements CapabilitiesChooser {
// Ready to select. Choose score closest to 0.
int scoreClosestToZero = NO_SCORE;
int chosenIndex = -1;
- for (int i = 0; i < scores.length; i++) {
+ for (int i = 0; i < availnum; i++) {
int score = scores[i];
if (score == NO_SCORE) {
continue;
@@ -138,7 +142,7 @@ public class DefaultCapabilitiesChooser implements CapabilitiesChooser {
if (DEBUG) {
System.err.println("Chosen index: " + chosenIndex);
System.err.println("Chosen capabilities:");
- System.err.println(available[chosenIndex]);
+ System.err.println(available.get(chosenIndex));
}
return chosenIndex;
diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java
index 47110add9..c728c1634 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java
@@ -32,6 +32,8 @@
package javax.media.nativewindow;
+import com.jogamp.common.util.ReflectionUtil;
+
public class DefaultGraphicsConfiguration implements Cloneable, AbstractGraphicsConfiguration {
private AbstractGraphicsScreen screen;
protected CapabilitiesImmutable capabilitiesChosen;
@@ -39,8 +41,16 @@ public class DefaultGraphicsConfiguration implements Cloneable, AbstractGraphics
public DefaultGraphicsConfiguration(AbstractGraphicsScreen screen,
CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested) {
+ if(null == screen) {
+ throw new NativeWindowException("Null screen");
+ }
+ if(null == capsChosen) {
+ throw new NativeWindowException("Null chosen caps");
+ }
+ if(null == capsRequested) {
+ throw new NativeWindowException("Null requested caps");
+ }
this.screen = screen;
-
this.capabilitiesChosen = capsChosen;
this.capabilitiesRequested = capsRequested;
}
@@ -96,9 +106,17 @@ public class DefaultGraphicsConfiguration implements Cloneable, AbstractGraphics
}
public String toString() {
- return getClass().toString()+"[" + screen +
+ return ReflectionUtil.getBaseName(getClass())+"[" + screen +
",\n\tchosen " + capabilitiesChosen+
",\n\trequested " + capabilitiesRequested+
"]";
}
+
+ public static String toHexString(int val) {
+ return "0x"+Integer.toHexString(val);
+ }
+
+ public static String toHexString(long val) {
+ return "0x"+Long.toHexString(val);
+ }
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java
index cb367f939..3d9f6d6ca 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java
@@ -33,6 +33,7 @@
package javax.media.nativewindow;
+import com.jogamp.common.util.ReflectionUtil;
import com.jogamp.nativewindow.impl.NativeWindowFactoryImpl;
public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice {
@@ -143,7 +144,7 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice
}
public String toString() {
- return getClass().toString()+"[type "+getType()+", connection "+getConnection()+", unitID "+getUnitID()+", handle 0x"+Long.toHexString(getHandle())+"]";
+ return ReflectionUtil.getBaseName(getClass())+"[type "+getType()+", connection "+getConnection()+", unitID "+getUnitID()+", handle 0x"+Long.toHexString(getHandle())+"]";
}
/**
diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java
index 065385ae3..7b7a89bff 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java
@@ -32,6 +32,8 @@
package javax.media.nativewindow;
+import com.jogamp.common.util.ReflectionUtil;
+
public class DefaultGraphicsScreen implements Cloneable, AbstractGraphicsScreen {
AbstractGraphicsDevice device;
private int idx;
@@ -62,6 +64,6 @@ public class DefaultGraphicsScreen implements Cloneable, AbstractGraphicsScreen
}
public String toString() {
- return getClass().toString()+"["+device+", idx "+idx+"]";
+ return ReflectionUtil.getBaseName(getClass())+"["+device+", idx "+idx+"]";
}
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java
index c061f597f..ad1bc3634 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java
@@ -33,10 +33,13 @@
package javax.media.nativewindow;
-import java.util.*;
+import com.jogamp.common.util.ReflectionUtil;
+import com.jogamp.nativewindow.impl.Debug;
+import com.jogamp.nativewindow.impl.DefaultGraphicsConfigurationFactoryImpl;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
-import com.jogamp.common.util.*;
-import com.jogamp.nativewindow.impl.*;
/**
* Provides the mechanism by which the graphics configuration for a
@@ -65,6 +68,18 @@ public abstract class GraphicsConfigurationFactory {
initialize();
}
+ protected static String getThreadName() {
+ return Thread.currentThread().getName();
+ }
+
+ protected static String toHexString(int val) {
+ return "0x" + Integer.toHexString(val);
+ }
+
+ protected static String toHexString(long val) {
+ return "0x" + Long.toHexString(val);
+ }
+
/** Creates a new NativeWindowFactory instance. End users do not
need to call this method. */
protected GraphicsConfigurationFactory() {
@@ -88,7 +103,7 @@ public abstract class GraphicsConfigurationFactory {
// AWTGraphicsDevice instances -- the OpenGL binding will take
// care of handling AWTGraphicsDevices on X11 platforms (as
// well as X11GraphicsDevices in non-AWT situations)
- registerFactory(abstractGraphicsDeviceClass, new GraphicsConfigurationFactoryImpl());
+ registerFactory(abstractGraphicsDeviceClass, new DefaultGraphicsConfigurationFactoryImpl());
}
/** Returns the factory for use with the given type of
@@ -232,4 +247,5 @@ public abstract class GraphicsConfigurationFactory {
chooseGraphicsConfigurationImpl(CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested,
CapabilitiesChooser chooser, AbstractGraphicsScreen screen)
throws IllegalArgumentException, NativeWindowException;
+
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
index a36440873..5d36df6ed 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
@@ -49,7 +49,7 @@ import java.lang.reflect.Method;
hardware-accelerated rendering using the OpenGL API. */
public abstract class NativeWindowFactory {
- protected static final boolean DEBUG = Debug.debug("NativeWindow");
+ protected static final boolean DEBUG;
/** OpenKODE/EGL type, as retrieved with {@link #getNativeWindowType(boolean)}*/
public static final String TYPE_EGL = "EGL";
@@ -80,6 +80,7 @@ public abstract class NativeWindowFactory {
public static final String AWTComponentClassName = "java.awt.Component" ;
public static final String JAWTUtilClassName = "com.jogamp.nativewindow.impl.jawt.JAWTUtil" ;
public static final String X11UtilClassName = "com.jogamp.nativewindow.impl.x11.X11Util";
+ public static final String GDIClassName = "com.jogamp.nativewindow.impl.windows.GDI";
public static final String X11JAWTToolkitLockClassName = "com.jogamp.nativewindow.impl.jawt.x11.X11JAWTToolkitLock" ;
public static final String X11ToolkitLockClassName = "com.jogamp.nativewindow.impl.x11.X11ToolkitLock" ;
private static Class jawtUtilClass;
@@ -113,13 +114,41 @@ public abstract class NativeWindowFactory {
static {
JVMUtil.initSingleton();
+ DEBUG = Debug.debug("NativeWindow");
+ if(DEBUG) {
+ Throwable td = new Throwable(Thread.currentThread().getName()+" - Info: NativeWindowFactory.<init>");
+ td.printStackTrace();
+ }
}
static boolean initialized = false;
+ private static void initNativeImpl(final boolean firstUIActionOnProcess, final ClassLoader cl) {
+ String clazzName = null;
+ if( TYPE_X11.equals(nativeWindowingTypePure) ) {
+ clazzName = X11UtilClassName;
+ } else if( TYPE_WINDOWS.equals(nativeWindowingTypePure) ) {
+ clazzName = GDIClassName;
+ }
+ if( null != clazzName ) {
+ ReflectionUtil.callStaticMethod(clazzName, "initSingleton",
+ new Class[] { boolean.class },
+ new Object[] { new Boolean(firstUIActionOnProcess) }, cl );
+ }
+ }
+
/**
* Static one time initialization of this factory.<br>
- * This initialization method <b>must be called</b> once by the program or utilizing modules!<br>
+ * This initialization method <b>must be called</b> once by the program or utilizing modules!
+ * <p>
+ * The parameter <code>firstUIActionOnProcess</code> has an impact on concurrent locking:
+ * <ul>
+ * <li> {@link #getDefaultToolkitLock() getDefaultToolkitLock() }</li>
+ * <li> {@link #getDefaultToolkitLock(java.lang.String) getDefaultToolkitLock(type) }</li>
+ * <li> {@link #createDefaultToolkitLock(java.lang.String, long) createDefaultToolkitLock(type, dpyHandle) }</li>
+ * <li> {@link #createDefaultToolkitLockNoAWT(java.lang.String, long) createDefaultToolkitLockNoAWT(type, dpyHandle) }</li>
+ * </ul>
+ * </p>
* @param firstUIActionOnProcess Should be <code>true</code> if called before the first UI action of the running program,
* otherwise <code>false</code>.
*/
@@ -128,8 +157,7 @@ public abstract class NativeWindowFactory {
initialized = true;
if(DEBUG) {
- Throwable td = new Throwable("Info: NativeWindowFactory.initSingleton("+firstUIActionOnProcess+")");
- td.printStackTrace();
+ System.err.println(Thread.currentThread().getName()+" - NativeWindowFactory.initSingleton("+firstUIActionOnProcess+")");
}
// Gather the windowing OS first
@@ -144,15 +172,14 @@ public abstract class NativeWindowFactory {
nativeWindowingTypeCustom = nativeOSNameCustom;
}
- ClassLoader cl = NativeWindowFactory.class.getClassLoader();
+ final ClassLoader cl = NativeWindowFactory.class.getClassLoader();
- if( TYPE_X11.equals(nativeWindowingTypePure) ) {
- // explicit initialization of X11Util
- ReflectionUtil.callStaticMethod(X11UtilClassName, "initSingleton",
- new Class[] { boolean.class },
- new Object[] { new Boolean(firstUIActionOnProcess) }, cl );
+ if(firstUIActionOnProcess) {
+ // X11 initialization before possible AWT initialization
+ initNativeImpl(firstUIActionOnProcess, cl);
}
isFirstUIActionOnProcess = firstUIActionOnProcess;
+ isAWTAvailable = false; // may be set to true below
if( !Debug.getBooleanProperty("java.awt.headless", true, acc) &&
ReflectionUtil.isClassAvailable(AWTComponentClassName, cl) &&
@@ -180,16 +207,13 @@ public abstract class NativeWindowFactory {
// AWT is only available in case all above classes are available
// and AWT is not int headless mode
isAWTAvailable = ((Boolean)resO).equals(Boolean.FALSE);
- } else {
- isAWTAvailable = false;
}
- } else {
- isAWTAvailable = false;
}
- } else {
- isAWTAvailable = false;
}
-
+ if(!firstUIActionOnProcess) {
+ // X11 initialization after possible AWT initialization
+ initNativeImpl(firstUIActionOnProcess, cl);
+ }
registeredFactories = Collections.synchronizedMap(new HashMap());
// register our default factory -> NativeWindow
@@ -270,10 +294,7 @@ public abstract class NativeWindowFactory {
/**
* Provides the system default {@link ToolkitLock}, a singleton instance.
* <br>
- * This is a {@link com.jogamp.nativewindow.impl.jawt.JAWTToolkitLock}
- * in case of a <b>X11 system</b> <em>and</em> <b>AWT availability</b> and if
- * this factory has been initialized with <b>{@link #initSingleton(boolean) initSingleton(firstUIActionOnProcess==true)}</b>, <br>
- * otherwise {@link com.jogamp.nativewindow.impl.NullToolkitLock} is returned.
+ * @see #getDefaultToolkitLock(java.lang.String)
*/
public static ToolkitLock getDefaultToolkitLock() {
return getDefaultToolkitLock(getNativeWindowType(false));
@@ -282,15 +303,27 @@ public abstract class NativeWindowFactory {
/**
* Provides the default {@link ToolkitLock} for <code>type</code>, a singleton instance.
* <br>
- * This is a {@link com.jogamp.nativewindow.impl.jawt.JAWTToolkitLock}
- * in case of a <b>X11 type</b> or <b>AWT type / X11 system</b> <em>and</em> <b>AWT availability</b> and if
- * this factory has been initialized with <b>{@link #initSingleton(boolean) initSingleton(firstUIActionOnProcess==true)}</b>, <br>
- * otherwise {@link com.jogamp.nativewindow.impl.NullToolkitLock} is returned.
+ * <ul>
+ * <li> If {@link #initSingleton(boolean) initSingleton( <b>firstUIActionOnProcess := false</b> )} </li>
+ * <ul>
+ * <li>If native <b>X11 type</b> with or w/o AWT</li>
+ * <ul>
+ * <li> If <b>AWT available</b> </li>
+ * <ul>
+ * <li> return {@link com.jogamp.nativewindow.impl.jawt.JAWTToolkitLock} </li>
+ * </ul>
+ * </ul>
+ * </ul>
+ * <li> Otherwise return {@link com.jogamp.nativewindow.impl.NullToolkitLock} </li>
+ * </ul>
*/
public static ToolkitLock getDefaultToolkitLock(String type) {
- if( isAWTAvailable() && !isFirstUIActionOnProcess() &&
- ( TYPE_X11 == type || TYPE_AWT == type && TYPE_X11 == getNativeWindowType(false) ) ) {
- return getAWTToolkitLock();
+ if( !isFirstUIActionOnProcess() ) {
+ if( TYPE_X11 == type || TYPE_AWT == type && TYPE_X11 == getNativeWindowType(false) ) {
+ if( isAWTAvailable() ) {
+ return getAWTToolkitLock();
+ }
+ }
}
return NativeWindowFactoryImpl.getNullToolkitLock();
}
@@ -308,39 +341,63 @@ public abstract class NativeWindowFactory {
public static ToolkitLock getNullToolkitLock() {
return NativeWindowFactoryImpl.getNullToolkitLock();
}
+
/**
* Creates the default {@link ToolkitLock} for <code>type</code> and <code>deviceHandle</code>.
* <br>
- * This is a {@link com.jogamp.nativewindow.impl.jawt.x11.X11JAWTToolkitLock}
- * in case of a <b>X11 type</b> <em>and</em> <b>AWT availability</b> and if
- * this factory has been initialized with <b>{@link #initSingleton(boolean) initSingleton(firstUIActionOnProcess==true)}</b>, <br>
- * or a {@link com.jogamp.nativewindow.impl.x11.X11ToolkitLock}
- * in case of a <b>X11 type</b> <em>and</em> <b>no AWT availability</b> and if
- * this factory has been initialized with <b>{@link #initSingleton(boolean) initSingleton(firstUIActionOnProcess==true)}</b>, <br>
- * otherwise {@link com.jogamp.nativewindow.impl.NullToolkitLock} is returned.
+ * <ul>
+ * <li> If {@link #initSingleton(boolean) initSingleton( <b>firstUIActionOnProcess := false</b> )} </li>
+ * <ul>
+ * <li>If <b>X11 type</b> </li>
+ * <ul>
+ * <li> If <b>AWT available</b> </li>
+ * <ul>
+ * <li> return {@link com.jogamp.nativewindow.impl.jawt.x11.X11JAWTToolkitLock} </li>
+ * </ul>
+ * <li> If <b>AWT not available</b> </li>
+ * <ul>
+ * <li> return {@link com.jogamp.nativewindow.impl.x11.X11ToolkitLock} </li>
+ * </ul>
+ * </ul>
+ * </ul>
+ * <li> Otherwise return {@link com.jogamp.nativewindow.impl.NullToolkitLock} </li>
+ * </ul>
*/
public static ToolkitLock createDefaultToolkitLock(String type, long deviceHandle) {
- if( TYPE_X11 == type ) {
- if( 0== deviceHandle ) {
- throw new RuntimeException("JAWTUtil.createDefaultToolkitLock() called with NULL device but on X11");
- }
- if( !isFirstUIActionOnProcess() ) {
+ if( !isFirstUIActionOnProcess() ) {
+ if( TYPE_X11 == type ) {
+ if( 0== deviceHandle ) {
+ throw new RuntimeException("JAWTUtil.createDefaultToolkitLock() called with NULL device but on X11");
+ }
if( isAWTAvailable() ) {
return createX11AWTToolkitLock(deviceHandle);
- } else {
- return createX11ToolkitLock(deviceHandle);
}
+ return createX11ToolkitLock(deviceHandle);
}
}
return NativeWindowFactoryImpl.getNullToolkitLock();
}
+ /**
+ * Creates the default {@link ToolkitLock} for <code>type</code> and <code>deviceHandle</code>.
+ * <br>
+ * <ul>
+ * <li> If {@link #initSingleton(boolean) initSingleton( <b>firstUIActionOnProcess := false</b> )} </li>
+ * <ul>
+ * <li>If <b>X11 type</b> </li>
+ * <ul>
+ * <li> return {@link com.jogamp.nativewindow.impl.x11.X11ToolkitLock} </li>
+ * </ul>
+ * </ul>
+ * <li> Otherwise return {@link com.jogamp.nativewindow.impl.NullToolkitLock} </li>
+ * </ul>
+ */
public static ToolkitLock createDefaultToolkitLockNoAWT(String type, long deviceHandle) {
- if( TYPE_X11 == type ) {
- if( 0== deviceHandle ) {
- throw new RuntimeException("JAWTUtil.createDefaultToolkitLockNoAWT() called with NULL device but on X11");
- }
- if( !isFirstUIActionOnProcess() ) {
+ if( !isFirstUIActionOnProcess() ) {
+ if( TYPE_X11 == type ) {
+ if( 0== deviceHandle ) {
+ throw new RuntimeException("JAWTUtil.createDefaultToolkitLockNoAWT() called with NULL device but on X11");
+ }
return createX11ToolkitLock(deviceHandle);
}
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/WindowClosingProtocol.java b/src/nativewindow/classes/javax/media/nativewindow/WindowClosingProtocol.java
new file mode 100644
index 000000000..949aee79c
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/WindowClosingProtocol.java
@@ -0,0 +1,66 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package javax.media.nativewindow;
+
+/**
+ * Protocol for handling window closing events.
+ * <p>
+ * The implementation shall obey either the user value set by this interface,<br>
+ * an underlying toolkit set user value or it's default, eg. {@link #DO_NOTHING_ON_CLOSE DO_NOTHING_ON_CLOSE} within an AWT environment.<br>
+ * If none of the above determines the operation,
+ * this protocol default behavior {@link #DISPOSE_ON_CLOSE DISPOSE_ON_CLOSE} shall be used.</p>
+ */
+public interface WindowClosingProtocol {
+ /**
+ * Dispose resources on native window close operation.<br>
+ * This is the default behavior in case no underlying toolkit defines otherwise.
+ */
+ int DISPOSE_ON_CLOSE = 1;
+
+ /**
+ * Do nothing on native window close operation.<br>
+ * This is the default behavior within an AWT environment.
+ */
+ int DO_NOTHING_ON_CLOSE = 0;
+
+ /**
+ * @return the current close operation value
+ * @see #DISPOSE_ON_CLOSE
+ * @see #DO_NOTHING_ON_CLOSE
+ */
+ int getDefaultCloseOperation();
+
+ /**
+ * @param op the new close operation value
+ * @return the previous close operation value
+ * @see #DISPOSE_ON_CLOSE
+ * @see #DO_NOTHING_ON_CLOSE
+ */
+ int setDefaultCloseOperation(int op);
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
index c3d10de10..e428bb0b1 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
@@ -40,6 +40,7 @@
package javax.media.nativewindow.awt;
+import com.jogamp.common.util.ReflectionUtil;
import javax.media.nativewindow.*;
import java.awt.Component;
import java.awt.GraphicsConfiguration;
@@ -155,7 +156,7 @@ public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration imple
}
public String toString() {
- return getClass().toString()+"[" + getScreen() +
+ return ReflectionUtil.getBaseName(getClass())+"[" + getScreen() +
",\n\tchosen " + capabilitiesChosen+
",\n\trequested " + capabilitiesRequested+
",\n\t" + config +
diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java
index cc4cd464f..2638ae18a 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java
@@ -39,6 +39,7 @@
package javax.media.nativewindow.awt;
+import com.jogamp.common.util.ReflectionUtil;
import javax.media.nativewindow.*;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
@@ -91,7 +92,7 @@ public class AWTGraphicsDevice extends DefaultGraphicsDevice implements Cloneabl
}
public String toString() {
- return getClass().toString()+"[type "+getType()+"[subType "+getSubType()+"], connection "+getConnection()+", unitID "+getUnitID()+", awtDevice "+device+", handle 0x"+Long.toHexString(getHandle())+"]";
+ return ReflectionUtil.getBaseName(getClass())+"[type "+getType()+"[subType "+getSubType()+"], connection "+getConnection()+", unitID "+getUnitID()+", awtDevice "+device+", handle 0x"+Long.toHexString(getHandle())+"]";
}
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTWindowClosingProtocol.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTWindowClosingProtocol.java
new file mode 100644
index 000000000..a0e9efa49
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTWindowClosingProtocol.java
@@ -0,0 +1,138 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package javax.media.nativewindow.awt;
+
+import java.awt.Component;
+import java.awt.Window;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+import javax.media.nativewindow.WindowClosingProtocol;
+import com.jogamp.nativewindow.impl.awt.AWTMisc;
+
+public class AWTWindowClosingProtocol implements WindowClosingProtocol {
+
+ private Component comp;
+ private Runnable closingOperation;
+ private volatile boolean closingListenerSet = false;
+ private Object closingListenerLock = new Object();
+ private int defaultCloseOperation = DISPOSE_ON_CLOSE;
+ private boolean defaultCloseOperationSetByUser = false;
+
+ public AWTWindowClosingProtocol(Component comp, Runnable closingOperation) {
+ this.comp = comp;
+ this.closingOperation = closingOperation;
+ }
+
+ class WindowClosingAdapter extends WindowAdapter {
+ public void windowClosing(WindowEvent e) {
+ int op = AWTWindowClosingProtocol.this.getDefaultCloseOperation();
+
+ if( DISPOSE_ON_CLOSE == op ) {
+ // we have to issue this call right away,
+ // otherwise the window gets destroyed
+ closingOperation.run();
+ }
+ }
+ }
+ WindowListener windowClosingAdapter = new WindowClosingAdapter();
+
+ final boolean addClosingListenerImpl() {
+ Window w = AWTMisc.getWindow(comp);
+ if(null!=w) {
+ w.addWindowListener(windowClosingAdapter);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Adds this closing listener to the components Window if exist and only one time.<br>
+ * Hence you may call this method every time to ensure it has been set,
+ * ie in case the Window parent is not available yet.
+ *
+ * @return
+ */
+ public final boolean addClosingListenerOneShot() {
+ if(!closingListenerSet) {
+ synchronized(closingListenerLock) {
+ if(!closingListenerSet) {
+ closingListenerSet=addClosingListenerImpl();
+ return closingListenerSet;
+ }
+ }
+ }
+ return false;
+ }
+
+ public final boolean removeClosingListener() {
+ if(closingListenerSet) {
+ synchronized(closingListenerLock) {
+ if(closingListenerSet) {
+ Window w = AWTMisc.getWindow(comp);
+ if(null!=w) {
+ w.removeWindowListener(windowClosingAdapter);
+ closingListenerSet = false;
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @return the user set close operation if set by {@link #setDefaultCloseOperation(int) setDefaultCloseOperation(int)},
+ * otherwise return the AWT/Swing close operation value translated to
+ * a {@link WindowClosingProtocol} value .
+ */
+ public final int getDefaultCloseOperation() {
+ int op = -1;
+ synchronized(closingListenerLock) {
+ if(defaultCloseOperationSetByUser) {
+ op = defaultCloseOperation;
+ }
+ }
+ if(0 <= op) {
+ return op;
+ }
+ // User didn't determine the behavior, use underlying AWT behavior
+ return AWTMisc.getNWClosingOperation(comp);
+ }
+
+ public final int setDefaultCloseOperation(int op) {
+ synchronized(closingListenerLock) {
+ int _op = defaultCloseOperation;
+ defaultCloseOperation = op;
+ defaultCloseOperationSetByUser = true;
+ return _op;
+ }
+ }
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java
index 07171e141..7b5f19047 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java
@@ -33,6 +33,8 @@
package javax.media.nativewindow.x11;
import javax.media.nativewindow.*;
+
+import com.jogamp.common.util.ReflectionUtil;
import com.jogamp.nativewindow.impl.x11.XVisualInfo;
/** Encapsulates a graphics configuration, or OpenGL pixel format, on
@@ -68,7 +70,7 @@ public class X11GraphicsConfiguration extends DefaultGraphicsConfiguration imple
}
public String toString() {
- return getClass().toString()+"["+getScreen()+", visualID 0x" + Long.toHexString(getVisualID()) +
+ return ReflectionUtil.getBaseName(getClass())+"["+getScreen()+", visualID 0x" + Long.toHexString(getVisualID()) +
",\n\tchosen " + capabilitiesChosen+
",\n\trequested " + capabilitiesRequested+
"]";
diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java
index 949afe5bd..33799d717 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java
@@ -32,13 +32,18 @@
package javax.media.nativewindow.x11;
+import com.jogamp.nativewindow.impl.Debug;
import com.jogamp.nativewindow.impl.x11.X11Util;
-import javax.media.nativewindow.*;
+import javax.media.nativewindow.DefaultGraphicsDevice;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.nativewindow.ToolkitLock;
/** Encapsulates a graphics device on X11 platforms.
*/
public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
+ public static final boolean DEBUG = Debug.debug("GraphicsDevice");
boolean closeDisplay = false;
/** Constructs a new X11GraphicsDevice corresponding to the given connection and default
@@ -78,10 +83,16 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl
public void setCloseDisplay(boolean close) {
closeDisplay = close;
+ if(DEBUG && close) {
+ System.err.println(Thread.currentThread().getName() + " - X11GraphicsDevice.setCloseDisplay(true): "+this);
+ }
}
public boolean close() {
// FIXME: shall we respect the unitID ?
if(closeDisplay && 0 != handle) {
+ if(DEBUG) {
+ System.err.println(Thread.currentThread().getName() + " - X11GraphicsDevice.close(): "+this);
+ }
X11Util.closeDisplay(handle);
handle = 0;
return true;
diff --git a/src/nativewindow/native/NativewindowCommon.c b/src/nativewindow/native/NativewindowCommon.c
new file mode 100644
index 000000000..e357045d6
--- /dev/null
+++ b/src/nativewindow/native/NativewindowCommon.c
@@ -0,0 +1,57 @@
+
+#include "NativewindowCommon.h"
+
+static const char * const ClazzNameRuntimeException = "java/lang/RuntimeException";
+static jclass runtimeExceptionClz=NULL;
+
+void NativewindowCommon_FatalError(JNIEnv *env, const char* msg, ...)
+{
+ char buffer[512];
+ va_list ap;
+
+ va_start(ap, msg);
+ vsnprintf(buffer, sizeof(buffer), msg, ap);
+ va_end(ap);
+
+ fprintf(stderr, "%s\n", buffer);
+ (*env)->FatalError(env, buffer);
+}
+
+void NativewindowCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...)
+{
+ char buffer[512];
+ va_list ap;
+
+ va_start(ap, msg);
+ vsnprintf(buffer, sizeof(buffer), msg, ap);
+ va_end(ap);
+
+ (*env)->ThrowNew(env, runtimeExceptionClz, buffer);
+}
+
+int NativewindowCommon_init(JNIEnv *env) {
+ if(NULL==runtimeExceptionClz) {
+ jclass c = (*env)->FindClass(env, ClazzNameRuntimeException);
+ if(NULL==c) {
+ NativewindowCommon_FatalError(env, "Nativewindow: can't find %s", ClazzNameRuntimeException);
+ }
+ runtimeExceptionClz = (jclass)(*env)->NewGlobalRef(env, c);
+ (*env)->DeleteLocalRef(env, c);
+ if(NULL==runtimeExceptionClz) {
+ NativewindowCommon_FatalError(env, "Nativewindow: can't use %s", ClazzNameRuntimeException);
+ }
+ return 1;
+ }
+ return 0;
+}
+
+jchar* NativewindowCommon_GetNullTerminatedStringChars(JNIEnv* env, jstring str)
+{
+ jchar* strChars = NULL;
+ strChars = calloc((*env)->GetStringLength(env, str) + 1, sizeof(jchar));
+ if (strChars != NULL) {
+ (*env)->GetStringRegion(env, str, 0, (*env)->GetStringLength(env, str), strChars);
+ }
+ return strChars;
+}
+
diff --git a/src/nativewindow/native/NativewindowCommon.h b/src/nativewindow/native/NativewindowCommon.h
new file mode 100644
index 000000000..5dc5debef
--- /dev/null
+++ b/src/nativewindow/native/NativewindowCommon.h
@@ -0,0 +1,15 @@
+
+#ifndef NATIVEWINDOW_COMMON_H
+#define NATIVEWINDOW_COMMON_H 1
+
+#include <jni.h>
+#include <stdlib.h>
+
+int NativewindowCommon_init(JNIEnv *env);
+
+jchar* NativewindowCommon_GetNullTerminatedStringChars(JNIEnv* env, jstring str);
+
+void NativewindowCommon_FatalError(JNIEnv *env, const char* msg, ...);
+void NativewindowCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...);
+
+#endif
diff --git a/src/nativewindow/native/windows/GDImisc.c b/src/nativewindow/native/windows/GDImisc.c
index 427e15d4a..798edcbbf 100644
--- a/src/nativewindow/native/windows/GDImisc.c
+++ b/src/nativewindow/native/windows/GDImisc.c
@@ -29,6 +29,7 @@
#include <stdio.h>
+#include "NativewindowCommon.h"
#include "com_jogamp_nativewindow_impl_windows_GDI.h"
// #define VERBOSE_ON 1
@@ -39,19 +40,6 @@
#define DBG_PRINT(args...)
#endif
-static void _FatalError(JNIEnv *env, const char* msg, ...)
-{
- char buffer[512];
- va_list ap;
-
- va_start(ap, msg);
- vsnprintf(buffer, sizeof(buffer), msg, ap);
- va_end(ap);
-
- fprintf(stderr, "%s\n", buffer);
- (*env)->FatalError(env, buffer);
-}
-
static const char * const ClazzNamePoint = "javax/media/nativewindow/util/Point";
static const char * const ClazzAnyCstrName = "<init>";
static const char * const ClazzNamePointCstrSignature = "(II)V";
@@ -59,74 +47,176 @@ static const char * const ClazzNamePointCstrSignature = "(II)V";
static jclass pointClz = NULL;
static jmethodID pointCstr = NULL;
-#define NATIVEWINDOW_DUMMY_WINDOW_NAME "__nativewindow_dummy_window"
-static ATOM nativewindowClass = 0;
+HINSTANCE GetApplicationHandle() {
+ return GetModuleHandle(NULL);
+}
-LRESULT CALLBACK DummyWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
- return DefWindowProc(hWnd,uMsg,wParam,lParam);
+/* Java->C glue code:
+ * Java package: com.jogamp.nativewindow.impl.windows.GDI
+ * Java method: boolean CreateWindowClass(long hInstance, java.lang.String clazzName, long wndProc)
+ * C function: BOOL CreateWindowClass(HANDLE hInstance, LPCSTR clazzName, HANDLE wndProc);
+ */
+JNIEXPORT jboolean JNICALL
+Java_com_jogamp_nativewindow_impl_windows_GDI_CreateWindowClass
+ (JNIEnv *env, jclass _unused, jlong jHInstance, jstring jClazzName, jlong wndProc)
+{
+ HINSTANCE hInstance = (HINSTANCE) (intptr_t) jHInstance;
+ const TCHAR* clazzName = NULL;
+ WNDCLASS wc;
+ jboolean res;
+
+#ifdef UNICODE
+ clazzName = NewtCommon_GetNullTerminatedStringChars(env, jClazzName);
+#else
+ clazzName = (*env)->GetStringUTFChars(env, jClazzName, NULL);
+#endif
+
+ ZeroMemory( &wc, sizeof( wc ) );
+ if( GetClassInfo( hInstance, clazzName, &wc ) ) {
+ // registered already
+ res = JNI_TRUE;
+ } else {
+ // register now
+ ZeroMemory( &wc, sizeof( wc ) );
+ wc.style = CS_HREDRAW | CS_VREDRAW ;
+ wc.lpfnWndProc = (WNDPROC) (intptr_t) wndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = hInstance;
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor( NULL, IDC_ARROW);
+ wc.hbrBackground = NULL; // no background paint - GetStockObject(BLACK_BRUSH);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = clazzName;
+ res = ( 0 != RegisterClass( &wc ) ) ? JNI_TRUE : JNI_FALSE ;
+ }
+
+#ifdef UNICODE
+ free((void*) clazzName);
+#else
+ (*env)->ReleaseStringUTFChars(env, jClazzName, clazzName);
+#endif
+
+ return res;
+}
+
+/* Java->C glue code:
+ * Java package: com.jogamp.nativewindow.impl.windows.GDI
+ * Java method: boolean DestroyWindowClass(long hInstance, java.lang.String className)
+ * C function: BOOL DestroyWindowClass(HANDLE hInstance, LPCSTR className);
+ */
+JNIEXPORT jboolean JNICALL
+Java_com_jogamp_nativewindow_impl_windows_GDI_DestroyWindowClass
+ (JNIEnv *env, jclass _unused, jlong jHInstance, jstring jClazzName)
+{
+ HINSTANCE hInstance = (HINSTANCE) (intptr_t) jHInstance;
+ const TCHAR* clazzName = NULL;
+ jboolean res;
+
+#ifdef UNICODE
+ clazzName = NewtCommon_GetNullTerminatedStringChars(env, jClazzName);
+#else
+ clazzName = (*env)->GetStringUTFChars(env, jClazzName, NULL);
+#endif
+
+ res = ( 0 != UnregisterClass( clazzName, hInstance ) ) ? JNI_TRUE : JNI_FALSE ;
+
+#ifdef UNICODE
+ free((void*) clazzName);
+#else
+ (*env)->ReleaseStringUTFChars(env, jClazzName, clazzName);
+#endif
+
+ return res;
}
-HWND CreateDummyWindow0(HINSTANCE hInstance, int x, int y, int width, int height ) {
- DWORD dwExStyle;
- DWORD dwStyle;
- HWND hWnd;
-
- dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
- dwStyle = WS_OVERLAPPEDWINDOW;
- if( !(hWnd=CreateWindowEx( dwExStyle,
- NATIVEWINDOW_DUMMY_WINDOW_NAME,
- NATIVEWINDOW_DUMMY_WINDOW_NAME,
- dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
- x, y, width, height,
- NULL, NULL, hInstance, NULL ) ) ) {
- return( 0 );
- }
- return( hWnd );
+
+/* Java->C glue code:
+ * Java package: com.jogamp.nativewindow.impl.windows.GDI
+ * Java method: long CreateDummyWindow0(long hInstance, java.lang.String className, java.lang.String windowName, int x, int y, int width, int height)
+ * C function: HANDLE CreateDummyWindow0(HANDLE hInstance, LPCSTR className, LPCSTR windowName, int x, int y, int width, int height);
+ */
+JNIEXPORT jlong JNICALL
+Java_com_jogamp_nativewindow_impl_windows_GDI_CreateDummyWindow0
+ (JNIEnv *env, jclass _unused, jlong jHInstance, jstring jWndClassName, jstring jWndName, jint x, jint y, jint width, jint height)
+{
+ HINSTANCE hInstance = (HINSTANCE) (intptr_t) jHInstance;
+ const TCHAR* wndClassName = NULL;
+ const TCHAR* wndName = NULL;
+ DWORD dwExStyle;
+ DWORD dwStyle;
+ HWND hWnd;
+
+#ifdef UNICODE
+ wndClassName = NewtCommon_GetNullTerminatedStringChars(env, jWndClassName);
+ wndName = NewtCommon_GetNullTerminatedStringChars(env, jWndName);
+#else
+ wndClassName = (*env)->GetStringUTFChars(env, jWndClassName, NULL);
+ wndName = (*env)->GetStringUTFChars(env, jWndName, NULL);
+#endif
+
+ dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
+ dwStyle = WS_OVERLAPPEDWINDOW;
+
+ hWnd = CreateWindowEx( dwExStyle,
+ wndClassName,
+ wndName,
+ dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
+ x, y, width, height,
+ NULL, NULL, hInstance, NULL );
+
+#ifdef UNICODE
+ free((void*) wndClassName);
+ free((void*) wndName);
+#else
+ (*env)->ReleaseStringUTFChars(env, jWndClassName, wndClassName);
+ (*env)->ReleaseStringUTFChars(env, jWndName, wndName);
+#endif
+
+ return (jlong) (intptr_t) hWnd;
}
+
/*
* Class: com_jogamp_nativewindow_impl_windows_GDI
* Method: initIDs0
* Signature: ()Z
*/
-JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_windows_GDI_initIDs0
+JNIEXPORT jboolean JNICALL Java_com_jogamp_nativewindow_impl_windows_GDI_initIDs0
(JNIEnv *env, jclass clazz)
{
- if(NULL==pointClz) {
+ if(NativewindowCommon_init(env)) {
jclass c = (*env)->FindClass(env, ClazzNamePoint);
if(NULL==c) {
- _FatalError(env, "FatalError com_jogamp_nativewindow_impl_windows_GDI: can't find %s", ClazzNamePoint);
+ NativewindowCommon_FatalError(env, "FatalError com_jogamp_nativewindow_impl_windows_GDI: can't find %s", ClazzNamePoint);
}
pointClz = (jclass)(*env)->NewGlobalRef(env, c);
(*env)->DeleteLocalRef(env, c);
if(NULL==pointClz) {
- _FatalError(env, "FatalError com_jogamp_nativewindow_impl_windows_GDI: can't use %s", ClazzNamePoint);
+ NativewindowCommon_FatalError(env, "FatalError com_jogamp_nativewindow_impl_windows_GDI: can't use %s", ClazzNamePoint);
}
pointCstr = (*env)->GetMethodID(env, pointClz, ClazzAnyCstrName, ClazzNamePointCstrSignature);
if(NULL==pointCstr) {
- _FatalError(env, "FatalError com_jogamp_nativewindow_impl_windows_GDI: can't fetch %s.%s %s",
+ NativewindowCommon_FatalError(env, "FatalError com_jogamp_nativewindow_impl_windows_GDI: can't fetch %s.%s %s",
ClazzNamePoint, ClazzAnyCstrName, ClazzNamePointCstrSignature);
}
}
- HINSTANCE hInstance = GetModuleHandle(NULL);
- if( !nativewindowClass ) {
- WNDCLASS wc;
- ZeroMemory( &wc, sizeof( wc ) );
- wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
- wc.lpfnWndProc = (WNDPROC) DummyWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = NULL;
- wc.hCursor = NULL;
- wc.hbrBackground = NULL;
- wc.lpszMenuName = NULL;
- wc.lpszClassName = NATIVEWINDOW_DUMMY_WINDOW_NAME;
- if( !(nativewindowClass = RegisterClass( &wc )) ) {
- _FatalError(env, "FatalError com_jogamp_nativewindow_impl_windows_GDI: RegisterClass Failed: %d", GetLastError() );
- }
- }
- return (jlong) hInstance;
+ return JNI_TRUE;
+}
+
+LRESULT CALLBACK DummyWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+ return DefWindowProc(hWnd,uMsg,wParam,lParam);
+}
+
+/*
+ * Class: com_jogamp_nativewindow_impl_windows_GDI
+ * Method: getDummyWndProc0
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_windows_GDI_getDummyWndProc0
+ (JNIEnv *env, jclass clazz)
+{
+ return (jlong) (intptr_t) DummyWndProc;
}
/*
diff --git a/src/nativewindow/native/x11/Xmisc.c b/src/nativewindow/native/x11/Xmisc.c
index efb20c54e..0d92880b3 100644
--- a/src/nativewindow/native/x11/Xmisc.c
+++ b/src/nativewindow/native/x11/Xmisc.c
@@ -80,6 +80,7 @@ Bool XF86VidModeSetGammaRamp(
#define RTLD_DEFAULT NULL
#endif
+#include "NativewindowCommon.h"
#include "com_jogamp_nativewindow_impl_x11_X11Lib.h"
// #define VERBOSE_ON 1
@@ -93,107 +94,66 @@ Bool XF86VidModeSetGammaRamp(
/* Need to pull this in as we don't have a stub header for it */
extern Bool XineramaEnabled(Display* display);
-static void _FatalError(JNIEnv *env, const char* msg, ...)
-{
- char buffer[512];
- va_list ap;
-
- va_start(ap, msg);
- vsnprintf(buffer, sizeof(buffer), msg, ap);
- va_end(ap);
-
- fprintf(stderr, "%s\n", buffer);
- (*env)->FatalError(env, buffer);
-}
-
static const char * const ClazzNameBuffers = "com/jogamp/common/nio/Buffers";
static const char * const ClazzNameBuffersStaticCstrName = "copyByteBuffer";
static const char * const ClazzNameBuffersStaticCstrSignature = "(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;";
static const char * const ClazzNameByteBuffer = "java/nio/ByteBuffer";
-static const char * const ClazzNameRuntimeException = "java/lang/RuntimeException";
static const char * const ClazzNamePoint = "javax/media/nativewindow/util/Point";
static const char * const ClazzAnyCstrName = "<init>";
static const char * const ClazzNamePointCstrSignature = "(II)V";
static jclass clazzBuffers = NULL;
static jmethodID cstrBuffers = NULL;
static jclass clazzByteBuffer = NULL;
-static jclass clazzRuntimeException=NULL;
static jclass pointClz = NULL;
static jmethodID pointCstr = NULL;
static void _initClazzAccess(JNIEnv *env) {
jclass c;
- if(NULL!=clazzRuntimeException) return ;
-
- c = (*env)->FindClass(env, ClazzNameRuntimeException);
- if(NULL==c) {
- _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameRuntimeException);
- }
- clazzRuntimeException = (jclass)(*env)->NewGlobalRef(env, c);
- (*env)->DeleteLocalRef(env, c);
- if(NULL==clazzRuntimeException) {
- _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameRuntimeException);
- }
+ if(!NativewindowCommon_init(env)) return;
c = (*env)->FindClass(env, ClazzNameBuffers);
if(NULL==c) {
- _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameBuffers);
+ NativewindowCommon_FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameBuffers);
}
clazzBuffers = (jclass)(*env)->NewGlobalRef(env, c);
(*env)->DeleteLocalRef(env, c);
if(NULL==clazzBuffers) {
- _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameBuffers);
+ NativewindowCommon_FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameBuffers);
}
c = (*env)->FindClass(env, ClazzNameByteBuffer);
if(NULL==c) {
- _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameByteBuffer);
+ NativewindowCommon_FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameByteBuffer);
}
clazzByteBuffer = (jclass)(*env)->NewGlobalRef(env, c);
(*env)->DeleteLocalRef(env, c);
if(NULL==c) {
- _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameByteBuffer);
+ NativewindowCommon_FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameByteBuffer);
}
cstrBuffers = (*env)->GetStaticMethodID(env, clazzBuffers,
ClazzNameBuffersStaticCstrName, ClazzNameBuffersStaticCstrSignature);
if(NULL==cstrBuffers) {
- _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't create %s.%s %s",
+ NativewindowCommon_FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't create %s.%s %s",
ClazzNameBuffers, ClazzNameBuffersStaticCstrName, ClazzNameBuffersStaticCstrSignature);
}
c = (*env)->FindClass(env, ClazzNamePoint);
if(NULL==c) {
- _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNamePoint);
+ NativewindowCommon_FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNamePoint);
}
pointClz = (jclass)(*env)->NewGlobalRef(env, c);
(*env)->DeleteLocalRef(env, c);
if(NULL==pointClz) {
- _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNamePoint);
+ NativewindowCommon_FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNamePoint);
}
pointCstr = (*env)->GetMethodID(env, pointClz, ClazzAnyCstrName, ClazzNamePointCstrSignature);
if(NULL==pointCstr) {
- _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't fetch %s.%s %s",
+ NativewindowCommon_FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't fetch %s.%s %s",
ClazzNamePoint, ClazzAnyCstrName, ClazzNamePointCstrSignature);
}
}
-static void _throwNewRuntimeException(Display * unlockDisplay, JNIEnv *env, const char* msg, ...)
-{
- char buffer[512];
- va_list ap;
-
- if(NULL!=unlockDisplay) {
- XUnlockDisplay(unlockDisplay);
- }
-
- va_start(ap, msg);
- vsnprintf(buffer, sizeof(buffer), msg, ap);
- va_end(ap);
-
- (*env)->ThrowNew(env, clazzRuntimeException, buffer);
-}
-
static JNIEnv * x11ErrorHandlerJNIEnv = NULL;
static XErrorHandler origErrorHandler = NULL ;
static int errorHandlerBlocked = 0 ;
@@ -208,7 +168,7 @@ static int x11ErrorHandler(Display *dpy, XErrorEvent *e)
// Since the X11 Error may happen anytime, a exception could mess up the JVM completely.
// Experienced this for remote displays issuing non supported commands, eg. glXCreateContextAttribsARB(..)
//
- _throwNewRuntimeException(NULL, x11ErrorHandlerJNIEnv, "Info: Nativewindow X11 Error: Display %p, Code 0x%X, errno %s",
+ NativewindowCommon_throwNewRuntimeException(x11ErrorHandlerJNIEnv, "Info: Nativewindow X11 Error: Display %p, Code 0x%X, errno %s",
dpy, e->error_code, strerror(errno));
#endif
@@ -256,7 +216,7 @@ static XIOErrorHandler origIOErrorHandler = NULL;
static int x11IOErrorHandler(Display *dpy)
{
fprintf(stderr, "Nativewindow X11 IOError: Display %p (%s): %s\n", dpy, XDisplayName(NULL), strerror(errno));
- // _FatalError(x11ErrorHandlerJNIEnv, "Nativewindow X11 IOError: Display %p (%s): %s", dpy, XDisplayName(NULL), strerror(errno));
+ // NativewindowCommon_FatalError(x11ErrorHandlerJNIEnv, "Nativewindow X11 IOError: Display %p (%s): %s", dpy, XDisplayName(NULL), strerror(errno));
if(NULL!=origIOErrorHandler) {
origIOErrorHandler(dpy);
}
@@ -315,7 +275,7 @@ Java_com_jogamp_nativewindow_impl_x11_X11Lib_XGetVisualInfo1__JJLjava_nio_ByteBu
jobject jbyteSource;
jobject jbyteCopy;
if(0==arg0) {
- _FatalError(env, "invalid display connection..");
+ NativewindowCommon_FatalError(env, "invalid display connection..");
}
if (arg2 != NULL) {
_ptr2 = (XVisualInfo *) (((char*) (*env)->GetDirectBufferAddress(env, arg2)) + 0);
@@ -344,7 +304,7 @@ JNIEXPORT jlong JNICALL
Java_com_jogamp_nativewindow_impl_x11_X11Lib_DefaultVisualID(JNIEnv *env, jclass _unused, jlong display, jint screen) {
jlong r;
if(0==display) {
- _FatalError(env, "invalid display connection..");
+ NativewindowCommon_FatalError(env, "invalid display connection..");
}
x11ErrorHandlerEnable((Display *) (intptr_t) display, 1, env);
r = (jlong) XVisualIDFromVisual( DefaultVisual( (Display*) (intptr_t) display, screen ) );
@@ -360,7 +320,7 @@ Java_com_jogamp_nativewindow_impl_x11_X11Lib_DefaultVisualID(JNIEnv *env, jclass
JNIEXPORT void JNICALL
Java_com_jogamp_nativewindow_impl_x11_X11Lib_XLockDisplay__J(JNIEnv *env, jclass _unused, jlong display) {
if(0==display) {
- _FatalError(env, "invalid display connection..");
+ NativewindowCommon_FatalError(env, "invalid display connection..");
}
XLockDisplay((Display *) (intptr_t) display);
}
@@ -373,7 +333,7 @@ Java_com_jogamp_nativewindow_impl_x11_X11Lib_XLockDisplay__J(JNIEnv *env, jclass
JNIEXPORT void JNICALL
Java_com_jogamp_nativewindow_impl_x11_X11Lib_XUnlockDisplay__J(JNIEnv *env, jclass _unused, jlong display) {
if(0==display) {
- _FatalError(env, "invalid display connection..");
+ NativewindowCommon_FatalError(env, "invalid display connection..");
}
XUnlockDisplay((Display *) (intptr_t) display);
}
@@ -387,7 +347,7 @@ JNIEXPORT jint JNICALL
Java_com_jogamp_nativewindow_impl_x11_X11Lib_XCloseDisplay__J(JNIEnv *env, jclass _unused, jlong display) {
int _res;
if(0==display) {
- _FatalError(env, "invalid display connection..");
+ NativewindowCommon_FatalError(env, "invalid display connection..");
}
x11ErrorHandlerEnable((Display *) (intptr_t) display, 1, env);
_res = XCloseDisplay((Display *) (intptr_t) display);
@@ -420,12 +380,12 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummy
Screen* scrn;
if(NULL==dpy) {
- _FatalError(env, "invalid display connection..");
+ NativewindowCommon_FatalError(env, "invalid display connection..");
return 0;
}
if(visualID<0) {
- _throwNewRuntimeException(NULL, env, "invalid VisualID ..");
+ NativewindowCommon_throwNewRuntimeException(env, "invalid VisualID ..");
return 0;
}
@@ -450,7 +410,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummy
if (visual==NULL)
{
x11ErrorHandlerEnable(dpy, 0, env);
- _throwNewRuntimeException(dpy, env, "could not query Visual by given VisualID, bail out!");
+ NativewindowCommon_throwNewRuntimeException(env, "could not query Visual by given VisualID, bail out!");
return 0;
}
@@ -515,7 +475,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_DestroyDummy
Window w = (Window) window;
if(NULL==dpy) {
- _throwNewRuntimeException(NULL, env, "invalid display connection..");
+ NativewindowCommon_throwNewRuntimeException(env, "invalid display connection..");
return;
}