diff options
author | Sven Gothel <[email protected]> | 2019-07-08 04:55:28 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2019-07-08 04:55:28 +0200 |
commit | f74e9c1597612edbff81425d4f2f528da5ebaf43 (patch) | |
tree | c45eaf4828f3a74b5066ed0f2e5dc8bf238364dc /src | |
parent | a307ab505ed3fb5fe64f01478ce6d2933cd26c7d (diff) |
iOS / MacOS: PixelScale Update
- IOSUtil/OSXUtil: Return float value and refine name to GetScreenPixelScale*
- WindowDriver's updateMaxScreenPixelScaleByDisplayID(..) and updateMaxScreenPixelScaleByWindowHandle(..)
will only update the maxPixelScale, as actual user pixelSize change should not be triggered here.
A user pixelSize adaption to the changed underlying scale capabilities (e.g. switch monitor)
should be supported by the implemented WindowDriver's: updatePixelScale(..) called by native code.
Diffstat (limited to 'src')
10 files changed, 118 insertions, 110 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/ios/IOSUtil.java b/src/nativewindow/classes/jogamp/nativewindow/ios/IOSUtil.java index bd4b36239..7100cb0b5 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/ios/IOSUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/ios/IOSUtil.java @@ -115,18 +115,18 @@ public class IOSUtil implements ToolkitProperties { return (Insets) GetInsets0(windowOrView); } - public static double GetPixelScaleByDisplayID(final int displayID) { - if( 0 != displayID ) { - return GetPixelScale1(displayID); + public static float GetScreenPixelScaleByScreenIdx(final int screenIdx) { + if( 0 <= screenIdx ) { + return GetScreenPixelScale1(screenIdx); } else { - return 1.0; // default + return 1.0f; // default } } - public static double GetPixelScale(final long windowOrView) { + public static float GetScreenPixelScale(final long windowOrView) { if( 0 != windowOrView ) { - return GetPixelScale2(windowOrView); + return GetScreenPixelScale2(windowOrView); } else { - return 1.0; // default + return 1.0f; // default } } @@ -310,8 +310,8 @@ public class IOSUtil implements ToolkitProperties { private static native boolean isUIWindow0(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 double GetPixelScale1(int displayID); - private static native double GetPixelScale2(long windowOrView); + private static native float GetScreenPixelScale1(int screenIdx); + private static native float GetScreenPixelScale2(long windowOrView); private static native long CreateUIWindow0(int x, int y, int width, int height); private static native void DestroyUIWindow0(long uiWindow); private static native long GetCALayer0(long uiView); diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java index 3b824cfe4..0f4a70ddc 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java @@ -592,7 +592,7 @@ public class JAWTUtil { final Object res = getCGDisplayIDMethodOnOSX.invoke(device); if (res instanceof Integer) { final int displayID = ((Integer)res).intValue(); - sx = (float) OSXUtil.GetPixelScaleByDisplayID(displayID); + sx = OSXUtil.GetScreenPixelScaleByDisplayID(displayID); sy = sx; } } catch (final Throwable t) {} diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java index b1bf248ce..e93c9574f 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java @@ -107,18 +107,18 @@ public class OSXUtil implements ToolkitProperties { return (Insets) GetInsets0(windowOrView); } - public static double GetPixelScaleByDisplayID(final int displayID) { + public static float GetScreenPixelScaleByDisplayID(final int displayID) { if( 0 != displayID ) { - return GetPixelScale1(displayID); + return GetScreenPixelScale1(displayID); } else { - return 1.0; // default + return 1.0f; // default } } - public static double GetPixelScale(final long windowOrView) { + public static float GetScreenPixelScale(final long windowOrView) { if( 0 != windowOrView ) { - return GetPixelScale2(windowOrView); + return GetScreenPixelScale2(windowOrView); } else { - return 1.0; // default + return 1.0f; // default } } @@ -404,8 +404,8 @@ 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 double GetPixelScale1(int displayID); - private static native double GetPixelScale2(long windowOrView); + private static native float GetScreenPixelScale1(int displayID); + private static native float GetScreenPixelScale2(long windowOrView); private static native long CreateNSWindow0(int x, int y, int width, int height); private static native void DestroyNSWindow0(long nsWindow); private static native long GetNSView0(long nsWindow); diff --git a/src/nativewindow/native/ios/IOSmisc.m b/src/nativewindow/native/ios/IOSmisc.m index 49fe8325e..70cff4c06 100644 --- a/src/nativewindow/native/ios/IOSmisc.m +++ b/src/nativewindow/native/ios/IOSmisc.m @@ -252,35 +252,35 @@ JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_ios_IOSUtil_GetInsets0 /* * Class: Java_jogamp_nativewindow_ios_IOSUtil - * Method: GetPixelScale1 - * Signature: (I)D + * Method: GetScreenPixelScale1 + * Signature: (I)F */ -JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_ios_IOSUtil_GetPixelScale1 - (JNIEnv *env, jclass unused, jint displayID) +JNIEXPORT jfloat JNICALL Java_jogamp_nativewindow_ios_IOSUtil_GetScreenPixelScale1 + (JNIEnv *env, jclass unused, jint screenIdx) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; CGFloat pixelScale = 1.0; // default - // UIScreen *screen = IOSUtil_getUIScreenByCGDirectDisplayID((CGDirectDisplayID)displayID); - UIScreen *screen = [UIScreen mainScreen]; - if( NULL != screen ) { -NS_DURING - // Available >= 10.7 - pixelScale = [screen scale]; // HiDPI scaling -NS_HANDLER -NS_ENDHANDLER + + NSArray *screens = [UIScreen screens]; + int count = [screens count]; + if( 0 <= screenIdx && screenIdx < count ) { + UIScreen * screen = (UIScreen *) [screens objectAtIndex: screenIdx]; + if( NULL != screen ) { + pixelScale = [screen scale]; + } } [pool release]; - return (jdouble)pixelScale; + return (jfloat)pixelScale; } /* * Class: Java_jogamp_nativewindow_ios_IOSUtil - * Method: GetPixelScale1 - * Signature: (J)D + * Method: GetScreenPixelScale1 + * Signature: (J)F */ -JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_ios_IOSUtil_GetPixelScale2 +JNIEXPORT jfloat JNICALL Java_jogamp_nativewindow_ios_IOSUtil_GetScreenPixelScale2 (JNIEnv *env, jclass unused, jlong winOrView) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -302,16 +302,11 @@ JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_ios_IOSUtil_GetPixelScale2 NativewindowCommon_throwNewRuntimeException(env, "neither win nor view %p\n", nsObj); } - CGFloat pixelScale = 1.0; // default -NS_DURING - // Available >= 10.7 - pixelScale = [screen scale]; // HiDPI scaling -NS_HANDLER -NS_ENDHANDLER + CGFloat pixelScale = [screen scale]; [pool release]; - return (jdouble)pixelScale; + return (jfloat)pixelScale; } /* diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m index fb15c43b9..1135c5fb2 100644 --- a/src/nativewindow/native/macosx/OSXmisc.m +++ b/src/nativewindow/native/macosx/OSXmisc.m @@ -266,10 +266,10 @@ JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetInsets0 /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil - * Method: GetPixelScale1 - * Signature: (I)D + * Method: GetScreenPixelScale1 + * Signature: (I)F */ -JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetPixelScale1 +JNIEXPORT jfloat JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetScreenPixelScale1 (JNIEnv *env, jclass unused, jint displayID) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -285,15 +285,15 @@ NS_ENDHANDLER } [pool release]; - return (jdouble)pixelScale; + return (jfloat)pixelScale; } /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil - * Method: GetPixelScale1 - * Signature: (J)D + * Method: GetScreenPixelScale1 + * Signature: (J)F */ -JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetPixelScale2 +JNIEXPORT jfloat JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetScreenPixelScale2 (JNIEnv *env, jclass unused, jlong winOrView) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -324,7 +324,7 @@ NS_ENDHANDLER [pool release]; - return (jdouble)pixelScale; + return (jfloat)pixelScale; } /* diff --git a/src/newt/classes/jogamp/newt/driver/ios/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/ios/ScreenDriver.java index 47280865d..daa033edb 100644 --- a/src/newt/classes/jogamp/newt/driver/ios/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/ios/ScreenDriver.java @@ -82,7 +82,7 @@ public class ScreenDriver extends ScreenImpl { // for(int crtIdx=0; crtIdx<count; crtIdx++) { final int crt_id = crtIDs[crtIdx]; - final float pixelScaleRaw = (float)IOSUtil.GetPixelScaleByDisplayID(crt_id); + final float pixelScaleRaw = IOSUtil.GetScreenPixelScaleByScreenIdx(crt_id); pixelScaleArray[crtIdx] = FloatUtil.isZero(pixelScaleRaw, FloatUtil.EPSILON) ? 1.0f : pixelScaleRaw; propsOrigArray[crtIdx] = getMonitorProps0(crt_id); if ( null == propsOrigArray[crtIdx] ) { diff --git a/src/newt/classes/jogamp/newt/driver/ios/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/ios/WindowDriver.java index 2a257436a..79c35c310 100644 --- a/src/newt/classes/jogamp/newt/driver/ios/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/ios/WindowDriver.java @@ -49,6 +49,7 @@ import jogamp.newt.driver.DriverUpdatePosition; import com.jogamp.newt.event.InputEvent; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.MonitorEvent; +import com.jogamp.newt.event.MouseEvent; import com.jogamp.opengl.math.FloatUtil; public class WindowDriver extends WindowImpl implements MutableSurface, DriverClearFocus, DriverUpdatePosition { @@ -75,7 +76,7 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl if( SurfaceScaleUtils.setNewPixelScale(hasPixelScale, hasPixelScale, newPixelScale, minPixelScale, maxPixelScale, DEBUG_IMPLEMENTATION ? getClass().getName() : null) ) { if( sendEvent ) { - if( deferOffThread ) { + if( defer && deferOffThread ) { superSizeChangedOffThread(defer, getWidth(), getHeight(), true); } else { super.sizeChanged(defer, getWidth(), getHeight(), true); @@ -89,51 +90,55 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl } } - private boolean updatePixelScaleByDisplayID(final boolean sendEvent) { - final float maxPixelScaleRaw = (float) IOSUtil.GetPixelScaleByDisplayID(getDisplayID()); + /** + * Essentially updates {@code maxPixelScale} .. + */ + private boolean updateMaxScreenPixelScaleByDisplayID(final boolean sendEvent) { + final float maxPixelScaleRaw = IOSUtil.GetScreenPixelScaleByScreenIdx(getDisplayID()); if( DEBUG_IMPLEMENTATION ) { - System.err.println("WindowDriver.updatePixelScale.1: "+hasPixelScale[0]+", "+maxPixelScaleRaw+" (max)"); + System.err.println("WindowDriver.updatePixelScale.1: req "+reqPixelScale[0]+", has "+hasPixelScale[0]+", max "+maxPixelScaleRaw); } - return updatePixelScale(sendEvent, true /* defer */, false /*offthread */, maxPixelScaleRaw, maxPixelScaleRaw); + return updatePixelScale(sendEvent, true /* defer */, false /*offthread */, hasPixelScale[0], maxPixelScaleRaw); } - private boolean updatePixelScaleByWindowHandle(final boolean sendEvent) { + /** + * Essentially updates {@code maxPixelScale} .. + */ + private boolean updateMaxScreenPixelScaleByWindowHandle(final boolean sendEvent) { final long handle = getWindowHandle(); if( 0 != handle ) { - final float maxPixelScaleRaw = (float)IOSUtil.GetPixelScale(handle); + final float maxPixelScaleRaw = IOSUtil.GetScreenPixelScale(handle); if( DEBUG_IMPLEMENTATION ) { - System.err.println("WindowDriver.updatePixelScale.2: "+hasPixelScale[0]+", "+maxPixelScaleRaw+" (max)"); + System.err.println("WindowDriver.updatePixelScale.2: req "+reqPixelScale[0]+", has "+hasPixelScale[0]+", max "+maxPixelScaleRaw); } - return updatePixelScale(sendEvent, true /* defer */, false /*offthread */, maxPixelScaleRaw, maxPixelScaleRaw); + return updatePixelScale(sendEvent, true /* defer */, false /*offthread */, hasPixelScale[0], maxPixelScaleRaw); } else { return false; } } /** Called from native code */ - protected void updatePixelScale(final boolean defer, final float newPixelScaleRaw, final float maxPixelScaleRaw) { + protected void updatePixelScale(final boolean defer, final float oldPixelScaleRaw, final float newPixelScaleRaw, final float maxPixelScaleRaw, final boolean changed) { if( DEBUG_IMPLEMENTATION ) { - System.err.println("WindowDriver.updatePixelScale.3: "+hasPixelScale[0]+" (has) -> "+newPixelScaleRaw+" (new), "+maxPixelScaleRaw+" (max), drop "+!isNativeValid()); - } - if( isNativeValid() ) { - updatePixelScale(true /* sendEvent*/, defer, true /*offthread */, newPixelScaleRaw, maxPixelScaleRaw); + System.err.println("WindowDriver.updatePixelScale.3: req "+reqPixelScale[0]+", has "+hasPixelScale[0]+", old "+oldPixelScaleRaw+", new "+newPixelScaleRaw+", max "+maxPixelScaleRaw+", changed "+changed); } + updatePixelScale(true /* sendEvent*/, defer, true /*offthread */, newPixelScaleRaw, maxPixelScaleRaw); } @Override protected final void instantiationFinishedImpl() { - updatePixelScaleByDisplayID(false /* sendEvent*/); + updateMaxScreenPixelScaleByDisplayID(false /* sendEvent*/); } @Override protected void setScreen(final ScreenImpl newScreen) { // never null ! super.setScreen(newScreen); - updatePixelScaleByDisplayID(false /* sendEvent*/); // caller (reparent, ..) will send reshape event + updateMaxScreenPixelScaleByDisplayID(false /* sendEvent*/); // caller (reparent, ..) will send reshape event } @Override protected void monitorModeChanged(final MonitorEvent me, final boolean success) { - updatePixelScaleByWindowHandle(false /* sendEvent*/); // send reshape event itself + updateMaxScreenPixelScaleByWindowHandle(false /* sendEvent*/); // send reshape event itself } @Override @@ -441,7 +446,7 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl createWindow(false, 0 != oldWindowHandle, pClientLevelOnSreen, width, height, flags); } // no native event (fullscreen, some reparenting) - updatePixelScaleByWindowHandle(false /* sendEvent */); + updateMaxScreenPixelScaleByWindowHandle(false /* sendEvent */); if( isOffscreenInstance) { super.sizeChanged(false, width, height, true); positionChanged(false, x, y); diff --git a/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java index ddeea265a..590f706df 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java @@ -88,7 +88,7 @@ public class ScreenDriver extends ScreenImpl { // for(int crtIdx=0; crtIdx<count; crtIdx++) { final int crt_id = crtIDs[crtIdx]; - final float pixelScaleRaw = (float)OSXUtil.GetPixelScaleByDisplayID(crt_id); + final float pixelScaleRaw = OSXUtil.GetScreenPixelScaleByDisplayID(crt_id); pixelScaleArray[crtIdx] = FloatUtil.isZero(pixelScaleRaw, FloatUtil.EPSILON) ? 1.0f : pixelScaleRaw; propsOrigArray[crtIdx] = getMonitorProps0(crt_id); if ( null == propsOrigArray[crtIdx] ) { diff --git a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java index e6ae7719c..1c6102f88 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java @@ -82,7 +82,7 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl if( SurfaceScaleUtils.setNewPixelScale(hasPixelScale, hasPixelScale, newPixelScale, minPixelScale, maxPixelScale, DEBUG_IMPLEMENTATION ? getClass().getName() : null) ) { if( sendEvent ) { - if( deferOffThread ) { + if( defer && deferOffThread ) { superSizeChangedOffThread(defer, getWidth(), getHeight(), true); } else { super.sizeChanged(defer, getWidth(), getHeight(), true); @@ -96,51 +96,55 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl } } - private boolean updatePixelScaleByDisplayID(final boolean sendEvent) { - final float maxPixelScaleRaw = (float) OSXUtil.GetPixelScaleByDisplayID(getDisplayID()); + /** + * Essentially updates {@code maxPixelScale} .. + */ + private boolean updateMaxScreenPixelScaleByDisplayID(final boolean sendEvent) { + final float maxPixelScaleRaw = OSXUtil.GetScreenPixelScaleByDisplayID(getDisplayID()); if( DEBUG_IMPLEMENTATION ) { - System.err.println("WindowDriver.updatePixelScale.1: "+hasPixelScale[0]+", "+maxPixelScaleRaw+" (max)"); + System.err.println("WindowDriver.updatePixelScale.1: req "+reqPixelScale[0]+", has "+hasPixelScale[0]+", max "+maxPixelScaleRaw); } - return updatePixelScale(sendEvent, true /* defer */, false /*offthread */, maxPixelScaleRaw, maxPixelScaleRaw); + return updatePixelScale(sendEvent, true /* defer */, false /*offthread */, hasPixelScale[0], maxPixelScaleRaw); } - private boolean updatePixelScaleByWindowHandle(final boolean sendEvent) { + /** + * Essentially updates {@code maxPixelScale} .. + */ + private boolean updateMaxScreenPixelScaleByWindowHandle(final boolean sendEvent) { final long handle = getWindowHandle(); if( 0 != handle ) { - final float maxPixelScaleRaw = (float)OSXUtil.GetPixelScale(handle); + final float maxPixelScaleRaw = OSXUtil.GetScreenPixelScale(handle); if( DEBUG_IMPLEMENTATION ) { - System.err.println("WindowDriver.updatePixelScale.2: "+hasPixelScale[0]+", "+maxPixelScaleRaw+" (max)"); + System.err.println("WindowDriver.updatePixelScale.2: req "+reqPixelScale[0]+", has "+hasPixelScale[0]+", max "+maxPixelScaleRaw); } - return updatePixelScale(sendEvent, true /* defer */, false /*offthread */, maxPixelScaleRaw, maxPixelScaleRaw); + return updatePixelScale(sendEvent, true /* defer */, false /*offthread */, hasPixelScale[0], maxPixelScaleRaw); } else { return false; } } /** Called from native code */ - protected void updatePixelScale(final boolean defer, final float newPixelScaleRaw, final float maxPixelScaleRaw) { + protected void updatePixelScale(final boolean defer, final float oldPixelScaleRaw, final float newPixelScaleRaw, final float maxPixelScaleRaw, final boolean changed) { if( DEBUG_IMPLEMENTATION ) { - System.err.println("WindowDriver.updatePixelScale.3: "+hasPixelScale[0]+" (has) -> "+newPixelScaleRaw+" (new), "+maxPixelScaleRaw+" (max), drop "+!isNativeValid()); - } - if( isNativeValid() ) { - updatePixelScale(true /* sendEvent*/, defer, true /*offthread */, newPixelScaleRaw, maxPixelScaleRaw); + System.err.println("WindowDriver.updatePixelScale.3: req "+reqPixelScale[0]+", has "+hasPixelScale[0]+", old "+oldPixelScaleRaw+", new "+newPixelScaleRaw+", max "+maxPixelScaleRaw+", changed "+changed); } + updatePixelScale(true /* sendEvent*/, defer, true /*offthread */, newPixelScaleRaw, maxPixelScaleRaw); } @Override protected final void instantiationFinishedImpl() { - updatePixelScaleByDisplayID(false /* sendEvent*/); + updateMaxScreenPixelScaleByDisplayID(false /* sendEvent*/); } @Override protected void setScreen(final ScreenImpl newScreen) { // never null ! super.setScreen(newScreen); - updatePixelScaleByDisplayID(false /* sendEvent*/); // caller (reparent, ..) will send reshape event + updateMaxScreenPixelScaleByDisplayID(false /* sendEvent*/); // caller (reparent, ..) will send reshape event } @Override protected void monitorModeChanged(final MonitorEvent me, final boolean success) { - updatePixelScaleByWindowHandle(false /* sendEvent*/); // send reshape event itself + updateMaxScreenPixelScaleByWindowHandle(false /* sendEvent*/); // send reshape event itself } @Override @@ -448,7 +452,7 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl createWindow(false, 0 != oldWindowHandle, pClientLevelOnSreen, width, height, flags); } // no native event (fullscreen, some reparenting) - updatePixelScaleByWindowHandle(false /* sendEvent */); + updateMaxScreenPixelScaleByWindowHandle(false /* sendEvent */); if( isOffscreenInstance) { super.sizeChanged(false, width, height, true); positionChanged(false, x, y); diff --git a/src/newt/native/MacNewtNSWindow.m b/src/newt/native/MacNewtNSWindow.m index 31d7863d3..96dff76f6 100644 --- a/src/newt/native/MacNewtNSWindow.m +++ b/src/newt/native/MacNewtNSWindow.m @@ -272,21 +272,20 @@ static jmethodID windowRepaintID = NULL; - (BOOL) softLock { - // DBG_PRINT("*************** softLock.0: %p\n", (void*)pthread_self()); int err; if( 0 != ( err = pthread_mutex_lock(&softLockSync) ) ) { NSLog(@"NewtNSView::softLock failed: errCode %d - %@", err, [NSThread callStackSymbols]); return NO; } softLockCount++; - // DBG_PRINT("*************** softLock.X: %p\n", (void*)pthread_self()); + // DBG_PRINT("*************** softLock: %p count %d\n", (void*)pthread_self(), softLockCount); return 0 < softLockCount; } - (BOOL) softUnlock { - // DBG_PRINT("*************** softUnlock: %p\n", (void*)pthread_self()); softLockCount--; + // DBG_PRINT("*************** softUnlock: %p count %d\n", (void*)pthread_self(), softLockCount); int err; if( 0 != ( err = pthread_mutex_unlock(&softLockSync) ) ) { softLockCount++; @@ -321,7 +320,7 @@ static jmethodID windowRepaintID = NULL; - (void) drawRect:(NSRect)dirtyRect { - DBG_PRINT("*************** dirtyRect: %p %lf/%lf %lfx%lf\n", + DBG_PRINT("*************** drawRect: dirtyRect: %p %lf/%lf %lfx%lf\n", javaWindowObject, dirtyRect.origin.x, dirtyRect.origin.y, dirtyRect.size.width, dirtyRect.size.height); if(NULL==javaWindowObject) { @@ -789,20 +788,24 @@ static jmethodID windowRepaintID = NULL; // HiDPI scaling BOOL useHiDPI = false; CGFloat maxPixelScale = 1.0; - CGFloat winPixelScale = 1.0; + CGFloat pixelScale = 1.0; NSWindow* window = [self window]; NSScreen* screen = [window screen]; + CGFloat oldPixelScale = [[self layer] contentsScale]; NS_DURING maxPixelScale = [screen backingScaleFactor]; useHiDPI = [self wantsBestResolutionOpenGLSurface]; if( useHiDPI ) { - winPixelScale = [window backingScaleFactor]; + pixelScale = [window backingScaleFactor]; } NS_HANDLER NS_ENDHANDLER - DBG_PRINT("viewDidChangeBackingProperties: PixelScale: HiDPI %d, max %f, window %f\n", useHiDPI, (float)maxPixelScale, (float)winPixelScale); - [[self layer] setContentsScale: winPixelScale]; - + BOOL changeScale = oldPixelScale != pixelScale; + DBG_PRINT("viewDidChangeBackingProperties: PixelScale: useHiDPI %d, max %f, old %f -> %f (change %d)\n", + useHiDPI, (float)maxPixelScale, (float)oldPixelScale, (float)pixelScale, changeScale); + if( changeScale ) { + [[self layer] setContentsScale: pixelScale]; + } if (javaWindowObject == NULL) { DBG_PRINT("viewDidChangeBackingProperties: null javaWindowObject\n"); return; @@ -813,8 +816,8 @@ NS_ENDHANDLER DBG_PRINT("viewDidChangeBackingProperties: null JNIEnv\n"); return; } - - (*env)->CallVoidMethod(env, javaWindowObject, updatePixelScaleID, JNI_TRUE, (jfloat)winPixelScale, (jfloat)maxPixelScale); // defer + (*env)->CallVoidMethod(env, javaWindowObject, updatePixelScaleID, JNI_TRUE /* defer */, + (jfloat)oldPixelScale, (jfloat)pixelScale, (jfloat)maxPixelScale, (jboolean)changeScale); // detaching thread not required - daemon // NewtCommon_ReleaseJNIEnv(shallBeDetached); @@ -830,7 +833,7 @@ NS_ENDHANDLER enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(ZSIIISF)V"); enqueueKeyEventID = (*env)->GetMethodID(env, clazz, "enqueueKeyEvent", "(ZSISCC)V"); sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(ZIIZ)V"); - updatePixelScaleID = (*env)->GetMethodID(env, clazz, "updatePixelScale", "(ZFF)V"); + updatePixelScaleID = (*env)->GetMethodID(env, clazz, "updatePixelScale", "(ZFFFZ)V"); visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(ZZ)V"); insetsChangedID = (*env)->GetMethodID(env, clazz, "insetsChanged", "(ZIIII)V"); sizeScreenPosInsetsChangedID = (*env)->GetMethodID(env, clazz, "sizeScreenPosInsetsChanged", "(ZIIIIIIIIZZ)V"); @@ -1125,7 +1128,7 @@ NS_ENDHANDLER return; } jobject javaWindowObject = [newtView getJavaWindowObject]; - if (javaWindowObject == NULL) { + if ( NULL == javaWindowObject ) { DBG_PRINT("focusChanged: null javaWindowObject\n"); return; } @@ -1254,21 +1257,22 @@ NS_ENDHANDLER - (void) sendResizeEvent { - jobject javaWindowObject = NULL; + NewtNSView* newtView = (NewtNSView *) [self contentView]; + if( ! [newtView isKindOfClass:[NewtNSView class]] ) { + return; + } + jobject javaWindowObject = [newtView getJavaWindowObject]; + if ( NULL == javaWindowObject ) { + DBG_PRINT("sendResizeEvent: null javaWindowObject\n"); + return; + } int shallBeDetached = 0; JNIEnv* env = NewtCommon_GetJNIEnv(1 /* asDaemon */, &shallBeDetached); - if( NULL == env ) { DBG_PRINT("windowDidResize: null JNIEnv\n"); return; } - NewtNSView* newtView = (NewtNSView *) [self contentView]; - if( [newtView isKindOfClass:[NewtNSView class]] ) { - javaWindowObject = [newtView getJavaWindowObject]; - } - if( NULL != javaWindowObject ) { - [self updateSizePosInsets: env jwin: javaWindowObject defer:JNI_TRUE]; - } + [self updateSizePosInsets: env jwin: javaWindowObject defer:JNI_TRUE]; // detaching thread not required - daemon // NewtCommon_ReleaseJNIEnv(shallBeDetached); } @@ -1280,7 +1284,7 @@ NS_ENDHANDLER return; } jobject javaWindowObject = [newtView getJavaWindowObject]; - if (javaWindowObject == NULL) { + if ( NULL == javaWindowObject ) { DBG_PRINT("windowDidMove: null javaWindowObject\n"); return; } |