aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/com/sun/opengl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2008-06-01 08:17:55 +0000
committerSven Gothel <[email protected]>2008-06-01 08:17:55 +0000
commit806564c9599510db2bb0e2d0e441ca6ad8068aa0 (patch)
tree1e3c4e827f9f9b64f70af277218728cb107b485e /src/classes/com/sun/opengl
parent31d1dd9cd0b0d1b5a0dd7ac61dfe88ee214364a8 (diff)
Refactoring JOGL to partition core windowing, AWT, GL, ES1 and ES2 .. WIP
Compile Clean: X11, noAWT, ES1, no *.impl.x11/win/macosx See jogl/make/build.xml for new build properties. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1654 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/opengl')
-rw-r--r--src/classes/com/sun/opengl/impl/GLContextImpl.java2
-rw-r--r--src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java4
-rw-r--r--src/classes/com/sun/opengl/impl/GLDrawableImpl.java14
-rw-r--r--src/classes/com/sun/opengl/impl/NativeLibLoader.java23
-rw-r--r--src/classes/com/sun/opengl/impl/awt/AWTNativeLibLoader.java71
-rw-r--r--src/classes/com/sun/opengl/impl/awt/JAWTWindow.java156
-rw-r--r--src/classes/com/sun/opengl/impl/awt/JAWT_PlatformInfo.java (renamed from src/classes/com/sun/opengl/impl/JAWT_PlatformInfo.java)4
-rwxr-xr-xsrc/classes/com/sun/opengl/impl/awt/Java2D.java (renamed from src/classes/com/sun/opengl/impl/Java2D.java)4
-rw-r--r--src/classes/com/sun/opengl/impl/awt/Java2DGLContext.java (renamed from src/classes/com/sun/opengl/impl/Java2DGLContext.java)5
-rwxr-xr-xsrc/classes/com/sun/opengl/impl/egl/EGLContext.java2
-rwxr-xr-xsrc/classes/com/sun/opengl/impl/egl/EGLDrawable.java30
-rwxr-xr-xsrc/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java11
-rw-r--r--src/classes/com/sun/opengl/impl/macosx/awt/MacOSXJAWTWindow.java68
-rw-r--r--src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java4
-rw-r--r--src/classes/com/sun/opengl/impl/windows/awt/WindowsJAWTWindow.java68
-rw-r--r--src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java175
-rw-r--r--src/classes/com/sun/opengl/impl/x11/X11OnscreenGLDrawable.java80
-rw-r--r--src/classes/com/sun/opengl/impl/x11/awt/X11AWTGLDrawableFactory.java203
-rw-r--r--src/classes/com/sun/opengl/impl/x11/awt/X11JAWTWindow.java141
-rw-r--r--src/classes/com/sun/opengl/impl/x11/awt/X11SunJDKReflection.java (renamed from src/classes/com/sun/opengl/impl/x11/X11SunJDKReflection.java)4
20 files changed, 763 insertions, 306 deletions
diff --git a/src/classes/com/sun/opengl/impl/GLContextImpl.java b/src/classes/com/sun/opengl/impl/GLContextImpl.java
index 17169ebf2..eb9cf0e55 100644
--- a/src/classes/com/sun/opengl/impl/GLContextImpl.java
+++ b/src/classes/com/sun/opengl/impl/GLContextImpl.java
@@ -326,7 +326,7 @@ public abstract class GLContextImpl extends GLContext {
/** Helper routine which resets a ProcAddressTable generated by the
GLEmitter by looking up anew all of its function pointers. */
protected void resetProcAddressTable(Object table) {
- ProcAddressHelper.resetProcAddressTable(table, GLDrawableFactoryImpl.getFactoryImpl());
+ ProcAddressHelper.resetProcAddressTable(table, (GLDrawableFactoryImpl)getGLDrawable().getFactory());
}
/** Indicates whether the underlying OpenGL context has been
diff --git a/src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java b/src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java
index d0e9118ea..20616f34d 100644
--- a/src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java
+++ b/src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java
@@ -72,10 +72,6 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory implements
super(profile);
}
- public static GLDrawableFactoryImpl getFactoryImpl() {
- return (GLDrawableFactoryImpl) getFactory();
- }
-
// Helper function for more lazily loading the GLU library;
// apparently can't use System.loadLibrary on UNIX because it uses
// RTLD_LOCAL and we need to call dlsym(RTLD_DEFAULT)
diff --git a/src/classes/com/sun/opengl/impl/GLDrawableImpl.java b/src/classes/com/sun/opengl/impl/GLDrawableImpl.java
index df1aab796..690bfd88c 100644
--- a/src/classes/com/sun/opengl/impl/GLDrawableImpl.java
+++ b/src/classes/com/sun/opengl/impl/GLDrawableImpl.java
@@ -42,6 +42,8 @@ package com.sun.opengl.impl;
import javax.media.opengl.*;
public abstract class GLDrawableImpl implements GLDrawable {
+ protected GLDrawableFactory factory;
+ protected NativeWindow component;
private GLCapabilities chosenCapabilities;
/** For offscreen GLDrawables (pbuffers and "pixmap" drawables),
@@ -63,4 +65,16 @@ public abstract class GLDrawableImpl implements GLDrawable {
public void setChosenGLCapabilities(GLCapabilities caps) {
chosenCapabilities = caps;
}
+
+ public NativeWindow getNativeWindow() {
+ return component;
+ }
+
+ public GLDrawableFactory getFactory() {
+ return factory;
+ }
+
+ public String getProfile() {
+ return factory.getProfile();
+ }
}
diff --git a/src/classes/com/sun/opengl/impl/NativeLibLoader.java b/src/classes/com/sun/opengl/impl/NativeLibLoader.java
index ffe8df3e2..aaf782296 100644
--- a/src/classes/com/sun/opengl/impl/NativeLibLoader.java
+++ b/src/classes/com/sun/opengl/impl/NativeLibLoader.java
@@ -115,29 +115,6 @@ public class NativeLibLoader {
});
}
- /* FIXME: refactor Java SE dependencies
- public static void loadAWTImpl() {
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- // Make sure that awt.dll is loaded before loading jawt.dll. Otherwise
- // a Dialog with "awt.dll not found" might pop up.
- // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4481947.
- Toolkit.getDefaultToolkit();
-
- // Must pre-load JAWT on all non-Mac platforms to
- // ensure references from jogl_awt shared object
- // will succeed since JAWT shared object isn't in
- // default library path
- boolean isOSX = System.getProperty("os.name").equals("Mac OS X");
- String[] preload = { "jawt" };
-
- loadLibrary("jogl_awt", preload, !isOSX, false);
- return null;
- }
- });
- }
- */
-
public static void loadCgImpl() {
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
diff --git a/src/classes/com/sun/opengl/impl/awt/AWTNativeLibLoader.java b/src/classes/com/sun/opengl/impl/awt/AWTNativeLibLoader.java
new file mode 100644
index 000000000..5e39c445f
--- /dev/null
+++ b/src/classes/com/sun/opengl/impl/awt/AWTNativeLibLoader.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.sun.opengl.impl.awt;
+
+import com.sun.opengl.impl.*;
+
+import java.awt.Toolkit;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+public class AWTNativeLibLoader extends NativeLibLoader {
+ public static void loadAWTImpl() {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ // Make sure that awt.dll is loaded before loading jawt.dll. Otherwise
+ // a Dialog with "awt.dll not found" might pop up.
+ // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4481947.
+ Toolkit.getDefaultToolkit();
+
+ // Must pre-load JAWT on all non-Mac platforms to
+ // ensure references from jogl_awt shared object
+ // will succeed since JAWT shared object isn't in
+ // default library path
+ boolean isOSX = System.getProperty("os.name").equals("Mac OS X");
+ String[] preload = { "jawt" };
+
+ loadLibrary("jogl_awt", preload, !isOSX, false);
+ return null;
+ }
+ });
+ }
+}
diff --git a/src/classes/com/sun/opengl/impl/awt/JAWTWindow.java b/src/classes/com/sun/opengl/impl/awt/JAWTWindow.java
new file mode 100644
index 000000000..068088f71
--- /dev/null
+++ b/src/classes/com/sun/opengl/impl/awt/JAWTWindow.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.sun.opengl.impl.awt;
+
+import com.sun.opengl.impl.*;
+
+import java.awt.Component;
+import javax.media.opengl.*;
+import com.sun.opengl.impl.*;
+
+public abstract class JAWTWindow implements NativeWindow {
+ protected static final boolean DEBUG = Debug.debug("GLDrawable");
+
+ // lifetime: forever
+ protected Component component;
+ protected boolean locked;
+
+ // lifetime: valid while locked
+ protected long display;
+ protected long screen;
+ protected long drawable;
+ // lifetime: valid after lock, forever
+ protected long visualID;
+ protected int screenIndex;
+
+ public JAWTWindow(Object comp) {
+ init(comp);
+ }
+
+ protected void init(Object windowObject) throws NativeWindowException {
+ this.locked = false;
+ this.component = (Component)comp;
+ this.display= null;
+ this.screen= null;
+ this.screenIndex = -1;
+ this.drawable= null;
+ this.visualID = 0;
+ initNative();
+ }
+
+ public abstract boolean initNative() throws NativeWindowException;
+
+ public boolean lockSurface() throws NativeWindowException {
+ if (locked) {
+ throw new NativeWindowException("Surface already locked");
+ }
+ locked = true;
+ }
+
+ public void unlockSurface() {
+ if (!locked) {
+ throw new NativeWindowException("Surface already locked");
+ }
+ locked = false;
+ display= null;
+ screen= null;
+ drawable= null;
+ }
+
+ public boolean isSurfaceLocked() {
+ return locked;
+ }
+
+ public long getDisplayHandle() {
+ return display;
+ }
+ public long getScreenHandle() {
+ return screen;
+ }
+ public int getScreenIndex() {
+ return screenIndex;
+ }
+ public long getWindowHandle() {
+ return drawable;
+ }
+ public long getVisualID() {
+ return visualID;
+ }
+
+ public void setSize(int width, int height) {
+ component.setSize(width, height);
+ }
+
+ public int getWidth() {
+ return component.getWidth();
+ }
+
+ public int getHeight() {
+ return component.getHeight();
+ }
+
+ public int getX() {
+ return component.getX();
+ }
+ public int getY() {
+ return component.getY();
+ }
+
+ public void setPosition(int x, int y) {
+ component.setLocation(x,y);
+ }
+
+ public void setVisible(boolean visible) {
+ component.setVisible(visible);
+ }
+
+ public boolean isVisible() {
+ return component.isVisible();
+ }
+
+ public boolean setFullscreen(boolean fullscreen) {
+ return false; // FIXME
+ }
+
+ public boolean isFullscreen() {
+ return false; // FIXME
+ }
+
+}
diff --git a/src/classes/com/sun/opengl/impl/JAWT_PlatformInfo.java b/src/classes/com/sun/opengl/impl/awt/JAWT_PlatformInfo.java
index ca101eff9..cd80c1be9 100644
--- a/src/classes/com/sun/opengl/impl/JAWT_PlatformInfo.java
+++ b/src/classes/com/sun/opengl/impl/awt/JAWT_PlatformInfo.java
@@ -37,7 +37,9 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.sun.opengl.impl;
+package com.sun.opengl.impl.awt;
+
+import com.sun.opengl.impl.*;
/** Marker class for all window system-specific JAWT data structures. */
diff --git a/src/classes/com/sun/opengl/impl/Java2D.java b/src/classes/com/sun/opengl/impl/awt/Java2D.java
index 713effa67..ed0a80f00 100755
--- a/src/classes/com/sun/opengl/impl/Java2D.java
+++ b/src/classes/com/sun/opengl/impl/awt/Java2D.java
@@ -37,7 +37,9 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.sun.opengl.impl;
+package com.sun.opengl.impl.awt;
+
+import com.sun.opengl.impl.*;
import java.awt.*;
import java.awt.image.*;
diff --git a/src/classes/com/sun/opengl/impl/Java2DGLContext.java b/src/classes/com/sun/opengl/impl/awt/Java2DGLContext.java
index 86bcb6482..48461c116 100644
--- a/src/classes/com/sun/opengl/impl/Java2DGLContext.java
+++ b/src/classes/com/sun/opengl/impl/awt/Java2DGLContext.java
@@ -37,8 +37,9 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.sun.opengl.impl;
+package com.sun.opengl.impl.awt;
+import com.sun.opengl.impl.*;
import java.awt.Graphics;
/** Provides a construct by which the shared GLJPanel code can
@@ -48,4 +49,4 @@ import java.awt.Graphics;
public interface Java2DGLContext {
public void setGraphics(Graphics g);
-} \ No newline at end of file
+}
diff --git a/src/classes/com/sun/opengl/impl/egl/EGLContext.java b/src/classes/com/sun/opengl/impl/egl/EGLContext.java
index 25ac2c726..ab0fbb304 100755
--- a/src/classes/com/sun/opengl/impl/egl/EGLContext.java
+++ b/src/classes/com/sun/opengl/impl/egl/EGLContext.java
@@ -122,7 +122,7 @@ public class EGLContext extends GLContextImpl {
}
}
- EGLDrawableFactory factory = (EGLDrawableFactory) GLDrawableFactory.getFactory();
+ EGLDrawableFactory factory = (EGLDrawableFactory) drawable.getFactory();
boolean isGLES2 = EGLDrawableFactory.PROFILE_GLES2.equals(factory.getProfile());
int[] contextAttrs = null;
// FIXME: need to determine whether to specify the context
diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java
index 8ac790157..0227ba32f 100755
--- a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java
+++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java
@@ -35,12 +35,11 @@
package com.sun.opengl.impl.egl;
+import com.sun.opengl.impl.GLDrawableImpl;
+
import javax.media.opengl.*;
-public class EGLDrawable implements GLDrawable {
- private long windowHandle;
- private long screenHandle;
- private long displayHandle;
+public class EGLDrawable extends GLDrawableImpl {
private long display;
private GLCapabilities capabilities;
private GLCapabilitiesChooser chooser;
@@ -48,21 +47,16 @@ public class EGLDrawable implements GLDrawable {
private long surface;
private int[] tmp = new int[1];
- public EGLDrawable(long displayHandle,
- long screenHandle,
- long windowHandle,
+ public EGLDrawable(EGLDrawableFactory factory,
+ NativeWindow component,
GLCapabilities capabilities,
GLCapabilitiesChooser chooser) throws GLException {
- this.displayHandle = displayHandle;
- this.screenHandle = screenHandle;
- this.windowHandle = windowHandle;
+ this.factory = factory;
+ this.component = component;
this.capabilities = capabilities;
this.chooser = chooser;
- // Set things up
- EGLDrawableFactory factory = (EGLDrawableFactory) GLDrawableFactory.getFactory();
-
- display = EGL.eglGetDisplay((displayHandle>0)?displayHandle:EGL.EGL_DEFAULT_DISPLAY);
+ display = EGL.eglGetDisplay((component.getDisplayHandle()>0)?component.getDisplayHandle():EGL.EGL_DEFAULT_DISPLAY);
if (display == EGL.EGL_NO_DISPLAY) {
throw new GLException("eglGetDisplay failed");
}
@@ -108,7 +102,7 @@ public class EGLDrawable implements GLDrawable {
public void setRealized(boolean realized) {
if (realized) {
// Create the window surface
- surface = EGL.eglCreateWindowSurface(display, config, windowHandle, null);
+ surface = EGL.eglCreateWindowSurface(display, config, component.getWindowHandle(), null);
if (surface == EGL.EGL_NO_SURFACE) {
throw new GLException("Creation of window surface (eglCreateWindowSurface) failed");
}
@@ -153,9 +147,9 @@ public class EGLDrawable implements GLDrawable {
}
public String toString() {
- return "EGLDrawable[ displayHandle " + displayHandle +
- ", screenHandle "+ screenHandle +
- ", windowHandle "+ windowHandle +
+ return "EGLDrawable[ displayHandle " + component.getDisplayHandle() +
+ ", screenHandle "+ component.getScreenHandle() +
+ ", windowHandle "+ component.getWindowHandle() +
", display " + display +
", config " + config +
", surface " + surface +
diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java
index 516f6d5a9..bd0f83a3c 100755
--- a/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java
+++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java
@@ -102,17 +102,10 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl {
return null;
}
- public GLDrawable getGLDrawable(Object target,
+ public GLDrawable createGLDrawable(NativeWindow target,
GLCapabilities capabilities,
GLCapabilitiesChooser chooser) {
- if( !(target instanceof long[]) ) {
- throw new GLException("target is not instanceof long[]");
- }
- long[] targetHandles = (long[])target;
- if(targetHandles.length!=3) {
- throw new GLException("target handle array != 3 [display, screen, window]");
- }
- return new EGLDrawable(targetHandles[0], targetHandles[1], targetHandles[2],
+ return new EGLDrawable(this, target,
capabilities,
chooser);
}
diff --git a/src/classes/com/sun/opengl/impl/macosx/awt/MacOSXJAWTWindow.java b/src/classes/com/sun/opengl/impl/macosx/awt/MacOSXJAWTWindow.java
new file mode 100644
index 000000000..5f676a138
--- /dev/null
+++ b/src/classes/com/sun/opengl/impl/macosx/awt/MacOSXJAWTWindow.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.sun.opengl.impl.macosx.awt;
+
+import com.sun.opengl.impl.macosx.*;
+import com.sun.opengl.impl.awt.*;
+
+import javax.media.opengl.*;
+import com.sun.opengl.impl.*;
+
+public class MacOSXJAWTWindow extends JAWTWindow {
+
+ // Variables for lockSurface/unlockSurface
+ //private JAWT_DrawingSurface ds;
+ //private JAWT_DrawingSurfaceInfo dsi;
+ //private JAWT_MacOSXDrawingSurfaceInfo x11dsi;
+
+ public MacOSXJAWTWindow(Object comp) {
+ super(comp);
+ }
+
+ public int lockSurface() throws NativeWindowException {
+ super.lockSurface();
+ return 0;
+ }
+
+ public void unlockSurface() {
+ super.unlockSurface();
+ }
+}
+
diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java
index ddccfda4f..1ce39ed33 100644
--- a/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java
+++ b/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java
@@ -70,7 +70,7 @@ public class WindowsGLDrawableFactory extends GLDrawableFactoryImpl {
return null;
}
- public GLDrawable getGLDrawable(Object target,
+ public GLDrawable createGLDrawable(NativeWindow target,
GLCapabilities capabilities,
GLCapabilitiesChooser chooser) {
if (target == null) {
@@ -86,7 +86,7 @@ public class WindowsGLDrawableFactory extends GLDrawableFactoryImpl {
if (chooser == null) {
chooser = new DefaultGLCapabilitiesChooser();
}
- return new WindowsOnscreenGLDrawable((Component) target, capabilities, chooser);
+ return new WindowsOnscreenGLDrawable(getProfile(), target, capabilities, chooser);
}
public GLDrawableImpl createOffscreenDrawable(GLCapabilities capabilities,
diff --git a/src/classes/com/sun/opengl/impl/windows/awt/WindowsJAWTWindow.java b/src/classes/com/sun/opengl/impl/windows/awt/WindowsJAWTWindow.java
new file mode 100644
index 000000000..68ef2702b
--- /dev/null
+++ b/src/classes/com/sun/opengl/impl/windows/awt/WindowsJAWTWindow.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.sun.opengl.impl.windows.awt;
+
+import com.sun.opengl.impl.windows.*;
+import com.sun.opengl.impl.awt.*;
+
+import javax.media.opengl.*;
+import com.sun.opengl.impl.*;
+
+public class WindowsJAWTWindow extends JAWTWindow {
+
+ // Variables for lockSurface/unlockSurface
+ //private JAWT_DrawingSurface ds;
+ //private JAWT_DrawingSurfaceInfo dsi;
+ //private JAWT_WindowsDrawingSurfaceInfo x11dsi;
+
+ public WindowsJAWTWindow(Object comp) {
+ super(comp);
+ }
+
+ public int lockSurface() throws NativeWindowException {
+ super.lockSurface();
+ return 0;
+ }
+
+ public void unlockSurface() {
+ super.unlockSurface();
+ }
+}
+
diff --git a/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java b/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java
index dcb9a0b37..1505e60d6 100644
--- a/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java
+++ b/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java
@@ -39,11 +39,6 @@
package com.sun.opengl.impl.x11;
-import java.awt.Component;
-import java.awt.Graphics;
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsDevice;
-import java.awt.GraphicsEnvironment;
import java.nio.*;
import java.security.*;
import java.util.*;
@@ -59,9 +54,6 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl {
// in this case
private static boolean isVendorATI;
- // See whether we're running in headless mode
- private static boolean isHeadless;
-
// Map for rediscovering the GLCapabilities associated with a
// particular screen and visualID after the fact
private static Map visualToGLCapsMap = Collections.synchronizedMap(new HashMap());
@@ -101,8 +93,6 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl {
com.sun.opengl.impl.NativeLibLoader.loadCore();
DRIHack.end();
-
- isHeadless = GraphicsEnvironment.isHeadless();
}
public X11GLDrawableFactory(String profile) {
@@ -117,134 +107,18 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl {
public AbstractGraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities,
GLCapabilitiesChooser chooser,
AbstractGraphicsDevice absDevice) {
- if (capabilities == null) {
- capabilities = new GLCapabilities();
- }
- if (chooser == null) {
- chooser = new DefaultGLCapabilitiesChooser();
- }
- GraphicsDevice device = null;
- if (absDevice != null &&
- !(absDevice instanceof AWTGraphicsDevice)) {
- throw new IllegalArgumentException("This GLDrawableFactory accepts only AWTGraphicsDevice objects");
- }
-
- if ((absDevice == null) ||
- (((AWTGraphicsDevice) absDevice).getGraphicsDevice() == null)) {
- device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
- } else {
- device = ((AWTGraphicsDevice) absDevice).getGraphicsDevice();
- }
-
- int screen;
- if (isXineramaEnabled()) {
- screen = 0;
- } else {
- screen = X11SunJDKReflection.graphicsDeviceGetScreen(device);
- }
-
- // Until we have a rock-solid visual selection algorithm written
- // in pure Java, we're going to provide the underlying window
- // system's selection to the chooser as a hint
-
- int[] attribs = glCapabilities2AttribList(capabilities, isMultisampleAvailable(), false, 0, 0);
- XVisualInfo[] infos = null;
- GLCapabilities[] caps = null;
- int recommendedIndex = -1;
- lockToolkit();
- try {
- long display = getDisplayConnection();
- XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs, 0);
- if (DEBUG) {
- System.err.print("!!! glXChooseVisual recommended ");
- if (recommendedVis == null) {
- System.err.println("null visual");
- } else {
- System.err.println("visual id 0x" + Long.toHexString(recommendedVis.visualid()));
- }
- }
- int[] count = new int[1];
- XVisualInfo template = XVisualInfo.create();
- template.screen(screen);
- infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count, 0);
- if (infos == null) {
- throw new GLException("Error while enumerating available XVisualInfos");
- }
- caps = new GLCapabilities[infos.length];
- for (int i = 0; i < infos.length; i++) {
- caps[i] = xvi2GLCapabilities(display, infos[i]);
- // Attempt to find the visual chosen by glXChooseVisual
- if (recommendedVis != null && recommendedVis.visualid() == infos[i].visualid()) {
- recommendedIndex = i;
- }
- }
- } finally {
- unlockToolkit();
- }
- // Store these away for later
- for (int i = 0; i < infos.length; i++) {
- if (caps[i] != null) {
- visualToGLCapsMap.put(new ScreenAndVisualIDKey(screen, infos[i].visualid()),
- caps[i].clone());
- }
- }
- int chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex);
- if (chosen < 0 || chosen >= caps.length) {
- throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")");
- }
- XVisualInfo vis = infos[chosen];
- if (vis == null) {
- throw new GLException("GLCapabilitiesChooser chose an invalid visual");
- }
- // FIXME: need to look at glue code and see type of this field
- long visualID = vis.visualid();
- // FIXME: the storage for the infos array, as well as that for the
- // recommended visual, is leaked; should free them here with XFree()
-
- // Now figure out which GraphicsConfiguration corresponds to this
- // visual by matching the visual ID
- GraphicsConfiguration[] configs = device.getConfigurations();
- for (int i = 0; i < configs.length; i++) {
- GraphicsConfiguration config = configs[i];
- if (config != null) {
- if (X11SunJDKReflection.graphicsConfigurationGetVisualID(config) == visualID) {
- return new AWTGraphicsConfiguration(config);
- }
- }
- }
-
- // Either we weren't able to reflectively introspect on the
- // X11GraphicsConfig or something went wrong in the steps above;
- // we're going to return null without signaling an error condition
- // in this case (although we should distinguish between the two
- // and possibly report more of an error in the latter case)
return null;
}
- public GLDrawable getGLDrawable(Object target,
- GLCapabilities capabilities,
- GLCapabilitiesChooser chooser) {
+ public GLDrawable createGLDrawable(NativeWindow target,
+ GLCapabilities capabilities,
+ GLCapabilitiesChooser chooser) {
if (target == null) {
throw new IllegalArgumentException("Null target");
}
- if (!(target instanceof Component)) {
- throw new IllegalArgumentException("GLDrawables not supported for objects of type " +
- target.getClass().getName() + " (only Components are supported in this implementation)");
- }
- Component comp = (Component) target;
- X11OnscreenGLDrawable drawable = new X11OnscreenGLDrawable(comp);
- // Figure out the GLCapabilities of this component
- GraphicsConfiguration config = comp.getGraphicsConfiguration();
- if (config == null) {
- throw new IllegalArgumentException("GLDrawableFactory.chooseGraphicsConfiguration() was not used when creating this Component");
- }
- int visualID = X11SunJDKReflection.graphicsConfigurationGetVisualID(config);
- int screen;
- if (isXineramaEnabled()) {
- screen = 0;
- } else {
- screen = X11SunJDKReflection.graphicsDeviceGetScreen(config.getDevice());
- }
+ X11OnscreenGLDrawable drawable = new X11OnscreenGLDrawable(getProfile(), target);
+ int visualID = target.getVisualID();
+ int screen = target.getScreenIndex();
drawable.setChosenGLCapabilities((GLCapabilities) visualToGLCapsMap.get(new ScreenAndVisualIDKey(screen, visualID)));
return drawable;
}
@@ -551,29 +425,9 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl {
}
public void lockToolkit() {
- if (isHeadless) {
- // Workaround for running (to some degree) in headless
- // environments but still supporting rendering via pbuffers
- // For full correctness, would need to implement a Lock class
- return;
- }
-
- if (!Java2D.isOGLPipelineActive() || !Java2D.isQueueFlusherThread()) {
- JAWT.getJAWT().Lock();
- }
}
public void unlockToolkit() {
- if (isHeadless) {
- // Workaround for running (to some degree) in headless
- // environments but still supporting rendering via pbuffers
- // For full correctness, would need to implement a Lock class
- return;
- }
-
- if (!Java2D.isOGLPipelineActive() || !Java2D.isQueueFlusherThread()) {
- JAWT.getJAWT().Unlock();
- }
}
public void lockAWTForJava2D() {
@@ -682,23 +536,6 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl {
throw new GLException("Unimplemented on this platform");
}
- //---------------------------------------------------------------------------
- // Xinerama-related functionality
- //
-
- private boolean checkedXinerama;
- private boolean xineramaEnabled;
- protected synchronized boolean isXineramaEnabled() {
- if (!checkedXinerama) {
- checkedXinerama = true;
- lockToolkit();
- long display = getDisplayConnection();
- xineramaEnabled = GLX.XineramaEnabled(display);
- unlockToolkit();
- }
- return xineramaEnabled;
- }
-
//----------------------------------------------------------------------
// Gamma-related functionality
//
diff --git a/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLDrawable.java b/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLDrawable.java
index b1a3ebac7..6ee4d453e 100644
--- a/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLDrawable.java
+++ b/src/classes/com/sun/opengl/impl/x11/X11OnscreenGLDrawable.java
@@ -39,23 +39,12 @@
package com.sun.opengl.impl.x11;
-import java.awt.Component;
-
import javax.media.opengl.*;
import com.sun.opengl.impl.*;
public class X11OnscreenGLDrawable extends X11GLDrawable {
- public static final int LOCK_SURFACE_NOT_READY = 1;
- public static final int LOCK_SURFACE_CHANGED = 2;
- public static final int LOCK_SUCCESS = 3;
-
- protected Component component;
+ protected NativeWindow component;
- // Variables for lockSurface/unlockSurface
- private JAWT_DrawingSurface ds;
- private JAWT_DrawingSurfaceInfo dsi;
- private JAWT_X11DrawingSurfaceInfo x11dsi;
-
// Indicates whether the component (if an onscreen context) has been
// realized. Plausibly, before the component is realized the JAWT
// should return an error or NULL object from some of its
@@ -68,7 +57,7 @@ public class X11OnscreenGLDrawable extends X11GLDrawable {
// addNotify() is called on the component.
protected boolean realized;
- public X11OnscreenGLDrawable(Component component) {
+ public X11OnscreenGLDrawable(NativeWindow component) {
super(null, null);
this.component = component;
}
@@ -98,7 +87,7 @@ public class X11OnscreenGLDrawable extends X11GLDrawable {
try {
boolean didLock = false;
- if (drawable == 0) {
+ if (component.getWindowHandle() == 0) {
if (lockSurface() == LOCK_SURFACE_NOT_READY) {
return;
}
@@ -106,7 +95,7 @@ public class X11OnscreenGLDrawable extends X11GLDrawable {
didLock = true;
}
- GLX.glXSwapBuffers(display, drawable);
+ GLX.glXSwapBuffers(component.getDisplayHandle(), component.getWindowHandle());
if (didLock) {
unlockSurface();
@@ -120,67 +109,10 @@ public class X11OnscreenGLDrawable extends X11GLDrawable {
if (!realized) {
return LOCK_SURFACE_NOT_READY;
}
- if (drawable != 0) {
- throw new GLException("Surface already locked");
- }
- ds = JAWT.getJAWT().GetDrawingSurface(component);
- if (ds == null) {
- // Widget not yet realized
- return LOCK_SURFACE_NOT_READY;
- }
- int res = ds.Lock();
- if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) {
- throw new GLException("Unable to lock surface");
- }
- // See whether the surface changed and if so destroy the old
- // OpenGL context so it will be recreated (NOTE: removeNotify
- // should handle this case, but it may be possible that race
- // conditions can cause this code to be triggered -- should test
- // more)
- int ret = LOCK_SUCCESS;
- if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) {
- ret = LOCK_SURFACE_CHANGED;
- }
- dsi = ds.GetDrawingSurfaceInfo();
- if (dsi == null) {
- // Widget not yet realized
- ds.Unlock();
- JAWT.getJAWT().FreeDrawingSurface(ds);
- ds = null;
- return LOCK_SURFACE_NOT_READY;
- }
- x11dsi = (JAWT_X11DrawingSurfaceInfo) dsi.platformInfo();
- display = x11dsi.display();
- drawable = x11dsi.drawable();
- visualID = x11dsi.visualID();
- if (display == 0 || drawable == 0) {
- // Widget not yet realized
- ds.FreeDrawingSurfaceInfo(dsi);
- ds.Unlock();
- JAWT.getJAWT().FreeDrawingSurface(ds);
- ds = null;
- dsi = null;
- x11dsi = null;
- display = 0;
- drawable = 0;
- visualID = 0;
- return LOCK_SURFACE_NOT_READY;
- }
- return ret;
+ return component.lockSurface();
}
public void unlockSurface() {
- if (drawable == 0) {
- throw new GLException("Surface already unlocked");
- }
- ds.FreeDrawingSurfaceInfo(dsi);
- ds.Unlock();
- JAWT.getJAWT().FreeDrawingSurface(ds);
- ds = null;
- dsi = null;
- x11dsi = null;
- display = 0;
- drawable = 0;
- visualID = 0;
+ return component.lockSurface();
}
}
diff --git a/src/classes/com/sun/opengl/impl/x11/awt/X11AWTGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/x11/awt/X11AWTGLDrawableFactory.java
new file mode 100644
index 000000000..de61d2315
--- /dev/null
+++ b/src/classes/com/sun/opengl/impl/x11/awt/X11AWTGLDrawableFactory.java
@@ -0,0 +1,203 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.sun.opengl.impl.x11.awt;
+
+import com.sun.opengl.impl.x11.*;
+import java.awt.Graphics;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.nio.*;
+import java.security.*;
+import java.util.*;
+import javax.media.opengl.*;
+import com.sun.gluegen.runtime.*;
+import com.sun.opengl.impl.*;
+
+public class X11AWTGLDrawableFactory extends X11GLDrawableFactory {
+ // See whether we're running in headless mode
+ private static boolean isHeadless;
+
+ static {
+ // See DRIHack.java for an explanation of why this is necessary
+ DRIHack.begin();
+
+ com.sun.opengl.impl.NativeLibLoader.loadCore();
+
+ DRIHack.end();
+
+ isHeadless = GraphicsEnvironment.isHeadless();
+ }
+
+ public AbstractGraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities,
+ GLCapabilitiesChooser chooser,
+ AbstractGraphicsDevice absDevice) {
+ if (capabilities == null) {
+ capabilities = new GLCapabilities();
+ }
+ if (chooser == null) {
+ chooser = new DefaultGLCapabilitiesChooser();
+ }
+ GraphicsDevice device = null;
+ if (absDevice != null &&
+ !(absDevice instanceof AWTGraphicsDevice)) {
+ throw new IllegalArgumentException("This GLDrawableFactory accepts only AWTGraphicsDevice objects");
+ }
+
+ if ((absDevice == null) ||
+ (((AWTGraphicsDevice) absDevice).getGraphicsDevice() == null)) {
+ device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ } else {
+ device = ((AWTGraphicsDevice) absDevice).getGraphicsDevice();
+ }
+
+ int screen;
+ if (isXineramaEnabled()) {
+ screen = 0;
+ } else {
+ screen = X11SunJDKReflection.graphicsDeviceGetScreen(device);
+ }
+
+ // Until we have a rock-solid visual selection algorithm written
+ // in pure Java, we're going to provide the underlying window
+ // system's selection to the chooser as a hint
+
+ int[] attribs = glCapabilities2AttribList(capabilities, isMultisampleAvailable(), false, 0, 0);
+ XVisualInfo[] infos = null;
+ GLCapabilities[] caps = null;
+ int recommendedIndex = -1;
+ lockToolkit();
+ try {
+ long display = getDisplayConnection();
+ XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs, 0);
+ if (DEBUG) {
+ System.err.print("!!! glXChooseVisual recommended ");
+ if (recommendedVis == null) {
+ System.err.println("null visual");
+ } else {
+ System.err.println("visual id 0x" + Long.toHexString(recommendedVis.visualid()));
+ }
+ }
+ int[] count = new int[1];
+ XVisualInfo template = XVisualInfo.create();
+ template.screen(screen);
+ infos = GLX.XGetVisualInfo(display, GLX.VisualScreenMask, template, count, 0);
+ if (infos == null) {
+ throw new GLException("Error while enumerating available XVisualInfos");
+ }
+ caps = new GLCapabilities[infos.length];
+ for (int i = 0; i < infos.length; i++) {
+ caps[i] = xvi2GLCapabilities(display, infos[i]);
+ // Attempt to find the visual chosen by glXChooseVisual
+ if (recommendedVis != null && recommendedVis.visualid() == infos[i].visualid()) {
+ recommendedIndex = i;
+ }
+ }
+ } finally {
+ unlockToolkit();
+ }
+ // Store these away for later
+ for (int i = 0; i < infos.length; i++) {
+ if (caps[i] != null) {
+ visualToGLCapsMap.put(new ScreenAndVisualIDKey(screen, infos[i].visualid()),
+ caps[i].clone());
+ }
+ }
+ int chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex);
+ if (chosen < 0 || chosen >= caps.length) {
+ throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")");
+ }
+ XVisualInfo vis = infos[chosen];
+ if (vis == null) {
+ throw new GLException("GLCapabilitiesChooser chose an invalid visual");
+ }
+ // FIXME: need to look at glue code and see type of this field
+ long visualID = vis.visualid();
+ // FIXME: the storage for the infos array, as well as that for the
+ // recommended visual, is leaked; should free them here with XFree()
+
+ // Now figure out which GraphicsConfiguration corresponds to this
+ // visual by matching the visual ID
+ GraphicsConfiguration[] configs = device.getConfigurations();
+ for (int i = 0; i < configs.length; i++) {
+ GraphicsConfiguration config = configs[i];
+ if (config != null) {
+ if (X11SunJDKReflection.graphicsConfigurationGetVisualID(config) == visualID) {
+ return new AWTGraphicsConfiguration(config);
+ }
+ }
+ }
+
+ // Either we weren't able to reflectively introspect on the
+ // X11GraphicsConfig or something went wrong in the steps above;
+ // we're going to return null without signaling an error condition
+ // in this case (although we should distinguish between the two
+ // and possibly report more of an error in the latter case)
+ return null;
+ }
+
+ public void lockToolkit() {
+ if (isHeadless) {
+ // Workaround for running (to some degree) in headless
+ // environments but still supporting rendering via pbuffers
+ // For full correctness, would need to implement a Lock class
+ return;
+ }
+
+ if (!Java2D.isOGLPipelineActive() || !Java2D.isQueueFlusherThread()) {
+ JAWT.getJAWT().Lock();
+ }
+ }
+
+ public void unlockToolkit() {
+ if (isHeadless) {
+ // Workaround for running (to some degree) in headless
+ // environments but still supporting rendering via pbuffers
+ // For full correctness, would need to implement a Lock class
+ return;
+ }
+
+ if (!Java2D.isOGLPipelineActive() || !Java2D.isQueueFlusherThread()) {
+ JAWT.getJAWT().Unlock();
+ }
+ }
+
+
+}
diff --git a/src/classes/com/sun/opengl/impl/x11/awt/X11JAWTWindow.java b/src/classes/com/sun/opengl/impl/x11/awt/X11JAWTWindow.java
new file mode 100644
index 000000000..2115f383d
--- /dev/null
+++ b/src/classes/com/sun/opengl/impl/x11/awt/X11JAWTWindow.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.sun.opengl.impl.x11.awt;
+
+import com.sun.opengl.impl.x11.*;
+import com.sun.opengl.impl.awt.*;
+
+import javax.media.opengl.*;
+import com.sun.opengl.impl.*;
+
+public class X11JAWTWindow extends JAWTWindow {
+
+ // Variables for lockSurface/unlockSurface
+ private JAWT_DrawingSurface ds;
+ private JAWT_DrawingSurfaceInfo dsi;
+ private JAWT_X11DrawingSurfaceInfo x11dsi;
+
+ //---------------------------------------------------------------------------
+ // Xinerama-related functionality
+ //
+
+ private boolean checkedXinerama;
+ private boolean xineramaEnabled;
+ protected synchronized boolean isXineramaEnabled() {
+ if (!checkedXinerama) {
+ checkedXinerama = true;
+ lockToolkit();
+ long display = getDisplayConnection();
+ xineramaEnabled = GLX.XineramaEnabled(display);
+ unlockToolkit();
+ }
+ return xineramaEnabled;
+ }
+
+ public X11JAWTWindow(Object comp) {
+ super(comp);
+ }
+
+ public int lockSurface() throws NativeWindowException {
+ super.lockSurface();
+ ds = JAWT.getJAWT().GetDrawingSurface(component);
+ if (ds == null) {
+ // Widget not yet realized
+ return LOCK_SURFACE_NOT_READY;
+ }
+ int res = ds.Lock();
+ if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) {
+ throw new NativeWindowException("Unable to lock surface");
+ }
+ // See whether the surface changed and if so destroy the old
+ // OpenGL context so it will be recreated (NOTE: removeNotify
+ // should handle this case, but it may be possible that race
+ // conditions can cause this code to be triggered -- should test
+ // more)
+ int ret = LOCK_SUCCESS;
+ if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) {
+ ret = LOCK_SURFACE_CHANGED;
+ }
+ dsi = ds.GetDrawingSurfaceInfo();
+ if (dsi == null) {
+ // Widget not yet realized
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ return LOCK_SURFACE_NOT_READY;
+ }
+ x11dsi = (JAWT_X11DrawingSurfaceInfo) dsi.platformInfo();
+ display = x11dsi.display();
+ drawable = x11dsi.drawable();
+ visualID = x11dsi.visualID();
+ screen= null;
+ if (isXineramaEnabled()) {
+ screenIndex = 0;
+ } else {
+ screenIndex = X11SunJDKReflection.graphicsDeviceGetScreen(config.getDevice());
+ }
+ if (display == 0 || drawable == 0) {
+ // Widget not yet realized
+ ds.FreeDrawingSurfaceInfo(dsi);
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ dsi = null;
+ x11dsi = null;
+ display = 0;
+ drawable = 0;
+ visualID = 0;
+ screen= null;
+ screenIndex = -1;
+ return LOCK_SURFACE_NOT_READY;
+ }
+ return ret;
+ }
+
+ public void unlockSurface() {
+ super.unlockSurface();
+ ds.FreeDrawingSurfaceInfo(dsi);
+ ds.Unlock();
+ JAWT.getJAWT().FreeDrawingSurface(ds);
+ ds = null;
+ dsi = null;
+ x11dsi = null;
+ }
+}
diff --git a/src/classes/com/sun/opengl/impl/x11/X11SunJDKReflection.java b/src/classes/com/sun/opengl/impl/x11/awt/X11SunJDKReflection.java
index 0760399ab..5e19bfbb5 100644
--- a/src/classes/com/sun/opengl/impl/x11/X11SunJDKReflection.java
+++ b/src/classes/com/sun/opengl/impl/x11/awt/X11SunJDKReflection.java
@@ -37,7 +37,9 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package com.sun.opengl.impl.x11;
+package com.sun.opengl.impl.x11.awt;
+
+import com.sun.opengl.impl.x11.*;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;