diff options
7 files changed, 436 insertions, 73 deletions
diff --git a/make/scripts/tests-win.bat b/make/scripts/tests-win.bat index 7e40967c2..94bc49c38 100755 --- a/make/scripts/tests-win.bat +++ b/make/scripts/tests-win.bat @@ -78,6 +78,7 @@ REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintin REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.perf.TestPerf001RawInit00NEWT %* REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.perf.TestPerf001GLJPanelInit01AWT %* scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.perf.TestPerf001GLJPanelInit02AWT %* +REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.perf.TestPerf001GLWindowInit03NEWT %* REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNewtAWTWrapper %* REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNEWT -time 30000 diff --git a/make/scripts/tests-x64-dbg.bat b/make/scripts/tests-x64-dbg.bat index 726be54ba..a42c79254 100755 --- a/make/scripts/tests-x64-dbg.bat +++ b/make/scripts/tests-x64-dbg.bat @@ -24,7 +24,7 @@ REM set D_ARGS="-Djogamp.debug=all" REM set D_ARGS="-Djogl.debug.GLContext" "-Djogl.debug.FBObject"
REM set D_ARGS="-Djogl.debug.GLDrawable" "-Djogl.debug.EGLDrawableFactory.DontQuery"
REM set D_ARGS="-Djogl.debug.GLDrawable" "-Djogl.debug.EGLDrawableFactory.QueryNativeTK"
-REM set D_ARGS="-Djogl.debug=all" "-Dnewt.debug=all" "-Dnativewindow.debug=all"
+set D_ARGS="-Djogl.debug=all" "-Dnewt.debug=all" "-Dnativewindow.debug=all"
REM set D_ARGS="-Djogl.debug.GLDrawable" "-Djogl.debug.GLContext" "-Djogl.debug.GLCanvas"
REM set D_ARGS="-Djogl.debug=all" "-Dnewt.debug=all" "-Dnativewindow.debug=all" "-Djogamp.debug=all" "-Djogl.debug.EGLDrawableFactory.DontQuery"
REM set D_ARGS="-Dnativewindow.debug.GraphicsConfiguration -Djogl.debug.CapabilitiesChooser -Djogl.debug.GLProfile"
@@ -53,7 +53,7 @@ REM set D_ARGS="-Djogl.debug.GLCanvas" "-Djogl.debug.GLJPanel" "-Djogl.debug.Til REM set D_ARGS="-Djogl.debug.GLCanvas" "-Djogl.debug.GLJPanel" "-Djogl.debug.TileRenderer"
REM set D_ARGS="-Dnewt.debug.Window"
REM set D_ARGS="-Dnewt.debug.Window.KeyEvent"
-set D_ARGS="-Dnewt.debug.Window.MouseEvent"
+REM set D_ARGS="-Dnewt.debug.Window.MouseEvent"
REM set D_ARGS="-Dnewt.debug.Window.MouseEvent" "-Dnewt.debug.Window.KeyEvent"
REM set D_ARGS="-Dnewt.debug.Window" "-Dnewt.debug.Display"
REM set D_ARGS="-Djogl.debug.GLDebugMessageHandler" "-Djogl.debug.DebugGL" "-Djogl.debug.TraceGL"
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index f2231a0de..53e4e22cd 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -176,6 +176,7 @@ function jrun() { #D_ARGS="-Djogamp.common.utils.locks.Lock.timeout=3000 -Djogamp.debug.Lock -Dnativewindow.debug.ToolkitLock.TraceLock" #D_ARGS="-Djogamp.common.utils.locks.Lock.timeout=600000 -Djogamp.debug.Lock -Djogamp.debug.Lock.TraceLock -Dnativewindow.debug.ToolkitLock.TraceLock" #D_ARGS="-Djogamp.common.utils.locks.Lock.timeout=600000 -Djogamp.debug.Lock -Dnativewindow.debug.X11Util" + #D_ARGS="-Djogamp.common.utils.locks.Lock.timeout=600000 -Dnativewindow.debug.X11Util" #D_ARGS="-Dnewt.debug.EDT -Djogamp.common.utils.locks.Lock.timeout=600000 -Djogl.debug.Animator -Dnewt.debug.Display -Dnewt.debug.Screen" #D_ARGS="-Dnewt.debug.Window -Djogamp.common.utils.locks.Lock.timeout=600000" #D_ARGS="-Dnewt.debug=all -Djogamp.common.utils.locks.Lock.timeout=600000" @@ -337,6 +338,7 @@ function testawtswt() { #testnoawt com.jogamp.opengl.test.junit.jogl.perf.TestPerf001RawInit00NEWT $* #testawt com.jogamp.opengl.test.junit.jogl.perf.TestPerf001GLJPanelInit01AWT $* testawt com.jogamp.opengl.test.junit.jogl.perf.TestPerf001GLJPanelInit02AWT $* +#testnoawt com.jogamp.opengl.test.junit.jogl.perf.TestPerf001GLWindowInit03NEWT $* # # tile rendring / printing w/ & w/o AWT diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index 1adafaf87..2c805fa00 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -58,6 +58,7 @@ import java.util.List; import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindowFactory; import javax.media.nativewindow.WindowClosingProtocol; import javax.media.opengl.DefaultGLCapabilitiesChooser; import javax.media.opengl.GL; @@ -338,6 +339,51 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing this.setFocusable(true); // allow keyboard input! } + /** + * Attempts to initialize the backend, if not initialized yet. + * <p> + * If backend is already initialized method returns <code>true</code>. + * </p> + * <p> + * If <code>offthread</code> is <code>true</code>, initialization will kicked off + * on a <i>short lived</i> arbitrary thread and method returns immediately.<br/> + * If platform supports such <i>arbitrary thread</i> initialization method returns + * <code>true</code>, otherwise <code>false</code>. + * </p> + * <p> + * Due to threading restrictions, <i>arbitrary thread</i> initialization is <i>not supported</i> on: + * <ul> + * <li>{@link NativeWindowFactory.TYPE_WINDOWS}</li> + * </ul> + * </p> + * <p> + * If <code>offthread</code> is <code>false</code>, initialization be performed + * on the current thread and method returns after initialization.<br/> + * Method returns <code>true</code> if initialization was successful, otherwise <code>false</code>. + * <p> + * @param offthread + */ + public final boolean initializeBackend(boolean offthread) { + if( offthread ) { + if( NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(true) ) { + return false; + } + new Thread(getThreadName()+"-GLJPanel_Init") { + public void run() { + if( !isInitialized ) { + initializeBackendImpl(); + } + } }.start(); + return true; + } else { + if( !isInitialized ) { + return initializeBackendImpl(); + } else { + return true; + } + } + } + @Override public final void setSharedContext(GLContext sharedContext) throws IllegalStateException { helper.setSharedContext(this.getContext(), sharedContext); @@ -457,8 +503,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing return; } - if (backend == null || !isInitialized) { - createAndInitializeBackend(); + if( !isInitialized ) { + initializeBackendImpl(); } if (!isInitialized || printActive) { @@ -552,8 +598,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing private final Runnable setupPrintOnEDT = new Runnable() { @Override public void run() { - if (backend == null || !isInitialized) { - createAndInitializeBackend(); + if( !isInitialized ) { + initializeBackendImpl(); } if (!isInitialized) { if(DEBUG) { @@ -1020,35 +1066,47 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing // Internals only below this point // - private void createAndInitializeBackend() { - if ( 0 >= panelWidth || 0 >= panelHeight ) { - // See whether we have a non-zero size yet and can go ahead with - // initialization - if (0 >= reshapeWidth || 0 >= reshapeHeight ) { - return; - } + private final Object initSync = new Object(); + private boolean initializeBackendImpl() { + if( !isInitialized ) { + synchronized(initSync) { + if( !isInitialized ) { + if ( 0 >= panelWidth || 0 >= panelHeight ) { + // See whether we have a non-zero size yet and can go ahead with + // initialization + if (0 >= reshapeWidth || 0 >= reshapeHeight ) { + return false; + } - if (DEBUG) { - System.err.println(getThreadName()+": GLJPanel.createAndInitializeBackend: " +panelWidth+"x"+panelHeight + " -> " + reshapeWidth+"x"+reshapeHeight); - } - // Pull down reshapeWidth and reshapeHeight into panelWidth and - // panelHeight eagerly in order to complete initialization, and - // force a reshape later - panelWidth = reshapeWidth; - panelHeight = reshapeHeight; - } + if (DEBUG) { + System.err.println(getThreadName()+": GLJPanel.createAndInitializeBackend: " +panelWidth+"x"+panelHeight + " -> " + reshapeWidth+"x"+reshapeHeight); + } + // Pull down reshapeWidth and reshapeHeight into panelWidth and + // panelHeight eagerly in order to complete initialization, and + // force a reshape later + panelWidth = reshapeWidth; + panelHeight = reshapeHeight; + } - if ( null == backend ) { - if ( oglPipelineUsable() ) { - backend = new J2DOGLBackend(); - } else { - backend = new OffscreenBackend(glProfile, customPixelBufferProvider); - } - isInitialized = false; - } + if ( null == backend ) { + if ( oglPipelineUsable() ) { + backend = new J2DOGLBackend(); + } else { + backend = new OffscreenBackend(glProfile, customPixelBufferProvider); + } + isInitialized = false; + } - if (!isInitialized) { - backend.initialize(); + if (!isInitialized) { + backend.initialize(); + } + return isInitialized; + } else { + return true; + } + } + } else { + return true; } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit01AWT.java index 24bd1b748..0472fdb31 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit01AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit01AWT.java @@ -34,6 +34,8 @@ import java.lang.reflect.InvocationTargetException; import javax.media.opengl.GLAnimatorControl; import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLProfile; import javax.media.opengl.awt.GLCanvas; @@ -65,8 +67,8 @@ public class TestPerf001GLJPanelInit01AWT extends UITestCase { GLProfile.initSingleton(); } - public void test(final boolean useGears, final int width, final int height, final int rows, final int columns, - final boolean useGLJPanel, final boolean useAnim) { + public void test(final GLCapabilitiesImmutable caps, final boolean useGears, final int width, final int height, final int rows, + final int columns, final boolean useGLJPanel, final boolean useAnim) { final GLAnimatorControl animator = useAnim ? new Animator() : null; final JFrame frame; @@ -90,7 +92,7 @@ public class TestPerf001GLJPanelInit01AWT extends UITestCase { public void run() { t[0] = Platform.currentTimeMillis(); for(int i=0; i<panelCount; i++) { - final GLAutoDrawable glad = useGLJPanel ? createGLJPanel(useGears, animator, eSize) : createGLCanvas(useGears, animator, eSize); + final GLAutoDrawable glad = useGLJPanel ? createGLJPanel(caps, useGears, animator, eSize) : createGLCanvas(caps, useGears, animator, eSize); glad.addGLEventListener(new GLEventListener() { @Override public void init(GLAutoDrawable drawable) { @@ -158,8 +160,8 @@ public class TestPerf001GLJPanelInit01AWT extends UITestCase { System.err.println("Total: "+(t[4]-t[0])); } - private GLAutoDrawable createGLCanvas(boolean useGears, GLAnimatorControl anim, Dimension size) { - GLCanvas canvas = new GLCanvas(); + private GLAutoDrawable createGLCanvas(GLCapabilitiesImmutable caps, boolean useGears, GLAnimatorControl anim, Dimension size) { + GLCanvas canvas = new GLCanvas(caps); canvas.setSize(size); canvas.setPreferredSize(size); if( useGears ) { @@ -170,8 +172,8 @@ public class TestPerf001GLJPanelInit01AWT extends UITestCase { } return canvas; } - private GLAutoDrawable createGLJPanel(boolean useGears, GLAnimatorControl anim, Dimension size) { - GLJPanel canvas = new GLJPanel(); + private GLAutoDrawable createGLJPanel(GLCapabilitiesImmutable caps, boolean useGears, GLAnimatorControl anim, Dimension size) { + GLJPanel canvas = new GLJPanel(caps); canvas.setSize(size); canvas.setPreferredSize(size); if( useGears ) { @@ -184,13 +186,20 @@ public class TestPerf001GLJPanelInit01AWT extends UITestCase { } @Test - public void test01NopGLJPanel() throws InterruptedException, InvocationTargetException { - test(false /*useGears*/, width, height, rows, cols, true /* useGLJPanel */, false /*useAnim*/); + public void test01NopGLJPanelDef() throws InterruptedException, InvocationTargetException { + test(new GLCapabilities(null), false /*useGears*/, width, height, rows, cols, true /* useGLJPanel */, false /*useAnim*/); } @Test - public void test02NopGLCanvas() throws InterruptedException, InvocationTargetException { - test(false /*useGears*/, width, height, rows, cols, false /* useGLJPanel */, false /*useAnim*/); + public void test02NopGLJPanelBitmap() throws InterruptedException, InvocationTargetException { + GLCapabilities caps = new GLCapabilities(null); + caps.setBitmap(true); + test(caps, false /*useGears*/, width, height, rows, cols, true /* useGLJPanel */, false /*useAnim*/); + } + + @Test + public void test11NopGLCanvasDef() throws InterruptedException, InvocationTargetException { + test(new GLCapabilities(null), false /*useGears*/, width, height, rows, cols, false /* useGLJPanel */, false /*useAnim*/); } static long duration = 0; // ms @@ -235,7 +244,7 @@ public class TestPerf001GLJPanelInit01AWT extends UITestCase { if( manual ) { GLProfile.initSingleton(); TestPerf001GLJPanelInit01AWT demo = new TestPerf001GLJPanelInit01AWT(); - demo.test(useGears, width, height, rows, cols, useGLJPanel, false /*useAnim*/); + demo.test(null, useGears, width, height, rows, cols, useGLJPanel, false /*useAnim*/); } else { org.junit.runner.JUnitCore.main(TestPerf001GLJPanelInit01AWT.class.getName()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit02AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit02AWT.java index 0ac66f907..1c3accb67 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit02AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit02AWT.java @@ -30,16 +30,20 @@ package com.jogamp.opengl.test.junit.jogl.perf; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; +import java.awt.Graphics; import java.lang.reflect.InvocationTargetException; import javax.media.opengl.GLAnimatorControl; import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLProfile; import javax.media.opengl.awt.GLCanvas; import javax.media.opengl.awt.GLJPanel; import javax.swing.JFrame; import javax.swing.JPanel; +import javax.swing.JTextArea; import javax.swing.SwingUtilities; import org.junit.Assume; @@ -65,9 +69,13 @@ public class TestPerf001GLJPanelInit02AWT extends UITestCase { GLProfile.initSingleton(); } - public void test(final boolean useGears, final int width, final int height, final int frameCount, - final boolean useGLJPanel, final boolean useAnim) { + public void test(final GLCapabilitiesImmutable caps, final boolean useGears, final int width, final int height, + final int frameCount, final boolean initMT, final boolean useGLJPanel, final boolean useGLCanvas, final boolean useAnim, final boolean overlap) { final GLAnimatorControl animator = useAnim ? new Animator() : null; + final int cols = (int)Math.round(Math.sqrt(frameCount)); + final int rows = frameCount / cols; + final int eWidth = width/cols-32; + final int eHeight = height/rows-32; final JFrame[] frame = new JFrame[frameCount]; final long[] t = new long[10]; @@ -80,26 +88,66 @@ public class TestPerf001GLJPanelInit02AWT extends UITestCase { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { t[0] = Platform.currentTimeMillis(); + int x = 32, y = 32; for(int i=0; i<frameCount; i++) { frame[i] = new JFrame("frame_"+i+"/"+frameCount); + frame[i].setLocation(x, y); + if(!overlap) { + x+=eWidth+32; + if(x>=width) { + x=32; + y+=eHeight+32; + } + } final JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); // panel.setBounds(0, 0, width, height); - final Dimension eSize = new Dimension(width, height); - final GLAutoDrawable glad = useGLJPanel ? createGLJPanel(useGears, animator, eSize) : createGLCanvas(useGears, animator, eSize); - glad.addGLEventListener(new GLEventListener() { - @Override - public void init(GLAutoDrawable drawable) { - initCount++; - } - @Override - public void dispose(GLAutoDrawable drawable) {} - @Override - public void display(GLAutoDrawable drawable) {} - @Override - public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {} - }); - panel.add((Component)glad); + final Dimension eSize = new Dimension(eWidth, eHeight); + final GLAutoDrawable glad = useGLJPanel ? createGLJPanel(initMT, caps, useGears, animator, eSize) : ( useGLCanvas ? createGLCanvas(caps, useGears, animator, eSize) : null ); + if( null != glad ) { + glad.addGLEventListener(new GLEventListener() { + @Override + public void init(GLAutoDrawable drawable) { + initCount++; + } + @Override + public void dispose(GLAutoDrawable drawable) {} + @Override + public void display(GLAutoDrawable drawable) {} + @Override + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {} + }); + panel.add((Component)glad); + } else { + @SuppressWarnings("serial") + final JTextArea c = new JTextArea("area "+i) { + boolean initialized = false, added = false; + int reshapeWidth=0, reshapeHeight=0; + @Override + public void addNotify() { + added = true; + super.addNotify(); + } + @SuppressWarnings("deprecation") + @Override + public void reshape(int x, int y, int width, int height) { + super.reshape(x, y, width, height); + reshapeWidth = width; reshapeHeight = height; + } + @Override + protected void paintComponent(final Graphics g) { + super.paintComponent(g); + if( !initialized && added && reshapeWidth > 0 && reshapeHeight > 0 && isDisplayable() ) { + initialized = true; + initCount++; + } + } + }; + c.setEditable(false); + c.setSize(eSize); + c.setPreferredSize(eSize); + panel.add(c); + } frame[i].getContentPane().add(panel); // frame.validate(); @@ -124,9 +172,9 @@ public class TestPerf001GLJPanelInit02AWT extends UITestCase { } t[3] = Platform.currentTimeMillis(); final double panelCountF = frameCount; - System.err.printf("P: %d %s:%n\tctor\t%6d/t %6.2f/1%n\tvisible\t%6d/t %6.2f/1%n\tsum-i\t%6d/t %6.2f/1%n", + System.err.printf("P: %d %s%s:%n\tctor\t%6d/t %6.2f/1%n\tvisible\t%6d/t %6.2f/1%n\tsum-i\t%6d/t %6.2f/1%n", frameCount, - useGLJPanel?"GLJPanel":"GLCanvas", + useGLJPanel?"GLJPanel":(useGLCanvas?"GLCanvas":"No_GL"), initMT?" (mt)":" (01)", t[1]-t[0], (t[1]-t[0])/panelCountF, t[3]-t[1], (t[3]-t[1])/panelCountF, t[3]-t[0], (t[3]-t[0])/panelCountF); @@ -160,8 +208,8 @@ public class TestPerf001GLJPanelInit02AWT extends UITestCase { System.err.println("Total: "+(t[4]-t[0])); } - private GLAutoDrawable createGLCanvas(boolean useGears, GLAnimatorControl anim, Dimension size) { - GLCanvas canvas = new GLCanvas(); + private GLAutoDrawable createGLCanvas(GLCapabilitiesImmutable caps, boolean useGears, GLAnimatorControl anim, Dimension size) { + GLCanvas canvas = new GLCanvas(caps); canvas.setSize(size); canvas.setPreferredSize(size); if( useGears ) { @@ -172,8 +220,8 @@ public class TestPerf001GLJPanelInit02AWT extends UITestCase { } return canvas; } - private GLAutoDrawable createGLJPanel(boolean useGears, GLAnimatorControl anim, Dimension size) { - GLJPanel canvas = new GLJPanel(); + private GLAutoDrawable createGLJPanel(boolean initMT, GLCapabilitiesImmutable caps, boolean useGears, GLAnimatorControl anim, Dimension size) { + GLJPanel canvas = new GLJPanel(caps); canvas.setSize(size); canvas.setPreferredSize(size); if( useGears ) { @@ -182,17 +230,50 @@ public class TestPerf001GLJPanelInit02AWT extends UITestCase { if( null != anim ) { anim.add(canvas); } + if( initMT ) { + canvas.initializeBackend(true /* offthread */); + } return canvas; } + static GLCapabilitiesImmutable caps = null; + + @Test + public void test00NopNoGLDefGrid() throws InterruptedException, InvocationTargetException { + test(null, false /*useGears*/, width, height , frameCount, false /* initMT */, false /* useGLJPanel */, + false /* useGLCanvas */, false /*useAnim*/, false /* overlap */); + } + + @Test + public void test01NopGLCanvasDefGrid() throws InterruptedException, InvocationTargetException { + test(new GLCapabilities(null), false /*useGears*/, width, height , frameCount, false /* initMT */, false /* useGLJPanel */, + true /* useGLCanvas */, false /*useAnim*/, false /* overlap */); + } + @Test - public void test01NopGLJPanel() throws InterruptedException, InvocationTargetException { - test(false /*useGears*/, width, height, frameCount , true /* useGLJPanel */, false /*useAnim*/); + public void test02NopGLJPanelDefGridSingle() throws InterruptedException, InvocationTargetException { + test(new GLCapabilities(null), false /*useGears*/, width, height , frameCount, false /* initMT */, true /* useGLJPanel */, + false /* useGLCanvas */, false /*useAnim*/, false /* overlap */); } @Test - public void test02NopGLCanvas() throws InterruptedException, InvocationTargetException { - test(false /*useGears*/, width, height, frameCount , false /* useGLJPanel */, false /*useAnim*/); + public void test03NopGLJPanelDefGridMT() throws InterruptedException, InvocationTargetException { + test(new GLCapabilities(null), false /*useGears*/, width, height , frameCount, true /* initMT */, true /* useGLJPanel */, + false /* useGLCanvas */, false /*useAnim*/, false /* overlap */); + } + + // @Test + public void test04NopGLJPanelDefOverlapSingle() throws InterruptedException, InvocationTargetException { + test(new GLCapabilities(null), false /*useGears*/, width, height , frameCount, false /* initMT */, true /* useGLJPanel */, + false /* useGLCanvas */, false /*useAnim*/, true /* overlap */); + } + + // @Test + public void test05NopGLJPanelBitmapGridSingle() throws InterruptedException, InvocationTargetException { + GLCapabilities caps = new GLCapabilities(null); + caps.setBitmap(true); + test(caps, false /*useGears*/, width, height , frameCount, false /* initMT */, true /* useGLJPanel */, + false /* useGLCanvas */, false /*useAnim*/, false); } static long duration = 0; // ms @@ -202,7 +283,7 @@ public class TestPerf001GLJPanelInit02AWT extends UITestCase { volatile int initCount = 0; public static void main(String[] args) { - boolean useGLJPanel = true, useGears = false, manual=false; + boolean useGLJPanel = true, initMT = false, useGLCanvas = false, useGears = false, manual=false; boolean waitMain = false; for(int i=0; i<args.length; i++) { @@ -215,8 +296,17 @@ public class TestPerf001GLJPanelInit02AWT extends UITestCase { height = MiscUtils.atoi(args[++i], height); } else if(args[i].equals("-count")) { frameCount = MiscUtils.atoi(args[++i], frameCount); + } else if(args[i].equals("-initMT")) { + initMT = true; + manual = true; } else if(args[i].equals("-glcanvas")) { useGLJPanel = false; + useGLCanvas = true; + manual = true; + } else if(args[i].equals("-glnone")) { + useGLJPanel = false; + useGLCanvas = false; + manual = true; } else if(args[i].equals("-gears")) { useGears = true; } else if(args[i].equals("-wait")) { @@ -235,7 +325,7 @@ public class TestPerf001GLJPanelInit02AWT extends UITestCase { if( manual ) { GLProfile.initSingleton(); TestPerf001GLJPanelInit02AWT demo = new TestPerf001GLJPanelInit02AWT(); - demo.test(useGears, width, height, frameCount, useGLJPanel, false /*useAnim*/); + demo.test(null, useGears, width, height, frameCount, initMT, useGLJPanel, useGLCanvas, false /*useAnim*/, false /* overlap */); } else { org.junit.runner.JUnitCore.main(TestPerf001GLJPanelInit02AWT.class.getName()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLWindowInit03NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLWindowInit03NEWT.java new file mode 100644 index 000000000..ce93b2615 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLWindowInit03NEWT.java @@ -0,0 +1,203 @@ +/** + * Copyright 2013 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions 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. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.opengl.test.junit.jogl.perf; + +import java.lang.reflect.InvocationTargetException; + +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; + +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import com.jogamp.common.os.Platform; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Screen; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.UITestCase; + +/** + * Multiple GLJPanels in a JFrame + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestPerf001GLWindowInit03NEWT extends UITestCase { + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(); + } + + public void test(final GLCapabilitiesImmutable caps, final boolean useGears, final int width, final int height, final int frameCount, boolean reuseDevice) { + final int cols = (int)Math.round(Math.sqrt(frameCount)); + final int rows = frameCount / cols; + final int eWidth = width/cols; + final int eHeight = height/rows; + + final GLWindow[] frame = new GLWindow[frameCount]; + final long[] t = new long[10]; + if( wait ) { + UITestCase.waitForKey("Pre-Init"); + } + System.err.println("INIT START"); + initCount = 0; + + t[0] = Platform.currentTimeMillis(); + int x = 32, y = 32; + for(int i=0; i<frameCount; i++) { + final Screen screen = NewtFactory.createScreen(NewtFactory.createDisplay(null, reuseDevice), 0); + frame[i] = GLWindow.create(screen, caps); + frame[i].setTitle("frame_"+i+"/"+frameCount); + frame[i].setPosition(x, y); + x+=eWidth+32; + if(x>=width) { + x=32; + y+=eHeight+32; + } + frame[i].setSize(eWidth, eHeight); + if( useGears ) { + frame[i].addGLEventListener(new GearsES2()); + } + frame[i].addGLEventListener(new GLEventListener() { + @Override + public void init(GLAutoDrawable drawable) { + initCount++; + } + @Override + public void dispose(GLAutoDrawable drawable) {} + @Override + public void display(GLAutoDrawable drawable) {} + @Override + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {} + }); + } + t[1] = Platform.currentTimeMillis(); + for(int i=0; i<frameCount; i++) { + frame[i].setVisible(false /*wait*/, true /*visible*/); + } + t[2] = Platform.currentTimeMillis(); + + while( frameCount > initCount ) { + try { + Thread.sleep(10); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + } + t[3] = Platform.currentTimeMillis(); + final double panelCountF = frameCount; + System.err.printf("P: %d GLWindow:%n\tctor\t%6d/t %6.2f/1%n\tvisible\t%6d/t %6.2f/1%n\tsum-i\t%6d/t %6.2f/1%n", + frameCount, + t[1]-t[0], (t[1]-t[0])/panelCountF, + t[3]-t[1], (t[3]-t[1])/panelCountF, + t[3]-t[0], (t[3]-t[0])/panelCountF); + + System.err.println("INIT END: "+initCount); + if( wait ) { + UITestCase.waitForKey("Post-Init"); + } + try { + Thread.sleep(duration); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + t[4] = Platform.currentTimeMillis(); + for(int i=0; i<frameCount; i++) { + frame[i].destroy(); + } + + final long ti_net = (t[4]-t[0])-duration; + System.err.printf("T: duration %d %d%n\ttotal-d\t%6d/t %6.2f/1%n\ttotal-i\t%6d/t %6.2f/1%n", + duration, t[4]-t[3], + t[4]-t[0], (t[4]-t[0])/panelCountF, + ti_net, ti_net/panelCountF); + System.err.println("Total: "+(t[4]-t[0])); + } + + static GLCapabilitiesImmutable caps = null; + + @Test + public void test01NopGLWindowNoReuse() throws InterruptedException, InvocationTargetException { + test(new GLCapabilities(null), false /*useGears*/, width, height , frameCount, false /* reuseDevice */); + } + @Test + public void test02NopGLWindowReuse() throws InterruptedException, InvocationTargetException { + test(new GLCapabilities(null), false /*useGears*/, width, height , frameCount, true /* reuseDevice */); + } + + static long duration = 0; // ms + static boolean wait = false; + static int width = 800, height = 600, frameCount = 25; + + volatile int initCount = 0; + + public static void main(String[] args) { + boolean useGears = false, manual=false; + boolean waitMain = false; + + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + duration = MiscUtils.atol(args[i], duration); + } else if(args[i].equals("-width")) { + width = MiscUtils.atoi(args[++i], width); + } else if(args[i].equals("-height")) { + height = MiscUtils.atoi(args[++i], height); + } else if(args[i].equals("-count")) { + frameCount = MiscUtils.atoi(args[++i], frameCount); + } else if(args[i].equals("-gears")) { + useGears = true; + } else if(args[i].equals("-wait")) { + wait = true; + manual = true; + } else if(args[i].equals("-waitMain")) { + waitMain = true; + manual = true; + } else if(args[i].equals("-manual")) { + manual = true; + } + } + if( waitMain ) { + UITestCase.waitForKey("Main-Start"); + } + if( manual ) { + GLProfile.initSingleton(); + TestPerf001GLWindowInit03NEWT demo = new TestPerf001GLWindowInit03NEWT(); + demo.test(null, useGears, width, height, frameCount, false /* reuseDevice */); + } else { + org.junit.runner.JUnitCore.main(TestPerf001GLWindowInit03NEWT.class.getName()); + } + } + +} |