aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-12-23 03:33:30 +0100
committerSven Gothel <[email protected]>2011-12-23 03:33:30 +0100
commit3f5df93484a2ea97c6e51a717f05d9ddcec64d84 (patch)
tree33d6bbed9029c4c9fabc4db023d20162a82096cb /src/newt
parentc6fca0edc9f092a8f08f14f6ad128b62c6227c6e (diff)
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.
Diffstat (limited to 'src/newt')
-rw-r--r--src/newt/classes/jogamp/newt/ScreenImpl.java42
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/AndroidScreen.java9
-rw-r--r--src/newt/classes/jogamp/newt/driver/awt/AWTScreen.java26
-rw-r--r--src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java6
-rw-r--r--src/newt/classes/jogamp/newt/driver/broadcom/egl/Screen.java13
-rw-r--r--src/newt/classes/jogamp/newt/driver/intel/gdl/Screen.java12
-rw-r--r--src/newt/classes/jogamp/newt/driver/kd/KDScreen.java19
-rw-r--r--src/newt/classes/jogamp/newt/driver/kd/KDWindow.java2
-rw-r--r--src/newt/classes/jogamp/newt/driver/macosx/MacScreen.java7
-rw-r--r--src/newt/classes/jogamp/newt/driver/windows/WindowsScreen.java9
-rw-r--r--src/newt/classes/jogamp/newt/driver/x11/X11Screen.java15
-rw-r--r--src/newt/native/X11Screen.c4
12 files changed, 112 insertions, 52 deletions
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 <code>idx</code>
+ * value or <code>0</code>.
+ * <p>
+ * On big-desktops this shall return always 0.
+ * </p>
+ */
protected abstract int validateScreenIndex(int idx);
+ /**
+ * Returns the <b>rotated</b> virtual ScreenSize.
+ * <p>
+ * This method is called after the ScreenMode has been set,
+ * hence you may utilize it.
+ * </p>
+ */
+ protected abstract DimensionImmutable getNativeScreenSizeImpl();
+
public final String getFQName() {
return fqname;
}
/**
- * Set the <b>rotated</b> ScreenSize.
- * @see com.jogamp.newt.ScreenMode#getRotatedWidth()
- * @see com.jogamp.newt.ScreenMode#getRotatedHeight()
+ * Updates the <b>rotated</b> 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 <b>rotated</b> width.
- * @see com.jogamp.newt.ScreenMode#getRotatedWidth()
+ * @return the <b>rotated</b> virtual width.
*/
public final int getWidth() {
return (usrWidth>0) ? usrWidth : (width>0) ? width : 480;
}
/**
- * @return the <b>rotated</b> height
- * @see com.jogamp.newt.ScreenMode#getRotatedHeight()
+ * @return the <b>rotated</b> 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<referencedScreenModeListener.size(); i++) {
((ScreenModeListener)referencedScreenModeListener.get(i)).screenModeChanged(sm, success);
@@ -502,8 +514,6 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener {
if(null == currentSM) {
throw new InternalError("getCurrentScreenModeImpl() == null");
}
- // Update rotated Screen size, since native RandR impl. is more correct.
- setScreenSize(currentSM.getRotatedWidth(), currentSM.getRotatedHeight());
ArrayHashSet<ScreenMode> 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<Long>() {
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<DimensionImmutable>() {
+ public DimensionImmutable run(long dpy) {
+ return new Dimension(getWidth0(dpy, screen_idx), getHeight0(dpy, screen_idx));
+ } } );
+ }
+
//----------------------------------------------------------------------
// Internals only
//
diff --git a/src/newt/native/X11Screen.c b/src/newt/native/X11Screen.c
index ce8265556..1b7fea770 100644
--- a/src/newt/native/X11Screen.c
+++ b/src/newt/native/X11Screen.c
@@ -57,14 +57,14 @@ JNIEXPORT jint JNICALL Java_jogamp_newt_driver_x11_X11Screen_getWidth0
(JNIEnv *env, jclass clazz, jlong display, jint scrn_idx)
{
Display * dpy = (Display *) (intptr_t) display;
- return (jint) XDisplayWidth( dpy, scrn_idx);
+ return (jint) DisplayWidth( dpy, scrn_idx);
}
JNIEXPORT jint JNICALL Java_jogamp_newt_driver_x11_X11Screen_getHeight0
(JNIEnv *env, jclass clazz, jlong display, jint scrn_idx)
{
Display * dpy = (Display *) (intptr_t) display;
- return (jint) XDisplayHeight( dpy, scrn_idx);
+ return (jint) DisplayHeight( dpy, scrn_idx);
}
static int showedRandRVersion = 0;