diff options
author | Sven Gothel <[email protected]> | 2013-03-19 00:22:28 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-03-19 00:22:28 +0100 |
commit | f354fb204d8973453c538dda78a2c82c87be61dc (patch) | |
tree | f70748d4aaaacd442f9baa146be554120d8f8080 /src/test/com/jogamp/opengl | |
parent | 12e868f79938f44eba6f50313f977be76d8ea2bb (diff) |
OSX/CALayer: OSX/CALayer Threading Part3 - Run CALayer ops in a streaming design on main-thread w/o [infinitive] blocking
History:
Part1 commit 896e8b021b39e9415040a57a1d540d7d24b02db1 (Run CALayer Ops on current thread to avoid blocking)
Part2 commit 28c6472335b924080d638b33a28f8f4eedb459b1 (Run CALayer Ops on main-thread w/o blocking)
Dependency:
GlueGen commit 4becdfa125b07ff969d6540e1112735b53cd15eb (Fix RecursiveLockImpl* Timeout corner case)
Part2 misses essential locking of the OpenGL context (and it's surface upfront) while creating the
NSOpenGLLayer instance. The latter instantiates a OpenGL context shared w/ JOGL's, hence it cannot be locked.
Encapsulating NSOpenGLLayer creation/attachment and it's detachment/release in sub-classes
AttachNSOpenGLLayer and DetachNSOpenGLLayer, where instances will be streamed on main-thread.
Both tasks are triggered at associateDrawable(boolean bound).
The mentioned GL context locking requires disturbs the 'streaming' design considerably in AttachNSOpenGLLayer.
It is solved by attempt to acquire the recursive lock of the surface and the context via 'tryLock(maxwait)'
w/ screen-vSync-period/2. If the locks could not be acquired completly, the AttachNSOpenGLLayer instance
will be re-queued to the main-thread for later execution.
Before DetachNSOpenGLLayer is being streamed, it is validated whether AttachNSOpenGLLayer did run.
A recursive situation does happen w/ resizing an offscreen pbuffer drawable! Hence extra care is being taken.
Diffstat (limited to 'src/test/com/jogamp/opengl')
4 files changed, 85 insertions, 28 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java index 48c3c89b3..c2eebbfd8 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java @@ -55,13 +55,14 @@ import com.jogamp.opengl.test.junit.util.MiscUtils; import com.jogamp.opengl.test.junit.util.UITestCase; public class TestAddRemove01GLCanvasSwingAWT extends UITestCase { - static long durationPerTest = 50; + static long durationPerTest = 100; static int addRemoveCount = 15; static int pauseEach = 0; static int pauseDuration = 500; static boolean noOnscreenTest = false; static boolean noOffscreenTest = false; - static boolean shallUseOffscreenPBufferLayer = false; + static boolean offscreenPBufferOnly = false; + static boolean offscreenFBOOnly = false; static GLProfile glp; static int width, height; static boolean waitForKey = false; @@ -143,6 +144,9 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase { throws AWTException, InterruptedException, InvocationTargetException { + if(waitForKey) { + UITestCase.waitForKey("Start"); + } for(int i=0; i<addRemoveOpCount; i++) { System.err.println("Loop # "+i+" / "+addRemoveCount); final GLCanvas glc = new GLCanvas(caps); @@ -195,29 +199,47 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase { return; } GLCapabilities caps = new GLCapabilities(glp); - if(shallUseOffscreenPBufferLayer) { - caps.setPBuffer(true); - caps.setOnscreen(true); // simulate normal behavior .. - } runTestGL(true, caps, addRemoveCount); } @Test - public void test02Offscreen() + public void test02OffscreenFBO() throws AWTException, InterruptedException, InvocationTargetException { if( noOffscreenTest || !JAWTUtil.isOffscreenLayerSupported() ) { System.err.println("No offscreen test requested or platform doesn't support offscreen rendering."); return; } + if( offscreenPBufferOnly ) { + System.err.println("Only PBuffer test is requested."); + return; + } GLCapabilities caps = new GLCapabilities(glp); - if(shallUseOffscreenPBufferLayer) { + if(offscreenPBufferOnly) { caps.setPBuffer(true); caps.setOnscreen(true); // simulate normal behavior .. } runTestGL(false, caps, addRemoveCount); } + @Test + public void test03OffscreenPBuffer() + throws AWTException, InterruptedException, InvocationTargetException + { + if( noOffscreenTest || !JAWTUtil.isOffscreenLayerSupported() ) { + System.err.println("No offscreen test requested or platform doesn't support offscreen rendering."); + return; + } + if( offscreenFBOOnly ) { + System.err.println("Only FBO test is requested."); + return; + } + GLCapabilities caps = new GLCapabilities(glp); + caps.setPBuffer(true); + caps.setOnscreen(true); // simulate normal behavior .. + runTestGL(false, caps, addRemoveCount); + } + public static void main(String args[]) throws IOException { for(int i=0; i<args.length; i++) { if(args[i].equals("-time")) { @@ -238,8 +260,10 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase { noOnscreenTest = true; } else if(args[i].equals("-noOffscreen")) { noOffscreenTest = true; + } else if(args[i].equals("-layeredFBO")) { + offscreenFBOOnly = true; } else if(args[i].equals("-layeredPBuffer")) { - shallUseOffscreenPBufferLayer = true; + offscreenPBufferOnly = true; } else if(args[i].equals("-wait")) { waitForKey = true; } else if(args[i].equals("-waitPost")) { @@ -247,6 +271,7 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase { } } System.err.println("waitForKey "+waitForKey); + System.err.println("waitForKeyPost "+waitForKeyPost); System.err.println("addRemoveCount "+addRemoveCount); System.err.println("pauseEach "+pauseEach); @@ -254,10 +279,9 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase { System.err.println("noOnscreenTest "+noOnscreenTest); System.err.println("noOffscreenTest "+noOffscreenTest); - System.err.println("shallUseOffscreenPBufferLayer "+shallUseOffscreenPBufferLayer); - if(waitForKey) { - UITestCase.waitForKey("Start"); - } - org.junit.runner.JUnitCore.main(TestAddRemove01GLCanvasSwingAWT.class.getName()); + System.err.println("offscreenPBufferOnly "+offscreenPBufferOnly); + System.err.println("offscreenFBOOnly "+offscreenFBOOnly); + + org.junit.runner.JUnitCore.main(TestAddRemove01GLCanvasSwingAWT.class.getName()); } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove02GLWindowNewtCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove02GLWindowNewtCanvasAWT.java index ce88abfba..8b447485c 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove02GLWindowNewtCanvasAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove02GLWindowNewtCanvasAWT.java @@ -63,10 +63,12 @@ public class TestAddRemove02GLWindowNewtCanvasAWT extends UITestCase { static int pauseDuration = 500; static boolean noOnscreenTest = false; static boolean noOffscreenTest = false; - static boolean shallUseOffscreenPBufferLayer = false; + static boolean offscreenPBufferOnly = false; + static boolean offscreenFBOOnly = false; static GLProfile glp; static int width, height; static boolean waitForKey = false; + static boolean waitForKeyPost = false; @BeforeClass public static void initClass() { @@ -183,6 +185,9 @@ public class TestAddRemove02GLWindowNewtCanvasAWT extends UITestCase { Thread.sleep(pauseDuration); } } + if(waitForKeyPost) { + UITestCase.waitForKey("End"); + } } @Test @@ -194,26 +199,40 @@ public class TestAddRemove02GLWindowNewtCanvasAWT extends UITestCase { return; } GLCapabilities caps = new GLCapabilities(glp); - if(shallUseOffscreenPBufferLayer) { - caps.setPBuffer(true); - caps.setOnscreen(true); // simulate normal behavior .. - } runTestGL(true, caps, addRemoveCount); } @Test - public void test02Offscreen() + public void test02OffscreenFBO() throws AWTException, InterruptedException, InvocationTargetException { if( noOffscreenTest || !JAWTUtil.isOffscreenLayerSupported() ) { System.err.println("No offscreen test requested or platform doesn't support offscreen rendering."); return; } + if( offscreenPBufferOnly ) { + System.err.println("Only PBuffer test is requested."); + return; + } GLCapabilities caps = new GLCapabilities(glp); - if(shallUseOffscreenPBufferLayer) { - caps.setPBuffer(true); - caps.setOnscreen(true); // simulate normal behavior .. + runTestGL(false, caps, addRemoveCount); + } + + @Test + public void test03OffscreenPBuffer() + throws AWTException, InterruptedException, InvocationTargetException + { + if( noOffscreenTest || !JAWTUtil.isOffscreenLayerSupported() ) { + System.err.println("No offscreen test requested or platform doesn't support offscreen rendering."); + return; } + if( offscreenFBOOnly ) { + System.err.println("Only FBO test is requested."); + return; + } + GLCapabilities caps = new GLCapabilities(glp); + caps.setPBuffer(true); + caps.setOnscreen(true); // simulate normal behavior .. runTestGL(false, caps, addRemoveCount); } @@ -237,13 +256,18 @@ public class TestAddRemove02GLWindowNewtCanvasAWT extends UITestCase { noOnscreenTest = true; } else if(args[i].equals("-noOffscreen")) { noOffscreenTest = true; + } else if(args[i].equals("-layeredFBO")) { + offscreenFBOOnly = true; } else if(args[i].equals("-layeredPBuffer")) { - shallUseOffscreenPBufferLayer = true; + offscreenPBufferOnly = true; } else if(args[i].equals("-wait")) { waitForKey = true; + } else if(args[i].equals("-waitPost")) { + waitForKeyPost = true; } } System.err.println("waitForKey "+waitForKey); + System.err.println("waitForKeyPost "+waitForKeyPost); System.err.println("addRemoveCount "+addRemoveCount); System.err.println("pauseEach "+pauseEach); @@ -251,7 +275,8 @@ public class TestAddRemove02GLWindowNewtCanvasAWT extends UITestCase { System.err.println("noOnscreenTest "+noOnscreenTest); System.err.println("noOffscreenTest "+noOffscreenTest); - System.err.println("shallUseOffscreenPBufferLayer "+shallUseOffscreenPBufferLayer); + System.err.println("offscreenPBufferOnly "+offscreenPBufferOnly); + System.err.println("offscreenFBOOnly "+offscreenFBOOnly); if(waitForKey) { UITestCase.waitForKey("Start"); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java b/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java index a6b3eb85d..d8a2e7810 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java @@ -155,7 +155,7 @@ public class TestSwingAWTRobotUsageBeforeJOGLInitBug411 extends UITestCase { colorPanel.setBackground(Color.white); colorPanel.repaint(); }}); - + robot = new Robot(); robot.setAutoWaitForIdle(true); @@ -210,6 +210,8 @@ public class TestSwingAWTRobotUsageBeforeJOGLInitBug411 extends UITestCase { AWTRobotUtil.toFrontAndRequestFocus(robot, frame); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(drawable, true)); + drawable.addGLEventListener(new GearsES2()); for(int i=0; i<100; i++) { @@ -262,6 +264,8 @@ public class TestSwingAWTRobotUsageBeforeJOGLInitBug411 extends UITestCase { GLWindow win0 = GLWindow.create(caps); win0.setSize(100,100); win0.setVisible(true); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(win0, true)); + Screen screen = win0.getScreen(); win0.setPosition(screen.getWidth()-150, 0); win0.addGLEventListener(new GearsES2()); @@ -274,6 +278,7 @@ public class TestSwingAWTRobotUsageBeforeJOGLInitBug411 extends UITestCase { runTestGL(newtCanvasAWT, win1); win0.destroy(); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(win0, false)); Assert.assertEquals(false, win0.isNativeValid()); Assert.assertEquals(true, anim.isAnimating()); // due to newtCanvasAWT/win1 @@ -313,8 +318,7 @@ public class TestSwingAWTRobotUsageBeforeJOGLInitBug411 extends UITestCase { GLCanvas glCanvas = new GLCanvas(caps); anim.add(glCanvas); runTestGL(glCanvas, glCanvas); - - Assert.assertEquals(true, anim.isAnimating()); + anim.remove(glCanvas); Assert.assertEquals(false, anim.isAnimating()); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04AWT.java index b0e58b5ec..0af42ec03 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04AWT.java @@ -159,6 +159,8 @@ public class TestParenting04AWT extends UITestCase { } canvas1.setNEWTChild(glWindow2); // put g2 -> w1. free g1 of w1 canvas2.setNEWTChild(glWindow1); // put g1 -> w2 + frame1.invalidate(); + frame2.invalidate(); frame1.validate(); frame2.validate(); } @@ -176,6 +178,8 @@ public class TestParenting04AWT extends UITestCase { } canvas1.setNEWTChild(glWindow1); canvas2.setNEWTChild(glWindow2); + frame1.invalidate(); + frame2.invalidate(); frame1.validate(); frame2.validate(); } |