diff options
author | Sven Gothel <[email protected]> | 2019-08-19 12:29:48 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2019-08-19 12:29:48 +0200 |
commit | c7858dc766cb9f76ac8f543796b1587a0f8f9279 (patch) | |
tree | 690c27a21bd82f2ed9424fcbf1fe35d8c71508d5 /src/nativewindow/classes/jogamp | |
parent | 13c6bbbde5ea476d60e0a2f04a5172d3302d0edd (diff) |
Bug 1363: Java 11: Don't use GraphicsDevice.getScaleFactor() on Java9+ [illegal reflective access]
Use non-reflective method to get the pixel scale on Java9+
It's now possible to use GraphicsConfiguration.getDefaultTransform()
instead of using reflection to get the pixel scale, which eliminates an
illegal reflective access warning.
Orig patch by Wade Walker
Diffstat (limited to 'src/nativewindow/classes/jogamp')
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java index 6158e792e..c8c12e128 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java @@ -42,6 +42,7 @@ import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Toolkit; +import java.awt.geom.AffineTransform; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.security.AccessController; @@ -373,8 +374,10 @@ public class JAWTUtil { try { final GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); final Class<?> gdClass = gd.getClass(); - d.getScaleFactorMethod = gdClass.getDeclaredMethod("getScaleFactor"); - d.getScaleFactorMethod.setAccessible(true); + if( !PlatformPropsImpl.JAVA_9 ) { + d.getScaleFactorMethod = gdClass.getDeclaredMethod("getScaleFactor"); + d.getScaleFactorMethod.setAccessible(true); + } if( Platform.OSType.MACOS == PlatformPropsImpl.OS_TYPE ) { d.getCGDisplayIDMethodOnOSX = gdClass.getDeclaredMethod("getCGDisplayID"); d.getCGDisplayIDMethodOnOSX.setAccessible(true); @@ -590,6 +593,7 @@ public class JAWTUtil { minScale[1] = 1f; float sx = 1f; float sy = 1f; + boolean gotSXZ = false; if( !SKIP_AWT_HIDPI ) { if( null != getCGDisplayIDMethodOnOSX ) { // OSX specific, preserving double type @@ -599,10 +603,11 @@ public class JAWTUtil { final int displayID = ((Integer)res).intValue(); sx = OSXUtil.GetScreenPixelScaleByDisplayID(displayID); sy = sx; + gotSXZ = true; } } catch (final Throwable t) {} } - if( null != getScaleFactorMethod ) { + if( !gotSXZ && null != getScaleFactorMethod ) { // Generic (?) try { final Object res = getScaleFactorMethod.invoke(device); @@ -612,8 +617,16 @@ public class JAWTUtil { sx = ((Double)res).floatValue(); } sy = sx; + gotSXZ = true; } catch (final Throwable t) {} } + if( !gotSXZ ) { + final GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + final GraphicsConfiguration gc = gd.getDefaultConfiguration(); + final AffineTransform tx = gc.getDefaultTransform(); + sx = (float)tx.getScaleX(); + sy = (float)tx.getScaleY(); + } } changed = maxScale[0] != sx || maxScale[1] != sy; maxScale[0] = sx; |