JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestBug722GLContextDrawableSwitchNewt2AWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2013 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.glels;
30
31import java.io.IOException;
32
33import com.jogamp.opengl.GLCapabilities;
34import com.jogamp.opengl.GLProfile;
35
36
37import com.jogamp.newt.Display;
38import com.jogamp.newt.NewtFactory;
39import com.jogamp.newt.Screen;
40import com.jogamp.opengl.GLEventListenerState;
41import com.jogamp.opengl.util.Animator;
42import com.jogamp.opengl.GLRendererQuirks;
43import com.jogamp.opengl.test.junit.util.GLEventListenerCounter;
44import com.jogamp.opengl.test.junit.util.MiscUtils;
45
46import org.junit.Test;
47import org.junit.FixMethodOrder;
48import org.junit.runners.MethodSorters;
49
50/**
51 * Tests Bug 722
52 * <p>
53 * See Bug 722 - https://jogamp.org/bugzilla/show_bug.cgi?id=722.
54 * </p>
55 */
56@FixMethodOrder(MethodSorters.NAME_ASCENDING)
58
59 static int loops = 10;
60 static long duration2 = 100; // ms
61
62 /**
63 * Interesting artifact w/ ATI proprietary driver is that the
64 * bug causing the quirk {@link GLRendererQuirks#DontCloseX11Display}
65 * also causes an XCB crash when reusing the X11 display connection
66 * from AWT -> NEWT. Pre-allocating the X11 Display and keeping it referenced
67 * to avoid such re-usage worksaround this problem.
68 */
69 public static boolean fixedNewtDisplay = true;
70
71 @Test(timeout=180000) // TO 3 min
72 public void test11GLWindow2GLCanvasOnScrnGL2ES2() throws InterruptedException {
73 final GLCapabilities caps = getCaps(GLProfile.GL2ES2);
74 if(null == caps) {
75 System.err.println("GL2ES2 n/a, test n/a.");
76 return;
77 }
78 if( jogamp.nativewindow.jawt.JAWTUtil.isOffscreenLayerRequired() ) {
79 System.err.println("JAWT required offscreen, test n/a.");
80 return;
81 }
82
83
84 final GLADType gladType1 = GLADType.GLWindow;
85 final GLADType gladType2 = GLADType.GLCanvasOnscreen;
86
87 final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener();
88 final Animator animator = new Animator();
89 animator.start();
90
91 final Display dpy;
92 final Screen screen;
93 if( fixedNewtDisplay ) {
94 dpy = NewtFactory.createDisplay(null);
95 screen = NewtFactory.createScreen(dpy, 0);
96 screen.addReference();
97 } else {
98 dpy = null;
99 screen = null;
100 }
101
102 duration = duration2;
103
104 for(int i=0; i<loops; i++) {
105 final GLEventListenerState glels[] = new GLEventListenerState[1];
106 final GLEventListenerCounter glelTracker = new GLEventListenerCounter();
107
108 // - create glad1 w/o context
109 // - create context using glad1 and assign it to glad1
110 {
111 System.err.println("Test "+i+"/"+loops+".1: GLAD-1 "+gladType1+", preserving.");
112 testGLADOneLifecycle(screen, caps, gladType1, width, height,
113 glelTracker, snapshotGLEventListener,
114 null,
115 glels, animator);
116 System.err.println("Test "+i+"/"+loops+".1: done");
117 }
118
119 // - create glad2 w/ survived context
120 {
121 System.err.println("Test "+i+"/"+loops+".2: GLAD-1 "+gladType2+", restoring.");
122 testGLADOneLifecycle(screen, caps, gladType2, width+100, height+100,
123 glelTracker, snapshotGLEventListener,
124 glels[0],
125 null, null);
126 System.err.println("Test "+i+"/"+loops+".2: done.");
127 }
128 }
129 animator.stop();
130
131 if( fixedNewtDisplay ) {
132 screen.removeReference();
133 }
134 }
135
136 public static void main(final String args[]) throws IOException {
137 for(int i=0; i<args.length; i++) {
138 if(args[i].equals("-time")) {
139 i++;
140 duration2 = MiscUtils.atol(args[i], duration2);
141 } else if(args[i].equals("-loops")) {
142 i++;
143 loops = MiscUtils.atoi(args[i], loops);
144 } else if(args[i].equals("-noFixedNewtDisplay")) {
145 fixedNewtDisplay = false;
146 }
147 }
148 /**
149 BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
150 System.err.println("Press enter to continue");
151 System.err.println(stdin.readLine()); */
152 org.junit.runner.JUnitCore.main(TestBug722GLContextDrawableSwitchNewt2AWT.class.getName());
153 }
154}
static Display createDisplay(final String name)
Create a Display entity.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
Definition: Screen.java:58
abstract int addReference()
See Display#addReference().
abstract int removeReference()
See Display#removeReference().
Specifies a set of OpenGL capabilities.
GLEventListenerState is holding GLAutoDrawable components crucial to relocating all its GLEventListen...
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
Definition: GLProfile.java:594
Test re-association of GLContext/GLDrawables, here GLContext's survival of GLDrawable destruction and...
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
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