summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/newt/classes/com/jogamp/newt/opengl/GLWindow.java14
-rw-r--r--src/newt/classes/jogamp/newt/WindowImpl.java10
-rw-r--r--src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java42
-rw-r--r--src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java101
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestGearsNewtAWTWrapper.java68
6 files changed, 154 insertions, 83 deletions
diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
index a6c655915..de62747be 100644
--- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
+++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
@@ -40,7 +40,6 @@ import javax.media.nativewindow.CapabilitiesImmutable;
import javax.media.nativewindow.NativeSurface;
import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.NativeWindowException;
-import javax.media.nativewindow.NativeWindowFactory;
import javax.media.nativewindow.SurfaceUpdatedListener;
import javax.media.nativewindow.util.InsetsImmutable;
import javax.media.nativewindow.util.Point;
@@ -472,17 +471,16 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind
if( ( null != context ) ) {
throw new InternalError("GLWindow.LifecycleHook.setVisiblePost: "+WindowImpl.getThreadName()+" - Null drawable, but valid context - "+GLWindow.this);
}
- final NativeWindow nw;
- if (window.getWrappedWindow() != null) {
- nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow(), window.getPrivateGraphicsConfiguration());
- } else {
- nw = window;
+ final NativeSurface ns;
+ {
+ final NativeSurface wrapped_ns = window.getWrappedSurface();
+ ns = null != wrapped_ns ? wrapped_ns : window;
}
- final GLCapabilitiesImmutable glCaps = (GLCapabilitiesImmutable) nw.getGraphicsConfiguration().getChosenCapabilities();
+ final GLCapabilitiesImmutable glCaps = (GLCapabilitiesImmutable) ns.getGraphicsConfiguration().getChosenCapabilities();
if(null==factory) {
factory = GLDrawableFactory.getFactory(glCaps.getGLProfile());
}
- drawable = (GLDrawableImpl) factory.createGLDrawable(nw);
+ drawable = (GLDrawableImpl) factory.createGLDrawable(ns);
drawable.setRealized(true);
if( !GLWindow.this.pushGLEventListenerState() ) {
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index 01a58a305..bfb450f68 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -1562,9 +1562,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
return old;
}
- /** If this Window actually wraps one from another toolkit such as
- the AWT, this will return a non-null value. */
- public Object getWrappedWindow() {
+ /**
+ * If this Window actually wraps a {@link NativeSurface} from another instance or toolkit,
+ * it will return such reference. Otherwise returns null.
+ */
+ public NativeSurface getWrappedSurface() {
return null;
}
@@ -1598,7 +1600,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
"\n, Visible "+isVisible()+", focus "+hasFocus()+
"\n, Undecorated "+undecorated+" ("+isUndecorated()+")"+
"\n, AlwaysOnTop "+alwaysOnTop+", Fullscreen "+fullscreen+
- "\n, WrappedWindow "+getWrappedWindow()+
+ "\n, WrappedSurface "+getWrappedSurface()+
"\n, ChildWindows "+childWindows.size());
sb.append(", SurfaceUpdatedListeners num "+surfaceUpdatedHelper.size()+" [");
diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java
index 17eb6a2fb..85cb655d7 100644
--- a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java
+++ b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java
@@ -47,13 +47,15 @@ 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.NativeWindowException;
+import javax.media.nativewindow.NativeWindowFactory;
import javax.media.nativewindow.VisualIDHolder;
-
import com.jogamp.nativewindow.awt.AWTGraphicsConfiguration;
import com.jogamp.nativewindow.awt.AWTGraphicsDevice;
import com.jogamp.nativewindow.awt.AWTGraphicsScreen;
+import com.jogamp.nativewindow.awt.JAWTWindow;
import com.jogamp.newt.Window;
@SuppressWarnings("serial")
@@ -61,17 +63,15 @@ public class AWTCanvas extends Canvas {
private GraphicsDevice device;
private GraphicsConfiguration chosen;
private AWTGraphicsConfiguration awtConfig;
-
- private WindowDriver newtWindowImpl;
+ private volatile JAWTWindow jawtWindow=null; // the JAWTWindow presentation of this AWT Canvas, bound to the 'drawable' lifecycle
private CapabilitiesChooser chooser=null;
private CapabilitiesImmutable capabilities;
private boolean displayConfigChanged=false;
- public AWTCanvas(WindowDriver newtWindowImpl, CapabilitiesImmutable capabilities, CapabilitiesChooser chooser) {
+ public AWTCanvas(CapabilitiesImmutable capabilities, CapabilitiesChooser chooser) {
super();
- this.newtWindowImpl = newtWindowImpl;
if(null==capabilities) {
throw new NativeWindowException("Capabilities null");
}
@@ -89,7 +89,7 @@ public class AWTCanvas extends Canvas {
*/
@Override
public void update(Graphics g) {
- paint(g);
+ // paint(g);
}
/** Overridden to cause OpenGL rendering to be performed during
@@ -99,7 +99,6 @@ public class AWTCanvas extends Canvas {
*/
@Override
public void paint(Graphics g) {
- newtWindowImpl.windowRepaint(0, 0, getWidth(), getHeight());
}
public boolean hasDeviceChanged() {
@@ -120,8 +119,7 @@ public class AWTCanvas extends Canvas {
*/
awtConfig = chooseGraphicsConfiguration(capabilities, capabilities, chooser, device);
if(Window.DEBUG_IMPLEMENTATION) {
- Exception e = new Exception("Info: Created Config: "+awtConfig);
- e.printStackTrace();
+ System.err.println(getThreadName()+": AWTCanvas.addNotify.0: Created Config: "+awtConfig);
}
if(null==awtConfig) {
throw new NativeWindowException("Error: NULL AWTGraphicsConfiguration");
@@ -137,12 +135,27 @@ public class AWTCanvas extends Canvas {
// after native peer is valid: Windows
disableBackgroundErase();
+ {
+ jawtWindow = (JAWTWindow) NativeWindowFactory.getNativeWindow(this, awtConfig);
+ // trigger initialization cycle
+ jawtWindow.lockSurface();
+ jawtWindow.unlockSurface();
+ }
+
GraphicsConfiguration gc = super.getGraphicsConfiguration();
if(null!=gc) {
device = gc.getDevice();
}
+ if(Window.DEBUG_IMPLEMENTATION) {
+ System.err.println(getThreadName()+": AWTCanvas.addNotify.X");
+ }
}
+ public NativeSurface getNativeSurface() {
+ final JAWTWindow _jawtWindow = jawtWindow;
+ return (null != _jawtWindow) ? _jawtWindow : null;
+ }
+
public void removeNotify() {
try {
dispose();
@@ -152,6 +165,13 @@ public class AWTCanvas extends Canvas {
}
private void dispose() {
+ if( null != jawtWindow ) {
+ jawtWindow.destroy();
+ if(Window.DEBUG_IMPLEMENTATION) {
+ System.err.println(getThreadName()+": AWTCanvas.disposeJAWTWindowAndAWTDeviceOnEDT(): post JAWTWindow: "+jawtWindow);
+ }
+ jawtWindow=null;
+ }
if(null != awtConfig) {
AbstractGraphicsDevice adevice = awtConfig.getNativeGraphicsConfiguration().getScreen().getDevice();
String adeviceMsg=null;
@@ -160,10 +180,12 @@ public class AWTCanvas extends Canvas {
}
boolean closed = adevice.close();
if(Window.DEBUG_IMPLEMENTATION) {
- System.err.println("AWTCanvas.dispose(): closed GraphicsDevice: "+adeviceMsg+", result: "+closed);
+ System.err.println(getThreadName()+": AWTCanvas.dispose(): closed GraphicsDevice: "+adeviceMsg+", result: "+closed);
}
}
}
+
+ private String getThreadName() { return Thread.currentThread().getName(); }
/**
* Overridden to choose a GraphicsConfiguration on a parent container's
diff --git a/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java
index 0172309fb..cc678e4ef 100644
--- a/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java
@@ -40,6 +40,7 @@ import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Insets;
+import javax.media.nativewindow.NativeSurface;
import javax.media.nativewindow.NativeWindowException;
import javax.media.nativewindow.util.Point;
@@ -111,31 +112,38 @@ public class WindowDriver extends WindowImpl {
}
container.setLayout(new BorderLayout());
- canvas = new AWTCanvas(this, capsRequested, WindowDriver.this.capabilitiesChooser);
+ if( null == canvas ) {
+ canvas = new AWTCanvas(capsRequested, WindowDriver.this.capabilitiesChooser);
- // canvas.addComponentListener(listener);
- container.add(canvas, BorderLayout.CENTER);
+ // canvas.addComponentListener(listener);
+ container.add(canvas, 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
+ // 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
- // direct w/o EDT
- new AWTWindowAdapter(new LocalWindowListener(), this).addTo(canvas); // fwd all AWT Window events to here
+ // direct w/o EDT
+ new AWTWindowAdapter(new LocalWindowListener(), this).addTo(canvas); // fwd all AWT Window events to here
+ }
reconfigureWindowImpl(getX(), getY(), getWidth(), getHeight(), getReconfigureFlags(FLAG_CHANGE_VISIBILITY | FLAG_CHANGE_DECORATION, true));
// throws exception if failed ..
- setWindowHandle(1); // just a marker ..
+ final NativeSurface ns = canvas.getNativeSurface();
+ if( null != ns ) {
+ setGraphicsConfiguration( canvas.getAWTGraphicsConfiguration() );
+ setWindowHandle( ns.getSurfaceHandle() );
+ }
}
protected void closeNativeImpl() {
- setWindowHandle(0); // just a marker ..
+ setWindowHandle(0);
if(null!=container) {
container.setVisible(false);
container.remove(canvas);
container.setEnabled(false);
canvas.setEnabled(false);
+ canvas = null;
}
if(owningFrame && null!=frame) {
frame.dispose();
@@ -172,6 +180,10 @@ public class WindowDriver extends WindowImpl {
}
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());
@@ -182,26 +194,44 @@ public class WindowDriver extends WindowImpl {
}
}
- final Dimension szClient = new Dimension(width, height);
- canvas.setMinimumSize(szClient);
- canvas.setPreferredSize(szClient);
- canvas.setSize(szClient);
- if(DEBUG_IMPLEMENTATION) {
+ 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
+ } else {
+ container.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);
- System.err.println(getThreadName()+": AWTWindow new size: szClient "+szClient+", szCont "+szContainer+", insets "+insets);
- }
-
- if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
- if(null != frame) {
- frame.pack();
+ if(DEBUG_IMPLEMENTATION) {
+ final Dimension szClient = new Dimension(width, height);
+ System.err.println(getThreadName()+": AWTWindow new size: szClient "+szClient+", szCont "+szContainer+", insets "+insets);
}
- container.validate();
- container.setVisible(0 != ( FLAG_IS_VISIBLE & flags));
+ container.setSize(szContainer);
+ container.validate();
+ defineSize(width, height); // we are on AWT-EDT .. change values immediately
}
- container.setLocation(x, y);
+ if( container.getX() != x || container.getY() != y ) {
+ container.setLocation(x, y);
+ }
if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
if( 0 != ( FLAG_IS_VISIBLE & flags ) ) {
@@ -215,12 +245,6 @@ public class WindowDriver extends WindowImpl {
}
}
visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
- } else {
- container.invalidate();
- if(null != frame) {
- frame.pack();
- }
- container.validate();
}
return true;
@@ -233,8 +257,8 @@ public class WindowDriver extends WindowImpl {
}
@Override
- public Object getWrappedWindow() {
- return canvas;
+ public NativeSurface getWrappedSurface() {
+ return ( null != canvas ) ? canvas.getNativeSurface() : null;
}
class LocalWindowListener implements com.jogamp.newt.event.WindowListener {
@@ -247,7 +271,11 @@ public class WindowDriver extends WindowImpl {
@Override
public void windowResized(com.jogamp.newt.event.WindowEvent e) {
if(null!=canvas) {
- WindowDriver.this.sizeChanged(false, canvas.getWidth(), canvas.getHeight(), false);
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("Window Resized: "+canvas);
+ }
+ WindowDriver.this.sizeChanged(false, canvas.getWidth(), canvas.getHeight(), true);
+ WindowDriver.this.windowRepaint(false, 0, 0, getWidth(), getHeight());
}
}
@Override
@@ -268,7 +296,12 @@ public class WindowDriver extends WindowImpl {
}
@Override
public void windowRepaint(WindowUpdateEvent e) {
- WindowDriver.this.windowRepaint(false, 0, 0, getWidth(), getHeight());
+ if(null!=canvas) {
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("Window Repaint: "+canvas);
+ }
+ WindowDriver.this.windowRepaint(false, 0, 0, getWidth(), getHeight());
+ }
}
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
index 5e523c780..9bbbbce05 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
@@ -270,7 +270,7 @@ public class GearsES2 implements GLEventListener {
public void display(GLAutoDrawable drawable) {
GLAnimatorControl anim = drawable.getAnimator();
if( verbose && ( null == anim || !anim.isAnimating() ) ) {
- System.err.println(Thread.currentThread()+" GearsES2.display"+drawable.getWidth()+"x"+drawable.getHeight()+", swapInterval "+swapInterval+", drawable 0x"+Long.toHexString(drawable.getHandle()));
+ System.err.println(Thread.currentThread()+" GearsES2.display "+drawable.getWidth()+"x"+drawable.getHeight()+", swapInterval "+swapInterval+", drawable 0x"+Long.toHexString(drawable.getHandle()));
}
// Turn the gears' teeth
if(doRotate) {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestGearsNewtAWTWrapper.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestGearsNewtAWTWrapper.java
index cc20cc27e..0b907d5ee 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestGearsNewtAWTWrapper.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestGearsNewtAWTWrapper.java
@@ -34,6 +34,7 @@ import javax.media.opengl.*;
import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
import com.jogamp.opengl.test.junit.util.UITestCase;
import com.jogamp.opengl.test.junit.util.QuitAdapter;
import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
@@ -49,6 +50,9 @@ import org.junit.Test;
public class TestGearsNewtAWTWrapper extends UITestCase {
static GLProfile glp;
static int width, height;
+ static boolean useAnimator = true;
+ static boolean doResizeTest = true;
+ static long duration = 500; // ms
@BeforeClass
public static void initClass() {
@@ -73,39 +77,50 @@ public class TestGearsNewtAWTWrapper extends UITestCase {
glWindow.addGLEventListener(new GearsES2(1));
- Animator animator = new Animator(glWindow);
+ Animator animator = useAnimator ? new Animator(glWindow) : null;
QuitAdapter quitAdapter = new QuitAdapter();
glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
+ if( useAnimator ) {
+ animator.start();
+ }
+
int div = 3;
glWindow.setSize(width/div, height/div);
glWindow.setVisible(true);
- glWindow.display();
- Assert.assertTrue("Size not reached: Expected "+(width/div)+"x"+(height/div)+", Is "+glWindow.getWidth()+"x"+glWindow.getHeight(),
- AWTRobotUtil.waitForSize(glWindow, width/div, height/div));
-
- div = 2;
- glWindow.setSize(width/div, height/div);
- glWindow.display();
- Assert.assertTrue("Size not reached: Expected "+(width/div)+"x"+(height/div)+", Is "+glWindow.getWidth()+"x"+glWindow.getHeight(),
- AWTRobotUtil.waitForSize(glWindow, width/div, height/div));
-
- div = 1;
- glWindow.setSize(width/div, height/div);
- glWindow.display();
- Assert.assertTrue("Size not reached: Expected "+(width/div)+"x"+(height/div)+", Is "+glWindow.getWidth()+"x"+glWindow.getHeight(),
- AWTRobotUtil.waitForSize(glWindow, width/div, height/div));
-
- animator.setUpdateFPSFrames(1, null);
- animator.start();
+ if( doResizeTest ) {
+ glWindow.display();
+ Assert.assertTrue("Size not reached: Expected "+(width/div)+"x"+(height/div)+", Is "+glWindow.getWidth()+"x"+glWindow.getHeight(),
+ AWTRobotUtil.waitForSize(glWindow, width/div, height/div));
+ Thread.sleep(600);
+
+ div = 2;
+ glWindow.setSize(width/div, height/div);
+ glWindow.display();
+ Assert.assertTrue("Size not reached: Expected "+(width/div)+"x"+(height/div)+", Is "+glWindow.getWidth()+"x"+glWindow.getHeight(),
+ AWTRobotUtil.waitForSize(glWindow, width/div, height/div));
+ Thread.sleep(600);
+
+ div = 1;
+ glWindow.setSize(width/div, height/div);
+ glWindow.display();
+ Assert.assertTrue("Size not reached: Expected "+(width/div)+"x"+(height/div)+", Is "+glWindow.getWidth()+"x"+glWindow.getHeight(),
+ AWTRobotUtil.waitForSize(glWindow, width/div, height/div));
+ Thread.sleep(600);
+ }
- while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
+ final long t0 = System.currentTimeMillis();
+ long t1 = t0;
+ while(!quitAdapter.shouldQuit() && t1-t0<duration) {
Thread.sleep(100);
+ t1 = System.currentTimeMillis();
}
- animator.stop();
+ if( useAnimator ) {
+ animator.stop();
+ }
glWindow.destroy();
}
@@ -115,17 +130,18 @@ public class TestGearsNewtAWTWrapper extends UITestCase {
runTestGL(caps);
}
- static long duration = 500; // ms
-
public static void main(String args[]) {
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
i++;
- try {
- duration = Integer.parseInt(args[i]);
- } catch (Exception ex) { ex.printStackTrace(); }
+ duration = MiscUtils.atol(args[i], duration);
+ } else if(args[i].equals("-noanim")) {
+ useAnimator = false;
+ } else if(args[i].equals("-noresize")) {
+ doResizeTest = false;
}
}
+ System.err.println("useAnimator "+useAnimator);
org.junit.runner.JUnitCore.main(TestGearsNewtAWTWrapper.class.getName());
}
}