aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes/com/sun
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2009-05-29 01:47:02 +0000
committerSven Gothel <[email protected]>2009-05-29 01:47:02 +0000
commit4c32ea23370336b99eba4c1ebd1f07c409219a15 (patch)
tree7d97e763a81f86650c2085eeeaeaf04ffaddf6bd /src/newt/classes/com/sun
parenta7b402128a2cd00c099acde944f793455d8856a5 (diff)
JOGL
Added OpenGL 3.0 and 3.1 support 3.0 as part of GL2 (extensions only) 3.1 forward compatible as GL3, ie doesn't contain the GL2 fixed function stuff etc Added code to retrieve a 3.0/3.1 context: X11/GLX and Windows/WGL TODO: MacOSX !! Updated GL and GLX extensions Fixing auto GLProfile selection, determine if GL2ES[1] uses GL2 or ES Usage of the unified GraphicsConfiguration of NativeWindow for all platforms. Sure, the broken OS (Win32/MacOSX) have a update mechanism for theit queried Capabilities after drawable creation. Adding X11/GLX GLXFBConfig usage and fixing it's attribute mapping Fixing GLX/X11 FBConfig/XVisual query function's memory leak, using a manual implementation, which copies the data and calls XFree. Added WGL extension WGL_ARB_create_context Tested: Linux x86 and x86_64 GL2, ES2 and ES1 Note: Nvidia driver couldn't make the succesfully created 3.1 context current. TODO: Verify Windows and MacOSX !! git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1919 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/newt/classes/com/sun')
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/Display.java33
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/NewtFactory.java63
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/Screen.java54
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/Window.java48
-rw-r--r--src/newt/classes/com/sun/javafx/newt/awt/AWTDisplay.java7
-rw-r--r--src/newt/classes/com/sun/javafx/newt/awt/AWTScreen.java9
-rw-r--r--src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java10
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/macosx/MacDisplay.java5
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/macosx/MacScreen.java7
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java12
-rw-r--r--src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java36
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/opengl/kd/KDDisplay.java12
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/opengl/kd/KDScreen.java12
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java40
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/windows/WindowsDisplay.java5
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/windows/WindowsScreen.java7
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java12
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/x11/X11Display.java7
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/x11/X11Screen.java9
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/x11/X11Window.java26
20 files changed, 205 insertions, 209 deletions
diff --git a/src/newt/classes/com/sun/javafx/newt/Display.java b/src/newt/classes/com/sun/javafx/newt/Display.java
index a0a4217ca..b5d3c8520 100755
--- a/src/newt/classes/com/sun/javafx/newt/Display.java
+++ b/src/newt/classes/com/sun/javafx/newt/Display.java
@@ -33,21 +33,23 @@
package com.sun.javafx.newt;
+import javax.media.nativewindow.*;
+
public abstract class Display {
private static Class getDisplayClass(String type)
throws ClassNotFoundException
{
Class displayClass = null;
- if (NewtFactory.KD.equals(type)) {
+ if (NativeWindowFactory.TYPE_EGL.equals(type)) {
displayClass = Class.forName("com.sun.javafx.newt.opengl.kd.KDDisplay");
- } else if (NewtFactory.WINDOWS.equals(type)) {
+ } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) {
displayClass = Class.forName("com.sun.javafx.newt.windows.WindowsDisplay");
- } else if (NewtFactory.MACOSX.equals(type)) {
+ } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) {
displayClass = Class.forName("com.sun.javafx.newt.macosx.MacDisplay");
- } else if (NewtFactory.X11.equals(type)) {
+ } else if (NativeWindowFactory.TYPE_X11.equals(type)) {
displayClass = Class.forName("com.sun.javafx.newt.x11.X11Display");
- } else if (NewtFactory.AWT.equals(type)) {
+ } else if (NativeWindowFactory.TYPE_AWT.equals(type)) {
displayClass = Class.forName("com.sun.javafx.newt.awt.AWTDisplay");
} else {
throw new RuntimeException("Unknown display type \"" + type + "\"");
@@ -60,20 +62,26 @@ public abstract class Display {
Class displayClass = getDisplayClass(type);
Display display = (Display) displayClass.newInstance();
display.name=name;
- display.handle=0;
display.createNative();
+ if(null==display.aDevice) {
+ throw new RuntimeException("Display.createNative() failed to instanciate an AbstractGraphicsDevice");
+ }
return display;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
- protected static Display wrapHandle(String type, String name, long handle) {
+ public synchronized void destroy() {
+ closeNative();
+ }
+
+ protected static Display wrapHandle(String type, String name, AbstractGraphicsDevice aDevice) {
try {
Class displayClass = getDisplayClass(type);
Display display = (Display) displayClass.newInstance();
display.name=name;
- display.handle=handle;
+ display.aDevice=aDevice;
return display;
} catch (Exception e) {
throw new RuntimeException(e);
@@ -81,16 +89,21 @@ public abstract class Display {
}
protected abstract void createNative();
+ protected abstract void closeNative();
public String getName() {
return name;
}
public long getHandle() {
- return handle;
+ return aDevice.getHandle();
+ }
+
+ public AbstractGraphicsDevice getGraphicsDevice() {
+ return aDevice;
}
protected String name;
- protected long handle;
+ protected AbstractGraphicsDevice aDevice;
}
diff --git a/src/newt/classes/com/sun/javafx/newt/NewtFactory.java b/src/newt/classes/com/sun/javafx/newt/NewtFactory.java
index c455dce19..993c3c8a0 100755
--- a/src/newt/classes/com/sun/javafx/newt/NewtFactory.java
+++ b/src/newt/classes/com/sun/javafx/newt/NewtFactory.java
@@ -33,31 +33,15 @@
package com.sun.javafx.newt;
-import javax.media.nativewindow.AbstractGraphicsConfiguration;
-import javax.media.nativewindow.Capabilities;
+import javax.media.nativewindow.*;
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";
-
- /** Generic AWT wrapped window type, if available */
- public static final String AWT = "AWT";
-
// Work-around for initialization order problems on Mac OS X
// between native Newt and (apparently) Fmod
static {
- Window.init(getWindowType());
+ Window.init(NativeWindowFactory.getNativeWindowType());
}
static int getPropertyIntValue(String propname) {
@@ -71,34 +55,11 @@ public abstract class NewtFactory {
return i;
}
- /** Creates a Window of the default type for the current operating system. */
- public static String getWindowType() {
- String osName = System.getProperty("newt.ws.name");
- if(null==osName||osName.length()==0) {
- osName = System.getProperty("os.name");
- }
- String osNameLowerCase = osName.toLowerCase();
- String windowType;
- if (osNameLowerCase.startsWith("kd")) {
- windowType = KD;
- } else if (osNameLowerCase.startsWith("wind")) {
- windowType = WINDOWS;
- } else if (osNameLowerCase.startsWith("mac os x") ||
- osNameLowerCase.startsWith("darwin")) {
- windowType = MACOSX;
- } else if (osNameLowerCase.equals("awt")) {
- windowType = AWT;
- } else {
- windowType = X11;
- }
- return windowType;
- }
-
/**
* Create a Display entity, incl native creation
*/
public static Display createDisplay(String name) {
- return Display.create(getWindowType(), name);
+ return Display.create(NativeWindowFactory.getNativeWindowType(), name);
}
/**
@@ -112,7 +73,7 @@ public abstract class NewtFactory {
* Create a Screen entity, incl native creation
*/
public static Screen createScreen(Display display, int index) {
- return Screen.create(getWindowType(), display, index);
+ return Screen.create(NativeWindowFactory.getNativeWindowType(), display, index);
}
/**
@@ -126,11 +87,11 @@ public abstract class NewtFactory {
* Create a Window entity, incl native creation
*/
public static Window createWindow(Screen screen, Capabilities caps) {
- return Window.create(getWindowType(), screen, caps);
+ return Window.create(NativeWindowFactory.getNativeWindowType(), screen, caps);
}
public static Window createWindow(Screen screen, Capabilities caps, boolean undecorated) {
- return Window.create(getWindowType(), screen, caps, undecorated);
+ return Window.create(NativeWindowFactory.getNativeWindowType(), screen, caps, undecorated);
}
/**
@@ -143,24 +104,24 @@ public abstract class NewtFactory {
/**
* Instantiate a Display entity using the native handle.
*/
- public static Display wrapDisplay(String name, long handle) {
- return Display.wrapHandle(getWindowType(), name, handle);
+ public static Display wrapDisplay(String name, AbstractGraphicsDevice device) {
+ return Display.wrapHandle(NativeWindowFactory.getNativeWindowType(), name, device);
}
/**
* Instantiate a Screen entity using the native handle.
*/
- public static Screen wrapScreen(Display display, int index, long handle) {
- return Screen.wrapHandle(getWindowType(), display, index, handle);
+ public static Screen wrapScreen(Display display, AbstractGraphicsScreen screen) {
+ return Screen.wrapHandle(NativeWindowFactory.getNativeWindowType(), display, screen);
}
/**
* Instantiate a Window entity using the native handle.
*/
- public static Window wrapWindow(Screen screen, Capabilities caps, AbstractGraphicsConfiguration config,
+ public static Window wrapWindow(Screen screen, AbstractGraphicsConfiguration config,
long windowHandle, boolean fullscreen, boolean visible,
int x, int y, int width, int height) {
- return Window.wrapHandle(getWindowType(), screen, caps, config,
+ return Window.wrapHandle(NativeWindowFactory.getNativeWindowType(), screen, config,
windowHandle, fullscreen, visible, x, y, width, height);
}
diff --git a/src/newt/classes/com/sun/javafx/newt/Screen.java b/src/newt/classes/com/sun/javafx/newt/Screen.java
index f35c04b61..346257f6c 100755
--- a/src/newt/classes/com/sun/javafx/newt/Screen.java
+++ b/src/newt/classes/com/sun/javafx/newt/Screen.java
@@ -33,21 +33,23 @@
package com.sun.javafx.newt;
+import javax.media.nativewindow.*;
+
public abstract class Screen {
private static Class getScreenClass(String type)
throws ClassNotFoundException
{
Class screenClass = null;
- if (NewtFactory.KD.equals(type)) {
+ if (NativeWindowFactory.TYPE_EGL.equals(type)) {
screenClass = Class.forName("com.sun.javafx.newt.opengl.kd.KDScreen");
- } else if (NewtFactory.WINDOWS.equals(type)) {
+ } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) {
screenClass = Class.forName("com.sun.javafx.newt.windows.WindowsScreen");
- } else if (NewtFactory.MACOSX.equals(type)) {
+ } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) {
screenClass = Class.forName("com.sun.javafx.newt.macosx.MacScreen");
- } else if (NewtFactory.X11.equals(type)) {
+ } else if (NativeWindowFactory.TYPE_X11.equals(type)) {
screenClass = Class.forName("com.sun.javafx.newt.x11.X11Screen");
- } else if (NewtFactory.AWT.equals(type)) {
+ } else if (NativeWindowFactory.TYPE_AWT.equals(type)) {
screenClass = Class.forName("com.sun.javafx.newt.awt.AWTScreen");
} else {
throw new RuntimeException("Unknown window type \"" + type + "\"");
@@ -65,40 +67,50 @@ public abstract class Screen {
Class screenClass = getScreenClass(type);
Screen screen = (Screen) screenClass.newInstance();
screen.display = display;
- screen.index = idx;
- screen.handle = 0;
- screen.createNative();
+ screen.createNative(idx);
+ if(null==screen.aScreen) {
+ throw new RuntimeException("Screen.createNative() failed to instanciate an AbstractGraphicsScreen");
+ }
return screen;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
- protected static Screen wrapHandle(String type, Display display, int idx, long handle) {
+ public synchronized void destroy() {
+ closeNative();
+ }
+
+ protected static Screen wrapHandle(String type, Display display, AbstractGraphicsScreen aScreen) {
try {
Class screenClass = getScreenClass(type);
Screen screen = (Screen) screenClass.newInstance();
screen.display = display;
- screen.index = idx;
- screen.handle = handle;
+ screen.aScreen = aScreen;
return screen;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
- protected abstract void createNative();
+ protected abstract void createNative(int index);
+ protected abstract void closeNative();
+
+ protected void setScreenSize(int w, int h) {
+ System.out.println("Detected screen size "+w+"x"+h);
+ width=w; height=h;
+ }
public Display getDisplay() {
return display;
}
public int getIndex() {
- return index;
+ return aScreen.getIndex();
}
- public long getHandle() {
- return handle;
+ public AbstractGraphicsScreen getGraphicsScreen() {
+ return aScreen;
}
/**
@@ -119,18 +131,8 @@ public abstract class Screen {
return (usrHeight>0) ? usrHeight : (height>0) ? height : 480;
}
- /**
- * The actual implementation shall call this function
- * to set the detected screen size
- */
- public void setScreenSize(int w, int h) {
- System.out.println("Detected screen size "+w+"x"+h);
- width=w; height=h;
- }
-
protected Display display;
- protected int index;
- protected long handle;
+ protected AbstractGraphicsScreen aScreen;
protected int width=-1, height=-1; // detected values: set using setScreenSize
protected static int usrWidth=-1, usrHeight=-1; // property values: newt.ws.swidth and newt.ws.sheight
}
diff --git a/src/newt/classes/com/sun/javafx/newt/Window.java b/src/newt/classes/com/sun/javafx/newt/Window.java
index d649b53a4..f400265ee 100755
--- a/src/newt/classes/com/sun/javafx/newt/Window.java
+++ b/src/newt/classes/com/sun/javafx/newt/Window.java
@@ -34,10 +34,7 @@
package com.sun.javafx.newt;
import com.sun.javafx.newt.impl.Debug;
-import javax.media.nativewindow.AbstractGraphicsConfiguration;
-import javax.media.nativewindow.Capabilities;
-import javax.media.nativewindow.NativeWindow;
-import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.*;
import java.util.ArrayList;
import java.util.Iterator;
@@ -54,7 +51,7 @@ public abstract class Window implements NativeWindow
// initialized first then the connection to the window server
// breaks, leading to errors from deep within the AppKit
static void init(String type) {
- if (NewtFactory.MACOSX.equals(type)) {
+ if (NativeWindowFactory.TYPE_MACOSX.equals(type)) {
try {
getWindowClass(type);
} catch (Exception e) {
@@ -67,15 +64,15 @@ public abstract class Window implements NativeWindow
throws ClassNotFoundException
{
Class windowClass = null;
- if (NewtFactory.KD.equals(type)) {
+ if (NativeWindowFactory.TYPE_EGL.equals(type)) {
windowClass = Class.forName("com.sun.javafx.newt.opengl.kd.KDWindow");
- } else if (NewtFactory.WINDOWS.equals(type)) {
+ } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) {
windowClass = Class.forName("com.sun.javafx.newt.windows.WindowsWindow");
- } else if (NewtFactory.MACOSX.equals(type)) {
+ } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) {
windowClass = Class.forName("com.sun.javafx.newt.macosx.MacWindow");
- } else if (NewtFactory.X11.equals(type)) {
+ } else if (NativeWindowFactory.TYPE_X11.equals(type)) {
windowClass = Class.forName("com.sun.javafx.newt.x11.X11Window");
- } else if (NewtFactory.AWT.equals(type)) {
+ } else if (NativeWindowFactory.TYPE_AWT.equals(type)) {
windowClass = Class.forName("com.sun.javafx.newt.awt.AWTWindow");
} else {
throw new NativeWindowException("Unknown window type \"" + type + "\"");
@@ -102,7 +99,7 @@ public abstract class Window implements NativeWindow
}
}
- protected static Window wrapHandle(String type, Screen screen, Capabilities caps, AbstractGraphicsConfiguration config,
+ protected static Window wrapHandle(String type, Screen screen, AbstractGraphicsConfiguration config,
long windowHandle, boolean fullscreen, boolean visible,
int x, int y, int width, int height)
{
@@ -111,7 +108,6 @@ public abstract class Window implements NativeWindow
Window window = (Window) windowClass.newInstance();
window.invalidate();
window.screen = screen;
- window.chosenCaps = caps;
window.config = config;
window.windowHandle = windowHandle;
window.fullscreen=fullscreen;
@@ -165,15 +161,12 @@ public abstract class Window implements NativeWindow
public String toString() {
StringBuffer sb = new StringBuffer();
- sb.append("NEWT-Window[windowHandle "+getWindowHandle()+
+ sb.append("NEWT-Window[config "+config+
+ ", windowHandle "+getWindowHandle()+
", surfaceHandle "+getSurfaceHandle()+
", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+
", visible "+isVisible()+
- ", wrappedWindow "+getWrappedWindow()+
- ", config "+config+
- ", "+chosenCaps+
- ", screen handle/index "+getScreenHandle()+"/"+getScreenIndex() +
- ", display handle "+getDisplayHandle());
+ ", wrappedWindow "+getWrappedWindow());
sb.append(", WindowListeners num "+windowListeners.size()+" [");
for (Iterator iter = windowListeners.iterator(); iter.hasNext(); ) {
@@ -193,8 +186,6 @@ public abstract class Window implements NativeWindow
protected Screen screen;
- // The Capabilities is used to determine the AbstractGraphicsConfiguration
- protected Capabilities chosenCaps;
protected AbstractGraphicsConfiguration config;
protected long windowHandle;
protected boolean locked=false;
@@ -268,8 +259,6 @@ public abstract class Window implements NativeWindow
public void invalidate(boolean internal) {
unlockSurface();
screen = null;
- config = null;
- chosenCaps = null;
windowHandle = 0;
locked = false;
fullscreen=false;
@@ -288,19 +277,11 @@ public abstract class Window implements NativeWindow
}
public long getDisplayHandle() {
- if(null==screen ||
- null==screen.getDisplay()) {
- return 0;
- }
return screen.getDisplay().getHandle();
}
- public long getScreenHandle() {
- return (null!=screen)?screen.getHandle():0;
- }
-
public int getScreenIndex() {
- return (null!=screen)?screen.getIndex():0;
+ return screen.getIndex();
}
public long getWindowHandle() {
@@ -312,11 +293,8 @@ public abstract class Window implements NativeWindow
}
public Capabilities getChosenCapabilities() {
- if (chosenCaps == null)
- return null;
-
// Must return a new copy to avoid mutation by end user
- return (Capabilities) chosenCaps.clone();
+ return (Capabilities) config.getCapabilities().clone();
}
public AbstractGraphicsConfiguration getGraphicsConfiguration() {
diff --git a/src/newt/classes/com/sun/javafx/newt/awt/AWTDisplay.java b/src/newt/classes/com/sun/javafx/newt/awt/AWTDisplay.java
index 35cb7d466..f6f4a6fe8 100644
--- a/src/newt/classes/com/sun/javafx/newt/awt/AWTDisplay.java
+++ b/src/newt/classes/com/sun/javafx/newt/awt/AWTDisplay.java
@@ -33,13 +33,18 @@
package com.sun.javafx.newt.awt;
+import java.awt.*;
import com.sun.javafx.newt.*;
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.awt.*;
public class AWTDisplay extends Display {
public AWTDisplay() {
}
protected void createNative() {
- handle = 0;
+ aDevice = (AWTGraphicsDevice) AWTGraphicsDevice.createDevice(null); // default
}
+
+ protected void closeNative() { }
}
diff --git a/src/newt/classes/com/sun/javafx/newt/awt/AWTScreen.java b/src/newt/classes/com/sun/javafx/newt/awt/AWTScreen.java
index 02351baf6..93e57d72f 100644
--- a/src/newt/classes/com/sun/javafx/newt/awt/AWTScreen.java
+++ b/src/newt/classes/com/sun/javafx/newt/awt/AWTScreen.java
@@ -34,12 +34,17 @@
package com.sun.javafx.newt.awt;
import com.sun.javafx.newt.*;
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.awt.*;
public class AWTScreen extends Screen {
public AWTScreen() {
}
- protected void createNative() {
- handle = 0;
+ protected void createNative(int index) {
+ aScreen = new AWTGraphicsScreen((AWTGraphicsDevice)display.getGraphicsDevice());
}
+
+ protected void closeNative() { }
+
}
diff --git a/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java b/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java
index 9e539da8a..6c20cfbcf 100644
--- a/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java
+++ b/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java
@@ -47,8 +47,8 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import com.sun.javafx.newt.Window;
-import javax.media.nativewindow.Capabilities;
-import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.awt.*;
/** An implementation of the Newt Window class built using the
AWT. This is provided for convenience of porting to platforms
@@ -76,8 +76,10 @@ public class AWTWindow extends Window {
}
protected void createNative(Capabilities caps) {
- chosenCaps = (Capabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID)
- config = null; // n/a
+ config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen());
+ if (config == null) {
+ throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
+ }
runOnEDT(new Runnable() {
public void run() {
frame = new Frame(getTitle());
diff --git a/src/newt/classes/com/sun/javafx/newt/macosx/MacDisplay.java b/src/newt/classes/com/sun/javafx/newt/macosx/MacDisplay.java
index 711a4dcf1..f0d624c4b 100755
--- a/src/newt/classes/com/sun/javafx/newt/macosx/MacDisplay.java
+++ b/src/newt/classes/com/sun/javafx/newt/macosx/MacDisplay.java
@@ -34,12 +34,15 @@
package com.sun.javafx.newt.macosx;
import com.sun.javafx.newt.*;
+import javax.media.nativewindow.*;
public class MacDisplay extends Display {
public MacDisplay() {
}
protected void createNative() {
- handle = 0;
+ aDevice = new DefaultGraphicsDevice(NativeWindowFactory.TYPE_MACOSX);
}
+
+ protected void closeNative() { }
}
diff --git a/src/newt/classes/com/sun/javafx/newt/macosx/MacScreen.java b/src/newt/classes/com/sun/javafx/newt/macosx/MacScreen.java
index e27c2a21d..564edd14d 100755
--- a/src/newt/classes/com/sun/javafx/newt/macosx/MacScreen.java
+++ b/src/newt/classes/com/sun/javafx/newt/macosx/MacScreen.java
@@ -34,12 +34,15 @@
package com.sun.javafx.newt.macosx;
import com.sun.javafx.newt.*;
+import javax.media.nativewindow.*;
public class MacScreen extends Screen {
public MacScreen() {
}
- protected void createNative() {
- handle = 0;
+ protected void createNative(int index) {
+ aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index);
}
+
+ protected void closeNative() { }
}
diff --git a/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java b/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java
index 39f7a5bba..49cc84cba 100755
--- a/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java
+++ b/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java
@@ -33,8 +33,7 @@
package com.sun.javafx.newt.macosx;
-import javax.media.nativewindow.Capabilities;
-import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.*;
import com.sun.javafx.newt.*;
import com.sun.javafx.newt.impl.*;
@@ -144,11 +143,10 @@ public class MacWindow extends Window {
}
protected void createNative(Capabilities caps) {
- // FIXME: no way to really set the proper Capabilities nor the
- // AbstractGraphicsConfiguration since we don't do (OpenGL)
- // pixel format selection here
- chosenCaps = (Capabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID)
- config = null; // n/a
+ config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen());
+ if (config == null) {
+ throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
+ }
}
protected void closeNative() {
diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java b/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java
index 8f7c309f8..634e05e5f 100644
--- a/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java
+++ b/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java
@@ -72,7 +72,8 @@ public class GLWindow extends Window implements GLAutoDrawable {
/** Constructor. Do not call this directly -- use {@link
create()} instead. */
- protected GLWindow(Window window) {
+ protected GLWindow(Window window, boolean ownerOfDisplayAndScreen) {
+ this.ownerOfDisplayAndScreen = ownerOfDisplayAndScreen;
this.window = window;
this.window.setAutoDrawableClient(true);
window.addWindowListener(new WindowListener() {
@@ -130,13 +131,16 @@ public class GLWindow extends Window implements GLAutoDrawable {
if (caps == null) {
caps = new GLCapabilities();
}
+
+ boolean ownerOfDisplayAndScreen=false;
if (window == null) {
+ ownerOfDisplayAndScreen = true;
Display display = NewtFactory.createDisplay(null); // local display
Screen screen = NewtFactory.createScreen(display, 0); // screen 0
window = NewtFactory.createWindow(screen, caps, undecorated);
}
- return new GLWindow(window);
+ return new GLWindow(window, ownerOfDisplayAndScreen);
}
protected void createNative(Capabilities caps) {
@@ -162,9 +166,17 @@ public class GLWindow extends Window implements GLAutoDrawable {
drawable.setRealized(false);
}
- if(null!=window) {
+ Screen _screen = null;
+ Display _device = null;
+ if(null!=window) {
+ if(ownerOfDisplayAndScreen) {
+ _screen = getScreen();
+ if(null != _screen) {
+ _device = _screen.getDisplay();
+ }
+ }
window.destroy();
- }
+ }
if(Window.DEBUG_WINDOW_EVENT) {
System.out.println("GLWindow.destroy fin: "+this);
@@ -172,6 +184,13 @@ public class GLWindow extends Window implements GLAutoDrawable {
drawable = null;
context = null;
+
+ if(null != _screen) {
+ _screen.destroy();
+ }
+ if(null != _device) {
+ _device.destroy();
+ }
window = null;
}
@@ -251,15 +270,19 @@ public class GLWindow extends Window implements GLAutoDrawable {
factory = GLDrawableFactory.getFactory();
NativeWindow nw = window;
if (window.getWrappedWindow() != null) {
- nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow());
+ nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow(), nw.getGraphicsConfiguration());
}
- drawable = factory.createGLDrawable(nw, (GLCapabilities) window.getChosenCapabilities(), null);
+ drawable = factory.createGLDrawable(nw);
window.setVisible(true);
drawable.setRealized(true);
context = drawable.createContext(null);
}
}
+ public Screen getScreen() {
+ return window.getScreen();
+ }
+
public void setTitle(String title) {
window.setTitle(title);
}
@@ -495,6 +518,7 @@ public class GLWindow extends Window implements GLAutoDrawable {
private long curTime = 0;
private long lastCheck = 0;
private int totalFrames = 0, lastFrames = 0;
+ private boolean ownerOfDisplayAndScreen;
private DisplayAction displayAction = new DisplayAction();
diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDDisplay.java b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDDisplay.java
index 3efe4efe6..a13a95586 100755
--- a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDDisplay.java
+++ b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDDisplay.java
@@ -36,7 +36,8 @@ package com.sun.javafx.newt.opengl.kd;
import com.sun.javafx.newt.*;
import com.sun.javafx.newt.impl.*;
import com.sun.opengl.impl.egl.*;
-import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.egl.*;
public class KDDisplay extends Display {
static {
@@ -48,13 +49,20 @@ public class KDDisplay extends Display {
protected void createNative() {
// FIXME: map name to EGL_*_DISPLAY
- handle = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY);
+ long handle = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY);
if (handle == EGL.EGL_NO_DISPLAY) {
throw new NativeWindowException("eglGetDisplay failed");
}
if (!EGL.eglInitialize(handle, null, null)) {
throw new NativeWindowException("eglInitialize failed");
}
+ aDevice = new EGLGraphicsDevice(handle);
+ }
+
+ protected void closeNative() {
+ if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) {
+ EGL.eglTerminate(aDevice.getHandle());
+ }
}
}
diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDScreen.java b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDScreen.java
index b003efec7..752a55752 100755
--- a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDScreen.java
+++ b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDScreen.java
@@ -34,12 +34,20 @@
package com.sun.javafx.newt.opengl.kd;
import com.sun.javafx.newt.*;
+import javax.media.nativewindow.*;
public class KDScreen extends Screen {
public KDScreen() {
}
- protected void createNative() {
- handle = 0;
+ protected void createNative(int index) {
+ aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index);
+ }
+
+ protected void closeNative() { }
+
+ // elevate access to this package ..
+ protected void setScreenSize(int w, int h) {
+ super.setScreenSize(w, h);
}
}
diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java
index 7b7662e7c..e5a34a264 100755
--- a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java
+++ b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java
@@ -36,7 +36,7 @@ package com.sun.javafx.newt.opengl.kd;
import com.sun.javafx.newt.*;
import com.sun.javafx.newt.impl.*;
import com.sun.opengl.impl.egl.*;
-import javax.media.nativewindow.Capabilities;
+import javax.media.nativewindow.*;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import javax.media.nativewindow.NativeWindowException;
@@ -58,41 +58,21 @@ public class KDWindow extends Window {
}
protected void createNative(Capabilities caps) {
- int eglRenderableType;
- if(GLProfile.isGLES1()) {
- eglRenderableType = EGL.EGL_OPENGL_ES_BIT;
+ config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen());
+ if (config == null) {
+ throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
}
- else if(GLProfile.isGLES2()) {
- eglRenderableType = EGL.EGL_OPENGL_ES2_BIT;
- } else {
- eglRenderableType = EGL.EGL_OPENGL_BIT;
- }
- GLCapabilities glCaps = null;
- if (caps instanceof GLCapabilities) {
- glCaps = (GLCapabilities) caps;
- } else {
- glCaps = new GLCapabilities();
- glCaps.setRedBits(caps.getRedBits());
- glCaps.setGreenBits(caps.getGreenBits());
- glCaps.setBlueBits(caps.getBlueBits());
- glCaps.setAlphaBits(caps.getAlphaBits());
- }
- EGLConfig config = new EGLConfig(getDisplayHandle(), glCaps);
- this.config = config;
- chosenCaps = config.getCapabilities();
+
+ GLCapabilities eglCaps = (GLCapabilities)config.getCapabilities();
+ int[] eglAttribs = EGLGraphicsConfiguration.GLCapabilities2AttribList(eglCaps);
windowHandle = 0;
windowID = ++_windowID;
- eglWindowHandle = CreateWindow(windowID, getDisplayHandle(), config.getAttributeList());
+ eglWindowHandle = CreateWindow(windowID, getDisplayHandle(), eglAttribs);
if (eglWindowHandle == 0) {
- throw new NativeWindowException("Error creating egl window: "+eglWindowHandle);
+ throw new NativeWindowException("Error creating egl window: "+config);
}
setVisible0(eglWindowHandle, false);
- /*
- windowHandle = RealizeWindow(eglWindowHandle);
- if (0 == windowHandle) {
- throw new NativeWindowException("Error native Window Handle is null");
- } */
windowHandleClose = eglWindowHandle;
}
@@ -162,7 +142,7 @@ public class KDWindow extends Window {
nfs_width=width;
nfs_height=height;
} else {
- screen.setScreenSize(width, height);
+ ((KDScreen)screen).setScreenSize(width, height);
}
sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED);
}
diff --git a/src/newt/classes/com/sun/javafx/newt/windows/WindowsDisplay.java b/src/newt/classes/com/sun/javafx/newt/windows/WindowsDisplay.java
index bfd928190..69e868f37 100755
--- a/src/newt/classes/com/sun/javafx/newt/windows/WindowsDisplay.java
+++ b/src/newt/classes/com/sun/javafx/newt/windows/WindowsDisplay.java
@@ -34,12 +34,15 @@
package com.sun.javafx.newt.windows;
import com.sun.javafx.newt.*;
+import javax.media.nativewindow.*;
public class WindowsDisplay extends Display {
public WindowsDisplay() {
}
protected void createNative() {
- handle = 0;
+ aDevice = new DefaultGraphicsDevice(NativeWindowFactory.TYPE_WINDOWS);
}
+
+ protected void closeNative() { }
}
diff --git a/src/newt/classes/com/sun/javafx/newt/windows/WindowsScreen.java b/src/newt/classes/com/sun/javafx/newt/windows/WindowsScreen.java
index 455d0ed60..f18bb8265 100755
--- a/src/newt/classes/com/sun/javafx/newt/windows/WindowsScreen.java
+++ b/src/newt/classes/com/sun/javafx/newt/windows/WindowsScreen.java
@@ -34,12 +34,15 @@
package com.sun.javafx.newt.windows;
import com.sun.javafx.newt.*;
+import javax.media.nativewindow.*;
public class WindowsScreen extends Screen {
public WindowsScreen() {
}
- protected void createNative() {
- handle = 0;
+ protected void createNative(int index) {
+ aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index);
}
+
+ protected void closeNative() { }
}
diff --git a/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java
index 6c7d8ab56..abb26a009 100755
--- a/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java
+++ b/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java
@@ -33,8 +33,7 @@
package com.sun.javafx.newt.windows;
-import javax.media.nativewindow.Capabilities;
-import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.*;
import com.sun.javafx.newt.*;
import com.sun.javafx.newt.impl.*;
@@ -65,11 +64,10 @@ public class WindowsWindow extends Window {
protected void createNative(Capabilities caps) {
long wndClass = getWindowClass();
- // FIXME: no way to really set the proper Capabilities nor the
- // AbstractGraphicsConfiguration since we don't do (OpenGL)
- // pixel format selection here
- chosenCaps = (Capabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID)
- config = null; // n/a
+ config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen());
+ if (config == null) {
+ throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
+ }
windowHandle = CreateWindow(WINDOW_CLASS_NAME, getHInstance(), 0, undecorated, x, y, width, height);
if (windowHandle == 0) {
throw new NativeWindowException("Error creating window");
diff --git a/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java b/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java
index 5486c9fb6..2371b20e8 100755
--- a/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java
+++ b/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java
@@ -35,6 +35,8 @@ package com.sun.javafx.newt.x11;
import com.sun.javafx.newt.*;
import com.sun.javafx.newt.impl.*;
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.x11.*;
public class X11Display extends Display {
static {
@@ -45,12 +47,15 @@ public class X11Display extends Display {
}
protected void createNative() {
- handle = CreateDisplay(name);
+ long handle = CreateDisplay(name);
if (handle == 0 ) {
throw new RuntimeException("Error creating display: "+name);
}
+ aDevice = new X11GraphicsDevice(handle);
}
+ protected void closeNative() { }
+
//----------------------------------------------------------------------
// Internals only
//
diff --git a/src/newt/classes/com/sun/javafx/newt/x11/X11Screen.java b/src/newt/classes/com/sun/javafx/newt/x11/X11Screen.java
index ede522685..36d9d8baf 100755
--- a/src/newt/classes/com/sun/javafx/newt/x11/X11Screen.java
+++ b/src/newt/classes/com/sun/javafx/newt/x11/X11Screen.java
@@ -35,6 +35,8 @@ package com.sun.javafx.newt.x11;
import com.sun.javafx.newt.*;
import com.sun.javafx.newt.impl.*;
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.x11.*;
public class X11Screen extends Screen {
static {
@@ -44,15 +46,18 @@ public class X11Screen extends Screen {
public X11Screen() {
}
- protected void createNative() {
- handle = GetScreen(display.getHandle(), index);
+ protected void createNative(int index) {
+ long handle = GetScreen(display.getHandle(), index);
if (handle == 0 ) {
throw new RuntimeException("Error creating screen: "+index);
}
+ aScreen = new X11GraphicsScreen((X11GraphicsDevice)getDisplay().getGraphicsDevice(), index);
setScreenSize(getWidth0(display.getHandle(), index),
getHeight0(display.getHandle(), index));
}
+ protected void closeNative() { }
+
//----------------------------------------------------------------------
// Internals only
//
diff --git a/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java b/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java
index 9314cc0ae..13333ed78 100755
--- a/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java
+++ b/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java
@@ -35,9 +35,7 @@ package com.sun.javafx.newt.x11;
import com.sun.javafx.newt.*;
import com.sun.javafx.newt.impl.*;
-import javax.media.nativewindow.Capabilities;
-import javax.media.nativewindow.GraphicsConfigurationFactory;
-import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.*;
import javax.media.nativewindow.x11.*;
public class X11Window extends Window {
@@ -57,18 +55,13 @@ public class X11Window extends Window {
}
protected void createNative(Capabilities caps) {
- // FIXME: we're running the visual selection algorithm (i.e.,
- // from the OpenGL binding) but have no mechanism for
- // capturing the chosen Capabilities
- chosenCaps = (Capabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID)
- X11GraphicsDevice device = new X11GraphicsDevice(getScreenIndex());
- X11GraphicsConfiguration config = (X11GraphicsConfiguration)
- GraphicsConfigurationFactory.getFactory(device).chooseGraphicsConfiguration(caps, null, device);
- long visualID = 0;
- if (config != null) {
- visualID = ((X11GraphicsConfiguration) config).getVisualID();
+ config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen());
+ if (config == null) {
+ throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
}
- long w = CreateWindow(getDisplayHandle(), getScreenHandle(), getScreenIndex(), visualID, x, y, width, height);
+ X11GraphicsConfiguration x11config = (X11GraphicsConfiguration) config;
+ long visualID = x11config.getVisualID();
+ long w = CreateWindow(getDisplayHandle(), getScreenIndex(), visualID, x, y, width, height);
if (w == 0 || w!=windowHandle) {
throw new NativeWindowException("Error creating window: "+w);
}
@@ -135,7 +128,7 @@ public class X11Window extends Window {
//
private static native boolean initIDs();
- private native long CreateWindow(long display, long screen, int screen_index,
+ private native long CreateWindow(long display, int screen_index,
long visualID, int x, int y, int width, int height);
private native void CloseWindow(long display, long windowHandle);
private native void setVisible0(long display, long windowHandle, boolean visible);
@@ -163,8 +156,7 @@ public class X11Window extends Window {
sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED);
}
- private void windowCreated(long visualID, long windowHandle, long windowDeleteAtom) {
- this.config = new X11GraphicsConfiguration(visualID);
+ private void windowCreated(long windowHandle, long windowDeleteAtom) {
this.windowHandle = windowHandle;
this.windowDeleteAtom=windowDeleteAtom;
}