aboutsummaryrefslogtreecommitdiffstats
path: root/src/junit/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-05-21 06:15:17 +0200
committerSven Gothel <[email protected]>2010-05-21 06:15:17 +0200
commit6e599a2696f878786783e0fea17534e67655a5c9 (patch)
tree65774f7318ea67a170902efefbd3a952c94d7f6d /src/junit/com/jogamp
parent3d8e85915ccdf48b9a97b5ed279716a2204a7a82 (diff)
Changed NEWT NativeWindow creation contract - AWT/NEWT Parenting - Misc Fixes
+++++ Changed NEWT NativeWindow creation contract Original contract: (1) A native window was created as soon as possible, ie when NEWTFactory.createWindow(..) was called - if possible. (2) A valid native window has to be created at least after setVisible(true) has been called. Problems: Not all implementation are able to create the native window that early, but at setVisible(true) only (e.g: KD and EGL). Due to window parenting especially the new AWT/NEWT parenting, the native window can only be created in case the parent native window is valid. New contract: (1) A native window is created at setVisible(true), if it's a top level window or the native parent window is valid. (2) A valid native window may not be created after setVisible(true) has been called. Subsequent setVisible(true) calls shall be made in case the creation has not been done yet. This is demonstrated in GLWindow.display() for example. The new contract implements a lazy native window creation. +++++ AWT/NEWT Parenting - HierarchyListener and ComponentListener ensure that the NEWT child window will be setVisible according to the AWT parent window. - Lazy native window creation relaxes requirements to the parent window's state. - Attachment of the child window and setVisible() may be called after NEWT child window creation. - GLWindow supports NEWT child window creation directly The test case TestParenting01AWT.java reflect this new contract and demonstrates more simplified and more flexible use cases. +++++ NEWT Fixes: - All NEWT implementation's native code method names end with 0. - GLWindow: don't issue the actual 'init'/'display' call to GLEventListeners in case the window is not visible. - NEWT setSize/setPosition: if native-window call native-window action and let the attributes being set by the feedback call, which issues more action, ie RESIZE. else set the attributes directly, no feedback call/action is necessary. +++++ X11 Fixes: - X11GLContext MakeContextCurrent: Use MakeCurrent in case write and read drawable are equal, otherwise SEGV happens on ATI with heavy multithreading involved! Even XLockDisplay and XSync didn't help here .. - X11GLXDrawableFactory shared resource: Removed the resource holder thread to simplify code, hence proper release is no more desired and it could become a cause for deadlock. - Moved XInitThreads() from NEWT X11Window -> NativeWindow X11Util, since NativeWindow is loaded first (essential for XInitThreads()) and it is the more basic lib. - Made call to XInitThreads() conditional, ie it's spared if AWT could be used - which causes SEGV .. (AWT bug). See X11Util.java +++++ JOGL Fixes: - GLProfile.isAWTAvailable() -> NativeWindowFactory.isAWTAvailable() - GLProfile.isAWTJOGLAvailable() -> GLProfile.isAWTAvailable()
Diffstat (limited to 'src/junit/com/jogamp')
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01NEWT.java (renamed from src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01CORE.java)8
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNEWT.java2
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java12
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/newt/TestParenting01AWT.java107
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/newt/TestParenting01NEWT.java40
-rwxr-xr-xsrc/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java10
6 files changed, 90 insertions, 89 deletions
diff --git a/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01CORE.java b/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01NEWT.java
index e2de8c1e1..48388d4e9 100755
--- a/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01CORE.java
+++ b/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01NEWT.java
@@ -46,7 +46,7 @@ import com.jogamp.newt.opengl.*;
import com.jogamp.newt.*;
import java.io.IOException;
-public class TestGLProfile01CORE {
+public class TestGLProfile01NEWT {
static GLProfile glp;
@BeforeClass
@@ -120,9 +120,9 @@ public class TestGLProfile01CORE {
protected void dumpVersion(GLProfile glp) {
GLCapabilities caps = new GLCapabilities(glp);
- GLWindow glWindow = GLWindow.create(caps);
+ GLWindow glWindow = GLWindow.create(caps, false);
Assert.assertNotNull(glWindow);
- glWindow.setTitle("TestGLProfile01CORE");
+ glWindow.setTitle("TestGLProfile01NEWT");
glWindow.addGLEventListener(new DumpVersion());
@@ -133,7 +133,7 @@ public class TestGLProfile01CORE {
}
public static void main(String args[]) throws IOException {
- String tstname = TestGLProfile01CORE.class.getName();
+ String tstname = TestGLProfile01NEWT.class.getName();
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
tstname,
"filtertrace=true",
diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNEWT.java b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNEWT.java
index 23c39290c..e50ffbde9 100755
--- a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNEWT.java
+++ b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNEWT.java
@@ -64,7 +64,7 @@ public class TestGearsNEWT {
}
protected void runTestGL(GLCapabilities caps) throws InterruptedException {
- GLWindow glWindow = GLWindow.create(caps);
+ GLWindow glWindow = GLWindow.create(caps, false);
Assert.assertNotNull(glWindow);
glWindow.setTitle("Gears NEWT Test");
diff --git a/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java
index ff4186b0c..cd0c7c0e0 100755
--- a/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java
+++ b/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java
@@ -105,9 +105,9 @@ public class TestDrawable01NEWT {
Assert.assertTrue(glCaps.getGreenBits()>5);
Assert.assertTrue(glCaps.getBlueBits()>5);
Assert.assertTrue(glCaps.getRedBits()>5);
- Assert.assertTrue(glCaps.isOnscreen()==onscreen);
+ Assert.assertEquals(glCaps.isOnscreen(),onscreen);
Assert.assertTrue(onscreen || !pbuffer || glCaps.isPBuffer()); // pass if onscreen, or !pbuffer req. or have pbuffer
- Assert.assertTrue(glCaps.getDoubleBuffered()==onscreen);
+ Assert.assertEquals(glCaps.getDoubleBuffered(),onscreen);
Assert.assertTrue(glCaps.getDepthBits()>4);
drawable = factory.createGLDrawable(window);
@@ -115,10 +115,10 @@ public class TestDrawable01NEWT {
// System.out.println("Pre: "+drawable);
//
drawable.setRealized(true);
- Assert.assertTrue(width==drawable.getWidth());
- Assert.assertTrue(height==drawable.getHeight());
- // Assert.assertTrue(glCaps==drawable.getChosenGLCapabilities());
- Assert.assertTrue(window==drawable.getNativeWindow());
+ // Assert.assertEquals(width,drawable.getWidth());
+ // Assert.assertEquals(height,drawable.getHeight());
+ // Assert.assertEquals(glCaps,drawable.getChosenGLCapabilities());
+ Assert.assertEquals(window,drawable.getNativeWindow());
// System.out.println("Post: "+drawable);
context = drawable.createContext(null);
diff --git a/src/junit/com/jogamp/test/junit/newt/TestParenting01AWT.java b/src/junit/com/jogamp/test/junit/newt/TestParenting01AWT.java
index 9d0001733..2c0dc31c1 100755
--- a/src/junit/com/jogamp/test/junit/newt/TestParenting01AWT.java
+++ b/src/junit/com/jogamp/test/junit/newt/TestParenting01AWT.java
@@ -73,32 +73,27 @@ public class TestParenting01AWT {
height = 480;
}
- static void destroyWindow(Display display, Screen screen, Window window, GLWindow glWindow) {
- if(null!=glWindow) {
- glWindow.destroy();
- }
- if(null!=window) {
- window.destroy();
- }
- if(null!=screen) {
- screen.destroy();
- }
- if(null!=display) {
- display.destroy();
- }
+ @Test
+ public void testWindowParenting01NewtChildOnAWTParentLayouted() throws InterruptedException {
+ runNewtChildOnAWTParent(true, false);
}
@Test
- public void testWindowParenting01NewtChildOnAWTParentLayouted() throws InterruptedException {
- runNewtChildOnAWTParent(true);
+ public void testWindowParenting02NewtChildOnAWTParentLayoutedDef() throws InterruptedException {
+ runNewtChildOnAWTParent(true, true);
+ }
+
+ @Test
+ public void testWindowParenting03NewtChildOnAWTParentDirect() throws InterruptedException {
+ runNewtChildOnAWTParent(false, false);
}
@Test
- public void testWindowParenting02NewtChildOnAWTParentDirect() throws InterruptedException {
- runNewtChildOnAWTParent(false);
+ public void testWindowParenting04NewtChildOnAWTParentDirectDef() throws InterruptedException {
+ runNewtChildOnAWTParent(false, true);
}
- public void runNewtChildOnAWTParent(boolean useLayout) throws InterruptedException {
+ public void runNewtChildOnAWTParent(boolean useLayout, boolean deferredPeer) throws InterruptedException {
Frame frame = new Frame("AWT Parent Frame");
Assert.assertNotNull(frame);
Component overlayedAWTComponent = null;
@@ -111,7 +106,9 @@ public class TestParenting01AWT {
frame.add(new Button("South"), BorderLayout.SOUTH);
frame.add(new Button("East"), BorderLayout.EAST);
frame.add(new Button("West"), BorderLayout.WEST);
- frame.add(overlayedAWTComponent, BorderLayout.CENTER);
+ if(!deferredPeer) {
+ frame.add(overlayedAWTComponent, BorderLayout.CENTER);
+ }
} else {
overlayedAWTComponent = frame;
@@ -119,57 +116,55 @@ public class TestParenting01AWT {
Assert.assertNotNull(overlayedAWTComponent);
frame.setSize(width, height);
- frame.setVisible(true); // should have native peers after this!
-
- GLCapabilities caps = new GLCapabilities(null);
- Assert.assertNotNull(caps);
- Display display = NewtFactory.createDisplay(null); // local display
- Assert.assertNotNull(display);
- System.out.println("Display: "+display);
- Screen screen = NewtFactory.createScreen(display, 0); // screen 0
- Assert.assertNotNull(screen);
+ if(!deferredPeer) {
+ // ensure native peers are valid and component is displayable
+ frame.setVisible(true);
+ }
NEWTEventFiFo eventFifo = new NEWTEventFiFo();
- Window window2 = NewtFactory.createWindow(overlayedAWTComponent, screen, caps, false);
- Assert.assertNotNull(window2);
-
- GLWindow glWindow2 = GLWindow.create(window2);
- Assert.assertNotNull(glWindow2);
+ GLCapabilities caps = new GLCapabilities(null);
+ Assert.assertNotNull(caps);
- glWindow2.setSize(width, height);
- Assert.assertTrue(false==glWindow2.isVisible());
- Assert.assertTrue(width==glWindow2.getWidth());
- Assert.assertTrue(height==glWindow2.getHeight());
+ GLWindow glWindow = GLWindow.create(overlayedAWTComponent, caps);
+ Assert.assertNotNull(glWindow);
+ Assert.assertEquals(overlayedAWTComponent.isVisible(),glWindow.isVisible());
+ if(!deferredPeer) {
+ Assert.assertTrue(0!=glWindow.getWindowHandle());
+ } else {
+ Assert.assertTrue(0==glWindow.getWindowHandle());
+ }
+ glWindow.setTitle("NEWT - CHILD");
+ glWindow.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo)));
+ glWindow.addWindowListener(new TraceWindowAdapter(new WindowAction(eventFifo)));
- glWindow2.setTitle("NEWT - CHILD");
- glWindow2.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo)));
- glWindow2.addWindowListener(new TraceWindowAdapter(new WindowAction(eventFifo)));
- glWindow2.setVisible(true);
+ if(deferredPeer) {
+ if(useLayout) {
+ frame.add(overlayedAWTComponent, BorderLayout.CENTER);
+ }
+ frame.setVisible(true); // should have native peers after this - and all childs shall be visible!
+ }
- GLEventListener demo2 = new Gears();
- setDemoFields(demo2, window2, glWindow2, false);
- glWindow2.addGLEventListener(demo2);
+ GLEventListener demo = new Gears();
+ setDemoFields(demo, glWindow, false);
+ glWindow.addGLEventListener(demo);
long duration = durationPerTest;
long step = 20;
NEWTEvent event;
- boolean shouldQuit = false;
- while (duration>0 && !shouldQuit) {
- glWindow2.display();
+ while (duration>0 && !glWindow.isDestroyed()) {
+ glWindow.display();
Thread.sleep(step);
duration -= step;
while( null != ( event = (NEWTEvent) eventFifo.get() ) ) {
Window source = (Window) event.getSource();
- if(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY == event.getEventType()) {
- shouldQuit = true;
- } else if(event instanceof KeyEvent) {
+ if(event instanceof KeyEvent) {
KeyEvent keyEvent = (KeyEvent) event;
switch(keyEvent.getKeyChar()) {
case 'q':
- shouldQuit = true;
+ glWindow.destroy();
break;
case 'f':
source.setFullscreen(!source.isFullscreen());
@@ -178,13 +173,17 @@ public class TestParenting01AWT {
}
}
}
- destroyWindow(null, null, window2, glWindow2);
+ glWindow.destroy();
+ if(useLayout) {
+ frame.remove(overlayedAWTComponent);
+ }
frame.dispose();
}
- public static void setDemoFields(GLEventListener demo, Window window, GLWindow glWindow, boolean debug) {
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
Assert.assertNotNull(demo);
- Assert.assertNotNull(window);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getWindow();
if(debug) {
MiscUtils.setFieldIfExists(demo, "glDebug", true);
MiscUtils.setFieldIfExists(demo, "glTrace", true);
diff --git a/src/junit/com/jogamp/test/junit/newt/TestParenting01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestParenting01NEWT.java
index 1940534dd..ee135e83e 100755
--- a/src/junit/com/jogamp/test/junit/newt/TestParenting01NEWT.java
+++ b/src/junit/com/jogamp/test/junit/newt/TestParenting01NEWT.java
@@ -68,23 +68,17 @@ public class TestParenting01NEWT {
height = 480;
}
- static Window createWindow(NativeWindow parent, Screen screen, Capabilities caps, int width, int height) {
+ static Window createWindow(Screen screen, Capabilities caps) {
Assert.assertNotNull(caps);
- Window window;
- window = ( null == parent ) ? NewtFactory.createWindow(screen, caps, false) : NewtFactory.createWindow(parent, screen, caps, false) ;
+ Window window = NewtFactory.createWindow(screen, caps, false) ;
Assert.assertNotNull(window);
- window.setSize(width, height);
- Assert.assertTrue(false==window.isVisible());
- Assert.assertTrue(width==window.getWidth());
- Assert.assertTrue(height==window.getHeight());
+ return window;
+ }
- caps = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+ static Window createWindow(NativeWindow parent, Capabilities caps) {
Assert.assertNotNull(caps);
- Assert.assertTrue(caps.getGreenBits()>5);
- Assert.assertTrue(caps.getBlueBits()>5);
- Assert.assertTrue(caps.getRedBits()>5);
- Assert.assertTrue(caps.isOnscreen()==true);
-
+ Window window = NewtFactory.createWindow(parent, caps, true);
+ Assert.assertNotNull(window);
return window;
}
@@ -117,30 +111,38 @@ public class TestParenting01NEWT {
NEWTEventFiFo eventFifo = new NEWTEventFiFo();
- Window window1 = createWindow( null, screen, caps, width, height );
+ Window window1 = createWindow(screen, caps);
Assert.assertNotNull(window1);
GLWindow glWindow1 = GLWindow.create(window1);
Assert.assertNotNull(glWindow1);
- Assert.assertTrue(width==glWindow1.getWidth());
- Assert.assertTrue(height==glWindow1.getHeight());
+ glWindow1.setSize(width, height);
+ Assert.assertEquals(width,glWindow1.getWidth());
+ Assert.assertEquals(height,glWindow1.getHeight());
glWindow1.setTitle("testWindowParenting01NewtOnNewtParentChildDraw - PARENT");
glWindow1.setPosition(x,y);
glWindow1.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo)));
glWindow1.addWindowListener(new TraceWindowAdapter());
glWindow1.setVisible(true);
+ Capabilities capsChosen = glWindow1.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+ Assert.assertNotNull(capsChosen);
+ Assert.assertTrue(capsChosen.isOnscreen()==true);
- Window window2 = createWindow(window1, screen, caps, width/2, height/2);
+ Window window2 = createWindow(window1, caps);
Assert.assertNotNull(window2);
GLWindow glWindow2 = GLWindow.create(window2);
Assert.assertNotNull(glWindow2);
- Assert.assertTrue(width/2==glWindow2.getWidth());
- Assert.assertTrue(height/2==glWindow2.getHeight());
+ glWindow2.setSize(width/2, height/2);
+ //Assert.assertEquals(width/2,glWindow2.getWidth());
+ //Assert.assertEquals(height/2,glWindow2.getHeight());
glWindow2.setTitle("testWindowParenting01NewtOnNewtParentChildDraw - CHILD");
glWindow2.setPosition(glWindow1.getWidth()/2, glWindow1.getHeight()/2);
glWindow2.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo)));
glWindow2.addWindowListener(new TraceWindowAdapter(new WindowAction(eventFifo)));
// glWindow2.addMouseListener(new TraceMouseAdapter());
glWindow2.setVisible(true);
+ capsChosen = glWindow2.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+ Assert.assertNotNull(capsChosen);
+ Assert.assertTrue(capsChosen.isOnscreen()==true);
GLEventListener demo1 = new RedSquare();
setDemoFields(demo1, window1, glWindow1, false);
diff --git a/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java
index 4969a685f..e0affa4ab 100755
--- a/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java
+++ b/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java
@@ -69,11 +69,11 @@ public class TestWindows01NEWT {
Window window = NewtFactory.createWindow(screen, caps, onscreen && undecorated);
Assert.assertNotNull(window);
window.setSize(width, height);
- Assert.assertTrue(false==window.isVisible());
+ Assert.assertEquals(false,window.isVisible());
window.setVisible(true);
- Assert.assertTrue(true==window.isVisible());
- Assert.assertTrue(width==window.getWidth());
- Assert.assertTrue(height==window.getHeight());
+ Assert.assertEquals(true,window.isVisible());
+ // Assert.assertEquals(width,window.getWidth());
+ // Assert.assertEquals(height,window.getHeight());
// System.out.println("Created: "+window);
//
@@ -85,7 +85,7 @@ public class TestWindows01NEWT {
Assert.assertTrue(caps.getGreenBits()>5);
Assert.assertTrue(caps.getBlueBits()>5);
Assert.assertTrue(caps.getRedBits()>5);
- Assert.assertTrue(caps.isOnscreen()==onscreen);
+ Assert.assertEquals(caps.isOnscreen(),onscreen);
return window;
}