diff options
author | Sven Gothel <[email protected]> | 2015-03-21 04:37:39 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-03-21 04:37:39 +0100 |
commit | 7438540ee6604cf91e14f12da891834d4cd83cfe (patch) | |
tree | f08c7ebae83b406450b83c6b8f17c608ad1c7c48 | |
parent | 9a8ae7c79cb6a89626eeb6a9a00fc9e32f9c0a71 (diff) |
Bug 1148 - OSX MonitorDevice: Use unique and native deviceID instead of index
Adopt to bug 1147, commit 2c88b6dfd4eb7e2cd9a50fa48e08ecafc980931a.
Using the native unique deviceID makes monitor identification more robust.
This also allows us simplify
displayID -> NSScreen-idx -> MonitorDevice
into
displayID -> MonitorDevice
and to survive a primary monitor change.
9 files changed, 160 insertions, 153 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java index 93c3dbaf7..3b824cfe4 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java @@ -550,19 +550,18 @@ public class JAWTUtil { return jawtToolkitLock; } - public static final int getMonitorIndex(final GraphicsDevice device) { - int idx = -1; + public static final int getMonitorDisplayID(final GraphicsDevice device) { + int displayID = 0; 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); + displayID = ((Integer)res).intValue(); } } catch (final Throwable t) {} } - return idx; + return displayID; } /** diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java index a5970b87c..8ad089a56 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java @@ -107,17 +107,19 @@ 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); - } public static double GetPixelScaleByDisplayID(final int displayID) { - return GetPixelScale1(displayID); + if( 0 != displayID ) { + return GetPixelScale1(displayID); + } else { + return 1.0; // default + } } public static double GetPixelScale(final long windowOrView) { - return GetPixelScale2(windowOrView); + if( 0 != windowOrView ) { + return GetPixelScale2(windowOrView); + } else { + return 1.0; // default + } } public static long CreateNSWindow(final int x, final int y, final int width, final int height) { @@ -398,8 +400,6 @@ 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); private static native long CreateNSWindow0(int x, int y, int width, int height); diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m index 87494e946..919108db9 100644 --- a/src/nativewindow/native/macosx/OSXmisc.m +++ b/src/nativewindow/native/macosx/OSXmisc.m @@ -138,6 +138,9 @@ Java_jogamp_nativewindow_macosx_OSXUtil_isNSWindow0(JNIEnv *env, jclass _unused, } static CGDirectDisplayID OSXUtil_getCGDirectDisplayIDByNSScreen(NSScreen *screen) { + if( NULL == screen ) { + return (CGDirectDisplayID)0; + } // Mind: typedef uint32_t CGDirectDisplayID; NSDictionary * dict = [screen deviceDescription]; NSNumber * val = (NSNumber *) [dict objectForKey: @"NSScreenNumber"]; @@ -154,19 +157,7 @@ static NSScreen * OSXUtil_getNSScreenByCGDirectDisplayID(CGDirectDisplayID displ return screen; } } - 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; + return NULL; } /* @@ -275,52 +266,6 @@ 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 - */ -JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetPixelScale0 - (JNIEnv *env, jclass unused, jint screen_idx) -{ - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - - CGFloat pixelScale; - NSScreen *screen; - NSArray *screens = [NSScreen screens]; - if( screen_idx<0 || screen_idx>=[screens count] ) { - screen = NULL; - pixelScale = 1.0; - } else { - screen = (NSScreen *) [screens objectAtIndex: screen_idx]; - pixelScale = 1.0; // default -NS_DURING - // Available >= 10.7 - pixelScale = [screen backingScaleFactor]; // HiDPI scaling -NS_HANDLER -NS_ENDHANDLER - } - [pool release]; - - return (jdouble)pixelScale; -} - -/* - * Class: Java_jogamp_nativewindow_macosx_OSXUtil * Method: GetPixelScale1 * Signature: (I)D */ @@ -329,14 +274,15 @@ JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetPixelScale1 { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - CGFloat pixelScale; + CGFloat pixelScale = 1.0; // default NSScreen *screen = OSXUtil_getNSScreenByCGDirectDisplayID((CGDirectDisplayID)displayID); - pixelScale = 1.0; // default + if( NULL != screen ) { NS_DURING - // Available >= 10.7 - pixelScale = [screen backingScaleFactor]; // HiDPI scaling + // Available >= 10.7 + pixelScale = [screen backingScaleFactor]; // HiDPI scaling NS_HANDLER NS_ENDHANDLER + } [pool release]; return (jdouble)pixelScale; diff --git a/src/newt/classes/jogamp/newt/awt/NewtFactoryAWT.java b/src/newt/classes/jogamp/newt/awt/NewtFactoryAWT.java index 4faa5de9c..8eaca7c0e 100644 --- a/src/newt/classes/jogamp/newt/awt/NewtFactoryAWT.java +++ b/src/newt/classes/jogamp/newt/awt/NewtFactoryAWT.java @@ -180,7 +180,7 @@ public class NewtFactoryAWT extends NewtFactory { screen.addReference(); try { if( NativeWindowFactory.TYPE_MACOSX == nwt ) { - res = screen.getMonitor( JAWTUtil.getMonitorIndex( awtComp.getGraphicsConfiguration().getDevice() ) ); + res = screen.getMonitor( JAWTUtil.getMonitorDisplayID( awtComp.getGraphicsConfiguration().getDevice() ) ); } if( null == res ) { // Fallback, use AWT component coverage diff --git a/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java index f493bdc95..1389692fc 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java @@ -42,6 +42,7 @@ import jogamp.newt.MonitorModeProps; import jogamp.newt.ScreenImpl; import com.jogamp.common.util.ArrayHashSet; +import com.jogamp.newt.Display; import com.jogamp.newt.MonitorDevice; import com.jogamp.newt.MonitorMode; import com.jogamp.opengl.math.FloatUtil; @@ -63,8 +64,8 @@ public class ScreenDriver extends ScreenImpl { @Override protected void closeNativeImpl() { } - private MonitorMode getMonitorModeImpl(final MonitorModeProps.Cache cache, final int crt_idx, final int mode_idx) { - final int[] modeProps = getMonitorMode0(crt_idx, mode_idx); + private MonitorMode getMonitorModeImpl(final MonitorModeProps.Cache cache, final int crt_id, final int mode_idx) { + final int[] modeProps = getMonitorMode0(crt_id, mode_idx); final MonitorMode res; if (null == modeProps || 0 >= modeProps.length) { res = null; @@ -74,9 +75,10 @@ public class ScreenDriver extends ScreenImpl { return res; } - private class CrtProps { + class CrtProps { CrtProps() { - count = getMonitorCount0(); + crtIDs = getMonitorDeviceIds0(); + count = crtIDs.length; pixelScaleArray = new float[count]; propsOrigArray = new int[count][]; propsFixedArray = new int[count][]; @@ -85,11 +87,12 @@ public class ScreenDriver extends ScreenImpl { // Gather whole topology of monitors (NSScreens) // for(int crtIdx=0; crtIdx<count; crtIdx++) { - final float pixelScaleRaw = (float)OSXUtil.GetPixelScaleByScreenIdx(crtIdx); + final int crt_id = crtIDs[crtIdx]; + final float pixelScaleRaw = (float)OSXUtil.GetPixelScaleByDisplayID(crt_id); pixelScaleArray[crtIdx] = FloatUtil.isZero(pixelScaleRaw, FloatUtil.EPSILON) ? 1.0f : pixelScaleRaw; - propsOrigArray[crtIdx] = getMonitorProps0(crtIdx); + propsOrigArray[crtIdx] = getMonitorProps0(crt_id); if ( null == propsOrigArray[crtIdx] ) { - throw new InternalError("Could not gather device props "+crtIdx+"/"+count); + throw new InternalError("Could not gather device props "+crtIdx+"/"+count+" -> "+Display.toHexString(crt_id)); } // copy orig -> fixed final int propsLen = propsOrigArray[crtIdx].length; @@ -128,7 +131,16 @@ public class ScreenDriver extends ScreenImpl { } } } + int getIndex(final int crt_id) { + for(int i=0; i<count; i++) { + if( crt_id == crtIDs[i] ) { + return i; + } + } + return -1; + } final int count; + final int[] crtIDs; final float[] pixelScaleArray; final int[][] propsOrigArray; final int[][] propsFixedArray; @@ -142,13 +154,14 @@ public class ScreenDriver extends ScreenImpl { // Collect all monitorModes for all monitorDevices // for(int crtIdx=0; crtIdx<crtProps.count; crtIdx++) { + final int crt_id = crtProps.crtIDs[crtIdx]; final ArrayHashSet<MonitorMode> supportedModes = new ArrayHashSet<MonitorMode>(); int modeIdx = 0; { // Get all supported modes for this monitorDevice MonitorMode mode; while( true ) { - mode = getMonitorModeImpl(cache, crtIdx, modeIdx); + mode = getMonitorModeImpl(cache, crt_id, modeIdx); if( null != mode ) { if( mode.getSurfaceSize().getBitsPerPixel() >= 24 ) { // drop otherwise supportedModes.getOrAdd(mode); @@ -160,11 +173,11 @@ public class ScreenDriver extends ScreenImpl { } } if( 0 >= modeIdx ) { - throw new InternalError("Could not gather single mode of device "+crtIdx+"/"+crtProps.count); + throw new InternalError("Could not gather single mode of device "+crtIdx+"/"+crtProps.count+" -> "+Display.toHexString(crt_id)); } - final MonitorMode currentMode = getMonitorModeImpl(cache, crtIdx, -1); + final MonitorMode currentMode = getMonitorModeImpl(cache, crt_id, -1); if ( null == currentMode ) { - throw new InternalError("Could not gather current mode of device "+crtIdx+"/"+crtProps.count+", but gathered "+modeIdx+" modes"); + throw new InternalError("Could not gather current mode of device "+crtIdx+"/"+crtProps.count+" -> "+Display.toHexString(crt_id)+", but gathered "+modeIdx+" modes"); } // merge monitor-props + supported modes final float pixelScale = crtProps.pixelScaleArray[crtIdx]; @@ -177,15 +190,19 @@ public class ScreenDriver extends ScreenImpl { @Override protected boolean updateNativeMonitorDeviceViewportImpl(final MonitorDevice monitor, final float[] pixelScale, final Rectangle viewportPU, final Rectangle viewportWU) { final CrtProps crtProps = new CrtProps(); - final int crtIdx = monitor.getId(); - if( 0 > crtIdx || crtIdx >= crtProps.count ) { - throw new IndexOutOfBoundsException("monitor id "+crtIdx+" not withon [0.."+(crtProps.count-1)+"]"); + final int crt_id = monitor.getId(); + if( 0 == crt_id ) { + throw new IllegalArgumentException("Invalid monitor id "+Display.toHexString(crt_id)); + } + final int crt_idx = crtProps.getIndex(crt_id); + if( 0 > crt_idx || crt_idx >= crtProps.count ) { + throw new IndexOutOfBoundsException("monitor id "+crt_idx+" not within [0.."+(crtProps.count-1)+"]"); } - final int[] fixedMonitorProps = crtProps.propsFixedArray[crtIdx]; + final int[] fixedMonitorProps = crtProps.propsFixedArray[crt_idx]; int offset = MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT; viewportPU.set(fixedMonitorProps[offset++], fixedMonitorProps[offset++], fixedMonitorProps[offset++], fixedMonitorProps[offset++]); viewportWU.set(fixedMonitorProps[offset++], fixedMonitorProps[offset++], fixedMonitorProps[offset++], fixedMonitorProps[offset++]); - final float _pixelScale = crtProps.pixelScaleArray[crtIdx]; + final float _pixelScale = crtProps.pixelScaleArray[crt_idx]; pixelScale[0] = _pixelScale; pixelScale[1] = _pixelScale; return true; @@ -206,8 +223,8 @@ public class ScreenDriver extends ScreenImpl { return 0; // big-desktop w/ multiple monitor attached, only one screen available } - private native int getMonitorCount0(); - private native int[] getMonitorProps0(int crt_idx); - private native int[] getMonitorMode0(int crt_index, int mode_idx); - private native boolean setMonitorMode0(int crt_index, int nativeId, int rot); + private native int[] getMonitorDeviceIds0(); + private native int[] getMonitorProps0(int crt_id); + private native int[] getMonitorMode0(int crt_id, int mode_idx); + private native boolean setMonitorMode0(int crt_id, int nativeId, int rot); } diff --git a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java index 7f3a53626..d241545d5 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java @@ -96,8 +96,8 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl } } - private boolean updatePixelScaleByScreenIdx(final boolean sendEvent) { - final float maxPixelScaleRaw = (float) OSXUtil.GetPixelScaleByScreenIdx(getScreen().getIndex()); + private boolean updatePixelScaleByDisplayID(final boolean sendEvent) { + final float maxPixelScaleRaw = (float) OSXUtil.GetPixelScaleByDisplayID(getDisplayID()); if( DEBUG_IMPLEMENTATION ) { System.err.println("WindowDriver.updatePixelScale.1: "+hasPixelScale[0]+", "+maxPixelScaleRaw+" (max)"); } @@ -130,13 +130,13 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl @Override protected final void instantiationFinished() { - updatePixelScaleByScreenIdx(false /* sendEvent*/); + updatePixelScaleByDisplayID(false /* sendEvent*/); } @Override protected void setScreen(final ScreenImpl newScreen) { // never null ! super.setScreen(newScreen); - updatePixelScaleByScreenIdx(false /* sendEvent*/); // caller (reparent, ..) will send reshape event + updatePixelScaleByDisplayID(false /* sendEvent*/); // caller (reparent, ..) will send reshape event } @Override @@ -640,6 +640,16 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl super.enqueueKeyEvent(wait, eventType, modifiers, keyCode, keySym, keyChar); } + protected int getDisplayID() { + if( !isOffscreenInstance ) { + final long whandle = getWindowHandle(); + if(0 != whandle) { + return getDisplayID0(whandle); + } + } + return 0; + } + //---------------------------------------------------------------------- // Internals only // @@ -716,6 +726,7 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl /** Must be called on Main-Thread */ private native void initWindow0(long parentWindow, long window, int x, int y, int w, int h, float reqPixelScale, boolean opaque, boolean visible, long view); + private native int getDisplayID0(long window); private native void setPixelScale0(long window, long view, float reqPixelScale); private native boolean lockSurface0(long window, long view); private native boolean unlockSurface0(long window, long view); diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m index fbac6b37e..5593cd682 100644 --- a/src/newt/native/MacWindow.m +++ b/src/newt/native/MacWindow.m @@ -366,19 +366,15 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_DisplayDriver_destroyPoint [pool release]; } -NSScreen * NewtScreen_getNSScreenByIndex(int screen_idx, BOOL cap) { +#if 0 +static NSScreen * NewtScreen_getNSScreenByIndex(int screen_idx) { NSArray *screens = [NSScreen screens]; if( screen_idx<0 || screen_idx>=[screens count] ) { - if( cap ) { - screen_idx=0; - } else { - return NULL; - } + return NULL; } return (NSScreen *) [screens objectAtIndex: screen_idx]; } - -NSScreen * NewtScreen_getNSScreenByCoord(int x, int y) { +static NSScreen * NewtScreen_getNSScreenByCoord(int x, int y) { NSArray *screens = [NSScreen screens]; int i; for(i=[screens count]-1; i>=0; i--) { @@ -391,9 +387,9 @@ NSScreen * NewtScreen_getNSScreenByCoord(int x, int y) { return screen; } } - return (NSScreen *) [screens objectAtIndex: 0]; + return NULL; } - +#endif static void NewtScreen_dump() { #ifdef VERBOSE_ON NSArray *screens = [NSScreen screens]; @@ -420,12 +416,27 @@ NS_ENDHANDLER CGDirectDisplayID NewtScreen_getCGDirectDisplayIDByNSScreen(NSScreen *screen) { + if( NULL == screen ) { + return (CGDirectDisplayID)0; + } // Mind: typedef uint32_t CGDirectDisplayID; NSDictionary * dict = [screen deviceDescription]; NSNumber * val = (NSNumber *) [dict objectForKey: @"NSScreenNumber"]; // [NSNumber integerValue] returns NSInteger which is 32 or 64 bit native size return (CGDirectDisplayID) [val integerValue]; } +static NSScreen * NewtScreen_getNSScreenByCGDirectDisplayID(CGDirectDisplayID displayID) { + NSArray *screens = [NSScreen screens]; + int i; + for(i=[screens count]-1; i>=0; i--) { + NSScreen * screen = (NSScreen *) [screens objectAtIndex: i]; + CGDirectDisplayID dID = NewtScreen_getCGDirectDisplayIDByNSScreen(screen); + if( dID == displayID ) { + return screen; + } + } + return NULL; +} /** * Only in >= 10.6: @@ -453,16 +464,28 @@ static long GetDictionaryLong(CFDictionaryRef theDict, const void* key) /* * Class: jogamp_newt_driver_macosx_ScreenDriver - * Method: getMonitorCount0 + * Method: getMonitorDeviceIds0 * Signature: ()I */ -JNIEXPORT jint JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_getMonitorCount0 +JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_getMonitorDeviceIds0 (JNIEnv *env, jobject obj) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSArray *screens = [NSScreen screens]; + int count = [screens count]; + int32_t displayIDs[count]; + int i; + for(i=0; i<count; i++) { + NSScreen * screen = (NSScreen *) [screens objectAtIndex: i]; + displayIDs[i] = (int32_t)NewtScreen_getCGDirectDisplayIDByNSScreen(screen); + } + jintArray properties = (*env)->NewIntArray(env, count); + if (properties == NULL) { + NewtCommon_throwNewRuntimeException(env, "Could not allocate int array of size %d", count); + } + (*env)->SetIntArrayRegion(env, properties, 0, count, displayIDs); [pool release]; - return (jint) [screens count]; + return properties; } /* @@ -471,7 +494,7 @@ JNIEXPORT jint JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_getMonitorCou * Signature: (I)[I */ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_getMonitorProps0 - (JNIEnv *env, jobject obj, jint crt_idx) + (JNIEnv *env, jobject obj, jint crt_id) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -485,28 +508,31 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_getMonit timespec_now(&t1); timespec_subtract(&td, &t1, &t0); td_ms = timespec_milliseconds(&td); fprintf(stderr, "MacScreen_getMonitorProps0.1: %ld ms\n", td_ms); fflush(NULL); #endif - NSScreen *screen = NewtScreen_getNSScreenByIndex((int)crt_idx, false); + CGDirectDisplayID displayID = (CGDirectDisplayID)crt_id; + NSScreen *screen = NewtScreen_getNSScreenByCGDirectDisplayID(displayID); if( NULL == screen ) { [pool release]; return NULL; } - CGDirectDisplayID display = NewtScreen_getCGDirectDisplayIDByNSScreen(screen); + CGDirectDisplayID mainDisplayID = CGMainDisplayID(); + BOOL isPrimary = mainDisplayID == displayID; #ifdef DBG_PERF timespec_now(&t1); timespec_subtract(&td, &t1, &t0); td_ms = timespec_milliseconds(&td); fprintf(stderr, "MacScreen_getMonitorProps0.2: %ld ms\n", td_ms); fflush(NULL); #endif - CGSize sizeMM = CGDisplayScreenSize(display); + CGSize sizeMM = CGDisplayScreenSize(displayID); #ifdef DBG_PERF timespec_now(&t1); timespec_subtract(&td, &t1, &t0); td_ms = timespec_milliseconds(&td); fprintf(stderr, "MacScreen_getMonitorProps0.3: %ld ms\n", td_ms); fflush(NULL); #endif - CGRect dBounds = CGDisplayBounds (display); // origin top-left + CGRect dBounds = CGDisplayBounds (displayID); // origin top-left #ifdef VERBOSE_ON - BOOL usesGL = CGDisplayUsesOpenGLAcceleration(display); + BOOL usesGL = CGDisplayUsesOpenGLAcceleration(displayID); NSRect sFrame = [screen frame]; // origin bottom-left - DBG_PRINT( "getMonitorProps0: scrn %d, top-left displayBounds[%d/%d %dx%d], bottom-left screenFrame[%d/%d %dx%d], usesGL %d\n", (int)crt_idx, + DBG_PRINT( "getMonitorProps0: crt_id 0x%X (prim %d), top-left displayBounds[%d/%d %dx%d], bottom-left screenFrame[%d/%d %dx%d], usesGL %d\n", + (int)crt_id, isPrimary, (int)dBounds.origin.x, (int)dBounds.origin.y, (int)dBounds.size.width, (int)dBounds.size.height, (int)sFrame.origin.x, (int)sFrame.origin.y, (int)sFrame.size.width, (int)sFrame.size.height, (int)usesGL); @@ -516,9 +542,9 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_getMonit jint prop[ propCount ]; int offset = 0; prop[offset++] = propCount; - prop[offset++] = crt_idx; + prop[offset++] = crt_id; prop[offset++] = 0; // isClone - prop[offset++] = 0 == crt_idx ? 1 : 0; // isPrimary + prop[offset++] = isPrimary ? 1 : 0; // isPrimary prop[offset++] = (jint) sizeMM.width; prop[offset++] = (jint) sizeMM.height; prop[offset++] = (jint) dBounds.origin.x; // rotated viewport x (pixel units, will be fixed in java code) @@ -547,11 +573,12 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_getMonit * Signature: (II)[I */ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_getMonitorMode0 - (JNIEnv *env, jobject obj, jint crt_idx, jint mode_idx) + (JNIEnv *env, jobject obj, jint crt_id, jint mode_idx) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - NSScreen *screen = NewtScreen_getNSScreenByIndex((int)crt_idx, false); + CGDirectDisplayID displayID = (CGDirectDisplayID)crt_id; + NSScreen *screen = NewtScreen_getNSScreenByCGDirectDisplayID(displayID); if( NULL == screen ) { [pool release]; return NULL; @@ -563,21 +590,19 @@ NS_DURING NS_HANDLER NS_ENDHANDLER - CGDirectDisplayID display = NewtScreen_getCGDirectDisplayIDByNSScreen(screen); - - CFArrayRef availableModes = CGDisplayAvailableModes(display); + CFArrayRef availableModes = CGDisplayAvailableModes(displayID); CFIndex numberOfAvailableModes = CFArrayGetCount(availableModes); CFIndex numberOfAvailableModesRots = ROTMODES_PER_REALMODE * numberOfAvailableModes; CFDictionaryRef mode = NULL; - int currentCCWRot = (int)CGDisplayRotation(display); + int currentCCWRot = (int)CGDisplayRotation(displayID); jint ccwRot = 0; int nativeId = 0; #ifdef VERBOSE_ON if(0 >= mode_idx) { // only for current mode (-1) and first mode (scanning) - DBG_PRINT( "getScreenMode0: scrn %d (s %p, d %p, pscale %lf), mode %d, avail: %d/%d, current rot %d ccw\n", - (int)crt_idx, screen, (void*)(intptr_t)display, pixelScale, (int)mode_idx, (int)numberOfAvailableModes, (int)numberOfAvailableModesRots, currentCCWRot); + DBG_PRINT( "getScreenMode0: crtID 0x%X (s %p, pscale %lf), mode %d, avail: %d/%d, current rot %d ccw\n", + (uint32_t)displayID, screen, pixelScale, (int)mode_idx, (int)numberOfAvailableModes, (int)numberOfAvailableModesRots, currentCCWRot); } #endif @@ -594,7 +619,7 @@ NS_ENDHANDLER mode = (CFDictionaryRef)CFArrayGetValueAtIndex(availableModes, nativeId); } else { // current mode - mode = CGDisplayCurrentMode(display); + mode = CGDisplayCurrentMode(displayID); ccwRot = currentCCWRot; CFRange range = CFRangeMake (0, numberOfAvailableModes); nativeId = CFArrayGetFirstIndexOfValue(availableModes, range, (CFDictionaryRef)mode); @@ -652,26 +677,25 @@ NS_ENDHANDLER * Signature: (III)Z */ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_setMonitorMode0 - (JNIEnv *env, jobject object, jint crt_idx, jint nativeId, jint ccwRot) + (JNIEnv *env, jobject object, jint crt_id, jint nativeId, jint ccwRot) { jboolean res = JNI_TRUE; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - NSScreen *screen = NewtScreen_getNSScreenByIndex((int)crt_idx, false); + CGDirectDisplayID displayID = (CGDirectDisplayID)crt_id; + NSScreen *screen = NewtScreen_getNSScreenByCGDirectDisplayID(displayID); if( NULL == screen ) { [pool release]; return JNI_FALSE; } - CGDirectDisplayID display = NewtScreen_getCGDirectDisplayIDByNSScreen(screen); - - CFArrayRef availableModes = CGDisplayAvailableModes(display); + CFArrayRef availableModes = CGDisplayAvailableModes(displayID); CFIndex numberOfAvailableModes = CFArrayGetCount(availableModes); #ifdef VERBOSE_ON CFIndex numberOfAvailableModesRots = ROTMODES_PER_REALMODE * numberOfAvailableModes; #endif - DBG_PRINT( "setScreenMode0: scrn %d (%p, %p), nativeID %d, rot %d ccw, avail: %d/%d\n", - (int)crt_idx, screen, (void*)(intptr_t)display, (int)nativeId, ccwRot, (int)numberOfAvailableModes, (int)numberOfAvailableModesRots); + DBG_PRINT( "setScreenMode0: crtID 0x%X (%p), nativeID %d, rot %d ccw, avail: %d/%d\n", + (uint32_t)displayID, screen, (int)nativeId, ccwRot, (int)numberOfAvailableModes, (int)numberOfAvailableModesRots); CFDictionaryRef mode = NULL; @@ -689,7 +713,7 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_setMonito } if( NULL != mode ) { - CGError err = CGDisplaySwitchToMode(display, mode); + CGError err = CGDisplaySwitchToMode(displayID, mode); if(kCGErrorSuccess != err) { DBG_PRINT( "setScreenMode0: SetMode failed: %d\n", (int)err); res = JNI_FALSE; @@ -807,6 +831,15 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_createWindow return (jlong) ((intptr_t) myWindow); } +JNIEXPORT jint JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_getDisplayID0(JNIEnv *env, jobject jthis, jlong window) { + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NewtMacWindow* myWindow = (NewtMacWindow*) ((intptr_t) window); + NSScreen *screen = [myWindow screen]; + int32_t displayID = (int32_t)NewtScreen_getCGDirectDisplayIDByNSScreen(screen); + [pool release]; + return (jint) displayID; +} + /** * Method is called on Main-Thread, hence no special invocation required inside method. * @@ -968,10 +1001,13 @@ NS_DURING * <https://developer.apple.com/library/mac/documentation/graphicsimaging/Conceptual/QuartzDisplayServicesConceptual/Articles/DisplayCapture.html> * NSScreen *myScreen = NewtScreen_getNSScreenByCoord(x, y); - if ( [myView respondsToSelector:@selector(enterFullScreenMode:withOptions:)] ) { - // Available >= 10.5 - Makes the menubar disapear - [myView enterFullScreenMode: myScreen withOptions:NULL]; - } */ + if( NULL != myScreen ) { + if ( [myView respondsToSelector:@selector(enterFullScreenMode:withOptions:)] ) { + // Available >= 10.5 - Makes the menubar disapear + [myView enterFullScreenMode: myScreen withOptions:NULL]; + } + } + */ if( myWindow->hasPresentationSwitch ) { DBG_PRINT( "initWindow0.%d - %p view %p, setPresentationOptions 0x%X\n", dbgIdx++, myWindow, myView, (int)myWindow->fullscreenPresentationOptions); @@ -1005,9 +1041,9 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_setPixelScale #ifdef VERBOSE_ON int dbgIdx = 1; #endif - DBG_PRINT( "setPixelScale0 - %p (this), %p (window), view %p, reqPixScale %f (START)\n", (void*)(intptr_t)jthis, myWindow, myView, (float)reqPixelScale); + (void)myWindow; NS_DURING // HiDPI scaling: Setup - Available >= 10.7 diff --git a/src/newt/native/NewtMacWindow.h b/src/newt/native/NewtMacWindow.h index 0f80df2d7..7dc5c6e19 100644 --- a/src/newt/native/NewtMacWindow.h +++ b/src/newt/native/NewtMacWindow.h @@ -49,8 +49,6 @@ // #define DBG_LIFECYCLE 1 -NSScreen * NewtScreen_getNSScreenByIndex(int screen_idx, BOOL cap); -NSScreen * NewtScreen_getNSScreenByCoord(int x, int y); CGDirectDisplayID NewtScreen_getCGDirectDisplayIDByNSScreen(NSScreen *screen); @interface NewtView : NSView diff --git a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01cNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01cNEWT.java index b70b5ce7d..06173a9f1 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01cNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01cNEWT.java @@ -110,7 +110,7 @@ public class TestScreenMode01cNEWT extends UITestCase { } @Test - public void testScreenFullscreenSingleQ1() throws InterruptedException { + public void test01ScreenFullscreenSingleQ1() throws InterruptedException { final Display display = NewtFactory.createDisplay(null); // local display Assert.assertNotNull(display); final Screen screen = NewtFactory.createScreen(display, 0); // screen 0 @@ -126,7 +126,7 @@ public class TestScreenMode01cNEWT extends UITestCase { } @Test - public void testScreenFullscreenSingleQ2() throws InterruptedException { + public void test02ScreenFullscreenSingleQ2() throws InterruptedException { final Display display = NewtFactory.createDisplay(null); // local display Assert.assertNotNull(display); final Screen screen = NewtFactory.createScreen(display, 0); // screen 0 @@ -146,7 +146,7 @@ public class TestScreenMode01cNEWT extends UITestCase { } @Test - public void testScreenFullscreenSpanQ1Q2() throws InterruptedException { + public void test03ScreenFullscreenSpanQ1Q2() throws InterruptedException { final Display display = NewtFactory.createDisplay(null); // local display Assert.assertNotNull(display); final Screen screen = NewtFactory.createScreen(display, 0); // screen 0 @@ -169,7 +169,7 @@ public class TestScreenMode01cNEWT extends UITestCase { } @Test - public void testScreenFullscreenSpanALL() throws InterruptedException { + public void test04ScreenFullscreenSpanALL() throws InterruptedException { final Display display = NewtFactory.createDisplay(null); // local display Assert.assertNotNull(display); final Screen screen = NewtFactory.createScreen(display, 0); // screen 0 |