diff options
author | Kenneth Russel <[email protected]> | 2009-03-19 00:32:21 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2009-03-19 00:32:21 +0000 |
commit | c4cd0db6b9865c97245921d2824bcc4c1541e615 (patch) | |
tree | 6f9df4a383767992fa9ec36d820630bfabedf75a /src/newt/classes/com | |
parent | 23d13ee00ebdf7052299fc65af6f50e43d673e67 (diff) |
Movement of Capabilities class and chooseCapabilities functionality
into NativeWindowFactory introduced an undesirable dependence between
the windowing toolkit, which can be replaced via NativeWindowFactory,
and the library which implements the selection algorithm, for example
OpenGL. This would prevent, for example, an easy SWT port of JOGL.
To fix this, refactored chooseCapabilities into new
GraphicsConfigurationFactory, the default implementation of which is
currently a no-op on X11 platforms, and which is provided by JOGL in a
toolkit-agnostic manner via GLX. Refactored OpenGL portions of
Capabilities class back into GLCapabilities. Reintroduced
GLCapabilitiesChooser interface for compatibility and to avoid having
to import javax.media.nativewindow classes in most user code.
Fixed problem in GLProfile where failures to load native libraries
were being squelched. Reorganized build to have all outputs under
build/ directory.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1884 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/newt/classes/com')
8 files changed, 96 insertions, 64 deletions
diff --git a/src/newt/classes/com/sun/javafx/newt/NewtFactory.java b/src/newt/classes/com/sun/javafx/newt/NewtFactory.java index c0116d0a3..c455dce19 100755 --- a/src/newt/classes/com/sun/javafx/newt/NewtFactory.java +++ b/src/newt/classes/com/sun/javafx/newt/NewtFactory.java @@ -33,7 +33,8 @@ package com.sun.javafx.newt; -import javax.media.nativewindow.NWCapabilities; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.Capabilities; import java.util.ArrayList; import java.util.Iterator; @@ -124,18 +125,18 @@ public abstract class NewtFactory { /** * Create a Window entity, incl native creation */ - public static Window createWindow(Screen screen, NWCapabilities caps) { + public static Window createWindow(Screen screen, Capabilities caps) { return Window.create(getWindowType(), screen, caps); } - public static Window createWindow(Screen screen, NWCapabilities caps, boolean undecorated) { + public static Window createWindow(Screen screen, Capabilities caps, boolean undecorated) { return Window.create(getWindowType(), screen, caps, undecorated); } /** * Create a Window entity using the given implementation type, incl native creation */ - public static Window createWindow(String type, Screen screen, NWCapabilities caps) { + public static Window createWindow(String type, Screen screen, Capabilities caps) { return Window.create(type, screen, caps); } @@ -156,10 +157,10 @@ public abstract class NewtFactory { /** * Instantiate a Window entity using the native handle. */ - public static Window wrapWindow(Screen screen, NWCapabilities caps, long visualID, + public static Window wrapWindow(Screen screen, Capabilities caps, AbstractGraphicsConfiguration config, long windowHandle, boolean fullscreen, boolean visible, int x, int y, int width, int height) { - return Window.wrapHandle(getWindowType(), screen, caps, visualID, + return Window.wrapHandle(getWindowType(), screen, caps, config, windowHandle, fullscreen, visible, x, y, width, height); } diff --git a/src/newt/classes/com/sun/javafx/newt/Window.java b/src/newt/classes/com/sun/javafx/newt/Window.java index e9466b7d6..f323f824e 100755 --- a/src/newt/classes/com/sun/javafx/newt/Window.java +++ b/src/newt/classes/com/sun/javafx/newt/Window.java @@ -34,7 +34,8 @@ package com.sun.javafx.newt; import com.sun.javafx.newt.impl.Debug; -import javax.media.nativewindow.NWCapabilities; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.Capabilities; import javax.media.nativewindow.NativeWindow; import javax.media.nativewindow.NativeWindowException; @@ -82,17 +83,16 @@ public abstract class Window implements NativeWindow return windowClass; } - protected static Window create(String type, Screen screen, NWCapabilities caps) { + protected static Window create(String type, Screen screen, Capabilities caps) { return create(type, screen, caps, false); } - protected static Window create(String type, Screen screen, NWCapabilities caps, boolean undecorated) { + protected static Window create(String type, Screen screen, Capabilities caps, boolean undecorated) { try { Class windowClass = getWindowClass(type); Window window = (Window) windowClass.newInstance(); window.invalidate(); window.screen = screen; - window.visualID = 0; window.setUndecorated(undecorated); window.createNative(caps); return window; @@ -102,7 +102,7 @@ public abstract class Window implements NativeWindow } } - protected static Window wrapHandle(String type, Screen screen, NWCapabilities caps, long visualID, + protected static Window wrapHandle(String type, Screen screen, Capabilities caps, AbstractGraphicsConfiguration config, long windowHandle, boolean fullscreen, boolean visible, int x, int y, int width, int height) { @@ -112,7 +112,7 @@ public abstract class Window implements NativeWindow window.invalidate(); window.screen = screen; window.chosenCaps = caps; - window.visualID = visualID; + window.config = config; window.windowHandle = windowHandle; window.fullscreen=fullscreen; window.visible=visible; @@ -128,12 +128,12 @@ public abstract class Window implements NativeWindow } /** - * Create native windowHandle, ie creates a new native invisible window + * Create native windowHandle, ie creates a new native invisible window. * - * Shall use the capabilities to determine the visualID - * and shall set chosenCaps. + * Shall use the capabilities to determine the graphics configuration + * and shall set the chosen capabilities. */ - protected abstract void createNative(NWCapabilities caps); + protected abstract void createNative(Capabilities caps); protected abstract void closeNative(); @@ -170,7 +170,7 @@ public abstract class Window implements NativeWindow ", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ ", visible "+isVisible()+ ", wrappedWindow "+getWrappedWindow()+ - ", visualID "+visualID+ + ", config "+config+ ", "+chosenCaps+ ", screen handle/index "+getScreenHandle()+"/"+getScreenIndex() + ", display handle "+getDisplayHandle()); @@ -193,14 +193,9 @@ public abstract class Window implements NativeWindow protected Screen screen; - /** - * The NWCapabilities shall be used to determine the visualID - */ - protected NWCapabilities chosenCaps; - /** - * The visualID shall be determined using the NWCapabilities - */ - protected long visualID; + // The Capabilities is used to determine the AbstractGraphicsConfiguration + protected Capabilities chosenCaps; + protected AbstractGraphicsConfiguration config; protected long windowHandle; protected boolean locked=false; protected boolean fullscreen, visible; @@ -272,7 +267,7 @@ public abstract class Window implements NativeWindow public void invalidate(boolean internal) { unlockSurface(); screen = null; - visualID = 0; + config = null; chosenCaps = null; windowHandle = 0; locked = false; @@ -315,16 +310,16 @@ public abstract class Window implements NativeWindow return windowHandle; // default: return window handle } - public NWCapabilities getChosenCapabilities() { + public Capabilities getChosenCapabilities() { if (chosenCaps == null) return null; // Must return a new copy to avoid mutation by end user - return (NWCapabilities) chosenCaps.clone(); + return (Capabilities) chosenCaps.clone(); } - public long getVisualID() { - return visualID; + public AbstractGraphicsConfiguration getGraphicsConfiguration() { + return config; } public int getWidth() { 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 bc1ffb828..bd29d7576 100644 --- a/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java +++ b/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java @@ -47,7 +47,7 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.util.*; import com.sun.javafx.newt.Window; -import javax.media.nativewindow.NWCapabilities; +import javax.media.nativewindow.Capabilities; import javax.media.nativewindow.NativeWindowException; /** An implementation of the Newt Window class built using the @@ -75,9 +75,9 @@ public class AWTWindow extends Window { } } - protected void createNative(NWCapabilities caps) { - chosenCaps = (NWCapabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID) - visualID = 0; // n/a + protected void createNative(Capabilities caps) { + chosenCaps = (Capabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID) + config = null; // n/a runOnEDT(new Runnable() { public void run() { frame = new Frame(getTitle()); 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 3447ea888..598313fcd 100755 --- a/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java +++ b/src/newt/classes/com/sun/javafx/newt/macosx/MacWindow.java @@ -33,7 +33,7 @@ package com.sun.javafx.newt.macosx; -import javax.media.nativewindow.NWCapabilities; +import javax.media.nativewindow.Capabilities; import javax.media.nativewindow.NativeWindowException; import com.sun.javafx.newt.*; @@ -143,9 +143,12 @@ public class MacWindow extends Window { public MacWindow() { } - protected void createNative(NWCapabilities caps) { - chosenCaps = (NWCapabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID) - visualID = 0; // n/a + 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 } 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 1d4b4c5ad..196396857 100644 --- a/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java @@ -90,7 +90,7 @@ public class GLWindow extends Window implements GLAutoDrawable { } /** Creates a new GLWindow on the local display, screen 0, with a - dummy visual ID, and with the default NWCapabilities. */ + dummy visual ID, and with the default GLCapabilities. */ public static GLWindow create() { return create(null, null, false); } @@ -103,26 +103,26 @@ public class GLWindow extends Window implements GLAutoDrawable { public static GLWindow create(Window window) { return create(window, null, false); } - public static GLWindow create(NWCapabilities caps) { + public static GLWindow create(GLCapabilities caps) { return create(null, caps, false); } /** Creates a new GLWindow on the local display, screen 0, with a - dummy visual ID, and with the given NWCapabilities. */ - public static GLWindow create(NWCapabilities caps, boolean undecorated) { + dummy visual ID, and with the given GLCapabilities. */ + public static GLWindow create(GLCapabilities caps, boolean undecorated) { return create(null, caps, undecorated); } - /** Creates a new GLWindow referring to the given window, and with the given NWCapabilities. */ - public static GLWindow create(Window window, NWCapabilities caps) { + /** Creates a new GLWindow referring to the given window, and with the given GLCapabilities. */ + public static GLWindow create(Window window, GLCapabilities caps) { return create(window, caps, false); } public static GLWindow create(Window window, - NWCapabilities caps, + GLCapabilities caps, boolean undecorated) { if (caps == null) { - caps = new NWCapabilities(); + caps = new GLCapabilities(); } if (window == null) { Display display = NewtFactory.createDisplay(null); // local display @@ -133,7 +133,7 @@ public class GLWindow extends Window implements GLAutoDrawable { return new GLWindow(window); } - protected void createNative(NWCapabilities caps) { + protected void createNative(Capabilities caps) { shouldNotCallThis(); } @@ -247,7 +247,7 @@ public class GLWindow extends Window implements GLAutoDrawable { if (window.getWrappedWindow() != null) { nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow()); } - drawable = factory.createGLDrawable(nw, window.getChosenCapabilities(), null); + drawable = factory.createGLDrawable(nw, (GLCapabilities) window.getChosenCapabilities(), null); window.setVisible(true); drawable.setRealized(true); context = drawable.createContext(null); @@ -501,6 +501,14 @@ public class GLWindow extends Window implements GLAutoDrawable { private SwapBuffersAction swapBuffersAction = new SwapBuffersAction(); //---------------------------------------------------------------------- + // Window methods that are not really needed + // + + public Capabilities getChosenCapabilities() { + return getChosenGLCapabilities(); + } + + //---------------------------------------------------------------------- // GLDrawable methods that are not really needed // @@ -511,11 +519,11 @@ public class GLWindow extends Window implements GLAutoDrawable { public void setRealized(boolean realized) { } - public NWCapabilities getChosenNWCapabilities() { + public GLCapabilities getChosenGLCapabilities() { if (drawable == null) return null; - return drawable.getChosenNWCapabilities(); + return drawable.getChosenGLCapabilities(); } public NativeWindow getNativeWindow() { 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 e17e3040d..7b7662e7c 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,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.NWCapabilities; +import javax.media.nativewindow.Capabilities; +import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import javax.media.nativewindow.NativeWindowException; @@ -56,7 +57,7 @@ public class KDWindow extends Window { public KDWindow() { } - protected void createNative(NWCapabilities caps) { + protected void createNative(Capabilities caps) { int eglRenderableType; if(GLProfile.isGLES1()) { eglRenderableType = EGL.EGL_OPENGL_ES_BIT; @@ -66,8 +67,18 @@ public class KDWindow extends Window { } else { eglRenderableType = EGL.EGL_OPENGL_BIT; } - EGLConfig config = new EGLConfig(getDisplayHandle(), caps); - visualID = config.getNativeConfigID(); + 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(); windowHandle = 0; 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 956220c47..0d9015d66 100755 --- a/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java +++ b/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java @@ -33,7 +33,7 @@ package com.sun.javafx.newt.windows; -import javax.media.nativewindow.NWCapabilities; +import javax.media.nativewindow.Capabilities; import javax.media.nativewindow.NativeWindowException; import com.sun.javafx.newt.*; @@ -63,11 +63,14 @@ public class WindowsWindow extends Window { return hdc; } - protected void createNative(NWCapabilities caps) { + protected void createNative(Capabilities caps) { long wndClass = getWindowClass(); - chosenCaps = (NWCapabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID) - visualID = 0; // n/a - windowHandle = CreateWindow(WINDOW_CLASS_NAME, getHInstance(), visualID, x, y, width, height); + // 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 + windowHandle = CreateWindow(WINDOW_CLASS_NAME, getHInstance(), 0, x, y, width, height); if (windowHandle == 0) { throw new NativeWindowException("Error creating window"); } 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 6e336f25d..9314cc0ae 100755 --- a/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java +++ b/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java @@ -35,8 +35,10 @@ package com.sun.javafx.newt.x11; import com.sun.javafx.newt.*; import com.sun.javafx.newt.impl.*; -import javax.media.nativewindow.NWCapabilities; +import javax.media.nativewindow.Capabilities; +import javax.media.nativewindow.GraphicsConfigurationFactory; import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.x11.*; public class X11Window extends Window { private static final String WINDOW_CLASS_NAME = "NewtWindow"; @@ -54,9 +56,18 @@ public class X11Window extends Window { public X11Window() { } - protected void createNative(NWCapabilities caps) { - chosenCaps = (NWCapabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID) - visualID = 0; // n/a + 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(); + } long w = CreateWindow(getDisplayHandle(), getScreenHandle(), getScreenIndex(), visualID, x, y, width, height); if (w == 0 || w!=windowHandle) { throw new NativeWindowException("Error creating window: "+w); @@ -153,7 +164,7 @@ public class X11Window extends Window { } private void windowCreated(long visualID, long windowHandle, long windowDeleteAtom) { - this.visualID = visualID; + this.config = new X11GraphicsConfiguration(visualID); this.windowHandle = windowHandle; this.windowDeleteAtom=windowDeleteAtom; } |