diff options
Diffstat (limited to 'src')
6 files changed, 75 insertions, 13 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java index b2428f7fa..0cf56c0c9 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java @@ -29,16 +29,19 @@ package com.jogamp.nativewindow.swt; import com.jogamp.common.os.Platform; +import java.io.PrintStream; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.security.AccessController; import java.security.PrivilegedAction; +import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.GCData; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.internal.DPIUtil; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Scrollable; import com.jogamp.nativewindow.AbstractGraphicsScreen; @@ -288,11 +291,6 @@ public class SWTAccessor { OS_gdk_window_set_background_pattern = mb; isX11GTK = isX11 && null != OS_gtk_class; - - if(DEBUG) { - System.err.println("SWTAccessor.<init>: isX11 "+isX11+", isX11GTK "+isX11GTK+" (GTK Version: "+OS_gtk_version+")"); - System.err.println("SWTAccessor.<init>: isOSX "+isOSX+", isWindows "+isWindows); - } } private static Number getIntOrLong(final long arg) { @@ -394,6 +392,46 @@ public class SWTAccessor { // // Common any toolkit // + public static void printInfo(final PrintStream out, final Display d) { + out.println("SWT: Platform: "+SWT.getPlatform()+", Version "+SWT.getVersion()); + out.println("SWT: isX11 "+isX11+", isX11GTK "+isX11GTK+" (GTK Version: "+OS_gtk_version+")"); + out.println("SWT: isOSX "+isOSX+", isWindows "+isWindows); + out.println("SWT: Display.DPI "+d.getDPI()+", DPIUtil: scalingFactor "+getScalingFactor()+", deviceZoom "+DPIUtil.getDeviceZoom()+ + ", useCairoAutoScale "+DPIUtil.useCairoAutoScale()); + } + + public static float getScalingFactor() { + final int deviceZoom = DPIUtil.getDeviceZoom(); + if ( 100 == deviceZoom || DPIUtil.useCairoAutoScale() ) { + return 1f; + } + return deviceZoom/100f; + } + public static int autoScaleUp (final int v) { + final int deviceZoom = DPIUtil.getDeviceZoom(); + if (100 == deviceZoom || DPIUtil.useCairoAutoScale()) { + return v; + } + final float scaleFactor = deviceZoom/100f; + return Math.round (v * scaleFactor); + } + public static com.jogamp.nativewindow.util.Point autoScaleUp (final com.jogamp.nativewindow.util.Point v) { + final int deviceZoom = DPIUtil.getDeviceZoom(); + if (100 == deviceZoom || DPIUtil.useCairoAutoScale() || null == v) { + return v; + } + final float scaleFactor = deviceZoom/100f; + return v.set(Math.round(v.getX() * scaleFactor), Math.round(v.getY() * scaleFactor)); + } + public static com.jogamp.nativewindow.util.Rectangle autoScaleUp (final com.jogamp.nativewindow.util.Rectangle v) { + final int deviceZoom = DPIUtil.getDeviceZoom(); + if (100 == deviceZoom || DPIUtil.useCairoAutoScale() || null == v) { + return v; + } + final float scaleFactor = deviceZoom/100f; + return v.set(Math.round(v.getX() * scaleFactor), Math.round(v.getY() * scaleFactor), + Math.round(v.getWidth() * scaleFactor), Math.round(v.getHeight() * scaleFactor)); + } /** * Returns the unscaled {@link Scrollable#getClientArea()} in pixels. diff --git a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java index 2930a4fd3..2615ebbb5 100644 --- a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java +++ b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java @@ -176,6 +176,29 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC addListener (SWT.FocusOut, swtListener); } + /** + * Set's the NEWT {@link Window}'s size using {@link Window#setSize(int, int)}. + * <p> + * For all non-native DPI autoscale platforms, it utilizes {@link SWTAccessor#autoScaleUp(Point)} + * by multiplying the given {@link Rectangle} size to emulate DPI scaling, see Bug 1422. + * </p> + * <p> + * Currently native DPI autoscale platforms are + * <ul> + * <li>{@link SWTAccessor#isOSX}</li> + * </ul> + * hence the emulated DPI scaling is enabled for all other platforms. + * </p> + * @param r containing desired size + */ + private final void setNewtChildSize(final Rectangle r) { + if( !SWTAccessor.isOSX ) { + final Point p = SWTAccessor.autoScaleUp(new Point(r.width, r.height)); + newtChild.setSize(p.getX(), p.getY()); + } else { + newtChild.setSize(r.width, r.height); + } + } private final Listener swtListener = new Listener () { @Override public void handleEvent (final Event event) { @@ -187,7 +210,7 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC } if( validateNative() && newtChildReady ) { if( postSetSize ) { - newtChild.setSize(clientAreaWindow.width, clientAreaWindow.height); + setNewtChildSize(clientAreaWindow); postSetSize = false; } if( postSetPos ) { @@ -357,7 +380,7 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC } if( sizeChanged ) { if( newtChildReady ) { - newtChild.setSize(nClientAreaWindow.width, nClientAreaWindow.height); + setNewtChildSize(nClientAreaWindow); newtChild.setSurfaceScale(pixelScale); } else { postSetSize = true; @@ -529,7 +552,7 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC newtDisplay.setEDTUtil( edtUtil ); } - newtChild.setSize(clientAreaWindow.width, clientAreaWindow.height); + setNewtChildSize(clientAreaWindow); newtChild.reparentWindow(nativeWindow, -1, -1, Window.REPARENT_HINT_BECOMES_VISIBLE); newtChild.setPosition(clientAreaWindow.x, clientAreaWindow.y); newtChild.setVisible(true); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestGLCanvasSWTNewtCanvasSWTPosInTabs.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestGLCanvasSWTNewtCanvasSWTPosInTabs.java index a5bafd15d..86e0f9d9b 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestGLCanvasSWTNewtCanvasSWTPosInTabs.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestGLCanvasSWTNewtCanvasSWTPosInTabs.java @@ -184,6 +184,7 @@ public class TestGLCanvasSWTNewtCanvasSWTPosInTabs extends UITestCase { {
display = new Display();
Assert.assertNotNull( display );
+ SWTAccessor.printInfo(System.err, display);
shell = new Shell( display );
shell.setText( getSimpleTestName(".") );
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAccessor01.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAccessor01.java index bf98a8e95..79dc71406 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAccessor01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAccessor01.java @@ -83,12 +83,11 @@ public class TestSWTAccessor01 extends UITestCase { } protected void init() throws InterruptedException, InvocationTargetException { - System.err.println("SWT Platform: "+SWT.getPlatform()+", Version "+SWT.getVersion()); - System.err.println("GTK_VERSION: "+SWTAccessor.GTK_VERSION()); SWTAccessor.invoke(true, new Runnable() { public void run() { display = new Display(); Assert.assertNotNull( display ); + SWTAccessor.printInfo(System.err, display); shell = new Shell( display ); Assert.assertNotNull( shell ); shell.setLayout( new GridLayout(3, false) ); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAccessor02NewtGLWindow.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAccessor02NewtGLWindow.java index 787858175..b40eb3203 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAccessor02NewtGLWindow.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAccessor02NewtGLWindow.java @@ -92,12 +92,11 @@ public class TestSWTAccessor02NewtGLWindow extends UITestCase { Composite composite = null; protected void init() throws InterruptedException, InvocationTargetException { - System.err.println("SWT Platform: "+SWT.getPlatform()+", Version "+SWT.getVersion()); - System.err.println("GTK_VERSION: "+SWTAccessor.GTK_VERSION()); SWTAccessor.invoke(true, new Runnable() { public void run() { display = new Display(); Assert.assertNotNull( display ); + SWTAccessor.printInfo(System.err, display); shell = new Shell( display ); Assert.assertNotNull( shell ); shell.setLayout( new GridLayout(3, false) ); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAccessor03AWTGLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAccessor03AWTGLn.java index d3c4de885..732db5c51 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAccessor03AWTGLn.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAccessor03AWTGLn.java @@ -55,6 +55,7 @@ import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; import com.jogamp.common.os.Platform; +import com.jogamp.junit.util.JunitTracer; import com.jogamp.nativewindow.swt.SWTAccessor; import com.jogamp.opengl.test.junit.jogl.demos.es1.OneTriangle; import com.jogamp.opengl.test.junit.util.MiscUtils; @@ -82,7 +83,7 @@ public class TestSWTAccessor03AWTGLn extends UITestCase { // NSLocking issues on OSX and AWT, able to freeze whole test suite! // Since this test is merely a technical nature to validate the accessor w/ SWT // we can drop it w/o bothering. - UITestCase.setTestSupported(false); + JunitTracer.setTestSupported(false); return; } System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() ); @@ -107,6 +108,7 @@ public class TestSWTAccessor03AWTGLn extends UITestCase { public void run() { display = new Display(); Assert.assertNotNull( display ); + SWTAccessor.printInfo(System.err, display); shell = new Shell( display ); Assert.assertNotNull( shell ); shell.setLayout( new FillLayout() ); |