JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestBug1398Deadlock02AWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2020 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 com.jogamp.opengl.GLProfile;
32import com.jogamp.opengl.GLCapabilities;
33import com.jogamp.opengl.awt.GLCanvas;
34import com.jogamp.opengl.util.Animator;
35import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
36import com.jogamp.opengl.test.junit.util.GLTestUtil;
37import com.jogamp.opengl.test.junit.util.UITestCase;
38import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
39
40import java.awt.Frame;
41import java.awt.event.WindowAdapter;
42import java.awt.event.WindowEvent;
43
44import org.junit.Assert;
45import org.junit.Assume;
46import org.junit.BeforeClass;
47import org.junit.Test;
48import org.junit.FixMethodOrder;
49import org.junit.runners.MethodSorters;
50
51
52@FixMethodOrder(MethodSorters.NAME_ASCENDING)
54 @BeforeClass
55 public static void startup() {
56 System.out.println("GLProfile "+GLProfile.glAvailabilityToString());
57 }
58
59 protected void runTestGL(final GLCapabilities caps, final boolean triggerDeadlock) throws InterruptedException {
60 final Frame frame = new Frame("TestBug1398AWT");
61 Assert.assertNotNull(frame);
62
63 final GLCanvas glCanvas = new GLCanvas(caps);
64 Assert.assertNotNull(glCanvas);
65
66 glCanvas.addGLEventListener(new GearsES2());
67
68 final Animator animator = new Animator(glCanvas);
69 animator.setUpdateFPSFrames(10, System.err);
70
71 frame.add(glCanvas);
72
73 frame.addWindowListener(new WindowAdapter() {
74 @Override
75 public void windowClosing(final WindowEvent e) {
76 animator.stop();
77 frame.dispose();
78 System.exit(0);
79 }
80 });
81
82 try {
83 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
84 @Override
85 public void run() {
86 // Revalidate size/layout.
87 // Always validate if component added/removed.
88 // Ensure 1st paint of GLCanvas will have a valid size, hence drawable gets created.
89 frame.setSize(512, 512);
90 if( triggerDeadlock ) {
91 frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH); // Bug1398 special case of AWTEDT(JOGL) -> AppKit -> AWTEDT deadlock
92 }
93 frame.validate();
94
95 frame.setVisible(true);
96 }});
97 } catch (final Throwable t) {
98 t.printStackTrace();
99 Assume.assumeNoException(t);
100 }
101 animator.start();
102 Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, true, null));
103 Assert.assertEquals(true, GLTestUtil.waitForContextCreated(glCanvas, true, null));
104
105 Thread.sleep(1000); // 1s
106
107 Assert.assertTrue(0 < animator.getTotalFPSFrames());
108
109 animator.stop();
110
111 try {
112 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
113 @Override
114 public void run() {
115 frame.setVisible(false);
116 frame.remove(glCanvas);
117 frame.dispose();
118 }});
119 } catch (final Throwable t) {
120 t.printStackTrace();
121 Assume.assumeNoException(t);
122 }
123 }
124
125 @Test(timeout = 10000)
126 public void test01NoDeadlock() throws InterruptedException {
127 final GLProfile glp = GLProfile.getDefault();
128 System.out.println("GLProfile Default: "+glp);
129 if(glp.isGL2ES2()) {
130 final GLCapabilities caps = new GLCapabilities(glp);
131 runTestGL(caps, false);
132 } else {
133 System.out.println("not a GL2ES2 profile");
134 }
135 }
136
137 @Test(timeout = 10000)
138 public void test02TriggerDeadlock() throws InterruptedException {
139 final GLProfile glp = GLProfile.getDefault();
140 System.out.println("GLProfile Default: "+glp);
141 if(glp.isGL2ES2()) {
142 final GLCapabilities caps = new GLCapabilities(glp);
143 runTestGL(caps, true);
144 } else {
145 System.out.println("not a GL2ES2 profile");
146 }
147 }
148
149 public static void main(final String args[]) {
150 org.junit.runner.JUnitCore.main(TestBug1398Deadlock02AWT.class.getName());
151 }
152}
NEWT Window events are provided for notification purposes ONLY.
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
final boolean isGL2ES2()
Indicates whether this profile is capable of GL2ES2.
static String glAvailabilityToString(final AbstractGraphicsDevice device)
Definition: GLProfile.java:333
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
void runTestGL(final GLCapabilities caps, final boolean triggerDeadlock)
static boolean waitForRealized(final java.awt.Component comp, final boolean realized, final Runnable waitAction)
static boolean waitForContextCreated(final GLAutoDrawable autoDrawable, final boolean created, final Runnable waitAction)
Definition: GLTestUtil.java:42
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