diff options
author | Sven Gothel <[email protected]> | 2015-01-23 01:20:33 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-01-23 01:20:33 +0100 |
commit | 1341fe0216e4f12d7243e98290cc97824b1c0b5c (patch) | |
tree | 202dd91558731f9164e5f050b7aa9db50fc3c5b6 | |
parent | db775658a7f5d6614ae716b7492af8210f5e5f18 (diff) |
Bug 1120 - Add OSXUtil.GetPixelScale(final RectangleImmutable r, final int[] screenIndexOut) ( Part-1 )
-rwxr-xr-x | make/scripts/setenv-jogl.sh | 13 | ||||
-rw-r--r-- | make/scripts/tests.sh | 4 | ||||
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java | 55 | ||||
-rw-r--r-- | src/nativewindow/native/macosx/OSXmisc.m | 56 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java | 33 |
5 files changed, 152 insertions, 9 deletions
diff --git a/make/scripts/setenv-jogl.sh b/make/scripts/setenv-jogl.sh index bbaf5187c..79db4f9b1 100755 --- a/make/scripts/setenv-jogl.sh +++ b/make/scripts/setenv-jogl.sh @@ -115,17 +115,18 @@ JOGAMP_ALL_NOAWT_ALT_CLASSPATH=.:"$GLUEGEN_ALT_JAR":"$JOAL_JAR":"$JOGL_ALL_NOAWT JOGAMP_MOBILE_ALT_CLASSPATH=.:"$GLUEGEN_ALT_JAR":"$JOAL_JAR":"$JOGL_MOBILE_CLASSPATH":"$SWT_CLASSPATH":"$JUNIT_JAR":"$ANT_JARS":"$SEMVER_JAR":"$GLUEGEN_TESTUTIL_JAR" export JOGAMP_ALL_AWT_CLASSPATH JOGAMP_ALL_NOAWT_CLASSPATH JOGAMP_MOBILE_CLASSPATH JOGAMP_ATOMICS_NOAWT_CLASSPATH JOGAMP_ALL_NOAWT_ALT_CLASSPATH JOGAMP_MOBILE_ALT_CLASSPATH -CLASSPATH=.:"$GLUEGEN_JAR":"$JOAL_JAR":"$JOGL_CLASSPATH":"$SWT_CLASSPATH":"$JUNIT_JAR":"$ANT_JARS":"$SEMVER_JAR":"$GLUEGEN_TESTUTIL_JAR" -export CLASSPATH +JOGAMP_CLASSPATH=.:"$GLUEGEN_JAR":"$JOAL_JAR":"$JOGL_CLASSPATH":"$SWT_CLASSPATH":"$JUNIT_JAR":"$ANT_JARS":"$SEMVER_JAR":"$GLUEGEN_TESTUTIL_JAR" +export JOGAMP_CLASSPATH -# We use TempJarCache per default now! -#export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$GLUEGEN_OS":"$JOGL_LIB_DIR" -#export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH":"$GLUEGEN_OS:"$JOGL_LIB_DIR" +export JOGAMP_LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$GLUEGEN_OS":"$JOGL_LIB_DIR" +export JOGAMP_DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH":"$GLUEGEN_OS":"$JOGL_LIB_DIR" echo JOGAMP_ALL_AWT_CLASSPATH: "$JOGAMP_ALL_AWT_CLASSPATH" echo JOGAMP_ALL_NOAWT_CLASSPATH: "$JOGAMP_ALL_NOAWT_CLASSPATH" echo JOGAMP_MOBILE_CLASSPATH: "$JOGAMP_MOBILE_CLASSPATH" -echo CLASSPATH: "$CLASSPATH" +echo JOGAMP_CLASSPATH: "$JOGAMP_CLASSPATH" +echo JOGAMP_LD_LIBRARY_PATH: "$JOGAMP_LD_LIBRARY_PATH" +echo JOGAMP_DYLD_LIBRARY_PATH: "$JOGAMP_DYLD_LIBRARY_PATH" echo echo MacOSX REMEMBER to add the JVM arguments "-XstartOnFirstThread -Djava.awt.headless=true" for running demos without AWT, e.g. NEWT echo MacOSX REMEMBER to add the JVM arguments "-XstartOnFirstThread -Djava.awt.headless=true com.jogamp.newt.util.MainThread" for running demos with NEWT diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index dc6802bb4..a8b557dc8 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -42,6 +42,10 @@ if [ $MOSX -eq 1 ] ; then MOSX_MT=1 fi +# We use TempJarCache per default now! +#export LD_LIBRARY_PATH=$JOGAMP_LD_LIBRARY_PATH +#export DYLD_LIBRARY_PATH=$JOGAMP_DYLD_LIBRARY_PATH + #export LD_LIBRARY_PATH=$spath/../../EXTERNAL/PVRVFrame/OGLES-2.0/Linux_x86_64:$LD_LIBRARY_PATH #export LD_LIBRARY_PATH=$spath/../../EXTERNAL/PVRVFrame/OGLES-2.0/Linux_x86_32:$LD_LIBRARY_PATH #export LD_LIBRARY_PATH=/usr/local/projects/Xorg.modular/build-x86_64/lib:$LD_LIBRARY_PATH diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java index cf163bd82..9af74d9f5 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java @@ -31,6 +31,8 @@ import javax.media.nativewindow.NativeWindowException; import javax.media.nativewindow.NativeWindowFactory; import javax.media.nativewindow.util.Insets; import javax.media.nativewindow.util.Point; +import javax.media.nativewindow.util.Rectangle; +import javax.media.nativewindow.util.RectangleImmutable; import com.jogamp.common.util.Function; import com.jogamp.common.util.FunctionTask; @@ -107,6 +109,58 @@ public class OSXUtil implements ToolkitProperties { return (Insets) GetInsets0(windowOrView); } + /** + * Returns the pixel-scale of the NSScreen, with the highest + * {@link RectangleImmutable#coverage(RectangleImmutable) coverage} of the given rectangle in window units. + * <p> + * If no coverage is detected the pixel-scale of the first NSScreen is returned. + * </p> + * @param r arbitrary rectangle in window units + * @param screenIndexOut storage returning the native screen index containing the given rectangle + */ + public static double GetPixelScale(final RectangleImmutable r, final int[] screenIndexOut) { + if( DEBUG ) { + System.err.printf("GetPixelScale covering %s%n", r.toString()); + } + final int screenCount; + final RectangleImmutable[] screenBounds; + final double[] pixelScales; + { + final double[] sd = GetScreenData0(); + if( 0 != sd.length % 5 ) { + throw new InternalError("GetScreenData0 didn't return multiple of 5 but "+sd.length); + } + screenCount = sd.length / 5; + screenBounds = new RectangleImmutable[screenCount]; + pixelScales = new double[screenCount] ; + for(int i=0; i<screenCount; i++) { + final int j = i*5; + pixelScales[i] = sd[j+0]; + screenBounds[i] = new Rectangle((int)sd[j+1], (int)sd[j+2], (int)sd[j+3], (int)sd[j+4]); + if( DEBUG ) { + System.err.printf("GetPixelScale.Screen[%d]: scale %f, bounds[%f / %f %f x %f]%n", + i, pixelScales[i], sd[j+1], sd[j+2], sd[j+3], sd[j+4]); + } + } + } + double pixelScale = pixelScales[0]; + screenIndexOut[0] = 0; + float maxCoverage = Float.MIN_VALUE; + for(int i=screenCount-1; i>=0; i--) { + final RectangleImmutable sb = screenBounds[i]; + final float coverage = sb.coverage(r); + if( coverage > maxCoverage ) { + maxCoverage = coverage; + screenIndexOut[0] = i; + pixelScale = pixelScales[i]; + } + } + if( DEBUG ) { + System.err.printf("GetPixelScale Result: screen %d, scale %f%n%n", screenIndexOut[0], pixelScale); + } + return pixelScale; + } + public static double GetPixelScale(final int screenIndex) { return GetPixelScale0(screenIndex); } @@ -393,6 +447,7 @@ 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[] GetScreenData0(); private static native double GetPixelScale0(int screenIndex); private static native double GetPixelScale1(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 127b329d1..997bafba0 100644 --- a/src/nativewindow/native/macosx/OSXmisc.m +++ b/src/nativewindow/native/macosx/OSXmisc.m @@ -249,6 +249,62 @@ JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetInsets0 return res; } +static CGDirectDisplayID GetCGDirectDisplayIDByNSScreen(NSScreen *screen) { + // Mind: typedef uint32_t CGDirectDisplayID; - however, we assume it's 64bit on 64bit ?! + 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]; +} + +/* + * Class: Java_jogamp_nativewindow_macosx_OSXUtil + * Method: GetScreenData0 + * Signature: ()[F + */ +JNIEXPORT jdoubleArray JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetScreenData0 + (JNIEnv *env, jclass unused) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + CGFloat pixelScale; + CGDirectDisplayID display; + NSRect dBounds; + NSScreen *screen; + NSArray *screens = [NSScreen screens]; + int sCount = [screens count]; + jdouble res[sCount*5]; + int i,j; + + for(i=0; i<sCount; i++) { + j = i*5; + screen = (NSScreen *) [screens objectAtIndex: i]; + pixelScale = 1.0; // default +NS_DURING + // Available >= 10.7 + pixelScale = [screen backingScaleFactor]; // HiDPI scaling +NS_HANDLER +NS_ENDHANDLER + display = GetCGDirectDisplayIDByNSScreen(screen); + dBounds = CGDisplayBounds (display); // origin top-left + res[j+0] = (jdouble)pixelScale; + res[j+1] = (jdouble)dBounds.origin.x; + res[j+2] = (jdouble)dBounds.origin.y; + res[j+3] = (jdouble)dBounds.size.width; + res[j+4] = (jdouble)dBounds.size.height; + } + + jdoubleArray jniRes = (*env)->NewDoubleArray(env, sCount*5); // x,y,w,h,scale + if (jniRes == NULL) { + NativewindowCommon_throwNewRuntimeException(env, "Could not allocate double array of size %d", sCount*5); + } + (*env)->SetDoubleArrayRegion(env, jniRes, 0, sCount*5, res); + + [pool release]; + + return jniRes; +} + /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil * Method: GetPixelScale0 diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java index 3e2476563..340816a13 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java @@ -31,11 +31,16 @@ package com.jogamp.opengl.test.junit.jogl.demos.es2.awt; import java.awt.AWTException; import java.awt.BorderLayout; import java.awt.Dimension; +import java.awt.DisplayMode; +import java.awt.GraphicsDevice; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.lang.reflect.InvocationTargetException; +import javax.media.nativewindow.NativeSurface; import javax.media.nativewindow.ScalableSurface; +import javax.media.nativewindow.util.Rectangle; +import javax.media.nativewindow.util.RectangleImmutable; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLCapabilitiesImmutable; @@ -45,6 +50,8 @@ import javax.media.opengl.awt.GLJPanel; import javax.swing.JFrame; import javax.swing.SwingUtilities; +import jogamp.common.os.PlatformPropsImpl; + import org.junit.AfterClass; import org.junit.Assert; import org.junit.Assume; @@ -53,6 +60,7 @@ import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; +import com.jogamp.common.os.Platform; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.TraceKeyAdapter; import com.jogamp.newt.event.TraceWindowAdapter; @@ -76,6 +84,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { static boolean shallUsePBuffer = false; static boolean shallUseBitmap = false; static boolean useMSAA = false; + static int msaaNumSamples = 4; static int swapInterval = 0; static boolean useAnimator = true; static boolean manualTest = false; @@ -212,7 +221,23 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { if( e.isAutoRepeat() ) { return; } - if(e.getKeyChar()=='x') { + if(e.getKeyChar()=='p') { + System.err.println(); + final java.awt.Point los = glJPanel.getLocationOnScreen(); + final RectangleImmutable r = new Rectangle(los.x, los.y, glJPanel.getWidth(), glJPanel.getHeight()); + final GraphicsDevice gd = glJPanel.getGraphicsConfiguration().getDevice(); + final DisplayMode dm = gd.getDisplayMode(); + System.err.printf("GetPixelScale: AWT DisplayMode %d x %d pixel-units%n", dm.getWidth(), dm.getHeight()); + System.err.printf("GetPixelScale: NW Screen: %s%n", glJPanel.getNativeSurface().getGraphicsConfiguration().getScreen()); + System.err.printf("GetPixelScale: Panel Bounds: %s window-units%n", r.toString()); + System.err.printf("GetPixelScale: Panel Resolution: %d x %d pixel-units%n", glJPanel.getSurfaceWidth(), glJPanel.getSurfaceHeight()); + if( Platform.OSType.MACOS == PlatformPropsImpl.OS_TYPE ) { + final int[] screenIndexOut = { 0 }; + final double pixelScale = jogamp.nativewindow.macosx.OSXUtil.GetPixelScale(r, screenIndexOut); + System.err.printf("GetPixelScale: PixelScale %f on screen-idx %d%n", pixelScale, screenIndexOut[0]); + } + System.err.println(); + } else if(e.getKeyChar()=='x') { final int[] hadSurfacePixelScale = glJPanel.getCurrentSurfaceScale(new int[2]); final int[] reqSurfacePixelScale; if( hadSurfacePixelScale[0] == ScalableSurface.IDENTITY_PIXELSCALE ) { @@ -316,7 +341,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { } final GLCapabilities caps = new GLCapabilities( glp ); if(useMSAA) { - caps.setNumSamples(4); + caps.setNumSamples(msaaNumSamples); caps.setSampleBuffers(true); } if(shallUsePBuffer) { @@ -504,7 +529,9 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { i++; swapInterval = MiscUtils.atoi(args[i], swapInterval); } else if(args[i].equals("-msaa")) { + i++; useMSAA = true; + msaaNumSamples = MiscUtils.atoi(args[i], msaaNumSamples); } else if(args[i].equals("-noanim")) { useAnimator = false; } else if(args[i].equals("-pbuffer")) { @@ -527,7 +554,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { System.err.println("forceES2 "+forceES2); System.err.println("forceGL3 "+forceGL3); System.err.println("forceGLFFP "+forceGLFFP); - System.err.println("useMSAA "+useMSAA); + System.err.println("useMSAA "+useMSAA+", msaaNumSamples "+msaaNumSamples); System.err.println("useAnimator "+useAnimator); System.err.println("shallUsePBuffer "+shallUsePBuffer); System.err.println("shallUseBitmap "+shallUseBitmap); |