aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes/javax/media
diff options
context:
space:
mode:
Diffstat (limited to 'src/nativewindow/classes/javax/media')
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java23
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java36
2 files changed, 48 insertions, 11 deletions
diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
index 944fdee74..2125fb4c0 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
@@ -74,6 +74,8 @@ public abstract class NativeWindowFactory {
private static String nativeOSNamePure;
private static String nativeWindowingTypeCustom;
private static String nativeOSNameCustom;
+ private static final boolean isAWTAvailable;
+ private static final String awtComponentClassName = "java.awt.Component" ;
/** Creates a new NativeWindowFactory instance. End users do not
need to call this method. */
@@ -123,21 +125,17 @@ public abstract class NativeWindowFactory {
// We break compile-time dependencies on the AWT here to
// make it easier to run this code on mobile devices
- Class componentClass = null;
- if ( ReflectionUtil.isClassAvailable("java.awt.Component") &&
- ReflectionUtil.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") ) {
- try {
- componentClass = ReflectionUtil.getClass("java.awt.Component", false);
- } catch (Exception e) { }
- }
+ isAWTAvailable = !Debug.getBooleanProperty("java.awt.headless", true, acc) &&
+ ReflectionUtil.isClassAvailable(awtComponentClassName) &&
+ ReflectionUtil.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") ;
boolean toolkitLockForced = Debug.getBooleanProperty("nativewindow.locking", true, acc);
- boolean awtToolkitLockDisabled = Debug.getBooleanProperty("java.awt.headless", true, acc) ||
+ boolean awtToolkitLockDisabled = !isAWTAvailable ||
Debug.getBooleanProperty("nativewindow.nolocking", true, acc) ;
NativeWindowFactory _factory = null;
- if( !awtToolkitLockDisabled && null!=componentClass && TYPE_X11.equals(nativeWindowingTypeCustom) ) {
+ if( !awtToolkitLockDisabled && TYPE_X11.equals(nativeWindowingTypeCustom) ) {
// There are certain operations that may be done by
// user-level native code which must share the display
// connection with the underlying window toolkit. In JOGL,
@@ -195,9 +193,9 @@ public abstract class NativeWindowFactory {
factory = _factory;
}
- if(null!=componentClass) {
+ if ( isAWTAvailable ) {
// register either our default factory or (if exist) the X11/AWT one -> AWT Component
- registerFactory(componentClass, factory);
+ registerFactory(ReflectionUtil.getClass(awtComponentClassName, false), factory);
}
defaultFactory = factory;
@@ -207,6 +205,9 @@ public abstract class NativeWindowFactory {
}
}
+ /** @return true if not headless, AWT Component and NativeWindow's AWT part available */
+ public static boolean isAWTAvailable() { return isAWTAvailable; }
+
public static String getNativeOSName(boolean useCustom) {
return useCustom?nativeOSNameCustom:nativeOSNamePure;
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
index 9b48f8f6e..f56248e67 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
@@ -40,7 +40,9 @@
package javax.media.nativewindow.awt;
import javax.media.nativewindow.*;
+import java.awt.Component;
import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
import java.awt.Transparency;
import java.awt.image.ColorModel;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
@@ -67,6 +69,40 @@ public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration imple
this.encapsulated=null;
}
+ /**
+ * @param capsChosen if null, <code>capsRequested</code> is copied and aligned
+ * with the graphics capabilties of the AWT Component to produce the chosen Capabilties.
+ * Otherwise the <code>capsChosen</code> is used.
+ */
+ public static AWTGraphicsConfiguration create(Component awtComp, Capabilities capsChosen, Capabilities capsRequested)
+ {
+ AWTGraphicsScreen awtScreen = null;
+ AWTGraphicsDevice awtDevice = null;
+ GraphicsDevice awtGraphicsDevice = null;
+ GraphicsConfiguration awtGfxConfig = awtComp.getGraphicsConfiguration();
+ if(null!=awtGfxConfig) {
+ awtGraphicsDevice = awtGfxConfig.getDevice();
+ if(null!=awtGraphicsDevice) {
+ // Create Device/Screen
+ awtDevice = new AWTGraphicsDevice(awtGraphicsDevice);
+ awtScreen = new AWTGraphicsScreen(awtDevice);
+ }
+ }
+ if(null==awtScreen) {
+ // use defaults since no native peer is available yet
+ awtScreen = (AWTGraphicsScreen) AWTGraphicsScreen.createScreenDevice(-1);
+ awtDevice = (AWTGraphicsDevice) awtScreen.getDevice();
+ awtGraphicsDevice = awtDevice.getGraphicsDevice();
+ }
+
+ if(null==capsChosen) {
+ capsChosen = (Capabilities) capsRequested.clone() ;
+ GraphicsConfiguration gc = awtGraphicsDevice.getDefaultConfiguration();
+ setupCapabilitiesRGBABits(capsChosen, gc);
+ }
+ return new AWTGraphicsConfiguration(awtScreen, capsChosen, capsRequested, awtGfxConfig);
+ }
+
public Object clone() {
return super.clone();
}