29package com.jogamp.opengl.test.junit.newt.parenting;
31import org.junit.Assert;
32import org.junit.BeforeClass;
34import org.junit.FixMethodOrder;
35import org.junit.runners.MethodSorters;
37import java.awt.Button;
38import java.awt.BorderLayout;
39import java.awt.Container;
42import com.jogamp.opengl.*;
43import javax.swing.SwingUtilities;
45import com.jogamp.common.os.Platform;
46import com.jogamp.junit.util.JunitTracer;
47import com.jogamp.newt.Window;
48import com.jogamp.newt.opengl.*;
49import com.jogamp.newt.awt.NewtCanvasAWT;
51import java.io.IOException;
52import java.lang.reflect.InvocationTargetException;
54import com.jogamp.opengl.test.junit.util.*;
55import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
64@FixMethodOrder(MethodSorters.NAME_ASCENDING)
66 static int width, height;
67 static long durationPerTest = 800;
69 static boolean manual_test =
false;
72 public static void initClass() throws InterruptedException {
74 if( Platform.OSType.LINUX == Platform.getOSType() ) {
75 JunitTracer.setTestSupported(
false);
88 System.err.println(
"MyGLEventListenerCounter.init: "+
this);
94 super.dispose(drawable);
95 System.err.println(
"MyGLEventListenerCounter.dispose: "+
this);
102 testGLWindowInvisibleReparentRecreateImpl(
false );
107 testGLWindowInvisibleReparentRecreateImpl(
true );
110 private void testGLWindowInvisibleReparentRecreateImpl(
final boolean triggerPreserveGLState)
throws InterruptedException, InvocationTargetException {
112 Assert.assertNotNull(glWindow1);
113 Assert.assertEquals(
false, glWindow1.
isVisible());
115 Assert.assertNull(glWindow1.
getParent());
116 glWindow1.
setTitle(
"testWindowParenting01CreateVisibleDestroy");
117 final MyGLEventListenerCounter glelCounter =
new MyGLEventListenerCounter();
121 Assert.assertEquals(
"Init Counter Invalid "+glelCounter, 0, glelCounter.initCount);
124 Assert.assertNotNull(newtCanvasAWT);
125 Assert.assertEquals(
false, glWindow1.
isVisible());
127 Assert.assertNull(glWindow1.
getParent());
128 Assert.assertEquals(
"Init Counter Invalid "+glelCounter, 0, glelCounter.initCount);
130 final Frame frame1 =
new Frame(
"AWT Parent Frame");
131 frame1.setLayout(
new BorderLayout());
132 frame1.add(
new Button(
"North"), BorderLayout.NORTH);
133 frame1.add(
new Button(
"South"), BorderLayout.SOUTH);
134 frame1.add(
new Button(
"East"), BorderLayout.EAST);
135 frame1.add(
new Button(
"West"), BorderLayout.WEST);
137 final Container container1 =
new Container();
138 container1.setLayout(
new BorderLayout());
139 container1.add(
new Button(
"north"), BorderLayout.NORTH);
140 container1.add(
new Button(
"south"), BorderLayout.SOUTH);
141 container1.add(
new Button(
"east"), BorderLayout.EAST);
142 container1.add(
new Button(
"west"), BorderLayout.WEST);
143 container1.add(newtCanvasAWT, BorderLayout.CENTER);
145 frame1.add(container1, BorderLayout.CENTER);
148 SwingUtilities.invokeAndWait(
new Runnable() {
151 frame1.setSize(width, height);
152 frame1.setVisible(
true);
160 Assert.assertEquals(
"Init Counter Invalid "+glelCounter, 1, glelCounter.initCount);
161 Assert.assertEquals(
"Dispose Counter Invalid "+glelCounter, 0, glelCounter.disposeCount);
163 final int reparentingHints = Window.REPARENT_HINT_FORCE_RECREATION |
164 ( triggerPreserveGLState ? Window.REPARENT_HINT_BECOMES_VISIBLE : 0 );
170 System.err.println(getSimpleTestName(
".")+
": Start Reparent #1");
172 System.err.println(getSimpleTestName(
".")+
": Result Reparent #1: "+rop1);
175 Assert.assertEquals(
"Init Counter Invalid (Preserve Failed 1) "+glelCounter, 1, glelCounter.initCount);
176 Assert.assertEquals(
"Dispose Counter Invalid (Preserve Failed 1) "+glelCounter, 0, glelCounter.disposeCount);
185 System.err.println(getSimpleTestName(
".")+
": Start Reparent #2");
187 System.err.println(getSimpleTestName(
".")+
": Result Reparent #2: "+rop2);
193 if( triggerPreserveGLState ) {
194 Assert.assertEquals(
"Init Counter Invalid (Preserve Failed 2) "+glelCounter, 1, glelCounter.initCount);
195 Assert.assertEquals(
"Dispose Counter Invalid (Preserve Failed 2) "+glelCounter, 0, glelCounter.disposeCount);
197 Assert.assertEquals(
"Init Counter Invalid (Preserve Failed 2) "+glelCounter, 2, glelCounter.initCount);
198 Assert.assertEquals(
"Dispose Counter Invalid (Preserve Failed 2) "+glelCounter, 1, glelCounter.disposeCount);
201 final long t0 = System.currentTimeMillis();
203 while( t1 - t0 < durationPerTest ) {
205 t1 = System.currentTimeMillis();
208 SwingUtilities.invokeAndWait(
new Runnable() {
211 frame1.setVisible(
false);
215 SwingUtilities.invokeAndWait(
new Runnable() {
218 frame1.setVisible(
true);
224 SwingUtilities.invokeAndWait(
new Runnable() {
227 frame1.remove(newtCanvasAWT);
234 SwingUtilities.invokeAndWait(
new Runnable() {
245 if( triggerPreserveGLState ) {
246 Assert.assertEquals(
"Init Counter Invalid (Preserve Failed 1) "+glelCounter, 1, glelCounter.initCount);
247 Assert.assertEquals(
"Dispose Counter Invalid (Preserve Failed 1) "+glelCounter, 1, glelCounter.disposeCount);
249 Assert.assertEquals(
"Init Counter Invalid (Preserve Failed 1) "+glelCounter, 2, glelCounter.initCount);
250 Assert.assertEquals(
"Dispose Counter Invalid (Preserve Failed 1) "+glelCounter, 2, glelCounter.disposeCount);
254 public static void main(
final String args[])
throws IOException {
256 for(
int i=0; i<args.length; i++) {
257 if(args[i].equals(
"-time")) {
258 durationPerTest =
MiscUtils.
atol(args[++i], durationPerTest);
262 org.junit.runner.JUnitCore.
main(tstname);
AWT Canvas containing a NEWT Window using native parenting.
NativeWindow getNativeWindow()
Returns the associated NativeWindow of this NativeWindowHolder, which is identical to getNativeSurfac...
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final NativeWindow getParent()
final boolean isNativeValid()
final ReparentOperation reparentWindow(final NativeWindow newParent, final int x, final int y, final int hints)
Change this window's parent window.
final void setTitle(final String title)
final boolean isVisible()
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
Test GL preservation case for reparenting.
void test02GLWindowReparentRecreateGLPreserve()
static void main(final String args[])
void test01GLWindowReparentRecreateNoPreserve()
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
static long atol(final String str, final long def)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
static boolean waitForVisible(final Window win, final boolean visible, final Runnable waitAction)
Reparenting operation types.
ACTION_NATIVE_CREATION
Native window creation after tree change - instead of reparenting.
boolean isOnscreen()
Returns whether an on- or offscreen surface is requested, available or chosen.
Specifying NEWT's Window functionality:
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.