From 0adbc977ac7848e8092fa1d58174d0a37aabb86b Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 9 Mar 2015 15:45:36 +0100 Subject: Bug 1142 - NEWT: Add support to retrieve the primary MonitorDevice Support added for - Windows - X11 XRandR 1.3 - OSX Note: Our whole MonitorMode association handling is currently _not_ dynamic. - only on Windows we actually use native unique ID, which might not change (adapter and monitor idx) - On OSX and X11 we simply use indices, but if monitor setup changes - they refer to different instances. In case it is desired to cover dynamic monitor setup change, we need to address this issue in a new bug entry. --- .../classes/jogamp/newt/MonitorDeviceImpl.java | 23 ++++++++------ src/newt/classes/jogamp/newt/MonitorModeProps.java | 36 ++++++++++++++++++---- src/newt/classes/jogamp/newt/ScreenImpl.java | 23 ++++++++++++-- .../classes/jogamp/newt/ScreenMonitorState.java | 9 +++++- .../jogamp/newt/driver/android/ScreenDriver.java | 1 + .../jogamp/newt/driver/awt/ScreenDriver.java | 1 + .../jogamp/newt/driver/bcm/egl/ScreenDriver.java | 1 + .../jogamp/newt/driver/bcm/vc/iv/ScreenDriver.java | 1 + .../jogamp/newt/driver/intel/gdl/ScreenDriver.java | 1 + .../jogamp/newt/driver/kd/ScreenDriver.java | 1 + .../jogamp/newt/driver/windows/ScreenDriver.java | 6 ++-- .../classes/jogamp/newt/driver/x11/RandR11.java | 1 + .../classes/jogamp/newt/driver/x11/RandR13.java | 1 - 13 files changed, 83 insertions(+), 22 deletions(-) (limited to 'src/newt/classes/jogamp') diff --git a/src/newt/classes/jogamp/newt/MonitorDeviceImpl.java b/src/newt/classes/jogamp/newt/MonitorDeviceImpl.java index 3f039a9f4..9f458d215 100644 --- a/src/newt/classes/jogamp/newt/MonitorDeviceImpl.java +++ b/src/newt/classes/jogamp/newt/MonitorDeviceImpl.java @@ -41,7 +41,8 @@ public class MonitorDeviceImpl extends MonitorDevice { /** * @param screen associated {@link Screen} * @param nativeId unique monitor device ID - * @param isClone TODO + * @param isClone flag + * @param isPrimary flag * @param sizeMM size in millimeters * @param currentMode * @param pixelScale pre-fetched current pixel-scale, maybe {@code null} for {@link ScalableSurface#IDENTITY_PIXELSCALE}. @@ -49,11 +50,11 @@ public class MonitorDeviceImpl extends MonitorDevice { * @param viewportWU viewport in window-units * @param supportedModes all supported {@link MonitorMode}s */ - public MonitorDeviceImpl(final ScreenImpl screen, final int nativeId, final boolean isClone, - final DimensionImmutable sizeMM, - final MonitorMode currentMode, final float[] pixelScale, final Rectangle viewportPU, - final Rectangle viewportWU, final ArrayHashSet supportedModes) { - super(screen, nativeId, isClone, sizeMM, currentMode, pixelScale, viewportPU, viewportWU, supportedModes); + public MonitorDeviceImpl(final ScreenImpl screen, final int nativeId, + final boolean isClone, final boolean isPrimary, + final DimensionImmutable sizeMM, final MonitorMode currentMode, final float[] pixelScale, + final Rectangle viewportPU, final Rectangle viewportWU, final ArrayHashSet supportedModes) { + super(screen, nativeId, isClone, isPrimary, sizeMM, currentMode, pixelScale, viewportPU, viewportWU, supportedModes); } @Override @@ -80,7 +81,7 @@ public class MonitorDeviceImpl extends MonitorDevice { } // if mode has changed somehow, update it .. if( getCurrentMode().hashCode() != mmU.hashCode() ) { - setCurrentModeValue(mmU); + setCurrentModeValue(mmU, isPrimary); sms.fireMonitorModeChanged(this, mmU, true); } return mmU; @@ -139,7 +140,7 @@ public class MonitorDeviceImpl extends MonitorDevice { } } if( success ) { - setCurrentModeValue(mmU); + setCurrentModeValue(mmU, isPrimary); modeChanged = !isOriginalMode(); } sms.fireMonitorModeChanged(this, mmU, success); @@ -152,8 +153,9 @@ public class MonitorDeviceImpl extends MonitorDevice { } } - private final void setCurrentModeValue(final MonitorMode currentMode) { + private final void setCurrentModeValue(final MonitorMode currentMode, final boolean isPrimary) { this.currentMode = currentMode; + this.isPrimary = isPrimary; } /* pp */ final Rectangle getMutuableViewportPU() { return viewportPU; } @@ -166,4 +168,7 @@ public class MonitorDeviceImpl extends MonitorDevice { /* pp */ final void setIsClone(final boolean isClone) { this.isClone = isClone; } + /* pp */ final void setIsPrimary(final boolean isPrimary) { + this.isPrimary = isPrimary; + } } diff --git a/src/newt/classes/jogamp/newt/MonitorModeProps.java b/src/newt/classes/jogamp/newt/MonitorModeProps.java index 873b9edc3..073a9a355 100644 --- a/src/newt/classes/jogamp/newt/MonitorModeProps.java +++ b/src/newt/classes/jogamp/newt/MonitorModeProps.java @@ -133,6 +133,7 @@ public class MonitorModeProps { *
  • count
  • *
  • id
  • *
  • IsClone
  • + *
  • IsPrimary
  • *
  • ScreenSizeMM[width, height] (2 elements)
  • *
  • Rotated Viewport pixel-units (4 elements)
  • *
  • Rotated Viewport window-units (4 elements)
  • @@ -141,17 +142,18 @@ public class MonitorModeProps { *
  • SupportedModeId+
  • * *

    - * Viewport := [x, y, width, height] (4 elements) + * with Viewport := [x, y, width, height] (4 elements) *

    *

    * WARNING: must be synchronized with ScreenMode.h, native implementation *

    */ - public static final int MIN_MONITOR_DEVICE_PROPERTIES = 16; + public static final int MIN_MONITOR_DEVICE_PROPERTIES = 17; public static final int IDX_MONITOR_DEVICE_VIEWPORT = 1 // count + 1 // native mode + 1 // isClone + + 1 // isPrimary + MonitorModeProps.NUM_RESOLUTION_PROPERTIES // sizeMM ; @@ -161,6 +163,10 @@ public class MonitorModeProps { public final ArrayHashSet sizeAndRates = new ArrayHashSet(); public final ArrayHashSet monitorModes = new ArrayHashSet(); public final ArrayHashSet monitorDevices = new ArrayHashSet(); + + public final void setPrimary(final MonitorDevice p) { primary = p; } + public final MonitorDevice getPrimary() { return primary;} + private MonitorDevice primary = null; } /** WARNING: must be synchronized with ScreenMode.h, native implementation */ @@ -292,6 +298,7 @@ public class MonitorModeProps { final List allMonitorModes = cache.monitorModes.getData(); final int id = monitorProperties[offset++]; final boolean isClone = 0 == monitorProperties[offset++] ? false : true; + final boolean isPrimary = 0 == monitorProperties[offset++] ? false : true; final DimensionImmutable sizeMM = streamInResolution(monitorProperties, offset); offset+=NUM_RESOLUTION_PROPERTIES; final Rectangle viewportPU = new Rectangle(monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++]); final Rectangle viewportWU = new Rectangle(monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++]); @@ -311,9 +318,14 @@ public class MonitorModeProps { } } } - MonitorDevice monitorDevice = new MonitorDeviceImpl(screen, id, isClone, sizeMM, currentMode, pixelScale, viewportPU, viewportWU, supportedModes); + MonitorDevice monitorDevice = new MonitorDeviceImpl(screen, id, isClone, isPrimary, + sizeMM, currentMode, pixelScale, + viewportPU, viewportWU, supportedModes); if(null!=cache) { monitorDevice = cache.monitorDevices.getOrAdd(monitorDevice); + if( monitorDevice.isPrimary() ) { + cache.setPrimary(monitorDevice); + } } if( null != monitor_idx ) { final int _monitorIdx = cache.monitorDevices.indexOf(monitorDevice); @@ -373,12 +385,18 @@ public class MonitorModeProps { offset++; final int id = monitorProperties[offset++]; final boolean isClone = 0 == monitorProperties[offset++] ? false : true; + final boolean isPrimary = 0 == monitorProperties[offset++] ? false : true; final DimensionImmutable sizeMM = streamInResolution(monitorProperties, offset); offset+=NUM_RESOLUTION_PROPERTIES; final Rectangle viewportPU = new Rectangle(monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++]); final Rectangle viewportWU = new Rectangle(monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++]); - MonitorDevice monitorDevice = new MonitorDeviceImpl(screen, id, isClone, sizeMM, currentMode, pixelScale, viewportPU, viewportWU, supportedModes); + MonitorDevice monitorDevice = new MonitorDeviceImpl(screen, id, isClone, isPrimary, + sizeMM, currentMode, pixelScale, + viewportPU, viewportWU, supportedModes); if(null!=cache) { monitorDevice = cache.monitorDevices.getOrAdd(monitorDevice); + if( monitorDevice.isPrimary() ) { + cache.setPrimary(monitorDevice); + } } if( null != monitor_idx ) { final int _monitorIdx = cache.monitorDevices.indexOf(monitorDevice); @@ -402,6 +420,7 @@ public class MonitorModeProps { data[idx++] = data.length; data[idx++] = monitorDevice.getId(); data[idx++] = monitorDevice.isClone() ? 1 : 0; + data[idx++] = monitorDevice.isPrimary() ? 1 : 0; data[idx++] = monitorDevice.getSizeMM().getWidth(); data[idx++] = monitorDevice.getSizeMM().getHeight(); data[idx++] = monitorDevice.getViewport().getX(); @@ -424,8 +443,13 @@ public class MonitorModeProps { return data; } - /** Identify monitor devices in cloned mode, i.e. consecutive devices being 100% covered by preceding devices. */ - /* pp */ static void identifyClonedMonitorDevices(final MonitorModeProps.Cache cache) { + /** + * Identify monitor devices: + *
      + *
    • cloned mode, i.e. consecutive devices being 100% covered by preceding devices.
    • + *
    + */ + /* pp */ static void identifyMonitorDevices(final MonitorModeProps.Cache cache) { final ArrayList monitors = cache.monitorDevices.toArrayList(); final int monitorCount = monitors.size(); for(int i=0; i=0; i--) { diff --git a/src/newt/classes/jogamp/newt/ScreenMonitorState.java b/src/newt/classes/jogamp/newt/ScreenMonitorState.java index ae982414b..fd1329f91 100644 --- a/src/newt/classes/jogamp/newt/ScreenMonitorState.java +++ b/src/newt/classes/jogamp/newt/ScreenMonitorState.java @@ -46,6 +46,7 @@ public class ScreenMonitorState { private final RecursiveLock lock = LockFactory.createRecursiveLock(); private final ArrayHashSet allMonitors; private final ArrayHashSet allMonitorModes; + private final MonitorDevice primaryMonitor; private final ArrayList listener = new ArrayList(); private static HashMap screenFQN2ScreenMonitorState = new HashMap(); @@ -107,15 +108,21 @@ public class ScreenMonitorState { } public ScreenMonitorState(final ArrayHashSet allMonitors, - final ArrayHashSet allMonitorModes) { + final ArrayHashSet allMonitorModes, + final MonitorDevice primaryMonitor) { this.allMonitors = allMonitors; this.allMonitorModes = allMonitorModes; + this.primaryMonitor = primaryMonitor; } protected ArrayHashSet getMonitorDevices() { return allMonitors; } + protected MonitorDevice getPrimaryMonitorDevice() { + return primaryMonitor; + } + protected ArrayHashSet getMonitorModes() { return allMonitorModes; } diff --git a/src/newt/classes/jogamp/newt/driver/android/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/android/ScreenDriver.java index 60e6e7d5f..a95b3d429 100644 --- a/src/newt/classes/jogamp/newt/driver/android/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/android/ScreenDriver.java @@ -105,6 +105,7 @@ public class ScreenDriver extends jogamp.newt.ScreenImpl { props[i++] = props.length; props[i++] = 0; // crt_idx props[i++] = 0; // is-clone + props[i++] = 1; // is-primary i = getScreenSizeMM(outMetrics, props, i); // sizeMM props[i++] = 0; // rotated viewport x pixel-units props[i++] = 0; // rotated viewport y pixel-units diff --git a/src/newt/classes/jogamp/newt/driver/awt/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/awt/ScreenDriver.java index aba7a1ab9..69bbef06c 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/awt/ScreenDriver.java @@ -110,6 +110,7 @@ public class ScreenDriver extends ScreenImpl { props[i++] = props.length; props[i++] = 0; // crt_idx props[i++] = 0; // is-clone + props[i++] = 1; // is-primary props[i++] = ScreenImpl.default_sm_widthmm; // FIXME props[i++] = ScreenImpl.default_sm_heightmm; // FIXME props[i++] = 0; // rotated viewport x pixel-units diff --git a/src/newt/classes/jogamp/newt/driver/bcm/egl/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/bcm/egl/ScreenDriver.java index 704fad73f..9c68c1528 100644 --- a/src/newt/classes/jogamp/newt/driver/bcm/egl/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/bcm/egl/ScreenDriver.java @@ -85,6 +85,7 @@ public class ScreenDriver extends jogamp.newt.ScreenImpl { props[i++] = props.length; props[i++] = 0; // crt_idx props[i++] = 0; // is-clone + props[i++] = 1; // is-primary props[i++] = ScreenImpl.default_sm_widthmm; // FIXME props[i++] = ScreenImpl.default_sm_heightmm; // FIXME props[i++] = 0; // rotated viewport x pixel-units diff --git a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/ScreenDriver.java index 8d46adeab..f236edd6b 100644 --- a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/ScreenDriver.java @@ -78,6 +78,7 @@ public class ScreenDriver extends ScreenImpl { props[i++] = props.length; props[i++] = 0; // crt_idx props[i++] = 0; // is-clone + props[i++] = 1; // is-primary props[i++] = ScreenImpl.default_sm_widthmm; // FIXME props[i++] = ScreenImpl.default_sm_heightmm; // FIXME props[i++] = 0; // rotated viewport x pixel-units diff --git a/src/newt/classes/jogamp/newt/driver/intel/gdl/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/intel/gdl/ScreenDriver.java index b55378459..5c29c4e37 100644 --- a/src/newt/classes/jogamp/newt/driver/intel/gdl/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/intel/gdl/ScreenDriver.java @@ -87,6 +87,7 @@ public class ScreenDriver extends jogamp.newt.ScreenImpl { props[i++] = props.length; props[i++] = 0; // crt_idx props[i++] = 0; // is-clone + props[i++] = 1; // is-primary props[i++] = ScreenImpl.default_sm_widthmm; // FIXME props[i++] = ScreenImpl.default_sm_heightmm; // FIXME props[i++] = 0; // rotated viewport x pixel-units diff --git a/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java index 1e878bc3a..328523ad4 100644 --- a/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java @@ -83,6 +83,7 @@ public class ScreenDriver extends ScreenImpl { props[i++] = props.length; props[i++] = 0; // crt_idx props[i++] = 0; // is-clone + props[i++] = 1; // is-primary props[i++] = ScreenImpl.default_sm_widthmm; // FIXME props[i++] = ScreenImpl.default_sm_heightmm; // FIXME props[i++] = 0; // rotated viewport x pixel-units diff --git a/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java index 013f9f9ca..ea3e76eb3 100644 --- a/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java @@ -119,7 +119,7 @@ public class ScreenDriver extends ScreenImpl { // has at least one mode -> add device final MonitorMode currentMode = getMonitorModeImpl(cache, adapterName, -1); if ( null != currentMode ) { // enabled - final int[] monitorProps = getMonitorDevice0(adapterName, adapterIdx, monitorIdx, getMonitorId(adapterIdx, monitorIdx)); + final int[] monitorProps = getMonitorDevice0(adapterIdx, monitorIdx, getMonitorId(adapterIdx, monitorIdx)); // merge monitor-props + supported modes MonitorModeProps.streamInMonitorDevice(cache, this, currentMode, null, supportedModes, monitorProps, 0, null); @@ -139,7 +139,7 @@ public class ScreenDriver extends ScreenImpl { final String adapterName = getAdapterName(adapterIdx); if( null != adapterName ) { if( null != getMonitorName(adapterName, monitorIdx, true) ) { - final int[] monitorProps = getMonitorDevice0(adapterName, adapterIdx, monitorIdx, getMonitorId(adapterIdx, monitorIdx)); + final int[] monitorProps = getMonitorDevice0(adapterIdx, monitorIdx, getMonitorId(adapterIdx, monitorIdx)); int offset = MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT; viewportPU.set(monitorProps[offset++], monitorProps[offset++], monitorProps[offset++], monitorProps[offset++]); viewportWU.set(monitorProps[offset++], monitorProps[offset++], monitorProps[offset++], monitorProps[offset++]); @@ -187,6 +187,6 @@ public class ScreenDriver extends ScreenImpl { private native String getAdapterName0(int adapter_idx); private native String getMonitorName0(String adapterName, int monitor_idx, boolean onlyActive); private native int[] getMonitorMode0(String adapterName, int mode_idx); - private native int[] getMonitorDevice0(String adapterName, int adapter_idx, int monitor_idx, int monitorId); + private native int[] getMonitorDevice0(int adapter_idx, int monitor_idx, int monitorId); private native boolean setMonitorMode0(int adapter_idx, int x, int y, int width, int height, int bits, int freq, int flags, int rot); } diff --git a/src/newt/classes/jogamp/newt/driver/x11/RandR11.java b/src/newt/classes/jogamp/newt/driver/x11/RandR11.java index a4c578b26..e9cb95548 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/RandR11.java +++ b/src/newt/classes/jogamp/newt/driver/x11/RandR11.java @@ -187,6 +187,7 @@ class RandR11 implements RandR { props[i++] = props.length; props[i++] = crt_idx; props[i++] = 0; // is-clone + props[i++] = 0 == crt_idx ? 1 : 0; // is-primary props[i++] = widthMM; props[i++] = heightMM; props[i++] = 0; // rotated viewport x pixel-units diff --git a/src/newt/classes/jogamp/newt/driver/x11/RandR13.java b/src/newt/classes/jogamp/newt/driver/x11/RandR13.java index b6d8f13a1..2f7110b5c 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/RandR13.java +++ b/src/newt/classes/jogamp/newt/driver/x11/RandR13.java @@ -247,7 +247,6 @@ class RandR13 implements RandR { try { setScreenViewport0(dpy, screen_idx, screenResources, viewport.getX(), viewport.getY(), viewport.getWidth(), viewport.getHeight()); } finally { - dumpInfo0(dpy, screen_idx, screenResources); releaseScreenResourceHandle(screenResources); } } -- cgit v1.2.3