JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestFBOAutoDrawableDeadlockAWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2011 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 */
28package com.jogamp.opengl.test.junit.jogl.acore;
29
30import java.awt.EventQueue;
31import java.lang.reflect.InvocationTargetException;
32
33import com.jogamp.opengl.DefaultGLCapabilitiesChooser;
34import com.jogamp.opengl.GLCapabilities;
35import com.jogamp.opengl.GLDrawableFactory;
36import com.jogamp.opengl.GLOffscreenAutoDrawable;
37import com.jogamp.opengl.GLProfile;
38
39import jogamp.nativewindow.jawt.JAWTUtil;
40
41import org.junit.Assert;
42import org.junit.BeforeClass;
43import org.junit.Test;
44import org.junit.FixMethodOrder;
45import org.junit.runners.MethodSorters;
46
47import com.jogamp.common.util.InterruptSource;
48import com.jogamp.common.util.RunnableTask;
49import com.jogamp.opengl.test.junit.util.UITestCase;
50
51@FixMethodOrder(MethodSorters.NAME_ASCENDING)
53 static GLProfile glp;
54 static int width, height;
55
56 @BeforeClass
57 public static void initClass() {
58 glp = GLProfile.getGL2ES2();
59 Assert.assertNotNull( glp );
60 width = 512;
61 height = 512;
62 }
63
64 protected void runTestGL( final GLCapabilities caps ) throws InterruptedException, InvocationTargetException {
66 null, caps, new DefaultGLCapabilitiesChooser(), 512, 512);
67
68 final boolean[] done = {false};
69 final Runnable pbufferCreationAction = new Runnable() {
70 public void run() {
71 System.err.println("AA.1");
72 fbod.display();
73 done[ 0 ] = true;
74 System.err.println("AA.X");
75 }
76 };
77
78 EventQueue.invokeAndWait(new Runnable() {
79 public void run() {
80 Assert.assertTrue(EventQueue.isDispatchThread());
81 JAWTUtil.lockToolkit();
82 try {
83 final RunnableTask rTask = new RunnableTask(pbufferCreationAction, new Object(), false, null);
84 System.err.println("BB.0: "+rTask.getSyncObject());
85 synchronized (rTask.getSyncObject()) {
86 System.err.println("BB.1: "+rTask.getSyncObject());
87 new InterruptSource.Thread(null, rTask, Thread.currentThread().getName()+"-Pbuffer_Creation").start();
88 try {
89 System.err.println("BB.2");
90 rTask.getSyncObject().wait();
91 System.err.println("BB.3");
92 } catch (final InterruptedException e) {
93 throw new RuntimeException(e);
94 }
95 System.err.println("BB.X");
96 }
97 } finally {
98 JAWTUtil.unlockToolkit();
99 }
100 }
101 });
102 Assert.assertTrue(done[0]);
103 fbod.destroy();
104 }
105
106 @Test(timeout = 10000)
107 public void testDeadlock() throws InterruptedException, InvocationTargetException {
108 final GLCapabilities caps = new GLCapabilities( glp );
109 runTestGL( caps );
110 }
111
112 static long duration = 500; // ms
113
114 public static void main( final String args[] ) {
115 for ( int i = 0; i < args.length; i++ ) {
116 if ( args[ i ].equals( "-time" ) ) {
117 i++;
118 try {
119 duration = Integer.parseInt( args[ i ] );
120 }
121 catch ( final Exception ex ) {
122 ex.printStackTrace();
123 }
124 }
125 }
126 org.junit.runner.JUnitCore.main( TestFBOAutoDrawableDeadlockAWT.class.getName() );
127 }
128}
Specifies a set of OpenGL capabilities.
abstract GLOffscreenAutoDrawable createOffscreenAutoDrawable(AbstractGraphicsDevice device, GLCapabilitiesImmutable caps, GLCapabilitiesChooser chooser, int width, int height)
Creates a realized GLOffscreenAutoDrawable incl it's offscreen NativeSurface with the given capabilit...
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Platform-independent GLAutoDrawable specialization, exposing offscreen functionality.