summaryrefslogtreecommitdiffstats
path: root/src/newt/classes
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-02-16 06:23:43 +0100
committerSven Gothel <[email protected]>2015-02-16 06:23:43 +0100
commit70faf070f50ea66fd4cc8f5f586614810f378787 (patch)
treec4e1175587337386620c823927c017c6fd68c727 /src/newt/classes
parent1eea4278f1be5900f0d990d0a7d352923def217c (diff)
Bug 1129 - NEWT MonitorDevice's physical size on Windows must be read via EDID
On Windows, one must read the monitor's EDID data as stored in the registry, no 'simple' API works otherwise. The proper way requires utilizing the Windows Setup-API. This code is inspired by Ofek Shilon's code and blog post: <http://ofekshilon.com/2014/06/19/reading-specific-monitor-dimensions/> See: function 'NewtEDID_GetMonitorSizeFromEDIDByModelName' In contrast to Ofek's code, function 'NewtEDID_GetMonitorSizeFromEDIDByDevice' uses the proper link from DISPLAY_DEVICE.DeviceID -> SP_DEVICE_INTERFACE_DETAIL_DATA.DevicePath, where DISPLAY_DEVICE.DeviceID is the monitor's enumeration via: EnumDisplayDevices(adapterName, monitor_idx, &ddMon, EDD_GET_DEVICE_INTERFACE_NAME); Hence the path to the registry-entry is well determined instead of just comparing the monitor's model name.
Diffstat (limited to 'src/newt/classes')
-rw-r--r--src/newt/classes/com/jogamp/newt/opengl/GLWindow.java5
-rw-r--r--src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java82
2 files changed, 48 insertions, 39 deletions
diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
index d638b3ae5..e15f52730 100644
--- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
+++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
@@ -1004,6 +1004,11 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind
glWindow.addGLEventListener(new GLEventListener() {
@Override
public void init(final GLAutoDrawable drawable) {
+ final MonitorDevice monitor = glWindow.getMainMonitor();
+ System.err.println("Main Monitor: "+monitor);
+ final float[] pixelPerMM = monitor.getPixelsPerMM(new float[2]);
+ System.err.println(" pp/mm ["+pixelPerMM[0]+", "+pixelPerMM[1]+"]");
+ System.err.println(" pp/in ["+pixelPerMM[0]*25.4f+", "+pixelPerMM[1]*25.4f+"]");
final GL gl = drawable.getGL();
System.err.println(JoglVersion.getGLInfo(gl, null));
System.err.println("Requested: "+drawable.getNativeSurface().getGraphicsConfiguration().getRequestedCapabilities());
diff --git a/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java
index b476ee38a..947ea27f4 100644
--- a/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java
@@ -65,19 +65,21 @@ public class ScreenDriver extends ScreenImpl {
protected void closeNativeImpl() {
}
- private final String getAdapterName(final int crt_idx) {
- return getAdapterName0(crt_idx);
+ private final String getAdapterName(final int adapter_idx) {
+ return getAdapterName0(adapter_idx);
}
- private final String getActiveMonitorName(final String adapterName, final int monitor_idx) {
- return getActiveMonitorName0(adapterName, monitor_idx);
+ private final String getMonitorName(final String adapterName, final int monitor_idx, final boolean onlyActive) {
+ return getMonitorName0(adapterName, monitor_idx, onlyActive);
+ }
+ private final int getFirstActiveMonitor(final String adapterName) {
+ return getFirstActiveMonitor0(adapterName);
}
- private final MonitorMode getMonitorModeImpl(final MonitorModeProps.Cache cache, final String adapterName, final int crtModeIdx) {
+ private final MonitorMode getMonitorModeImpl(final MonitorModeProps.Cache cache, final String adapterName, final int mode_idx) {
if( null == adapterName ) {
return null;
}
- final String activeMonitorName = getActiveMonitorName(adapterName, 0);
- final int[] modeProps = null != activeMonitorName ? getMonitorMode0(adapterName, crtModeIdx) : null;
+ final int[] modeProps = getMonitorMode0(adapterName, mode_idx);
if ( null == modeProps || 0 >= modeProps.length) {
return null;
}
@@ -86,34 +88,35 @@ public class ScreenDriver extends ScreenImpl {
@Override
protected void collectNativeMonitorModesAndDevicesImpl(final MonitorModeProps.Cache cache) {
- int crtIdx = 0;
ArrayHashSet<MonitorMode> supportedModes = new ArrayHashSet<MonitorMode>();
- String adapterName = getAdapterName(crtIdx);
- while( null != adapterName ) {
- int crtModeIdx = 0;
- MonitorMode mode;
- do {
- mode = getMonitorModeImpl(cache, adapterName, crtModeIdx);
- if( null != mode ) {
- supportedModes.getOrAdd(mode);
- // next mode on same monitor
- crtModeIdx++;
- }
- } while( null != mode);
- if( 0 < crtModeIdx ) {
- // has at least one mode -> add device
- final MonitorMode currentMode = getMonitorModeImpl(cache, adapterName, -1);
- if ( null != currentMode ) { // enabled
- final int[] monitorProps = getMonitorDevice0(adapterName, crtIdx);
- // merge monitor-props + supported modes
- MonitorModeProps.streamInMonitorDevice(cache, this, currentMode, null, supportedModes, monitorProps, 0, null);
-
- // next monitor, 1st mode
- supportedModes= new ArrayHashSet<MonitorMode>();
+ int adapter_idx;
+ String adapterName;
+ for(adapter_idx=0; null != ( adapterName = getAdapterName(adapter_idx) ); adapter_idx++ ) {
+ final int activeMonitorIdx = getFirstActiveMonitor(adapterName);
+ if( 0 <= activeMonitorIdx ) {
+ int mode_idx = 0;
+ MonitorMode mode;
+ do {
+ mode = getMonitorModeImpl(cache, adapterName, mode_idx);
+ if( null != mode ) {
+ supportedModes.getOrAdd(mode);
+ // next mode on same monitor
+ mode_idx++;
+ }
+ } while( null != mode);
+ if( 0 < mode_idx ) {
+ // has at least one mode -> add device
+ final MonitorMode currentMode = getMonitorModeImpl(cache, adapterName, -1);
+ if ( null != currentMode ) { // enabled
+ final int[] monitorProps = getMonitorDevice0(adapterName, adapter_idx);
+ // merge monitor-props + supported modes
+ MonitorModeProps.streamInMonitorDevice(cache, this, currentMode, null, supportedModes, monitorProps, 0, null);
+
+ // next monitor, 1st mode
+ supportedModes = new ArrayHashSet<MonitorMode>();
+ }
}
}
- crtIdx++;
- adapterName = getAdapterName(crtIdx);
}
}
@@ -121,8 +124,8 @@ public class ScreenDriver extends ScreenImpl {
protected boolean updateNativeMonitorDeviceViewportImpl(final MonitorDevice monitor, final float[] pixelScale, final Rectangle viewportPU, final Rectangle viewportWU) {
final String adapterName = getAdapterName(monitor.getId());
if( null != adapterName ) {
- final String activeMonitorName = getActiveMonitorName(adapterName, 0);
- if( null != activeMonitorName ) {
+ final int activeMonitorIdx = getFirstActiveMonitor(adapterName);
+ if( 0 <= activeMonitorIdx ) {
final int[] monitorProps = getMonitorDevice0(adapterName, monitor.getId());
int offset = MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT;
viewportPU.set(monitorProps[offset++], monitorProps[offset++], monitorProps[offset++], monitorProps[offset++]);
@@ -168,9 +171,10 @@ public class ScreenDriver extends ScreenImpl {
private native int getVirtualHeightImpl0();
private static native void dumpMonitorInfo0();
- private native String getAdapterName0(int crt_index);
- private native String getActiveMonitorName0(String adapterName, int crtModeIdx);
- private native int[] getMonitorMode0(String adapterName, int crtModeIdx);
- private native int[] getMonitorDevice0(String adapterName, int monitor_index);
- private native boolean setMonitorMode0(int monitor_index, int x, int y, int width, int height, int bits, int freq, int flags, int rot);
+ private native String getAdapterName0(int adapter_idx);
+ private native String getMonitorName0(String adapterName, int monitor_idx, boolean onlyActive);
+ private native int getFirstActiveMonitor0(String adapterName);
+ private native int[] getMonitorMode0(String adapterName, int mode_idx);
+ private native int[] getMonitorDevice0(String adapterName, int adapter_idx);
+ private native boolean setMonitorMode0(int adapter_idx, int x, int y, int width, int height, int bits, int freq, int flags, int rot);
}