summaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-07-27 20:00:06 +0200
committerSven Gothel <[email protected]>2015-07-27 20:00:06 +0200
commit6ae08be1742e6d805b316c0d440364854a49e68f (patch)
tree666866771aeb8fe880fd810f5a664e8e0315a6e9 /src/nativewindow
parent8e1f5fc43ba84d5e6373f0c29089ac32b7ce95dd (diff)
Bug 1184 - JOGL AWT Canvas Components don't update AWTGraphicsConfiguration when reconfigured.
JOGL AWT Components, e.g. GLCanvas or NewtCanvasAWT, may be reconfigured by moving them to another display/monitor or by other means. Since AWT has no means to notify the user code via an event, JOGL components usually determine the reconfiguration via the override 'GraphicsConfiguration getGraphicsConfiguration()'. GLCanvas is sensible to this reconfiguration, however its AWTGraphicsConfiguration (owned via JAWTWindow) is not changed. Implement reconfiguration detection for all JOGL AWT Components and update the AWTGraphicsConfiguration if required. For now, constraint reconfiguration on GraphicsDevice change as currently implemented in GLCanvas. The updated AWTGraphicsConfiguration allows using the updated GraphicsDevice as it might be required for further information, e.g. pixel-scale on OSX.
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsConfiguration.java38
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java40
2 files changed, 64 insertions, 14 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsConfiguration.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsConfiguration.java
index 62fd49092..cc70b6b7b 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsConfiguration.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/AWTGraphicsConfiguration.java
@@ -73,19 +73,42 @@ public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration imple
}
/**
+ * @deprecated Use {@link #create(GraphicsConfiguration, CapabilitiesImmutable, CapabilitiesImmutable)}
+ * Method constructs a new {@link AWTGraphicsConfiguration} primarily based
+ * on the given {@link Component}'s {@link GraphicsConfiguration}.
+ * @param awtComp the {@link Component}, which {@link GraphicsConfiguration} is used for the resulting {@link AWTGraphicsConfiguration}
* @param capsChosen if null, <code>capsRequested</code> is copied and aligned
* with the graphics {@link Capabilities} of the AWT Component to produce the chosen {@link Capabilities}.
* Otherwise the <code>capsChosen</code> is used.
* @param capsRequested if null, default {@link Capabilities} are used, otherwise the given values.
*/
- public static AWTGraphicsConfiguration create(final Component awtComp, CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested) {
- final GraphicsConfiguration awtGfxConfig = awtComp.getGraphicsConfiguration();
- if(null==awtGfxConfig) {
- throw new NativeWindowException("AWTGraphicsConfiguration.create: Null AWT GraphicsConfiguration @ "+awtComp);
+ public static AWTGraphicsConfiguration create(final Component awtComp, final CapabilitiesImmutable capsChosen, final CapabilitiesImmutable capsRequested) {
+ if(null==awtComp) {
+ throw new IllegalArgumentException("Null AWT Component");
}
- final GraphicsDevice awtGraphicsDevice = awtGfxConfig.getDevice();
+ final GraphicsConfiguration gc = awtComp.getGraphicsConfiguration();
+ if( null == gc ) {
+ throw new NativeWindowException("Null AWT GraphicsConfiguration @ "+awtComp);
+ }
+ return create(gc, capsChosen, capsRequested);
+ }
+
+ /**
+ * Method constructs a new {@link AWTGraphicsConfiguration} primarily based
+ * on the given {@link GraphicsConfiguration}.
+ * @param gc the {@link GraphicsConfiguration} for the resulting {@link AWTGraphicsConfiguration}
+ * @param capsChosen if null, <code>capsRequested</code> is copied and aligned
+ * with the graphics {@link Capabilities} of the AWT Component to produce the chosen {@link Capabilities}.
+ * Otherwise the <code>capsChosen</code> is used.
+ * @param capsRequested if null, default {@link Capabilities} are used, otherwise the given values.
+ */
+ public static AWTGraphicsConfiguration create(final GraphicsConfiguration gc, CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested) {
+ if(null==gc) {
+ throw new IllegalArgumentException("Null AWT GraphicsConfiguration");
+ }
+ final GraphicsDevice awtGraphicsDevice = gc.getDevice();
if(null==awtGraphicsDevice) {
- throw new NativeWindowException("AWTGraphicsConfiguration.create: Null AWT GraphicsDevice @ "+awtGfxConfig);
+ throw new NativeWindowException("Null AWT GraphicsDevice @ "+gc);
}
// Create Device/Screen
@@ -96,7 +119,6 @@ public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration imple
capsRequested = new Capabilities();
}
if(null==capsChosen) {
- final GraphicsConfiguration gc = awtGraphicsDevice.getDefaultConfiguration();
capsChosen = AWTGraphicsConfiguration.setupCapabilitiesRGBABits(capsRequested, gc);
}
final GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(awtDevice, capsChosen);
@@ -105,7 +127,7 @@ public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration imple
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);
+ return new AWTGraphicsConfiguration(awtScreen, capsChosen, capsRequested, gc);
}
// open access to superclass method
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
index d315e1876..3a8cbefc6 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
@@ -49,7 +49,6 @@ import java.awt.Container;
import java.awt.Cursor;
import java.awt.EventQueue;
import java.awt.GraphicsConfiguration;
-import java.awt.Window;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.HierarchyEvent;
@@ -91,10 +90,10 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
// lifetime: forever
protected final Component component;
private final AppContextInfo appContextInfo;
- private final AWTGraphicsConfiguration config; // control access due to delegation
private final SurfaceUpdatedHelper surfaceUpdatedHelper = new SurfaceUpdatedHelper();
private final RecursiveLock surfaceLock = LockFactory.createRecursiveLock();
private final JAWTComponentListener jawtComponentListener;
+ private volatile AWTGraphicsConfiguration awtConfig; // control access through delegation
// lifetime: valid after lock but may change with each 1st lock, purges after invalidate
private boolean isApplet;
@@ -128,9 +127,9 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
}
appContextInfo = new AppContextInfo("<init>");
this.component = (Component)comp;
- this.config = (AWTGraphicsConfiguration) config;
this.jawtComponentListener = new JAWTComponentListener();
invalidate();
+ this.awtConfig = (AWTGraphicsConfiguration) config;
this.isApplet = false;
this.offscreenSurfaceLayer = 0;
}
@@ -265,6 +264,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
}
invalidateNative();
jawt = null;
+ awtConfig = null;
isOffscreenLayerSurface = false;
drawable= 0;
drawable_old = 0;
@@ -280,6 +280,34 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
}
protected abstract void invalidateNative();
+ /**
+ * Set a new {@link AWTGraphicsConfiguration} instance,
+ * as required if {@link #getAWTComponent() upstream component}'s {@link GraphicsConfiguration} has been changed
+ * due to reconfiguration, e.g. moving to a different monitor or changed capabilities.
+ * <p>
+ * {@link #getAWTComponent() Upstream component} shall override {@link Component#getGraphicsConfiguration()},
+ * which shall call this method if detecting a reconfiguration.
+ * See JOGL's GLCanvas and NewtCanvasAWT.
+ * </p>
+ * @param config the new {@link AWTGraphicsConfiguration}
+ * @see #getAWTGraphicsConfiguration()
+ */
+ public final void setAWTGraphicsConfiguration(final AWTGraphicsConfiguration config) {
+ if(DEBUG) {
+ System.err.println(jawtStr()+".setAWTGraphicsConfiguration(): "+this.awtConfig+" -> "+config);
+ // Thread.dumpStack();
+ }
+ this.awtConfig = config;
+ }
+ /**
+ * Return the current {@link AWTGraphicsConfiguration} instance,
+ * which also holds its {@link #getAWTComponent() upstream component}'s {@link GraphicsConfiguration}
+ * @see #setAWTGraphicsConfiguration(AWTGraphicsConfiguration)
+ */
+ public final AWTGraphicsConfiguration getAWTGraphicsConfiguration() {
+ return awtConfig;
+ }
+
@Override
public boolean setSurfaceScale(final float[] pixelScale) {
System.arraycopy(pixelScale, 0, reqPixelScale, 0, 2);
@@ -527,7 +555,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
@Override
public final void setChosenCapabilities(final CapabilitiesImmutable caps) {
((MutableGraphicsConfiguration)getGraphicsConfiguration()).setChosenCapabilities(caps);
- config.setChosenCapabilities(caps);
+ awtConfig.setChosenCapabilities(caps);
}
@Override
@@ -706,7 +734,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
@Override
public final AbstractGraphicsConfiguration getGraphicsConfiguration() {
- return config.getNativeGraphicsConfiguration();
+ return awtConfig.getNativeGraphicsConfiguration();
}
@Override
@@ -877,7 +905,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
"], pixels[scale "+getPixelScaleX()+", "+getPixelScaleY()+" -> "+getSurfaceWidth()+"x"+getSurfaceHeight()+"]"+
", visible "+component.isVisible());
sb.append(", lockedExt "+isSurfaceLockedByOtherThread()+
- ",\n\tconfig "+config+
+ ",\n\tconfig "+awtConfig+
",\n\tawtComponent "+getAWTComponent()+
",\n\tsurfaceLock "+surfaceLock+"]");