aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-09-06 23:14:11 +0200
committerSven Gothel <[email protected]>2013-09-06 23:14:11 +0200
commitb780eff49b626bd8429e1e87609f7a917f7b094e (patch)
tree40211bcd92c25aea0a005e0de57106ec540498bc /src/test
parent95d49687f5b9b783f3d8008df86df58cc0f9bfab (diff)
GLCanvas Printing WIP: Add GLJPanel; GLCanvas TILE_SIZE 512; print(Graphics): Don't force on AWT-EDT -> Deadlock; releasePrint(): perform reshape/display!
Diffstat (limited to 'src/test')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java9
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java226
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/tile/TiledPrintingAWTBase.java9
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java18
4 files changed, 249 insertions, 13 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java
index 7d6135935..30967d75b 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java
@@ -58,6 +58,7 @@ import com.jogamp.newt.event.TraceWindowAdapter;
import com.jogamp.newt.event.awt.AWTKeyAdapter;
import com.jogamp.newt.event.awt.AWTWindowAdapter;
import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
import com.jogamp.opengl.test.junit.util.QuitAdapter;
import com.jogamp.opengl.util.Animator;
@@ -97,7 +98,7 @@ public class TestTiledPrintingGearsAWT extends TiledPrintingAWTBase {
final Gears gears = new Gears();
glCanvas.addGLEventListener(gears);
- final Frame frame = new Frame("Gears AWT Test");
+ final Frame frame = new Frame("AWT Print (offscr "+offscreenPrinting+")");
Assert.assertNotNull(frame);
final ActionListener print72DPIAction = new ActionListener() {
@@ -141,6 +142,9 @@ public class TestTiledPrintingGearsAWT extends TiledPrintingAWTBase {
frame.pack();
frame.setVisible(true);
}});
+ Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, true));
+
animator.setUpdateFPSFrames(60, System.err);
animator.start();
@@ -157,6 +161,9 @@ public class TestTiledPrintingGearsAWT extends TiledPrintingAWTBase {
}
}
+ try {
+ Thread.sleep(1000); // time to flush ..
+ } catch (InterruptedException e) { }
Assert.assertNotNull(frame);
Assert.assertNotNull(glCanvas);
Assert.assertNotNull(animator);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java
new file mode 100644
index 000000000..260c9e04c
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java
@@ -0,0 +1,226 @@
+/**
+ * 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.tile;
+
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.Label;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.print.PageFormat;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLJPanel;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+import com.jogamp.newt.event.TraceKeyAdapter;
+import com.jogamp.newt.event.TraceWindowAdapter;
+import com.jogamp.newt.event.awt.AWTKeyAdapter;
+import com.jogamp.newt.event.awt.AWTWindowAdapter;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
+import com.jogamp.opengl.test.junit.util.QuitAdapter;
+import com.jogamp.opengl.util.Animator;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase {
+
+ static boolean waitForKey = false;
+ static GLProfile glp;
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ if(GLProfile.isAvailable(GLProfile.GL2)) {
+ glp = GLProfile.get(GLProfile.GL2);
+ Assert.assertNotNull(glp);
+ width = 640;
+ height = 480;
+ } else {
+ setTestSupported(false);
+ }
+ // Runtime.getRuntime().traceInstructions(true);
+ // Runtime.getRuntime().traceMethodCalls(true);
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ protected void runTestGL(GLCapabilities caps, final boolean offscreenPrinting) throws InterruptedException, InvocationTargetException {
+ final GLJPanel glJPanel = new GLJPanel(caps);
+ Assert.assertNotNull(glJPanel);
+ Dimension glc_sz = new Dimension(width, height);
+ glJPanel.setMinimumSize(glc_sz);
+ glJPanel.setPreferredSize(glc_sz);
+ glJPanel.setSize(glc_sz);
+
+ final Gears gears = new Gears();
+ glJPanel.addGLEventListener(gears);
+
+ final JFrame frame = new JFrame("Swing Print (offscr "+offscreenPrinting+")");
+ Assert.assertNotNull(frame);
+
+ final ActionListener print72DPIAction = new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ doPrintManual(frame, glJPanel, TestTiledPrintingGearsSwingAWT.this, offscreenPrinting, 72);
+ } };
+ final ActionListener print300DPIAction = new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ doPrintManual(frame, glJPanel, TestTiledPrintingGearsSwingAWT.this, offscreenPrinting, 300);
+ } };
+ final Button print72DPIButton = new Button("72dpi");
+ print72DPIButton.addActionListener(print72DPIAction);
+ final Button print300DPIButton = new Button("300dpi");
+ print300DPIButton.addActionListener(print300DPIAction);
+
+ final JPanel printPanel = new JPanel();
+ printPanel.add(print72DPIButton);
+ printPanel.add(print300DPIButton);
+ final JPanel southPanel = new JPanel();
+ southPanel.add(new Label("South"));
+ final JPanel eastPanel = new JPanel();
+ eastPanel.add(new Label("East"));
+ final JPanel westPanel = new JPanel();
+ westPanel.add(new Label("West"));
+
+ Animator animator = new Animator(glJPanel);
+ QuitAdapter quitAdapter = new QuitAdapter();
+
+ new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter)).addTo(glJPanel);
+ new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame);
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ final Container fcont = frame.getContentPane();
+ fcont.setLayout(new BorderLayout());
+ fcont.add(printPanel, BorderLayout.NORTH);
+ fcont.add(glJPanel, BorderLayout.CENTER);
+ fcont.add(southPanel, BorderLayout.SOUTH);
+ fcont.add(eastPanel, BorderLayout.EAST);
+ fcont.add(westPanel, BorderLayout.WEST);
+ fcont.validate();
+ frame.pack();
+ frame.setVisible(true);
+ } } ) ;
+
+ Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glJPanel, true));
+
+ animator.setUpdateFPSFrames(60, System.err);
+ animator.start();
+ Assert.assertEquals(true, animator.isAnimating());
+
+ boolean dpi72Done = false;
+ boolean dpi300Done = false;
+ while(!quitAdapter.shouldQuit() && animator.isAnimating() && ( 0 == duration || animator.getTotalFPSDuration()<duration )) {
+ Thread.sleep(200);
+ if( !dpi72Done ) {
+ dpi72Done = true;
+ System.err.println("XXX "+glJPanel);
+ doPrintAuto(frame, glJPanel, TestTiledPrintingGearsSwingAWT.this, PageFormat.LANDSCAPE, null, offscreenPrinting, 72);
+ } else if( !dpi300Done ) {
+ dpi300Done = true;
+ doPrintAuto(frame, glJPanel, TestTiledPrintingGearsSwingAWT.this, PageFormat.LANDSCAPE, null, offscreenPrinting, 300);
+ }
+ }
+
+ try {
+ Thread.sleep(1000); // time to flush ..
+ } catch (InterruptedException e) { }
+ Assert.assertNotNull(frame);
+ Assert.assertNotNull(glJPanel);
+ Assert.assertNotNull(animator);
+
+ animator.stop();
+ Assert.assertEquals(false, animator.isAnimating());
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setVisible(false);
+ }});
+ Assert.assertEquals(false, frame.isVisible());
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ final Frame _frame = frame;
+ _frame.remove(glJPanel);
+ _frame.dispose();
+ }});
+ }
+
+ @Test
+ public void test01_Onscreen() throws InterruptedException, InvocationTargetException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ runTestGL(caps, false);
+ }
+ @Test
+ public void test02_Offscreen() throws InterruptedException, InvocationTargetException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ runTestGL(caps, true);
+ }
+
+ static long duration = 500; // ms
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ duration = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ } else if(args[i].equals("-wait")) {
+ waitForKey = true;
+ }
+ }
+ if(waitForKey) {
+ BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
+ System.err.println("Press enter to continue");
+ try {
+ System.err.println(stdin.readLine());
+ } catch (IOException e) { }
+ }
+ org.junit.runner.JUnitCore.main(TestTiledPrintingGearsSwingAWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TiledPrintingAWTBase.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TiledPrintingAWTBase.java
index 4a5953b5a..80268b07c 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TiledPrintingAWTBase.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TiledPrintingAWTBase.java
@@ -175,8 +175,10 @@ public abstract class TiledPrintingAWTBase extends UITestCase implements Printab
g2d.scale(scale , scale );
}
- frame.printAll(g2d);
- awtPrintObject.releasePrint();
+ AWTEDTExecutor.singleton.invoke(true, new Runnable() {
+ public void run() {
+ frame.printAll(g2d);
+ } } );
if( scaleComp != 1 ) {
System.err.println("PRINT DPI: reset frame size "+frameWidth+"x"+frameHeight);
@@ -188,13 +190,14 @@ public abstract class TiledPrintingAWTBase extends UITestCase implements Printab
}
});
}
+ awtPrintObject.releasePrint();
if( g2d == offscreenG2D ) {
printG2D.translate(moveX, moveY);
printG2D.scale(scale , scale );
printG2D.drawImage(offscreenImage, 0, 0, offscreenImage.getWidth(), offscreenImage.getHeight(), null); // Null ImageObserver since image data is ready.
}
-
+
/* tell the caller that this page is part of the printed document */
return PAGE_EXISTS;
}
diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
index a760bbb27..e85052d08 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
@@ -39,8 +39,8 @@ import java.awt.Robot;
import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLDrawable;
-import javax.media.opengl.awt.GLCanvas;
import org.junit.Assert;
@@ -702,21 +702,21 @@ public class AWTRobotUtil {
Thread.sleep(TIME_SLICE);
}
// if GLCanvas, ensure it got also painted -> drawable.setRealized(true);
- if(wait<POLL_DIVIDER && comp instanceof GLCanvas) {
- GLCanvas glcanvas = (GLCanvas) comp;
- for (wait=0; wait<POLL_DIVIDER && realized != glcanvas.isRealized(); wait++) {
+ if(wait<POLL_DIVIDER && comp instanceof GLAutoDrawable) {
+ GLAutoDrawable glad = (GLAutoDrawable) comp;
+ for (wait=0; wait<POLL_DIVIDER && realized != glad.isRealized(); wait++) {
Thread.sleep(TIME_SLICE);
}
if(wait>=POLL_DIVIDER) {
// for some reason GLCanvas hasn't been painted yet, force it!
- System.err.println("XXX: FORCE REPAINT PRE - canvas: "+glcanvas);
- glcanvas.repaint();
- for (wait=0; wait<POLL_DIVIDER && realized != glcanvas.isRealized(); wait++) {
+ System.err.println("XXX: FORCE REPAINT PRE - glad: "+glad);
+ comp.repaint();
+ for (wait=0; wait<POLL_DIVIDER && realized != glad.isRealized(); wait++) {
Thread.sleep(TIME_SLICE);
}
- System.err.println("XXX: FORCE REPAINT POST - canvas: "+glcanvas);
+ System.err.println("XXX: FORCE REPAINT POST - glad: "+glad);
}
- for (wait=0; wait<POLL_DIVIDER && realized != glcanvas.isRealized(); wait++) {
+ for (wait=0; wait<POLL_DIVIDER && realized != glad.isRealized(); wait++) {
Thread.sleep(TIME_SLICE);
}
}