diff options
author | Sven Gothel <[email protected]> | 2023-05-14 05:41:22 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-05-14 05:41:22 +0200 |
commit | 9d1e7c9adca97780a5b45b135c5693cffee218fc (patch) | |
tree | 454a8afe6c9f5d4d31efed60403476e0a7fe5092 /src/newt | |
parent | cfe56e9e6bda15873fefce6f03d343ccdfc51f9b (diff) |
HiDPI AWT/NEWT: Propagate AWT enforced pixelScale via setSurfaceScale() blocking native change by monitor-pixelScale (Windows, X11)
Diffstat (limited to 'src/newt')
4 files changed, 21 insertions, 47 deletions
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index 7ccab3336..783bc6857 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -636,23 +636,16 @@ public class NewtCanvasAWT extends java.awt.Canvas implements NativeWindowHolder } } } - private final boolean updatePixelScale(final GraphicsConfiguration gc) { - if( jawtWindow.updatePixelScale(gc, true) ) { + + /** Propagates AWT pixelScale to NEWT */ + private final boolean updatePixelScale(final GraphicsConfiguration gc, final boolean force) { + if( jawtWindow.updatePixelScale(gc, false) || jawtWindow.hasPixelScaleChanged() || force ) { + jawtWindow.hasPixelScaleChanged(); // clear + final float[] hasPixelScale = jawtWindow.getCurrentSurfaceScale(new float[2]); final Window cWin = newtChild; final Window dWin = cWin.getDelegatedWindow(); if( dWin instanceof WindowImpl ) { - final float[] maxPixelScale = jawtWindow.getMaximumSurfaceScale(new float[2]); - final float[] minPixelScale = jawtWindow.getMinimumSurfaceScale(new float[2]); - // FIXME: Bug 1373, 1374: Implement general High-DPI for even non native DPI toolkit aware platforms (Linux, Windows) - // final float[] curPixelScale = jawtWindow.getCurrentSurfaceScale(new float[2]); - // ((WindowImpl)dWin).pixelScaleChangeNotify(curPixelScale, minPixelScale, maxPixelScale); - ((WindowImpl)dWin).pixelScaleChangeNotify(minPixelScale, maxPixelScale, true); - // ((WindowImpl)dWin).sizeChangedNotify(true /* defer */, getWidth(), getHeight(), true /* force */); - } else { - final float[] reqPixelScale = jawtWindow.getRequestedSurfaceScale(new float[2]); - if( jawtWindow.setSurfaceScale(reqPixelScale) ) { - // jawtWindow.getRequestedSurfaceScale(reqPixelScale); - } + ((WindowImpl)dWin).setSurfaceScale(hasPixelScale); } return true; } @@ -761,7 +754,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements NativeWindowHolder System.err.println("NewtCanvasAWT.reshape: "+x+"/"+y+" "+width+"x"+height); } if( validateComponent(true) ) { - if( !printActive && updatePixelScale(getGraphicsConfiguration()) ) { + if( !printActive && updatePixelScale(getGraphicsConfiguration(), false /* force */) ) { // NOP } else { // newtChild.setSize(width, height); @@ -1059,8 +1052,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements NativeWindowHolder } newtChild.setVisible(false); newtChild.setSize(w, h); - final float[] reqSurfaceScale = newtChild.getRequestedSurfaceScale(new float[2]); - jawtWindow.setSurfaceScale(reqSurfaceScale); + updatePixelScale(getGraphicsConfiguration(), true /* force */); // AWT -> NEWT newtChild.reparentWindow(jawtWindow, -1, -1, Window.REPARENT_HINT_BECOMES_VISIBLE); newtChild.addSurfaceUpdatedListener(jawtWindow); if( jawtWindow.isOffscreenLayerSurfaceEnabled() && diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index c860e4c3e..8632dc5f4 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -163,6 +163,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer protected final float[] maxPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; protected final float[] hasPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; protected final float[] reqPixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE }; + private boolean hasSetPixelScale = false; private volatile int[] pixelPos = new int[] { 64, 64 }; // client-area pos w/o insets in pixel units private volatile int[] pixelSize = new int[] { 128, 128 }; // client-area size w/o insets in pixel units, default: may be overwritten by user private volatile int[] windowPos = new int[] { 64, 64 }; // client-area pos w/o insets in window units @@ -2695,15 +2696,20 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer /** * {@inheritDoc} - * <p> - * FIXME: Bug 1373, 1374: Implement general High-DPI for even non native DPI toolkit aware platforms (Linux, Windows) - * </p> */ @Override public boolean setSurfaceScale(final float[] pixelScale) { + final boolean isAuto = SurfaceScaleUtils.isEqual(pixelScale, ScalableSurface.AUTOMAX_PIXELSCALE); + if( DEBUG_IMPLEMENTATION ) { + System.err.println("WindowImpl.setPixelScale.0: has["+hasPixelScale[0]+", "+hasPixelScale[1]+"], req["+ + reqPixelScale[0]+", "+reqPixelScale[1]+"] -> req["+ + pixelScale[0]+", "+pixelScale[1]+"], isAuto "+isAuto+", realized "+isNativeValid()); + } System.arraycopy(pixelScale, 0, reqPixelScale, 0, 2); + hasSetPixelScale = !isAuto; return false; } + protected boolean hasSetPixelScale() { return hasSetPixelScale; } @Override public final float[] getRequestedSurfaceScale(final float[] result) { @@ -2967,7 +2973,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer boolean res = false; if( DEBUG_IMPLEMENTATION ) { System.err.println("Window.SoftPixelScale.0a: req "+reqPixelScale[0]+", has "+hasPixelScale[0]+", new "+newPixelScale[0]+" - "+getThreadName()); - // Thread.dumpStack(); + Thread.dumpStack(); } synchronized( scaleLock ) { try { @@ -5245,30 +5251,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer // Misc // - /** - * Notify to update the pixel-scale values. - * <p> - * FIXME: Bug 1373, 1374: Implement general High-DPI for even non native DPI toolkit aware platforms (Linux, Windows) - * A variation may be be desired like - * {@code pixelScaleChangeNotify(final float[] curPixelScale, final float[] minPixelScale, final float[] maxPixelScale)}. - * </p> - * <p> - * Maybe create interface {@code ScalableSurface.Upstream} with above method, - * to allow downstream to notify upstream ScalableSurface implementations like NEWT's {@link Window} to act accordingly. - * </p> - * @param minPixelScale - * @param maxPixelScale - * @param reset if {@code true} {@link #setSurfaceScale(float[]) reset pixel-scale} w/ {@link #getRequestedSurfaceScale(float[]) requested values} - * value to reflect the new minimum and maximum values. - */ - public final void pixelScaleChangeNotify(final float[] minPixelScale, final float[] maxPixelScale, final boolean reset) { - System.arraycopy(minPixelScale, 0, this.minPixelScale, 0, 2); - System.arraycopy(maxPixelScale, 0, this.maxPixelScale, 0, 2); - if( reset ) { - setSurfaceScale(reqPixelScale); - } - } - @Override public final void windowRepaint(final int x, final int y, final int width, final int height) { windowRepaint(false, x, y, width, height); diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java index 1605d4126..b95911adf 100644 --- a/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java @@ -76,7 +76,7 @@ public class WindowDriver extends WindowImpl { */ private boolean updatePixelScaleByMonitor(final long crt_handle, final int[] move_diff, final boolean sendEvent, final boolean defer) { boolean res = false; - if( 0 != crt_handle ) { + if( !hasSetPixelScale() && 0 != crt_handle ) { final float newPixelScaleRaw[] = { 0, 0 }; if( GDIUtil.GetMonitorPixelScale(crt_handle, newPixelScaleRaw) ) { res = applySoftPixelScale(move_diff, sendEvent, defer, newPixelScaleRaw); diff --git a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java index 5fb01c619..e939edeae 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java @@ -105,7 +105,7 @@ public class WindowDriver extends WindowImpl { */ private boolean updatePixelScaleByMonitor(final MonitorDevice md, final int[] move_diff, final boolean sendEvent, final boolean defer) { boolean res = false; - if( null != md ) { + if( !hasSetPixelScale() && null != md ) { final float newPixelScale[] = { 0, 0 }; md.getPixelScale(newPixelScale); if( DEBUG_IMPLEMENTATION ) { |