aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2009-05-29 01:47:02 +0000
committerSven Gothel <[email protected]>2009-05-29 01:47:02 +0000
commit4c32ea23370336b99eba4c1ebd1f07c409219a15 (patch)
tree7d97e763a81f86650c2085eeeaeaf04ffaddf6bd /src/nativewindow
parenta7b402128a2cd00c099acde944f793455d8856a5 (diff)
JOGL
Added OpenGL 3.0 and 3.1 support 3.0 as part of GL2 (extensions only) 3.1 forward compatible as GL3, ie doesn't contain the GL2 fixed function stuff etc Added code to retrieve a 3.0/3.1 context: X11/GLX and Windows/WGL TODO: MacOSX !! Updated GL and GLX extensions Fixing auto GLProfile selection, determine if GL2ES[1] uses GL2 or ES Usage of the unified GraphicsConfiguration of NativeWindow for all platforms. Sure, the broken OS (Win32/MacOSX) have a update mechanism for theit queried Capabilities after drawable creation. Adding X11/GLX GLXFBConfig usage and fixing it's attribute mapping Fixing GLX/X11 FBConfig/XVisual query function's memory leak, using a manual implementation, which copies the data and calls XFree. Added WGL extension WGL_ARB_create_context Tested: Linux x86 and x86_64 GL2, ES2 and ES1 Note: Nvidia driver couldn't make the succesfully created 3.1 context current. TODO: Verify Windows and MacOSX !! git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1919 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java5
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java124
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java3
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java16
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java29
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java8
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java41
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java13
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java23
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11JAWTWindow.java33
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11SunJDKReflection.java15
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java77
-rw-r--r--src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java7
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java21
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java18
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsScreen.java55
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/Capabilities.java4
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java79
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java68
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java71
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java64
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java36
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java105
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java26
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java32
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java95
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java50
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java24
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java23
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java87
30 files changed, 1068 insertions, 184 deletions
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java b/src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java
index eb39b9f59..85d50e6bd 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/GraphicsConfigurationFactoryImpl.java
@@ -35,10 +35,9 @@ package com.sun.nativewindow.impl;
import javax.media.nativewindow.*;
public class GraphicsConfigurationFactoryImpl extends GraphicsConfigurationFactory {
- // By default we just return null; X11 is the only window system requiring eager visual selection
public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities,
CapabilitiesChooser chooser,
- AbstractGraphicsDevice device) {
- return null;
+ AbstractGraphicsScreen screen) {
+ return new DefaultGraphicsConfiguration(screen, capabilities);
}
}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java b/src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java
new file mode 100644
index 000000000..0425014df
--- /dev/null
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/InternalBufferUtil.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2009 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.sun.nativewindow.impl;
+
+import java.lang.reflect.*;
+import java.nio.*;
+
+/** Internal copy of selected routines from BufferUtil to avoid
+ outward dependencies on com.sun.opengl.util package. */
+public class InternalBufferUtil {
+ public static final int SIZEOF_BYTE = 1;
+ public static final int SIZEOF_SHORT = 2;
+ public static final int SIZEOF_INT = 4;
+ public static final int SIZEOF_FLOAT = 4;
+
+ //----------------------------------------------------------------------
+ // Allocation routines
+ //
+
+ /** Allocates a new direct ByteBuffer with the specified number of
+ elements. The returned buffer will have its byte order set to
+ the host platform's native byte order. */
+ public static ByteBuffer newByteBuffer(int numElements) {
+ ByteBuffer bb = ByteBuffer.allocateDirect(numElements);
+ nativeOrder(bb);
+ return bb;
+ }
+
+ /** Allocates a new direct IntBuffer with the specified number of
+ elements. The returned buffer will have its byte order set to
+ the host platform's native byte order. */
+ public static IntBuffer newIntBuffer(int numElements) {
+ ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT);
+ return bb.asIntBuffer();
+ }
+
+ //----------------------------------------------------------------------
+ // Copy routines (type-to-type)
+ //
+
+ /** Copies the <i>remaining</i> elements (as defined by
+ <code>limit() - position()</code>) in the passed ByteBuffer into
+ a newly-allocated direct ByteBuffer. The returned buffer will
+ have its byte order set to the host platform's native byte
+ order. The position of the newly-allocated buffer will be zero,
+ and the position of the passed buffer is unchanged (though its
+ mark is changed). */
+ public static ByteBuffer copyByteBuffer(ByteBuffer orig) {
+ ByteBuffer dest = newByteBuffer(orig.remaining());
+ dest.put(orig);
+ dest.rewind();
+ return dest;
+ }
+
+ //----------------------------------------------------------------------
+ // Conversion routines
+ //
+
+ public static ByteBuffer nativeOrder(ByteBuffer buf) {
+ if (!isCDCFP) {
+ try {
+ if (byteOrderClass == null) {
+ byteOrderClass = Class.forName("java.nio.ByteOrder");
+ orderMethod = ByteBuffer.class.getMethod("order", new Class[] { byteOrderClass });
+ Method nativeOrderMethod = byteOrderClass.getMethod("nativeOrder", null);
+ nativeOrderObject = nativeOrderMethod.invoke(null, null);
+ }
+ } catch (Throwable t) {
+ // Must be running on CDC / FP
+ isCDCFP = true;
+ }
+
+ if (!isCDCFP) {
+ try {
+ orderMethod.invoke(buf, new Object[] { nativeOrderObject });
+ } catch (Throwable t) {
+ }
+ }
+ }
+ return buf;
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only below this point
+ //
+
+ // NOTE that this work must be done reflectively at the present time
+ // because this code must compile and run correctly on both CDC/FP and J2SE
+ private static boolean isCDCFP;
+ private static Class byteOrderClass;
+ private static Object nativeOrderObject;
+ private static Method orderMethod;
+}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java
index 0be1f77d6..980f2705a 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/NativeLibLoaderBase.java
@@ -48,6 +48,8 @@ import java.security.PrivilegedAction;
import java.util.HashSet;
public class NativeLibLoaderBase {
+ private static boolean DEBUG = true;
+
public interface LoaderAction {
/**
* Loads the library specified by libname. Optionally preloads the libraries specified by
@@ -70,6 +72,7 @@ public class NativeLibLoaderBase {
System.loadLibrary(preload[i]);
}
catch (UnsatisfiedLinkError e) {
+ if(DEBUG) e.printStackTrace();
if (!preloadIgnoreError && e.getMessage().indexOf("already loaded") < 0) {
throw e;
}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java
index 8a865733a..3d873209f 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/NativeWindowFactoryImpl.java
@@ -41,8 +41,8 @@ public class NativeWindowFactoryImpl extends NativeWindowFactory {
protected static final boolean DEBUG = Debug.debug("NativeWindowFactoryImpl");
// This subclass of NativeWindowFactory handles the case of
- // NativeWindows and AWT Components being passed in
- protected NativeWindow getNativeWindowImpl(Object winObj) throws IllegalArgumentException {
+ // NativeWindows being passed in
+ protected NativeWindow getNativeWindowImpl(Object winObj, AbstractGraphicsConfiguration config) throws IllegalArgumentException {
if (null == winObj) {
throw new IllegalArgumentException("winObj is null");
}
@@ -51,8 +51,12 @@ public class NativeWindowFactoryImpl extends NativeWindowFactory {
return (NativeWindow) winObj;
}
+ if (null == config) {
+ throw new IllegalArgumentException("AbstractGraphicsConfiguration is null with a non NativeWindow object");
+ }
+
if (NWReflection.isAWTComponent(winObj)) {
- return getAWTNativeWindow(winObj);
+ return getAWTNativeWindow(winObj, config);
}
throw new IllegalArgumentException("Target window object type " +
@@ -62,7 +66,7 @@ public class NativeWindowFactoryImpl extends NativeWindowFactory {
private Constructor nativeWindowConstructor = null;
- private NativeWindow getAWTNativeWindow(Object winObj) {
+ private NativeWindow getAWTNativeWindow(Object winObj, AbstractGraphicsConfiguration config) {
if (nativeWindowConstructor == null) {
try {
String osName = System.getProperty("os.name");
@@ -85,14 +89,14 @@ public class NativeWindowFactoryImpl extends NativeWindowFactory {
throw new IllegalArgumentException("OS " + osName + " not yet supported");
}
- nativeWindowConstructor = NWReflection.getConstructor(windowClassName, new Class[] { Object.class });
+ nativeWindowConstructor = NWReflection.getConstructor(windowClassName, new Class[] { Object.class, AbstractGraphicsConfiguration.class });
} catch (Exception e) {
throw (IllegalArgumentException) new IllegalArgumentException().initCause(e);
}
}
try {
- return (NativeWindow) nativeWindowConstructor.newInstance(new Object[] { winObj });
+ return (NativeWindow) nativeWindowConstructor.newInstance(new Object[] { winObj, config });
} catch (Exception ie) {
throw (IllegalArgumentException) new IllegalArgumentException().initCause(ie);
}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java
index b4124a375..e448cd5d3 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java
@@ -41,12 +41,15 @@ import javax.media.nativewindow.*;
public class NullWindow implements NativeWindow {
protected boolean locked;
protected int width, height, scrnIndex;
- protected long windowHandle, surfaceHandle, displayHandle;
+ protected long surfaceHandle, displayHandle;
+ protected AbstractGraphicsConfiguration config;
- public NullWindow() {
- locked=false;
- scrnIndex=-1;
+ public NullWindow(AbstractGraphicsConfiguration cfg) {
+ invalidate();
+ config = cfg;
+ displayHandle=cfg.getScreen().getDevice().getHandle();
+ scrnIndex=cfg.getScreen().getIndex();
}
protected void init(Object windowObject) throws NativeWindowException {
@@ -57,6 +60,9 @@ public class NullWindow implements NativeWindow {
public synchronized void invalidate() {
locked = false;
+ displayHandle=0;
+ scrnIndex=-1;
+ surfaceHandle=0;
}
public synchronized int lockSurface() throws NativeWindowException {
@@ -78,22 +84,13 @@ public class NullWindow implements NativeWindow {
}
public long getDisplayHandle() {
- return windowHandle;
- }
- public void setDisplayHandle(long handle) {
- windowHandle=handle;
- }
- public long getScreenHandle() {
- return 0;
+ return displayHandle;
}
public int getScreenIndex() {
return scrnIndex;
}
- public void setScreenIndex(int idx) {
- scrnIndex=idx;
- }
public long getWindowHandle() {
- return windowHandle;
+ return 0;
}
public long getSurfaceHandle() {
return surfaceHandle;
@@ -102,7 +99,7 @@ public class NullWindow implements NativeWindow {
surfaceHandle=handle;
}
public AbstractGraphicsConfiguration getGraphicsConfiguration() {
- return null;
+ return config;
}
public Object getWrappedWindow() {
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java
index e6aa3ca74..78a384e1f 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTUtil.java
@@ -52,16 +52,19 @@ public class JAWTUtil {
static {
lockedToolkit = false;
+ lockedStack = null;
headlessMode = GraphicsEnvironment.isHeadless();
}
private static boolean lockedToolkit;
+ private static Exception lockedStack;
public static synchronized void lockToolkit() throws NativeWindowException {
if (lockedToolkit) {
throw new NativeWindowException("Toolkit already locked");
}
lockedToolkit = true;
+ lockedStack = new Exception("JAWT - locked");
if (headlessMode) {
// Workaround for running (to some degree) in headless
@@ -84,11 +87,16 @@ public class JAWTUtil {
JAWT.getJAWT().Unlock();
lockedToolkit = false;
+ lockedStack = null;
}
}
public static boolean isToolkitLocked() {
return lockedToolkit;
}
+
+ public static Exception getLockedStack() {
+ return lockedStack;
+ }
}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java
index cccf911bd..aa171f498 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java
@@ -44,7 +44,7 @@ import javax.media.nativewindow.*;
import com.sun.nativewindow.impl.*;
public abstract class JAWTWindow implements NativeWindow {
- protected static final boolean DEBUG = Debug.debug("GLDrawable");
+ protected static final boolean DEBUG = Debug.debug("NativeWindow");
// See whether we're running in headless mode
private static boolean headlessMode;
@@ -56,15 +56,16 @@ public abstract class JAWTWindow implements NativeWindow {
// lifetime: forever
protected Component component;
protected boolean locked;
+ protected AbstractGraphicsConfiguration config;
// lifetime: valid after lock, forever until invalidate
- protected long display;
- protected long screen;
protected long drawable;
- protected AbstractGraphicsConfiguration config;
- protected int screenIndex;
- public JAWTWindow(Object comp) {
+ public JAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
+ if (config == null) {
+ throw new NativeWindowException("Error: AbstractGraphicsConfiguration is null");
+ }
+ this.config = config;
init((Component)comp);
}
@@ -79,16 +80,18 @@ public abstract class JAWTWindow implements NativeWindow {
public synchronized void invalidate() {
locked = false;
component = null;
- display= 0;
- screen= 0;
- screenIndex = -1;
drawable= 0;
- config = null;
}
public synchronized int lockSurface() throws NativeWindowException {
+ if(DEBUG) {
+ if(JAWTUtil.isToolkitLocked()) {
+ JAWTUtil.getLockedStack().printStackTrace();
+ throw new NativeWindowException("JAWT already locked - "+this);
+ }
+ }
if (locked) {
- throw new NativeWindowException("Surface already locked");
+ throw new NativeWindowException("Surface already locked - "+this);
}
locked = true;
return LOCK_SUCCESS;
@@ -105,13 +108,10 @@ public abstract class JAWTWindow implements NativeWindow {
}
public long getDisplayHandle() {
- return display;
- }
- public long getScreenHandle() {
- return screen;
+ return config.getScreen().getDevice().getHandle();
}
public int getScreenIndex() {
- return screenIndex;
+ return config.getScreen().getIndex();
}
public long getWindowHandle() {
return drawable;
@@ -142,14 +142,13 @@ public abstract class JAWTWindow implements NativeWindow {
public String toString() {
StringBuffer sb = new StringBuffer();
- sb.append("JAWT-Window[windowHandle "+getWindowHandle()+
+ sb.append("JAWT-Window[config "+config+
+ ", windowHandle "+getWindowHandle()+
", surfaceHandle "+getSurfaceHandle()+
", pos "+component.getX()+"/"+component.getY()+", size "+getWidth()+"x"+getHeight()+
", visible "+component.isVisible()+
- ", wrappedWindow "+getWrappedWindow()+
- ", config "+config+
- ", screen handle/index "+getScreenHandle()+"/"+getScreenIndex() +
- ", display handle "+getDisplayHandle()+"]");
+ ", locked "+locked+
+ ", wrappedWindow "+getWrappedWindow()+"]");
return sb.toString();
}
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java
index e627b18f4..ef1984474 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java
@@ -50,8 +50,8 @@ import java.security.*;
public class MacOSXJAWTWindow extends JAWTWindow {
- public MacOSXJAWTWindow(Object comp) {
- super(comp);
+ public MacOSXJAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
+ super(comp, config);
}
protected void initNative() throws NativeWindowException {
@@ -65,6 +65,7 @@ public class MacOSXJAWTWindow extends JAWTWindow {
ds = JAWT.getJAWT().GetDrawingSurface(component);
if (ds == null) {
// Widget not yet realized
+ super.unlockSurface();
return NativeWindow.LOCK_SURFACE_NOT_READY;
}
int res = ds.Lock();
@@ -94,6 +95,7 @@ public class MacOSXJAWTWindow extends JAWTWindow {
ds.Unlock();
JAWT.getJAWT().FreeDrawingSurface(ds);
ds = null;
+ super.unlockSurface();
return NativeWindow.LOCK_SURFACE_NOT_READY;
}
firstLock = false;
@@ -105,14 +107,10 @@ public class MacOSXJAWTWindow extends JAWTWindow {
JAWT.getJAWT().FreeDrawingSurface(ds);
ds = null;
dsi = null;
+ super.unlockSurface();
return NativeWindow.LOCK_SURFACE_NOT_READY;
}
drawable = macosxdsi.cocoaViewRef();
- // FIXME: Are the followup abstractions available ? would it be usefull ?
- display = 0;
- config = null;
- screen= 0;
- screenIndex = 0;
if (drawable == 0) {
// Widget not yet realized
@@ -122,6 +120,7 @@ public class MacOSXJAWTWindow extends JAWTWindow {
ds = null;
dsi = null;
macosxdsi = null;
+ super.unlockSurface();
return NativeWindow.LOCK_SURFACE_NOT_READY;
}
return ret;
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java
index 122ee3f8d..e624641cd 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java
@@ -49,8 +49,8 @@ public class WindowsJAWTWindow extends JAWTWindow {
public static final boolean PROFILING = false; // FIXME
public static final int PROFILING_TICKS = 600; // FIXME
- public WindowsJAWTWindow(Object comp) {
- super(comp);
+ public WindowsJAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
+ super(comp, config);
}
protected void initNative() throws NativeWindowException {
@@ -69,6 +69,7 @@ public class WindowsJAWTWindow extends JAWTWindow {
ds = JAWT.getJAWT().GetDrawingSurface(component);
if (ds == null) {
// Widget not yet realized
+ super.unlockSurface();
return LOCK_SURFACE_NOT_READY;
}
int res = ds.Lock();
@@ -89,16 +90,21 @@ public class WindowsJAWTWindow extends JAWTWindow {
ds.Unlock();
JAWT.getJAWT().FreeDrawingSurface(ds);
ds = null;
+ super.unlockSurface();
return LOCK_SURFACE_NOT_READY;
}
win32dsi = (JAWT_Win32DrawingSurfaceInfo) dsi.platformInfo();
+ if (win32dsi == null) {
+ // Widget not yet realized
+ ds.FreeDrawingSurfaceInfo(dsi);
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ dsi = null;
+ super.unlockSurface();
+ return LOCK_SURFACE_NOT_READY;
+ }
drawable = win32dsi.hdc();
- // FIXME: Are the followup abstractions available ? would it be usefull ?
- display = 0;
- config = null;
- screen= 0;
- screenIndex = 0;
-
if (drawable == 0) {
// Widget not yet realized
ds.FreeDrawingSurfaceInfo(dsi);
@@ -107,6 +113,7 @@ public class WindowsJAWTWindow extends JAWTWindow {
ds = null;
dsi = null;
win32dsi = null;
+ super.unlockSurface();
return LOCK_SURFACE_NOT_READY;
}
if (PROFILING) {
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11JAWTWindow.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11JAWTWindow.java
index e8d955b21..1d6e8eea2 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11JAWTWindow.java
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11JAWTWindow.java
@@ -48,8 +48,8 @@ import java.awt.GraphicsEnvironment;
public class X11JAWTWindow extends JAWTWindow {
- public X11JAWTWindow(Object comp) {
- super(comp);
+ public X11JAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
+ super(comp, config);
}
protected void initNative() throws NativeWindowException {
@@ -63,6 +63,7 @@ public class X11JAWTWindow extends JAWTWindow {
ds = JAWT.getJAWT().GetDrawingSurface(component);
if (ds == null) {
// Widget not yet realized
+ super.unlockSurface();
return LOCK_SURFACE_NOT_READY;
}
int res = ds.Lock();
@@ -83,21 +84,22 @@ public class X11JAWTWindow extends JAWTWindow {
ds.Unlock();
JAWT.getJAWT().FreeDrawingSurface(ds);
ds = null;
+ super.unlockSurface();
return LOCK_SURFACE_NOT_READY;
}
x11dsi = (JAWT_X11DrawingSurfaceInfo) dsi.platformInfo();
- display = x11dsi.display();
- drawable = x11dsi.drawable();
- long visualID = x11dsi.visualID();
- config = new X11GraphicsConfiguration(visualID);
- screen= 0;
- if (X11Lib.XineramaEnabled(display)) {
- screenIndex = 0;
- } else {
- GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
- screenIndex = X11SunJDKReflection.graphicsDeviceGetScreen(device);
+ if (x11dsi == null) {
+ // Widget not yet realized
+ ds.FreeDrawingSurfaceInfo(dsi);
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ dsi = null;
+ super.unlockSurface();
+ return LOCK_SURFACE_NOT_READY;
}
- if (display == 0 || drawable == 0) {
+ drawable = x11dsi.drawable();
+ if (drawable == 0) {
// Widget not yet realized
ds.FreeDrawingSurfaceInfo(dsi);
ds.Unlock();
@@ -105,11 +107,8 @@ public class X11JAWTWindow extends JAWTWindow {
ds = null;
dsi = null;
x11dsi = null;
- display = 0;
drawable = 0;
- config = null;
- screen= 0;
- screenIndex = -1;
+ super.unlockSurface();
return LOCK_SURFACE_NOT_READY;
}
return ret;
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11SunJDKReflection.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11SunJDKReflection.java
index a4160033d..ef1f82cee 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11SunJDKReflection.java
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/x11/X11SunJDKReflection.java
@@ -56,6 +56,7 @@ 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;
private static boolean initted;
@@ -67,6 +68,8 @@ public class X11SunJDKReflection {
x11GraphicsDeviceClass = Class.forName("sun.awt.X11GraphicsDevice");
x11GraphicsDeviceGetScreenMethod = x11GraphicsDeviceClass.getDeclaredMethod("getScreen", new Class[] {});
x11GraphicsDeviceGetScreenMethod.setAccessible(true);
+ x11GraphicsDeviceGetDisplayMethod = x11GraphicsDeviceClass.getDeclaredMethod("getDisplay", new Class[] {});
+ x11GraphicsDeviceGetDisplayMethod.setAccessible(true);
x11GraphicsConfigClass = Class.forName("sun.awt.X11GraphicsConfig");
x11GraphicsConfigGetVisualMethod = x11GraphicsConfigClass.getDeclaredMethod("getVisual", new Class[] {});
@@ -92,6 +95,18 @@ public class X11SunJDKReflection {
}
}
+ public static long graphicsDeviceGetDisplay(GraphicsDevice device) {
+ if (!initted) {
+ return 0;
+ }
+
+ try {
+ return ((Long) x11GraphicsDeviceGetDisplayMethod.invoke(device, new Object[] {})).longValue();
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
public static int graphicsConfigurationGetVisualID(AbstractGraphicsConfiguration config) {
try {
if (config instanceof AWTGraphicsConfiguration) {
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java
index 5250e251b..1844b1c37 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11GraphicsConfigurationFactory.java
@@ -34,27 +34,72 @@ package com.sun.nativewindow.impl.x11;
import javax.media.nativewindow.*;
import javax.media.nativewindow.x11.*;
+import com.sun.nativewindow.impl.x11.XVisualInfo;
+import com.sun.nativewindow.impl.x11.X11Lib;
public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactory {
- // FIXME: there is a "quality of implementation" issue here. We
- // want to allow the use of the GraphicsConfigurationFactory in
- // conjunction with OpenGL as well as other rendering mechanisms.
- // On X11 platforms the OpenGL pixel format is associated with the
- // window's visual. On other platforms, the OpenGL pixel format is
- // chosen lazily. As in the OpenGL binding, the default
- // X11GraphicsConfigurationFactory would need to provide a default
- // mechanism for selecting a visual based on a set of
- // capabilities. Here we always return 0 for the visual ID, which
- // presumably corresponds to the default visual (which may be a
- // bad assumption). When using OpenGL, the OpenGL binding is
- // responsible for registering a GraphicsConfigurationFactory
- // which actually performs visual selection, though based on
- // GLCapabilities.
public AbstractGraphicsConfiguration
chooseGraphicsConfiguration(Capabilities capabilities,
CapabilitiesChooser chooser,
- AbstractGraphicsDevice device)
+ AbstractGraphicsScreen screen)
throws IllegalArgumentException, NativeWindowException {
- return new X11GraphicsConfiguration(0);
+
+ if(null==screen || !(screen instanceof X11GraphicsScreen)) {
+ throw new NativeWindowException("Only valid X11GraphicsScreen are allowed");
+ }
+ return new X11GraphicsConfiguration((X11GraphicsScreen)screen, capabilities, getXVisualInfo(screen, capabilities));
+ }
+
+ public static XVisualInfo getXVisualInfo(AbstractGraphicsScreen screen, long visualID)
+ {
+ XVisualInfo xvi_temp = XVisualInfo.create();
+ xvi_temp.visualid(visualID);
+ xvi_temp.screen(screen.getIndex());
+ int num[] = { -1 };
+
+ XVisualInfo[] xvis = X11Lib.XGetVisualInfoCopied(screen.getDevice().getHandle(), X11Lib.VisualIDMask|X11Lib.VisualScreenMask, xvi_temp, num, 0);
+
+ if(xvis==null || num[0]<1) {
+ return null;
+ }
+
+ return XVisualInfo.create(xvis[0]);
+ }
+
+ public static XVisualInfo getXVisualInfo(AbstractGraphicsScreen screen, Capabilities capabilities)
+ {
+ XVisualInfo xv = getXVisualInfoImpl(screen, capabilities, 4 /* TrueColor */);
+ if(null!=xv) return xv;
+ return getXVisualInfoImpl(screen, capabilities, 5 /* DirectColor */);
+ }
+
+ private static XVisualInfo getXVisualInfoImpl(AbstractGraphicsScreen screen, Capabilities capabilities, int c_class)
+ {
+ XVisualInfo ret = null;
+ int[] num = { -1 };
+
+ XVisualInfo vinfo_template = XVisualInfo.create();
+ vinfo_template.screen(screen.getIndex());
+ vinfo_template.c_class(c_class);
+
+ XVisualInfo[] vinfos = X11Lib.XGetVisualInfoCopied(screen.getDevice().getHandle(), X11Lib.VisualScreenMask, vinfo_template, num, 0);
+ XVisualInfo best=null;
+ int rdepth = capabilities.getRedBits() + capabilities.getGreenBits() + capabilities.getBlueBits() + capabilities.getAlphaBits();
+ for (int i = 0; vinfos!=null && i < num[0]; i++) {
+ if ( best == null ||
+ best.depth() < vinfos[i].depth() )
+ {
+ best = vinfos[i];
+ if(rdepth <= best.depth())
+ break;
+ }
+ }
+ if ( null!=best && ( rdepth <= best.depth() || 24 == best.depth()) ) {
+ ret = XVisualInfo.create(best);
+ }
+ best = null;
+
+ return ret;
}
}
+
diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java
index 703f8baf3..42e7ab495 100644
--- a/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java
+++ b/src/nativewindow/classes/com/sun/nativewindow/impl/x11/X11Util.java
@@ -66,6 +66,13 @@ public class X11Util {
return staticDisplay;
}
+ public static long getDefaultDisplay() {
+ if (staticDisplay == 0) {
+ getDisplayConnection(); // will set xineramaEnabled
+ }
+ return staticDisplay;
+ }
+
public static boolean isXineramaEnabled() {
if (staticDisplay == 0) {
getDisplayConnection(); // will set xineramaEnabled
diff --git a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java
index 512ebf17c..8cf8d1b0d 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java
@@ -42,5 +42,24 @@ package javax.media.nativewindow;
/** A marker interface describing a graphics configuration, visual, or
pixel format in a toolkit-independent manner. */
-public interface AbstractGraphicsConfiguration {
+public interface AbstractGraphicsConfiguration extends Cloneable {
+ /**
+ * Return the screen this graphics configuration is valid for
+ */
+ public AbstractGraphicsScreen getScreen();
+
+ /**
+ * Return the capabilities reflecting this graphics configuration,
+ * which may differ from the capabilites used to choose this configuration.
+ */
+ public Capabilities getCapabilities();
+
+ /**
+ * In case this instance already reflects a native configuration,
+ * return this one.
+ * Otherwise return the encapsuled native configuration,
+ * as it shall be included e.g. in the AWT case.
+ */
+ public AbstractGraphicsConfiguration getNativeGraphicsConfiguration();
}
+
diff --git a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java
index 3bef97aaf..4240ec81e 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java
@@ -39,8 +39,20 @@
package javax.media.nativewindow;
-/** A marker interface describing a graphics device in a
- toolkit-independent manner. */
+/** A interface describing a graphics device in a
+ toolkit-independent manner.
+ */
+
+public interface AbstractGraphicsDevice extends Cloneable {
+ /**
+ * Returns the type of the underlying subsystem, ie
+ * NativeWindowFactory.TYPE_KD, NativeWindowFactory.TYPE_X11, ..
+ */
+ public String getType();
-public interface AbstractGraphicsDevice {
+ /**
+ * Returns the native handle of the underlying native device,
+ * if such thing exist.
+ */
+ public long getHandle();
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsScreen.java
new file mode 100644
index 000000000..eb2cc9120
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsScreen.java
@@ -0,0 +1,55 @@
+/*
+ * 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 javax.media.nativewindow;
+
+/** A interface describing a graphics screen in a
+ toolkit-independent manner.
+ */
+
+public interface AbstractGraphicsScreen extends Cloneable {
+ /**
+ * 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/javax/media/nativewindow/Capabilities.java b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java
index 6fadd3e7e..201d2538f 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java
@@ -122,11 +122,11 @@ public class Capabilities implements Cloneable {
/** Returns a textual representation of this Capabilities
object. */
public String toString() {
- return ("Capabilities [" +
+ return getClass().toString()+"[" +
"Red: " + redBits +
", Green: " + greenBits +
", Blue: " + blueBits +
", Alpha: " + alphaBits +
- " ]");
+ " ]";
}
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java
new file mode 100644
index 000000000..7aba7e171
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package javax.media.nativewindow;
+
+public class DefaultGraphicsConfiguration implements Cloneable, AbstractGraphicsConfiguration {
+ private AbstractGraphicsScreen screen;
+ private Capabilities capabilities;
+
+ public DefaultGraphicsConfiguration(AbstractGraphicsScreen screen, Capabilities caps) {
+ this.screen = screen;
+ this.capabilities = caps;
+ }
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new NativeWindowException(e);
+ }
+ }
+
+ public AbstractGraphicsScreen getScreen() {
+ return screen;
+ }
+
+ public Capabilities getCapabilities() {
+ return (Capabilities)capabilities.clone();
+ }
+
+ public AbstractGraphicsConfiguration getNativeGraphicsConfiguration() {
+ return this;
+ }
+
+ /**
+ * Set the capabilities to a new value.
+ * Despite the architecture's goal to gather this data upfront,
+ * on some platforms we can gather the info only after the window creation..
+ * However, if you can, please use {@link GraphicsConfigurationFactory GraphicsConfigurationFactory}.
+ *
+ * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen)
+ */
+ protected void setCapabilities(Capabilities caps) {
+ capabilities = (Capabilities) caps.clone();
+ }
+
+ public String toString() {
+ return getClass().toString()+"[" + screen +", "+ capabilities +"]";
+ }
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java
new file mode 100644
index 000000000..fdc849d0f
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package javax.media.nativewindow;
+
+public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice {
+ private String type;
+ protected long handle;
+
+ public DefaultGraphicsDevice(String type) {
+ this.type = type;
+ this.handle = 0;
+ }
+
+ public DefaultGraphicsDevice(String type, long handle) {
+ this.type = type;
+ this.handle = handle;
+ }
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new NativeWindowException(e);
+ }
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public long getHandle() {
+ return handle;
+ }
+
+ public String toString() {
+ return getClass().toString()+"[type "+getType()+", 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
new file mode 100644
index 000000000..0af32c9ec
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/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 javax.media.nativewindow;
+
+public class DefaultGraphicsScreen implements Cloneable, AbstractGraphicsScreen {
+ AbstractGraphicsDevice device;
+ private int idx;
+
+ public DefaultGraphicsScreen(AbstractGraphicsDevice device, int idx) {
+ this.device = device;
+ this.idx = idx;
+ }
+
+ public static AbstractGraphicsScreen createScreenDevice(int screenIdx) {
+ return new DefaultGraphicsScreen(new DefaultGraphicsDevice(NativeWindowFactory.TYPE_DEFAULT), screenIdx);
+ }
+
+ public static AbstractGraphicsScreen createDefault() {
+ return createScreenDevice(0);
+ }
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new NativeWindowException(e);
+ }
+ }
+
+ public AbstractGraphicsDevice getDevice() {
+ return device;
+ }
+
+ public int getIndex() {
+ return idx;
+ }
+
+ public String toString() {
+ return getClass().toString()+"["+device+", idx "+idx+"]";
+ }
+}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java
index afddaf7aa..09aca9ff3 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java
@@ -54,9 +54,21 @@ import com.sun.nativewindow.impl.*;
*/
public abstract class GraphicsConfigurationFactory {
+ protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration");
+
private static Map/*<Class, NativeWindowFactory>*/ registeredFactories =
Collections.synchronizedMap(new HashMap());
private static Class abstractGraphicsDeviceClass;
+ private static Class anyDeviceClass;
+
+ /**
+ * Marker class javax.media.nativewindow.GraphicsConfigurationFactory.AnyDevice.class
+ * If a factory is registered with it, it matches for all device types !
+ */
+ public static class AnyDevice implements AbstractGraphicsDevice {
+ public String getType() { return "OPAQUE"; }
+ public long getHandle() { return 0; }
+ }
static {
initialize();
@@ -73,6 +85,7 @@ public abstract class GraphicsConfigurationFactory {
String factoryClassName = null;
abstractGraphicsDeviceClass = javax.media.nativewindow.AbstractGraphicsDevice.class;
+ anyDeviceClass = javax.media.nativewindow.GraphicsConfigurationFactory.AnyDevice.class;
if (!osNameLowerCase.startsWith("wind") &&
!osNameLowerCase.startsWith("mac os x")) {
@@ -115,17 +128,33 @@ public abstract class GraphicsConfigurationFactory {
if (!(abstractGraphicsDeviceClass.isAssignableFrom(abstractGraphicsDeviceImplementor))) {
throw new IllegalArgumentException("Given class must implement AbstractGraphicsDevice");
}
+
+ // Check if opaque AnyDevice match exist, it needs an exact match
+ GraphicsConfigurationFactory factory = (GraphicsConfigurationFactory)registeredFactories.get(anyDeviceClass);
+ if(null!=factory) {
+ if(DEBUG) {
+ System.err.println("GraphicsConfigurationFactory.getFactory() OPAQUE "+anyDeviceClass+" -> "+factory);
+ }
+ return factory;
+ }
Class clazz = abstractGraphicsDeviceImplementor;
while (clazz != null) {
- GraphicsConfigurationFactory factory =
+ factory =
(GraphicsConfigurationFactory) registeredFactories.get(clazz);
if (factory != null) {
+ if(DEBUG) {
+ System.err.println("GraphicsConfigurationFactory.getFactory() "+abstractGraphicsDeviceImplementor+" -> "+factory);
+ }
return factory;
}
clazz = clazz.getSuperclass();
}
// Return the default
- return (GraphicsConfigurationFactory) registeredFactories.get(abstractGraphicsDeviceClass);
+ factory = (GraphicsConfigurationFactory)registeredFactories.get(abstractGraphicsDeviceClass);
+ if(DEBUG) {
+ System.err.println("GraphicsConfigurationFactory.getFactory() DEFAULT "+abstractGraphicsDeviceClass+" -> "+factory);
+ }
+ return factory;
}
/** Registers a GraphicsConfigurationFactory handling graphics
@@ -141,18 +170,32 @@ public abstract class GraphicsConfigurationFactory {
if (!(abstractGraphicsDeviceClass.isAssignableFrom(abstractGraphicsDeviceImplementor))) {
throw new IllegalArgumentException("Given class must implement AbstractGraphicsDevice");
}
+ if(DEBUG) {
+ System.err.println("GraphicsConfigurationFactory.registerFactory() "+abstractGraphicsDeviceImplementor+" -> "+factory);
+ }
registeredFactories.put(abstractGraphicsDeviceImplementor, factory);
}
/**
* <P> Selects a graphics configuration on the specified graphics
* device compatible with the supplied {@link Capabilities}. Some
- * platforms (specifically X11) require the graphics configuration
- * to be specified when the native window is created. This method
- * is mainly intended to be both used and implemented by the
- * OpenGL binding, and may return null on platforms on which the
- * OpenGL pixel format selection process is performed later or in
- * other unspecified situations. </P>
+ * 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.</P>
+ *
+ * <P>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#setCapabilities DefaultGraphicsConfiguration.setCapabilities()}.
+ * </P>
+ *
+ * <P>
+ * This method is mainly intended to be both used and implemented by the
+ * OpenGL binding.</P>
*
* <P> The concrete data type of the passed graphics device and
* returned graphics configuration must be specified in the
@@ -171,10 +214,13 @@ public abstract class GraphicsConfigurationFactory {
* NativeWindowFactory.
* @throws NativeWindowException if any window system-specific errors caused
* the selection of the graphics configuration to fail.
+ *
+ * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen)
+ * @see javax.media.nativewindow.DefaultGraphicsConfiguration#setCapabilities(Capabilities caps)
*/
public abstract AbstractGraphicsConfiguration
chooseGraphicsConfiguration(Capabilities capabilities,
CapabilitiesChooser chooser,
- AbstractGraphicsDevice device)
+ AbstractGraphicsScreen screen)
throws IllegalArgumentException, NativeWindowException;
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java
index 75e8552f9..f55815aaa 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java
@@ -77,12 +77,6 @@ public interface NativeWindow {
public void invalidate();
/**
- * Lifetime: locked state
- */
- public long getDisplayHandle();
- public long getScreenHandle();
-
- /**
* Returns the window handle for this NativeWindow. <P>
*
* The window handle shall reflect the platform one
@@ -105,27 +99,27 @@ public interface NativeWindow {
*/
public long getSurfaceHandle();
+ /** Returns the current width of this window. */
+ public int getWidth();
+
+ /** Returns the current height of this window. */
+ public int getHeight();
+
/**
* Returns the graphics configuration corresponding to this window.
- * The graphics configuration is most relevant on X11 platforms
- * where it also decides other properties related to hardware
- * accelerated rendering such as the OpenGL pixel format. This
- * method may return null on platforms where it is not needed, and
- * is only guaranteed to return a valid value while the window is
- * locked.
+ * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen)
*/
public AbstractGraphicsConfiguration getGraphicsConfiguration();
/**
- * Returns the index of the screen on which this window currently
- * lies. This method is only guaranteed to return a valid value
- * while the window is locked.
+ * Convenience: Get display handle from
+ * AbstractGraphicsConfiguration . AbstractGraphicsScreen . AbstractGraphicsDevice
*/
- public int getScreenIndex();
-
- /** Returns the current width of this window. */
- public int getWidth();
+ public long getDisplayHandle();
- /** Returns the current height of this window. */
- public int getHeight();
+ /**
+ * Convenience: Get display handle from
+ * AbstractGraphicsConfiguration . AbstractGraphicsScreen
+ */
+ public int getScreenIndex();
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
index 80ee97081..1096fe3c7 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
@@ -45,10 +45,29 @@ import com.sun.nativewindow.impl.*;
hardware-accelerated rendering using the OpenGL API. */
public abstract class NativeWindowFactory {
+ /** OpenKODE/EGL type */
+ public static final String TYPE_EGL = "EGL";
+
+ /** Microsoft Windows type */
+ public static final String TYPE_WINDOWS = "Windows";
+
+ /** X11 type */
+ public static final String TYPE_X11 = "X11";
+
+ /** Mac OS X type */
+ public static final String TYPE_MACOSX = "MacOSX";
+
+ /** Generic AWT type */
+ public static final String TYPE_AWT = "AWT";
+
+ /** Generic DEFAULT type, where platform implementation don't care */
+ public static final String TYPE_DEFAULT = "default";
+
private static NativeWindowFactory defaultFactory;
private static Map/*<Class, NativeWindowFactory>*/ registeredFactories =
Collections.synchronizedMap(new HashMap());
private static Class nativeWindowClass;
+ private static String nativeWindowingType=null;
/** Creates a new NativeWindowFactory instance. End users do not
need to call this method. */
@@ -63,8 +82,6 @@ public abstract class NativeWindowFactory {
}
initialized = true;
- String osName = System.getProperty("os.name");
- String osNameLowerCase = osName.toLowerCase();
String factoryClassName = null;
// We break compile-time dependencies on the AWT here to
@@ -78,34 +95,59 @@ public abstract class NativeWindowFactory {
Class componentClass = null;
try {
componentClass = Class.forName("java.awt.Component");
- } catch (Exception e) {
- }
- if (componentClass != null) {
- if (!osNameLowerCase.startsWith("wind") &&
- !osNameLowerCase.startsWith("mac os x")) {
- // Assume X11 platform -- should probably test for these explicitly
- boolean exceptionOccurred = true;
+ } catch (Exception e) { }
+
+ if(TYPE_X11.equals(getNativeWindowType())) {
+ // Assume X11 platform -- should probably test for these explicitly
+ NativeWindowFactory _factory = null;
+ if (componentClass != null) {
try {
Constructor factoryConstructor =
NWReflection.getConstructor("com.sun.nativewindow.impl.x11.awt.X11AWTNativeWindowFactory", new Class[] {});
- factory = (NativeWindowFactory) factoryConstructor.newInstance(null);
- exceptionOccurred = false;
+ _factory = (NativeWindowFactory) factoryConstructor.newInstance(null);
} catch (Exception e) { }
- if (exceptionOccurred) {
- // Try the non-AWT X11 native window factory
- try {
- Constructor factoryConstructor =
- NWReflection.getConstructor("com.sun.nativewindow.impl.x11.X11NativeWindowFactory", new Class[] {});
- factory = (NativeWindowFactory) factoryConstructor.newInstance(null);
- } catch (Exception e) { }
- }
}
- registerFactory(componentClass, factory);
- defaultFactory = factory;
+ if (null ==_factory) {
+ // Try the non-AWT X11 native window factory
+ try {
+ Constructor factoryConstructor =
+ NWReflection.getConstructor("com.sun.nativewindow.impl.x11.X11NativeWindowFactory", new Class[] {});
+ _factory = (NativeWindowFactory) factoryConstructor.newInstance(null);
+ } catch (Exception e) { }
+ }
+ if (null !=_factory) {
+ factory = _factory;
+ }
}
+ registerFactory(componentClass, factory);
+ defaultFactory = factory;
}
}
+ public static String getNativeWindowType() {
+ if(null==nativeWindowingType) {
+ String osName = System.getProperty("nativewindow.ws.name");
+ if(null==osName||osName.length()==0) {
+ osName = System.getProperty("os.name");
+ }
+ String osNameLowerCase = osName.toLowerCase();
+ String windowType;
+ if (osNameLowerCase.startsWith("kd")) {
+ nativeWindowingType = NativeWindowFactory.TYPE_EGL;
+ } else if (osNameLowerCase.startsWith("wind")) {
+ nativeWindowingType = NativeWindowFactory.TYPE_WINDOWS;
+ } else if (osNameLowerCase.startsWith("mac os x") ||
+ osNameLowerCase.startsWith("darwin")) {
+ nativeWindowingType = NativeWindowFactory.TYPE_MACOSX;
+ } else if (osNameLowerCase.equals("awt")) {
+ nativeWindowingType = NativeWindowFactory.TYPE_AWT;
+ } else {
+ nativeWindowingType = NativeWindowFactory.TYPE_X11;
+ }
+ }
+ return nativeWindowingType;
+ }
+
/** Sets the default NativeWindowFactory. Certain operations on
X11 platforms require synchronization, and the implementation
of this synchronization may be specific to the window toolkit
@@ -168,12 +210,15 @@ public abstract class NativeWindowFactory {
registeredFactories.put(windowClass, factory);
}
- /** Converts the given window object into a {@link NativeWindow
- NativeWindow} which can be operated upon by the {@link
- GLDrawableFactory GLDrawableFactory}. The object may be a
+ /** Converts the given window object and it's optional
+ {@link AbstractGraphicsConfiguration AbstractGraphicsConfiguration} into a
+ {@link NativeWindow NativeWindow} which can be operated upon by the
+ {@link GLDrawableFactory GLDrawableFactory}. The object may be a
component for a particular window toolkit, such as an AWT
- Canvas. It may also be a NativeWindow object, in which no
- conversion is necessary. The particular implementation of the
+ Canvas. In this case {@link AbstractGraphicsConfiguration AbstractGraphicsConfiguration}
+ must be valid. It may also be a NativeWindow object, in which no
+ conversion is necessary and {@link AbstractGraphicsConfiguration AbstractGraphicsConfiguration}
+ will be ignored. The particular implementation of the
NativeWindowFactory is responsible for handling objects from a
particular window toolkit. The built-in NativeWindowFactory
handles NativeWindow instances as well as AWT Components.
@@ -181,19 +226,21 @@ public abstract class NativeWindowFactory {
@throws IllegalArgumentException if the given window object
could not be handled by any of the registered
NativeWindowFactory instances
+
+ @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen)
*/
- public static NativeWindow getNativeWindow(Object winObj) throws IllegalArgumentException, NativeWindowException {
+ public static NativeWindow getNativeWindow(Object winObj, AbstractGraphicsConfiguration config) throws IllegalArgumentException, NativeWindowException {
if (winObj == null) {
throw new IllegalArgumentException("Null window object");
}
- return getFactory(winObj.getClass()).getNativeWindowImpl(winObj);
+ return getFactory(winObj.getClass()).getNativeWindowImpl(winObj, config);
}
/** Performs the conversion from a toolkit's window object to a
NativeWindow. Implementors of concrete NativeWindowFactory
subclasses should override this method. */
- protected abstract NativeWindow getNativeWindowImpl(Object winObj) throws IllegalArgumentException;
+ protected abstract NativeWindow getNativeWindowImpl(Object winObj, AbstractGraphicsConfiguration config) throws IllegalArgumentException;
/** Returns the object which provides support for synchronizing
with the underlying window toolkit. On most platforms the
diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
index 389417615..89af0c6f6 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
@@ -39,20 +39,42 @@
package javax.media.nativewindow.awt;
+import javax.media.nativewindow.*;
import java.awt.GraphicsConfiguration;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
/** A wrapper for an AWT GraphicsConfiguration allowing it to be
handled in a toolkit-independent manner. */
-public class AWTGraphicsConfiguration implements AbstractGraphicsConfiguration {
+public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration implements Cloneable {
private GraphicsConfiguration config;
+ AbstractGraphicsConfiguration encapsuled;
- public AWTGraphicsConfiguration(GraphicsConfiguration config) {
+ public AWTGraphicsConfiguration(AWTGraphicsScreen screen, Capabilities caps, GraphicsConfiguration config, AbstractGraphicsConfiguration encapsuled) {
+ super(screen, caps);
this.config = config;
+ this.encapsuled=encapsuled;
+ }
+
+ public AWTGraphicsConfiguration(AWTGraphicsScreen screen, Capabilities caps, GraphicsConfiguration config) {
+ super(screen, caps);
+ this.config = config;
+ this.encapsuled=null;
+ }
+
+ public Object clone() {
+ return super.clone();
}
public GraphicsConfiguration getGraphicsConfiguration() {
return config;
}
+
+ public AbstractGraphicsConfiguration getNativeGraphicsConfiguration() {
+ return (null!=encapsuled)?encapsuled:this;
+ }
+
+ public String toString() {
+ return getClass().toString()+"[" + getScreen() + ", " + getCapabilities() + ", " + config +", encapsuled "+encapsuled+"]";
+ }
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java
index 72c53f550..077cbf8aa 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java
@@ -39,20 +39,48 @@
package javax.media.nativewindow.awt;
+import javax.media.nativewindow.*;
import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
import javax.media.nativewindow.AbstractGraphicsDevice;
+import com.sun.nativewindow.impl.*;
/** A wrapper for an AWT GraphicsDevice allowing it to be
handled in a toolkit-independent manner. */
-public class AWTGraphicsDevice implements AbstractGraphicsDevice {
+public class AWTGraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
private GraphicsDevice device;
- public AWTGraphicsDevice(GraphicsDevice device) {
+ protected AWTGraphicsDevice(GraphicsDevice device) {
+ super(NativeWindowFactory.TYPE_AWT);
this.device = device;
}
+ public static AbstractGraphicsDevice createDevice(GraphicsDevice awtDevice) {
+ if(null==awtDevice) {
+ awtDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ }
+ return new AWTGraphicsDevice(awtDevice);
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+
public GraphicsDevice getGraphicsDevice() {
return device;
}
+
+ /**
+ * In case the native handle was specified, e.g. using X11,
+ * we shall be able to mark it.
+ */
+ public void setHandle(long handle) {
+ this.handle = handle;
+ }
+
+ public String toString() {
+ return getClass().toString()+"[type "+getType()+", awtDevice "+device+", handle 0x"+Long.toHexString(getHandle())+"]";
+ }
}
+
diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java
new file mode 100644
index 000000000..2ad8a99af
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java
@@ -0,0 +1,95 @@
+/*
+ * 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 javax.media.nativewindow.awt;
+
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import com.sun.nativewindow.impl.*;
+
+/** A wrapper for an AWT GraphicsDevice (screen) allowing it to be
+ handled in a toolkit-independent manner. */
+
+public class AWTGraphicsScreen extends DefaultGraphicsScreen implements Cloneable {
+
+ public AWTGraphicsScreen(AWTGraphicsDevice device) {
+ super(device, findScreenIndex(device.getGraphicsDevice()));
+ }
+
+ public static GraphicsDevice getScreenDevice(int index) {
+ if(index<0) return null;
+ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ GraphicsDevice[] gs = ge.getScreenDevices();
+ if(index<gs.length) {
+ return gs[index];
+ }
+ return null;
+ }
+
+ public static int findScreenIndex(GraphicsDevice awtDevice) {
+ if(null==awtDevice) return -1;
+ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ GraphicsDevice[] gs = ge.getScreenDevices();
+ for (int j = 0; j < gs.length; j++) {
+ if(gs[j] == awtDevice) return j;
+ }
+ return -1;
+ }
+
+ public static AbstractGraphicsScreen createScreenDevice(GraphicsDevice awtDevice) {
+ AWTGraphicsDevice device = (AWTGraphicsDevice) AWTGraphicsDevice.createDevice(awtDevice);
+ return new AWTGraphicsScreen(device);
+ }
+
+ public static AbstractGraphicsScreen createScreenDevice(int index) {
+ GraphicsDevice awtDevice = getScreenDevice(index);
+ return createScreenDevice(awtDevice);
+ }
+
+ public static AbstractGraphicsScreen createDefault() {
+ return createScreenDevice(-1);
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+}
+
diff --git a/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java
new file mode 100644
index 000000000..49c337359
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package javax.media.nativewindow.egl;
+
+import javax.media.nativewindow.*;
+
+/** Encapsulates a graphics device on EGL platforms.
+ */
+
+public class EGLGraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
+ /** Constructs a new EGLGraphicsDevice corresponding to the given EGL display handle. */
+ public EGLGraphicsDevice(long eglDisplay) {
+ super(NativeWindowFactory.TYPE_EGL, eglDisplay);
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+}
+
diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java
index 1cf4da42a..8784033bc 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java
@@ -33,6 +33,7 @@
package javax.media.nativewindow.x11;
import javax.media.nativewindow.*;
+import com.sun.nativewindow.impl.x11.XVisualInfo;
/** Encapsulates a graphics configuration, or OpenGL pixel format, on
X11 platforms. Objects of this type are returned from {@link
@@ -40,20 +41,27 @@ import javax.media.nativewindow.*;
NativeWindowFactory.chooseGraphicsConfiguration()} on X11
platforms when toolkits other than the AWT are being used. */
-public class X11GraphicsConfiguration implements AbstractGraphicsConfiguration {
- private long visualID;
+public class X11GraphicsConfiguration extends DefaultGraphicsConfiguration implements Cloneable {
+ private XVisualInfo info;
- /** Constructs a new X11GraphicsConfiguration corresponding to the given visual ID. */
- public X11GraphicsConfiguration(long visualID) {
- this.visualID = visualID;
+ public X11GraphicsConfiguration(X11GraphicsScreen screen, Capabilities caps, XVisualInfo info) {
+ super(screen, caps);
+ this.info = info;
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+
+ public XVisualInfo getXVisualInfo() {
+ return info;
}
- /** Returns the visual ID that this graphics configuration object represents. */
public long getVisualID() {
- return visualID;
+ return (null!=info)?info.visualid():0;
}
public String toString() {
- return "[X11GraphicsConfiguration visualID = " + visualID + "]";
+ return getClass().toString()+"["+getScreen()+", visualID 0x" + Long.toHexString(getVisualID()) + ", " + getCapabilities() +"]";
}
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java
index 5a12e0e62..5e1871b18 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java
@@ -34,22 +34,19 @@ package javax.media.nativewindow.x11;
import javax.media.nativewindow.*;
-/** Encapsulates a graphics device, or screen, on X11
- platforms. Objects of this type are passed to {@link
- NativeWindowFactory#chooseGraphicsConfiguration
- NativeWindowFactory.chooseGraphicsConfiguration()} on X11
- platforms when toolkits other than the AWT are being used. */
+import com.sun.nativewindow.impl.x11.*;
-public class X11GraphicsDevice implements AbstractGraphicsDevice {
- private int screen;
+/** Encapsulates a graphics device on X11 platforms.
+ */
- /** Constructs a new X11GraphicsDevice corresponding to the given screen. */
- public X11GraphicsDevice(int screen) {
- this.screen = screen;
+public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
+ /** Constructs a new X11GraphicsDevice corresponding to the given native display handle. */
+ public X11GraphicsDevice(long display) {
+ super(NativeWindowFactory.TYPE_X11, display);
}
- /** Returns the screen that this graphics device object represents. */
- public int getScreen() {
- return screen;
+ public Object clone() {
+ return super.clone();
}
}
+
diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java
new file mode 100644
index 000000000..1dcc7f026
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+package javax.media.nativewindow.x11;
+
+import javax.media.nativewindow.*;
+
+import com.sun.nativewindow.impl.x11.*;
+
+/** Encapsulates a screen index on X11
+ platforms. Objects of this type are passed to {@link
+ NativeWindowFactory#chooseGraphicsConfiguration
+ NativeWindowFactory.chooseGraphicsConfiguration()} on X11
+ platforms when toolkits other than the AWT are being used. */
+
+public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneable {
+
+ /** Constructs a new X11GraphicsScreen corresponding to the given native screen index. */
+ public X11GraphicsScreen(X11GraphicsDevice device, int screen) {
+ super(device, fetchScreen(screen));
+ }
+
+ public static AbstractGraphicsScreen createScreenDevice(long display, int screenIdx) {
+ if(0==display) throw new NativeWindowException("display is null");
+ return new X11GraphicsScreen(new X11GraphicsDevice(display), screenIdx);
+ }
+
+ public static AbstractGraphicsScreen createDefault() {
+ long display = X11Util.getDefaultDisplay();
+ int scrnIdx = X11Lib.DefaultScreen(display);
+ return createScreenDevice(display, scrnIdx);
+ }
+
+ public long getDefaultVisualID() {
+ long display = X11Util.getDefaultDisplay();
+ int scrnIdx = X11Lib.DefaultScreen(display);
+ return X11Lib.DefaultVisualID(display, scrnIdx);
+ }
+
+ private static int fetchScreen(int screen) {
+ // FIXME NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
+ /*
+ try {
+ if(!com.sun.nativewindow.impl.x11.X11Util.isXineramaEnabled()) {
+ return screen;
+ }
+ } finally {
+ // FIXME NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
+ }
+ return 0;
+ */
+ return screen;
+ }
+
+ public Object clone() {
+ return super.clone();
+ }
+}