diff options
author | Sven Gothel <[email protected]> | 2023-05-15 06:47:22 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-05-15 06:47:22 +0200 |
commit | 900c35c6a49e0d53e38dd07da709bf81e28abd3e (patch) | |
tree | 97a10ef8c5e0609f66545f19a0b370e183af132f /src/nativewindow/classes/com | |
parent | cc5e46d8096a9395246518ad413385167f5f8eee (diff) |
HiDPI: Revise AWT GLCanvas/GLJPanel ScalableSurface: No setSurfaceScale(), have AWT toolkit define pixelScale only (simplification)
This aligns with Glenn's initial AWT patch commit e5e7514d649cd7dd28bbb8e04b72338dc09c2c83, i.e. removing redundancies...
Tested on Linux, Windows and MacOS w/ GLCanvas, GLJPanel and GLWindow using pixelScale values:
- Linux: 1, 2
- Windows: 1, 1.25, 2
- MacOS: 1, 2
Diffstat (limited to 'src/nativewindow/classes/com')
-rw-r--r-- | src/nativewindow/classes/com/jogamp/nativewindow/ScalableSurface.java | 20 | ||||
-rw-r--r-- | src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java | 74 |
2 files changed, 64 insertions, 30 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/ScalableSurface.java b/src/nativewindow/classes/com/jogamp/nativewindow/ScalableSurface.java index eea9e4bed..ec584f3be 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/ScalableSurface.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/ScalableSurface.java @@ -1,5 +1,5 @@ /** - * Copyright 2014 JogAmp Community. All rights reserved. + * Copyright 2014-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -39,12 +39,25 @@ public interface ScalableSurface { public static final float AUTOMAX_PIXELSCALE = 0f; /** + * Returns true if {@link #setSurfaceScale(float[])} is supported, otherwise false. + * <p> + * For pure downstream scalable surfaces like AWT widgets, + * setting the picel scale is not supported since the pixel scale is set by the underlying toolkit. + * </p> + */ + public boolean canSetSurfaceScale(); + + /** * Request a pixel scale in x- and y-direction for the associated {@link NativeSurface}, * where {@code size_in_pixel_units = pixel_scale * size_in_window_units}. * <p> * Default pixel scale request for both directions is {@link #AUTOMAX_PIXELSCALE}. * </p> * <p> + * If {@link #canSetSurfaceScale()} returns false, requested pixel scale is {@link #AUTOMAX_PIXELSCALE}, + * immutable and method returns false. + * </p> + * <p> * In case platform only supports uniform pixel scale, i.e. one scale for both directions, * either {@link #AUTOMAX_PIXELSCALE} or the maximum requested pixel scale component is used. * </p> @@ -61,15 +74,20 @@ public interface ScalableSurface { * @param pixelScale <i>requested</i> surface pixel scale float[2] values for x- and y-direction. * @return {@code true} if the {@link #getCurrentSurfaceScale(float[]) current pixel scale} has changed, otherwise {@code false}. * @see #getRequestedSurfaceScale(float[]) + * @see #canSetSurfaceScale() */ public boolean setSurfaceScale(final float[] pixelScale); /** * Returns the {@link #setSurfaceScale(float[]) requested} pixel scale of the associated {@link NativeSurface}. + * <p> + * If {@link #canSetSurfaceScale()} returns false, requested pixel scale is {@link #AUTOMAX_PIXELSCALE} and immutable. + * </p> * * @param result float[2] storage for the result * @return the passed storage containing the current pixelScale for chaining * @see #setSurfaceScale(float[]) + * @see #canSetSurfaceScale() */ public float[] getRequestedSurfaceScale(final float[] result); diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java index 78cb58b8d..f7d4761fe 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 JogAmp Community. All rights reserved. + * Copyright (c) 2010-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -102,10 +102,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, protected Insets insets; private volatile long offscreenSurfaceLayer; - private final float[] minPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; - private final float[] maxPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; private final float[] hasPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; - private final float[] reqPixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE }; private volatile boolean hasPixelScaleChanged = false; private long drawable_old; @@ -283,10 +280,6 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, insets = new Insets(); hasPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE; hasPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE; - minPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE; - minPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE; - maxPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE; - maxPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE; hasPixelScaleChanged = false; } protected abstract void invalidateNative(final long _offscreenSurfaceLayer); @@ -322,15 +315,36 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, return awtConfig; } + /** + * {@inheritDoc} + * <p> + * This implementation returns false, i.e. not supporting manual change of pixel-scale. + * </p> + */ + @Override + public final boolean canSetSurfaceScale() { return false; } + + /** + * {@inheritDoc} + * <p> + * Ignored for an AWT widget since pixelScale is dictated by AWT mechanisms. + * </p> + */ @Override public boolean setSurfaceScale(final float[] pixelScale) { - System.arraycopy(pixelScale, 0, reqPixelScale, 0, 2); return false; } + /** + * {@inheritDoc} + * <p> + * Returns {@link ScalableSurface#AUTOMAX_PIXELSCALE}, always. + * </p> + */ @Override public final float[] getRequestedSurfaceScale(final float[] result) { - System.arraycopy(reqPixelScale, 0, result, 0, 2); + result[0] = ScalableSurface.AUTOMAX_PIXELSCALE; + result[1] = ScalableSurface.AUTOMAX_PIXELSCALE; return result; } @@ -340,15 +354,28 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, return result; } + /** + * {@inheritDoc} + * <p> + * Returns 1.0, always. + * </p> + */ @Override public float[] getMinimumSurfaceScale(final float[] result) { - System.arraycopy(minPixelScale, 0, result, 0, 2); + result[0] = 1f; + result[1] = 1f; return result; } + /** + * {@inheritDoc} + * <p> + * Returns {@link #getCurrentSurfaceScale(float[])}. + * </p> + */ @Override public final float[] getMaximumSurfaceScale(final float[] result) { - System.arraycopy(maxPixelScale, 0, result, 0, 2); + System.arraycopy(hasPixelScale, 0, result, 0, 2); return result; } @@ -390,17 +417,15 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, * @see Component#getGraphicsConfiguration() */ public final boolean updatePixelScale(final GraphicsConfiguration gc, final boolean clearFlag) { - if( JAWTUtil.getPixelScale(gc, minPixelScale, maxPixelScale) ) { + final float[] min = { 1, 1 }; + final float[] max = { hasPixelScale[0], hasPixelScale[1] }; + if( JAWTUtil.getPixelScale(gc, min, max) ) { // Enforce maxPixelScale as used by AWT - hasPixelScaleChanged = true; - System.arraycopy(maxPixelScale, 0, hasPixelScale, 0, 2); if( DEBUG ) { - System.err.println("JAWTWindow.updatePixelScale: updated req["+ - reqPixelScale[0]+", "+reqPixelScale[1]+"], min["+ - minPixelScale[0]+", "+minPixelScale[1]+"], max["+ - maxPixelScale[0]+", "+maxPixelScale[1]+"], has["+ - hasPixelScale[0]+", "+hasPixelScale[1]+"]"); + System.err.println("JAWTWindow.updatePixelScale: ["+hasPixelScale[0]+", "+hasPixelScale[1]+"] -> ["+max[0]+", "+max[1]+"]"); } + hasPixelScaleChanged = true; + System.arraycopy(max, 0, hasPixelScale, 0, 2); } if( clearFlag ) { final boolean r = hasPixelScaleChanged; @@ -428,15 +453,6 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, return v; } - /** - * set requested pixelScale - * @return true if pixelScale has changed, otherwise false - */ - protected final boolean setReqPixelScale() { - updatePixelScale(awtConfig.getAWTGraphicsConfiguration(), true); - return SurfaceScaleUtils.setNewPixelScale(hasPixelScale, hasPixelScale, reqPixelScale, minPixelScale, maxPixelScale, DEBUG ? getClass().getSimpleName() : null); - } - /** @return the JAWT_DrawingSurfaceInfo's (JAWT_Rectangle) bounds in pixel units, updated with lock */ public final RectangleImmutable getJAWTSurfaceBounds() { return jawt_surface_bounds; } |