From 969e427642d3b9be376cefaada9febd489b7b3d7 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 26 Jun 2010 06:59:48 +0300 Subject: GLAutoDrawable: setAnimator/getAnimator/invoke/display changes; NEWT: Adding native repaint; NewtCanvasAWT focus fix Support for native repaint, which shall call display() in case no animator is running. GLAutoDrawable invoke(GLRunnable) impl. handles case if invoked on animator thread, or no animator thread is running (issueing a display() call). The impl resides in GLDrawableHelper. GLEventListener's init() and glViewport()/reshape() method must be called before the 1st display() and after a dispose() call. It could miss the 1st display() call if added after the setVisible(true) call - due to the native repainting. The impl resides in GLDrawableHelper. The Animator un-/registers itself at the GLAutoDrawable via setAnimator. NEWT Window reparent always issues a resize() and display() call. NEWT native Window uses direct send.*Event for input events (again), instead of enqueueing it for performance. NEWT Window implements all status change and Java native event callbacks, instead of having duplicated code in all implementations. NewtCanvasAWT if the Newt window is focused, the AWT/Swing component[s] will loose the focus. --- .../jogamp/test/junit/jogl/awt/TestAWT01GLn.java | 4 + .../test/junit/jogl/awt/TestSwingAWT01GLn.java | 4 + .../test/junit/jogl/demos/es1/RedSquare.java | 7 +- .../test/junit/jogl/demos/gl2/gears/Gears.java | 5 +- .../junit/jogl/demos/gl2/gears/TestGearsAWT.java | 4 + .../junit/jogl/demos/gl2/gears/TestGearsNEWT.java | 4 + .../demos/gl2/gears/TestGearsNewtAWTWrapper.java | 4 + .../junit/jogl/drawable/TestDrawable01NEWT.java | 4 + .../junit/jogl/offscreen/TestOffscreen01NEWT.java | 4 + .../test/junit/jogl/texture/TestTexture01AWT.java | 4 + .../jogamp/test/junit/newt/GLRunnableDummy.java | 63 --- .../com/jogamp/test/junit/newt/KeyAction.java | 49 --- .../test/junit/newt/TestGLWindows01NEWT.java | 152 +++++-- .../junit/newt/TestGLWindows02NEWTAnimated.java | 230 +++++++++++ .../test/junit/newt/TestListenerCom01AWT.java | 7 +- .../test/junit/newt/TestParenting01NEWT.java | 313 --------------- .../test/junit/newt/TestParenting01aAWT.java | 429 -------------------- .../test/junit/newt/TestParenting01bAWT.java | 188 --------- .../test/junit/newt/TestParenting01cAWT.java | 195 --------- .../test/junit/newt/TestParenting01cSwingAWT.java | 374 ----------------- .../jogamp/test/junit/newt/TestParenting02AWT.java | 270 ------------- .../test/junit/newt/TestParenting02NEWT.java | 231 ----------- .../jogamp/test/junit/newt/TestWindows01NEWT.java | 1 + .../com/jogamp/test/junit/newt/WindowAction.java | 48 --- .../test/junit/newt/parenting/GLRunnableDummy.java | 63 +++ .../test/junit/newt/parenting/KeyAction.java | 49 +++ .../junit/newt/parenting/TestParenting01NEWT.java | 317 +++++++++++++++ .../junit/newt/parenting/TestParenting01aAWT.java | 447 +++++++++++++++++++++ .../junit/newt/parenting/TestParenting01bAWT.java | 192 +++++++++ .../junit/newt/parenting/TestParenting01cAWT.java | 253 ++++++++++++ .../newt/parenting/TestParenting01cSwingAWT.java | 383 ++++++++++++++++++ .../junit/newt/parenting/TestParenting02AWT.java | 274 +++++++++++++ .../junit/newt/parenting/TestParenting02NEWT.java | 240 +++++++++++ .../test/junit/newt/parenting/WindowAction.java | 48 +++ 34 files changed, 2654 insertions(+), 2206 deletions(-) delete mode 100644 src/junit/com/jogamp/test/junit/newt/GLRunnableDummy.java delete mode 100644 src/junit/com/jogamp/test/junit/newt/KeyAction.java create mode 100755 src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java delete mode 100755 src/junit/com/jogamp/test/junit/newt/TestParenting01NEWT.java delete mode 100755 src/junit/com/jogamp/test/junit/newt/TestParenting01aAWT.java delete mode 100755 src/junit/com/jogamp/test/junit/newt/TestParenting01bAWT.java delete mode 100755 src/junit/com/jogamp/test/junit/newt/TestParenting01cAWT.java delete mode 100755 src/junit/com/jogamp/test/junit/newt/TestParenting01cSwingAWT.java delete mode 100755 src/junit/com/jogamp/test/junit/newt/TestParenting02AWT.java delete mode 100755 src/junit/com/jogamp/test/junit/newt/TestParenting02NEWT.java delete mode 100644 src/junit/com/jogamp/test/junit/newt/WindowAction.java create mode 100644 src/junit/com/jogamp/test/junit/newt/parenting/GLRunnableDummy.java create mode 100644 src/junit/com/jogamp/test/junit/newt/parenting/KeyAction.java create mode 100755 src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java create mode 100755 src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01aAWT.java create mode 100755 src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01bAWT.java create mode 100755 src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cAWT.java create mode 100755 src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cSwingAWT.java create mode 100755 src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02AWT.java create mode 100755 src/junit/com/jogamp/test/junit/newt/parenting/TestParenting02NEWT.java create mode 100644 src/junit/com/jogamp/test/junit/newt/parenting/WindowAction.java (limited to 'src/junit') 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()5); + Assert.assertTrue(caps.getBlueBits()>5); + Assert.assertTrue(caps.getRedBits()>5); + Assert.assertEquals(caps.isOnscreen(),onscreen); + + return glWindow; + } + + static void destroyWindow(GLWindow glWindow, boolean deep) { + if(null!=glWindow) { + glWindow.destroy(deep); + } + } + + @Test + public void testWindowDecor01Simple() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window = createWindow(null, caps, width, height, true /* onscreen */, false /* undecorated */); + Animator animator = new Animator(window); + animator.start(); + while(animator.isAnimating() && animator.getDuration()0 && !shouldQuit) { - glWindow.display(); - Thread.sleep(step); - duration -= step; - - while( null != ( event = (NEWTEvent) eventFifo.get() ) ) { - Window source = (Window) event.getSource(); - if(event instanceof KeyEvent) { - KeyEvent keyEvent = (KeyEvent) event; - switch(keyEvent.getKeyChar()) { - case 'q': - shouldQuit = true; - break; - case 'f': - source.setFullscreen(!source.isFullscreen()); - break; - } - } - } - } - if(verbose) { - System.out.println("+++++++++++++++++++ END"); - } - Thread.sleep(waitReparent); - - glWindow.destroy(); - if(useLayout) { - frame.remove(newtCanvasAWT); - } - frame.dispose(); - } - - public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { - Assert.assertNotNull(demo); - Assert.assertNotNull(glWindow); - Window window = glWindow.getInnerWindow(); - if(debug) { - MiscUtils.setFieldIfExists(demo, "glDebug", true); - MiscUtils.setFieldIfExists(demo, "glTrace", true); - } - if(!MiscUtils.setFieldIfExists(demo, "window", window)) { - MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); - } - } - - static int atoi(String a) { - int i=0; - try { - i = Integer.parseInt(a); - } catch (Exception ex) { ex.printStackTrace(); } - return i; - } - - public static void main(String args[]) throws IOException { - verbose = true; - for(int i=0; i0 && !shouldQuit) { - glWindow1.display(); - glWindow2.display(); - Thread.sleep(step); - duration -= step; - x += 1; - y += 1; - glWindow1.setPosition(x,y); - glWindow2.setPosition(glWindow1.getWidth()/2,glWindow1.getHeight()/2-y); - - while( null != ( event = (NEWTEvent) eventFifo.get() ) ) { - Window source = (Window) event.getSource(); - if(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY == event.getEventType()) { - shouldQuit = true; - } else if(event instanceof KeyEvent) { - KeyEvent keyEvent = (KeyEvent) event; - switch(keyEvent.getKeyChar()) { - case 'q': - shouldQuit = true; - break; - case 'f': - source.setFullscreen(!source.isFullscreen()); - break; - } - } - } - } - destroyWindow(null, null, window2, glWindow2); - destroyWindow(display, screen, window1, glWindow1); - } - - public static void setDemoFields(GLEventListener demo, Window window, GLWindow glWindow, boolean debug) { - Assert.assertNotNull(demo); - Assert.assertNotNull(window); - if(debug) { - MiscUtils.setFieldIfExists(demo, "glDebug", true); - MiscUtils.setFieldIfExists(demo, "glTrace", true); - } - if(!MiscUtils.setFieldIfExists(demo, "window", window)) { - MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); - } - } - - static int atoi(String a) { - int i=0; - try { - i = Integer.parseInt(a); - } catch (Exception ex) { ex.printStackTrace(); } - return i; - } - - public static void main(String args[]) throws IOException { - for(int i=0; i1f) { + r=1f; + d*=-1f; + } else if(r<0f) { + r=0f; + d*=-1f; + } + } + +} diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/KeyAction.java b/src/junit/com/jogamp/test/junit/newt/parenting/KeyAction.java new file mode 100644 index 000000000..c9e1db074 --- /dev/null +++ b/src/junit/com/jogamp/test/junit/newt/parenting/KeyAction.java @@ -0,0 +1,49 @@ + +/* + * 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.parenting; + +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/parenting/TestParenting01NEWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java new file mode 100755 index 000000000..421f74aa4 --- /dev/null +++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java @@ -0,0 +1,317 @@ +/* + * 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.parenting; + +import java.lang.reflect.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.*; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.newt.*; +import com.jogamp.newt.event.*; +import com.jogamp.newt.opengl.*; + +import java.io.IOException; + +import com.jogamp.test.junit.util.*; +import com.jogamp.test.junit.jogl.demos.es1.RedSquare; +import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears; + +public class TestParenting01NEWT { + static { + GLProfile.initSingleton(); + } + + static int width, height; + static long durationPerTest = 500; + static long waitReparent = 0; + static GLCapabilities glCaps; + + @BeforeClass + public static void initClass() { + width = 640; + height = 480; + glCaps = new GLCapabilities(null); + } + + @Test + public void testWindowParenting01CreateVisibleDestroy() throws InterruptedException { + int x = 0; + int y = 0; + + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + + GLWindow glWindow1 = GLWindow.create(glCaps); + Assert.assertNotNull(glWindow1); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(false, glWindow1.isNativeWindowValid()); + Assert.assertNull(glWindow1.getParentNativeWindow()); + glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy"); + glWindow1.setSize(640, 480); + GLEventListener demo1 = new RedSquare(); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + + GLWindow glWindow2 = GLWindow.create(glWindow1, glCaps); + Assert.assertNotNull(glWindow2); + Assert.assertEquals(false, glWindow2.isVisible()); + Assert.assertEquals(false, glWindow2.isNativeWindowValid()); + Assert.assertEquals(glWindow1,glWindow2.getParentNativeWindow()); + glWindow2.setSize(320, 240); + GLEventListener demo2 = new Gears(); + setDemoFields(demo2, glWindow2, false); + glWindow2.addGLEventListener(demo2); + + // visible test + glWindow1.setVisible(true); + Assert.assertEquals(true, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow1.isNativeWindowValid()); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeWindowValid()); + glWindow1.setVisible(false); + Assert.assertEquals(false, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow1.isNativeWindowValid()); + Assert.assertEquals(false, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeWindowValid()); + glWindow1.setVisible(true); + Assert.assertEquals(true, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow1.isNativeWindowValid()); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeWindowValid()); + + Animator animator1 = new Animator(glWindow1); + animator1.start(); + Animator animator2 = new Animator(glWindow2); + animator2.start(); + while(animator1.isAnimating() && animator1.getDuration()0 && !shouldQuit) { + glWindow.display(); + Thread.sleep(step); + duration -= step; + + while( null != ( event = (NEWTEvent) eventFifo.get() ) ) { + Window source = (Window) event.getSource(); + if(event instanceof KeyEvent) { + KeyEvent keyEvent = (KeyEvent) event; + switch(keyEvent.getKeyChar()) { + case 'q': + shouldQuit = true; + break; + case 'f': + source.setFullscreen(!source.isFullscreen()); + break; + } + } + } + } + if(verbose) { + System.out.println("+++++++++++++++++++ END"); + } + Thread.sleep(waitReparent); + + glWindow.destroy(); + if(useLayout) { + frame.remove(newtCanvasAWT); + } + frame.dispose(); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + Window window = glWindow.getInnerWindow(); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + verbose = true; + for(int i=0; i0 && !shouldQuit) { + glWindow1.display(); + glWindow2.display(); + Thread.sleep(step); + duration -= step; + x += 1; + y += 1; + glWindow1.setPosition(x,y); + glWindow2.setPosition(glWindow1.getWidth()/2,glWindow1.getHeight()/2-y); + + while( null != ( event = (NEWTEvent) eventFifo.get() ) ) { + Window source = (Window) event.getSource(); + if(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY == event.getEventType()) { + shouldQuit = true; + } else if(event instanceof KeyEvent) { + KeyEvent keyEvent = (KeyEvent) event; + switch(keyEvent.getKeyChar()) { + case 'q': + shouldQuit = true; + break; + case 'f': + source.setFullscreen(!source.isFullscreen()); + break; + } + } + } + } + destroyWindow(null, null, window2, glWindow2); + destroyWindow(display, screen, window1, glWindow1); + } + + public static void setDemoFields(GLEventListener demo, Window window, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(window); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i