From c7858dc766cb9f76ac8f543796b1587a0f8f9279 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 19 Aug 2019 12:29:48 +0200 Subject: 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 --- .../classes/jogamp/nativewindow/jawt/JAWTUtil.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src') 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; -- cgit v1.2.3