JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestPBufferDeadlockAWT.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.GLAutoDrawable;
34import com.jogamp.opengl.GLCapabilities;
35import com.jogamp.opengl.GLDrawableFactory;
36import com.jogamp.opengl.GLProfile;
37
38import jogamp.nativewindow.jawt.JAWTUtil;
39
40import org.junit.Assert;
41import org.junit.BeforeClass;
42import org.junit.Test;
43import org.junit.FixMethodOrder;
44import org.junit.runners.MethodSorters;
45
46import com.jogamp.common.util.InterruptSource;
47import com.jogamp.common.util.RunnableTask;
48import com.jogamp.opengl.test.junit.util.UITestCase;
49
50@FixMethodOrder(MethodSorters.NAME_ASCENDING)
51public class TestPBufferDeadlockAWT extends UITestCase {
52 static GLProfile glp;
53 static int width, height;
54
55 @BeforeClass
56 public static void initClass() {
57 glp = GLProfile.getMaxFixedFunc(true);
58 Assert.assertNotNull( glp );
59 width = 512;
60 height = 512;
61 }
62
63 protected void runTestGL( final GLCapabilities caps ) throws InterruptedException, InvocationTargetException {
64 caps.setPBuffer(true);
65 final GLAutoDrawable pbuffer = GLDrawableFactory.getFactory( caps.getGLProfile() ).createOffscreenAutoDrawable(null, caps, null, 512, 512);
66
67 final boolean[] done = {false};
68 final Runnable pbufferCreationAction = new Runnable() {
69 public void run() {
70 System.err.println("AA.1");
71 pbuffer.display();
72 done[ 0 ] = true;
73 System.err.println("AA.X");
74 }
75 };
76
77 EventQueue.invokeAndWait(new Runnable() {
78 public void run() {
79 Assert.assertTrue(EventQueue.isDispatchThread());
80 JAWTUtil.lockToolkit();
81 try {
82 final RunnableTask rTask = new RunnableTask(pbufferCreationAction, new Object(), false, null);
83 System.err.println("BB.0: "+rTask.getSyncObject());
84 synchronized (rTask.getSyncObject()) {
85 System.err.println("BB.1: "+rTask.getSyncObject());
86 new InterruptSource.Thread(null, rTask, Thread.currentThread().getName()+"-Pbuffer_Creation").start();
87 try {
88 System.err.println("BB.2");
89 rTask.getSyncObject().wait();
90 System.err.println("BB.3");
91 } catch (final InterruptedException e) {
92 throw new RuntimeException(e);
93 }
94 System.err.println("BB.X");
95 }
96 } finally {
97 JAWTUtil.unlockToolkit();
98 }
99 }
100 });
101 Assert.assertTrue(done[0]);
102 pbuffer.destroy();
103 }
104
105 @Test(timeout = 10000)
106 public void testDeadlock() throws InterruptedException, InvocationTargetException {
107 final GLCapabilities caps = new GLCapabilities( glp );
108 runTestGL( caps );
109 }
110
111 static long duration = 500; // ms
112
113 public static void main( final String args[] ) {
114 for ( int i = 0; i < args.length; i++ ) {
115 if ( args[ i ].equals( "-time" ) ) {
116 i++;
117 try {
118 duration = Integer.parseInt( args[ i ] );
119 }
120 catch ( final Exception ex ) {
121 ex.printStackTrace();
122 }
123 }
124 }
125 org.junit.runner.JUnitCore.main( TestPBufferDeadlockAWT.class.getName() );
126 }
127}
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 getMaxFixedFunc(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the fixed function pipeline.
Definition: GLProfile.java:808
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.