aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-09-07 08:34:32 +0200
committerSven Gothel <[email protected]>2012-09-07 08:34:32 +0200
commitd22ac65d0f841e4c3698ec817d4ebbfdb7ee25a0 (patch)
treed5248185201aaad6bd4583e3c2226e0db653f9fc /src
parent1b6593f973970ad00a0a0f08b56cc83501a55ad2 (diff)
NEWT AWT Driver: Remove flashing (clear background @ update/paint method) ; Proper canvas size and direct events.
Diffstat (limited to 'src')
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java28
-rw-r--r--src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java28
-rw-r--r--src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java78
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestGearsNewtAWTWrapper.java20
4 files changed, 129 insertions, 25 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java
index 69b0d0482..2d63ca455 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java
@@ -28,6 +28,8 @@
package com.jogamp.newt.event.awt;
+import java.awt.Dimension;
+
import jogamp.newt.awt.event.AWTNewtEventFactory;
public class AWTWindowAdapter
@@ -61,9 +63,9 @@ public class AWTWindowAdapter
if(awtComponent instanceof java.awt.Window) {
((java.awt.Window)awtComponent).addWindowListener(this);
}
- return this;
+ return this;
}
-
+
public AWTAdapter removeFrom(java.awt.Component awtComponent) {
awtComponent.removeFocusListener(this);
awtComponent.removeComponentListener(this);
@@ -89,6 +91,9 @@ public class AWTWindowAdapter
public void focusGained(java.awt.event.FocusEvent e) {
com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("AWT: focusGained: "+e+" -> "+event);
+ }
if(null!=newtListener) {
((com.jogamp.newt.event.WindowListener)newtListener).windowGainedFocus(event);
} else {
@@ -98,6 +103,9 @@ public class AWTWindowAdapter
public void focusLost(java.awt.event.FocusEvent e) {
com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("AWT: focusLost: "+e+" -> "+event);
+ }
if(null!=newtListener) {
((com.jogamp.newt.event.WindowListener)newtListener).windowLostFocus(event);
} else {
@@ -108,7 +116,19 @@ public class AWTWindowAdapter
public void componentResized(java.awt.event.ComponentEvent e) {
com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
if(DEBUG_IMPLEMENTATION) {
- System.err.println("AWT: componentResized: "+event);
+ final java.awt.Component c = e.getComponent();
+ final java.awt.Dimension sz = c.getSize();
+ final java.awt.Insets insets;
+ final java.awt.Dimension sz2;
+ if(c instanceof java.awt.Container) {
+ insets = ((java.awt.Container)c).getInsets();
+ sz2 = new Dimension(sz.width - insets.left - insets.right,
+ sz.height - insets.top - insets.bottom);
+ } else {
+ insets = null;
+ sz2 = sz;
+ }
+ System.err.println("AWT: componentResized: "+sz+" ( "+insets+", "+sz2+" ), "+e+" -> "+event);
}
if(null!=newtListener) {
((com.jogamp.newt.event.WindowListener)newtListener).windowResized(event);
@@ -120,7 +140,7 @@ public class AWTWindowAdapter
public void componentMoved(java.awt.event.ComponentEvent e) {
com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
if(DEBUG_IMPLEMENTATION) {
- System.err.println("AWT: componentMoved: "+event);
+ System.err.println("AWT: componentMoved: "+e+" -> "+event);
}
if(null!=newtListener) {
((com.jogamp.newt.event.WindowListener)newtListener).windowMoved(event);
diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java
index b3fdcad41..17eb6a2fb 100644
--- a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java
+++ b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java
@@ -35,6 +35,7 @@
package jogamp.newt.driver.awt;
import java.awt.Canvas;
+import java.awt.Graphics;
import java.awt.GraphicsDevice;
import java.awt.GraphicsConfiguration;
import java.lang.reflect.Method;
@@ -61,14 +62,16 @@ public class AWTCanvas extends Canvas {
private GraphicsConfiguration chosen;
private AWTGraphicsConfiguration awtConfig;
+ private WindowDriver newtWindowImpl;
private CapabilitiesChooser chooser=null;
private CapabilitiesImmutable capabilities;
private boolean displayConfigChanged=false;
- public AWTCanvas(CapabilitiesImmutable capabilities, CapabilitiesChooser chooser) {
+ public AWTCanvas(WindowDriver newtWindowImpl, CapabilitiesImmutable capabilities, CapabilitiesChooser chooser) {
super();
+ this.newtWindowImpl = newtWindowImpl;
if(null==capabilities) {
throw new NativeWindowException("Capabilities null");
}
@@ -80,6 +83,25 @@ public class AWTCanvas extends Canvas {
return awtConfig;
}
+ /**
+ * Overridden from Canvas to prevent the AWT's clearing of the
+ * canvas from interfering with the OpenGL rendering.
+ */
+ @Override
+ public void update(Graphics g) {
+ paint(g);
+ }
+
+ /** Overridden to cause OpenGL rendering to be performed during
+ repaint cycles. Subclasses which override this method must call
+ super.paint() in their paint() method in order to function
+ properly.
+ */
+ @Override
+ public void paint(Graphics g) {
+ newtWindowImpl.windowRepaint(0, 0, getWidth(), getHeight());
+ }
+
public boolean hasDeviceChanged() {
boolean res = displayConfigChanged;
displayConfigChanged=false;
@@ -275,10 +297,10 @@ public class AWTCanvas extends Canvas {
private void disableBackgroundErase() {
if (!disableBackgroundEraseInitialized) {
try {
- AccessController.doPrivileged(new PrivilegedAction() {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
try {
- Class clazz = getToolkit().getClass();
+ Class<?> clazz = getToolkit().getClass();
while (clazz != null && disableBackgroundEraseMethod == null) {
try {
disableBackgroundEraseMethod =
diff --git a/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java
index 1723ffee5..bee43a95e 100644
--- a/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java
@@ -36,6 +36,7 @@ package jogamp.newt.driver.awt;
import java.awt.BorderLayout;
import java.awt.Container;
+import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Insets;
@@ -47,6 +48,8 @@ import jogamp.newt.WindowImpl;
import com.jogamp.nativewindow.awt.AWTGraphicsConfiguration;
import com.jogamp.nativewindow.awt.AWTGraphicsDevice;
import com.jogamp.nativewindow.awt.AWTGraphicsScreen;
+import com.jogamp.newt.event.WindowEvent;
+import com.jogamp.newt.event.WindowUpdateEvent;
import com.jogamp.newt.event.awt.AWTKeyAdapter;
import com.jogamp.newt.event.awt.AWTMouseAdapter;
import com.jogamp.newt.event.awt.AWTWindowAdapter;
@@ -107,18 +110,18 @@ public class WindowDriver extends WindowImpl {
frame.setTitle(getTitle());
}
container.setLayout(new BorderLayout());
- canvas = new AWTCanvas(capsRequested, WindowDriver.this.capabilitiesChooser);
-
- addWindowListener(new LocalWindowListener());
-
- new AWTMouseAdapter(this).addTo(canvas); // fwd all AWT Mouse events to here
- new AWTKeyAdapter(this).addTo(canvas); // fwd all AWT Key events to here
+
+ canvas = new AWTCanvas(this, capsRequested, WindowDriver.this.capabilitiesChooser);
// canvas.addComponentListener(listener);
container.add(canvas, BorderLayout.CENTER);
- container.setSize(getWidth(), getHeight());
- container.setLocation(getX(), getY());
- new AWTWindowAdapter(this).addTo(container); // fwd all AWT Window 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
reconfigureWindowImpl(getX(), getY(), getWidth(), getHeight(), getReconfigureFlags(FLAG_CHANGE_VISIBILITY | FLAG_CHANGE_DECORATION, true));
// throws exception if failed ..
@@ -174,20 +177,32 @@ public class WindowDriver extends WindowImpl {
frame.setUndecorated(isUndecorated());
} else {
if(DEBUG_IMPLEMENTATION) {
- System.err.println("AWTWindow can't undecorate already created frame");
+ System.err.println(getThreadName()+": AWTWindow can't undecorate already created frame");
}
}
}
+ final Dimension szClient = new Dimension(width, height);
+ canvas.setMinimumSize(szClient);
+ canvas.setPreferredSize(szClient);
+ canvas.setSize(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 new size: szClient "+szClient+", szCont "+szContainer+", insets "+insets);
+ }
+
if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
+ if(null != frame) {
+ frame.pack();
+ }
+ container.validate();
container.setVisible(0 != ( FLAG_IS_VISIBLE & flags));
}
container.setLocation(x, y);
- Insets insets = container.getInsets();
- container.setSize(width + insets.left + insets.right,
- height + insets.top + insets.bottom);
-
+
if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
if( 0 != ( FLAG_IS_VISIBLE & flags ) ) {
if( !hasDeviceChanged() ) {
@@ -200,6 +215,12 @@ public class WindowDriver extends WindowImpl {
}
}
visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
+ } else {
+ container.invalidate();
+ if(null != frame) {
+ frame.pack();
+ }
+ container.validate();
}
return true;
@@ -216,18 +237,41 @@ public class WindowDriver extends WindowImpl {
return canvas;
}
- class LocalWindowListener extends com.jogamp.newt.event.WindowAdapter {
+ class LocalWindowListener implements com.jogamp.newt.event.WindowListener {
@Override
public void windowMoved(com.jogamp.newt.event.WindowEvent e) {
if(null!=container) {
- definePosition(container.getX(), container.getY());
+ WindowDriver.this.positionChanged(false, container.getX(), container.getY());
}
}
@Override
public void windowResized(com.jogamp.newt.event.WindowEvent e) {
if(null!=canvas) {
- defineSize(canvas.getWidth(), canvas.getHeight());
+ WindowDriver.this.sizeChanged(false, canvas.getWidth(), canvas.getHeight(), false);
+ }
+ }
+ @Override
+ public void windowDestroyNotify(WindowEvent e) {
+ WindowDriver.this.windowDestroyNotify(false);
+ }
+ @Override
+ public void windowDestroyed(WindowEvent e) {
+ if(isNativeValid()) {
+ WindowDriver.this.windowDestroyNotify(true);
}
+
+ }
+ @Override
+ public void windowGainedFocus(WindowEvent e) {
+ WindowDriver.this.focusChanged(false, true);
+ }
+ @Override
+ public void windowLostFocus(WindowEvent e) {
+ WindowDriver.this.focusChanged(false, false);
+ }
+ @Override
+ public void windowRepaint(WindowUpdateEvent e) {
+ WindowDriver.this.windowRepaint(false, 0, 0, getWidth(), getHeight());
}
}
}
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 62914bd4e..cc20cc27e 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
@@ -33,6 +33,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.UITestCase;
import com.jogamp.opengl.test.junit.util.QuitAdapter;
import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
@@ -78,8 +79,25 @@ public class TestGearsNewtAWTWrapper extends UITestCase {
glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
- glWindow.setSize(width, height);
+ 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();