From 3f5df93484a2ea97c6e51a717f05d9ddcec64d84 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 23 Dec 2011 03:33:30 +0100 Subject: Screen: width/height reflects virtual Screen size (-> big-desktop) Add updateScreenSize() utilizing new getNativeScreenSizeImpl() to set/update the virtual Screen size. This replaces setScreenSize() where the ScreenMode dimension was being used which doesn't reflect the virtual size. ScreenMode Test Impact: We cannot assertEquals(sm.getRotatedWidth(), screen.getWidth()), since ScreenMode size != virtual size. --- src/newt/classes/jogamp/newt/ScreenImpl.java | 42 +++++++++++++--------- .../jogamp/newt/driver/android/AndroidScreen.java | 9 ++++- .../classes/jogamp/newt/driver/awt/AWTScreen.java | 26 +++++++++----- .../classes/jogamp/newt/driver/awt/AWTWindow.java | 6 +--- .../jogamp/newt/driver/broadcom/egl/Screen.java | 13 ++++--- .../jogamp/newt/driver/intel/gdl/Screen.java | 12 ++++++- .../classes/jogamp/newt/driver/kd/KDScreen.java | 19 +++++++--- .../classes/jogamp/newt/driver/kd/KDWindow.java | 2 +- .../jogamp/newt/driver/macosx/MacScreen.java | 7 +++- .../jogamp/newt/driver/windows/WindowsScreen.java | 9 +++-- .../classes/jogamp/newt/driver/x11/X11Screen.java | 15 +++++--- 11 files changed, 110 insertions(+), 50 deletions(-) (limited to 'src/newt/classes') diff --git a/src/newt/classes/jogamp/newt/ScreenImpl.java b/src/newt/classes/jogamp/newt/ScreenImpl.java index 3c46814d2..a8e6e68bd 100644 --- a/src/newt/classes/jogamp/newt/ScreenImpl.java +++ b/src/newt/classes/jogamp/newt/ScreenImpl.java @@ -178,6 +178,7 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { throw new NativeWindowException("Screen.createNative() failed to instanciate an AbstractGraphicsScreen"); } initScreenModeStatus(); + updateScreenSize(); if(DEBUG) { System.err.println("Screen.createNative() END ("+DisplayImpl.getThreadName()+", "+this+")"); } @@ -240,20 +241,36 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { protected abstract void createNativeImpl(); protected abstract void closeNativeImpl(); + + /** + * Returns the validated screen index, which is either the passed idx + * value or 0. + *

+ * On big-desktops this shall return always 0. + *

+ */ protected abstract int validateScreenIndex(int idx); + /** + * Returns the rotated virtual ScreenSize. + *

+ * This method is called after the ScreenMode has been set, + * hence you may utilize it. + *

+ */ + protected abstract DimensionImmutable getNativeScreenSizeImpl(); + public final String getFQName() { return fqname; } /** - * Set the rotated ScreenSize. - * @see com.jogamp.newt.ScreenMode#getRotatedWidth() - * @see com.jogamp.newt.ScreenMode#getRotatedHeight() + * Updates the rotated virtual ScreenSize using the native impl. */ - protected void setScreenSize(int w, int h) { - System.err.println("Detected screen size "+w+"x"+h); - width=w; height=h; + protected void updateScreenSize() { + final DimensionImmutable dim = getNativeScreenSizeImpl(); + width=dim.getWidth(); height=dim.getHeight(); + System.err.println("Detected screen size "+width+"x"+height); } public final Display getDisplay() { @@ -274,16 +291,14 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { /** - * @return the rotated width. - * @see com.jogamp.newt.ScreenMode#getRotatedWidth() + * @return the rotated virtual width. */ public final int getWidth() { return (usrWidth>0) ? usrWidth : (width>0) ? width : 480; } /** - * @return the rotated height - * @see com.jogamp.newt.ScreenMode#getRotatedHeight() + * @return the rotated virtual height. */ public final int getHeight() { return (usrHeight>0) ? usrHeight : (height>0) ? height : 480; @@ -361,9 +376,6 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { } success = setCurrentScreenModeImpl(smU); - if(success) { - setScreenSize(smU.getRotatedWidth(), smU.getRotatedHeight()); - } if(DEBUG) { t1 = System.currentTimeMillis() - t1; @@ -391,7 +403,7 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { public void screenModeChanged(ScreenMode sm, boolean success) { if(success) { - setScreenSize(sm.getRotatedWidth(), sm.getRotatedHeight()); + updateScreenSize(); } for(int i=0; i screenModes = collectNativeScreenModes(screenModesIdx2NativeIdx); if(screenModes.size()==0) { diff --git a/src/newt/classes/jogamp/newt/driver/android/AndroidScreen.java b/src/newt/classes/jogamp/newt/driver/android/AndroidScreen.java index 79bf744fe..f403bc425 100644 --- a/src/newt/classes/jogamp/newt/driver/android/AndroidScreen.java +++ b/src/newt/classes/jogamp/newt/driver/android/AndroidScreen.java @@ -29,6 +29,8 @@ package jogamp.newt.driver.android; import javax.media.nativewindow.*; +import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.DimensionImmutable; import com.jogamp.newt.ScreenMode; import com.jogamp.newt.util.ScreenModeUtil; @@ -78,6 +80,11 @@ public class AndroidScreen extends jogamp.newt.ScreenImpl { return 0; // FIXME: only one screen available ? } + protected DimensionImmutable getNativeScreenSizeImpl() { + final ScreenMode sm = getCurrentScreenMode(); + return new Dimension(sm.getRotatedWidth(), sm.getRotatedHeight()); + } + //---------------------------------------------------------------------- // Internals only // @@ -95,7 +102,7 @@ public class AndroidScreen extends jogamp.newt.ScreenImpl { if (ScreenMode.ROTATE_90 == nrot || ScreenMode.ROTATE_270 == nrot) { props[offset++] = outMetrics.heightPixels; props[offset++] = outMetrics.widthPixels; - } else { + } else { props[offset++] = outMetrics.widthPixels; props[offset++] = outMetrics.heightPixels; } diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTScreen.java b/src/newt/classes/jogamp/newt/driver/awt/AWTScreen.java index a8aa2844d..e2e0105eb 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/AWTScreen.java +++ b/src/newt/classes/jogamp/newt/driver/awt/AWTScreen.java @@ -38,6 +38,8 @@ import java.awt.DisplayMode; import jogamp.newt.ScreenImpl; import javax.media.nativewindow.awt.AWTGraphicsDevice; import javax.media.nativewindow.awt.AWTGraphicsScreen; +import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.DimensionImmutable; public class AWTScreen extends ScreenImpl { public AWTScreen() { @@ -45,26 +47,32 @@ public class AWTScreen extends ScreenImpl { protected void createNativeImpl() { aScreen = new AWTGraphicsScreen((AWTGraphicsDevice)display.getGraphicsDevice()); - - final DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode(); - if(null != mode) { - setScreenSize(mode.getWidth(), mode.getHeight()); - } } protected void setAWTGraphicsScreen(AWTGraphicsScreen s) { aScreen = s; } - // done by AWTWindow .. - protected void setScreenSize(int w, int h) { - super.setScreenSize(w, h); + /** + * Used by AWTWindow .. + */ + @Override + protected void updateScreenSize() { + super.updateScreenSize(); } protected void closeNativeImpl() { } protected int validateScreenIndex(int idx) { - return idx; // FIXME: ??? + return idx; // pass through ... } + + protected DimensionImmutable getNativeScreenSizeImpl() { + final DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode(); + if(null != mode) { + return new Dimension(mode.getWidth(), mode.getHeight()); + } + return null; + } } diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java b/src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java index 1cd98b068..5b6fcedbe 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java +++ b/src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java @@ -36,7 +36,6 @@ package jogamp.newt.driver.awt; import java.awt.BorderLayout; import java.awt.Container; -import java.awt.DisplayMode; import java.awt.Frame; import java.awt.Insets; @@ -157,10 +156,7 @@ public class AWTWindow extends WindowImpl { ((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()); - } + ((AWTScreen)getScreen()).updateScreenSize(); } return res; } diff --git a/src/newt/classes/jogamp/newt/driver/broadcom/egl/Screen.java b/src/newt/classes/jogamp/newt/driver/broadcom/egl/Screen.java index 9d96ac5d6..850f56c6d 100644 --- a/src/newt/classes/jogamp/newt/driver/broadcom/egl/Screen.java +++ b/src/newt/classes/jogamp/newt/driver/broadcom/egl/Screen.java @@ -34,6 +34,8 @@ package jogamp.newt.driver.broadcom.egl; import javax.media.nativewindow.*; +import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.DimensionImmutable; public class Screen extends jogamp.newt.ScreenImpl { @@ -47,7 +49,6 @@ public class Screen extends jogamp.newt.ScreenImpl { protected void createNativeImpl() { aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx); - setScreenSize(fixedWidth, fixedHeight); } protected void closeNativeImpl() { } @@ -55,12 +56,16 @@ public class Screen extends jogamp.newt.ScreenImpl { protected int validateScreenIndex(int idx) { return 0; // only one screen available } - + + protected DimensionImmutable getNativeScreenSizeImpl() { + return new Dimension(fixedWidth, fixedHeight); // FIXME + } + //---------------------------------------------------------------------- // Internals only // - static final int fixedWidth = 1920; - static final int fixedHeight = 1080; + private static final int fixedWidth = 1920; // FIXME + private static final int fixedHeight = 1080; // FIXME } diff --git a/src/newt/classes/jogamp/newt/driver/intel/gdl/Screen.java b/src/newt/classes/jogamp/newt/driver/intel/gdl/Screen.java index 62d9da4ed..6e156183f 100644 --- a/src/newt/classes/jogamp/newt/driver/intel/gdl/Screen.java +++ b/src/newt/classes/jogamp/newt/driver/intel/gdl/Screen.java @@ -35,6 +35,8 @@ package jogamp.newt.driver.intel.gdl; import jogamp.newt.*; import javax.media.nativewindow.*; +import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.DimensionImmutable; public class Screen extends jogamp.newt.ScreenImpl { @@ -57,6 +59,10 @@ public class Screen extends jogamp.newt.ScreenImpl { return 0; // only one screen available } + protected DimensionImmutable getNativeScreenSizeImpl() { + return new Dimension(cachedWidth, cachedHeight); + } + //---------------------------------------------------------------------- // Internals only // @@ -66,7 +72,11 @@ public class Screen extends jogamp.newt.ScreenImpl { // called by GetScreenInfo() .. private void screenCreated(int width, int height) { - setScreenSize(width, height); + cachedWidth = width; + cachedHeight = height; } + + private static int cachedWidth = 0; + private static int cachedHeight = 0; } diff --git a/src/newt/classes/jogamp/newt/driver/kd/KDScreen.java b/src/newt/classes/jogamp/newt/driver/kd/KDScreen.java index 0bfe8a622..bbfef370c 100644 --- a/src/newt/classes/jogamp/newt/driver/kd/KDScreen.java +++ b/src/newt/classes/jogamp/newt/driver/kd/KDScreen.java @@ -35,6 +35,8 @@ package jogamp.newt.driver.kd; import jogamp.newt.ScreenImpl; import javax.media.nativewindow.*; +import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.DimensionImmutable; public class KDScreen extends ScreenImpl { static { @@ -50,12 +52,19 @@ public class KDScreen extends ScreenImpl { protected void closeNativeImpl() { } - // elevate access to this package .. - protected void setScreenSize(int w, int h) { - super.setScreenSize(w, h); - } - protected int validateScreenIndex(int idx) { return 0; // only one screen available } + + protected DimensionImmutable getNativeScreenSizeImpl() { + return new Dimension(cachedWidth, cachedHeight); + } + + protected void sizeChanged(int w, int h) { + cachedWidth = w; + cachedHeight = h; + } + + private static int cachedWidth = 0; + private static int cachedHeight = 0; } diff --git a/src/newt/classes/jogamp/newt/driver/kd/KDWindow.java b/src/newt/classes/jogamp/newt/driver/kd/KDWindow.java index 0c720e559..92f8251bc 100644 --- a/src/newt/classes/jogamp/newt/driver/kd/KDWindow.java +++ b/src/newt/classes/jogamp/newt/driver/kd/KDWindow.java @@ -146,7 +146,7 @@ public class KDWindow extends WindowImpl { @Override protected void sizeChanged(boolean defer, int newWidth, int newHeight, boolean force) { if(fullscreen) { - ((KDScreen)getScreen()).setScreenSize(width, height); + ((KDScreen)getScreen()).sizeChanged(width, height); } super.sizeChanged(defer, newWidth, newHeight, force); } diff --git a/src/newt/classes/jogamp/newt/driver/macosx/MacScreen.java b/src/newt/classes/jogamp/newt/driver/macosx/MacScreen.java index 1c8128a5a..4954b0569 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/MacScreen.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/MacScreen.java @@ -37,6 +37,8 @@ package jogamp.newt.driver.macosx; import java.util.List; import javax.media.nativewindow.DefaultGraphicsScreen; +import javax.media.nativewindow.util.DimensionImmutable; +import javax.media.nativewindow.util.Dimension; import jogamp.newt.ScreenImpl; @@ -53,7 +55,6 @@ public class MacScreen extends ScreenImpl { protected void createNativeImpl() { aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx); - setScreenSize(getWidthImpl0(screen_idx), getHeightImpl0(screen_idx)); } protected void closeNativeImpl() { } @@ -110,6 +111,10 @@ public class MacScreen extends ScreenImpl { return idx; } + protected DimensionImmutable getNativeScreenSizeImpl() { + return new Dimension(getWidthImpl0(screen_idx), getHeightImpl0(screen_idx)); + } + private native int[] getScreenMode0(int screen_index, int mode_index); private native boolean setScreenMode0(int screen_index, int mode_idx); } diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowsScreen.java b/src/newt/classes/jogamp/newt/driver/windows/WindowsScreen.java index b1cdc36b2..7e3e3626c 100644 --- a/src/newt/classes/jogamp/newt/driver/windows/WindowsScreen.java +++ b/src/newt/classes/jogamp/newt/driver/windows/WindowsScreen.java @@ -34,6 +34,8 @@ package jogamp.newt.driver.windows; import javax.media.nativewindow.DefaultGraphicsScreen; +import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.DimensionImmutable; import jogamp.newt.ScreenImpl; @@ -51,9 +53,8 @@ public class WindowsScreen extends ScreenImpl { protected void createNativeImpl() { aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx); - setScreenSize(getWidthImpl0(screen_idx), getHeightImpl0(screen_idx)); } - + protected void closeNativeImpl() { } @@ -105,6 +106,10 @@ public class WindowsScreen extends ScreenImpl { return 0; // big-desktop, only one screen available } + protected DimensionImmutable getNativeScreenSizeImpl() { + return new Dimension(getWidthImpl0(screen_idx), getHeightImpl0(screen_idx)); + } + // Native calls private native int getWidthImpl0(int scrn_idx); diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java b/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java index 1c5388d2c..c52a21220 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java +++ b/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java @@ -43,6 +43,8 @@ import com.jogamp.newt.ScreenMode; import com.jogamp.newt.util.ScreenModeUtil; import java.util.List; +import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.DimensionImmutable; import javax.media.nativewindow.x11.*; public class X11Screen extends ScreenImpl { @@ -58,11 +60,7 @@ public class X11Screen extends ScreenImpl { // validate screen index Long handle = display.runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() { public Long run(long dpy) { - long handle = GetScreen0(dpy, screen_idx); - if(0 != handle) { - setScreenSize(getWidth0(dpy, screen_idx), getHeight0(dpy, screen_idx)); - } - return new Long(handle); + return new Long(GetScreen0(dpy, screen_idx)); } } ); if (handle.longValue() == 0) { throw new RuntimeException("Error creating screen: " + screen_idx); @@ -270,6 +268,13 @@ public class X11Screen extends ScreenImpl { } } + protected DimensionImmutable getNativeScreenSizeImpl() { + return display.runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() { + public DimensionImmutable run(long dpy) { + return new Dimension(getWidth0(dpy, screen_idx), getHeight0(dpy, screen_idx)); + } } ); + } + //---------------------------------------------------------------------- // Internals only // -- cgit v1.2.3