aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-11-25 00:12:17 +0100
committerSven Gothel <[email protected]>2011-11-25 00:12:17 +0100
commitc84e235b3284d0e18481748b44594116e25821a9 (patch)
treee18d64647e830132389ef675d85cef13a080380f
parent3bc1ef8344ad44969ef436a0b98b0cde490a78fa (diff)
JOGL/NativeWindow: Push down JOGL's X11AWTGLXGraphicsConfigurationFactory to NativeWindow X11AWTGraphicsConfigurationFactory
X11AWTGraphicsConfigurationFactory properly construct a AWTGraphicsConfiguration encapsulated a native X11GraphicsConfiguration, now available for non JOGL modules, ie NEWT. AWTGraphicsConfiguration's create() utilizes the X11AWTGraphicsConfigurationFactory via the generic factory mechanism and hence allows encapsulating a native [X11]GraphicsConfiguration. NewtCanvasAWT creates/destroys the JAWT NativeWindow on addNotify/removeNotify (reparentWindow) again. Hence the JAWTWindow is instantiated completly only, instead of utilizing updateConfiguration(..), which simplifies the mechanism.
-rw-r--r--src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java29
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java11
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java2
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java71
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/x11/awt/X11AWTGraphicsConfigurationFactory.java (renamed from src/jogl/classes/jogamp/opengl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java)104
-rw-r--r--src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java40
-rw-r--r--src/newt/classes/jogamp/newt/awt/NewtFactoryAWT.java23
7 files changed, 109 insertions, 171 deletions
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
index 2147287ba..c43bc7864 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
@@ -48,7 +48,6 @@ import javax.media.opengl.*;
import jogamp.opengl.*;
-import com.jogamp.common.JogampRuntimeException;
import com.jogamp.common.util.*;
import jogamp.nativewindow.WrappedSurface;
import jogamp.nativewindow.x11.*;
@@ -88,13 +87,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
// Register our GraphicsConfigurationFactory implementations
// The act of constructing them causes them to be registered
X11GLXGraphicsConfigurationFactory.registerFactory();
- if(GLProfile.isAWTAvailable()) {
- try {
- ReflectionUtil.callStaticMethod("jogamp.opengl.x11.glx.awt.X11AWTGLXGraphicsConfigurationFactory",
- "registerFactory", null, null, getClass().getClassLoader());
- } catch (JogampRuntimeException jre) { /* n/a .. */ }
- }
-
+
defaultDevice = new X11GraphicsDevice(X11Util.getNullDisplayName(), AbstractGraphicsDevice.DEFAULT_UNIT);
// Init shared resources off thread
@@ -110,7 +103,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
SharedResourceImplementation sharedResourceImpl;
SharedResourceRunner sharedResourceRunner;
Thread sharedResourceThread;
- HashMap/*<connection, SharedResource>*/ sharedMap = new HashMap();
+ HashMap<String /* connection */, SharedResourceRunner.Resource> sharedMap = new HashMap<String, SharedResourceRunner.Resource>();
static class SharedResource implements SharedResourceRunner.Resource {
X11GraphicsDevice device;
@@ -156,23 +149,24 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
}
public SharedResourceRunner.Resource mapPut(String connection, SharedResourceRunner.Resource resource) {
synchronized(sharedMap) {
- return (SharedResourceRunner.Resource) sharedMap.put(connection, resource);
+ return sharedMap.put(connection, resource);
}
}
public SharedResourceRunner.Resource mapGet(String connection) {
synchronized(sharedMap) {
- return (SharedResourceRunner.Resource) sharedMap.get(connection);
+ return sharedMap.get(connection);
}
}
- public Collection/*<Resource>*/ mapValues() {
+ public Collection<SharedResourceRunner.Resource> mapValues() {
synchronized(sharedMap) {
return sharedMap.values();
}
}
public SharedResourceRunner.Resource createSharedResource(String connection) {
- X11GraphicsDevice sharedDevice = new X11GraphicsDevice(X11Util.openDisplay(connection), AbstractGraphicsDevice.DEFAULT_UNIT);
- sharedDevice.setCloseDisplay(true);
+ X11GraphicsDevice sharedDevice =
+ new X11GraphicsDevice(X11Util.openDisplay(connection), AbstractGraphicsDevice.DEFAULT_UNIT,
+ NativeWindowFactory.getNullToolkitLock(), true); // own non-shared display connection, no locking
sharedDevice.lock();
try {
String glXVendorName = GLXUtil.getVendorName(sharedDevice.getHandle());
@@ -421,10 +415,9 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
final X11GraphicsScreen sharedScreen = (X11GraphicsScreen) sr.getScreen();
final AbstractGraphicsDevice sharedDevice = sharedScreen.getDevice(); // should be same ..
- // create screen/device pair
- X11GraphicsDevice device = new X11GraphicsDevice(X11Util.openDisplay(sharedDevice.getConnection()), AbstractGraphicsDevice.DEFAULT_UNIT);
- device.setCloseDisplay(true);
- X11GraphicsScreen screen = new X11GraphicsScreen(device, sharedScreen.getIndex());
+ // create screen/device pair - Null X11 locking, due to private non-shared Display handle
+ final X11GraphicsDevice device = new X11GraphicsDevice(X11Util.openDisplay(sharedDevice.getConnection()), AbstractGraphicsDevice.DEFAULT_UNIT, NativeWindowFactory.getNullToolkitLock(), true);
+ final X11GraphicsScreen screen = new X11GraphicsScreen(device, sharedScreen.getIndex());
WrappedSurface ns = new WrappedSurface(
X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsChosen, capsRequested, chooser, screen) );
diff --git a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java
index 3f8746e2a..259644467 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java
@@ -40,7 +40,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-
/**
* Provides the mechanism by which the graphics configuration for a
* window can be chosen before the window is created. The graphics
@@ -81,10 +80,12 @@ public abstract class GraphicsConfigurationFactory {
} catch (Exception e) {
throw new RuntimeException(e);
}
- try {
- ReflectionUtil.callStaticMethod("jogamp.nativewindow.x11.awt.X11AWTGraphicsConfigurationFactory",
- "registerFactory", null, null, GraphicsConfigurationFactory.class.getClassLoader());
- } catch (Exception e) { /* n/a */ }
+ if(NativeWindowFactory.isAWTAvailable()) {
+ try {
+ ReflectionUtil.callStaticMethod("jogamp.nativewindow.x11.awt.X11AWTGraphicsConfigurationFactory",
+ "registerFactory", null, null, GraphicsConfigurationFactory.class.getClassLoader());
+ } catch (Exception e) { /* n/a */ }
+ }
}
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java b/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java
index d0b586f59..e255dc051 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java
@@ -169,7 +169,7 @@ public interface NativeSurface extends SurfaceUpdatedListener {
* Returns the graphics configuration corresponding to this window.
* <p>
* In case the implementation utilizes a delegation pattern to wrap abstract toolkits,
- * this method shall return the native {@link AbstractGraphicsConfiguration}.
+ * this method shall return the native {@link AbstractGraphicsConfiguration} via {@link AbstractGraphicsConfiguration#getNativeGraphicsConfiguration()}.
* </p>
* @see AbstractGraphicsConfiguration#getNativeGraphicsConfiguration()
* @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen)
diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
index 012c952f1..45a3db838 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java
@@ -47,6 +47,7 @@ import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.image.ColorModel;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
+
import jogamp.nativewindow.Debug;
/** A wrapper for an AWT GraphicsConfiguration allowing it to be
@@ -70,67 +71,39 @@ public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration imple
this.config = config;
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.
+ * with the graphics Capabilities of the AWT Component to produce the chosen Capabilities.
* Otherwise the <code>capsChosen</code> is used.
*/
- public static AWTGraphicsConfiguration create(Component awtComp, CapabilitiesImmutable capsChosen, CapabilitiesImmutable 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, AbstractGraphicsDevice.DEFAULT_UNIT);
- awtScreen = new AWTGraphicsScreen(awtDevice);
- }
+ public static AWTGraphicsConfiguration create(Component awtComp, CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested) {
+ final GraphicsConfiguration awtGfxConfig = awtComp.getGraphicsConfiguration();
+ if(null==awtGfxConfig) {
+ throw new NativeWindowException("AWTGraphicsConfiguration.create: Null AWT GraphicsConfiguration @ "+awtComp);
}
- if(null==awtScreen) {
- // use defaults since no native peer is available yet
- awtScreen = (AWTGraphicsScreen) AWTGraphicsScreen.createScreenDevice(-1, AbstractGraphicsDevice.DEFAULT_UNIT);
- awtDevice = (AWTGraphicsDevice) awtScreen.getDevice();
- awtGraphicsDevice = awtDevice.getGraphicsDevice();
+ final GraphicsDevice awtGraphicsDevice = awtGfxConfig.getDevice();
+ if(null==awtGraphicsDevice) {
+ throw new NativeWindowException("AWTGraphicsConfiguration.create: Null AWT GraphicsDevice @ "+awtGfxConfig);
}
+ // Create Device/Screen
+ final AWTGraphicsDevice awtDevice = new AWTGraphicsDevice(awtGraphicsDevice, AbstractGraphicsDevice.DEFAULT_UNIT);
+ final AWTGraphicsScreen awtScreen = new AWTGraphicsScreen(awtDevice);
+
if(null==capsChosen) {
GraphicsConfiguration gc = awtGraphicsDevice.getDefaultConfiguration();
- capsChosen = setupCapabilitiesRGBABits(capsRequested, gc);
+ capsChosen = AWTGraphicsConfiguration.setupCapabilitiesRGBABits(capsRequested, gc);
+ }
+ final GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(awtDevice);
+ final AbstractGraphicsConfiguration config = factory.chooseGraphicsConfiguration(capsChosen, capsRequested, null, awtScreen);
+ if(config instanceof AWTGraphicsConfiguration) {
+ return (AWTGraphicsConfiguration) config;
}
+ // System.err.println("Info: AWTGraphicsConfiguration.create: Expected AWTGraphicsConfiguration got: "+config.getClass()+" w/ factory "+factory.getClass()+" - Unable to encapsulate native GraphicsConfiguration.");
return new AWTGraphicsConfiguration(awtScreen, capsChosen, capsRequested, awtGfxConfig);
- // FIXME: use encapsulated X11 as used in X11AWTGLXGraphicsConfigurationFactory
}
- public void updateGraphicsConfiguration(Component awtComp)
- {
- 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, AbstractGraphicsDevice.DEFAULT_UNIT);
- awtScreen = new AWTGraphicsScreen(awtDevice);
- }
- }
- if(null==awtScreen) {
- throw new NativeWindowException("native peer n/a: "+awtComp);
- }
- config = awtGfxConfig;
- setScreen(awtScreen);
-
- CapabilitiesImmutable caps = ( null != getChosenCapabilities() ) ? getChosenCapabilities() : getRequestedCapabilities();
- GraphicsConfiguration gc = awtGraphicsDevice.getDefaultConfiguration();
- setChosenCapabilities(setupCapabilitiesRGBABits(caps, gc));
- // FIXME: use encapsulated X11 as used in X11AWTGLXGraphicsConfigurationFactory
- }
-
// open access to superclass method
public void setChosenCapabilities(CapabilitiesImmutable capsChosen) {
super.setChosenCapabilities(capsChosen);
@@ -190,7 +163,7 @@ public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration imple
return capabilities;
}
- @Override
+ @Override
public String toString() {
return getClass().getSimpleName()+"[" + getScreen() +
",\n\tchosen " + capabilitiesChosen+
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java b/src/nativewindow/classes/jogamp/nativewindow/x11/awt/X11AWTGraphicsConfigurationFactory.java
index 5ecbba505..252a97078 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/x11/awt/X11AWTGraphicsConfigurationFactory.java
@@ -31,67 +31,69 @@
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
-package jogamp.opengl.x11.glx.awt;
+package jogamp.nativewindow.x11.awt;
+import java.awt.Component;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
-import javax.media.nativewindow.*;
-import javax.media.nativewindow.x11.*;
-import javax.media.nativewindow.awt.*;
-import javax.media.opengl.*;
-import jogamp.opengl.*;
-import jogamp.nativewindow.jawt.x11.*;
-import jogamp.nativewindow.x11.*;
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.AbstractGraphicsScreen;
+import javax.media.nativewindow.CapabilitiesChooser;
+import javax.media.nativewindow.CapabilitiesImmutable;
+import javax.media.nativewindow.GraphicsConfigurationFactory;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.nativewindow.ToolkitLock;
+import javax.media.nativewindow.awt.AWTGraphicsConfiguration;
+import javax.media.nativewindow.awt.AWTGraphicsDevice;
+import javax.media.nativewindow.awt.AWTGraphicsScreen;
+import javax.media.nativewindow.x11.X11GraphicsConfiguration;
+import javax.media.nativewindow.x11.X11GraphicsDevice;
+import javax.media.nativewindow.x11.X11GraphicsScreen;
-public class X11AWTGLXGraphicsConfigurationFactory extends GLGraphicsConfigurationFactory {
- protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration");
+import jogamp.nativewindow.jawt.x11.X11SunJDKReflection;
+import jogamp.nativewindow.x11.X11Util;
+public class X11AWTGraphicsConfigurationFactory extends GraphicsConfigurationFactory {
+
public static void registerFactory() {
- GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.awt.AWTGraphicsDevice.class, new X11AWTGLXGraphicsConfigurationFactory());
+ GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.awt.AWTGraphicsDevice.class, new X11AWTGraphicsConfigurationFactory());
}
- private X11AWTGLXGraphicsConfigurationFactory() {
+ private X11AWTGraphicsConfigurationFactory() {
}
protected AbstractGraphicsConfiguration chooseGraphicsConfigurationImpl(
CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested,
- CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) {
- GraphicsDevice device = null;
+ CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) {
if (absScreen != null &&
!(absScreen instanceof AWTGraphicsScreen)) {
throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only AWTGraphicsScreen objects");
}
-
if(null==absScreen) {
- absScreen = AWTGraphicsScreen.createScreenDevice(-1, AbstractGraphicsDevice.DEFAULT_UNIT);
- }
- AWTGraphicsScreen awtScreen = (AWTGraphicsScreen) absScreen;
- device = ((AWTGraphicsDevice)awtScreen.getDevice()).getGraphicsDevice();
-
- if ( !(capsChosen instanceof GLCapabilitiesImmutable) ) {
- throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilities objects - chosen");
- }
-
- if ( !(capsRequested instanceof GLCapabilitiesImmutable) ) {
- throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilities objects - requested");
- }
-
- if (chooser != null &&
- !(chooser instanceof GLCapabilitiesChooser)) {
- throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilitiesChooser objects");
+ absScreen = AWTGraphicsScreen.createDefault();
}
+ return chooseGraphicsConfigurationStatic(capsChosen, capsRequested, chooser, (AWTGraphicsScreen)absScreen);
+ }
+
+ public static AWTGraphicsConfiguration chooseGraphicsConfigurationStatic(
+ CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested,
+ CapabilitiesChooser chooser, AWTGraphicsScreen awtScreen) {
if(DEBUG) {
- System.err.println("X11AWTGLXGraphicsConfigurationFactory: got "+absScreen);
+ System.err.println("X11AWTGraphicsConfigurationFactory: got "+awtScreen);
}
+ final GraphicsDevice device = ((AWTGraphicsDevice)awtScreen.getDevice()).getGraphicsDevice();
+
long displayHandle = X11SunJDKReflection.graphicsDeviceGetDisplay(device);
boolean owner = false;
if(0==displayHandle) {
displayHandle = X11Util.openDisplay(null);
owner = true;
if(DEBUG) {
- System.err.println(Thread.currentThread().getName() + " - X11AWTGLXGraphicsConfigurationFactory: create local X11 display");
+ System.err.println(Thread.currentThread().getName() + " - X11AWTGraphicsConfigurationFactory: create local X11 display");
}
} else {
/**
@@ -102,21 +104,29 @@ public class X11AWTGLXGraphicsConfigurationFactory extends GLGraphicsConfigurati
*/
final String displayName = X11Util.XDisplayString(displayHandle);
if(DEBUG) {
- System.err.println(Thread.currentThread().getName() + " - X11AWTGLXGraphicsConfigurationFactory: create X11 display @ "+displayName+" / 0x"+Long.toHexString(displayHandle));
+ System.err.println(Thread.currentThread().getName() + " - X11AWTGraphicsConfigurationFactory: create X11 display @ "+displayName+" / 0x"+Long.toHexString(displayHandle));
}
displayHandle = X11Util.openDisplay(displayName);
owner = true;
}
- ((AWTGraphicsDevice)awtScreen.getDevice()).setSubType(NativeWindowFactory.TYPE_X11, displayHandle);
- X11GraphicsDevice x11Device = new X11GraphicsDevice(displayHandle, AbstractGraphicsDevice.DEFAULT_UNIT);
- x11Device.setCloseDisplay(owner);
- X11GraphicsScreen x11Screen = new X11GraphicsScreen(x11Device, awtScreen.getIndex());
+ final ToolkitLock lock = owner ?
+ NativeWindowFactory.getNullToolkitLock() : // own non-shared X11 display connection, no lock
+ NativeWindowFactory.createDefaultToolkitLock(NativeWindowFactory.TYPE_X11, NativeWindowFactory.TYPE_AWT, displayHandle);
+ final X11GraphicsDevice x11Device = new X11GraphicsDevice(displayHandle, AbstractGraphicsDevice.DEFAULT_UNIT, lock, owner);
+ final X11GraphicsScreen x11Screen = new X11GraphicsScreen(x11Device, awtScreen.getIndex());
if(DEBUG) {
- System.err.println("X11AWTGLXGraphicsConfigurationFactory: made "+x11Screen);
+ System.err.println("X11AWTGraphicsConfigurationFactory: made "+x11Screen);
}
- GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(x11Device);
- GraphicsConfiguration[] configs = device.getConfigurations();
-
+
+ final GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(x11Device);
+ X11GraphicsConfiguration x11Config = (X11GraphicsConfiguration) factory.chooseGraphicsConfiguration(capsChosen, capsRequested, chooser, x11Screen);
+ if (x11Config == null) {
+ throw new NativeWindowException("Unable to choose a GraphicsConfiguration (1): "+capsChosen+",\n\t"+chooser+"\n\t"+x11Screen);
+ }
+ if(DEBUG) {
+ System.err.println("X11AWTGraphicsConfigurationFactory: chosen x11Config: "+x11Config);
+ }
+
//
// Match the X11/GL Visual with AWT:
// - choose a config AWT agnostic and then
@@ -124,11 +134,8 @@ public class X11AWTGLXGraphicsConfigurationFactory extends GLGraphicsConfigurati
//
// The resulting GraphicsConfiguration has to be 'forced' on the AWT native peer,
// ie. returned by GLCanvas's getGraphicsConfiguration() befor call by super.addNotify().
- //
- X11GraphicsConfiguration x11Config = (X11GraphicsConfiguration) factory.chooseGraphicsConfiguration(capsChosen, capsRequested, chooser, x11Screen);
- if (x11Config == null) {
- throw new GLException("Unable to choose a GraphicsConfiguration (1): "+capsChosen+",\n\t"+chooser+"\n\t"+x11Screen);
- }
+ //
+ final GraphicsConfiguration[] configs = device.getConfigurations();
long visualID = x11Config.getVisualID();
for (int i = 0; i < configs.length; i++) {
GraphicsConfiguration gc = configs[i];
@@ -149,7 +156,7 @@ public class X11AWTGLXGraphicsConfigurationFactory extends GLGraphicsConfigurati
capsChosen = AWTGraphicsConfiguration.setupCapabilitiesRGBABits(capsChosen, gc);
x11Config = (X11GraphicsConfiguration) factory.chooseGraphicsConfiguration(capsChosen, capsRequested, chooser, x11Screen);
if (x11Config == null) {
- throw new GLException("Unable to choose a GraphicsConfiguration (2): "+capsChosen+",\n\t"+chooser+"\n\t"+x11Screen);
+ throw new NativeWindowException("Unable to choose a GraphicsConfiguration (2): "+capsChosen+",\n\t"+chooser+"\n\t"+x11Screen);
}
visualID = x11Config.getVisualID();
for (int i = 0; i < configs.length; i++) {
@@ -175,3 +182,4 @@ public class X11AWTGLXGraphicsConfigurationFactory extends GLGraphicsConfigurati
return new AWTGraphicsConfiguration(awtScreen, x11Config.getChosenCapabilities(), x11Config.getRequestedCapabilities(), gc, x11Config);
}
}
+
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
index f56a95537..2506710f5 100644
--- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
+++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
@@ -41,8 +41,6 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Set;
-import javax.media.nativewindow.Capabilities;
-import javax.media.nativewindow.CapabilitiesImmutable;
import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.WindowClosingProtocol;
import javax.media.nativewindow.awt.AWTWindowClosingProtocol;
@@ -72,6 +70,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
public static final boolean DEBUG = Debug.debug("Window");
private JAWTWindow jawtWindow = null;
+ private boolean shallUseOffscreenLayer = false;
private Window newtChild = null;
private boolean isOnscreen = true;
private int newtChildCloseOp;
@@ -91,7 +90,6 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
*/
public NewtCanvasAWT() {
super();
- createNativeWindow(new Capabilities());
}
/**
@@ -99,23 +97,6 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
*/
public NewtCanvasAWT(GraphicsConfiguration gc) {
super(gc);
- createNativeWindow(new Capabilities());
- }
-
- /**
- * Instantiates a NewtCanvas without a NEWT child.<br>
- */
- public NewtCanvasAWT(CapabilitiesImmutable caps) {
- super();
- createNativeWindow(caps);
- }
-
- /**
- * Instantiates a NewtCanvas without a NEWT child.<br>
- */
- public NewtCanvasAWT(GraphicsConfiguration gc, CapabilitiesImmutable caps) {
- super(gc);
- createNativeWindow(caps);
}
/**
@@ -123,7 +104,6 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
*/
public NewtCanvasAWT(Window child) {
super();
- createNativeWindow(child.getRequestedCapabilities());
setNEWTChild(child);
}
@@ -132,14 +112,9 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
*/
public NewtCanvasAWT(GraphicsConfiguration gc, Window child) {
super(gc);
- createNativeWindow(child.getRequestedCapabilities());
setNEWTChild(child);
}
- private final void createNativeWindow(CapabilitiesImmutable caps) {
- jawtWindow = NewtFactoryAWT.getNativeWindow(this, caps);
- }
-
/**
* Request an JAWT offscreen layer if supported it.
* Shall be called before {@link #addNotify()} is issued,
@@ -148,7 +123,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
* @see #isOffscreenLayerSurface()
*/
public void setShallUseOffscreenLayer(boolean v) {
- jawtWindow.setShallUseOffscreenLayer(v);
+ shallUseOffscreenLayer = v;
}
/**
@@ -391,9 +366,10 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
newtChild.setFocusAction(null); // no AWT focus traversal ..
if(add) {
- NewtFactoryAWT.updateGraphicsConfiguration(jawtWindow, this);
+ jawtWindow = NewtFactoryAWT.getNativeWindow(this, newtChild.getRequestedCapabilities());
+ jawtWindow.setShallUseOffscreenLayer(shallUseOffscreenLayer);
if(DEBUG) {
- System.err.println("NewtCanvasAWT.reparentWindow: "+newtChild);
+ System.err.println("NewtCanvasAWT.reparentWindow: newtChild: "+newtChild);
}
final int w;
final int h;
@@ -424,9 +400,13 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
// since this it is completely covered by the newtChild (z-order).
setFocusable(true);
} else {
- configureNewtChild(false);
+ configureNewtChild(false);
newtChild.setVisible(false);
newtChild.reparentWindow(null);
+ if(null != jawtWindow) {
+ jawtWindow.destroy();
+ jawtWindow=null;
+ }
}
}
diff --git a/src/newt/classes/jogamp/newt/awt/NewtFactoryAWT.java b/src/newt/classes/jogamp/newt/awt/NewtFactoryAWT.java
index d4b2fd3d6..a551ae689 100644
--- a/src/newt/classes/jogamp/newt/awt/NewtFactoryAWT.java
+++ b/src/newt/classes/jogamp/newt/awt/NewtFactoryAWT.java
@@ -36,6 +36,7 @@ import javax.media.nativewindow.awt.*;
import com.jogamp.newt.NewtFactory;
import jogamp.nativewindow.jawt.JAWTWindow;
+import jogamp.nativewindow.x11.awt.X11AWTGraphicsConfigurationFactory;
import jogamp.newt.Debug;
public class NewtFactoryAWT extends NewtFactory {
@@ -64,7 +65,7 @@ public class NewtFactoryAWT extends NewtFactory {
}
public static JAWTWindow getNativeWindow(java.awt.Component awtComp, CapabilitiesImmutable capsRequested) {
- AWTGraphicsConfiguration config = AWTGraphicsConfiguration.create(awtComp, null, capsRequested);
+ AWTGraphicsConfiguration config = X11AWTGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(awtComp, null, capsRequested);
NativeWindow nw = NativeWindowFactory.getNativeWindow(awtComp, config); // a JAWTWindow
if(! ( nw instanceof JAWTWindow ) ) {
throw new NativeWindowException("Not an AWT NativeWindow: "+nw);
@@ -73,24 +74,6 @@ public class NewtFactoryAWT extends NewtFactory {
System.err.println("NewtFactoryAWT.getNativeWindow: "+awtComp+" -> "+nw);
}
return (JAWTWindow)nw;
- }
-
- public static void updateGraphicsConfiguration(JAWTWindow nw, java.awt.Component awtComp) {
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("NewtFactoryAWT.updateGraphicsConfiguration: (pre) "+awtComp+" -> "+nw);
- }
- final AWTGraphicsConfiguration awtConfig = (AWTGraphicsConfiguration) nw.getGraphicsConfiguration();
- awtConfig.updateGraphicsConfiguration(awtComp);
- // lockSurface() re-issues JAWTWindow's native validation
- if( NativeSurface.LOCK_SURFACE_NOT_READY >= nw.lockSurface() ) {
- throw new NativeWindowException("could not lock "+nw);
- }
- nw.unlockSurface();
-
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("NewtFactoryAWT.updateGraphicsConfiguration: (post) "+awtComp+" -> "+nw);
- }
- }
-
+ }
}