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/nativewindow | |
parent | cfe56e9e6bda15873fefce6f03d343ccdfc51f9b (diff) |
HiDPI AWT/NEWT: Propagate AWT enforced pixelScale via setSurfaceScale() blocking native change by monitor-pixelScale (Windows, X11)
Diffstat (limited to 'src/nativewindow')
-rw-r--r-- | src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java | 1 | ||||
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java | 30 |
2 files changed, 26 insertions, 5 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java index 89ca40096..78cb58b8d 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java @@ -391,6 +391,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, */ public final boolean updatePixelScale(final GraphicsConfiguration gc, final boolean clearFlag) { if( JAWTUtil.getPixelScale(gc, minPixelScale, maxPixelScale) ) { + // Enforce maxPixelScale as used by AWT hasPixelScaleChanged = true; System.arraycopy(maxPixelScale, 0, hasPixelScale, 0, 2); if( DEBUG ) { diff --git a/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java b/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java index 8f45001f9..152b189d1 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java +++ b/src/nativewindow/classes/jogamp/nativewindow/SurfaceScaleUtils.java @@ -41,9 +41,29 @@ public class SurfaceScaleUtils { private static final float EPSILON = 1.1920929E-7f; // Float.MIN_VALUE == 1.4e-45f ; double EPSILON 2.220446049250313E-16d - private static boolean isZero(final float a) { + /** Returns true if `abs(a) < EPSILON`, otherwise false. */ + public static boolean isZero(final float a) { return Math.abs(a) < EPSILON; } + /** Returns true if `isZero(f2[0]) && isZero(f2[1])`, otherwise false. */ + public static boolean isZero(final float[] f2) { + return isZero(f2[0]) && isZero(f2[1]); + } + + /** Returns true if `abs(a-b) < EPSILON`, otherwise false. */ + public static boolean isEqual(final float a, final float b) { + return Math.abs(a-b) < EPSILON; + } + + /** Returns true if `isEqual(f2[0], c) && isEqual(f2[1], c)`, otherwise false. */ + public static boolean isEqual(final float[] f2, final float c) { + return isEqual(f2[0], c) && isEqual(f2[1], c); + } + + /** Returns true if `isEqual(f2[0], g2[0]) && isEqual(f2[1], g2[1])`, otherwise false. */ + public static boolean isEqual(final float[] f2, final float[] g2) { + return isEqual(f2[0], g2[0]) && isEqual(f2[1], g2[1]); + } /** * Returns integer rounded product, i.e. {@code (int) ( a * pixelScale + 0.5f )} @@ -158,15 +178,15 @@ public class SurfaceScaleUtils { * @return the constrained pixel-scale */ public static float clampPixelScale(final float pixelScale, final float minPixelScale, final float maxPixelScale) { - if( isZero(pixelScale-ScalableSurface.IDENTITY_PIXELSCALE) ) { + if( isEqual(pixelScale, ScalableSurface.IDENTITY_PIXELSCALE) ) { return ScalableSurface.IDENTITY_PIXELSCALE; - } else if( isZero(pixelScale-ScalableSurface.AUTOMAX_PIXELSCALE) || + } else if( isEqual(pixelScale, ScalableSurface.AUTOMAX_PIXELSCALE) || pixelScale > maxPixelScale || - isZero(pixelScale-maxPixelScale) + isEqual(pixelScale, maxPixelScale) ) { return maxPixelScale; - } else if( pixelScale < minPixelScale || isZero(pixelScale-minPixelScale) ) + } else if( pixelScale < minPixelScale || isEqual(pixelScale, minPixelScale) ) { return minPixelScale; } else { |