aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-02-13 12:51:40 +0100
committerSven Gothel <[email protected]>2012-02-13 12:51:40 +0100
commitf2bc8fe1f93b5a112093d9507bdb397e3b390215 (patch)
tree9e257513cbde8da2c71c56220c6dd185b8d2bf0d
parentc996bcdc264070ada3abce85becece2e852f93a4 (diff)
OSX/Java7 JAWT/JAWTUtil: Support OSX/Java7 CALayer only JAWT mode; Cleanup JAWT/JAWTUtil
- Support OSX/Java7 CALayer only JAWT mode - Cleanup JAWT/JAWTUtil while moving elaborated logic and data to JAWTUtil, leave generated JAWT simple.
-rw-r--r--make/config/nativewindow/jawt-CustomJavaCode.java35
-rw-r--r--make/config/nativewindow/jawt-DrawingSurfaceInfo-CustomJavaCode.java2
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java77
3 files changed, 76 insertions, 38 deletions
diff --git a/make/config/nativewindow/jawt-CustomJavaCode.java b/make/config/nativewindow/jawt-CustomJavaCode.java
index d3dc3845f..6ea57dca2 100644
--- a/make/config/nativewindow/jawt-CustomJavaCode.java
+++ b/make/config/nativewindow/jawt-CustomJavaCode.java
@@ -1,38 +1,23 @@
-/** Available and recommended on Mac OS X >= 10.6 Update 4 */
-public static final int JAWT_MACOSX_USE_CALAYER = 0x80000000;
-public static final VersionNumber JAWT_MacOSXCALayerMinVersion = new VersionNumber(10,6,4);
-
private int jawt_version_cached = 0;
public final int getCachedVersion() {
return jawt_version_cached;
}
-/** Helper routine for all users to call to access the JAWT. */
-public static JAWT getJAWT(final int jawt_version_flags) {
+protected static boolean getJAWT(final JAWT jawt, final int jawt_version_flags) {
JAWTUtil.initSingleton();
// Workaround for 4845371.
// Make sure the first reference to the JNI GetDirectBufferAddress is done
// from a privileged context so the VM's internal class lookups will succeed.
- return AccessController.doPrivileged(new PrivilegedAction<JAWT>() {
- public JAWT run() {
- int jawt_version_flags_mod = jawt_version_flags;
- JAWT jawt = JAWT.create();
- if( 0 != ( jawt_version_flags_mod & JAWT_MACOSX_USE_CALAYER ) ) {
- jawt.setVersion(jawt_version_flags_mod);
- if (JAWTFactory.JAWT_GetAWT(jawt)) {
- jawt.jawt_version_cached = jawt.getVersion();
- return jawt;
- }
- jawt_version_flags_mod &= ~JAWT_MACOSX_USE_CALAYER;
- System.err.println("MacOSX "+Platform.OS_VERSION_NUMBER+" >= "+JAWT_MacOSXCALayerMinVersion+": Failed to use JAWT_MACOSX_USE_CALAYER");
- }
- jawt.setVersion(jawt_version_flags_mod);
- if (!JAWTFactory.JAWT_GetAWT(jawt)) {
- throw new RuntimeException("Unable to initialize JAWT: 0x"+Integer.toHexString(jawt_version_flags_mod));
+ return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+ public Boolean run() {
+ jawt.setVersion(jawt_version_flags);
+ if (JAWTFactory.JAWT_GetAWT(jawt)) {
+ jawt.jawt_version_cached = jawt.getVersion();
+ return new Boolean(true);
}
- jawt.jawt_version_cached = jawt.getVersion();
- return jawt;
+ jawt.jawt_version_cached = 0;
+ return new Boolean(false);
}
- });
+ }).booleanValue();
}
diff --git a/make/config/nativewindow/jawt-DrawingSurfaceInfo-CustomJavaCode.java b/make/config/nativewindow/jawt-DrawingSurfaceInfo-CustomJavaCode.java
index 4ff3a45b0..092aa5991 100644
--- a/make/config/nativewindow/jawt-DrawingSurfaceInfo-CustomJavaCode.java
+++ b/make/config/nativewindow/jawt-DrawingSurfaceInfo-CustomJavaCode.java
@@ -13,7 +13,7 @@ private static JAWT_PlatformInfo newPlatformInfo(JAWT jawt, ByteBuffer buf) {
if (Platform.OS_TYPE == Platform.OSType.WINDOWS) {
factoryClass = Class.forName("jogamp.nativewindow.jawt.windows.JAWT_Win32DrawingSurfaceInfo");
} else if (Platform.OS_TYPE == Platform.OSType.MACOS) {
- if( 0 != ( jawt.getCachedVersion() & JAWT.JAWT_MACOSX_USE_CALAYER ) ) {
+ if( 0 != ( jawt.getCachedVersion() & JAWTUtil.JAWT_MACOSX_USE_CALAYER ) ) {
factoryClass = Class.forName("jogamp.nativewindow.jawt.macosx.JAWT_SurfaceLayers");
} else {
factoryClass = Class.forName("jogamp.nativewindow.jawt.macosx.JAWT_MacOSXDrawingSurfaceInfo");
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
index 21e9a3e09..a9326cc4a 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
@@ -52,10 +52,20 @@ import javax.media.nativewindow.NativeWindowException;
import jogamp.nativewindow.Debug;
import com.jogamp.common.os.Platform;
+import com.jogamp.common.util.VersionNumber;
public class JAWTUtil {
protected static final boolean DEBUG = Debug.debug("JAWT");
+ /** OSX JAWT version option to use CALayer */
+ public static final int JAWT_MACOSX_USE_CALAYER = 0x80000000;
+
+ /** OSX JAWT CALayer availability on Mac OS X >= 10.6 Update 4 (recommended) */
+ public static final VersionNumber JAWT_MacOSXCALayerMinVersion = new VersionNumber(10,6,4);
+
+ /** OSX JAWT CALayer required with Java >= 1.7.0 (implies OS X >= 10.7 */
+ public static final VersionNumber JAWT_MacOSXCALayerRequiredForJavaVersion = new VersionNumber(1,7,0);
+
// See whether we're running in headless mode
private static final boolean headlessMode;
private static final JAWT jawtLockObject;
@@ -80,12 +90,19 @@ public class JAWTUtil {
}
/**
- * Returns true if this platform's JAWT implementation supports
- * or uses offscreen layer.
+ * Returns true if this platform's JAWT implementation supports offscreen layer.
*/
public static boolean isOffscreenLayerSupported() {
return Platform.OS_TYPE == Platform.OSType.MACOS &&
- Platform.OS_VERSION_NUMBER.compareTo(JAWT.JAWT_MacOSXCALayerMinVersion) >= 0;
+ Platform.OS_VERSION_NUMBER.compareTo(JAWTUtil.JAWT_MacOSXCALayerMinVersion) >= 0;
+ }
+
+ /**
+ * Returns true if this platform's JAWT implementation requires using offscreen layer.
+ */
+ public static boolean isOffscreenLayerRequired() {
+ return Platform.OS_TYPE == Platform.OSType.MACOS &&
+ Platform.JAVA_VERSION_NUMBER.compareTo(JAWT_MacOSXCALayerRequiredForJavaVersion)>=0;
}
/**
@@ -93,20 +110,56 @@ public class JAWTUtil {
* @return
*/
public static JAWT getJAWT(boolean useOffscreenLayerIfAvailable) {
- int jawt_version_flags = JAWTFactory.JAWT_VERSION_1_4;
- if(useOffscreenLayerIfAvailable) {
- switch(Platform.OS_TYPE) {
- case MACOS:
- if(Platform.OS_VERSION_NUMBER.compareTo(JAWT.JAWT_MacOSXCALayerMinVersion) >= 0) {
- jawt_version_flags |= JAWT.JAWT_MACOSX_USE_CALAYER;
- }
+ final int jawt_version_flags = JAWTFactory.JAWT_VERSION_1_4;
+ JAWT jawt = JAWT.create();
+
+ // default queries
+ boolean tryOffscreenLayer = false;
+ boolean tryOnscreenLayer = true;
+ int jawt_version_flags_offscreen = jawt_version_flags;
+
+ if(isOffscreenLayerRequired()) {
+ if(Platform.OS_TYPE == Platform.OSType.MACOS) {
+ if(Platform.OS_VERSION_NUMBER.compareTo(JAWTUtil.JAWT_MacOSXCALayerMinVersion) >= 0) {
+ jawt_version_flags_offscreen |= JAWTUtil.JAWT_MACOSX_USE_CALAYER;
+ tryOffscreenLayer = true;
+ tryOnscreenLayer = false;
+ } else {
+ throw new RuntimeException("OSX: Invalid version of Java ("+Platform.JAVA_VERSION_NUMBER+") / OS X ("+Platform.OS_VERSION_NUMBER+")");
+ }
+ } else {
+ throw new InternalError("offscreen required, but n/a for: "+Platform.OS_TYPE);
+ }
+ } else if(useOffscreenLayerIfAvailable && isOffscreenLayerSupported()) {
+ if(Platform.OS_TYPE == Platform.OSType.MACOS) {
+ jawt_version_flags_offscreen |= JAWTUtil.JAWT_MACOSX_USE_CALAYER;
+ tryOffscreenLayer = true;
+ } else {
+ throw new InternalError("offscreen requested and supported, but n/a for: "+Platform.OS_TYPE);
+ }
+ }
+
+ StringBuilder errsb = new StringBuilder();
+ if(tryOffscreenLayer) {
+ errsb.append("Offscreen 0x").append(Integer.toHexString(jawt_version_flags_offscreen));
+ if( JAWT.getJAWT(jawt, jawt_version_flags_offscreen) ) {
+ return jawt;
+ }
+ }
+ if(tryOnscreenLayer) {
+ if(tryOffscreenLayer) {
+ errsb.append(", ");
}
+ errsb.append("Onscreen 0x").append(Integer.toHexString(jawt_version_flags));
+ if( JAWT.getJAWT(jawt, jawt_version_flags) ) {
+ return jawt;
+ }
}
- return JAWT.getJAWT(jawt_version_flags);
+ throw new RuntimeException("Unable to initialize JAWT, trials: "+errsb.toString());
}
public static boolean isJAWTUsingOffscreenLayer(JAWT jawt) {
- return 0 != ( jawt.getCachedVersion() & JAWT.JAWT_MACOSX_USE_CALAYER );
+ return 0 != ( jawt.getCachedVersion() & JAWTUtil.JAWT_MACOSX_USE_CALAYER );
}
static {