aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/classes')
-rw-r--r--src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java8
-rw-r--r--src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java181
2 files changed, 106 insertions, 83 deletions
diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java
index 85cb655d7..9a1632130 100644
--- a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java
+++ b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java
@@ -47,7 +47,7 @@ import javax.media.nativewindow.AbstractGraphicsScreen;
import javax.media.nativewindow.CapabilitiesChooser;
import javax.media.nativewindow.CapabilitiesImmutable;
import javax.media.nativewindow.GraphicsConfigurationFactory;
-import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.NativeWindowException;
import javax.media.nativewindow.NativeWindowFactory;
import javax.media.nativewindow.VisualIDHolder;
@@ -151,11 +151,15 @@ public class AWTCanvas extends Canvas {
}
}
- public NativeSurface getNativeSurface() {
+ public NativeWindow getNativeWindow() {
final JAWTWindow _jawtWindow = jawtWindow;
return (null != _jawtWindow) ? _jawtWindow : null;
}
+ public boolean isOffscreenLayerSurfaceEnabled() {
+ return null != jawtWindow ? jawtWindow.isOffscreenLayerSurfaceEnabled() : false;
+ }
+
public void removeNotify() {
try {
dispose();
diff --git a/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java
index cc678e4ef..c45a5ae3b 100644
--- a/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java
@@ -41,11 +41,14 @@ import java.awt.Frame;
import java.awt.Insets;
import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.NativeWindowException;
import javax.media.nativewindow.util.Point;
+import jogamp.nativewindow.awt.AWTMisc;
import jogamp.newt.WindowImpl;
+import com.jogamp.common.os.Platform;
import com.jogamp.nativewindow.awt.AWTGraphicsConfiguration;
import com.jogamp.nativewindow.awt.AWTGraphicsDevice;
import com.jogamp.nativewindow.awt.AWTGraphicsScreen;
@@ -71,25 +74,26 @@ public class WindowDriver extends WindowImpl {
public WindowDriver(Container container) {
super();
- this.container = container;
+ this.awtContainer = container;
if(container instanceof Frame) {
- frame = (Frame) container;
+ awtFrame = (Frame) container;
}
}
private boolean owningFrame;
- private Container container = null;
- private Frame frame = null; // same instance as container, just for impl. convenience
- private AWTCanvas canvas;
+ private Container awtContainer = null;
+ /** same instance as container, just for impl. convenience */
+ private Frame awtFrame = null;
+ private AWTCanvas awtCanvas;
protected void requestFocusImpl(boolean reparented) {
- container.requestFocus();
+ awtContainer.requestFocus();
}
@Override
protected void setTitleImpl(final String title) {
- if (frame != null) {
- frame.setTitle(title);
+ if (awtFrame != null) {
+ awtFrame.setTitle(title);
}
}
@@ -98,65 +102,66 @@ public class WindowDriver extends WindowImpl {
throw new RuntimeException("Window parenting not supported in AWT, use AWTWindow(Frame) cstr for wrapping instead");
}
- if(null==container) {
- frame = new Frame();
- container = frame;
+ if(null==awtContainer) {
+ awtFrame = new Frame();
+ awtContainer = awtFrame;
owningFrame=true;
} else {
owningFrame=false;
- defineSize(container.getWidth(), container.getHeight());
- definePosition(container.getX(), container.getY());
+ defineSize(awtContainer.getWidth(), awtContainer.getHeight());
+ definePosition(awtContainer.getX(), awtContainer.getY());
}
- if(null!=frame) {
- frame.setTitle(getTitle());
+ if(null!=awtFrame) {
+ awtFrame.setTitle(getTitle());
}
- container.setLayout(new BorderLayout());
+ awtContainer.setLayout(new BorderLayout());
- if( null == canvas ) {
- canvas = new AWTCanvas(capsRequested, WindowDriver.this.capabilitiesChooser);
+ if( null == awtCanvas ) {
+ awtCanvas = new AWTCanvas(capsRequested, WindowDriver.this.capabilitiesChooser);
// canvas.addComponentListener(listener);
- container.add(canvas, BorderLayout.CENTER);
+ awtContainer.add(awtCanvas, BorderLayout.CENTER);
// via EDT ..
- new AWTMouseAdapter(this).addTo(canvas); // fwd all AWT Mouse events to here
- new AWTKeyAdapter(this).addTo(canvas); // fwd all AWT Key events to here
+ new AWTMouseAdapter(this).addTo(awtCanvas); // fwd all AWT Mouse events to here
+ new AWTKeyAdapter(this).addTo(awtCanvas); // fwd all AWT Key events to here
// direct w/o EDT
- new AWTWindowAdapter(new LocalWindowListener(), this).addTo(canvas); // fwd all AWT Window events to here
+ new AWTWindowAdapter(new LocalWindowListener(), this).addTo(awtCanvas); // fwd all AWT Window events to here
}
reconfigureWindowImpl(getX(), getY(), getWidth(), getHeight(), getReconfigureFlags(FLAG_CHANGE_VISIBILITY | FLAG_CHANGE_DECORATION, true));
// throws exception if failed ..
- final NativeSurface ns = canvas.getNativeSurface();
- if( null != ns ) {
- setGraphicsConfiguration( canvas.getAWTGraphicsConfiguration() );
- setWindowHandle( ns.getSurfaceHandle() );
+ final NativeWindow nw = awtCanvas.getNativeWindow();
+ if( null != nw ) {
+ setGraphicsConfiguration( awtCanvas.getAWTGraphicsConfiguration() );
+ setWindowHandle( nw.getWindowHandle() );
}
}
protected void closeNativeImpl() {
setWindowHandle(0);
- if(null!=container) {
- container.setVisible(false);
- container.remove(canvas);
- container.setEnabled(false);
- canvas.setEnabled(false);
- canvas = null;
+ if(null!=awtContainer) {
+ awtContainer.setVisible(false);
+ awtContainer.remove(awtCanvas);
+ awtContainer.setEnabled(false);
+ awtCanvas.setEnabled(false);
}
- if(owningFrame && null!=frame) {
- frame.dispose();
+ if(owningFrame && null!=awtFrame) {
+ awtFrame.dispose();
owningFrame=false;
- frame = null;
}
+ awtCanvas = null;
+ awtFrame = null;
+ awtContainer = null;
}
@Override
public boolean hasDeviceChanged() {
- boolean res = canvas.hasDeviceChanged();
+ boolean res = awtCanvas.hasDeviceChanged();
if(res) {
- final AWTGraphicsConfiguration cfg = canvas.getAWTGraphicsConfiguration();
+ final AWTGraphicsConfiguration cfg = awtCanvas.getAWTGraphicsConfiguration();
if (null == cfg) {
throw new NativeWindowException("Error Device change null GraphicsConfiguration: "+this);
}
@@ -172,21 +177,54 @@ public class WindowDriver extends WindowImpl {
}
protected void updateInsetsImpl(javax.media.nativewindow.util.Insets insets) {
- Insets contInsets = container.getInsets();
+ Insets contInsets = awtContainer.getInsets();
insets.setLeftWidth(contInsets.left);
insets.setRightWidth(contInsets.right);
insets.setTopHeight(contInsets.top);
insets.setBottomHeight(contInsets.bottom);
}
+ private void setCanvasSizeImpl(int width, int height) {
+ final Dimension szClient = new Dimension(width, height);
+ final java.awt.Window awtWindow = AWTMisc.getWindow(awtCanvas);
+ final Container c= null != awtWindow ? awtWindow : awtContainer;
+ awtCanvas.setMinimumSize(szClient);
+ awtCanvas.setPreferredSize(szClient);
+ if(DEBUG_IMPLEMENTATION) {
+ final Insets insets = c.getInsets();
+ final Dimension szContainer = new Dimension(width + insets.left + insets.right,
+ height + insets.top + insets.bottom);
+ System.err.println(getThreadName()+": AWTWindow setCanvasSize: szClient "+szClient+", szCont "+szContainer+", insets "+insets);
+ }
+ awtCanvas.setSize(szClient);
+ awtCanvas.invalidate();
+ if(null != awtWindow) {
+ awtWindow.pack();
+ } else {
+ awtContainer.validate();
+ }
+ }
+ private void setFrameSizeImpl(int width, int height) {
+ final Insets insets = awtContainer.getInsets();
+ final Dimension szContainer = new Dimension(width + insets.left + insets.right,
+ height + insets.top + insets.bottom);
+ if(DEBUG_IMPLEMENTATION) {
+ final Dimension szClient = new Dimension(width, height);
+ System.err.println(getThreadName()+": AWTWindow setFrameSize: szClient "+szClient+", szCont "+szContainer+", insets "+insets);
+ }
+ awtContainer.setSize(szContainer);
+ awtCanvas.invalidate();
+ awtContainer.validate();
+ }
+
protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
if(DEBUG_IMPLEMENTATION) {
System.err.println("AWTWindow reconfig: "+x+"/"+y+" "+width+"x"+height+", "+
getReconfigureFlagsAsString(null, flags));
}
- if(0 != ( FLAG_CHANGE_DECORATION & flags) && null!=frame) {
- if(!container.isDisplayable()) {
- frame.setUndecorated(isUndecorated());
+ if(0 != ( FLAG_CHANGE_DECORATION & flags) && null!=awtFrame) {
+ if(!awtContainer.isDisplayable()) {
+ awtFrame.setUndecorated(isUndecorated());
} else {
if(DEBUG_IMPLEMENTATION) {
System.err.println(getThreadName()+": AWTWindow can't undecorate already created frame");
@@ -196,48 +234,29 @@ public class WindowDriver extends WindowImpl {
if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
if( 0 != ( FLAG_IS_VISIBLE & flags) ) {
- final Dimension szClient = new Dimension(width, height);
- canvas.setMinimumSize(szClient);
- canvas.setPreferredSize(szClient);
- if(DEBUG_IMPLEMENTATION) {
- final Insets insets = container.getInsets();
- final Dimension szContainer = new Dimension(width + insets.left + insets.right,
- height + insets.top + insets.bottom);
- System.err.println(getThreadName()+": AWTWindow initial size: szClient "+szClient+", szCont "+szContainer+", insets "+insets);
- }
- canvas.setSize(szClient);
- if(null != frame) {
- frame.pack();
- } else {
- container.validate();
- }
- container.setVisible( true );
- defineSize(width, height); // we are on AWT-EDT .. change values immediately
+ setCanvasSizeImpl(width, height);
+ awtContainer.setVisible( true );
} else {
- container.setVisible( false );
+ awtContainer.setVisible( false );
}
- } else if( canvas.getWidth() != width || canvas.getHeight() != height ) {
- final Insets insets = container.getInsets();
- final Dimension szContainer = new Dimension(width + insets.left + insets.right,
- height + insets.top + insets.bottom);
- if(DEBUG_IMPLEMENTATION) {
- final Dimension szClient = new Dimension(width, height);
- System.err.println(getThreadName()+": AWTWindow new size: szClient "+szClient+", szCont "+szContainer+", insets "+insets);
+ } else if( awtCanvas.getWidth() != width || awtCanvas.getHeight() != height ) {
+ if( Platform.OSType.MACOS == Platform.getOSType() && awtCanvas.isOffscreenLayerSurfaceEnabled() ) {
+ setFrameSizeImpl(width, height);
+ } else {
+ setCanvasSizeImpl(width, height);
}
- container.setSize(szContainer);
- container.validate();
- defineSize(width, height); // we are on AWT-EDT .. change values immediately
}
+ defineSize(width, height); // we are on AWT-EDT .. change values immediately
- if( container.getX() != x || container.getY() != y ) {
- container.setLocation(x, y);
+ if( awtContainer.getX() != x || awtContainer.getY() != y ) {
+ awtContainer.setLocation(x, y);
}
if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
if( 0 != ( FLAG_IS_VISIBLE & flags ) ) {
if( !hasDeviceChanged() ) {
// oops ??
- final AWTGraphicsConfiguration cfg = canvas.getAWTGraphicsConfiguration();
+ final AWTGraphicsConfiguration cfg = awtCanvas.getAWTGraphicsConfiguration();
if(null == cfg) {
throw new NativeWindowException("Error: !hasDeviceChanged && null == GraphicsConfiguration: "+this);
}
@@ -251,30 +270,30 @@ public class WindowDriver extends WindowImpl {
}
protected Point getLocationOnScreenImpl(int x, int y) {
- java.awt.Point ap = canvas.getLocationOnScreen();
+ java.awt.Point ap = awtCanvas.getLocationOnScreen();
ap.translate(x, y);
return new Point((int)(ap.getX()+0.5),(int)(ap.getY()+0.5));
}
@Override
public NativeSurface getWrappedSurface() {
- return ( null != canvas ) ? canvas.getNativeSurface() : null;
+ return ( null != awtCanvas ) ? awtCanvas.getNativeWindow() : null;
}
class LocalWindowListener implements com.jogamp.newt.event.WindowListener {
@Override
public void windowMoved(com.jogamp.newt.event.WindowEvent e) {
- if(null!=container) {
- WindowDriver.this.positionChanged(false, container.getX(), container.getY());
+ if(null!=awtContainer) {
+ WindowDriver.this.positionChanged(false, awtContainer.getX(), awtContainer.getY());
}
}
@Override
public void windowResized(com.jogamp.newt.event.WindowEvent e) {
- if(null!=canvas) {
+ if(null!=awtCanvas) {
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window Resized: "+canvas);
+ System.err.println("Window Resized: "+awtCanvas);
}
- WindowDriver.this.sizeChanged(false, canvas.getWidth(), canvas.getHeight(), true);
+ WindowDriver.this.sizeChanged(false, awtCanvas.getWidth(), awtCanvas.getHeight(), true);
WindowDriver.this.windowRepaint(false, 0, 0, getWidth(), getHeight());
}
}
@@ -296,9 +315,9 @@ public class WindowDriver extends WindowImpl {
}
@Override
public void windowRepaint(WindowUpdateEvent e) {
- if(null!=canvas) {
+ if(null!=awtCanvas) {
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window Repaint: "+canvas);
+ System.err.println("Window Repaint: "+awtCanvas);
}
WindowDriver.this.windowRepaint(false, 0, 0, getWidth(), getHeight());
}