summaryrefslogtreecommitdiffstats
path: root/src/newt/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-05-23 00:00:48 +0200
committerSven Gothel <[email protected]>2014-05-23 00:00:48 +0200
commit98ed02cdb7b325d8afde596a5ef04f97be2018d4 (patch)
tree57969bdf241d493cc110b29422d3c488fcfacc65 /src/newt/classes/jogamp
parentfb57c652fee6be133990cd7afbbd2fdfc084afaa (diff)
Bug 742 HiDPI: [Core API Change] Distinguish window-units and pixel-units: Refine commit fb57c652fee6be133990cd7afbbd2fdfc084afaa
- NEWT Screen, Monitor, MonitorMode, .. - All Units are in pixel units, not window units! - On OSX HiDPI, we report the current scaled monitor resolution, instead of the native pixel sized. Need to filter out those, i.e. report only native unscaled resolutions, since out MonitorMode analogy is per MonitorDevice and not per window! - Fix usage (one by one) of - Screen and Monitor viewport usage
Diffstat (limited to 'src/newt/classes/jogamp')
-rw-r--r--src/newt/classes/jogamp/newt/WindowImpl.java74
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/WindowDriver.java9
-rw-r--r--src/newt/classes/jogamp/newt/driver/bcm/egl/WindowDriver.java3
-rw-r--r--src/newt/classes/jogamp/newt/driver/intel/gdl/WindowDriver.java3
-rw-r--r--src/newt/classes/jogamp/newt/driver/linux/LinuxMouseTracker.java20
-rw-r--r--src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java5
6 files changed, 74 insertions, 40 deletions
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index b127426a8..6a5fc5de0 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -912,7 +912,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
@Override
public final MonitorDevice getMainMonitor() {
- return screen.getMainMonitor(new Rectangle(getX(), getY(), getWindowWidth(), getWindowHeight()));
+ return screen.getMainMonitor( getSurfaceBounds() );
}
/**
@@ -1071,8 +1071,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
@Override
public final void setSurfaceSize(final int pixelWidth, final int pixelHeight) {
- final int[] winSize = convertToWindowUnits(new int[]{pixelWidth, pixelHeight});
- setSize(winSize[0], winSize[1]);
+ // FIXME HiDPI: Shortcut, may need to adjust if we change scaling methodology
+ setSize(pixelWidth * getPixelScaleX(), pixelHeight * getPixelScaleY());
}
@Override
public final void setTopLevelSize(final int width, final int height) {
@@ -1877,13 +1877,13 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
@Override
- public final int getSurfaceWidth() {
- return pixWidth;
+ public final int getX() {
+ return x;
}
@Override
- public final int getSurfaceHeight() {
- return pixHeight;
+ public final int getY() {
+ return y;
}
@Override
@@ -1897,6 +1897,27 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
@Override
+ public final Rectangle getBounds() {
+ return new Rectangle(x, y, winWidth, winHeight);
+ }
+
+ @Override
+ public final int getSurfaceWidth() {
+ return pixWidth;
+ }
+
+ @Override
+ public final int getSurfaceHeight() {
+ return pixHeight;
+ }
+
+ @Override
+ public final Rectangle getSurfaceBounds() {
+ // FIXME HiDPI: Shortcut, may need to adjust if we change scaling methodology
+ return new Rectangle(x * getPixelScaleX(), y * getPixelScaleY(), pixWidth, pixHeight);
+ }
+
+ @Override
public final int[] convertToWindowUnits(final int[] pixelUnitsAndResult) {
pixelUnitsAndResult[0] /= getPixelScaleX();
pixelUnitsAndResult[1] /= getPixelScaleY();
@@ -1910,29 +1931,29 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
return windowUnitsAndResult;
}
- @Override
- public final Point convertToWindowUnits(final Point pixelUnitsAndResult) {
+ protected final Point convertToWindowUnits(final Point pixelUnitsAndResult) {
return pixelUnitsAndResult.scaleInv(getPixelScaleX(), getPixelScaleY());
}
- @Override
- public final Point convertToPixelUnits(final Point windowUnitsAndResult) {
+ protected final Point convertToPixelUnits(final Point windowUnitsAndResult) {
return windowUnitsAndResult.scale(getPixelScaleX(), getPixelScaleY());
}
- protected int getPixelScaleX() { return 1; }
- protected int getPixelScaleY() { return 1; }
-
@Override
- public final int getX() {
- return x;
+ public final Rectangle convertToWindowUnits(final Rectangle pixelUnitsAndResult) {
+ return pixelUnitsAndResult.scaleInv(getPixelScaleX(), getPixelScaleY());
}
@Override
- public final int getY() {
- return y;
+ public final Rectangle convertToPixelUnits(final Rectangle windowUnitsAndResult) {
+ return windowUnitsAndResult.scale(getPixelScaleX(), getPixelScaleY());
}
+ /** HiDPI: We currently base scaling of window units to pixel units on an integer scale factor per component. */
+ protected int getPixelScaleX() { return 1; }
+ /** HiDPI: We currently base scaling of window units to pixel units on an integer scale factor per component. */
+ protected int getPixelScaleY() { return 1; }
+
protected final boolean autoPosition() { return autoPosition; }
/** Sets the position fields {@link #x} and {@link #y} in window units to the given values and {@link #autoPosition} to false. */
@@ -1950,14 +1971,15 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
* and {@link #pixWidth} and {@link #pixHeight} in pixel units according to {@link #convertToPixelUnits(int[])}.
*/
protected final void defineSize(int winWidth, int winHeight) {
- final int[] pixelSize = convertToPixelUnits(new int[] { winWidth, winHeight });
+ final int pixWidth = winWidth * getPixelScaleX(); // FIXME HiDPI: Shortcut, may need to adjust if we change scaling methodology
+ final int pixHeight = winHeight * getPixelScaleY();
if(DEBUG_IMPLEMENTATION) {
System.err.println("defineSize: win["+this.winWidth+"x"+this.winHeight+" -> "+winWidth+"x"+winHeight+
- "], pixel["+this.pixWidth+"x"+this.pixHeight+" -> "+pixelSize[0]+"x"+pixelSize[1]+"]");
+ "], pixel["+this.pixWidth+"x"+this.pixHeight+" -> "+pixWidth+"x"+pixHeight+"]");
// Thread.dumpStack();
}
this.winWidth = winWidth; this.winHeight = winHeight;
- this.pixWidth = pixelSize[0]; this.pixHeight = pixelSize[0];
+ this.pixWidth = pixWidth; this.pixHeight = pixHeight;
}
@Override
@@ -2227,7 +2249,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
int x,y,w,h;
- final RectangleImmutable sviewport = screen.getViewport();
+ final RectangleImmutable sviewport = screen.getViewportInWindowUnits(WindowImpl.this);
final RectangleImmutable viewport;
final int fs_span_flag;
final boolean alwaysOnTopChange;
@@ -2240,7 +2262,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
fullscreenMonitors = getScreen().getMonitorDevices();
}
}
- viewport = MonitorDevice.unionOfViewports(new Rectangle(), fullscreenMonitors);
+ viewport = convertToWindowUnits(MonitorDevice.unionOfViewports(new Rectangle(), fullscreenMonitors));
if( isReconfigureFlagSupported(FLAG_IS_FULLSCREEN_SPAN) &&
( fullscreenMonitors.size() > 1 || sviewport.compareTo(viewport) > 0 ) ) {
fs_span_flag = FLAG_IS_FULLSCREEN_SPAN;
@@ -2292,7 +2314,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
if(DEBUG_IMPLEMENTATION) {
System.err.println("Window fs: "+_fullscreen+" "+x+"/"+y+" "+w+"x"+h+", "+isUndecorated()+
- ", virtl-screenSize: "+sviewport+", monitorsViewport "+viewport+
+ ", virtl-screenSize: "+sviewport+" [wu], monitorsViewport "+viewport+" [wu]"+
", spanning "+(0!=fs_span_flag)+
", alwaysOnTop "+alwaysOnTop+(alwaysOnTopChange?"*":"")+
", wasVisible "+wasVisible+", tempInvisible "+tempInvisible+
@@ -2449,7 +2471,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
if( !fullscreen && !fullscreenPaused ) {
// Simply move/resize window to fit in virtual screen if required
- final RectangleImmutable viewport = screen.getViewport();
+ final RectangleImmutable viewport = screen.getViewportInWindowUnits(WindowImpl.this);
if( viewport.getWidth() > 0 && viewport.getHeight() > 0 ) { // failsafe
final RectangleImmutable rect = new Rectangle(getX(), getY(), getWindowWidth(), getWindowHeight());
final RectangleImmutable isect = viewport.intersection(rect);
@@ -2475,7 +2497,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
// If changed monitor is part of this fullscreen mode, reset size! (Bug 771)
final MonitorDevice md = me.getMonitor();
if( fullscreenMonitors.contains(md) ) {
- final RectangleImmutable viewport = MonitorDevice.unionOfViewports(new Rectangle(), fullscreenMonitors);
+ final RectangleImmutable viewport = convertToWindowUnits(MonitorDevice.unionOfViewports(new Rectangle(), fullscreenMonitors));
if(DEBUG_IMPLEMENTATION) {
final RectangleImmutable rect = new Rectangle(getX(), getY(), getWindowWidth(), getWindowHeight());
System.err.println("Window.monitorModeChanged: FS Monitor Match: Fit window "+rect+" into new viewport union "+viewport+", provoked by "+md);
diff --git a/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java
index 93ff0c1e0..7a571318b 100644
--- a/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java
@@ -41,6 +41,7 @@ import javax.media.nativewindow.NativeWindowException;
import javax.media.nativewindow.VisualIDHolder;
import javax.media.nativewindow.util.Insets;
import javax.media.nativewindow.util.Point;
+import javax.media.nativewindow.util.Rectangle;
import javax.media.nativewindow.util.RectangleImmutable;
import javax.media.opengl.GLCapabilitiesChooser;
import javax.media.opengl.GLCapabilitiesImmutable;
@@ -54,7 +55,6 @@ import jogamp.opengl.egl.EGL;
import jogamp.opengl.egl.EGLDisplayUtil;
import jogamp.opengl.egl.EGLGraphicsConfiguration;
import jogamp.opengl.egl.EGLGraphicsConfigurationFactory;
-
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@@ -286,9 +286,10 @@ public class WindowDriver extends jogamp.newt.WindowImpl implements Callback2 {
if( isFullscreen() ) {
final MonitorDevice mainMonitor = getMainMonitor();
- final RectangleImmutable viewport = mainMonitor.getViewport();
- definePosition(viewport.getX(), viewport.getY());
- defineSize(viewport.getWidth(), viewport.getHeight());
+ final RectangleImmutable screenRect = mainMonitor.getViewport();
+ final RectangleImmutable winRect = this.convertToWindowUnits((Rectangle)screenRect.cloneMutable());
+ definePosition(winRect.getX(), winRect.getY());
+ defineSize(winRect.getWidth(), winRect.getHeight());
}
final boolean b;
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/egl/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/bcm/egl/WindowDriver.java
index be7e8fd07..4cbff69c1 100644
--- a/src/newt/classes/jogamp/newt/driver/bcm/egl/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/bcm/egl/WindowDriver.java
@@ -65,7 +65,8 @@ public class WindowDriver extends jogamp.newt.WindowImpl {
throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
}
setGraphicsConfiguration(cfg);
- setSizeImpl(getScreen().getWidth(), getScreen().getHeight());
+ final int[] winSize = convertToWindowUnits(new int[] {getScreen().getWidth(), getScreen().getHeight()});
+ setSizeImpl(winSize[0], winSize[1]);
setWindowHandle(realizeWindow(true, getWindowWidth(), getWindowHeight()));
if (0 == getWindowHandle()) {
diff --git a/src/newt/classes/jogamp/newt/driver/intel/gdl/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/intel/gdl/WindowDriver.java
index 7e15d0258..cf169f1c7 100644
--- a/src/newt/classes/jogamp/newt/driver/intel/gdl/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/intel/gdl/WindowDriver.java
@@ -67,7 +67,7 @@ public class WindowDriver extends jogamp.newt.WindowImpl {
setWindowHandle(nextWindowHandle++); // just a marker
surfaceHandle = CreateSurface(aDevice.getHandle(), getScreen().getWidth(), getScreen().getHeight(),
- getX(), getY(), getWindowWidth(), getWindowHeight());
+ getX(), getY(), getSurfaceWidth(), getSurfaceHeight());
if (surfaceHandle == 0) {
throw new NativeWindowException("Error creating window");
}
@@ -89,6 +89,7 @@ public class WindowDriver extends jogamp.newt.WindowImpl {
protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
ScreenDriver screen = (ScreenDriver) getScreen();
+ // Note for GDL: window units == pixel units
if(width>screen.getWidth()) {
width=screen.getWidth();
}
diff --git a/src/newt/classes/jogamp/newt/driver/linux/LinuxMouseTracker.java b/src/newt/classes/jogamp/newt/driver/linux/LinuxMouseTracker.java
index 9d7b8931b..3663ef0d4 100644
--- a/src/newt/classes/jogamp/newt/driver/linux/LinuxMouseTracker.java
+++ b/src/newt/classes/jogamp/newt/driver/linux/LinuxMouseTracker.java
@@ -36,6 +36,7 @@ import java.io.InputStream;
import jogamp.newt.WindowImpl;
+import com.jogamp.newt.Screen;
import com.jogamp.newt.Window;
import com.jogamp.newt.event.MouseEvent;
import com.jogamp.newt.event.WindowEvent;
@@ -178,13 +179,20 @@ public class LinuxMouseTracker implements WindowListener {
}
if(null != focusedWindow) {
- if( x >= focusedWindow.getScreen().getWidth() ) {
- x = focusedWindow.getScreen().getWidth() - 1;
- }
- if( y >= focusedWindow.getScreen().getHeight() ) {
- y = focusedWindow.getScreen().getHeight() - 1;
+ // Clip to Screen Size
+ {
+ final Screen focusedScreen = focusedWindow.getScreen();
+ final int sw = focusedScreen.getWidth();
+ final int sh = focusedScreen.getHeight();
+ if( x >= sw ) {
+ x = sw - 1;
+ }
+ if( y >= sh ) {
+ y = sh - 1;
+ }
}
- final int wx = x - focusedWindow.getX(), wy = y - focusedWindow.getY();
+ final int[] winScreenPos = focusedWindow.convertToPixelUnits(new int[] { focusedWindow.getX(), focusedWindow.getY() });
+ final int wx = x - winScreenPos[0], wy = y - winScreenPos[1];
if(old_x != x || old_y != y) {
// mouse moved
lastFocusedX = wx;
diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java
index 541247efd..00f935f86 100644
--- a/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java
@@ -253,7 +253,8 @@ public class WindowDriver extends WindowImpl {
public void run() {
final Point p0 = convertToPixelUnits( getLocationOnScreenImpl(0, 0) );
res[0] = Boolean.valueOf(confinePointer0(getWindowHandle(), confine,
- p0.getX(), p0.getY(), p0.getX()+getSurfaceWidth(), p0.getY()+getSurfaceHeight()));
+ p0.getX(), p0.getY(),
+ p0.getX()+getSurfaceWidth(), p0.getY()+getSurfaceHeight()));
}
});
return res[0].booleanValue();
@@ -264,7 +265,7 @@ public class WindowDriver extends WindowImpl {
this.runOnEDTIfAvail(true, new Runnable() {
@Override
public void run() {
- final Point sPos = getLocationOnScreenImpl(x, y);
+ final Point sPos = convertToPixelUnits( getLocationOnScreenImpl(x, y) );
warpPointer0(getWindowHandle(), sPos.getX(), sPos.getY());
}
});