summaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-02-17 07:30:34 +0100
committerSven Gothel <[email protected]>2015-02-17 07:30:34 +0100
commit37ec129f36097f41ed0d45cbccd7a93e493e2bb9 (patch)
treecb3f418d8b405c4ecb5825386cc04cf7687b5a98 /src/nativewindow
parenta28e1610e1c29279847bce80e1aa80a947ff799e (diff)
Bug 1130 - Add Mapping from AWT Component -> NEWT [Screen, MonitorDevice]
The mapping AWT Component -> NEWT [Screen, MonitorDevice] shall allow generic AWT applications to utilize NEWT's MonitorDevice information like physical monitor-size and DPI. - AWT-Component -> NEWT-Display: - NewtFactoryAWT.createDisplay - AWT-Component -> NEWT-Screen: - NewtFactoryAWT.createScreen - AWT-Component -> NEWT-MonitorMode: - NewtFactoryAWT.getMonitorDevice - NewtFactoryAWT.getMonitorDevice - If OSX, utilizing OSX's AWT Component -> MonitorDevice-Index mapping - Otherwise using the coverage to identify MonitorDevice See TestGearsES2GLJPanelAWT 'GetPixelScale', demonstrating the mapping while pressing 'p' (cached MonitorMode) and pressing SHIFT-'p' (non-cached MonitorMode).
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java88
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java4
-rw-r--r--src/nativewindow/native/macosx/OSXmisc.m28
3 files changed, 120 insertions, 0 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
index e733b7233..93c3dbaf7 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
@@ -49,14 +49,19 @@ import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Map;
+import com.jogamp.nativewindow.AbstractGraphicsDevice;
+import com.jogamp.nativewindow.AbstractGraphicsScreen;
import com.jogamp.nativewindow.NativeWindowException;
import com.jogamp.nativewindow.NativeWindowFactory;
import com.jogamp.nativewindow.ToolkitLock;
+import com.jogamp.nativewindow.awt.AWTGraphicsScreen;
import jogamp.common.os.PlatformPropsImpl;
import jogamp.nativewindow.Debug;
import jogamp.nativewindow.NWJNILibLoader;
+import jogamp.nativewindow.jawt.x11.X11SunJDKReflection;
import jogamp.nativewindow.macosx.OSXUtil;
+import jogamp.nativewindow.x11.X11Lib;
import com.jogamp.common.os.Platform;
import com.jogamp.common.util.PropertyAccess;
@@ -545,6 +550,21 @@ public class JAWTUtil {
return jawtToolkitLock;
}
+ public static final int getMonitorIndex(final GraphicsDevice device) {
+ int idx = -1;
+ if( null != getCGDisplayIDMethodOnOSX ) {
+ // OSX specific
+ try {
+ final Object res = getCGDisplayIDMethodOnOSX.invoke(device);
+ if (res instanceof Integer) {
+ final int displayID = ((Integer)res).intValue();
+ idx = OSXUtil.GetNSScreenIdx(displayID);
+ }
+ } catch (final Throwable t) {}
+ }
+ return idx;
+ }
+
/**
* Returns the pixel scale factor of the given {@link GraphicsDevice}, if supported.
* <p>
@@ -628,5 +648,73 @@ public class JAWTUtil {
}
return changed;
}
+
+ private static String getThreadName() {
+ return Thread.currentThread().getName();
+ }
+ private static String toHexString(final long val) {
+ return "0x" + Long.toHexString(val);
+ }
+
+ /**
+ * @param awtComp must be {@link java.awt.Component#isDisplayable() displayable}
+ * and must have a {@link java.awt.Component#getGraphicsConfiguration() GraphicsConfiguration}
+ * @return AbstractGraphicsDevice instance reflecting the {@code awtComp}
+ * @throws IllegalArgumentException if {@code awtComp} is not {@link java.awt.Component#isDisplayable() displayable}
+ * or has {@code null} {@link java.awt.Component#getGraphicsConfiguration() GraphicsConfiguration}.
+ * @see #getAbstractGraphicsScreen(java.awt.Component)
+ */
+ public static AbstractGraphicsDevice createDevice(final java.awt.Component awtComp) throws IllegalArgumentException {
+ if( !awtComp.isDisplayable() ) {
+ throw new IllegalArgumentException("Given AWT-Component is not displayable: "+awtComp);
+ }
+ final GraphicsDevice device;
+ final GraphicsConfiguration gc = awtComp.getGraphicsConfiguration();
+ if(null!=gc) {
+ device = gc.getDevice();
+ } else {
+ throw new IllegalArgumentException("Given AWT-Component has no GraphicsConfiguration set: "+awtComp);
+ }
+
+ final String displayConnection;
+ final String nwt = NativeWindowFactory.getNativeWindowType(true);
+ if( NativeWindowFactory.TYPE_X11 == nwt ) {
+ final long displayHandleAWT = X11SunJDKReflection.graphicsDeviceGetDisplay(device);
+ if( 0 == displayHandleAWT ) {
+ displayConnection = null; // default
+ if(DEBUG) {
+ System.err.println(getThreadName()+" - JAWTUtil.createDevice: Null AWT dpy, default X11 display");
+ }
+ } else {
+ /**
+ * Using the AWT display handle works fine with NVidia.
+ * However we experienced different results w/ AMD drivers,
+ * some work, but some behave erratic.
+ * I.e. hangs in XQueryExtension(..) via X11GraphicsScreen.
+ */
+ displayConnection = X11Lib.XDisplayString(displayHandleAWT);
+ if(DEBUG) {
+ System.err.println(getThreadName()+" - JAWTUtil.createDevice: AWT dpy "+displayConnection+" / "+toHexString(displayHandleAWT));
+ }
+ }
+ } else {
+ displayConnection = null; // default
+ }
+ return NativeWindowFactory.createDevice(displayConnection, true /* own */);
+ }
+
+ /**
+ * @param awtComp must be {@link java.awt.Component#isDisplayable() displayable}
+ * and must have a {@link java.awt.Component#getGraphicsConfiguration() GraphicsConfiguration}
+ * @return AbstractGraphicsScreen instance reflecting the {@code awtComp}
+ * @throws IllegalArgumentException if {@code awtComp} is not {@link java.awt.Component#isDisplayable() displayable}
+ * or has {@code null} {@link java.awt.Component#getGraphicsConfiguration() GraphicsConfiguration}.
+ * @see #createDevice(java.awt.Component)
+ */
+ public static AbstractGraphicsScreen getAbstractGraphicsScreen(final java.awt.Component awtComp) throws IllegalArgumentException {
+ final AbstractGraphicsDevice adevice = createDevice(awtComp);
+ return NativeWindowFactory.createScreen(adevice, AWTGraphicsScreen.findScreenIndex(awtComp.getGraphicsConfiguration().getDevice()));
+ }
+
}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
index 8ec7b7e95..a5970b87c 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
@@ -107,6 +107,9 @@ public class OSXUtil implements ToolkitProperties {
return (Insets) GetInsets0(windowOrView);
}
+ public static int GetNSScreenIdx(final int displayID) {
+ return GetNSScreenIdx0(displayID);
+ }
public static double GetPixelScaleByScreenIdx(final int screenIndex) {
return GetPixelScale0(screenIndex);
}
@@ -395,6 +398,7 @@ public class OSXUtil implements ToolkitProperties {
private static native boolean isNSWindow0(long object);
private static native Object GetLocationOnScreen0(long windowOrView, int src_x, int src_y);
private static native Object GetInsets0(long windowOrView);
+ private static native int GetNSScreenIdx0(int displayID);
private static native double GetPixelScale0(int screenIndex);
private static native double GetPixelScale1(int displayID);
private static native double GetPixelScale2(long windowOrView);
diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m
index 2cc272a41..87494e946 100644
--- a/src/nativewindow/native/macosx/OSXmisc.m
+++ b/src/nativewindow/native/macosx/OSXmisc.m
@@ -156,6 +156,18 @@ static NSScreen * OSXUtil_getNSScreenByCGDirectDisplayID(CGDirectDisplayID displ
}
return (NSScreen *) [screens objectAtIndex: 0];
}
+static int OSXUtil_getNSScreenIdxByCGDirectDisplayID(CGDirectDisplayID displayID) {
+ NSArray *screens = [NSScreen screens];
+ int i;
+ for(i=[screens count]-1; i>=0; i--) {
+ NSScreen * screen = (NSScreen *) [screens objectAtIndex: i];
+ CGDirectDisplayID dID = OSXUtil_getCGDirectDisplayIDByNSScreen(screen);
+ if( dID == displayID ) {
+ return i;
+ }
+ }
+ return -1;
+}
/*
* Class: Java_jogamp_nativewindow_macosx_OSXUtil
@@ -263,6 +275,22 @@ JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetInsets0
/*
* Class: Java_jogamp_nativewindow_macosx_OSXUtil
+ * Method: GetNSScreenIdx0
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetNSScreenIdx0
+ (JNIEnv *env, jclass unused, jint displayID)
+{
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+
+ int idx = OSXUtil_getNSScreenIdxByCGDirectDisplayID((CGDirectDisplayID)displayID);
+ [pool release];
+
+ return idx;
+}
+
+/*
+ * Class: Java_jogamp_nativewindow_macosx_OSXUtil
* Method: GetPixelScale0
* Signature: (I)D
*/