JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestShutdownCompleteAWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.jogl.acore;
30
31import java.awt.Frame;
32import java.io.IOException;
33import java.lang.reflect.InvocationTargetException;
34
35import com.jogamp.opengl.GLCapabilities;
36import com.jogamp.opengl.GLProfile;
37import com.jogamp.opengl.awt.GLCanvas;
38
39import org.junit.AfterClass;
40import org.junit.Assert;
41import org.junit.Test;
42import org.junit.FixMethodOrder;
43import org.junit.runners.MethodSorters;
44
45import com.jogamp.common.os.Platform;
46import com.jogamp.junit.util.JunitTracer;
47import com.jogamp.opengl.JoglVersion;
48import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
49import com.jogamp.opengl.test.junit.util.UITestCase;
50import com.jogamp.opengl.util.Animator;
51
52@FixMethodOrder(MethodSorters.NAME_ASCENDING)
53public class TestShutdownCompleteAWT extends UITestCase {
54
55 static long duration = 300; // ms
56
57 protected void runTestGL() throws InterruptedException, InvocationTargetException {
58 final Frame frame = new Frame("Gears AWT Test");
59 Assert.assertNotNull(frame);
60
61 final GLCanvas glCanvas = new GLCanvas(new GLCapabilities(GLProfile.getGL2ES2()));
62 Assert.assertNotNull(glCanvas);
63 frame.add(glCanvas);
64
65 glCanvas.addGLEventListener(new GearsES2(1));
66
67 final Animator animator = new Animator(glCanvas);
68
69 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
70 @Override
71 public void run() {
72 frame.setSize(256, 256);
73 frame.setVisible(true);
74 }});
75
76 animator.setUpdateFPSFrames(60, System.err);
77 animator.start();
78 Assert.assertEquals(true, animator.isAnimating());
79 Assert.assertEquals(true, glCanvas.isVisible());
80 Assert.assertEquals(true, glCanvas.isDisplayable());
81
82 while(animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
83 Thread.sleep(100);
84 }
85 Assert.assertEquals(true, glCanvas.isRealized());
86
87 animator.stop();
88 Assert.assertEquals(false, animator.isAnimating());
89 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
90 @Override
91 public void run() {
92 frame.setVisible(false);
93 }});
94 Assert.assertEquals(false, frame.isVisible());
95 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
96 @Override
97 public void run() {
98 frame.remove(glCanvas);
99 frame.dispose();
100 }});
101 }
102
103 @AfterClass
104 public static void afterAll() {
105 if(waitForKey) {
106 JunitTracer.waitForKey("Exit");
107 }
108 }
109
110 protected void oneLife(final boolean glInfo) throws InterruptedException, InvocationTargetException {
111 final long t0 = Platform.currentTimeMillis();
113 final long t1 = Platform.currentTimeMillis();
114 if(!initOnly) {
115 runTestGL();
116 }
117 final long t2 = Platform.currentTimeMillis();
118 if(glInfo) {
119 System.err.println(JoglVersion.getDefaultOpenGLInfo(null, null, false).toString());
120 }
121 final long t3 = Platform.currentTimeMillis();
123 final long t4 = Platform.currentTimeMillis();
124 System.err.println("Total: "+ (t4-t0) +"ms");
125 System.err.println(" GLProfile.initSingleton(): "+ (t1-t0) +"ms");
126 System.err.println(" Demo Code: "+ (t2-t1) +"ms");
127 System.err.println(" GLInfo: "+ (t3-t2) +"ms");
128 System.err.println(" GLProfile.shutdown(): "+ (t4-t3) +"ms");
129 }
130
131 @Test
132 public void test01OneLife() throws InterruptedException, InvocationTargetException {
133 oneLife(false);
134 }
135
136 @Test
137 public void test02AnotherLifeWithGLInfo() throws InterruptedException, InvocationTargetException {
138 oneLife(true);
139 }
140
141 @Test
142 public void test03AnotherLife() throws InterruptedException, InvocationTargetException {
143 oneLife(true);
144 }
145
146 @Test
147 public void test03TwoLifes() throws InterruptedException, InvocationTargetException {
148 oneLife(false);
149 oneLife(false);
150 }
151
152 static boolean initOnly = false;
153 static boolean waitForKey = false;
154
155 public static void main(final String args[]) throws IOException {
156 for(int i=0; i<args.length; i++) {
157 if(args[i].equals("-wait")) {
158 waitForKey = true;
159 } else if(args[i].equals("-initOnly")) {
160 initOnly = true;
161 }
162 }
163
164 if(waitForKey) {
165 JunitTracer.waitForKey("Start");
166 }
167 final String tstname = TestShutdownCompleteAWT.class.getName();
168 org.junit.runner.JUnitCore.main(tstname);
169 }
170
171}
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static void shutdown()
Manual shutdown method, may be called after your last JOGL use within the running JVM.
Definition: GLProfile.java:277
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
static void initSingleton()
Static initialization of JOGL.
Definition: GLProfile.java:204
static StringBuilder getDefaultOpenGLInfo(AbstractGraphicsDevice device, StringBuilder sb, final boolean withCapabilitiesInfo)
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
boolean isRealized()
Returns true if this drawable is realized, otherwise false.
Definition: GLCanvas.java:480
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368