aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rwxr-xr-xsrc/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java4
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/Display.java42
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/NewtFactory.java80
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/Screen.java44
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/Window.java143
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/windows/WindowsDisplay.java46
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/windows/WindowsScreen.java46
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/windows/WindowsWindow.java24
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/x11/X11Display.java59
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/x11/X11Screen.java59
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/x11/X11Window.java61
-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
-rw-r--r--src/classes/javax/media/opengl/GLAutoDrawable.java2
-rw-r--r--src/classes/javax/media/opengl/GLDrawable.java6
-rw-r--r--src/classes/javax/media/opengl/GLDrawableFactory.java114
-rw-r--r--src/classes/javax/media/opengl/NativeWindow.java68
-rw-r--r--src/classes/javax/media/opengl/NativeWindowException.java68
-rw-r--r--src/classes/javax/media/opengl/NativeWindowFactory.java140
-rw-r--r--src/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java46
-rw-r--r--src/classes/javax/media/opengl/awt/AWTGraphicsConfiguration.java (renamed from src/classes/javax/media/opengl/AWTGraphicsConfiguration.java)3
-rw-r--r--src/classes/javax/media/opengl/awt/AWTGraphicsDevice.java (renamed from src/classes/javax/media/opengl/AWTGraphicsDevice.java)3
-rw-r--r--src/classes/javax/media/opengl/awt/ComponentEvents.java (renamed from src/classes/javax/media/opengl/ComponentEvents.java)3
-rw-r--r--src/classes/javax/media/opengl/awt/GLCanvas.java (renamed from src/classes/javax/media/opengl/GLCanvas.java)13
-rw-r--r--src/classes/javax/media/opengl/awt/GLJPanel.java (renamed from src/classes/javax/media/opengl/GLJPanel.java)6
-rwxr-xr-xsrc/native/jogl/X11Window.c227
44 files changed, 1834 insertions, 542 deletions
diff --git a/src/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java b/src/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java
index e4ade6375..2040c55d1 100755
--- a/src/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java
+++ b/src/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java
@@ -44,7 +44,9 @@ public class TestSpatialization {
try {
// FIXME: this is a hack to get the native library loaded
- GLDrawableFactory.getFactory();
+ try {
+ GLDrawableFactory.getFactory(GLDrawableFactory.PROFILE_GLES1, null);
+ } catch (Exception e) {}
// Initialize the audio subsystem
Audio audio = Audio.getInstance();
// Create a track
diff --git a/src/classes/com/sun/javafx/newt/Display.java b/src/classes/com/sun/javafx/newt/Display.java
index 7be9a1b12..5ec2c381a 100755
--- a/src/classes/com/sun/javafx/newt/Display.java
+++ b/src/classes/com/sun/javafx/newt/Display.java
@@ -33,16 +33,33 @@
package com.sun.javafx.newt;
-public class Display {
+public abstract class Display {
- public Display() {
- this(null);
+ protected static Display create(String type, String name) {
+ try {
+ Class displayClass = null;
+ if (NewtFactory.KD.equals(type)) {
+ displayClass = Class.forName("com.sun.javafx.newt.kd.KDDisplay");
+ } else if (NewtFactory.WINDOWS.equals(type)) {
+ displayClass = Class.forName("com.sun.javafx.newt.displays.WindowsDisplay");
+ } else if (NewtFactory.X11.equals(type)) {
+ displayClass = Class.forName("com.sun.javafx.newt.x11.X11Display");
+ } else if (NewtFactory.MACOSX.equals(type)) {
+ displayClass = Class.forName("com.sun.javafx.newt.macosx.MacOSXDisplay");
+ } else {
+ throw new RuntimeException("Unknown display type \"" + type + "\"");
+ }
+ Display display = (Display) displayClass.newInstance();
+ display.name=name;
+ display.handle=0;
+ display.initNative();
+ return display;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
- public Display(String name) {
- this.name=name;
- this.handle=-1;
- }
+ protected abstract void initNative();
public String getName() {
return name;
@@ -52,17 +69,6 @@ public class Display {
return handle;
}
- /**
- * native handle
- *
- * write once ..
- */
- public void setHandle(long handle) {
- if(this.handle<0) {
- this.handle=handle;
- }
- }
-
protected String name;
protected long handle;
}
diff --git a/src/classes/com/sun/javafx/newt/NewtFactory.java b/src/classes/com/sun/javafx/newt/NewtFactory.java
new file mode 100755
index 000000000..e0281eafa
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/NewtFactory.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+public abstract class NewtFactory {
+ /** OpenKODE window type */
+ public static final String KD = "KD";
+
+ /** Microsoft Windows window type */
+ public static final String WINDOWS = "Windows";
+
+ /** X11 window type */
+ public static final String X11 = "X11";
+
+ /** Mac OS X window type */
+ public static final String MACOSX = "MacOSX";
+
+ /** Creates a Window of the default type for the current operating system. */
+ public static String getWindowType() {
+ String osName = System.getProperty("os.name");
+ String osNameLowerCase = osName.toLowerCase();
+ String windowType;
+ if (osNameLowerCase.startsWith("wind")) {
+ windowType = WINDOWS;
+ } else if (osNameLowerCase.startsWith("mac os x")) {
+ windowType = MACOSX;
+ } else {
+ windowType = X11;
+ }
+ return windowType;
+ }
+
+ public static Display createDisplay(String name) {
+ return Display.create(getWindowType(), name);
+ }
+
+ public static Screen createScreen(Display display, int index) {
+ return Screen.create(getWindowType(), display, index);
+ }
+
+ public static Window createWindow(Screen screen, long visualID) {
+ return Window.create(getWindowType(), screen, visualID);
+ }
+
+}
+
diff --git a/src/classes/com/sun/javafx/newt/Screen.java b/src/classes/com/sun/javafx/newt/Screen.java
index b698a0248..9252b30d4 100755
--- a/src/classes/com/sun/javafx/newt/Screen.java
+++ b/src/classes/com/sun/javafx/newt/Screen.java
@@ -33,17 +33,34 @@
package com.sun.javafx.newt;
-public class Screen {
+public abstract class Screen {
- public Screen(Display display) {
- this(display, 0);
+ protected static Screen create(String type, Display display, int idx) {
+ try {
+ Class screenClass = null;
+ if (NewtFactory.KD.equals(type)) {
+ screenClass = Class.forName("com.sun.javafx.newt.kd.KDScreen");
+ } else if (NewtFactory.WINDOWS.equals(type)) {
+ screenClass = Class.forName("com.sun.javafx.newt.screens.WindowsScreen");
+ } else if (NewtFactory.X11.equals(type)) {
+ screenClass = Class.forName("com.sun.javafx.newt.x11.X11Screen");
+ } else if (NewtFactory.MACOSX.equals(type)) {
+ screenClass = Class.forName("com.sun.javafx.newt.macosx.MacOSXScreen");
+ } else {
+ throw new RuntimeException("Unknown window type \"" + type + "\"");
+ }
+ Screen screen = (Screen) screenClass.newInstance();
+ screen.display = display;
+ screen.index = idx;
+ screen.handle = 0;
+ screen.initNative();
+ return screen;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
- public Screen(Display display, int idx) {
- this.display=display;
- this.index=idx;
- this.handle=-1;
- }
+ protected abstract void initNative();
public Display getDisplay() {
return display;
@@ -57,17 +74,6 @@ public class Screen {
return handle;
}
- /**
- * native handle
- *
- * write once ..
- */
- public void setHandle(long handle) {
- if(this.handle<0) {
- this.handle=handle;
- }
- }
-
protected Display display;
protected int index;
protected long handle;
diff --git a/src/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java
index 27610cdf2..16984d1f3 100755
--- a/src/classes/com/sun/javafx/newt/Window.java
+++ b/src/classes/com/sun/javafx/newt/Window.java
@@ -33,101 +33,120 @@
package com.sun.javafx.newt;
+import javax.media.opengl.NativeWindow;
+import javax.media.opengl.NativeWindowException;
+
import java.util.ArrayList;
import java.util.Iterator;
-public abstract class Window {
+public abstract class Window implements NativeWindow
+{
public static final boolean DEBUG_MOUSE_EVENT = false;
public static final boolean DEBUG_KEY_EVENT = false;
+ public static final boolean DEBUG_IMPLEMENTATION = true;
- /** OpenKODE window type */
- public static final String KD = "KD";
-
- /** Microsoft Windows window type */
- public static final String WINDOWS = "Windows";
-
- /** X11 window type */
- public static final String X11 = "X11";
-
- /** Mac OS X window type */
- public static final String MACOSX = "MacOSX";
-
- /** Creates a Window of the default type for the current operating system. */
- public static Window create(Screen screen, long visualID) {
- String osName = System.getProperty("os.name");
- String osNameLowerCase = osName.toLowerCase();
- String windowType;
- if (osNameLowerCase.startsWith("wind")) {
- windowType = WINDOWS;
- } else if (osNameLowerCase.startsWith("mac os x")) {
- windowType = MACOSX;
- } else {
- windowType = X11;
- }
- Window window = create(windowType);
- window.initNative(screen, visualID);
- return window;
- }
-
-
- public static Window create(String type) {
+ protected static Window create(String type, Screen screen, long visualID) {
try {
Class windowClass = null;
- if (KD.equals(type)) {
+ if (NewtFactory.KD.equals(type)) {
windowClass = Class.forName("com.sun.javafx.newt.kd.KDWindow");
- } else if (WINDOWS.equals(type)) {
+ } else if (NewtFactory.WINDOWS.equals(type)) {
windowClass = Class.forName("com.sun.javafx.newt.windows.WindowsWindow");
- } else if (X11.equals(type)) {
+ } else if (NewtFactory.X11.equals(type)) {
windowClass = Class.forName("com.sun.javafx.newt.x11.X11Window");
- } else if (MACOSX.equals(type)) {
+ } else if (NewtFactory.MACOSX.equals(type)) {
windowClass = Class.forName("com.sun.javafx.newt.macosx.MacOSXWindow");
} else {
throw new RuntimeException("Unknown window type \"" + type + "\"");
}
- return (Window) windowClass.newInstance();
+ Window window = (Window) windowClass.newInstance();
+ window.screen = screen;
+ window.visualID = visualID;
+ window.windowHandle = 0;
+ window.locked = false;
+ window.initNative();
+ return window;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
+ protected abstract void initNative();
- /**
- * [ display, screen, window ]
- */
- public long[] getHandles() {
- long[] handles = new long[3];
- handles[0] = getScreen().getDisplay().getHandle();
- handles[1] = getScreen().getHandle();
- handles[2] = getWindowHandle();
- return handles;
+ public Screen getScreen() {
+ return screen;
}
- protected abstract void initNative(Screen screen, long visualID);
-
- public abstract void setVisible(boolean visible);
- public abstract void setSize(int width, int height);
- public abstract void setPosition(int x, int y);
- public abstract boolean isVisible();
- public abstract int getWidth();
- public abstract int getHeight();
- public abstract int getX();
- public abstract int getY();
- public abstract boolean setFullscreen(boolean fullscreen);
- public abstract boolean isFullscreen();
public abstract int getDisplayWidth();
public abstract int getDisplayHeight();
- public abstract Screen getScreen();
- public abstract long getWindowHandle();
-
public abstract void pumpMessages();
public String toString() {
- return "Window[handle "+getWindowHandle()+
+ return "Window[handle "+windowHandle+
", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+
", visible "+isVisible()+"]";
}
+ protected Screen screen;
+ protected long visualID;
+ protected long windowHandle;
+ protected boolean locked;
+
+ //
+ // NativeWindow impl
+ //
+
+ public boolean lockSurface() throws NativeWindowException {
+ if (locked) {
+ throw new NativeWindowException("Surface already locked");
+ }
+ locked = true;
+ return true;
+ }
+
+ public void unlockSurface() {
+ if (!locked) {
+ throw new NativeWindowException("Surface already locked");
+ }
+ locked = false;
+ }
+
+ public boolean isSurfaceLocked() {
+ return locked;
+ }
+
+ public long getDisplayHandle() {
+ return screen.getDisplay().getHandle();
+ }
+
+ public long getScreenHandle() {
+ return screen.getHandle();
+ }
+
+ public int getScreenIndex() {
+ return screen.getIndex();
+ }
+
+ public long getWindowHandle() {
+ return windowHandle;
+ }
+
+ public long getVisualID() {
+ return visualID;
+ }
+
+ public abstract int getWidth();
+ public abstract int getHeight();
+ public abstract int getX();
+ public abstract int getY();
+ public abstract void setVisible(boolean visible);
+ public abstract void setSize(int width, int height);
+ public abstract void setPosition(int x, int y);
+ public abstract boolean isVisible();
+ public abstract boolean setFullscreen(boolean fullscreen);
+ public abstract boolean isFullscreen();
+
//
// MouseListener Support
//
diff --git a/src/classes/com/sun/javafx/newt/windows/WindowsDisplay.java b/src/classes/com/sun/javafx/newt/windows/WindowsDisplay.java
new file mode 100755
index 000000000..ce2ac8c4a
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/windows/WindowsDisplay.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt.windows;
+
+import com.sun.javafx.newt.*;
+import com.sun.opengl.impl.*;
+
+public class WindowsDisplay extends Display {
+ public WindowsDisplay() {
+ }
+
+ public void initNative() {
+ handle = 0;
+ }
+}
diff --git a/src/classes/com/sun/javafx/newt/windows/WindowsScreen.java b/src/classes/com/sun/javafx/newt/windows/WindowsScreen.java
new file mode 100755
index 000000000..cf163ce48
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/windows/WindowsScreen.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt.windows;
+
+import com.sun.javafx.newt.*;
+import com.sun.opengl.impl.*;
+
+public class WindowsScreen extends Screen {
+ public WindowsScreen() {
+ }
+
+ public void initNative() {
+ handle = 0;
+ }
+}
diff --git a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
index e170f9b56..c392cb20e 100755
--- a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
+++ b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
@@ -59,22 +59,14 @@ public class WindowsWindow extends Window {
public WindowsWindow() {
}
- public void initNative(Screen screen, long visualID) {
- this.screen = screen;
- this.visualID = visualID;
+ public void initNative() {
long wndClass = getWindowClass();
fullscreen=false;
visible=false;
- window = CreateWindow(WINDOW_CLASS_NAME, getHInstance(), visualID, x, y, width, height);
- if (window == 0) {
+ windowHandle = CreateWindow(WINDOW_CLASS_NAME, getHInstance(), visualID, x, y, width, height);
+ if (windowHandle == 0) {
throw new RuntimeException("Error creating window");
}
- screen.setHandle(0); // dummy
- screen.getDisplay().setHandle(0); // dummy
- }
-
- public Screen getScreen() {
- return screen;
}
public void setVisible(boolean visible) {
@@ -131,10 +123,6 @@ public class WindowsWindow extends Window {
return 480; // FIXME
}
- public long getWindowHandle() {
- return window;
- }
-
public void pumpMessages() {
DispatchMessages(window);
}
@@ -175,12 +163,6 @@ public class WindowsWindow extends Window {
private native void setSize0(long window, int width, int height);
private native boolean setFullScreen0(long window, boolean fullscreen);
- private void keyDown(long key) {
- }
-
- private void keyUp(long key) {
- }
-
private void sizeChanged(int newWidth, int newHeight) {
width = newWidth;
height = newHeight;
diff --git a/src/classes/com/sun/javafx/newt/x11/X11Display.java b/src/classes/com/sun/javafx/newt/x11/X11Display.java
new file mode 100755
index 000000000..5a4ed8eed
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/x11/X11Display.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt.x11;
+
+import com.sun.javafx.newt.*;
+import com.sun.opengl.impl.*;
+
+public class X11Display extends Display {
+ static {
+ NativeLibLoader.loadCore();
+ }
+
+ public X11Display() {
+ }
+
+ public void initNative() {
+ handle = CreateDisplay(name);
+ if (handle == 0 ) {
+ throw new RuntimeException("Error creating display: "+name);
+ }
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+
+ private native long CreateDisplay(String name);
+}
diff --git a/src/classes/com/sun/javafx/newt/x11/X11Screen.java b/src/classes/com/sun/javafx/newt/x11/X11Screen.java
new file mode 100755
index 000000000..279507fab
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/x11/X11Screen.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt.x11;
+
+import com.sun.javafx.newt.*;
+import com.sun.opengl.impl.*;
+
+public class X11Screen extends Screen {
+ static {
+ NativeLibLoader.loadCore();
+ }
+
+ public X11Screen() {
+ }
+
+ public void initNative() {
+ handle = GetScreen(display.getHandle(), index);
+ if (handle == 0 ) {
+ throw new RuntimeException("Error creating screen: "+index);
+ }
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+
+ private native long GetScreen(long dpy, int scrn_idx);
+}
diff --git a/src/classes/com/sun/javafx/newt/x11/X11Window.java b/src/classes/com/sun/javafx/newt/x11/X11Window.java
index 80021dca4..d89cd1169 100755
--- a/src/classes/com/sun/javafx/newt/x11/X11Window.java
+++ b/src/classes/com/sun/javafx/newt/x11/X11Window.java
@@ -37,10 +37,6 @@ import com.sun.javafx.newt.*;
import com.sun.opengl.impl.*;
public class X11Window extends Window {
- private Screen screen;
- private long visualID;
- private long dpy, scrn, window;
- private int scrn_idx;
private static final String WINDOW_CLASS_NAME = "NewtWindow";
// Default width and height -- will likely be re-set immediately by user
private int width = 100;
@@ -62,36 +58,28 @@ public class X11Window extends Window {
public X11Window() {
}
- public void initNative(Screen screen, long visualID) {
- this.screen = screen;
- this.visualID = visualID;
+ public void initNative() {
fullscreen=false;
visible=false;
- long w = CreateWindow(visualID, x, y, width, height);
- if (w == 0 || w!=window) {
+ long w = CreateWindow(getDisplayHandle(), getScreenHandle(), getScreenIndex(), visualID, x, y, width, height);
+ if (w == 0 || w!=windowHandle) {
throw new RuntimeException("Error creating window: "+w);
}
- screen.setHandle(scrn);
- screen.getDisplay().setHandle(dpy);
- }
-
- public Screen getScreen() {
- return screen;
}
public void setVisible(boolean visible) {
if(this.visible!=visible) {
this.visible=visible;
- setVisible0(dpy, window, visible);
+ setVisible0(getDisplayHandle(), windowHandle, visible);
}
}
public void setSize(int width, int height) {
- setSize0(dpy, window, width, height);
+ setSize0(getDisplayHandle(), windowHandle, width, height);
}
public void setPosition(int x, int y) {
- setPosition0(dpy, window, x, y);
+ setPosition0(getDisplayHandle(), windowHandle, x, y);
}
public boolean isVisible() {
@@ -120,16 +108,16 @@ public class X11Window extends Window {
this.fullscreen=fullscreen;
if(this.fullscreen) {
x = 0; y = 0;
- w = getDisplayWidth0(dpy, scrn_idx)/2;
- h = getDisplayHeight0(dpy, scrn_idx)/2;
+ w = getDisplayWidth0(getDisplayHandle(), getScreenIndex())/2;
+ h = getDisplayHeight0(getDisplayHandle(), getScreenIndex())/2;
} else {
x = nfs_x;
y = nfs_y;
w = nfs_width;
h = nfs_height;
}
- setPosition0(dpy, window, x, y);
- setSize0(dpy, window, w, h);
+ setPosition0(getDisplayHandle(), windowHandle, x, y);
+ setSize0(getDisplayHandle(), windowHandle, w, h);
}
return true;
}
@@ -138,20 +126,16 @@ public class X11Window extends Window {
return fullscreen;
}
- public long getWindowHandle() {
- return window;
- }
-
public void pumpMessages() {
- DispatchMessages(dpy, window);
+ DispatchMessages(getDisplayHandle(), windowHandle);
}
public int getDisplayWidth() {
- return getDisplayWidth0(dpy, scrn_idx);
+ return getDisplayWidth0(getDisplayHandle(), getScreenIndex());
}
public int getDisplayHeight() {
- return getDisplayHeight0(dpy, scrn_idx);
+ return getDisplayHeight0(getDisplayHandle(), getScreenIndex());
}
//----------------------------------------------------------------------
@@ -159,11 +143,12 @@ public class X11Window extends Window {
//
private static native boolean initIDs();
- private native long CreateWindow(long visualID, int x, int y, int width, int height);
- private native void setVisible0(long display, long window, boolean visible);
- private native void DispatchMessages(long display, long window);
- private native void setSize0(long display, long window, int width, int height);
- private native void setPosition0(long display, long window, int x, int y);
+ private native long CreateWindow(long display, long screen, int screen_index,
+ long visualID, int x, int y, int width, int height);
+ private native void setVisible0(long display, long windowHandle, boolean visible);
+ private native void DispatchMessages(long display, long windowHandle);
+ private native void setSize0(long display, long windowHandle, int width, int height);
+ private native void setPosition0(long display, long windowHandle, int x, int y);
private native int getDisplayWidth0(long display, int scrn_idx);
private native int getDisplayHeight0(long display, int scrn_idx);
@@ -185,11 +170,9 @@ public class X11Window extends Window {
}
}
- private void windowCreated(long dpy, int scrn_idx, long scrn, long window) {
- this.dpy = dpy;
- this.scrn_idx = scrn_idx;
- this.scrn = scrn;
- this.window = window;
+ private void windowCreated(long visualID, long windowHandle) {
+ this.visualID = visualID;
+ this.windowHandle = windowHandle;
}
private void windowClosed() {
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;
diff --git a/src/classes/javax/media/opengl/GLAutoDrawable.java b/src/classes/javax/media/opengl/GLAutoDrawable.java
index 40e2603c6..688b78879 100644
--- a/src/classes/javax/media/opengl/GLAutoDrawable.java
+++ b/src/classes/javax/media/opengl/GLAutoDrawable.java
@@ -52,7 +52,7 @@ import javax.media.opengl.glu.*;
GLContext for the GLAutoDrawable to be used both by the event
based rendering mechanism as well by end users directly. */
-public interface GLAutoDrawable extends GLDrawable /*, FIXME: ComponentEvents */ {
+public interface GLAutoDrawable extends GLDrawable {
/**
* Returns the context associated with this drawable. The returned
* context will be synchronized.
diff --git a/src/classes/javax/media/opengl/GLDrawable.java b/src/classes/javax/media/opengl/GLDrawable.java
index d57ddc0ee..c7f0ef803 100644
--- a/src/classes/javax/media/opengl/GLDrawable.java
+++ b/src/classes/javax/media/opengl/GLDrawable.java
@@ -136,4 +136,10 @@ public interface GLDrawable {
with the drawable; a best attempt is made to return a reasonable
value in this case. */
public GLCapabilities getChosenGLCapabilities();
+
+ public NativeWindow getNativeWindow();
+
+ public String getProfile();
+
+ public GLDrawableFactory getFactory();
}
diff --git a/src/classes/javax/media/opengl/GLDrawableFactory.java b/src/classes/javax/media/opengl/GLDrawableFactory.java
index 3ed34f86e..2c48e3ceb 100644
--- a/src/classes/javax/media/opengl/GLDrawableFactory.java
+++ b/src/classes/javax/media/opengl/GLDrawableFactory.java
@@ -77,7 +77,8 @@ import com.sun.opengl.impl.*;
*/
public abstract class GLDrawableFactory {
- private static GLDrawableFactory factory;
+ private static GLDrawableFactory awtFactory;
+ private static GLDrawableFactory nwFactory;
/** The desktop (OpenGL 2.0) profile */
public static final String PROFILE_GL_20 = "GL20";
@@ -91,9 +92,9 @@ public abstract class GLDrawableFactory {
private String profile;
/** Initializes the sole GLDrawableFactory instance for the given profile. */
- public static void initialize(String profile) throws GLException {
- if (factory != null) {
- throw new GLException("Already initialized");
+ public static void initializeAWTFactory(String profile) throws GLException {
+ if (awtFactory != null) {
+ return;
}
// See if the user is requesting one of the embedded profiles,
@@ -101,9 +102,9 @@ public abstract class GLDrawableFactory {
if (PROFILE_GLES1.equals(profile) ||
PROFILE_GLES2.equals(profile)) {
try {
- Class clazz = Class.forName("com.sun.opengl.impl.egl.EGLDrawableFactory");
+ Class clazz = Class.forName("com.sun.opengl.impl.egl.awt.EGLDrawableFactory");
Constructor c = clazz.getDeclaredConstructor(new Class[] { String.class });
- factory = (GLDrawableFactory) c.newInstance(new Object[] { profile });
+ awtFactory = (GLDrawableFactory) c.newInstance(new Object[] { profile });
return;
} catch (Exception e) {
e.printStackTrace();
@@ -118,7 +119,7 @@ public abstract class GLDrawableFactory {
String factoryClassName =
(String) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
- return System.getProperty("opengl.factory.class.name");
+ return System.getProperty("opengl.awt.factory.class.name");
}
});
String osName = System.getProperty("os.name");
@@ -134,6 +135,63 @@ public abstract class GLDrawableFactory {
if (factoryClassName != null) {
factoryClass = Class.forName(factoryClassName);
} else if (osNameLowerCase.startsWith("wind")) {
+ factoryClass = Class.forName("com.sun.opengl.impl.windows.awt.WindowsAWTGLDrawableFactory");
+ } else if (osNameLowerCase.startsWith("mac os x")) {
+ factoryClass = Class.forName("com.sun.opengl.impl.macosx.awt.MacOSXAWTGLDrawableFactory");
+ } else {
+ // Assume Linux, Solaris, etc. Should probably test for these explicitly.
+ factoryClass = Class.forName("com.sun.opengl.impl.x11.awt.X11AWTGLDrawableFactory");
+ }
+
+ if (factoryClass == null) {
+ throw new GLException("OS " + osName + " not yet supported");
+ }
+
+ Constructor c = factoryClass.getDeclaredConstructor(new Class[] { String.class });
+ awtFactory = (GLDrawableFactory) c.newInstance(new Object[] { profile });
+ } catch (Exception e) {
+ throw new GLException(e);
+ }
+ }
+
+ /** Initializes the sole GLDrawableFactory instance for the given profile. */
+ public static void initializeNWFactory(String profile) throws GLException {
+ if (nwFactory != null) {
+ return;
+ }
+
+ // See if the user is requesting one of the embedded profiles,
+ // and if so, try to instantiate the EGLDrawableFactory
+ if (PROFILE_GLES1.equals(profile) ||
+ PROFILE_GLES2.equals(profile)) {
+ try {
+ Class clazz = Class.forName("com.sun.opengl.impl.egl.EGLDrawableFactory");
+ Constructor c = clazz.getDeclaredConstructor(new Class[] { String.class });
+ nwFactory = (GLDrawableFactory) c.newInstance(new Object[] { profile });
+ return;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else if (!PROFILE_GL_20.equals(profile)) {
+ // We require that the user passes in one of the known profiles
+ throw new GLException("Unknown or unsupported profile \"" + profile + "\"");
+ }
+
+ // Use the desktop OpenGL as the fallback always
+ try {
+ String factoryClassName =
+ (String) AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ return System.getProperty("opengl.factory.class.name");
+ }
+ });
+ String osName = System.getProperty("os.name");
+ String osNameLowerCase = osName.toLowerCase();
+ Class factoryClass = null;
+
+ if (factoryClassName != null) {
+ factoryClass = Class.forName(factoryClassName);
+ } else if (osNameLowerCase.startsWith("wind")) {
factoryClass = Class.forName("com.sun.opengl.impl.windows.WindowsGLDrawableFactory");
} else if (osNameLowerCase.startsWith("mac os x")) {
factoryClass = Class.forName("com.sun.opengl.impl.macosx.MacOSXGLDrawableFactory");
@@ -147,7 +205,8 @@ public abstract class GLDrawableFactory {
}
Constructor c = factoryClass.getDeclaredConstructor(new Class[] { String.class });
- factory = (GLDrawableFactory) c.newInstance(new Object[] { profile });
+ nwFactory = (GLDrawableFactory) c.newInstance(new Object[] { profile });
+ return;
} catch (Exception e) {
throw new GLException(e);
}
@@ -160,12 +219,34 @@ public abstract class GLDrawableFactory {
}
/** Returns the sole GLDrawableFactory instance for the specified profile. */
- public static GLDrawableFactory getFactory() {
- if (factory == null) {
- throw new GLException("Must call initialize() first");
+ public static GLDrawableFactory getFactory(String profile, Object target) {
+ if(null==target) {
+ throw new IllegalArgumentException("target is null");
}
+ if(target instanceof NativeWindow) {
+ return getFactory(profile, false);
+ } else if (NativeWindowFactory.isAWTComponent(target)) {
+ return getFactory(profile, true);
+ }
+ throw new IllegalArgumentException("Target type is unsupported. Currently supported: \n"+
+ "\tjavax.media.opengl.NativeWindow\n"+
+ "\tjava.awt.Component\n");
+ }
- return factory;
+ public static GLDrawableFactory getFactory(String profile, boolean awt) {
+ if(awt) {
+ initializeAWTFactory(profile);
+ if(awtFactory == null) {
+ throw new GLException("Could not determine the AWT-GLDrawableFactory");
+ }
+ return awtFactory;
+ } else {
+ initializeNWFactory(profile);
+ if(nwFactory == null) {
+ throw new GLException("Could not determine the NativeWindow-GLDrawableFactory");
+ }
+ return nwFactory;
+ }
}
/** Indicates which profile this GLDrawableFactory was created for. */
@@ -223,14 +304,13 @@ public abstract class GLDrawableFactory {
* passed GLCapabilitiesChooser object is null, uses a
* DefaultGLCapabilitiesChooser instance.
*
- * @throws IllegalArgumentException if the passed target is either
- * null or its data type is not supported by this GLDrawableFactory.
+ * @throws IllegalArgumentException if the passed target is null
* @throws GLException if any window system-specific errors caused
* the creation of the GLDrawable to fail.
*/
- public abstract GLDrawable getGLDrawable(Object target,
- GLCapabilities capabilities,
- GLCapabilitiesChooser chooser)
+ public abstract GLDrawable createGLDrawable(NativeWindow target,
+ GLCapabilities capabilities,
+ GLCapabilitiesChooser chooser)
throws IllegalArgumentException, GLException;
//----------------------------------------------------------------------
diff --git a/src/classes/javax/media/opengl/NativeWindow.java b/src/classes/javax/media/opengl/NativeWindow.java
new file mode 100644
index 000000000..98e5edc68
--- /dev/null
+++ b/src/classes/javax/media/opengl/NativeWindow.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 javax.media.opengl;
+
+public interface NativeWindow {
+ public static final int LOCK_SURFACE_NOT_READY = 1;
+ public static final int LOCK_SURFACE_CHANGED = 2;
+ public static final int LOCK_SUCCESS = 3;
+
+ public boolean lockSurface() throws NativeWindowException ;
+ public void unlockSurface();
+ public boolean isSurfaceLocked();
+
+ public long getDisplayHandle();
+ public long getScreenHandle();
+ public int getScreenIndex();
+ public long getWindowHandle();
+ public long getVisualID();
+
+ public void setSize(int width, int height);
+ public void setPosition(int x, int y);
+ public int getWidth();
+ public int getHeight();
+ public int getX();
+ public int getY();
+
+ public void setVisible(boolean visible);
+ public boolean setFullscreen(boolean fullscreen);
+ public boolean isVisible();
+ public boolean isFullscreen();
+}
diff --git a/src/classes/javax/media/opengl/NativeWindowException.java b/src/classes/javax/media/opengl/NativeWindowException.java
new file mode 100644
index 000000000..cb43d3830
--- /dev/null
+++ b/src/classes/javax/media/opengl/NativeWindowException.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package javax.media.opengl;
+
+/** A generic exception for OpenGL errors used throughout the binding
+ as a substitute for {@link RuntimeException}. */
+
+public class NativeWindowException extends RuntimeException {
+ /** Constructs a NativeWindowException object. */
+ public NativeWindowException() {
+ super();
+ }
+
+ /** Constructs a NativeWindowException object with the specified detail
+ message. */
+ public NativeWindowException(String message) {
+ super(message);
+ }
+
+ /** Constructs a NativeWindowException object with the specified detail
+ message and root cause. */
+ public NativeWindowException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /** Constructs a NativeWindowException object with the specified root
+ cause. */
+ public NativeWindowException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/src/classes/javax/media/opengl/NativeWindowFactory.java b/src/classes/javax/media/opengl/NativeWindowFactory.java
new file mode 100644
index 000000000..c206adb78
--- /dev/null
+++ b/src/classes/javax/media/opengl/NativeWindowFactory.java
@@ -0,0 +1,140 @@
+/*
+ * 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 javax.media.opengl;
+
+import java.lang.reflect.*;
+import java.security.*;
+import com.sun.opengl.impl.*;
+
+public class NativeWindowFactory {
+ private static Constructor awtFactory = null;
+
+ /** Initializes the sole NativeWindowFactory instance . */
+ private static void initializeAWTFactory() throws GLException {
+ if (awtFactory == null) {
+ // Use the desktop OpenGL as the fallback always
+ try {
+ String osName = System.getProperty("os.name");
+ String osNameLowerCase = osName.toLowerCase();
+ Class factoryClass = null;
+ String factoryClassName = null;
+
+ // Because there are some complications with generating all
+ // platforms' Java glue code on all platforms (among them that we
+ // would have to include jawt.h and jawt_md.h in the jogl
+ // sources, which we currently don't have to do) we break the only
+ // static dependencies with platform-specific code here using reflection.
+
+ if (osNameLowerCase.startsWith("wind")) {
+ factoryClassName = "com.sun.opengl.impl.windows.awt.WindowsJAWTWindow";
+ } else if (osNameLowerCase.startsWith("mac os x")) {
+ factoryClassName = "com.sun.opengl.impl.macosx.awt.MacOSXJAWTWindow";
+ } else {
+ // Assume Linux, Solaris, etc. Should probably test for these explicitly.
+ factoryClassName = "com.sun.opengl.impl.x11.awt.X11JAWTWindow";
+ }
+
+ if (factoryClassName == null) {
+ throw new GLException("OS " + osName + " not yet supported");
+ }
+ factoryClass = Class.forName(factoryClassName);
+ if (factoryClass == null) {
+ throw new GLException("Factory " + factoryClassName + " not yet implemented");
+ }
+
+ try {
+ awtFactory = factoryClass.getDeclaredConstructor(new Class[] { Object.class });
+ } catch(NoSuchMethodException nsme) {}
+
+ } catch (Exception e) {
+ throw new GLException(e);
+ }
+ }
+ }
+
+ /**
+ * Returns true, if the given object is an instance of java.awt.Component.
+ * This check is performed on a Class.getName() basis,
+ * hence the independency to the java.awt.* package.
+ */
+ public static boolean isAWTComponent(Object target) {
+ Class clazz = target.getClass();
+ do {
+ if(clazz.getName().equals("java.awt.Component")) {
+ return true;
+ }
+ clazz = clazz.getSuperclass();
+ } while (clazz!=null);
+ return false;
+ }
+
+ /**
+ * Returns a NativeWindow.
+ *
+ * @throws IllegalArgumentException if the passed target is null
+ * @throws GLException if any window system-specific errors caused
+ * the creation of the GLDrawable to fail.
+ */
+ public static NativeWindow getNativeWindow(Object target)
+ throws IllegalArgumentException, GLException
+ {
+ if(null==target) {
+ throw new IllegalArgumentException("target is null");
+ }
+ if(target instanceof NativeWindow) {
+ return (NativeWindow)target;
+ }
+ if (isAWTComponent(target)) {
+ initializeAWTFactory();
+ if(awtFactory == null) {
+ throw new GLException("Could not determine an AWT-NativeWindow constructor");
+ }
+ try {
+ return (NativeWindow) awtFactory.newInstance(new Object[] { target });
+ } catch (Exception ie) {
+ ie.printStackTrace();
+ }
+ }
+ throw new IllegalArgumentException("Target type is unsupported. Currently supported: \n"+
+ "\tjavax.media.opengl.NativeWindow\n"+
+ "\tjava.awt.Component\n");
+ }
+}
+
diff --git a/src/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java b/src/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java
new file mode 100644
index 000000000..ef5a7f2d7
--- /dev/null
+++ b/src/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java
@@ -0,0 +1,46 @@
+/*
+ * 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 javax.media.opengl.awt;
+
+import javax.media.opengl.*;
+import javax.media.opengl.glu.*;
+
+public interface AWTGLAutoDrawable extends GLAutoDrawable, ComponentEvents {
+}
diff --git a/src/classes/javax/media/opengl/AWTGraphicsConfiguration.java b/src/classes/javax/media/opengl/awt/AWTGraphicsConfiguration.java
index 25647fc62..93f39bc27 100644
--- a/src/classes/javax/media/opengl/AWTGraphicsConfiguration.java
+++ b/src/classes/javax/media/opengl/awt/AWTGraphicsConfiguration.java
@@ -37,8 +37,9 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package javax.media.opengl;
+package javax.media.opengl.awt;
+import javax.media.opengl.*;
import java.awt.GraphicsConfiguration;
/** A wrapper for an AWT GraphicsConfiguration allowing it to be
diff --git a/src/classes/javax/media/opengl/AWTGraphicsDevice.java b/src/classes/javax/media/opengl/awt/AWTGraphicsDevice.java
index 98c7ef2bf..1073aac72 100644
--- a/src/classes/javax/media/opengl/AWTGraphicsDevice.java
+++ b/src/classes/javax/media/opengl/awt/AWTGraphicsDevice.java
@@ -37,8 +37,9 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package javax.media.opengl;
+package javax.media.opengl.awt;
+import javax.media.opengl.*;
import java.awt.GraphicsDevice;
/** A wrapper for an AWT GraphicsDevice allowing it to be
diff --git a/src/classes/javax/media/opengl/ComponentEvents.java b/src/classes/javax/media/opengl/awt/ComponentEvents.java
index bfbbb957b..0c4f63c2d 100644
--- a/src/classes/javax/media/opengl/ComponentEvents.java
+++ b/src/classes/javax/media/opengl/awt/ComponentEvents.java
@@ -37,8 +37,9 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package javax.media.opengl;
+package javax.media.opengl.awt;
+import javax.media.opengl.*;
import java.awt.event.*;
import java.beans.PropertyChangeListener;
diff --git a/src/classes/javax/media/opengl/GLCanvas.java b/src/classes/javax/media/opengl/awt/GLCanvas.java
index 42f3e68f3..8b52c6da4 100644
--- a/src/classes/javax/media/opengl/GLCanvas.java
+++ b/src/classes/javax/media/opengl/awt/GLCanvas.java
@@ -37,7 +37,9 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package javax.media.opengl;
+package javax.media.opengl.awt;
+
+import javax.media.opengl.*;
import java.awt.Canvas;
import java.awt.Color;
@@ -62,7 +64,7 @@ import com.sun.opengl.impl.*;
interfaces when adding a heavyweight doesn't work either because
of Z-ordering or LayoutManager problems. */
-public class GLCanvas extends Canvas implements GLAutoDrawable {
+public class GLCanvas extends Canvas implements AWTGLAutoDrawable {
private static final boolean DEBUG = Debug.debug("GLCanvas");
@@ -105,7 +107,8 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
which to create the GLCanvas; the GLDrawableFactory uses the
default screen device of the local GraphicsEnvironment if null
is passed for this argument. */
- public GLCanvas(GLCapabilities capabilities,
+ public GLCanvas(String profile,
+ GLCapabilities capabilities,
GLCapabilitiesChooser chooser,
GLContext shareWith,
GraphicsDevice device) {
@@ -139,7 +142,9 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
this.glCaps = capabilities;
}
if (!Beans.isDesignTime()) {
- drawable = GLDrawableFactory.getFactory().getGLDrawable(this, capabilities, chooser);
+ drawable = GLDrawableFactory.getFactory(profile, true).createGLDrawable(profile,
+ NativeWindowFactory.getNativeWindow(this),
+ capabilities, chooser);
context = (GLContextImpl) drawable.createContext(shareWith);
context.setSynchronized(true);
}
diff --git a/src/classes/javax/media/opengl/GLJPanel.java b/src/classes/javax/media/opengl/awt/GLJPanel.java
index 2d4e84d77..4c1df74da 100644
--- a/src/classes/javax/media/opengl/GLJPanel.java
+++ b/src/classes/javax/media/opengl/awt/GLJPanel.java
@@ -37,7 +37,9 @@
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
-package javax.media.opengl;
+package javax.media.opengl.awt;
+
+import javax.media.opengl.*;
import java.awt.*;
import java.awt.geom.*;
@@ -79,7 +81,7 @@ import com.sun.opengl.impl.*;
*/
-public class GLJPanel extends JPanel implements GLAutoDrawable {
+public class GLJPanel extends JPanel implements AWTGLAutoDrawable {
private static final boolean DEBUG = Debug.debug("GLJPanel");
private static final boolean VERBOSE = Debug.verbose();
diff --git a/src/native/jogl/X11Window.c b/src/native/jogl/X11Window.c
index e37525be7..c60fd2f9b 100755
--- a/src/native/jogl/X11Window.c
+++ b/src/native/jogl/X11Window.c
@@ -44,6 +44,97 @@
#include "MouseEvent.h"
#include "KeyEvent.h"
+// This is set by DispatchMessages, below, and cleared when it exits
+static JNIEnv* env = NULL;
+
+#define VERBOSE_ON 1
+
+#ifdef VERBOSE_ON
+
+static void _dumpVisualInfo(const char * msg, XVisualInfo *pVisualQuery) {
+ if(pVisualQuery!=NULL) {
+ fprintf(stderr, "%s: screen %d, visual: %p, visual-id: 0x%X, depth: %d, class %d, cmap sz: %d, bpp: %d, rgb 0x%X 0x%X 0x%X\n",
+ msg,
+ pVisualQuery->screen,
+ pVisualQuery->visual,
+ (int)pVisualQuery->visualid,
+ pVisualQuery->depth,
+ pVisualQuery->class,
+ pVisualQuery->colormap_size,
+ pVisualQuery->bits_per_rgb,
+ (int)pVisualQuery->red_mask,
+ (int)pVisualQuery->green_mask,
+ (int)pVisualQuery->blue_mask
+ );
+ } else {
+ fprintf(stderr, "%s: NULL XVisualInfo\n", msg);
+ }
+}
+
+#define DUMP_VISUAL_INFO(a,b) _dumpVisualInfo((a),(b))
+
+#else
+
+#define DUMP_VISUAL_INFO(a,b)
+
+#endif
+
+/**
+ * Display
+ */
+
+/*
+ * Class: com_sun_javafx_newt_x11_X11Display
+ * Method: CreateDisplay
+ * Signature: (Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_x11_X11Display_CreateDisplay
+ (JNIEnv *env, jobject obj, jstring displayName)
+{
+ Display * dpy = NULL;
+ const char * _displayName = NULL;
+ if(displayName!=0) {
+ _displayName = (*env)->GetStringUTFChars(env, displayName, 0);
+ }
+ dpy = XOpenDisplay(_displayName);
+ if(dpy==NULL) {
+ fprintf(stderr, "couldn't open display connection..\n");
+ }
+ return (jlong) (intptr_t) dpy;
+}
+
+/**
+ * Screen
+ */
+
+/*
+ * Class: com_sun_javafx_newt_x11_X11Screen
+ * Method: GetScreen
+ * Signature: (JI)J
+ */
+JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_x11_X11Screen_GetScreen
+ (JNIEnv *env, jobject obj, jlong display, jint screen_index)
+{
+ Display * dpy = (Display *)(intptr_t)display;
+ Screen * scrn= NULL;
+ if(dpy==NULL) {
+ fprintf(stderr, "[GetScreen] invalid display connection..\n");
+ return 0;
+ }
+ scrn = ScreenOfDisplay(dpy,screen_index);
+ if(scrn==NULL) {
+ scrn=DefaultScreenOfDisplay(dpy);
+ }
+ if(scrn==NULL) {
+ fprintf(stderr, "couldn't get screen ..\n");
+ }
+ return (jlong) (intptr_t) scrn;
+}
+
+/**
+ * Window
+ */
+
static jmethodID sizeChangedID = NULL;
static jmethodID positionChangedID = NULL;
static jmethodID windowClosedID = NULL;
@@ -52,11 +143,6 @@ static jmethodID windowCreatedID = NULL;
static jmethodID sendMouseEventID = NULL;
static jmethodID sendKeyEventID = NULL;
-// This is set by DispatchMessages, below, and cleared when it exits
-static JNIEnv* env = NULL;
-
-// #define VERBOSE_ON 1
-
/*
* Class: com_sun_javafx_newt_x11_X11Window
* Method: initIDs
@@ -69,7 +155,7 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_x11_X11Window_initIDs
positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V");
windowClosedID = (*env)->GetMethodID(env, clazz, "windowClosed", "()V");
windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V");
- windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(JIJJ)V");
+ windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(JJ)V");
sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIII)V");
sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V");
if (sizeChangedID == NULL ||
@@ -87,69 +173,116 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_x11_X11Window_initIDs
/*
* Class: com_sun_javafx_newt_x11_X11Window
* Method: CreateWindow
- * Signature: (JIIII)J
+ * Signature: (JJJIIIII)J
*/
JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_x11_X11Window_CreateWindow
- (JNIEnv *env, jobject obj, jlong visualID,
+ (JNIEnv *env, jobject obj, jlong display, jlong screen, jint screen_index,
+ jlong visualID,
jint x, jint y, jint width, jint height)
{
- Display * dpy;
- Screen * scrn;
- int scrn_idx;
+ Display * dpy = NULL;
+ Screen * scrn = NULL;
+ int scrn_idx = (int)screen_index;
Window windowParent = 0;
Window window = 0;
XVisualInfo visualTemplate;
XVisualInfo *pVisualQuery = NULL;
+ Visual *visual = NULL;
+ int depth;
+
XSetWindowAttributes xswa;
unsigned long attrMask;
int n;
- dpy = XOpenDisplay(NULL);
+ dpy = (Display *)(intptr_t)display;
if(dpy==NULL) {
- fprintf(stderr, "could not open X display ..\n");
+ fprintf(stderr, "[CreateWindow] invalid display connection..\n");
return 0;
}
+ scrn = (Screen *)(intptr_t)screen;
+ if(scrn==NULL) {
+ fprintf(stderr, "invalid screen connection..\n");
+ return 0;
+ }
+
+ visualID=33;
if(visualID>0) {
- // try given VisualID
+ // try given VisualID on screen
memset(&visualTemplate, 0, sizeof(XVisualInfo));
+ visualTemplate.screen = scrn_idx;
visualTemplate.visualid = (VisualID)visualID;
- pVisualQuery = XGetVisualInfo(dpy, VisualIDMask, &visualTemplate,&n);
+ pVisualQuery = XGetVisualInfo(dpy, VisualIDMask|VisualScreenMask, &visualTemplate,&n);
+ DUMP_VISUAL_INFO("Given VisualID,ScreenIdx", pVisualQuery);
+ if(pVisualQuery!=NULL) {
+ visual = pVisualQuery->visual;
+ depth = pVisualQuery->depth;
+ visualID = pVisualQuery->visualid;
+ XFree(pVisualQuery);
+ pVisualQuery=NULL;
+ }
+#ifdef VERBOSE_ON
+ fprintf(stderr, "trying given (screen %d, visualID: %d) found: %d\n", scrn_idx, visualID, (visual!=NULL));
+#endif
}
- if (pVisualQuery==NULL)
+ if (visual==NULL)
{
- // try default VisualID
- scrn = DefaultScreenOfDisplay(dpy);
- visualID = XVisualIDFromVisual(DefaultVisualOfScreen(scrn));
+ // try depth >=15 on screen
memset(&visualTemplate, 0, sizeof(XVisualInfo));
- visualTemplate.visualid = (VisualID)visualID;
- pVisualQuery = XGetVisualInfo(dpy, VisualIDMask, &visualTemplate,&n);
+ visualTemplate.screen = scrn_idx;
+ visualTemplate.depth = 15;
+ pVisualQuery = XGetVisualInfo(dpy, VisualScreenMask|VisualDepthMask, &visualTemplate,&n);
+ DUMP_VISUAL_INFO("Given VisualID,ScreenIdx", pVisualQuery);
+ if(pVisualQuery!=NULL) {
+ visual = pVisualQuery->visual;
+ depth = pVisualQuery->depth;
+ visualID = pVisualQuery->visualid;
+ XFree(pVisualQuery);
+ pVisualQuery=NULL;
+ }
+#ifdef VERBOSE_ON
+ fprintf(stderr, "trying (screen %d, depth >= 15) found: %d, id: %d\n", scrn_idx, (visual!=NULL), visualID);
+#endif
}
- if (pVisualQuery==NULL)
+ if (visual==NULL)
{
- fprintf(stderr, "could not query any XVisualInfo, bail out!\n");
- return 0;
- }
+ // try default ..
+ Visual * visual = XDefaultVisualOfScreen(scrn);
+ if(visual!=NULL) {
+ visualID = visual->visualid;
+ // try given VisualID on screen
+ memset(&visualTemplate, 0, sizeof(XVisualInfo));
+ visualTemplate.screen = scrn_idx;
+ visualTemplate.visualid = (VisualID)visualID;
+ pVisualQuery = XGetVisualInfo(dpy, VisualIDMask|VisualScreenMask, &visualTemplate,&n);
+ if(pVisualQuery!=NULL) {
+ visual = pVisualQuery->visual;
+ depth = pVisualQuery->depth;
+ visualID = pVisualQuery->visualid;
+ XFree(pVisualQuery);
+ pVisualQuery=NULL;
+ } else {
+ visual = NULL;
+ visualID = 0;
+ }
#ifdef VERBOSE_ON
- else {
- fprintf(stderr, "choosen visual: id: 0x%X, screen %d, depth: %d, class %d, cmap sz: %d, bpp: %d, rgb 0x%X 0x%X 0x%X\n",
- (int)pVisualQuery->visualid,
- pVisualQuery->screen,
- pVisualQuery->depth,
- pVisualQuery->class,
- pVisualQuery->colormap_size,
- pVisualQuery->bits_per_rgb,
- (int)pVisualQuery->red_mask,
- (int)pVisualQuery->green_mask,
- (int)pVisualQuery->blue_mask
- );
- }
+ fprintf(stderr, "default visual (screen %d, visualID: %d) found: %d\n", scrn_idx, visualID, (visual!=NULL));
#endif
+ }
+ }
+ DUMP_VISUAL_INFO("Choosen", pVisualQuery);
+ if (visual==NULL)
+ {
+ fprintf(stderr, "could not query any Visual, bail out!\n");
+ return 0;
+ }
- scrn_idx = pVisualQuery->screen;
- scrn = ScreenOfDisplay(dpy, scrn_idx);
+ if(pVisualQuery!=NULL) {
+ XFree(pVisualQuery);
+ pVisualQuery=NULL;
+ }
windowParent = XRootWindowOfScreen(scrn);
@@ -160,8 +293,8 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_x11_X11Window_CreateWindow
xswa.background_pixel = 0;
xswa.event_mask = ExposureMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask;
xswa.colormap = XCreateColormap(dpy,
- RootWindow(dpy, pVisualQuery->screen),
- pVisualQuery->visual,
+ XRootWindow(dpy, scrn_idx),
+ visual,
AllocNone);
window = XCreateWindow(dpy,
@@ -169,19 +302,15 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_x11_X11Window_CreateWindow
x, y,
width, height,
0, // border width
- pVisualQuery->depth,
+ depth,
InputOutput,
- pVisualQuery->visual,
+ visual,
attrMask,
&xswa);
- XFree(pVisualQuery);
-
- //XMapWindow(dpy, window);
XClearWindow(dpy, window);
XMapRaised(dpy, window);
- (*env)->CallVoidMethod(env, obj, windowCreatedID, (jlong) (intptr_t) dpy,
- (jint) scrn_idx, (jlong) (intptr_t) scrn, (jlong) window);
+ (*env)->CallVoidMethod(env, obj, windowCreatedID, (jlong) visualID, (jlong) window);
XSelectInput(dpy, window, ExposureMask|ButtonPressMask|ButtonReleaseMask|PointerMotionMask|
KeyPressMask|KeyReleaseMask);