From 969e427642d3b9be376cefaada9febd489b7b3d7 Mon Sep 17 00:00:00 2001
From: Sven Gothel
+ * Indicates whether a running animator thread is periodically issuing {@link #display()} calls or not.
+ * This method shall be called by an animator implementation only,
+ * Impacts {@link #display()} and {@link #invoke(boolean, GLRunnable)} semantics.
- * Warning: We cannot verify if the caller runs in the same thread
- * as the display caller, hence we cannot avoid a deadlock
- * in such case. You have to know what you are doing,
- * ie call this only in a I/O event listener, or such.
+ *
+ * e.g. {@link com.jogamp.opengl.util.Animator#start()}, passing the animator thread,
+ * and {@link com.jogamp.opengl.util.Animator#start()}, passing null
.
+ *
+ *
+ * @param animator null
reference indicates no running animator thread
+ * issues {@link #display()} calls on this GLAutoDrawable
,
+ * a valid reference indicates a running animator thread
+ * periodically issuing {@link #display()} calls.
+ *
+ * @throws GLException if a running animator thread is already registered and you try to register a different one without unregistering the previous one.
+ * @see #display()
+ * @see #invoke(boolean, GLRunnable)
+ */
+ public void setAnimator(Thread animator) throws GLException;
+
+ /**
+ * @return the value of the registered animator thread
+ *
+ * @see #setAnimator(Thread)
+ */
+ public Thread getAnimator();
+
/**
- * Enqueues the one-shot {@link javax.media.opengl.GLRunnable} into the queue,
- * which will be executed at the next {@link #display()} call.
*
+ * If {@link #setAnimator(Thread)} has not registered no running animator thread, the default,
+ * or if the current thread is the animator thread,
+ * a {@link #display()} call has to be issued after enqueueing the GLRunnable
.
+ * No extra synchronization must be performed in case wait
is true, since it is executed in the current thread.
+ * If {@link #setAnimator(Thread)} has registered a valid animator thread,
+ * no call of {@link #display()} must be issued, since the animator thread performs it.
+ * If wait
is true, the implementation must wait until the GLRunnable
is excecuted.
Causes OpenGL rendering to be performed for this GLAutoDrawable - in the following order: -
- Called automatically by the - window system toolkit upon receiving a repaint() request.
-- This routine may be called manually for better control over the - rendering process. It is legal to call another GLAutoDrawable's - display method from within the {@link GLEventListener#display - display(..)} callback.
-- In case of a new generated OpenGL context, - the implementation shall call {@link GLEventListener#init init(..)} for all - registered {@link GLEventListener}s before making the - actual {@link GLEventListener#display display(..)} calls, - in case this has not been done yet.
*/ + /** + *+ * Causes OpenGL rendering to be performed for this GLAutoDrawable + * in the following order: + *
+ * Called automatically by the + * window system toolkit upon receiving a repaint() request, + * except a running animator thread is registered with {@link #setAnimator(Thread)}.
+ * Maybe called periodically by a running animator thread,
+ * which must register itself with {@link #setAnimator(Thread)}.
+ * This routine may be called manually for better control over the + * rendering process. It is legal to call another GLAutoDrawable's + * display method from within the {@link GLEventListener#display + * display(..)} callback.
+ *+ * In case of a new generated OpenGL context, + * the implementation shall call {@link GLEventListener#init init(..)} for all + * registered {@link GLEventListener}s before making the + * actual {@link GLEventListener#display display(..)} calls, + * in case this has not been done yet.
+ * + * @see #setAnimator(Thread) + */ public void display(); /** Enables or disables automatic buffer swapping for this drawable. diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index 2dafd691a..f150b2507 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -378,7 +378,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { return; } - display(); + if( null == getAnimator() ) { + display(); + } } /** Overridden to track when this component is added to a container. @@ -492,8 +494,16 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { drawableHelper.removeGLEventListener(listener); } + public void setAnimator(Thread animator) { + drawableHelper.setAnimator(animator); + } + + public Thread getAnimator() { + return drawableHelper.getAnimator(); + } + public void invoke(boolean wait, GLRunnable glRunnable) { - drawableHelper.invoke(wait, glRunnable); + drawableHelper.invoke(this, wait, glRunnable); } public void setContext(GLContext ctx) { @@ -640,10 +650,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { if (sendReshape) { // Note: we ignore the given x and y within the parent component // since we are drawing directly into this heavyweight component. - int width = getWidth(); - int height = getHeight(); - getGL().glViewport(0, 0, width, height); - drawableHelper.reshape(GLCanvas.this, 0, 0, width, height); + drawableHelper.reshape(GLCanvas.this, 0, 0, getWidth(), getHeight()); sendReshape = false; } diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index 73962e979..d0d97fe31 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -380,8 +380,16 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { drawableHelper.removeGLEventListener(listener); } + public void setAnimator(Thread animator) { + drawableHelper.setAnimator(animator); + } + + public Thread getAnimator() { + return drawableHelper.getAnimator(); + } + public void invoke(boolean wait, GLRunnable glRunnable) { - drawableHelper.invoke(wait, glRunnable); + drawableHelper.invoke(this, wait, glRunnable); } public GLContext createContext(GLContext shareWith) { @@ -585,9 +593,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { } if (sendReshape) { if (DEBUG||VERBOSE) { - System.err.println("display: glViewport(" + viewportX + "," + viewportY + " " + panelWidth + "x" + panelHeight + ")"); + System.err.println("display: reshape(" + viewportX + "," + viewportY + " " + panelWidth + "x" + panelHeight + ")"); } - getGL().getGL2().glViewport(viewportX, viewportY, panelWidth, panelHeight); drawableHelper.reshape(GLJPanel.this, viewportX, viewportY, panelWidth, panelHeight); sendReshape = false; } diff --git a/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java b/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java index 1652acd82..f10218509 100755 --- a/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java +++ b/src/junit/com/jogamp/test/junit/jogl/awt/TestAWT01GLn.java @@ -48,6 +48,10 @@ import org.junit.After; import org.junit.Test; public class TestAWT01GLn { + static { + GLProfile.initSingleton(); + } + Frame frame=null; GLCanvas glCanvas=null; diff --git a/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWT01GLn.java b/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWT01GLn.java index ed8a5dd0f..6144a6308 100755 --- a/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWT01GLn.java +++ b/src/junit/com/jogamp/test/junit/jogl/awt/TestSwingAWT01GLn.java @@ -56,6 +56,10 @@ import static javax.swing.SwingUtilities.*; * @author Michael Bien */ public class TestSwingAWT01GLn { + static { + GLProfile.initSingleton(); + } + private Window[] windows; diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/es1/RedSquare.java b/src/junit/com/jogamp/test/junit/jogl/demos/es1/RedSquare.java index 9b8982ed4..be416f01d 100755 --- a/src/junit/com/jogamp/test/junit/jogl/demos/es1/RedSquare.java +++ b/src/junit/com/jogamp/test/junit/jogl/demos/es1/RedSquare.java @@ -44,6 +44,7 @@ public class RedSquare implements GLEventListener { private FloatBuffer vertices; public void init(GLAutoDrawable drawable) { + System.out.println("RedSquare: Init"); GL _gl = drawable.getGL(); if(glDebugEmu) { @@ -119,6 +120,7 @@ public class RedSquare implements GLEventListener { } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + System.out.println("RedSquare: Reshape"); GL2ES1 gl = drawable.getGL().getGL2ES1(); // Set location in front of camera gl.glMatrixMode(gl.GL_PROJECTION); @@ -147,6 +149,7 @@ public class RedSquare implements GLEventListener { } public void dispose(GLAutoDrawable drawable) { + System.out.println("RedSquare: Dispose"); GL2ES1 gl = drawable.getGL().getGL2ES1(); if(debug) { System.out.println(Thread.currentThread()+" RedSquare.dispose: "+gl.getContext()); @@ -163,8 +166,4 @@ public class RedSquare implements GLEventListener { System.out.println(Thread.currentThread()+" RedSquare.dispose: FIN"); } } - - public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { - } - } diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java index 1fa49be8c..ef5cf134a 100644 --- a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java +++ b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java @@ -25,6 +25,7 @@ public class Gears implements GLEventListener { private boolean mouseRButtonDown = false; public void init(GLAutoDrawable drawable) { + System.out.println("Gears: Init"); // Use debug pipeline // drawable.setGL(new DebugGL(drawable.getGL())); @@ -77,6 +78,7 @@ public class Gears implements GLEventListener { } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + System.out.println("Gears: Reshape"); GL2 gl = drawable.getGL().getGL2(); float h = (float)height / (float)width; @@ -91,6 +93,7 @@ public class Gears implements GLEventListener { } public void dispose(GLAutoDrawable drawable) { + System.out.println("Gears: Dispose"); } public void display(GLAutoDrawable drawable) { @@ -144,8 +147,6 @@ public class Gears implements GLEventListener { gl.glPopMatrix(); } - public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {} - public static void gear(GL2 gl, float inner_radius, float outer_radius, diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java index 2df3f0de9..b191dbbaf 100755 --- a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsAWT.java @@ -51,6 +51,10 @@ import org.junit.After; import org.junit.Test; public class TestGearsAWT { + static { + GLProfile.initSingleton(); + } + static GLProfile glp; static int width, height; diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNEWT.java b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNEWT.java index e50ffbde9..bafa8a1fb 100755 --- a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNEWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNEWT.java @@ -48,6 +48,10 @@ import org.junit.After; import org.junit.Test; public class TestGearsNEWT { + static { + GLProfile.initSingleton(); + } + static GLProfile glp; static int width, height; diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNewtAWTWrapper.java b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNewtAWTWrapper.java index 51977d6d3..316c9edb4 100755 --- a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNewtAWTWrapper.java +++ b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNewtAWTWrapper.java @@ -49,6 +49,10 @@ import org.junit.After; import org.junit.Test; public class TestGearsNewtAWTWrapper { + static { + GLProfile.initSingleton(); + } + static GLProfile glp; static int width, height; diff --git a/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java index cd0c7c0e0..8a9c960c1 100755 --- a/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java @@ -45,6 +45,10 @@ import com.jogamp.newt.*; import java.io.IOException; public class TestDrawable01NEWT { + static { + GLProfile.initSingleton(); + } + static GLProfile glp; static GLDrawableFactory factory; static int width, height; diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java index bae727019..ad198fca8 100755 --- a/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java @@ -57,6 +57,10 @@ import com.jogamp.test.junit.jogl.demos.es1.RedSquare; import java.io.IOException; public class TestOffscreen01NEWT { + static { + GLProfile.initSingleton(); + } + static GLProfile glpDefault; static GLDrawableFactory glDrawableFactory; static int width, height; diff --git a/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java b/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java index 7fdbd59c8..b34023bee 100755 --- a/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java @@ -56,6 +56,10 @@ import org.junit.BeforeClass; import org.junit.Test; public class TestTexture01AWT { + static { + GLProfile.initSingleton(); + } + static GLProfile glp; static GLCapabilities caps; BufferedImage textureImage; diff --git a/src/junit/com/jogamp/test/junit/newt/GLRunnableDummy.java b/src/junit/com/jogamp/test/junit/newt/GLRunnableDummy.java deleted file mode 100644 index 990a0c37d..000000000 --- a/src/junit/com/jogamp/test/junit/newt/GLRunnableDummy.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2010 Sven Gothel. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name Sven Gothel or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ - -package com.jogamp.test.junit.newt; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.AfterClass; -import org.junit.Test; - -import javax.media.opengl.*; - -public class GLRunnableDummy implements GLRunnable { - float r=0.0f; - float g=0.0f; - float b=0.0f; - float d=0.001f; - - public void run(GLAutoDrawable drawable) { - // nop .. - GL2ES1 gl = drawable.getGL().getGL2ES1(); - gl.glClearColor(r, g, b, 1f); - r+=d; - if(r>1f) { - r=1f; - d*=-1f; - } else if(r<0f) { - r=0f; - d*=-1f; - } - } - -} diff --git a/src/junit/com/jogamp/test/junit/newt/KeyAction.java b/src/junit/com/jogamp/test/junit/newt/KeyAction.java deleted file mode 100644 index 3ca12a840..000000000 --- a/src/junit/com/jogamp/test/junit/newt/KeyAction.java +++ /dev/null @@ -1,49 +0,0 @@ - -/* - * Copyright (c) 2010 Sven Gothel. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name Sven Gothel or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ - -package com.jogamp.test.junit.newt; - -import com.jogamp.newt.event.*; - -class KeyAction extends KeyAdapter { - NEWTEventFiFo eventFifo; - - public KeyAction(NEWTEventFiFo eventFifo) { - this.eventFifo = eventFifo; - } - - public void keyTyped(KeyEvent e) { - eventFifo.put(e); - } -} - diff --git a/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java index 4fd7744db..3a36a1132 100755 --- a/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java +++ b/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java @@ -47,8 +47,8 @@ import org.junit.Test; import javax.media.nativewindow.*; import javax.media.opengl.*; -import com.jogamp.opengl.util.Animator; import com.jogamp.newt.*; +import com.jogamp.newt.event.*; import com.jogamp.newt.opengl.*; import java.io.IOException; @@ -56,9 +56,13 @@ import com.jogamp.test.junit.util.MiscUtils; import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears; public class TestGLWindows01NEWT { + static { + GLProfile.initSingleton(); + } + static GLProfile glp; static int width, height; - static long duration = 100; // ms + static long durationPerTest = 100; // ms @BeforeClass public static void initClass() { @@ -67,7 +71,11 @@ public class TestGLWindows01NEWT { glp = GLProfile.getDefault(); } - static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) { + static GLWindow createWindow(Screen screen, GLCapabilities caps, + int width, int height, boolean onscreen, boolean undecorated, + boolean addGLEventListenerAfterVisible) + throws InterruptedException + { Assert.assertNotNull(caps); caps.setOnscreen(onscreen); // System.out.println("Requested: "+caps); @@ -84,12 +92,23 @@ public class TestGLWindows01NEWT { glWindow = GLWindow.create(caps, onscreen && undecorated); } Assert.assertNotNull(glWindow); + Assert.assertEquals(false,glWindow.isVisible()); Assert.assertEquals(false,glWindow.isNativeWindowValid()); + + GLEventListener demo = new Gears(); + setDemoFields(demo, glWindow); + if(!addGLEventListenerAfterVisible) { + glWindow.addGLEventListener(demo); + } + glWindow.addWindowListener(new TraceWindowAdapter()); + glWindow.setSize(width, height); - Assert.assertEquals(false,glWindow.isVisible()); + glWindow.setVisible(true); Assert.assertEquals(true,glWindow.isVisible()); Assert.assertEquals(true,glWindow.isNativeWindowValid()); + while(glWindow.getTotalFrames()<1) { Thread.sleep(100); } + Assert.assertEquals(1,glWindow.getTotalFrames()); // native expose .. // Assert.assertEquals(width,glWindow.getWidth()); // Assert.assertEquals(height,glWindow.getHeight()); // System.out.println("Created: "+glWindow); @@ -105,9 +124,10 @@ public class TestGLWindows01NEWT { Assert.assertTrue(caps.getRedBits()>5); Assert.assertEquals(caps.isOnscreen(),onscreen); - GLEventListener demo = new Gears(); - setDemoFields(demo, glWindow); - glWindow.addGLEventListener(demo); + if(addGLEventListenerAfterVisible) { + glWindow.addGLEventListener(demo); + glWindow.display(); + } return glWindow; } @@ -115,17 +135,21 @@ public class TestGLWindows01NEWT { static void destroyWindow(GLWindow glWindow, boolean deep) { if(null!=glWindow) { glWindow.destroy(deep); + Assert.assertEquals(false,glWindow.isNativeWindowValid()); } } @Test - public void testWindowNativeRecreate01Simple() throws InterruptedException { + public void testWindowNativeRecreate01aSimple() throws InterruptedException { GLCapabilities caps = new GLCapabilities(glp); Assert.assertNotNull(caps); - GLWindow window = createWindow(null, caps, width, height, true /* onscreen */, false /* undecorated */); + GLWindow window = createWindow(null, caps, width, height, + true /* onscreen */, false /* undecorated */, + false /*addGLEventListenerAfterVisible*/); - window.display(); - window.destroy(); + Assert.assertEquals(true,window.isNativeWindowValid()); + Assert.assertEquals(true,window.isVisible()); + window.destroy(false); Assert.assertEquals(false,window.isNativeWindowValid()); Assert.assertEquals(false,window.isVisible()); @@ -136,28 +160,70 @@ public class TestGLWindows01NEWT { window.setVisible(true); Assert.assertEquals(true,window.isNativeWindowValid()); Assert.assertEquals(true,window.isVisible()); + + window.setVisible(false); + Assert.assertEquals(true,window.isNativeWindowValid()); + Assert.assertEquals(false,window.isVisible()); + + destroyWindow(window, true); + } + + @Test + public void testWindowNativeRecreate01bSimple() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window = createWindow(null, caps, width, height, + true /* onscreen */, false /* undecorated */, + true /*addGLEventListenerAfterVisible*/); + + Assert.assertEquals(true,window.isNativeWindowValid()); + Assert.assertEquals(true,window.isVisible()); + window.destroy(false); + Assert.assertEquals(false,window.isNativeWindowValid()); + Assert.assertEquals(false,window.isVisible()); + window.display(); + Assert.assertEquals(false,window.isNativeWindowValid()); + Assert.assertEquals(false,window.isVisible()); + + window.setVisible(true); + Assert.assertEquals(true,window.isNativeWindowValid()); + Assert.assertEquals(true,window.isVisible()); - Animator animator = new Animator(window); - animator.start(); - while(animator.isAnimating() && animator.getDuration()Insets
object with the
- * specified top, left, bottom, and right insets.
- * @param top the inset from the top.
- * @param left the inset from the left.
- * @param bottom the inset from the bottom.
- * @param right the inset from the right.
- */
- public Insets(int top, int left, int bottom, int right) {
- this.top = top;
- this.left = left;
- this.bottom = bottom;
- this.right = right;
- }
-
- /**
- * Checks whether two insets objects are equal. Two instances
- * of Insets
are equal if the four integer values
- * of the fields top
, left
,
- * bottom
, and right
are all equal.
- * @return true
if the two insets are equal;
- * otherwise false
.
- */
- public boolean equals(Object obj) {
- if (obj instanceof Insets) {
- Insets insets = (Insets)obj;
- return ((top == insets.top) && (left == insets.left) &&
- (bottom == insets.bottom) && (right == insets.right));
- }
- return false;
- }
-
- /**
- * Returns the hash code for this Insets.
- *
- * @return a hash code for this Insets.
- */
- public int hashCode() {
- int sum1 = left + bottom;
- int sum2 = right + top;
- int val1 = sum1 * (sum1 + 1)/2 + left;
- int val2 = sum2 * (sum2 + 1)/2 + top;
- int sum3 = val1 + val2;
- return sum3 * (sum3 + 1)/2 + val2;
- }
-
- public String toString() {
- return getClass().getName() + "[top=" + top + ",left=" + left +
- ",bottom=" + bottom + ",right=" + right + "]";
- }
-
- public Object clone() {
- try {
- return super.clone();
- } catch (CloneNotSupportedException ex) {
- throw new InternalError();
- }
- }
-
-}
diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java
index 9bd4bb377..0cd5b31bc 100755
--- a/src/newt/classes/com/jogamp/newt/Window.java
+++ b/src/newt/classes/com/jogamp/newt/Window.java
@@ -34,11 +34,12 @@
package com.jogamp.newt;
import com.jogamp.newt.event.*;
+import com.jogamp.newt.util.*;
import com.jogamp.newt.impl.Debug;
-import com.jogamp.newt.util.EDTUtil;
import com.jogamp.common.util.*;
import javax.media.nativewindow.*;
+import com.jogamp.nativewindow.util.Rectangle;
import com.jogamp.nativewindow.impl.RecursiveToolkitLock;
import java.util.ArrayList;
@@ -46,7 +47,7 @@ import java.util.List;
import java.util.Iterator;
import java.lang.reflect.Method;
-public abstract class Window implements NativeWindow
+public abstract class Window implements NativeWindow, NEWTEventConsumer
{
public static final boolean DEBUG_MOUSE_EVENT = Debug.debug("Window.MouseEvent");
public static final boolean DEBUG_KEY_EVENT = Debug.debug("Window.KeyEvent");
@@ -155,7 +156,7 @@ public abstract class Window implements NativeWindow
return 0 != windowHandle ;
}
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.createNative() START ("+getThreadName()+", "+this+")");
+ System.out.println("Window.createNative() START ("+getThreadName()+", "+this+")");
}
if(validateParentWindowHandle()) {
Display dpy = getScreen().getDisplay();
@@ -163,7 +164,7 @@ public abstract class Window implements NativeWindow
setVisibleImpl(true);
}
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.createNative() END ("+getThreadName()+", "+this+")");
+ System.out.println("Window.createNative() END ("+getThreadName()+", "+this+")");
}
return 0 != windowHandle ;
}
@@ -190,7 +191,7 @@ public abstract class Window implements NativeWindow
}
} catch (NativeWindowException nwe) {
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.getNativeWindowHandle: not successful yet: "+nwe);
+ System.out.println("Window.getNativeWindowHandle: not successful yet: "+nwe);
}
} finally {
if(locked) {
@@ -198,7 +199,7 @@ public abstract class Window implements NativeWindow
}
}
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.getNativeWindowHandle: locked "+locked+", "+nativeWindow);
+ System.out.println("Window.getNativeWindowHandle: locked "+locked+", "+nativeWindow);
}
}
return handle;
@@ -245,7 +246,8 @@ public abstract class Window implements NativeWindow
"\n, Visible "+isVisible()+
"\n, Undecorated "+undecorated+
"\n, Fullscreen "+fullscreen+
- "\n, WrappedWindow "+getWrappedWindow());
+ "\n, WrappedWindow "+getWrappedWindow()+
+ "\n, ChildWindows "+childWindows.size());
sb.append(", SurfaceUpdatedListeners num "+surfaceUpdatedListeners.size()+" [");
for (Iterator iter = surfaceUpdatedListeners.iterator(); iter.hasNext(); ) {
@@ -376,41 +378,38 @@ public abstract class Window implements NativeWindow
public void run() {
windowLock();
try {
- if(DEBUG_WINDOW_EVENT) {
- System.err.println("Window.destroy(deep: "+deep+") START "+getThreadName()+", "+this);
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("Window.destroy(deep: "+deep+") START "+getThreadName()+", "+Window.this);
}
// Childs first ..
- ArrayList listeners = null;
- synchronized(childWindows) {
- listeners = childWindows;
- }
- for(Iterator i = listeners.iterator(); i.hasNext(); ) {
+ synchronized(childWindowsLock) {
+ for(Iterator i = childWindows.iterator(); i.hasNext(); ) {
NativeWindow nw = (NativeWindow) i.next();
+ System.out.println("Window.destroy(deep: "+deep+") CHILD BEGIN");
if(nw instanceof Window) {
- ((Window)nw).destroy(deep);
+ ((Window)nw).sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
+ if(deep) {
+ ((Window)nw).destroy(deep);
+ }
} else {
nw.destroy();
}
+ System.out.println("Window.destroy(deep: "+deep+") CHILD END");
+ }
}
// Now us ..
if(deep) {
- synchronized(childWindows) {
+ synchronized(childWindowsLock) {
childWindows = new ArrayList();
}
- synchronized(surfaceUpdatedListeners) {
+ synchronized(surfaceUpdatedListenersLock) {
surfaceUpdatedListeners = new ArrayList();
}
- synchronized(windowListeners) {
- windowListeners = new ArrayList();
- }
- synchronized(mouseListeners) {
- mouseListeners = new ArrayList();
- }
- synchronized(keyListeners) {
- keyListeners = new ArrayList();
- }
+ windowListeners = new ArrayList();
+ mouseListeners = new ArrayList();
+ keyListeners = new ArrayList();
}
Display dpy = null;
Screen scr = null;
@@ -428,8 +427,8 @@ public abstract class Window implements NativeWindow
dpy.destroy();
}
}
- if(DEBUG_WINDOW_EVENT) {
- System.err.println("Window.destroy(deep: "+deep+") END "+getThreadName()+", "+this);
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("Window.destroy(deep: "+deep+") END "+getThreadName()+", "+Window.this);
}
} finally {
windowUnlock();
@@ -466,16 +465,16 @@ public abstract class Window implements NativeWindow
try{
if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) {
String msg = new String("!!! Window Invalidate(deep: "+deep+") "+getThreadName());
- System.err.println(msg);
- //Exception e = new Exception(msg);
- //e.printStackTrace();
+ //System.out.println(msg);
+ Exception e = new Exception(msg);
+ e.printStackTrace();
}
windowHandle = 0;
- visible=false;
- fullscreen=false;
+ visible = false;
+ fullscreen = false;
if(deep) {
- screen = null;
+ screen = null;
parentWindowHandle = 0;
parentNativeWindow = null;
caps = null;
@@ -593,43 +592,6 @@ public abstract class Window implements NativeWindow
return false;
}
- /**
- * If set to true, the default value, this NEWT Window implementation will
- * handle the destruction (ie {@link #destroy()} call) within {@link #windowDestroyNotify()} implementation.
- *
- * The idea was that in a single threaded environment with one {@link Display} and many {@link Window}'s,
- * a performance benefit was expected while disabling the implicit {@link Display#pumpMessages} and
- * do it once via {@link GLWindow#runCurrentThreadPumpMessage()}
- * This could not have been verified. No measurable difference could have been recognized.
- *
- * Best performance has been achieved with one GLWindow per thread.
- *
- * Enabling local pump messages while using the EDT,
- * {@link com.jogamp.newt.NewtFactory#setUseEDT(boolean)},
- * will result in an exception.
- *
- * @deprecated EXPERIMENTAL, semantic is about to be removed after further verification.
- */
- public void setRunPumpMessages(boolean onoff) {
- if( onoff && null!=getScreen().getDisplay().getEDTUtil() ) {
- throw new GLException("GLWindow.setRunPumpMessages(true) - Can't do with EDT on");
- }
- runPumpMessages = onoff;
- }
-
protected void createNativeImpl() {
shouldNotCallThis();
}
@@ -178,7 +166,7 @@ public class GLWindow extends Window implements GLAutoDrawable {
// Lock: Have to cover whole workflow (dispose all, context, drawable and window)
windowLock();
try {
- if(null==window || window.isDestroyed()) {
+ if( isDestroyed() ) {
return; // nop
}
if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) {
@@ -186,21 +174,20 @@ public class GLWindow extends Window implements GLAutoDrawable {
e1.printStackTrace();
}
- if ( null != context && context.isCreated() && null != drawable && drawable.isRealized() ) {
- // Catch dispose GLExceptions by GLEventListener, just 'print' them
- // so we can continue with the destruction.
- try {
- helper.invokeGL(drawable, context, disposeAction, null);
- } catch (GLException gle) {
- gle.printStackTrace();
+ if( window.isNativeWindowValid() && null != drawable && drawable.isRealized() ) {
+ if( null != context && context.isCreated() ) {
+ // Catch dispose GLExceptions by GLEventListener, just 'print' them
+ // so we can continue with the destruction.
+ try {
+ helper.invokeGL(drawable, context, disposeAction, null);
+ } catch (GLException gle) {
+ gle.printStackTrace();
+ }
+
+ context.destroy();
+ context = null;
}
- }
- if (context != null && null != drawable && drawable.isRealized() ) {
- context.destroy();
- context = null;
- }
- if (drawable != null) {
drawable.setRealized(false);
drawable = null;
}
@@ -228,7 +215,7 @@ public class GLWindow extends Window implements GLAutoDrawable {
* @see #destroy()
*/
public void destroy(boolean deep) {
- if(!isDestroyed()) {
+ if( !isDestroyed() ) {
runOnEDTIfAvail(true, new DestroyAction(deep));
}
}
@@ -369,6 +356,13 @@ public class GLWindow extends Window implements GLAutoDrawable {
return window.isFullscreen();
}
+ public void enqueueEvent(boolean wait, com.jogamp.newt.event.NEWTEvent event) {
+ window.enqueueEvent(wait, event);
+ }
+ public boolean consumeEvent(NEWTEvent e) {
+ return window.consumeEvent(e);
+ }
+
public void addSurfaceUpdatedListener(int index, SurfaceUpdatedListener l) {
window.addSurfaceUpdatedListener(index, l);
}
@@ -414,6 +408,12 @@ public class GLWindow extends Window implements GLAutoDrawable {
return window.getKeyListeners();
}
+ public void sendWindowEvent(int eventType) {
+ window.sendWindowEvent(eventType);
+ }
+ public void enqueueWindowEvent(boolean wait, int eventType) {
+ window.enqueueWindowEvent(wait, eventType);
+ }
public void addWindowListener(int index, WindowListener l) {
window.addWindowListener(index, l);
}
@@ -426,6 +426,12 @@ public class GLWindow extends Window implements GLAutoDrawable {
public WindowListener[] getWindowListeners() {
return window.getWindowListeners();
}
+ public void setPropagateRepaint(boolean v) {
+ window.setPropagateRepaint(v);
+ }
+ public void windowRepaint(int x, int y, int width, int height) {
+ window.windowRepaint(x, y, width, height);
+ }
public String toString() {
return "NEWT-GLWindow[ \n\tHelper: "+helper+", \n\tDrawable: "+drawable + /** ", \n\tWindow: "+window+", \n\tFactory: "+factory+ */ "]";
@@ -483,8 +489,17 @@ public class GLWindow extends Window implements GLAutoDrawable {
helper.removeGLEventListener(listener);
}
+ public void setAnimator(Thread animator) {
+ helper.setAnimator(animator);
+ window.setPropagateRepaint(null==animator);
+ }
+
+ public Thread getAnimator() {
+ return helper.getAnimator();
+ }
+
public void invoke(boolean wait, GLRunnable glRunnable) {
- helper.invoke(wait, glRunnable);
+ helper.invoke(this, wait, glRunnable);
}
public void display() {
@@ -494,28 +509,26 @@ public class GLWindow extends Window implements GLAutoDrawable {
public void display(boolean forceReshape) {
if( null == window ) { return; }
+ if(sendDestroy || ( null!=window && window.hasDeviceChanged() && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED ) ) {
+ sendDestroy=false;
+ destroy();
+ return;
+ }
+
if( null == context && window.isVisible() ) {
// retry native window and drawable/context creation
setVisible(true);
}
- if( window.isNativeWindowValid() && null != context ) {
- if(runPumpMessages) {
- window.getScreen().getDisplay().pumpMessages();
+ if( window.isVisible() && window.isNativeWindowValid() && null != context ) {
+ if(forceReshape) {
+ sendReshape = true;
}
- if(sendDestroy || window.hasDeviceChanged() && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED) {
- destroy();
- sendDestroy=false;
- } else if ( window.isVisible() ) {
- if(forceReshape) {
- sendReshape = true;
- }
- windowLock();
- try{
- helper.invokeGL(drawable, context, displayAction, initAction);
- } finally {
- windowUnlock();
- }
+ windowLock();
+ try{
+ helper.invokeGL(drawable, context, displayAction, initAction);
+ } finally {
+ windowUnlock();
}
}
}
@@ -546,7 +559,7 @@ public class GLWindow extends Window implements GLAutoDrawable {
public void run() {
// Lock: Locked Surface/Window by MakeCurrent/Release
helper.init(GLWindow.this);
- startTime = System.currentTimeMillis();
+ startTime = System.currentTimeMillis(); // overwrite startTime to real init one
curTime = startTime;
if(perfLog) {
lastCheck = startTime;
@@ -560,10 +573,7 @@ public class GLWindow extends Window implements GLAutoDrawable {
public void run() {
// Lock: Locked Surface/Window by display _and_ MakeCurrent/Release
if (sendReshape) {
- int width = getWidth();
- int height = getHeight();
- getGL().glViewport(0, 0, width, height);
- helper.reshape(GLWindow.this, 0, 0, width, height);
+ helper.reshape(GLWindow.this, 0, 0, getWidth(), getHeight());
sendReshape = false;
}
@@ -589,8 +599,8 @@ public class GLWindow extends Window implements GLAutoDrawable {
private DisplayAction displayAction = new DisplayAction();
public long getStartTime() { return startTime; }
- public long getCurrentTime() { return curTime; }
- public long getDuration() { return curTime-startTime; }
+ public long getCurrentTime() { curTime = System.currentTimeMillis(); return curTime; }
+ public long getDuration() { return getCurrentTime()-startTime; }
public int getTotalFrames() { return totalFrames; }
private long startTime = 0;
diff --git a/src/newt/classes/com/jogamp/newt/util/Insets.java b/src/newt/classes/com/jogamp/newt/util/Insets.java
new file mode 100644
index 000000000..068cc1dfb
--- /dev/null
+++ b/src/newt/classes/com/jogamp/newt/util/Insets.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+package com.jogamp.newt.util;
+
+/**
+ * Simple class representing insets.
+ *
+ * @author tdv
+ */
+public class Insets implements Cloneable {
+ public int top;
+ public int left;
+ public int bottom;
+ public int right;
+
+ /**
+ * Creates and initializes a new Insets
object with the
+ * specified top, left, bottom, and right insets.
+ * @param top the inset from the top.
+ * @param left the inset from the left.
+ * @param bottom the inset from the bottom.
+ * @param right the inset from the right.
+ */
+ public Insets(int top, int left, int bottom, int right) {
+ this.top = top;
+ this.left = left;
+ this.bottom = bottom;
+ this.right = right;
+ }
+
+ /**
+ * Checks whether two insets objects are equal. Two instances
+ * of Insets
are equal if the four integer values
+ * of the fields top
, left
,
+ * bottom
, and right
are all equal.
+ * @return true
if the two insets are equal;
+ * otherwise false
.
+ */
+ public boolean equals(Object obj) {
+ if (obj instanceof Insets) {
+ Insets insets = (Insets)obj;
+ return ((top == insets.top) && (left == insets.left) &&
+ (bottom == insets.bottom) && (right == insets.right));
+ }
+ return false;
+ }
+
+ /**
+ * Returns the hash code for this Insets.
+ *
+ * @return a hash code for this Insets.
+ */
+ public int hashCode() {
+ int sum1 = left + bottom;
+ int sum2 = right + top;
+ int val1 = sum1 * (sum1 + 1)/2 + left;
+ int val2 = sum2 * (sum2 + 1)/2 + top;
+ int sum3 = val1 + val2;
+ return sum3 * (sum3 + 1)/2 + val2;
+ }
+
+ public String toString() {
+ return getClass().getName() + "[top=" + top + ",left=" + left +
+ ",bottom=" + bottom + ",right=" + right + "]";
+ }
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException ex) {
+ throw new InternalError();
+ }
+ }
+
+}
diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c
index 5e3311d3b..a1dab2678 100755
--- a/src/newt/native/WindowsWindow.c
+++ b/src/newt/native/WindowsWindow.c
@@ -109,15 +109,16 @@
#define STD_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr)
-static jmethodID sizeChangedID = NULL;
static jmethodID insetsChangedID = NULL;
+static jmethodID sizeChangedID = NULL;
static jmethodID positionChangedID = NULL;
static jmethodID focusChangedID = NULL;
+static jmethodID visibleChangedID = NULL;
static jmethodID windowDestroyNotifyID = NULL;
static jmethodID windowDestroyedID = NULL;
-static jmethodID enqueueMouseEventID = NULL;
-static jmethodID enqueueKeyEventID = NULL;
-static jmethodID sendPaintEventID = NULL;
+static jmethodID windowRepaintID = NULL;
+static jmethodID sendMouseEventID = NULL;
+static jmethodID sendKeyEventID = NULL;
static RECT* UpdateInsets(JNIEnv *env, HWND hwnd, jobject window);
@@ -506,7 +507,7 @@ static int WmChar(JNIEnv *env, jobject window, UINT character, UINT repCnt,
if (character == VK_RETURN) {
character = J_VK_ENTER;
}
- (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
+ (*env)->CallVoidMethod(env, window, sendKeyEventID,
(jint) EVENT_KEY_TYPED,
GetModifiers(),
(jint) -1,
@@ -551,7 +552,7 @@ static int WmKeyDown(JNIEnv *env, jobject window, UINT wkey, UINT repCnt,
character = WindowsKeyToJavaChar(wkey, modifiers, SAVE);
*/
- (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
+ (*env)->CallVoidMethod(env, window, sendKeyEventID,
(jint) EVENT_KEY_PRESSED,
modifiers,
(jint) jkey,
@@ -562,7 +563,7 @@ static int WmKeyDown(JNIEnv *env, jobject window, UINT wkey, UINT repCnt,
WM_KEYDOWN.
*/
if (jkey == J_VK_DELETE) {
- (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
+ (*env)->CallVoidMethod(env, window, sendKeyEventID,
(jint) EVENT_KEY_TYPED,
GetModifiers(),
(jint) -1,
@@ -586,7 +587,7 @@ static int WmKeyUp(JNIEnv *env, jobject window, UINT wkey, UINT repCnt,
character = WindowsKeyToJavaChar(wkey, modifiers, SAVE);
*/
- (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
+ (*env)->CallVoidMethod(env, window, sendKeyEventID,
(jint) EVENT_KEY_RELEASED,
modifiers,
(jint) jkey,
@@ -706,6 +707,7 @@ static void WmSize(JNIEnv *env, HWND wnd, jobject window, UINT type)
static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
+ LRESULT res = 0;
int useDefWindowProc = 0;
JNIEnv *env = NULL;
jobject window = NULL;
@@ -799,7 +801,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
case WM_LBUTTONDOWN:
NewtWindows_requestFocus ( wnd, FALSE, FALSE ); // request focus on this window, if not already ..
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_PRESSED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -808,7 +810,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_LBUTTONUP:
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_RELEASED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -818,7 +820,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
case WM_MBUTTONDOWN:
NewtWindows_requestFocus ( wnd, FALSE, FALSE ); // request focus on this window, if not already ..
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_PRESSED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -827,7 +829,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_MBUTTONUP:
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_RELEASED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -837,7 +839,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
case WM_RBUTTONDOWN:
NewtWindows_requestFocus ( wnd, FALSE, FALSE ); // request focus on this window, if not already ..
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_PRESSED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -846,7 +848,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_RBUTTONUP:
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_RELEASED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -855,7 +857,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_MOUSEMOVE:
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_MOVED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -871,7 +873,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
eventPt.x = x;
eventPt.y = y;
ScreenToClient(wnd, &eventPt);
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_WHEEL_MOVED,
GetModifiers(),
(jint) eventPt.x, (jint) eventPt.y,
@@ -881,17 +883,19 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
}
case WM_SETFOCUS:
- (*env)->CallVoidMethod(env, window, focusChangedID,
- (jlong)wParam, JNI_TRUE);
+ (*env)->CallVoidMethod(env, window, focusChangedID, JNI_TRUE);
useDefWindowProc = 1;
break;
case WM_KILLFOCUS:
- (*env)->CallVoidMethod(env, window, focusChangedID,
- (jlong)wParam, JNI_FALSE);
+ (*env)->CallVoidMethod(env, window, focusChangedID, JNI_FALSE);
useDefWindowProc = 1;
break;
+ case WM_SHOWWINDOW:
+ (*env)->CallVoidMethod(env, window, visibleChangedID, wParam==TRUE?JNI_TRUE:JNI_FALSE);
+ break;
+
case WM_MOVE:
DBG_PRINT("*** WindowsWindow: WM_MOVE window %p, %d/%d\n", wnd, (int)LOWORD(lParam), (int)HIWORD(lParam));
(*env)->CallVoidMethod(env, window, positionChangedID,
@@ -901,21 +905,24 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
case WM_PAINT: {
RECT r;
- if (GetUpdateRect(wnd, &r, FALSE)) {
- if ((r.right-r.left) > 0 && (r.bottom-r.top) > 0) {
- (*env)->CallVoidMethod(env, window, sendPaintEventID,
- 0, r.left, r.top, r.right-r.left, r.bottom-r.top);
+ useDefWindowProc = 0;
+ if (GetUpdateRect(wnd, &r, TRUE /* erase background */)) {
+ /*
+ jint width = r.right-r.left;
+ jint height = r.bottom-r.top;
+ if (width > 0 && height > 0) {
+ (*env)->CallVoidMethod(env, window, windowRepaintID, r.left, r.top, width, height);
}
ValidateRect(wnd, &r);
- useDefWindowProc = 0;
- } else {
- useDefWindowProc = 1;
+ */
}
break;
}
case WM_ERASEBKGND:
// ignore erase background
+ (*env)->CallVoidMethod(env, window, windowRepaintID, 0, 0, -1, -1);
useDefWindowProc = 0;
+ res = 1;
break;
@@ -926,7 +933,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
if (useDefWindowProc)
return DefWindowProc(wnd, message, wParam, lParam);
- return 0;
+ return res;
}
/*
@@ -1052,24 +1059,26 @@ JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_getHeight
JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_initIDs0
(JNIEnv *env, jclass clazz)
{
- sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V");
insetsChangedID = (*env)->GetMethodID(env, clazz, "insetsChanged", "(IIII)V");
+ sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V");
positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V");
- focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(JZ)V");
+ focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(Z)V");
+ visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(Z)V");
windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V");
windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V");
- enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(IIIIII)V");
- enqueueKeyEventID = (*env)->GetMethodID(env, clazz, "enqueueKeyEvent", "(IIIC)V");
- sendPaintEventID = (*env)->GetMethodID(env, clazz, "sendPaintEvent", "(IIIII)V");
- if (sizeChangedID == NULL ||
- insetsChangedID == NULL ||
+ windowRepaintID = (*env)->GetMethodID(env, clazz, "windowRepaint", "(IIII)V");
+ sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V");
+ sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V");
+ if (insetsChangedID == NULL ||
+ sizeChangedID == NULL ||
positionChangedID == NULL ||
focusChangedID == NULL ||
+ visibleChangedID == NULL ||
windowDestroyNotifyID == NULL ||
windowDestroyedID == NULL ||
- enqueueMouseEventID == NULL ||
- sendPaintEventID == NULL ||
- enqueueKeyEventID == NULL)
+ windowRepaintID == NULL ||
+ sendMouseEventID == NULL ||
+ sendKeyEventID == NULL)
{
return JNI_FALSE;
}
diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c
index a521d2dbd..dbf833633 100755
--- a/src/newt/native/X11Window.c
+++ b/src/newt/native/X11Window.c
@@ -151,14 +151,16 @@ static const char * const ClazzNameNewtWindow =
"com/jogamp/newt/Window";
static jclass newtWindowClz=NULL;
-static jmethodID windowChangedID = NULL;
+static jmethodID sizeChangedID = NULL;
+static jmethodID positionChangedID = NULL;
static jmethodID focusChangedID = NULL;
static jmethodID visibleChangedID = NULL;
static jmethodID windowDestroyNotifyID = NULL;
static jmethodID windowDestroyedID = NULL;
+static jmethodID windowRepaintID = NULL;
static jmethodID windowCreatedID = NULL;
-static jmethodID enqueueMouseEventID = NULL;
-static jmethodID enqueueKeyEventID = NULL;
+static jmethodID sendMouseEventID = NULL;
+static jmethodID sendKeyEventID = NULL;
static jmethodID displayCompletedID = NULL;
@@ -291,8 +293,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Display_CompleteDisplay0
* Window
*/
-// #define WINDOW_EVENT_MASK ( FocusChangeMask | StructureNotifyMask | ExposureMask | VisibilityNotify )
-#define WINDOW_EVENT_MASK ( FocusChangeMask | StructureNotifyMask | VisibilityNotify )
+#define WINDOW_EVENT_MASK ( FocusChangeMask | StructureNotifyMask | ExposureMask )
static int putPtrIn32Long(unsigned long * dst, uintptr_t src) {
int i=0;
@@ -505,31 +506,37 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Display_DispatchMessages
switch(evt.type) {
case ButtonPress:
NewtWindows_requestFocus1 ( dpy, evt.xany.window );
- (*env)->CallVoidMethod(env, jwindow, enqueueMouseEventID, (jint) EVENT_MOUSE_PRESSED,
+ (*env)->CallVoidMethod(env, jwindow, sendMouseEventID,
+ (jint) EVENT_MOUSE_PRESSED,
(jint) evt.xbutton.state,
(jint) evt.xbutton.x, (jint) evt.xbutton.y, (jint) evt.xbutton.button, 0 /*rotation*/);
break;
case ButtonRelease:
- (*env)->CallVoidMethod(env, jwindow, enqueueMouseEventID, (jint) EVENT_MOUSE_RELEASED,
+ (*env)->CallVoidMethod(env, jwindow, sendMouseEventID,
+ (jint) EVENT_MOUSE_RELEASED,
(jint) evt.xbutton.state,
(jint) evt.xbutton.x, (jint) evt.xbutton.y, (jint) evt.xbutton.button, 0 /*rotation*/);
break;
case MotionNotify:
- (*env)->CallVoidMethod(env, jwindow, enqueueMouseEventID, (jint) EVENT_MOUSE_MOVED,
+ (*env)->CallVoidMethod(env, jwindow, sendMouseEventID,
+ (jint) EVENT_MOUSE_MOVED,
(jint) evt.xmotion.state,
(jint) evt.xmotion.x, (jint) evt.xmotion.y, (jint) 0, 0 /*rotation*/);
break;
case KeyPress:
- (*env)->CallVoidMethod(env, jwindow, enqueueKeyEventID, (jint) EVENT_KEY_PRESSED,
+ (*env)->CallVoidMethod(env, jwindow, sendKeyEventID,
+ (jint) EVENT_KEY_PRESSED,
(jint) evt.xkey.state,
X11KeySym2NewtVKey(keySym), (jchar) keyChar);
break;
case KeyRelease:
- (*env)->CallVoidMethod(env, jwindow, enqueueKeyEventID, (jint) EVENT_KEY_RELEASED,
+ (*env)->CallVoidMethod(env, jwindow, sendKeyEventID,
+ (jint) EVENT_KEY_RELEASED,
(jint) evt.xkey.state,
X11KeySym2NewtVKey(keySym), (jchar) keyChar);
- (*env)->CallVoidMethod(env, jwindow, enqueueKeyEventID, (jint) EVENT_KEY_TYPED,
+ (*env)->CallVoidMethod(env, jwindow, sendKeyEventID,
+ (jint) EVENT_KEY_TYPED,
(jint) evt.xkey.state,
(jint) -1, (jchar) keyChar);
break;
@@ -546,9 +553,10 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Display_DispatchMessages
(unsigned int)evt.xconfigure.window, (unsigned int)evt.xconfigure.event, (unsigned int)evt.xconfigure.above,
evt.xconfigure.x, evt.xconfigure.y, evt.xconfigure.width, evt.xconfigure.height,
evt.xconfigure.override_redirect);
- (*env)->CallVoidMethod(env, jwindow, windowChangedID,
- (jint) evt.xconfigure.x, (jint) evt.xconfigure.y,
+ (*env)->CallVoidMethod(env, jwindow, sizeChangedID,
(jint) evt.xconfigure.width, (jint) evt.xconfigure.height);
+ (*env)->CallVoidMethod(env, jwindow, positionChangedID,
+ (jint) evt.xconfigure.x, (jint) evt.xconfigure.y);
break;
case ClientMessage:
if (evt.xclient.send_event==True && evt.xclient.data.l[0]==(Atom)wmDeleteAtom) {
@@ -568,25 +576,28 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Display_DispatchMessages
(*env)->CallVoidMethod(env, jwindow, focusChangedID, JNI_FALSE);
break;
+ case Expose:
+ DBG_PRINT( "X11: event . Expose call 0x%X %d/%d %dx%d\n", (unsigned int)evt.xexpose.window,
+ evt.xexpose.x, evt.xexpose.y, evt.xexpose.width, evt.xexpose.height);
+
+ if (evt.xexpose.width > 0 && evt.xexpose.height > 0) {
+ (*env)->CallVoidMethod(env, jwindow, windowRepaintID,
+ evt.xexpose.x, evt.xexpose.y, evt.xexpose.width, evt.xexpose.height);
+ }
+ break;
+
case MapNotify:
DBG_PRINT( "X11: event . MapNotify call 0x%X\n", (unsigned int)evt.xunmap.window);
- // FIXME (*env)->CallVoidMethod(env, jwindow, visibleChangedID, JNI_TRUE);
+ (*env)->CallVoidMethod(env, jwindow, visibleChangedID, JNI_TRUE);
break;
case UnmapNotify:
DBG_PRINT( "X11: event . UnmapNotify call 0x%X\n", (unsigned int)evt.xunmap.window);
- // FIXME (*env)->CallVoidMethod(env, jwindow, visibleChangedID, JNI_FALSE);
+ (*env)->CallVoidMethod(env, jwindow, visibleChangedID, JNI_FALSE);
break;
// unhandled events .. yet ..
- case VisibilityNotify:
- DBG_PRINT( "X11: event . VisibilityNotify call 0x%X\n", (unsigned int)evt.xvisibility.window);
- break;
- case Expose:
- DBG_PRINT( "X11: event . Expose call 0x%X\n", (unsigned int)evt.xexpose.window);
- /* FIXME: Might want to send a repaint event .. */
- break;
default:
DBG_PRINT("X11: event . unhandled %d 0x%X call 0x%X\n", evt.type, evt.type, (unsigned int)evt.xunmap.window);
}
@@ -653,23 +664,27 @@ JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getHeight0
JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_x11_X11Window_initIDs0
(JNIEnv *env, jclass clazz)
{
- windowChangedID = (*env)->GetMethodID(env, clazz, "windowChanged", "(IIII)V");
+ sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V");
+ positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V");
focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(Z)V");
visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(Z)V");
windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V");
windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V");
+ windowRepaintID = (*env)->GetMethodID(env, clazz, "windowRepaint", "(IIII)V");
windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(J)V");
- enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(IIIIII)V");
- enqueueKeyEventID = (*env)->GetMethodID(env, clazz, "enqueueKeyEvent", "(IIIC)V");
+ sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V");
+ sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V");
- if (windowChangedID == NULL ||
+ if (sizeChangedID == NULL ||
+ positionChangedID == NULL ||
focusChangedID == NULL ||
visibleChangedID == NULL ||
windowDestroyNotifyID == NULL ||
windowDestroyedID == NULL ||
+ windowRepaintID == NULL ||
windowCreatedID == NULL ||
- enqueueMouseEventID == NULL ||
- enqueueKeyEventID == NULL) {
+ sendMouseEventID == NULL ||
+ sendKeyEventID == NULL) {
return JNI_FALSE;
}
return JNI_TRUE;
@@ -749,12 +764,17 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_x11_X11Window_CreateWindow0
pVisualQuery=NULL;
}
- attrMask = ( CWBackPixel | CWBorderPixel | CWColormap | CWOverrideRedirect ) ;
+ attrMask = ( CWBackingStore | CWBackingPlanes | CWBackingPixel | CWBackPixel |
+ CWBorderPixel | CWColormap | CWOverrideRedirect ) ;
memset(&xswa, 0, sizeof(xswa));
xswa.override_redirect = ( 0 != parent ) ? True : False ;
xswa.border_pixel = 0;
xswa.background_pixel = 0;
+ xswa.backing_store=NotUseful; /* NotUseful, WhenMapped, Always */
+ xswa.backing_planes=0; /* planes to be preserved if possible */
+ xswa.backing_pixel=0; /* value to use in restoring planes */
+
xswa.colormap = XCreateColormap(dpy,
windowParent, // XRootWindow(dpy, scrn_idx),
visual,
@@ -781,6 +801,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_x11_X11Window_CreateWindow0
setJavaWindowProperty(env, dpy, window, javaObjectAtom, (*env)->NewGlobalRef(env, obj));
+ // XClearWindow(dpy, window);
XSync(dpy, False);
{
@@ -806,7 +827,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_x11_X11Window_CreateWindow0
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_CloseWindow0
- (JNIEnv *env, jobject obj, jlong display, jlong window, jlong javaObjectAtom)
+ (JNIEnv *env, jobject obj, jlong display, jlong window, jlong javaObjectAtom, jlong wmDeleteAtom)
{
Display * dpy = (Display *) (intptr_t) display;
Window w = (Window)window;
@@ -827,14 +848,19 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_CloseWindow0
_throwNewRuntimeException(dpy, env, "Internal Error .. Window global ref not the same!");
return;
}
- (*env)->DeleteGlobalRef(env, jwindow);
XSync(dpy, False);
XSelectInput(dpy, w, 0);
XUnmapWindow(dpy, w);
+
+ // Drain all events related to this window ..
+ JNICALL Java_com_jogamp_newt_impl_x11_X11Display_DispatchMessages0(env, obj, display, javaObjectAtom, wmDeleteAtom);
+
XDestroyWindow(dpy, w);
XSync(dpy, False);
+ (*env)->DeleteGlobalRef(env, jwindow);
+
DBG_PRINT( "X11: CloseWindow END\n");
(*env)->CallVoidMethod(env, obj, windowDestroyedID);
@@ -922,6 +948,11 @@ static void NewtWindows_reparentWindow
DBG_PRINT( "X11: reparentWindow dpy %p, parent %p/%p, win %p, %d/%d undec %d\n",
(void*)dpy, (void*) jparent, (void*)parent, (void*)w, x, y, undecorated);
+ // don't propagate events during reparenting
+ // long orig_xevent_mask = xwa->your_event_mask ;
+ /* XSelectInput(dpy, w, orig_xevent_mask & ~ ( StructureNotifyMask ) );
+ XSync(dpy, False); */
+
if(0 != jparent) {
// move into parent ..
NewtWindows_setDecorations (dpy, w, False);
@@ -955,6 +986,14 @@ static void NewtWindows_reparentWindow
XSync(dpy, False);
}
+ /* XSelectInput(dpy, w, orig_xevent_mask);
+ XSync(dpy, False); */
+
+ if(JNI_TRUE == isVisible) {
+ NewtWindows_requestFocus0 ( dpy, w, xwa );
+ XSync(dpy, False);
+ }
+
DBG_PRINT( "X11: reparentWindow X\n");
}
@@ -993,12 +1032,6 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_setPosSizeDecor0
xwc.width=width;
xwc.height=height;
XConfigureWindow(dpy, w, CWX|CWY|CWWidth|CWHeight, &xwc);
-
- if(JNI_TRUE == isVisible) {
- XGetWindowAttributes(dpy, w, &xwa);
- NewtWindows_requestFocus0 ( dpy, w, &xwa );
- XSync(dpy, False);
- }
}
/*
@@ -1039,7 +1072,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_reparentWindow0
JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_requestFocus0
(JNIEnv *env, jobject obj, jlong display, jlong window)
{
- NewtWindows_requestFocus ( (Display *) (intptr_t) display, (Window)window ) ;
+ NewtWindows_requestFocus1 ( (Display *) (intptr_t) display, (Window)window ) ;
}
/*
--
cgit v1.2.3