aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-05-20 20:58:40 +0200
committerSven Gothel <[email protected]>2014-05-20 20:58:40 +0200
commit83be0fa0ffe96c1acbc232965c2c03f40768184d (patch)
tree73d93f24921c181a416ffecd8fd8e144b272fd96 /src/nativewindow
parent0959f73ed6740724736c4871a7b63e3449f2f185 (diff)
Bug 742 HiDPI: Add access to private HiDPI in AWT pixelScale value in JAWTUtil and JAWTWindow
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java24
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java66
2 files changed, 87 insertions, 3 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
index e2a4ad4bd..8d7c382ee 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
@@ -46,6 +46,7 @@ import com.jogamp.nativewindow.MutableGraphicsConfiguration;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
+import java.awt.GraphicsDevice;
import java.awt.Window;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
@@ -750,6 +751,25 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
return component.hasFocus();
}
+ /**
+ * Returns the pixel scale factor of this {@link Component}'s {@link GraphicsDevice}, if supported.
+ * <p>
+ * If the component is not yet {@link Component#isDisplayable() displayable},
+ * <code>zero</code> is returned.
+ * </p>
+ * <p>
+ * If the component does not support pixel scaling the default
+ * <code>one</code> is returned.
+ * </p>
+ * <p>
+ * Note: Currently only supported on OSX since 1.7.0_40 for HiDPI retina displays
+ * </p>
+ * @return the pixel scale factor
+ */
+ protected final int getPixelScale() {
+ return JAWTUtil.getPixelScale(component);
+ }
+
protected StringBuilder jawt2String(StringBuilder sb) {
if( null == sb ) {
sb = new StringBuilder();
@@ -760,7 +780,9 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
if(null != jawt) {
sb.append("JAWT version: ").append(toHexString(jawt.getCachedVersion())).
append(", CA_LAYER: ").append(JAWTUtil.isJAWTUsingOffscreenLayer(jawt)).
- append(", isLayeredSurface ").append(isOffscreenLayerSurfaceEnabled()).append(", bounds ").append(bounds).append(", insets ").append(insets);
+ append(", isLayeredSurface ").append(isOffscreenLayerSurfaceEnabled()).
+ append(", bounds ").append(bounds).append(", insets ").append(insets).
+ append(", pixelScale ").append(getPixelScale());
} else {
sb.append("JAWT n/a, bounds ").append(bounds).append(", insets ").append(insets);
}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
index d4edf2ba9..fb979d440 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
@@ -37,7 +37,10 @@
package jogamp.nativewindow.jawt;
+import java.awt.Component;
import java.awt.EventQueue;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.lang.reflect.InvocationTargetException;
@@ -85,12 +88,15 @@ public class JAWTUtil {
private static final RecursiveLock jawtLock;
private static final ToolkitLock jawtToolkitLock;
+ private static final Method getScaleFactorMethod;
+
private static class PrivilegedDataBlob1 {
PrivilegedDataBlob1() {
ok = false;
}
- Method sunToolkitAWTLockMethod;
- Method sunToolkitAWTUnlockMethod;
+ Method sunToolkitAWTLockMethod;
+ Method sunToolkitAWTUnlockMethod;
+ Method getScaleFactorMethod;
boolean ok;
}
@@ -308,6 +314,7 @@ public class JAWTUtil {
sunToolkitAWTUnlockMethod = null;
hasSunToolkitAWTLock = false;
// hasSunToolkitAWTLock = false;
+ getScaleFactorMethod = null;
} else {
// Non-headless case
JAWTJNILibLoader.initSingleton(); // load libjawt.so
@@ -342,11 +349,17 @@ public class JAWTUtil {
} catch (Exception e) {
// Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5
}
+ try {
+ GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ d.getScaleFactorMethod = gd.getClass().getDeclaredMethod("getScaleFactor");
+ d.getScaleFactorMethod.setAccessible(true);
+ } catch (Throwable t) {}
return d;
}
});
sunToolkitAWTLockMethod = pdb1.sunToolkitAWTLockMethod;
sunToolkitAWTUnlockMethod = pdb1.sunToolkitAWTUnlockMethod;
+ getScaleFactorMethod = pdb1.getScaleFactorMethod;
boolean _hasSunToolkitAWTLock = false;
if ( pdb1.ok ) {
@@ -516,5 +529,54 @@ public class JAWTUtil {
return jawtToolkitLock;
}
+ /**
+ * Returns the pixel scale factor of the given {@link GraphicsDevice}, if supported.
+ * <p>
+ * If the component does not support pixel scaling the default
+ * <code>one</code> is returned.
+ * </p>
+ * <p>
+ * Note: Currently only supported on OSX since 1.7.0_40 for HiDPI retina displays
+ * </p>
+ * @param device the {@link GraphicsDevice} instance used to query the pixel scale
+ * @return the pixel scale factor
+ */
+ public static final int getPixelScale(final GraphicsDevice device) {
+ if( null != getScaleFactorMethod ) {
+ try {
+ final Object res = getScaleFactorMethod.invoke(device);
+ if (res instanceof Integer) {
+ return ((Integer)res).intValue();
+ }
+ } catch (Throwable t) {}
+ }
+ return 1;
+ }
+
+ /**
+ * Returns the pixel scale factor of the given {@link Component}'s {@link GraphicsDevice}, if supported.
+ * <p>
+ * If the component is not yet {@link Component#isDisplayable() displayable},
+ * <code>zero</code> is returned.
+ * </p>
+ * <p>
+ * If the component does not support pixel scaling the default
+ * <code>one</code> is returned.
+ * </p>
+ * <p>
+ * Note: Currently only supported on OSX since 1.7.0_40 for HiDPI retina displays
+ * </p>
+ * @param component the {@link Component} instance used to query the pixel scale
+ * @return the pixel scale factor
+ */
+ public static final int getPixelScale(final Component component) {
+ final GraphicsConfiguration gc = component.getGraphicsConfiguration();
+ final GraphicsDevice device = null != gc ? gc.getDevice() : null;
+ if( null == device ) {
+ return 0;
+ } else {
+ return JAWTUtil.getPixelScale(device);
+ }
+ }
}