diff options
author | Sven Gothel <[email protected]> | 2023-01-29 19:56:45 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-01-29 19:56:45 +0100 |
commit | e96aeb6e9acd2b1435f5fad244a1488e74a3a6d6 (patch) | |
tree | 68a4466d97b006e63f12040ff2db0a24d263344c /src | |
parent | 516d3d57eb54f6fe95d842d29a2929e024ee8f34 (diff) |
GDIUtil: Add GetMonitor*() variants incl. PixelScale; NEWT MonitorDevice: Add 64-bit nativeHandle (Windows HMONITOR), add PixelScale for Windows
Diffstat (limited to 'src')
19 files changed, 184 insertions, 59 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java b/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java index c0f277f09..9201c9881 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java @@ -28,6 +28,7 @@ package jogamp.nativewindow.windows; import com.jogamp.nativewindow.util.Point; +import com.jogamp.nativewindow.util.Rectangle; import com.jogamp.nativewindow.NativeWindowException; import com.jogamp.nativewindow.NativeWindowFactory; @@ -233,6 +234,27 @@ public class GDIUtil implements ToolkitProperties { return IsChild0(win); } + public static long GetMonitorFromWindow(final long windowHandle) { + return GDI.GetMonitorFromWindow(windowHandle); + } + public static long GetMonitorFromPoint(final int x, final int y) { + return GDI.GetMonitorFromPoint(x, y); + } + public static long GetMonitorFromRect(final int x_left, final int y_top, final int width, final int height) { + return GDI.GetMonitorFromRect(x_left, y_top, x_left + width - 1 /* right */, y_top + height - 1 /* bottom */); + } + public static long GetMonitorFromRect(final Rectangle rect) { + return GetMonitorFromRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); + } + + public static boolean GetMonitorPixelScale(final long hmon, final float[] pixel_scale_xy) { + return GDI.ShcGetMonitorPixelScale1(hmon, pixel_scale_xy, 0); + } + /** + public static boolean GetMonitorPixelScale(final int x, final int y, final float[] pixel_scale_xy) { + return GDI.ShcGetMonitorPixelScale2(x, y, pixel_scale_xy, 0); + } */ + public static void SetProcessThreadsAffinityMask(final long affinityMask, final boolean verbose) { SetProcessThreadsAffinityMask0(affinityMask, verbose); } diff --git a/src/newt/classes/com/jogamp/newt/MonitorDevice.java b/src/newt/classes/com/jogamp/newt/MonitorDevice.java index e96fc82f5..584b83505 100644 --- a/src/newt/classes/com/jogamp/newt/MonitorDevice.java +++ b/src/newt/classes/com/jogamp/newt/MonitorDevice.java @@ -60,7 +60,8 @@ import com.jogamp.common.util.ArrayHashSet; */ public abstract class MonitorDevice { protected final Screen screen; // backref - protected final int nativeId; // unique monitor device ID + protected final long nativeHandle; // unique monitor device long handle, implementation specific + protected final int nativeId; // unique monitor device integer Id, implementation specific protected final DimensionImmutable sizeMM; // in [mm] protected final MonitorMode originalMode; protected final ArrayHashSet<MonitorMode> supportedModes; // FIXME: May need to support mutable mode, i.e. adding modes on the fly! @@ -74,7 +75,8 @@ public abstract class MonitorDevice { /** * @param screen associated {@link Screen} - * @param nativeId unique monitor device ID + * @param nativeHandle unique monitor device long handle, implementation specific + * @param nativeId unique monitor device integer Id, implementation specific * @param isClone flag * @param isPrimary flag * @param sizeMM size in millimeters @@ -84,16 +86,17 @@ public abstract class MonitorDevice { * @param viewportWU viewport in window-units * @param supportedModes all supported {@link MonitorMode}s */ - protected MonitorDevice(final Screen screen, final int nativeId, + protected MonitorDevice(final Screen screen, final long nativeHandle, 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<MonitorMode> supportedModes) { this.screen = screen; + this.nativeHandle = nativeHandle; this.nativeId = nativeId; this.sizeMM = sizeMM; this.originalMode = currentMode; this.supportedModes = supportedModes; - this.pixelScale = null != pixelScale ? pixelScale : new float[] { 1.0f, 1.0f }; + this.pixelScale = null != pixelScale ? pixelScale : new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; this.viewportPU = viewportPU; this.viewportWU = viewportWU; @@ -137,7 +140,10 @@ public abstract class MonitorDevice { return nativeId; } - /** @return the immutable unique native Id of this monitor device. */ + /** @return the immutable unique native long handle of this monitor device, implementation specific. */ + public final long getHandle() { return nativeHandle; } + + /** @return the immutable unique native integer Id of this monitor device, implementation specific. */ public final int getId() { return nativeId; } /** @return {@code true} if this device represents a <i>clone</i>, otherwise return {@code false}. */ @@ -345,7 +351,14 @@ public abstract class MonitorDevice { final StringBuilder sb = new StringBuilder(); sb.append("Monitor[Id ").append(Display.toHexString(nativeId)).append(" ["); { + if( nativeHandle != nativeId ) { + sb.append("handle ").append(Display.toHexString(nativeHandle)); + preComma = true; + } if( isClone() ) { + if( preComma ) { + sb.append(", "); + } sb.append("clone"); preComma = true; } diff --git a/src/newt/classes/com/jogamp/newt/Screen.java b/src/newt/classes/com/jogamp/newt/Screen.java index 9b2a280f9..4c4faef8d 100644 --- a/src/newt/classes/com/jogamp/newt/Screen.java +++ b/src/newt/classes/com/jogamp/newt/Screen.java @@ -245,7 +245,7 @@ public abstract class Screen { return monitors.get(0); } - public final MonitorDevice getMonitor(final int monitorId) { + public final MonitorDevice getMonitorById(final int monitorId) { final List<MonitorDevice> monitors = getMonitorDevices(); final int monitorCount = monitors.size(); for(int i=0; i<monitorCount; i++) { @@ -257,6 +257,18 @@ public abstract class Screen { return null; } + public final MonitorDevice getMonitorByHandle(final long monitorHandle) { + final List<MonitorDevice> monitors = getMonitorDevices(); + final int monitorCount = monitors.size(); + for(int i=0; i<monitorCount; i++) { + final MonitorDevice monitor = monitors.get(i); + if( monitor.getHandle() == monitorHandle ) { + return monitor; + } + } + return null; + } + /** * Calculates the union of all monitor's {@link MonitorDevice#getViewport() viewport} in pixel- and window units. * <p> diff --git a/src/newt/classes/jogamp/newt/MonitorDeviceImpl.java b/src/newt/classes/jogamp/newt/MonitorDeviceImpl.java index 9f458d215..3e81d3877 100644 --- a/src/newt/classes/jogamp/newt/MonitorDeviceImpl.java +++ b/src/newt/classes/jogamp/newt/MonitorDeviceImpl.java @@ -40,7 +40,8 @@ public class MonitorDeviceImpl extends MonitorDevice { /** * @param screen associated {@link Screen} - * @param nativeId unique monitor device ID + * @param nativeHandle unique monitor device long handle, implementation specific + * @param nativeId unique monitor device integer Id, implementation specific * @param isClone flag * @param isPrimary flag * @param sizeMM size in millimeters @@ -50,11 +51,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, + public MonitorDeviceImpl(final ScreenImpl screen, final long nativeHandle, 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<MonitorMode> supportedModes) { - super(screen, nativeId, isClone, isPrimary, sizeMM, currentMode, pixelScale, viewportPU, viewportWU, supportedModes); + super(screen, nativeHandle, nativeId, isClone, isPrimary, sizeMM, currentMode, pixelScale, viewportPU, viewportWU, supportedModes); } @Override diff --git a/src/newt/classes/jogamp/newt/MonitorModeProps.java b/src/newt/classes/jogamp/newt/MonitorModeProps.java index eabb6be01..873ee3ed6 100644 --- a/src/newt/classes/jogamp/newt/MonitorModeProps.java +++ b/src/newt/classes/jogamp/newt/MonitorModeProps.java @@ -271,6 +271,7 @@ public class MonitorModeProps { * </p> * @param cache hash arrays of unique {@link MonitorMode} components and {@link MonitorDevice}s, allowing to avoid duplicates * @param screen the associated {@link ScreenImpl} + * @param monitor_handle unique monitor long handle, implementation specific * @param pixelScale pre-fetched current pixel-scale, maybe {@code null} for {@link ScalableSurface#IDENTITY_PIXELSCALE}. * @param monitorProperties the input data inclusive supported modes. * @param offset the offset to the input data @@ -279,9 +280,9 @@ public class MonitorModeProps { * matching the input <code>modeProperties</code>, or null if input could not be processed. */ public static MonitorDevice streamInMonitorDevice(final Cache cache, final ScreenImpl screen, - final float[] pixelScale, - final int[] monitorProperties, int offset, - final int[] monitor_idx) { + final long monitor_handle, + final float[] pixelScale, final int[] monitorProperties, + int offset, final int[] monitor_idx) { // min 11: count, id, ScreenSizeMM[width, height], Viewport[x, y, width, height], currentMonitorModeId, rotation, supportedModeId+ final int count = monitorProperties[offset]; if(MIN_MONITOR_DEVICE_PROPERTIES > count) { @@ -318,7 +319,7 @@ public class MonitorModeProps { } } } - MonitorDevice monitorDevice = new MonitorDeviceImpl(screen, id, isClone, isPrimary, + MonitorDevice monitorDevice = new MonitorDeviceImpl(screen, monitor_handle, id, isClone, isPrimary, sizeMM, currentMode, pixelScale, viewportPU, viewportWU, supportedModes); if(null!=cache) { @@ -356,6 +357,7 @@ public class MonitorModeProps { * </p> * @param cache hash arrays of unique {@link MonitorMode} components and {@link MonitorDevice}s, allowing to avoid duplicates * @param screen the associated {@link ScreenImpl} + * @param monitor_handle unique monitor long handle, implementation specific * @param currentMode pre-fetched current {@link MonitorMode}s from cache. * @param pixelScale pre-fetched current pixel-scale, maybe {@code null} for {@link ScalableSurface#IDENTITY_PIXELSCALE}. * @param supportedModes pre-assembled list of supported {@link MonitorMode}s from cache. @@ -366,6 +368,7 @@ public class MonitorModeProps { * matching the input <code>modeProperties</code>, or null if input could not be processed. */ public static MonitorDevice streamInMonitorDevice(final Cache cache, final ScreenImpl screen, + final long monitor_handle, final MonitorMode currentMode, final float[] pixelScale, final ArrayHashSet<MonitorMode> supportedModes, @@ -383,13 +386,13 @@ public class MonitorModeProps { throw new RuntimeException("properties array too short (count), should be >= "+count+", is "+(monitorProperties.length-offset)); } offset++; - final int id = monitorProperties[offset++]; + final int monitor_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, isPrimary, + MonitorDevice monitorDevice = new MonitorDeviceImpl(screen, monitor_handle, monitor_id, isClone, isPrimary, sizeMM, currentMode, pixelScale, viewportPU, viewportWU, supportedModes); if(null!=cache) { diff --git a/src/newt/classes/jogamp/newt/ScreenImpl.java b/src/newt/classes/jogamp/newt/ScreenImpl.java index 00bba64df..1dba31d4f 100644 --- a/src/newt/classes/jogamp/newt/ScreenImpl.java +++ b/src/newt/classes/jogamp/newt/ScreenImpl.java @@ -360,8 +360,8 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { * <li>{@link MonitorModeProps#MIN_MONITOR_DEVICE_PROPERTIES}</li> * </ul>, i.e. * <ul> - * <li>{@link MonitorModeProps#streamInMonitorDevice(jogamp.newt.MonitorModeProps.Cache, ScreenImpl, double[], int[], int, int[])}</li> - * <li>{@link MonitorModeProps#streamInMonitorDevice(int[], jogamp.newt.MonitorModeProps.Cache, ArrayHashSet, int[], int, ScreenImpl)}</li> + * <li>{@link MonitorModeProps#streamInMonitorDevice(jogamp.newt.MonitorModeProps.Cache, ScreenImpl, long, double[], int[], int, int[])}</li> + * <li>{@link MonitorModeProps#streamInMonitorDevice(int[], jogamp.newt.MonitorModeProps.Cache, long, ArrayHashSet, int[], int, ScreenImpl)}</li> * <li>{@link MonitorModeProps#streamInMonitorMode(int[], jogamp.newt.MonitorModeProps.Cache, int[], int)}</li> * </ul> * @param cache memory pool caching the result @@ -520,7 +520,7 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { if( MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES != i ) { throw new InternalError("XX"); } - return MonitorModeProps.streamInMonitorDevice(cache, this, null, props, 0, null); + return MonitorModeProps.streamInMonitorDevice(cache, this, monitorId, null, props, 0, null); } /** diff --git a/src/newt/classes/jogamp/newt/driver/android/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/android/ScreenDriver.java index a95b3d429..3c0b1aef4 100644 --- a/src/newt/classes/jogamp/newt/driver/android/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/android/ScreenDriver.java @@ -100,10 +100,11 @@ public class ScreenDriver extends jogamp.newt.ScreenImpl { } } + final int crt_id = 0; final int[] props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES - 1 - MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES]; int i = 0; props[i++] = props.length; - props[i++] = 0; // crt_idx + props[i++] = crt_id; props[i++] = 0; // is-clone props[i++] = 1; // is-primary i = getScreenSizeMM(outMetrics, props, i); // sizeMM @@ -115,7 +116,7 @@ public class ScreenDriver extends jogamp.newt.ScreenImpl { props[i++] = 0; // rotated viewport y window-units props[i++] = outMetrics.widthPixels; // rotated viewport width window-units props[i++] = outMetrics.heightPixels; // rotated viewport height window-units - MonitorModeProps.streamInMonitorDevice(cache, this, currentMode, null, cache.monitorModes, props, 0, null); + MonitorModeProps.streamInMonitorDevice(cache, this, crt_id, currentMode, null, cache.monitorModes, props, 0, null); } @Override diff --git a/src/newt/classes/jogamp/newt/driver/awt/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/awt/ScreenDriver.java index 69bbef06c..d577ed501 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/awt/ScreenDriver.java @@ -105,10 +105,11 @@ public class ScreenDriver extends ScreenImpl { } final MonitorMode currentMode = getModeProps(cache, awtGD.getDisplayMode()); + final int crt_id = 0; final int[] props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES - 1 - MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES]; int i = 0; props[i++] = props.length; - props[i++] = 0; // crt_idx + props[i++] = crt_id; props[i++] = 0; // is-clone props[i++] = 1; // is-primary props[i++] = ScreenImpl.default_sm_widthmm; // FIXME @@ -121,7 +122,7 @@ public class ScreenDriver extends ScreenImpl { props[i++] = 0; // rotated viewport y window-units props[i++] = currentMode.getRotatedWidth(); // rotated viewport width window-units props[i++] = currentMode.getRotatedHeight(); // rotated viewport height window-units - MonitorModeProps.streamInMonitorDevice(cache, this, currentMode, null, cache.monitorModes, props, 0, null); + MonitorModeProps.streamInMonitorDevice(cache, this, crt_id, currentMode, null, cache.monitorModes, props, 0, null); } @Override 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 9c68c1528..62dbd0c72 100644 --- a/src/newt/classes/jogamp/newt/driver/bcm/egl/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/bcm/egl/ScreenDriver.java @@ -80,10 +80,11 @@ public class ScreenDriver extends jogamp.newt.ScreenImpl { props[i++] = 0; // rotation final MonitorMode currentMode = MonitorModeProps.streamInMonitorMode(null, cache, props, 0); + final int crt_id = 0; props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES - 1 - MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES]; i = 0; props[i++] = props.length; - props[i++] = 0; // crt_idx + props[i++] = crt_id; props[i++] = 0; // is-clone props[i++] = 1; // is-primary props[i++] = ScreenImpl.default_sm_widthmm; // FIXME @@ -96,7 +97,7 @@ public class ScreenDriver extends jogamp.newt.ScreenImpl { props[i++] = 0; // rotated viewport y window-units props[i++] = fixedWidth; // FIXME rotated viewport width window-units props[i++] = fixedHeight; // FIXME rotated viewport height window-units - MonitorModeProps.streamInMonitorDevice(cache, this, currentMode, null, cache.monitorModes, props, 0, null); + MonitorModeProps.streamInMonitorDevice(cache, this, crt_id, currentMode, null, cache.monitorModes, props, 0, null); } @Override 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 b4af4045c..9e05e1002 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 @@ -73,10 +73,11 @@ public class ScreenDriver extends ScreenImpl { props[i++] = 0; // rotation final MonitorMode currentMode = MonitorModeProps.streamInMonitorMode(null, cache, props, 0); + final int crt_id = 0; props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES - 1 - MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES]; i = 0; props[i++] = props.length; - props[i++] = 0; // crt_idx + props[i++] = crt_id; props[i++] = 0; // is-clone props[i++] = 1; // is-primary props[i++] = ScreenImpl.default_sm_widthmm; // FIXME @@ -89,7 +90,7 @@ public class ScreenDriver extends ScreenImpl { props[i++] = 0; // rotated viewport y window-units props[i++] = cachedWidth; // rotated viewport width window-units props[i++] = cachedHeight; // rotated viewport height window-units - MonitorModeProps.streamInMonitorDevice(cache, this, currentMode, null, cache.monitorModes, props, 0, null); + MonitorModeProps.streamInMonitorDevice(cache, this, crt_id, currentMode, null, cache.monitorModes, props, 0, null); } @Override diff --git a/src/newt/classes/jogamp/newt/driver/egl/gbm/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/egl/gbm/ScreenDriver.java index eb0b93f3e..5281f0ddc 100644 --- a/src/newt/classes/jogamp/newt/driver/egl/gbm/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/egl/gbm/ScreenDriver.java @@ -112,10 +112,11 @@ public class ScreenDriver extends ScreenImpl { props[i++] = 0; // rotation final MonitorMode currentMode = MonitorModeProps.streamInMonitorMode(null, cache, props, 0); + final int crt_id = encoder[scridx].getCrtc_id(); props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES - 1 - MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES]; i = 0; props[i++] = props.length; - props[i++] = encoder[scridx].getCrtc_id(); // crt_id + props[i++] = crt_id; props[i++] = 0; // is-clone props[i++] = 1; // is-primary props[i++] = connectors[scridx].getMmWidth(); @@ -128,7 +129,7 @@ public class ScreenDriver extends ScreenImpl { props[i++] = 0; // rotated viewport y window-units props[i++] = mode[scridx].getHdisplay(); // rotated viewport width window-units props[i++] = mode[scridx].getVdisplay(); // rotated viewport height window-units - MonitorModeProps.streamInMonitorDevice(cache, this, currentMode, null, cache.monitorModes, props, 0, null); + MonitorModeProps.streamInMonitorDevice(cache, this, crt_id, currentMode, null, cache.monitorModes, props, 0, null); crtc_ids = new int[] { encoder[scridx].getCrtc_id() }; 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 5c29c4e37..ceb2c4cc6 100644 --- a/src/newt/classes/jogamp/newt/driver/intel/gdl/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/intel/gdl/ScreenDriver.java @@ -82,10 +82,11 @@ public class ScreenDriver extends jogamp.newt.ScreenImpl { props[i++] = 0; // rotation final MonitorMode currentMode = MonitorModeProps.streamInMonitorMode(null, cache, props, 0); + final int crt_id = 0; props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES - 1 - MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES]; i = 0; props[i++] = props.length; - props[i++] = 0; // crt_idx + props[i++] = crt_id; props[i++] = 0; // is-clone props[i++] = 1; // is-primary props[i++] = ScreenImpl.default_sm_widthmm; // FIXME @@ -98,7 +99,7 @@ public class ScreenDriver extends jogamp.newt.ScreenImpl { props[i++] = 0; // rotated viewport y window-units props[i++] = cachedWidth; // rotated viewport width window-units props[i++] = cachedWidth; // rotated viewport height window-units - MonitorModeProps.streamInMonitorDevice(cache, this, currentMode, null, cache.monitorModes, props, 0, null); + MonitorModeProps.streamInMonitorDevice(cache, this, crt_id, currentMode, null, cache.monitorModes, props, 0, null); } @Override diff --git a/src/newt/classes/jogamp/newt/driver/ios/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/ios/ScreenDriver.java index daa033edb..de5cdd239 100644 --- a/src/newt/classes/jogamp/newt/driver/ios/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/ios/ScreenDriver.java @@ -176,9 +176,8 @@ public class ScreenDriver extends ScreenImpl { } // merge monitor-props + supported modes final float pixelScale = crtProps.pixelScaleArray[crtIdx]; - MonitorModeProps.streamInMonitorDevice(cache, this, currentMode, - new float[] { pixelScale, pixelScale }, - supportedModes, crtProps.propsFixedArray[crtIdx], 0, null); + MonitorModeProps.streamInMonitorDevice(cache, this, crt_id, currentMode, + new float[] { pixelScale, pixelScale }, supportedModes, crtProps.propsFixedArray[crtIdx], 0, null); } } diff --git a/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java index 328523ad4..3112aa88f 100644 --- a/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java @@ -78,10 +78,11 @@ public class ScreenDriver extends ScreenImpl { props[i++] = 0; // rotation final MonitorMode currentMode = MonitorModeProps.streamInMonitorMode(null, cache, props, 0); + final int crt_id = 0; props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES - 1 - MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES]; i = 0; props[i++] = props.length; - props[i++] = 0; // crt_idx + props[i++] = crt_id; props[i++] = 0; // is-clone props[i++] = 1; // is-primary props[i++] = ScreenImpl.default_sm_widthmm; // FIXME @@ -94,7 +95,7 @@ public class ScreenDriver extends ScreenImpl { props[i++] = 0; // rotated viewport y window-units props[i++] = cachedWidth; // rotated viewport width window-units props[i++] = cachedWidth; // rotated viewport height window-units - MonitorModeProps.streamInMonitorDevice(cache, this, currentMode, null, cache.monitorModes, props, 0, null); + MonitorModeProps.streamInMonitorDevice(cache, this, crt_id, currentMode, null, cache.monitorModes, props, 0, null); } @Override diff --git a/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java index 590f706df..a4823034f 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java @@ -109,8 +109,8 @@ public class ScreenDriver extends ScreenImpl { final int x = thisMonitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+0]; final int y = thisMonitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+1]; final float thisPixelScale = pixelScaleArray[crtIdx]; - thisMonitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+2] *= thisPixelScale; // fix width - thisMonitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+3] *= thisPixelScale; // fix height + thisMonitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+2] *= thisPixelScale; // fix width in pixel + thisMonitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+3] *= thisPixelScale; // fix height in pixel if( 0 != x ) { // find matching viewport width for x-offset to apply it's pixelSize for(int i=0; i<count; i++) { @@ -182,9 +182,8 @@ public class ScreenDriver extends ScreenImpl { } // merge monitor-props + supported modes final float pixelScale = crtProps.pixelScaleArray[crtIdx]; - MonitorModeProps.streamInMonitorDevice(cache, this, currentMode, - new float[] { pixelScale, pixelScale }, - supportedModes, crtProps.propsFixedArray[crtIdx], 0, null); + MonitorModeProps.streamInMonitorDevice(cache, this, crt_id, currentMode, + new float[] { pixelScale, pixelScale }, supportedModes, crtProps.propsFixedArray[crtIdx], 0, null); } } diff --git a/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java index dfdb8b155..002836e0c 100644 --- a/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java @@ -34,8 +34,10 @@ package jogamp.newt.driver.windows; import com.jogamp.nativewindow.DefaultGraphicsScreen; +import com.jogamp.nativewindow.ScalableSurface; import com.jogamp.nativewindow.util.Rectangle; +import jogamp.nativewindow.windows.GDIUtil; import jogamp.newt.MonitorModeProps; import jogamp.newt.ScreenImpl; @@ -71,6 +73,9 @@ public class ScreenDriver extends ScreenImpl { private final String getMonitorName(final String adapterName, final int monitor_idx, final boolean onlyActive) { return getMonitorName0(adapterName, monitor_idx, onlyActive); } + private final String getMonitorName(final long hmon) { + return getMonitorName1(hmon); + } private final MonitorMode getMonitorModeImpl(final MonitorModeProps.Cache cache, final String adapterName, final int mode_idx) { if( null == adapterName ) { @@ -120,12 +125,31 @@ 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(adapterIdx, monitorIdx, getMonitorId(adapterIdx, monitorIdx)); - // merge monitor-props + supported modes - MonitorModeProps.streamInMonitorDevice(cache, this, currentMode, null, supportedModes, monitorProps, 0, null); - - // next monitor, 1st mode - supportedModes = new ArrayHashSet<MonitorMode>(false, ArrayHashSet.DEFAULT_INITIAL_CAPACITY, ArrayHashSet.DEFAULT_LOAD_FACTOR); + final int monitor_id = getMonitorId(adapterIdx, monitorIdx); + final float pixel_scale[] = { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; + final int[] monitorProps = getMonitorDevice0(adapterIdx, monitorIdx, monitor_id); + if( null != monitorProps && monitorProps.length >= MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT + 4 ) { + final int v_left = monitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+0]; + final int v_top = monitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+1]; + final int v_width = monitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+2]; + final int v_height = monitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+3]; + long monitor_handle = GDIUtil.GetMonitorFromRect(v_left, v_top, v_width, v_height); + if( 0 != monitor_handle ) { + final float pixel_scale_raw[] = new float[2]; + if( GDIUtil.GetMonitorPixelScale(monitor_handle, pixel_scale_raw) ) { + System.arraycopy(pixel_scale_raw, 0, pixel_scale, 0, 2); + } + } else { + monitor_handle = monitor_id; + } + // merge monitor-props + supported modes + MonitorModeProps.streamInMonitorDevice(cache, this, monitor_handle, currentMode, pixel_scale, supportedModes, monitorProps, 0, null); + + // next monitor, 1st mode + supportedModes = new ArrayHashSet<MonitorMode>(false, ArrayHashSet.DEFAULT_INITIAL_CAPACITY, ArrayHashSet.DEFAULT_LOAD_FACTOR); + } else { + throw new RuntimeException("monitorProps length should be > "+(MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+4)+", but is "+(monitorProps.length)); + } } } } @@ -187,6 +211,7 @@ public class ScreenDriver extends ScreenImpl { private static native void dumpMonitorInfo0(); private native String getAdapterName0(int adapter_idx); private native String getMonitorName0(String adapterName, int monitor_idx, boolean onlyActive); + private native String getMonitorName1(long hmon); private native int[] getMonitorMode0(String adapterName, int mode_idx); 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/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java index 873ee3f53..7fb70cc32 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java @@ -150,11 +150,12 @@ public class ScreenDriver extends ScreenImpl { } if( cache.monitorModes.size() > 0 ) { for(int i = 0; i < crtCount; i++) { - final int[] monitorProps = rAndR.getMonitorDeviceProps(device.getHandle(), this, cache, crt_ids[i]); + final int crt_id = crt_ids[i]; + final int[] monitorProps = rAndR.getMonitorDeviceProps(device.getHandle(), this, cache, crt_id); if( null != monitorProps && MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES <= monitorProps[0] && // Enabled ? I.e. contains active modes ? MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES <= monitorProps.length ) { - MonitorModeProps.streamInMonitorDevice(cache, this, null, monitorProps, 0, null); + MonitorModeProps.streamInMonitorDevice(cache, this, crt_id, null, monitorProps, 0, null); } } } diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index 1074dad6f..2423275da 100644 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -1767,15 +1767,15 @@ static LPCTSTR NewtScreen_getAdapterName(DISPLAY_DEVICE * device, int adapter_id return device->DeviceName; } -static LPCTSTR NewtScreen_getMonitorName(LPCTSTR adapterName, DISPLAY_DEVICE * device, int monitor_idx, BOOL onlyActive) { +static LPCTSTR NewtScreen_getMonitorName0(LPCTSTR adapterName, DISPLAY_DEVICE * device, int monitor_idx, BOOL onlyActive) { if( 0 > monitor_idx ) { - DBG_PRINT("*** WindowsWindow: getMonitorName(monitor_idx %d < 0)\n", monitor_idx); + DBG_PRINT("*** WindowsWindow: getMonitorName0(monitor_idx %d < 0)\n", monitor_idx); return NULL; } memset(device, 0, sizeof(DISPLAY_DEVICE)); device->cb = sizeof(DISPLAY_DEVICE); if( FALSE == EnumDisplayDevices(adapterName, monitor_idx, device, EDD_GET_DEVICE_INTERFACE_NAME) ) { - DBG_PRINT("*** WindowsWindow: getMonitorName.EnumDisplayDevices(monitor_idx %d).adapter -> FALSE\n", monitor_idx); + DBG_PRINT("*** WindowsWindow: getMonitorName0.EnumDisplayDevices(monitor_idx %d).adapter -> FALSE\n", monitor_idx); return NULL; } if( onlyActive ) { @@ -1791,6 +1791,24 @@ static LPCTSTR NewtScreen_getMonitorName(LPCTSTR adapterName, DISPLAY_DEVICE * d return device->DeviceName; } +static LPCTSTR NewtScreen_getMonitorName1(HMONITOR hmon, MONITORINFOEXA * info) { + if( 0 == hmon ) { + DBG_PRINT("*** WindowsWindow: getMonitorName1(hmon %p < 0)\n", (void*)hmon); + return NULL; + } + memset(info, 0, sizeof(MONITORINFOEXA)); + info->cbSize = sizeof(MONITORINFOEXA); + if( FALSE == GetMonitorInfo(hmon, info) ) { + DBG_PRINT("*** WindowsWindow: getMonitorName1.GetMonitorInfo(hmon %p) -> FALSE\n", (void*)hmon); + return NULL; + } + if( NULL == info->DszDeviceeviceName || 0 == _tcslen(device->DeviceName) ) { + return NULL; + } + + return info->szDevice; +} + static int NewtScreen_getFirstActiveNonCloneMonitor(LPCTSTR adapterName, DISPLAY_DEVICE * device) { memset(device, 0, sizeof(DISPLAY_DEVICE)); device->cb = sizeof(DISPLAY_DEVICE); @@ -1822,7 +1840,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_windows_ScreenDriver_dumpMonitorI STD_PRINT(" deviceString <%s> \n", aDevice.DeviceString); STD_PRINT(" deviceID <%s> \n", aDevice.DeviceID); j=0; - while(NULL != (dName = NewtScreen_getMonitorName(aName, &dDevice, j, FALSE))) { + while(NULL != (dName = NewtScreen_getMonitorName0(aName, &dDevice, j, FALSE))) { STD_PRINT("*** [%02d:%02d]: deviceName <%s> flags 0x%X active %d, mirror %d\n", i, j, dDevice.DeviceName, dDevice.StateFlags, 0 != ( dDevice.StateFlags & DISPLAY_DEVICE_ACTIVE ), @@ -1873,13 +1891,13 @@ JNIEXPORT jstring JNICALL Java_jogamp_newt_driver_windows_ScreenDriver_getMonito LPCTSTR monitorName; #ifdef UNICODE LPCTSTR adapterName = NewtCommon_GetNullTerminatedStringChars(env, jAdapterName); - monitorName = NewtScreen_getMonitorName(adapterName, &device, monitor_idx, onlyActive); - DBG_PRINT("*** WindowsWindow: getMonitorName(%s, monitor_idx %d) -> %s\n", adapterName, monitor_idx, (NULL==monitorName?"nil":monitorName)); + monitorName = NewtScreen_getMonitorName0(adapterName, &device, monitor_idx, onlyActive); + DBG_PRINT("*** WindowsWindow: getMonitorName0(%s, monitor_idx %d) -> %s\n", adapterName, monitor_idx, (NULL==monitorName?"nil":monitorName)); free((void*) adapterName); #else LPCTSTR adapterName = (*env)->GetStringUTFChars(env, jAdapterName, NULL); - monitorName = NewtScreen_getMonitorName(adapterName, &device, monitor_idx, onlyActive); - DBG_PRINT("*** WindowsWindow: getMonitorName(%s, monitor_idx %d) -> %s\n", adapterName, monitor_idx, (NULL==monitorName?"nil":monitorName)); + monitorName = NewtScreen_getMonitorName0(adapterName, &device, monitor_idx, onlyActive); + DBG_PRINT("*** WindowsWindow: getMonitorName0(%s, monitor_idx %d) -> %s\n", adapterName, monitor_idx, (NULL==monitorName?"nil":monitorName)); (*env)->ReleaseStringUTFChars(env, jAdapterName, adapterName); #endif if(NULL == monitorName) { @@ -1894,6 +1912,28 @@ JNIEXPORT jstring JNICALL Java_jogamp_newt_driver_windows_ScreenDriver_getMonito /* * Class: jogamp_newt_driver_windows_ScreenDriver + * Method: getMonitorName1 + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_jogamp_newt_driver_windows_ScreenDriver_getMonitorName1 + (JNIEnv *env, jobject obj, long jhmon) +{ + HMONITOR hmon = (HMONITOR) (intptr_t) jhmon; + MONITORINFOEXA info; + LPCTSTR monitorName = NewtScreen_getMonitorName1(hmon, &info); + DBG_PRINT("*** WindowsWindow: getMonitorName1(hmon %p) -> %s\n", (void*)hmon, (NULL==monitorName?"nil":monitorName)); + if(NULL == monitorName) { + return NULL; + } +#ifdef UNICODE + return (*env)->NewString(env, monitorName, wcslen(monitorName)); +#else + return (*env)->NewStringUTF(env, monitorName); +#endif +} + +/* + * Class: jogamp_newt_driver_windows_ScreenDriver * Method: getMonitorMode0 * Signature: (Ljava/lang/String;I)[I */ @@ -1987,7 +2027,7 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_windows_ScreenDriver_getMoni DBG_PRINT("*** WindowsWindow: adapter[name %s, idx %d], monitor[idx %d, id %d], EDID-avail %d\n", adapterName, adapter_idx, monitor_idx, monitor_id, NewtEDID_avail); - monitorName = NewtScreen_getMonitorName(adapterName, &monitorDevice, monitor_idx, TRUE); + monitorName = NewtScreen_getMonitorName0(adapterName, &monitorDevice, monitor_idx, TRUE); if( NULL == monitorName ) { DBG_PRINT("ERROR WindowsWindow: monitor[idx %d]: NULL\n", monitor_idx); return (*env)->NewIntArray(env, 0); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00aNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00aNEWT.java index 5e7ac8644..fbca2e614 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00aNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00aNEWT.java @@ -108,18 +108,21 @@ public class TestScreenMode00aNEWT extends UITestCase { Assert.assertEquals(modeOut, modeIn); } + final long monitor_handle = -1; + final int monitor_id = -1; final DimensionImmutable sizeMM = new Dimension(50, 50); final Rectangle viewport = new Rectangle(0, 0, 1920, 1080); final ArrayHashSet<MonitorMode> supportedModes = new ArrayHashSet<MonitorMode>(false, ArrayHashSet.DEFAULT_INITIAL_CAPACITY, ArrayHashSet.DEFAULT_LOAD_FACTOR); supportedModes.add(modeOut); - final MonitorDevice monOut = new MonitorDeviceImpl(null, -1, false, true, sizeMM, modeOut, null, viewport, viewport, supportedModes); + final MonitorDevice monOut = new MonitorDeviceImpl(null, monitor_handle, monitor_id, false, true, sizeMM, modeOut, null, viewport, viewport, supportedModes); System.err.println("01 out : "+monOut); cache.monitorDevices.add(monOut); { final int[] props = MonitorModeProps.streamOutMonitorDevice(monOut); - final MonitorDevice monIn = MonitorModeProps.streamInMonitorDevice(cache, null, null, props, 0, null); + final MonitorDevice monIn = MonitorModeProps.streamInMonitorDevice(cache, null, monitor_handle, null, props, 0, null); System.err.println("01 in : "+monIn); + Assert.assertEquals(monOut.getHandle(), monIn.getHandle()); Assert.assertEquals(monOut.getId(), monIn.getId()); Assert.assertEquals(monOut.isClone(), monIn.isClone()); Assert.assertEquals(monOut.isPrimary(), monIn.isPrimary()); |