diff options
author | Sven Gothel <[email protected]> | 2020-01-05 23:02:55 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-01-05 23:02:55 +0100 |
commit | 8caf3fab68dc890855961d22cb235d1c8f5c52c6 (patch) | |
tree | d074f8d2a16557f1bd6963efddac0ca5dd37e9da | |
parent | 1216aa7bc4284e5568d7dd7bbd7f6d9fed27d25b (diff) |
Bug 1358: GLCanvas: Call new OSXUtil.SetWindowPixelScale(..) when GLCanvas gets realized on MacOS
This fixes GLCanvas's High-DPI scaled size issue on MacOS of Bug 1358.
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java | 15 | ||||
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java | 6 | ||||
-rw-r--r-- | src/nativewindow/native/macosx/OSXmisc.m | 40 |
3 files changed, 57 insertions, 4 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java index 5e90c4035..6ca53b3f2 100644 --- a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java +++ b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java @@ -55,6 +55,7 @@ import com.jogamp.opengl.GLRunnable; import com.jogamp.opengl.GLSharedContextSetter; import com.jogamp.opengl.Threading; +import jogamp.nativewindow.macosx.OSXUtil; import jogamp.nativewindow.x11.X11Util; import jogamp.opengl.Debug; import jogamp.opengl.GLContextImpl; @@ -64,6 +65,7 @@ import jogamp.opengl.GLDrawableImpl; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.internal.DPIUtil; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; @@ -581,6 +583,15 @@ public class GLCanvas extends Canvas implements GLAutoDrawable, GLSharedContextS } } else { nativeWindowHandle = SWTAccessor.getWindowHandle(this); + if( SWTAccessor.isOSX ) { + final float reqPixelScale = DPIUtil.autoScaleUp(this, 1f); + if( DEBUG ) { + System.err.println(getThreadName()+": SWT.GLCanvas.OSX "+toHexString(hashCode())+": Scaling: devZoom "+DPIUtil.getDeviceZoom()+", general "+DPIUtil.autoScaleUp(1f)+", onWidged "+reqPixelScale); + } + if( reqPixelScale > 1f ) { + OSXUtil.SetWindowPixelScale(nativeWindowHandle, reqPixelScale); + } + } } final GLDrawableFactory glFactory = GLDrawableFactory.getFactory(capsRequested.getGLProfile()); @@ -593,11 +604,13 @@ public class GLCanvas extends Canvas implements GLAutoDrawable, GLSharedContextS if(!_drawable.isRealized()) { // oops if(DEBUG) { + System.err.println(getThreadName()+": SWT.GLCanvas.validate.X "+proxySurface); System.err.println(getThreadName()+": SWT.GLCanvas.validate.X "+toHexString(hashCode())+": Drawable could not be realized: "+_drawable); } } else { if(DEBUG) { - System.err.println(getThreadName()+": SWT.GLCanvas.validate "+toHexString(hashCode())+": Drawable created and realized"); + System.err.println(getThreadName()+": SWT.GLCanvas.validate "+proxySurface); + System.err.println(getThreadName()+": SWT.GLCanvas.validate "+toHexString(hashCode())+": Drawable created and realized: "+_drawable); } drawable = _drawable; } diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java index e847279e1..e06a68953 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java @@ -150,6 +150,11 @@ public class OSXUtil implements ToolkitProperties { return 1.0f; // default } } + public static void SetWindowPixelScale(final long windowOrView, final float reqPixelScale) { + if( 0 != windowOrView ) { + SetWindowPixelScale1(windowOrView, reqPixelScale); + } + } public static long CreateNSWindow(final int x, final int y, final int width, final int height) { final long res[] = { 0 }; @@ -436,6 +441,7 @@ public class OSXUtil implements ToolkitProperties { private static native float GetScreenPixelScale1(int displayID); private static native float GetScreenPixelScale2(long windowOrView); private static native float GetWindowPixelScale1(long windowOrView); + private static native void SetWindowPixelScale1(final long windowOrView, final float reqPixelScale); 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/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m index 8cbfde8ed..091b1a67e 100644 --- a/src/nativewindow/native/macosx/OSXmisc.m +++ b/src/nativewindow/native/macosx/OSXmisc.m @@ -358,16 +358,13 @@ JNIEXPORT jfloat JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetWindowPixelS NSObject *nsObj = (NSObject*) (intptr_t) winOrView; NSWindow* win = NULL; NSView* view = NULL; - NSScreen *screen = NULL; if( [nsObj isKindOfClass:[NSWindow class]] ) { win = (NSWindow*) nsObj; view = [win contentView]; - screen = [win screen]; } else if( nsObj != NULL && [nsObj isKindOfClass:[NSView class]] ) { view = (NSView*) nsObj; win = [view window]; - screen = [win screen]; } else { NativewindowCommon_throwNewRuntimeException(env, "neither win nor view %p\n", nsObj); } @@ -390,6 +387,43 @@ NS_ENDHANDLER /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil + * Method: SetWindowPixelScale1 + * Signature: (JF)V + */ +JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_SetWindowPixelScale1 + (JNIEnv *env, jclass unused, jlong winOrView, jfloat reqPixelScale) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + NSObject *nsObj = (NSObject*) (intptr_t) winOrView; + NSWindow* win = NULL; + NSView* view = NULL; + + if( [nsObj isKindOfClass:[NSWindow class]] ) { + win = (NSWindow*) nsObj; + view = [win contentView]; + } else if( nsObj != NULL && [nsObj isKindOfClass:[NSView class]] ) { + view = (NSView*) nsObj; + win = [view window]; + } else { + NativewindowCommon_throwNewRuntimeException(env, "neither win nor view %p\n", nsObj); + } + +NS_DURING + // HiDPI scaling: Setup - Available >= 10.7 + if( 1.0 == reqPixelScale ) { + [view setWantsBestResolutionOpenGLSurface: NO]; + } else { + [view setWantsBestResolutionOpenGLSurface: YES]; + } +NS_HANDLER +NS_ENDHANDLER + + [pool release]; +} + +/* + * Class: Java_jogamp_nativewindow_macosx_OSXUtil * Method: CreateNSWindow0 * Signature: (IIIIZ)J */ |