diff options
author | Sven Gothel <[email protected]> | 2012-09-28 18:52:31 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-09-28 18:52:31 +0200 |
commit | e4176f4e76f519b3599ad557210def3d35266e7b (patch) | |
tree | 1cb39ae2532b17ff5e1fd90a43198ce986878f26 /src | |
parent | 54f79e402ddb87de9caa3297228cbd16c452cfb4 (diff) |
NativeWindow/X11 + NEWT/X11: Cache 'isXineramaEnabled()' to reduce X11 server roundtrips.
Diffstat (limited to 'src')
5 files changed, 22 insertions, 16 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java index 2e4099c1b..142bb99e3 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java @@ -46,6 +46,7 @@ import javax.media.nativewindow.ToolkitLock; public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneable { final boolean handleOwner; + final boolean isXineramaEnabled; /** Constructs a new X11GraphicsDevice corresponding to the given connection and default * {@link javax.media.nativewindow.ToolkitLock} via {@link NativeWindowFactory#getDefaultToolkitLock(String)}.<br> @@ -56,6 +57,7 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl public X11GraphicsDevice(String connection, int unitID) { super(NativeWindowFactory.TYPE_X11, connection, unitID); handleOwner = false; + isXineramaEnabled = false; } /** Constructs a new X11GraphicsDevice corresponding to the given native display handle and default @@ -69,6 +71,7 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl throw new NativeWindowException("null display"); } handleOwner = owner; + isXineramaEnabled = X11Util.XineramaIsEnabled(this); } /** @@ -82,7 +85,9 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl throw new NativeWindowException("null display"); } handleOwner = owner; + isXineramaEnabled = X11Util.XineramaIsEnabled(this); } + private static int getDefaultScreenImpl(long dpy) { return X11Lib.DefaultScreen(dpy); @@ -114,6 +119,10 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl return X11Lib.DefaultVisualID(display, getDefaultScreenImpl(display)); } + public final boolean isXineramaEnabled() { + return isXineramaEnabled; + } + @Override public Object clone() { return super.clone(); diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsScreen.java b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsScreen.java index 7ab5bd6aa..fa57124fb 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsScreen.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsScreen.java @@ -48,7 +48,7 @@ public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneabl /** Constructs a new X11GraphicsScreen corresponding to the given native screen index. */ public X11GraphicsScreen(X11GraphicsDevice device, int screen) { - super(device, fetchScreen(device, screen)); + super(device, device.isXineramaEnabled() ? 0 : screen); } public static AbstractGraphicsScreen createScreenDevice(long display, int screenIdx, boolean owner) { @@ -61,14 +61,6 @@ public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneabl return X11Lib.DefaultVisualID(getDevice().getHandle(), getIndex()); } - private static int fetchScreen(X11GraphicsDevice device, int screen) { - // It still could be an AWT hold handle .. - if(X11Util.XineramaIsEnabled(device)) { - screen = 0; // Xinerama -> 1 screen - } - return screen; - } - public Object clone() { return super.clone(); } diff --git a/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java index bff050030..6e80e966a 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java +++ b/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java @@ -85,8 +85,8 @@ public class DisplayDriver extends DisplayImpl { CompleteDisplay0(aDevice.getHandle()); } catch(RuntimeException e) { closeNativeImpl(); - throw e; - } + throw e; + } } protected void closeNativeImpl() { @@ -111,6 +111,9 @@ public class DisplayDriver extends DisplayImpl { protected long getJavaObjectAtom() { return javaObjectAtom; } protected long getWindowDeleteAtom() { return windowDeleteAtom; } + /** Returns <code>null</code> if !{@link #isNativeValid()}, otherwise the Boolean value of {@link X11GraphicsDevice#isXineramaEnabled()}. */ + protected Boolean isXineramaEnabled() { return isNativeValid() ? Boolean.valueOf(((X11GraphicsDevice)aDevice).isXineramaEnabled()) : null; } + //---------------------------------------------------------------------- // Internals only // @@ -131,6 +134,6 @@ public class DisplayDriver extends DisplayImpl { private long windowDeleteAtom; /** X11 Window java object property used on EDT */ - private long javaObjectAtom; + private long javaObjectAtom; } diff --git a/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java index b09d98e06..7a3c718c0 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java @@ -282,8 +282,10 @@ public class ScreenDriver extends ScreenImpl { } }; protected int validateScreenIndex(final int idx) { - if(getDisplay().isNativeValid()) { - return X11Util.XineramaIsEnabled((X11GraphicsDevice)getDisplay().getGraphicsDevice()) ? 0 : idx; + final DisplayDriver x11Display = (DisplayDriver) getDisplay(); + final Boolean r = x11Display.isXineramaEnabled(); + if( null != r ) { + return r.booleanValue() ? 0 : idx; } else { return runWithTempDisplayHandle( xineramaEnabledQueryWithTemp ).booleanValue() ? 0 : idx; } diff --git a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java index aea86a420..bde723634 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java @@ -74,7 +74,7 @@ public class WindowDriver extends WindowImpl { throw new RuntimeException("Error creating display(EDT): "+edtDevice.getConnection()); } renderDevice = new X11GraphicsDevice(renderDeviceHandle, AbstractGraphicsDevice.DEFAULT_UNIT, true); - AbstractGraphicsScreen renderScreen = new X11GraphicsScreen((X11GraphicsDevice) renderDevice, screen.getIndex()); + final AbstractGraphicsScreen renderScreen = new X11GraphicsScreen(renderDevice, screen.getIndex()); final GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice(), capsRequested); final AbstractGraphicsConfiguration cfg = factory.chooseGraphicsConfiguration( @@ -300,5 +300,5 @@ public class WindowDriver extends WindowImpl { private static native void warpPointer0(long display, long windowHandle, int x, int y); private long windowHandleClose; - private AbstractGraphicsDevice renderDevice; + private X11GraphicsDevice renderDevice; } |