diff options
4 files changed, 357 insertions, 60 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 813eac385..9d6750f5b 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -662,6 +662,7 @@ function testawtswt() { #testawt com.jogamp.opengl.test.junit.jogl.awt.TestAWT01GLn $* #testawt com.jogamp.opengl.test.junit.jogl.awt.TestSwingAWT01GLn #testawt com.jogamp.opengl.test.junit.jogl.awt.TestAWT03GLCanvasRecreate01 $* +testawt com.jogamp.opengl.test.junit.jogl.awt.TestAWT03GLJPanelRecreate01 $* #testawt com.jogamp.opengl.test.junit.jogl.awt.TestAWT02WindowClosing #testawt com.jogamp.opengl.test.junit.jogl.awt.TestJScrollPaneMixHwLw01AWT $* #testawt com.jogamp.opengl.test.junit.jogl.awt.TestBug642JSplitPaneMixHwLw01AWT $* @@ -812,7 +813,7 @@ function testawtswt() { # Graph # #testnoawt com.jogamp.opengl.test.junit.graph.TestRegionRendererNEWT01 $* -testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT00 $* +#testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT00 $* #testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT01 $* #testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT10 $* #testnoawt com.jogamp.opengl.test.junit.graph.TestFontsNEWT00 $* diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index 126513ec7..01e13e545 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -78,6 +78,7 @@ import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLException; import javax.media.opengl.GLFBODrawable; +import javax.media.opengl.GLOffscreenAutoDrawable; import javax.media.opengl.GLProfile; import javax.media.opengl.GLRunnable; import javax.media.opengl.GLSharedContextSetter; @@ -540,12 +541,11 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing _lock.lock(); try { if( !isInitialized ) { - handleReshape = false; initializeBackendImpl(); } if (!isInitialized || printActive) { - return; + return; } // NOTE: must do this when the context is not current as it may @@ -554,13 +554,13 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing // current if( !printActive ) { if ( handleReshape ) { - handleReshape = false; - sendReshape = handleReshape(); + handleReshape = false; + sendReshape = handleReshape(); } if( isShowing ) { - updater.setGraphics(g); - backend.doPaintComponent(g); + updater.setGraphics(g); + backend.doPaintComponent(g); } } } finally { @@ -1295,23 +1295,24 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing private boolean initializeBackendImpl() { 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( handleReshape ) { + panelWidth = reshapeWidth; + panelHeight = reshapeHeight; + handleReshape = false; if (DEBUG) { - System.err.println(getThreadName()+": GLJPanel.createAndInitializeBackend: " + + System.err.println(getThreadName()+": GLJPanel.createAndInitializeBackend.1: " + panelWidth+"x"+panelHeight+" @ scale "+getPixelScaleStr() + " -> " + reshapeWidth+"x"+reshapeHeight+" @ scale "+getPixelScaleStr()); } - // Pull down reshapeWidth and reshapeHeight into panelWidth and - // panelHeight eagerly in order to complete initialization, and - // force a reshape later - panelWidth = reshapeWidth; - panelHeight = reshapeHeight; + } else { + if (DEBUG) { + System.err.println(getThreadName()+": GLJPanel.createAndInitializeBackend.0: " + + panelWidth+"x"+panelHeight+" @ scale "+getPixelScaleStr()); + } + } + + if ( 0 >= panelWidth || 0 >= panelHeight ) { + return false; } if ( null == backend ) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT03GLCanvasRecreate01.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT03GLCanvasRecreate01.java index 920fdda31..b074297e2 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT03GLCanvasRecreate01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT03GLCanvasRecreate01.java @@ -30,13 +30,13 @@ package com.jogamp.opengl.test.junit.jogl.awt; import javax.media.opengl.GLProfile; import javax.media.opengl.awt.GLCanvas; -import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.test.junit.util.UITestCase; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; - import com.jogamp.opengl.test.junit.util.MiscUtils; +import java.awt.Dimension; import java.awt.Frame; import java.awt.Label; @@ -52,12 +52,20 @@ import org.junit.runners.MethodSorters; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestAWT03GLCanvasRecreate01 extends UITestCase { - static long durationPerTest = 1000; // ms + static long durationPerTest = 500; // ms + + final static int sizeEps = 64; + final static Dimension size1 = new Dimension(512, 512-sizeEps-1); + final static Dimension size2 = new Dimension(512+sizeEps+1+256, 512+256); + final static Dimension size3 = new Dimension(512-256, 512-sizeEps-1-256); Frame frame1=null; Frame frame2=null; - GLCanvas glCanvas=null; - Label label = null; + Frame frame3=null; + GLCanvas glComp=null; + Label label1 = null; + Label label2 = null; + Label label3 = null; Animator animator = null; @BeforeClass @@ -67,39 +75,50 @@ public class TestAWT03GLCanvasRecreate01 extends UITestCase { @Before public void init() { - glCanvas = new GLCanvas(); - Assert.assertNotNull(glCanvas); - glCanvas.addGLEventListener(new GearsES2()); + glComp = new GLCanvas(); + Assert.assertNotNull(glComp); + glComp.addGLEventListener(new GearsES2()); - animator = new Animator(glCanvas); + animator = new Animator(glComp); animator.start(); - label = new Label("No GLCanvas"); - + label1 = new Label("L1 - No GLCanvas"); + label1.setMinimumSize(size1); + label1.setPreferredSize(size1); frame1 = new Frame("Frame 1"); Assert.assertNotNull(frame1); - frame1.add(label); - frame1.setSize(512, 512); + frame1.add(label1); frame1.setLocation(0, 0); + label2 = new Label("L2 - No GLCanvas"); + label2.setMinimumSize(size2); + label2.setPreferredSize(size2); frame2 = new Frame("Frame 2"); Assert.assertNotNull(frame2); - frame2.add(label); - frame2.setSize(512, 512); - frame2.setLocation(512, 0); + frame2.add(label2); + frame2.setLocation(size1.width + size1.width/2, 0); + + label3 = new Label("L3 - No GLCanvas"); + label3.setMinimumSize(size3); + label3.setPreferredSize(size3); + frame3 = new Frame("Frame 3"); + Assert.assertNotNull(frame3); + frame3.add(label3); + frame3.setLocation(0, size1.height + size1.height/2); } @After public void release() { Assert.assertNotNull(frame1); Assert.assertNotNull(frame2); - Assert.assertNotNull(glCanvas); + Assert.assertNotNull(glComp); try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { - glCanvas.destroy(); + glComp.destroy(); frame1.dispose(); frame2.dispose(); + frame3.dispose(); }}); } catch (final Throwable t) { t.printStackTrace(); @@ -107,19 +126,22 @@ public class TestAWT03GLCanvasRecreate01 extends UITestCase { } frame1=null; frame2=null; - glCanvas=null; + frame3=null; + glComp=null; animator.stop(); animator=null; } - private void addCanvas(final Frame frame) { + private void addCanvas(final Frame frame, final Label label, final Dimension size) { try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame.remove(label); - frame.add(glCanvas); - frame.validate(); + glComp.setPreferredSize(size); + glComp.setMinimumSize(size); + frame.add(glComp); + frame.pack(); }}); } catch (final Throwable t) { t.printStackTrace(); @@ -127,13 +149,14 @@ public class TestAWT03GLCanvasRecreate01 extends UITestCase { } } - private void removeCanvas(final Frame frame) { + private void removeCanvas(final Frame frame, final Label label) { try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { - frame.remove(glCanvas); + frame.remove(glComp); frame.add(label); - frame.validate(); + frame.pack(); + frame.repaint(); }}); } catch (final Throwable t) { t.printStackTrace(); @@ -145,6 +168,7 @@ public class TestAWT03GLCanvasRecreate01 extends UITestCase { try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { + frame.pack(); frame.setVisible(v); }}); } catch (final Throwable t) { @@ -153,26 +177,56 @@ public class TestAWT03GLCanvasRecreate01 extends UITestCase { } } + private void assertSize(final Dimension expSize) { + final int[] scale = { 1, 1 }; + glComp.getNativeSurfaceScale(scale); - @Test - public void testAddRemove3Times() throws InterruptedException { - setVisible(frame1, true); - setVisible(frame2, true); + final Dimension hasSize = glComp.getSize(null); - addCanvas(frame1); - Thread.sleep(durationPerTest/4); + Assert.assertTrue("AWT Size.width mismatch: expected "+expSize+", has "+hasSize, + Math.abs(expSize.width-hasSize.width) <= sizeEps); + Assert.assertTrue("AWT Size.height mismatch: expected "+expSize+", has "+hasSize, + Math.abs(expSize.height-hasSize.height) <= sizeEps); - removeCanvas(frame1); - addCanvas(frame2); - Thread.sleep(durationPerTest/4); + final int expSurfWidth = expSize.width * scale[0]; + final int expSurfHeight = expSize.height * scale[0]; + final int hasSurfWidth = glComp.getSurfaceWidth(); + final int hasSurfHeight = glComp.getSurfaceHeight(); - removeCanvas(frame2); - addCanvas(frame1); - Thread.sleep(durationPerTest/4); + Assert.assertTrue("GL Size.width mismatch: expected "+expSurfWidth+", has "+hasSurfWidth, + Math.abs(expSurfWidth-hasSurfWidth) <= sizeEps); + Assert.assertTrue("GL Size.height mismatch: expected "+expSurfHeight+", has "+hasSurfHeight, + Math.abs(expSurfHeight-hasSurfHeight) <= sizeEps); + } - removeCanvas(frame1); - addCanvas(frame2); - Thread.sleep(durationPerTest/4); + @Test + public void testAddRemove3Times() throws InterruptedException { + setVisible(frame1, true); + setVisible(frame2, true); + setVisible(frame3, true); + + // Init Frame 1 + addCanvas(frame1, label1, size1); + Thread.sleep(durationPerTest); + assertSize(size1); + + // Frame 1 -> Frame 2 + removeCanvas(frame1, label1); + addCanvas(frame2, label2, size2); + Thread.sleep(durationPerTest); + assertSize(size2); + + // Frame 2 -> Frame 3 + removeCanvas(frame2, label2); + addCanvas(frame3, label3, size3); + Thread.sleep(durationPerTest); + assertSize(size3); + + // Frame 3 -> Frame 1 + removeCanvas(frame3, label3); + addCanvas(frame1, label1, size1); + Thread.sleep(durationPerTest); + assertSize(size1); } public static void main(final String args[]) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT03GLJPanelRecreate01.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT03GLJPanelRecreate01.java new file mode 100644 index 000000000..b2d487784 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT03GLJPanelRecreate01.java @@ -0,0 +1,241 @@ +/** + * Copyright 2010 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.awt; + +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLJPanel; +import javax.swing.JFrame; +import javax.swing.JLabel; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.util.MiscUtils; + +import java.awt.BorderLayout; +import java.awt.Dimension; + +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Test; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestAWT03GLJPanelRecreate01 extends UITestCase { + static long durationPerTest = 500; // ms + + final static int sizeEps = 64; + final static Dimension size1 = new Dimension(512, 512-sizeEps-1); + final static Dimension size2 = new Dimension(512+sizeEps+1+256, 512+256); + final static Dimension size3 = new Dimension(512-256, 512-sizeEps-1-256); + + JFrame frame1=null; + JFrame frame2=null; + JFrame frame3=null; + GLJPanel glComp=null; + JLabel label1 = null; + JLabel label2 = null; + JLabel label3 = null; + Animator animator = null; + + @BeforeClass + public static void startup() { + System.out.println("GLProfile "+GLProfile.glAvailabilityToString()); + } + + @Before + public void init() { + glComp = new GLJPanel(); + Assert.assertNotNull(glComp); + glComp.addGLEventListener(new GearsES2()); + + animator = new Animator(glComp); + animator.start(); + + label1 = new JLabel("L1 - No GLJPanel"); + label1.setMinimumSize(size1); + label1.setPreferredSize(size1); + frame1 = new JFrame("Frame 1"); + Assert.assertNotNull(frame1); + frame1.add(label1); + frame1.setLocation(0, 0); + + label2 = new JLabel("L2 - No GLJPanel"); + label2.setMinimumSize(size2); + label2.setPreferredSize(size2); + frame2 = new JFrame("Frame 2"); + Assert.assertNotNull(frame2); + frame2.add(label2); + frame2.setLocation(size1.width, 0); + + label3 = new JLabel("L3 - No GLJPanel"); + label3.setMinimumSize(size3); + label3.setPreferredSize(size3); + frame3 = new JFrame("Frame 3"); + Assert.assertNotNull(frame3); + frame3.add(label3); + frame3.setLocation(0, size1.height); + } + + @After + public void release() { + Assert.assertNotNull(frame1); + Assert.assertNotNull(frame2); + Assert.assertNotNull(glComp); + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + glComp.destroy(); + frame1.dispose(); + frame2.dispose(); + frame3.dispose(); + }}); + } catch (final Throwable t) { + t.printStackTrace(); + Assume.assumeNoException(t); + } + frame1=null; + frame2=null; + frame3=null; + glComp=null; + + animator.stop(); + animator=null; + } + + private void addCanvas(final JFrame frame, final JLabel label, final Dimension size) { + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.getContentPane().remove(label); + glComp.setPreferredSize(size); + glComp.setMinimumSize(size); + frame.getContentPane().add(glComp, BorderLayout.CENTER); + frame.pack(); + }}); + } catch (final Throwable t) { + t.printStackTrace(); + Assume.assumeNoException(t); + } + } + + private void removeCanvas(final JFrame frame, final JLabel label) { + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.getContentPane().remove(glComp); + frame.getContentPane().add(label); + frame.pack(); + frame.repaint(); + }}); + } catch (final Throwable t) { + t.printStackTrace(); + Assume.assumeNoException(t); + } + } + + private void setVisible(final JFrame frame, final boolean v) { + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.pack(); + frame.setVisible(v); + }}); + } catch (final Throwable t) { + t.printStackTrace(); + Assume.assumeNoException(t); + } + } + + private void assertSize(final Dimension expSize) { + final int[] scale = { 1, 1 }; + glComp.getNativeSurfaceScale(scale); + + final Dimension hasSize = glComp.getSize(null); + + Assert.assertTrue("AWT Size.width mismatch: expected "+expSize+", has "+hasSize, + Math.abs(expSize.width-hasSize.width) <= sizeEps); + Assert.assertTrue("AWT Size.height mismatch: expected "+expSize+", has "+hasSize, + Math.abs(expSize.height-hasSize.height) <= sizeEps); + + final int expSurfWidth = expSize.width * scale[0]; + final int expSurfHeight = expSize.height * scale[0]; + final int hasSurfWidth = glComp.getSurfaceWidth(); + final int hasSurfHeight = glComp.getSurfaceHeight(); + + Assert.assertTrue("GL Size.width mismatch: expected "+expSurfWidth+", has "+hasSurfWidth, + Math.abs(expSurfWidth-hasSurfWidth) <= sizeEps); + Assert.assertTrue("GL Size.height mismatch: expected "+expSurfHeight+", has "+hasSurfHeight, + Math.abs(expSurfHeight-hasSurfHeight) <= sizeEps); + } + + @Test + public void testAddRemove3Times() throws InterruptedException { + setVisible(frame1, true); + setVisible(frame2, true); + setVisible(frame3, true); + + // Init Frame 1 + addCanvas(frame1, label1, size1); + Thread.sleep(durationPerTest); + assertSize(size1); + + // Frame 1 -> Frame 2 + removeCanvas(frame1, label1); + addCanvas(frame2, label2, size2); + Thread.sleep(durationPerTest); + assertSize(size2); + + // Frame 2 -> Frame 3 + removeCanvas(frame2, label2); + addCanvas(frame3, label3, size3); + Thread.sleep(durationPerTest); + assertSize(size3); + + // Frame 3 -> Frame 1 + removeCanvas(frame3, label3); + addCanvas(frame1, label1, size1); + Thread.sleep(durationPerTest); + assertSize(size1); + } + + public static void main(final String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = MiscUtils.atoi(args[++i], (int)durationPerTest); + } + } + org.junit.runner.JUnitCore.main(TestAWT03GLJPanelRecreate01.class.getName()); + } +} |