From bafd9b99816f55c105230a59211caf13f0315910 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 23 Nov 2011 07:44:42 +0100 Subject: NativeSurface's getGraphicsConfiguration() returns the native (delegated) AbstractGraphicsConfiguration, if delegation is used. This change restricts the usage of AbstractGraphicsConfiguration's getNativeGraphicsConfiguration() to NativeSurface implementations and hence reduces complexity. NativeSurface implementations are adapted and access to it's AbstractGraphicsConfiguration is controlled via get/set method avoiding flawed usage (read/write), since read access shall return the delegated AbstractGraphicsConfiguration, if used. --- src/newt/classes/jogamp/newt/OffscreenWindow.java | 9 +++--- src/newt/classes/jogamp/newt/WindowImpl.java | 16 ++++++---- .../jogamp/newt/driver/android/AndroidWindow.java | 2 +- .../classes/jogamp/newt/driver/awt/AWTCanvas.java | 4 +-- .../classes/jogamp/newt/driver/awt/AWTWindow.java | 36 +++++++++++----------- .../jogamp/newt/driver/broadcom/egl/Window.java | 21 +++++++------ .../jogamp/newt/driver/intel/gdl/Window.java | 9 +++--- .../classes/jogamp/newt/driver/kd/KDWindow.java | 9 +++--- .../jogamp/newt/driver/macosx/MacWindow.java | 8 +++-- .../jogamp/newt/driver/windows/WindowsWindow.java | 11 ++++--- .../classes/jogamp/newt/driver/x11/X11Window.java | 10 +++--- 11 files changed, 75 insertions(+), 60 deletions(-) (limited to 'src/newt/classes/jogamp') diff --git a/src/newt/classes/jogamp/newt/OffscreenWindow.java b/src/newt/classes/jogamp/newt/OffscreenWindow.java index e923c37a9..050e24b6c 100644 --- a/src/newt/classes/jogamp/newt/OffscreenWindow.java +++ b/src/newt/classes/jogamp/newt/OffscreenWindow.java @@ -51,12 +51,13 @@ public class OffscreenWindow extends WindowImpl implements SurfaceChangeable { if(capsRequested.isOnscreen()) { throw new NativeWindowException("Capabilities is onscreen"); } - AbstractGraphicsScreen aScreen = getScreen().getGraphicsScreen(); - config = GraphicsConfigurationFactory.getFactory(aScreen.getDevice()).chooseGraphicsConfiguration( - capsRequested, capsRequested, capabilitiesChooser, aScreen); - if (config == null) { + final AbstractGraphicsScreen aScreen = getScreen().getGraphicsScreen(); + final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(aScreen.getDevice()).chooseGraphicsConfiguration( + capsRequested, capsRequested, capabilitiesChooser, aScreen); + if (null == cfg) { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } + setGraphicsConfiguration(cfg); synchronized(OffscreenWindow.class) { setWindowHandle(nextWindowHandle++); diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index f4856bafe..5e211011c 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -87,7 +87,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer private boolean screenReferenceAdded = false; private NativeWindow parentWindow = null; private long parentWindowHandle = 0; - protected AbstractGraphicsConfiguration config = null; + private AbstractGraphicsConfiguration config = null; // control access due to delegation protected CapabilitiesImmutable capsRequested = null; protected CapabilitiesChooser capabilitiesChooser = null; // default null -> default protected boolean fullscreen = false, hasFocus = false; @@ -215,6 +215,10 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } } + protected final void setGraphicsConfiguration(AbstractGraphicsConfiguration cfg) { + config = cfg; + } + public static interface LifecycleHook { /** * Reset of internal state counter, ie totalFrames, etc. @@ -547,7 +551,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer if ( LOCK_SURFACE_NOT_READY == res ) { try { if( isNativeValid() ) { - final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + final AbstractGraphicsDevice adevice = getGraphicsConfiguration().getScreen().getDevice(); adevice.lock(); try { res = lockSurfaceImpl(); @@ -572,7 +576,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer windowLock.validateLocked(); if (surfaceLock.getHoldCount() == 1) { - final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + final AbstractGraphicsDevice adevice = getGraphicsConfiguration().getScreen().getDevice(); try { unlockSurfaceImpl(); } finally { @@ -615,8 +619,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer return false; } - public AbstractGraphicsConfiguration getGraphicsConfiguration() { - return config; + public final AbstractGraphicsConfiguration getGraphicsConfiguration() { + return config.getNativeGraphicsConfiguration(); } public final long getDisplayHandle() { @@ -1251,7 +1255,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } public final CapabilitiesImmutable getChosenCapabilities() { - return config.getNativeGraphicsConfiguration().getChosenCapabilities(); + return getGraphicsConfiguration().getChosenCapabilities(); } public final CapabilitiesImmutable getRequestedCapabilities() { diff --git a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java index 9cefa8163..32879b037 100644 --- a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java +++ b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java @@ -239,7 +239,7 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { } // propagate data .. - config = eglConfig; + setGraphicsConfiguration(eglConfig); setWindowHandle(surfaceHandle); Log.d(MD.TAG, "createNativeImpl X"); } diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java index 0729f02ab..390d96fde 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java +++ b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java @@ -99,7 +99,7 @@ public class AWTCanvas extends Canvas { if(null==awtConfig) { throw new NativeWindowException("Error: NULL AWTGraphicsConfiguration"); } - chosen = awtConfig.getGraphicsConfiguration(); + chosen = awtConfig.getAWTGraphicsConfiguration(); // before native peer is valid: X11 disableBackgroundErase(); @@ -192,7 +192,7 @@ public class AWTCanvas extends Canvas { */ AWTGraphicsConfiguration config = chooseGraphicsConfiguration( awtConfig.getChosenCapabilities(), awtConfig.getRequestedCapabilities(), chooser, gc.getDevice()); - final GraphicsConfiguration compatible = (null!=config)?config.getGraphicsConfiguration():null; + final GraphicsConfiguration compatible = (null!=config)?config.getAWTGraphicsConfiguration():null; if(Window.DEBUG_IMPLEMENTATION) { Exception e = new Exception("Info: Call Stack: "+Thread.currentThread().getName()); e.printStackTrace(); diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java b/src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java index 9aaa82fec..ca280fa8b 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java +++ b/src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java @@ -39,7 +39,9 @@ import java.awt.Container; import java.awt.DisplayMode; import java.awt.Frame; import java.awt.Insets; + import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.awt.AWTGraphicsConfiguration; import javax.media.nativewindow.awt.AWTGraphicsDevice; import javax.media.nativewindow.awt.AWTGraphicsScreen; import javax.media.nativewindow.util.Point; @@ -145,27 +147,24 @@ public class AWTWindow extends WindowImpl { public boolean hasDeviceChanged() { boolean res = canvas.hasDeviceChanged(); if(res) { - config = canvas.getAWTGraphicsConfiguration(); - if (config == null) { + final AWTGraphicsConfiguration cfg = canvas.getAWTGraphicsConfiguration(); + if (null == cfg) { throw new NativeWindowException("Error Device change null GraphicsConfiguration: "+this); } - updateDeviceData(); + setGraphicsConfiguration(cfg); + + // propagate new info .. + ((AWTScreen)getScreen()).setAWTGraphicsScreen((AWTGraphicsScreen)cfg.getScreen()); + ((AWTDisplay)getScreen().getDisplay()).setAWTGraphicsDevice((AWTGraphicsDevice)cfg.getScreen().getDevice()); + + final DisplayMode mode = ((AWTGraphicsDevice)cfg.getScreen().getDevice()).getGraphicsDevice().getDisplayMode(); + if(null != mode) { + ((AWTScreen)getScreen()).setScreenSize(mode.getWidth(), mode.getHeight()); + } } return res; } - private void updateDeviceData() { - // propagate new info .. - ((AWTScreen)getScreen()).setAWTGraphicsScreen((AWTGraphicsScreen)config.getScreen()); - ((AWTDisplay)getScreen().getDisplay()).setAWTGraphicsDevice((AWTGraphicsDevice)config.getScreen().getDevice()); - - final DisplayMode mode = ((AWTGraphicsDevice)config.getScreen().getDevice()).getGraphicsDevice().getDisplayMode(); - if(null != mode) { - ((AWTScreen)getScreen()).setScreenSize(mode.getWidth(), mode.getHeight()); - } - - } - protected void updateInsetsImpl(javax.media.nativewindow.util.Insets insets) { Insets contInsets = container.getInsets(); insets.setLeftWidth(contInsets.left); @@ -202,11 +201,12 @@ public class AWTWindow extends WindowImpl { if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) { if( 0 != ( FLAG_IS_VISIBLE & flags ) ) { if( !hasDeviceChanged() ) { - // oops ?? - config = canvas.getAWTGraphicsConfiguration(); - if(null == config) { + // oops ?? + final AWTGraphicsConfiguration cfg = canvas.getAWTGraphicsConfiguration(); + if(null == cfg) { throw new NativeWindowException("Error: !hasDeviceChanged && null == GraphicsConfiguration: "+this); } + setGraphicsConfiguration(cfg); } } visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags)); diff --git a/src/newt/classes/jogamp/newt/driver/broadcom/egl/Window.java b/src/newt/classes/jogamp/newt/driver/broadcom/egl/Window.java index 7df293c0d..6f66eedd3 100644 --- a/src/newt/classes/jogamp/newt/driver/broadcom/egl/Window.java +++ b/src/newt/classes/jogamp/newt/driver/broadcom/egl/Window.java @@ -35,6 +35,7 @@ package jogamp.newt.driver.broadcom.egl; import jogamp.opengl.egl.*; import javax.media.nativewindow.*; +import javax.media.nativewindow.awt.AWTGraphicsConfiguration; import javax.media.nativewindow.util.Insets; import javax.media.nativewindow.util.Point; import javax.media.opengl.GLCapabilitiesImmutable; @@ -51,13 +52,14 @@ public class Window extends jogamp.newt.WindowImpl { if(0!=getParentWindowHandle()) { throw new RuntimeException("Window parenting not supported (yet)"); } - // query a good configuration .. even thought we drop this one - // and reuse the EGLUtil choosen one later. - config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration( + // query a good configuration, however chose the final one by the native queried egl-cfg-id + // after creation at {@link #windowCreated(int, int, int)}. + final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration( capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen()); - if (config == null) { + if (null == cfg) { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } + setGraphicsConfiguration(cfg); setSizeImpl(getScreen().getWidth(), getScreen().getHeight()); setWindowHandle(realizeWindow(true, width, height)); @@ -139,7 +141,7 @@ public class Window extends jogamp.newt.WindowImpl { private long realizeWindow(boolean chromaKey, int width, int height) { if(DEBUG_IMPLEMENTATION) { - System.err.println("BCEGL Window.realizeWindow() with: chroma "+chromaKey+", "+width+"x"+height+", "+config); + System.err.println("BCEGL Window.realizeWindow() with: chroma "+chromaKey+", "+width+"x"+height+", "+getGraphicsConfiguration()); } long handle = CreateWindow(getDisplayHandle(), chromaKey, width, height); if (0 == handle) { @@ -152,13 +154,14 @@ public class Window extends jogamp.newt.WindowImpl { private void windowCreated(int cfgID, int width, int height) { this.width = width; this.height = height; - GLCapabilitiesImmutable capsReq = (GLCapabilitiesImmutable) config.getRequestedCapabilities(); - config = EGLGraphicsConfiguration.create(capsReq, getScreen().getGraphicsScreen(), cfgID); - if (config == null) { + GLCapabilitiesImmutable capsReq = (GLCapabilitiesImmutable) getGraphicsConfiguration().getRequestedCapabilities(); + final AbstractGraphicsConfiguration cfg = EGLGraphicsConfiguration.create(capsReq, getScreen().getGraphicsScreen(), cfgID); + if (null == cfg) { throw new NativeWindowException("Error creating EGLGraphicsConfiguration from id: "+cfgID+", "+this); } + setGraphicsConfiguration(cfg); if(DEBUG_IMPLEMENTATION) { - System.err.println("BCEGL Window.windowCreated(): "+toHexString(cfgID)+", "+width+"x"+height+", "+config); + System.err.println("BCEGL Window.windowCreated(): "+toHexString(cfgID)+", "+width+"x"+height+", "+cfg); } } diff --git a/src/newt/classes/jogamp/newt/driver/intel/gdl/Window.java b/src/newt/classes/jogamp/newt/driver/intel/gdl/Window.java index ab3e95e7e..6fc76a12d 100644 --- a/src/newt/classes/jogamp/newt/driver/intel/gdl/Window.java +++ b/src/newt/classes/jogamp/newt/driver/intel/gdl/Window.java @@ -51,14 +51,15 @@ public class Window extends jogamp.newt.WindowImpl { if(0!=getParentWindowHandle()) { throw new NativeWindowException("GDL Window does not support window parenting"); } - AbstractGraphicsScreen aScreen = getScreen().getGraphicsScreen(); - AbstractGraphicsDevice aDevice = getScreen().getDisplay().getGraphicsDevice(); + final AbstractGraphicsScreen aScreen = getScreen().getGraphicsScreen(); + final AbstractGraphicsDevice aDevice = getScreen().getDisplay().getGraphicsDevice(); - config = GraphicsConfigurationFactory.getFactory(aDevice).chooseGraphicsConfiguration( + final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(aDevice).chooseGraphicsConfiguration( capsRequested, capsRequested, capabilitiesChooser, aScreen); - if (config == null) { + if (null == cfg) { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } + setGraphicsConfiguration(cfg); synchronized(Window.class) { setWindowHandle(nextWindowHandle++); // just a marker diff --git a/src/newt/classes/jogamp/newt/driver/kd/KDWindow.java b/src/newt/classes/jogamp/newt/driver/kd/KDWindow.java index 10a75a017..0c720e559 100644 --- a/src/newt/classes/jogamp/newt/driver/kd/KDWindow.java +++ b/src/newt/classes/jogamp/newt/driver/kd/KDWindow.java @@ -55,18 +55,19 @@ public class KDWindow extends WindowImpl { if(0!=getParentWindowHandle()) { throw new RuntimeException("Window parenting not supported (yet)"); } - config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration( + final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration( capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen()); - if (config == null) { + if (null == cfg) { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } + setGraphicsConfiguration(cfg); - GLCapabilitiesImmutable eglCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + GLCapabilitiesImmutable eglCaps = (GLCapabilitiesImmutable) cfg.getChosenCapabilities(); int[] eglAttribs = EGLGraphicsConfiguration.GLCapabilities2AttribList(eglCaps); eglWindowHandle = CreateWindow(getDisplayHandle(), eglAttribs); if (eglWindowHandle == 0) { - throw new NativeWindowException("Error creating egl window: "+config); + throw new NativeWindowException("Error creating egl window: "+cfg); } setVisible0(eglWindowHandle, false); setWindowHandle(RealizeWindow(eglWindowHandle)); diff --git a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java b/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java index b7e572b6c..277f7e6b9 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java @@ -34,6 +34,7 @@ package jogamp.newt.driver.macosx; +import javax.media.nativewindow.AbstractGraphicsConfiguration; import javax.media.nativewindow.GraphicsConfigurationFactory; import javax.media.nativewindow.NativeWindow; import javax.media.nativewindow.NativeWindowException; @@ -59,11 +60,12 @@ public class MacWindow extends WindowImpl implements SurfaceChangeable, DriverCl @Override protected void createNativeImpl() { - config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration( + final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration( capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen()); - if (config == null) { + if (null == cfg) { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } + setGraphicsConfiguration(cfg); reconfigureWindowImpl(x, y, width, height, getReconfigureFlags(FLAG_CHANGE_VISIBILITY, true)); if (0 == getWindowHandle()) { throw new NativeWindowException("Error creating window"); @@ -303,7 +305,7 @@ public class MacWindow extends WindowImpl implements SurfaceChangeable, DriverCl } setWindowHandle(createWindow0(getParentWindowHandle(), pS.getX(), pS.getY(), width, height, - (config.getChosenCapabilities().isBackgroundOpaque() && !offscreenInstance), + (getGraphicsConfiguration().getChosenCapabilities().isBackgroundOpaque() && !offscreenInstance), fullscreen, ((isUndecorated() || offscreenInstance) ? NSBorderlessWindowMask : diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java b/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java index 28be93acd..2f3fcd726 100644 --- a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java +++ b/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java @@ -36,6 +36,8 @@ package jogamp.newt.driver.windows; import jogamp.nativewindow.windows.GDI; import jogamp.newt.WindowImpl; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; import javax.media.nativewindow.GraphicsConfigurationFactory; import javax.media.nativewindow.NativeWindowException; import javax.media.nativewindow.util.Insets; @@ -101,13 +103,14 @@ public class WindowsWindow extends WindowImpl { } protected void createNativeImpl() { - WindowsScreen screen = (WindowsScreen) getScreen(); - WindowsDisplay display = (WindowsDisplay) screen.getDisplay(); - config = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration( + final WindowsScreen screen = (WindowsScreen) getScreen(); + final WindowsDisplay display = (WindowsDisplay) screen.getDisplay(); + final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()).chooseGraphicsConfiguration( capsRequested, capsRequested, capabilitiesChooser, screen.getGraphicsScreen()); - if (config == null) { + if (null == cfg) { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } + setGraphicsConfiguration(cfg); final int flags = getReconfigureFlags(0, true) & ( FLAG_IS_ALWAYSONTOP | FLAG_IS_UNDECORATED ) ; setWindowHandle(CreateWindow0(display.getHInstance(), display.getWindowClassName(), display.getWindowClassName(), diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java index 2b6bac215..24d9d9edf 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java +++ b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java @@ -57,16 +57,16 @@ public class X11Window extends WindowImpl { final X11Screen screen = (X11Screen) getScreen(); final X11Display display = (X11Display) screen.getDisplay(); final GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice()); - config = factory.chooseGraphicsConfiguration( + final X11GraphicsConfiguration cfg = (X11GraphicsConfiguration) factory.chooseGraphicsConfiguration( capsRequested, capsRequested, capabilitiesChooser, screen.getGraphicsScreen()); if(DEBUG_IMPLEMENTATION) { - System.err.println("X11Window.createNativeImpl() factory: "+factory+", chosen config: "+config); + System.err.println("X11Window.createNativeImpl() factory: "+factory+", chosen config: "+cfg); } - if (config == null) { + if (null == cfg) { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } - X11GraphicsConfiguration x11config = (X11GraphicsConfiguration) config; - final long visualID = x11config.getVisualID(); + setGraphicsConfiguration(cfg); + final long visualID = cfg.getVisualID(); final int flags = getReconfigureFlags(0, true) & ( FLAG_IS_ALWAYSONTOP | FLAG_IS_UNDECORATED ) ; setWindowHandle(CreateWindow0(getParentWindowHandle(), -- cgit v1.2.3