diff options
Diffstat (limited to 'src/junit/com/jogamp/test')
3 files changed, 264 insertions, 59 deletions
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 277b41af3..436167dbf 100755 --- a/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java @@ -66,38 +66,102 @@ public class TestOffscreen01NEWT { @Test public void test01OffscreenWindow() { - GLWindow windowOffscreen = WindowUtilNEWT.createGLWindow(caps, width, height, false, true, false); - GLEventListener demo = new RedSquare(); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + Window window = NewtFactory.createWindow(screen, caps2, false /* undecorated */); + Assert.assertNotNull(window); + window.setSize(width, height); + GLWindow windowOffScreen = GLWindow.create(window); + Assert.assertNotNull(windowOffScreen); + windowOffScreen.setVisible(true); + GLWindow windowOnScreen = null; WindowListener wl=null; MouseListener ml=null; SurfaceUpdatedListener ul=null; - WindowUtilNEWT.run(windowOffscreen, null, windowOnScreen, wl, ml, ul, 2, false /*snapshot*/, false /*debug*/); + WindowUtilNEWT.run(windowOffScreen, null, windowOnScreen, wl, ml, ul, 2, false /*snapshot*/, false /*debug*/); try { Thread.sleep(1000); // 1000 ms } catch (Exception e) {} - WindowUtilNEWT.shutdown(windowOffscreen, windowOnScreen); + + if(null!=windowOnScreen) { + windowOnScreen.destroy(); + } + if(null!=windowOffScreen) { + windowOffScreen.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } } @Test public void test02OffscreenSnapshotWithDemo() { - GLWindow windowOffscreen = WindowUtilNEWT.createGLWindow(caps, width, height, false, true, false); - GLEventListener demo = new RedSquare(); + GLCapabilities caps2 = WindowUtilNEWT.fixCaps(caps, false, true, false); + + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + Window window = NewtFactory.createWindow(screen, caps2, false /* undecorated */); + Assert.assertNotNull(window); + window.setSize(width, height); + GLWindow windowOffScreen = GLWindow.create(window); + Assert.assertNotNull(windowOffScreen); + windowOffScreen.setVisible(true); + GLWindow windowOnScreen = null; WindowListener wl=null; MouseListener ml=null; SurfaceUpdatedListener ul=null; - WindowUtilNEWT.run(windowOffscreen, demo, windowOnScreen, wl, ml, ul, 2, true /*snapshot*/, false /*debug*/); + GLEventListener demo = new RedSquare(); + Assert.assertNotNull(demo); + + WindowUtilNEWT.run(windowOffScreen, demo, windowOnScreen, wl, ml, ul, 2, true /*snapshot*/, false /*debug*/); try { Thread.sleep(1000); // 1000 ms } catch (Exception e) {} - WindowUtilNEWT.shutdown(windowOffscreen, windowOnScreen); + + if(null!=windowOnScreen) { + windowOnScreen.destroy(); + } + if(null!=windowOffScreen) { + windowOffScreen.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } } public static void main(String args[]) { - org.junit.runner.JUnitCore.main(TestOffscreen01NEWT.class.getName()); + String tstname = TestOffscreen01NEWT.class.getName(); + try { + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } catch (Exception e) { + e.printStackTrace(); + } } } diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/WindowUtilNEWT.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/WindowUtilNEWT.java index 26b13cf7d..f6a6dc4be 100755 --- a/src/junit/com/jogamp/test/junit/jogl/offscreen/WindowUtilNEWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/WindowUtilNEWT.java @@ -34,6 +34,8 @@ package com.jogamp.test.junit.jogl.offscreen; import com.jogamp.test.junit.util.*; +import org.junit.Assert; + import java.lang.reflect.*; import javax.media.opengl.*; import javax.media.nativewindow.*; @@ -42,52 +44,29 @@ import com.jogamp.newt.opengl.*; public class WindowUtilNEWT { - public static Window createWindow(GLCapabilities caps, int w, int h, boolean onscreen, boolean pbuffer, boolean undecorated) { - GLCapabilities caps2 = (GLCapabilities) caps.clone(); - caps2.setOnscreen(onscreen); - caps2.setPBuffer(!onscreen && pbuffer); - caps2.setDoubleBuffered(!onscreen); - - Display display = NewtFactory.createDisplay(null); // local display - Screen screen = NewtFactory.createScreen(display, 0); // screen 0 - Window window = NewtFactory.createWindow(screen, caps2, onscreen && undecorated); - - GLCapabilities glCaps = (GLCapabilities) window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); - - GLDrawableFactory factory = GLDrawableFactory.getFactory(glCaps.getGLProfile()); - GLDrawable drawable = factory.createGLDrawable(window); - drawable.setRealized(true); - GLContext context = drawable.createContext(null); - - window.setSize(w, h); - window.setVisible(true); - return window; - } - - public static GLWindow createGLWindow(GLCapabilities caps, int w, int h, boolean onscreen, boolean pbuffer, boolean undecorated) { + public static GLCapabilities fixCaps(GLCapabilities caps, boolean onscreen, boolean pbuffer, boolean undecorated) { GLCapabilities caps2 = (GLCapabilities) caps.clone(); caps2.setOnscreen(onscreen); caps2.setPBuffer(!onscreen && pbuffer); caps2.setDoubleBuffered(!onscreen); - GLWindow window = GLWindow.create(caps2, onscreen && undecorated); - window.setSize(w, h); - window.setVisible(true); - return window; + return caps2; } - public static void run(GLWindow windowOffscreen, GLEventListener demo, + public static void run(GLWindow windowOffScreen, GLEventListener demo, GLWindow windowOnScreen, WindowListener wl, MouseListener ml, SurfaceUpdatedListener ul, int frames, boolean snapshot, boolean debug) { try { + Assert.assertNotNull(windowOffScreen); + if(debug && null!=demo) { MiscUtils.setField(demo, "glDebug", new Boolean(true)); MiscUtils.setField(demo, "glTrace", new Boolean(true)); } if(null!=demo) { - if(!MiscUtils.setField(demo, "window", windowOffscreen)) { - MiscUtils.setField(demo, "glWindow", windowOffscreen); + if(!MiscUtils.setField(demo, "window", windowOffScreen)) { + MiscUtils.setField(demo, "glWindow", windowOffScreen); } - windowOffscreen.addGLEventListener(demo); + windowOffScreen.addGLEventListener(demo); } if ( null != windowOnScreen ) { @@ -100,47 +79,35 @@ public class WindowUtilNEWT { windowOnScreen.setVisible(true); } - GLDrawable readDrawable = windowOffscreen.getContext().getGLDrawable() ; + GLDrawable readDrawable = windowOffScreen.getContext().getGLDrawable() ; if ( null == windowOnScreen ) { if(snapshot) { Surface2File s2f = new Surface2File(); - windowOffscreen.addSurfaceUpdatedListener(s2f); + windowOffScreen.addSurfaceUpdatedListener(s2f); } } else { ReadBuffer2Screen readDemo = new ReadBuffer2Screen( readDrawable ) ; windowOnScreen.addGLEventListener(readDemo); } if(null!=ul) { - windowOffscreen.addSurfaceUpdatedListener(ul); + windowOffScreen.addSurfaceUpdatedListener(ul); } if(debug) { System.out.println("+++++++++++++++++++++++++++"); - System.out.println(windowOffscreen); + System.out.println(windowOffScreen); System.out.println("+++++++++++++++++++++++++++"); } - while ( windowOffscreen.getTotalFrames() < frames) { - windowOffscreen.display(); + while ( windowOffScreen.getTotalFrames() < frames) { + windowOffScreen.display(); } - windowOffscreen.removeAllSurfaceUpdatedListener(); + windowOffScreen.removeAllSurfaceUpdatedListener(); } catch (GLException e) { e.printStackTrace(); } } - public static void shutdown(GLWindow windowOffscreen, GLWindow windowOnscreen) { - // Shut things down cooperatively - if(null!=windowOnscreen) { - windowOnscreen.destroy(); - } - if(null!=windowOffscreen) { - windowOffscreen.destroy(); - } - if(null!=windowOnscreen) { - windowOnscreen.getFactory().shutdown(); - } - } } diff --git a/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java new file mode 100755 index 000000000..91760ae80 --- /dev/null +++ b/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java @@ -0,0 +1,174 @@ +/* + * 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 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.nativewindow.*; + +import com.jogamp.newt.*; + +public class TestWindows01NEWT { + static int width, height; + + @BeforeClass + public static void initClass() { + width = 640; + height = 480; + } + + static Window createWindow(Screen screen, Capabilities caps, int width, int height, boolean onscreen, boolean undecorated) { + Assert.assertNotNull(caps); + caps.setOnscreen(onscreen); + // System.out.println("Requested: "+caps); + + // + // Create native windowing resources .. X11/Win/OSX + // + Window window = NewtFactory.createWindow(screen, caps, onscreen && undecorated); + Assert.assertNotNull(window); + window.setSize(width, height); + Assert.assertTrue(false==window.isVisible()); + window.setVisible(true); + Assert.assertTrue(true==window.isVisible()); + Assert.assertTrue(width==window.getWidth()); + Assert.assertTrue(height==window.getHeight()); + // System.out.println("Created: "+window); + + // + // Create native OpenGL resources .. XGL/WGL/CGL .. + // equivalent to GLAutoDrawable methods: setVisible(true) + // + caps = (Capabilities) window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + Assert.assertNotNull(caps); + Assert.assertTrue(caps.getGreenBits()>5); + Assert.assertTrue(caps.getBlueBits()>5); + Assert.assertTrue(caps.getRedBits()>5); + Assert.assertTrue(caps.isOnscreen()==onscreen); + + return window; + } + + static void destroyWindow(Display display, Screen screen, Window window) { + if(null!=window) { + window.destroy(); + } + if(null!=screen) { + screen.destroy(); + } + if(null!=display) { + display.destroy(); + } + } + + @Test + public void testWindowDecor01Simple() { + Capabilities caps = new Capabilities(); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + try { + Thread.sleep(1000); // 1000 ms + } catch (Exception e) {} + destroyWindow(display, screen, window); + } + + @Test + public void testWindowDecor02DestroyWinTwiceA() { + Capabilities caps = new Capabilities(); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + Window window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + try { + Thread.sleep(1000); // 1000 ms + } catch (Exception e) {} + destroyWindow(null, null, window); + destroyWindow(display, screen, window); + } + + @Test + public void testWindowDecor03TwoWin() { + Capabilities caps = new Capabilities(); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + + Window window1 = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + Window window2 = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); + try { + Thread.sleep(1000); // 1000 ms + } catch (Exception e) {} + destroyWindow(null, null, window2); + destroyWindow(display, screen, window1); + } + + public static void main(String args[]) { + String tstname = TestWindows01NEWT.class.getName(); + try { + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} |