From 52b745ed2196d3e00102e8fccace25f41386a016 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 13 Aug 2023 02:38:21 +0200 Subject: Animator*: Add ctor variants passing modeBits directly, i.e. enable/disable AWT rendering thread support. Adopt it in tests and demos --- .../test/junit/graph/TestTextRendererNEWT10.java | 2 +- .../acore/TestBug669RecursiveGLContext01NEWT.java | 12 +- .../acore/TestBug669RecursiveGLContext02NEWT.java | 20 +- ...tFBOOffThreadSharedContextMix2DemosES2NEWT.java | 8 +- .../TestFBOOnThreadSharedContext1DemoES2NEWT.java | 8 +- .../jogl/acore/TestGLAutoDrawableDelegateNEWT.java | 4 +- .../test/junit/jogl/acore/TestNVSwapGroupNEWT.java | 6 +- .../jogl/acore/TestSharedContextListNEWT.java | 2 +- .../jogl/acore/TestSharedContextListNEWT2.java | 6 +- .../jogl/acore/TestSharedContextVBOES1NEWT.java | 2 +- .../jogl/acore/TestSharedContextVBOES2NEWT0.java | 2 +- .../jogl/acore/TestSharedContextVBOES2NEWT1.java | 16 +- .../jogl/acore/TestSharedContextVBOES2NEWT2.java | 8 +- .../jogl/acore/TestSharedContextVBOES2NEWT3.java | 8 +- .../jogl/acore/TestSharedContextVBOES2NEWT4.java | 2 +- .../jogl/acore/TestSharedContextVBOES2NEWT5.java | 4 +- .../acore/anim/TestAnimatorGLWindow01NEWT.java | 8 +- .../ect/TestExclusiveContext01VSyncAnimNEWT.java | 2 +- .../ect/TestExclusiveContext11VSyncAnimNEWT.java | 2 +- .../glels/TestGLContextDrawableSwitch01NEWT.java | 7 +- .../glels/TestGLContextDrawableSwitch10NEWT.java | 2 +- .../awt/TestGLCanvasAWTActionDeadlock02AWT.java | 1038 ++++++++++---------- .../jogl/demos/es1/newt/TestOlympicES1NEWT.java | 3 +- .../jogl/demos/es2/newt/TestGearsES2NEWT.java | 3 +- .../demos/es2/newt/TestGearsES2NewtCanvasAWT.java | 32 +- .../demos/es2/newt/TestGearsES2NewtCanvasSWT.java | 3 +- .../demos/es2/newt/TestGearsES2SimpleNEWT.java | 2 +- .../jogl/demos/es2/newt/TestLandscapeES2NEWT.java | 6 +- .../es2/newt/TestLandscapeES2NewtCanvasAWT.java | 21 +- .../junit/jogl/demos/es2/swt/TestGearsES2SWT.java | 3 +- .../swt/TestGLCanvasSWTNewtCanvasSWTPosInTabs.java | 85 +- .../junit/jogl/swt/TestSWTJOGLGLCanvas01GLn.java | 58 +- .../newt/DemoCreateAndDisposeOnCloseNEWT.java | 2 +- .../newt/TestGLWindowInvisiblePointer01NEWT.java | 2 +- .../junit/newt/TestGLWindowWarpPointer01NEWT.java | 2 +- .../junit/newt/TestGLWindows02NEWTAnimated.java | 6 +- .../test/junit/newt/TestRemoteGLWindows01NEWT.java | 2 +- .../junit/newt/TestWindowAndPointerIconNEWT.java | 3 +- .../TestTranslucentChildWindowBug632NEWT.java | 2 +- 39 files changed, 731 insertions(+), 673 deletions(-) (limited to 'src/test') diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java index 23da67b3c..9a4ee19ef 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java @@ -247,7 +247,7 @@ public class TestTextRendererNEWT10 extends UITestCase { window.addGLEventListener(textGLListener); - final Animator anim = new Animator(); + final Animator anim = new Animator(0 /* w/o AWT */); anim.add(window); anim.start(); anim.setUpdateFPSFrames(60, null); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug669RecursiveGLContext01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug669RecursiveGLContext01NEWT.java index 27524a535..0fa29e190 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug669RecursiveGLContext01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug669RecursiveGLContext01NEWT.java @@ -76,7 +76,7 @@ public class TestBug669RecursiveGLContext01NEWT extends UITestCase { final GLCapabilities caps = new GLCapabilities(pro); final GLWindow window = GLWindow.create(caps); - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); if(anim) { animator.add(window); } @@ -107,16 +107,20 @@ public class TestBug669RecursiveGLContext01NEWT extends UITestCase { Assert.assertEquals(true, context.isCurrent()); // still current } + @Override public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { } + @Override public void init(final GLAutoDrawable drawable) { } + @Override public void dispose(final GLAutoDrawable drawable) { } + @Override public void display(final GLAutoDrawable drawable) { - final GLContextImpl context = (GLContextImpl)drawable.getContext(); - makeCurrentRecursive(context, 1); - releaseRecursive(context, 2); + final GLContextImpl context = (GLContextImpl)drawable.getContext(); + makeCurrentRecursive(context, 1); + releaseRecursive(context, 2); } }); window.addGLEventListener(new GearsES2()); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug669RecursiveGLContext02NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug669RecursiveGLContext02NEWT.java index 3acc07d8d..69301137d 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug669RecursiveGLContext02NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug669RecursiveGLContext02NEWT.java @@ -80,8 +80,8 @@ public class TestBug669RecursiveGLContext02NEWT extends UITestCase { final GLWindow window1 = GLWindow.create(caps); - final Animator animator1 = new Animator(); - final Animator animator2 = new Animator(); + final Animator animator1 = new Animator(0 /* w/o AWT */); + final Animator animator2 = new Animator(0 /* w/o AWT */); if(anim) { animator1.add(window1); animator2.add(window2); @@ -92,15 +92,19 @@ public class TestBug669RecursiveGLContext02NEWT extends UITestCase { window1.setPosition(250, 0); window1.setSize(200, 200); window1.addGLEventListener(new GLEventListener() { - public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { } + @Override + public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { } - public void init(final GLAutoDrawable drawable) { } + @Override + public void init(final GLAutoDrawable drawable) { } - public void dispose(final GLAutoDrawable drawable) { } + @Override + public void dispose(final GLAutoDrawable drawable) { } - public void display(final GLAutoDrawable drawable) { - window2.display(); - } + @Override + public void display(final GLAutoDrawable drawable) { + window2.display(); + } }); window1.addGLEventListener(new GearsES2()); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOffThreadSharedContextMix2DemosES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOffThreadSharedContextMix2DemosES2NEWT.java index b0b9b53e4..fa2e7d009 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOffThreadSharedContextMix2DemosES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOffThreadSharedContextMix2DemosES2NEWT.java @@ -176,8 +176,11 @@ public class TestFBOOffThreadSharedContextMix2DemosES2NEWT extends UITestCase { glWindow.addGLEventListener(mixerDemo); glWindow.addGLEventListener(new GLEventListener() { int i=0, c=0; + @Override public void init(final GLAutoDrawable drawable) {} + @Override public void dispose(final GLAutoDrawable drawable) {} + @Override public void display(final GLAutoDrawable drawable) { if(mainRun) return; @@ -200,6 +203,7 @@ public class TestFBOOffThreadSharedContextMix2DemosES2NEWT extends UITestCase { } } } + @Override public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { fbod1.setSurfaceSize(width, height); fbod2.setSurfaceSize(width, height); @@ -210,7 +214,7 @@ public class TestFBOOffThreadSharedContextMix2DemosES2NEWT extends UITestCase { animator0.add(fbod1); animator0.add(fbod2); - final Animator animator1 = new Animator(); + final Animator animator1 = new Animator(0 /* w/o AWT */); animator1.add(glWindow); final QuitAdapter quitAdapter = new QuitAdapter(); @@ -221,9 +225,11 @@ public class TestFBOOffThreadSharedContextMix2DemosES2NEWT extends UITestCase { glWindow.addWindowListener(quitAdapter); glWindow.addWindowListener(new WindowAdapter() { + @Override public void windowResized(final WindowEvent e) { System.err.println("window resized: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()); } + @Override public void windowMoved(final WindowEvent e) { System.err.println("window moved: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOnThreadSharedContext1DemoES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOnThreadSharedContext1DemoES2NEWT.java index 2bc512fa0..c3ac0d619 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOnThreadSharedContext1DemoES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOOnThreadSharedContext1DemoES2NEWT.java @@ -162,8 +162,11 @@ public class TestFBOOnThreadSharedContext1DemoES2NEWT extends UITestCase { glWindow.addGLEventListener(mixerDemo); glWindow.addGLEventListener(new GLEventListener() { int i=0, c=0; + @Override public void init(final GLAutoDrawable drawable) {} + @Override public void dispose(final GLAutoDrawable drawable) {} + @Override public void display(final GLAutoDrawable drawable) { if(mainRun) return; @@ -186,10 +189,11 @@ public class TestFBOOnThreadSharedContext1DemoES2NEWT extends UITestCase { } } } + @Override public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { } }); - final Animator animator1 = new Animator(); + final Animator animator1 = new Animator(0 /* w/o AWT */); animator1.add(fbod1); animator1.add(glWindow); @@ -201,9 +205,11 @@ public class TestFBOOnThreadSharedContext1DemoES2NEWT extends UITestCase { glWindow.addWindowListener(quitAdapter); glWindow.addWindowListener(new WindowAdapter() { + @Override public void windowResized(final WindowEvent e) { System.err.println("window resized: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()); } + @Override public void windowMoved(final WindowEvent e) { System.err.println("window moved: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateNEWT.java index 4432fad3e..8d05c6ee2 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateNEWT.java @@ -100,6 +100,7 @@ public class TestGLAutoDrawableDelegateNEWT extends UITestCase { }; window.setWindowDestroyNotifyAction( new Runnable() { + @Override public void run() { glad.windowDestroyNotifyOp(); } } ); @@ -124,9 +125,8 @@ public class TestGLAutoDrawableDelegateNEWT extends UITestCase { window.addKeyListener(quitAdapter); window.addWindowListener(quitAdapter); - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); animator.setUpdateFPSFrames(60, System.err); - animator.setModeBits(false, AnimatorBase.MODE_EXPECT_AWT_RENDERING_THREAD); animator.add(glad); animator.start(); Assert.assertTrue(animator.isStarted()); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestNVSwapGroupNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestNVSwapGroupNEWT.java index 2ac493dbc..2b875fe14 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestNVSwapGroupNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestNVSwapGroupNEWT.java @@ -72,6 +72,7 @@ public class TestNVSwapGroupNEWT extends UITestCase { final GearsES2 gears = new GearsES2(1); glWindow.addGLEventListener(new GLEventListener() { + @Override public void init(final GLAutoDrawable drawable) { final int[] maxVals = new int[] { -1, -1 } ; final GLContext glc = drawable.getContext(); @@ -84,8 +85,11 @@ public class TestNVSwapGroupNEWT extends UITestCase { } } } + @Override public void dispose(final GLAutoDrawable drawable) {} + @Override public void display(final GLAutoDrawable drawable) {} + @Override public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {} }); @@ -108,7 +112,7 @@ public class TestNVSwapGroupNEWT extends UITestCase { final int swap_group = 9999; final int swap_barrier = 9999; - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); final GLWindow f1 = runTestGL(animator, 0, 0, swap_group, swap_barrier); final InsetsImmutable insets = f1.getInsets(); final GLWindow f2 = runTestGL(animator, width+insets.getTotalWidth(), 0, swap_group, swap_barrier); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java index 263e78def..9b26a2e16 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java @@ -116,7 +116,7 @@ public class TestSharedContextListNEWT extends UITestCase { @Test public void test01() throws InterruptedException { initShared(); - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); final GLWindow f1 = runTestGL(animator, 0, 0, true, false); final InsetsImmutable insets = f1.getInsets(); final GLWindow f2 = runTestGL(animator, f1.getX()+width+insets.getTotalWidth(), diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT2.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT2.java index 095b03207..f4e2d0754 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT2.java @@ -119,11 +119,11 @@ public class TestSharedContextListNEWT2 extends UITestCase { public void test01() throws InterruptedException { initShared(); - final GLWindow f1 = runTestGL(new Animator(), 0, 0, true, false); + final GLWindow f1 = runTestGL(new Animator(0 /* w/o AWT */), 0, 0, true, false); final InsetsImmutable insets = f1.getInsets(); - final GLWindow f2 = runTestGL(new Animator(), f1.getX()+width+insets.getTotalWidth(), + final GLWindow f2 = runTestGL(new Animator(0 /* w/o AWT */), f1.getX()+width+insets.getTotalWidth(), f1.getY()+0, true, false); - final GLWindow f3 = runTestGL(new Animator(), f1.getX()+0, + final GLWindow f3 = runTestGL(new Animator(0 /* w/o AWT */), f1.getX()+0, f1.getY()+height+insets.getTotalHeight(), true, false); try { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java index a6406d4a0..3fd5415d6 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java @@ -156,7 +156,7 @@ public class TestSharedContextVBOES1NEWT extends UITestCase { @Test public void test01() throws InterruptedException { initShared(); - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); final GLWindow f1 = runTestGL(animator, 0, 0, true, false); final InsetsImmutable insets = f1.getInsets(); final GLWindow f2 = runTestGL(animator, f1.getX()+width+insets.getTotalWidth(), diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT0.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT0.java index 88099f578..2b7118ed4 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT0.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT0.java @@ -110,7 +110,7 @@ public class TestSharedContextVBOES2NEWT0 extends UITestCase { testCommonAnimatorSharedImpl(true); } private void testCommonAnimatorSharedImpl(final boolean useMappedBuffers) throws InterruptedException { - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); // // 1st diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT1.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT1.java index 7b06fcc5d..63dff5b91 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT1.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT1.java @@ -176,7 +176,7 @@ public class TestSharedContextVBOES2NEWT1 extends UITestCase { @Test public void test01CommonAnimatorSharedOnscreen() throws InterruptedException { initShared(true); - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); final GLWindow f1 = runTestGL(animator, 0, 0, true, false); final InsetsImmutable insets = f1.getInsets(); final GLWindow f2 = runTestGL(animator, f1.getX()+width+insets.getTotalWidth(), @@ -209,9 +209,9 @@ public class TestSharedContextVBOES2NEWT1 extends UITestCase { @Test public void test02EachWithAnimatorSharedOnscreen() throws InterruptedException { initShared(true); - final Animator animator1 = new Animator(); - final Animator animator2 = new Animator(); - final Animator animator3 = new Animator(); + final Animator animator1 = new Animator(0 /* w/o AWT */); + final Animator animator2 = new Animator(0 /* w/o AWT */); + final Animator animator3 = new Animator(0 /* w/o AWT */); final GLWindow f1 = runTestGL(animator1, 0, 0, true, false); final InsetsImmutable insets = f1.getInsets(); final GLWindow f2 = runTestGL(animator2, f1.getX()+width+insets.getTotalWidth(), @@ -247,7 +247,7 @@ public class TestSharedContextVBOES2NEWT1 extends UITestCase { @Test public void test11CommonAnimatorSharedOffscreen() throws InterruptedException { initShared(false); - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); final GLWindow f1 = runTestGL(animator, 0, 0, true, false); final InsetsImmutable insets = f1.getInsets(); final GLWindow f2 = runTestGL(animator, f1.getX()+width+insets.getTotalWidth(), @@ -280,9 +280,9 @@ public class TestSharedContextVBOES2NEWT1 extends UITestCase { @Test public void test12EachWithAnimatorSharedOffscreen() throws InterruptedException { initShared(false); - final Animator animator1 = new Animator(); - final Animator animator2 = new Animator(); - final Animator animator3 = new Animator(); + final Animator animator1 = new Animator(0 /* w/o AWT */); + final Animator animator2 = new Animator(0 /* w/o AWT */); + final Animator animator3 = new Animator(0 /* w/o AWT */); final GLWindow f1 = runTestGL(animator1, 0, 0, true, false); final InsetsImmutable insets = f1.getInsets(); final GLWindow f2 = runTestGL(animator2, f1.getX()+width+insets.getTotalWidth(), diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java index 05ee9bab4..e4dd026db 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java @@ -104,7 +104,7 @@ public class TestSharedContextVBOES2NEWT2 extends UITestCase { } public void syncedOneAnimator(final boolean destroyCleanOrder) throws InterruptedException { - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); animator.start(); final GearsES2 g1 = new GearsES2(0); @@ -222,7 +222,7 @@ public class TestSharedContextVBOES2NEWT2 extends UITestCase { } public void asyncEachAnimator(final boolean destroyCleanOrder) throws InterruptedException { - final Animator a1 = new Animator(); + final Animator a1 = new Animator(0 /* w/o AWT */); final GearsES2 g1 = new GearsES2(0); g1.setSyncObjects(g1); // this is master, since rendered we must use it as sync final GLWindow f1 = createGLWindow(0, 0, g1); @@ -231,7 +231,7 @@ public class TestSharedContextVBOES2NEWT2 extends UITestCase { final InsetsImmutable insets = f1.getInsets(); - final Animator a2 = new Animator(); + final Animator a2 = new Animator(0 /* w/o AWT */); final GearsES2 g2 = new GearsES2(0); g2.setSharedGears(g1); // also uses master g1 as sync, if required final GLWindow f2 = createGLWindow(f1.getX()+width+insets.getTotalWidth(), @@ -241,7 +241,7 @@ public class TestSharedContextVBOES2NEWT2 extends UITestCase { a2.start(); f2.setVisible(true); - final Animator a3 = new Animator(); + final Animator a3 = new Animator(0 /* w/o AWT */); final GearsES2 g3 = new GearsES2(0); g3.setSharedGears(g1); // also uses master g1 as sync, if required final GLWindow f3 = createGLWindow(f1.getX()+0, diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT3.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT3.java index 685ecf308..6291bc87b 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT3.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT3.java @@ -112,7 +112,7 @@ public class TestSharedContextVBOES2NEWT3 extends UITestCase { } public void syncedOneAnimator(final boolean destroyCleanOrder, final boolean useMappedBuffers) throws InterruptedException { - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); animator.start(); final GearsES2 g1 = new GearsES2(0); @@ -265,7 +265,7 @@ public class TestSharedContextVBOES2NEWT3 extends UITestCase { } public void asyncEachAnimator(final boolean destroyCleanOrder, final boolean useMappedBuffers) throws InterruptedException { - final Animator a1 = new Animator(); + final Animator a1 = new Animator(0 /* w/o AWT */); final GearsES2 g1 = new GearsES2(0); g1.setSyncObjects(g1); // this is master, since rendered we must use it as sync g1.setUseMappedBuffers(useMappedBuffers); @@ -276,7 +276,7 @@ public class TestSharedContextVBOES2NEWT3 extends UITestCase { final InsetsImmutable insets = f1.getInsets(); - final Animator a2 = new Animator(); + final Animator a2 = new Animator(0 /* w/o AWT */); final GearsES2 g2 = new GearsES2(0); g2.setSharedGears(g1); // also uses master g1 as sync, if required final GLWindow f2 = createGLWindow(f1.getX()+width+insets.getTotalWidth(), @@ -306,7 +306,7 @@ public class TestSharedContextVBOES2NEWT3 extends UITestCase { Assert.assertTrue(GLTestUtil.waitForContextCreated(f2, true, null)); Assert.assertTrue("Gears2 not initialized", g2.waitForInit(true)); - final Animator a3 = new Animator(); + final Animator a3 = new Animator(0 /* w/o AWT */); final GearsES2 g3 = new GearsES2(0); g3.setSharedGears(g1); // also uses master g1 as sync, if required final GLWindow f3 = createGLWindow(f1.getX()+0, diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT4.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT4.java index 840d732c0..6be45ba5f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT4.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT4.java @@ -96,7 +96,7 @@ public class TestSharedContextVBOES2NEWT4 extends UITestCase { @Test public void test01() throws InterruptedException { - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); animator.start(); final GearsES2 g1 = new GearsES2(0); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT5.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT5.java index 8317bb0c1..2d039d3ed 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT5.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT5.java @@ -101,7 +101,7 @@ public class TestSharedContextVBOES2NEWT5 extends UITestCase { public void asyncEachAnimator(final boolean destroyCleanOrder, final int loops) throws InterruptedException { // master - final Animator a1 = new Animator(); + final Animator a1 = new Animator(0 /* w/o AWT */); final GearsES2 g1 = new GearsES2(0); g1.setVerbose(false); g1.setSyncObjects(g1); // this is master, since rendered we must use it as sync @@ -130,7 +130,7 @@ public class TestSharedContextVBOES2NEWT5 extends UITestCase { final GLWindow[] sf = new GLWindow[slaveCount]; final GLContext[] sc = new GLContext[slaveCount]; for(int i=0; i Platform.getJavaVersionNumber().compareTo(version170); - System.err.println("OSX CALayer AWT-Mod Bug "+osxCALayerAWTModBug); - System.err.println("OSType "+Platform.getOSType()); - System.err.println("Java Version "+Platform.getJavaVersionNumber()); - - // Frame setup ---------------------------------------------------------- - - width = 300; - height = 300; - final MiniPApplet applet = this; - - final GraphicsEnvironment environment = - GraphicsEnvironment.getLocalGraphicsEnvironment(); - final GraphicsDevice displayDevice = environment.getDefaultScreenDevice(); - frame = new Frame(displayDevice.getDefaultConfiguration()); - - final Rectangle fullScreenRect; - if (fullScreen) { - final DisplayMode mode = displayDevice.getDisplayMode(); - fullScreenRect = new Rectangle(0, 0, mode.getWidth(), mode.getHeight()); - } else { - fullScreenRect = null; + // } + // }; + // loop.start(); } - // All AWT Mods on AWT-EDT, especially due to the follow-up complicated code! - AWTEDTExecutor.singleton.invoke(true, new Runnable() { - @Override - public void run() { - frame.setTitle("MiniPApplet"); - } } ); - if (fullScreen) { - try { - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - @Override - public void run() { - frame.setUndecorated(true); - frame.setBackground(Color.GRAY); - frame.setBounds(fullScreenRect); - frame.setVisible(true); - }}); - } catch (final Throwable t) { - t.printStackTrace(); - Assume.assumeNoException(t); - } - } - try { - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - @Override - public void run() { - frame.setLayout(null); - frame.add(applet); + + void setup() throws InterruptedException, InvocationTargetException { + if (printThreadInfo) System.out.println("Current thread at setup(): " + Thread.currentThread()); + + millisOffset = System.currentTimeMillis(); + + final VersionNumber version170 = new VersionNumber(1, 7, 0); + osxCALayerAWTModBug = Platform.OSType.MACOS == Platform.getOSType() && + 0 > Platform.getJavaVersionNumber().compareTo(version170); + System.err.println("OSX CALayer AWT-Mod Bug "+osxCALayerAWTModBug); + System.err.println("OSType "+Platform.getOSType()); + System.err.println("Java Version "+Platform.getJavaVersionNumber()); + + // Frame setup ---------------------------------------------------------- + + width = 300; + height = 300; + final MiniPApplet applet = this; + + final GraphicsEnvironment environment = + GraphicsEnvironment.getLocalGraphicsEnvironment(); + final GraphicsDevice displayDevice = environment.getDefaultScreenDevice(); + frame = new Frame(displayDevice.getDefaultConfiguration()); + + final Rectangle fullScreenRect; if (fullScreen) { - frame.invalidate(); + final DisplayMode mode = displayDevice.getDisplayMode(); + fullScreenRect = new Rectangle(0, 0, mode.getWidth(), mode.getHeight()); } else { - frame.pack(); + fullScreenRect = null; } - frame.setResizable(resizeableFrame); + // All AWT Mods on AWT-EDT, especially due to the follow-up complicated code! + AWTEDTExecutor.singleton.invoke(true, new Runnable() { + @Override + public void run() { + frame.setTitle("MiniPApplet"); + } } ); if (fullScreen) { - // After the pack(), the screen bounds are gonna be 0s - frame.setBounds(fullScreenRect); - applet.setBounds((fullScreenRect.width - applet.width) / 2, - (fullScreenRect.height - applet.height) / 2, - applet.width, applet.height); - } else { - final Insets insets = frame.getInsets(); - - final int windowW = applet.width + insets.left + insets.right; - final int windowH = applet.height + insets.top + insets.bottom; - final int locationX = 100; - final int locationY = 100; + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + frame.setUndecorated(true); + frame.setBackground(Color.GRAY); + frame.setBounds(fullScreenRect); + frame.setVisible(true); + }}); + } catch (final Throwable t) { + t.printStackTrace(); + Assume.assumeNoException(t); + } + } + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + frame.setLayout(null); + frame.add(applet); + if (fullScreen) { + frame.invalidate(); + } else { + frame.pack(); + } + frame.setResizable(resizeableFrame); + if (fullScreen) { + // After the pack(), the screen bounds are gonna be 0s + frame.setBounds(fullScreenRect); + applet.setBounds((fullScreenRect.width - applet.width) / 2, + (fullScreenRect.height - applet.height) / 2, + applet.width, applet.height); + } else { + final Insets insets = frame.getInsets(); + + final int windowW = applet.width + insets.left + insets.right; + final int windowH = applet.height + insets.top + insets.bottom; + final int locationX = 100; + final int locationY = 100; + + frame.setSize(windowW, windowH); + frame.setLocation(locationX, locationY); + + final int usableWindowH = windowH - insets.top - insets.bottom; + applet.setBounds((windowW - width)/2, insets.top + (usableWindowH - height)/2, width, height); + } + }}); + } catch (final Throwable t) { + t.printStackTrace(); + Assume.assumeNoException(t); + } - frame.setSize(windowW, windowH); - frame.setLocation(locationX, locationY); - final int usableWindowH = windowH - insets.top - insets.bottom; - applet.setBounds((windowW - width)/2, insets.top + (usableWindowH - height)/2, width, height); + frame.add(this); + frame.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(final WindowEvent e) { + try { + dispose(); + } catch (final Exception ex) { + Assume.assumeNoException(ex); + } + } + }); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + frame.setVisible(true); + } } ); + + // Canvas setup ---------------------------------------------------------- + + profile = GLProfile.getDefault(); + capabilities = new GLCapabilities(profile); + capabilities.setSampleBuffers(true); + capabilities.setNumSamples(numSamples); + capabilities.setDepthBits(24); + // capabilities.setStencilBits(8); // No Stencil on OSX w/ hw-accel ! + capabilities.setAlphaBits(8); + + canvas = new GLCanvas(capabilities); + canvas.setBounds(0, 0, width, height); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + MiniPApplet.this.setLayout(new BorderLayout()); + MiniPApplet.this.add(canvas, BorderLayout.CENTER); + MiniPApplet.this.validate(); + } } ); + canvas.addMouseMotionListener(this); + canvas.addKeyListener(this); + + // Setting up animation + listener = new SimpleListener(); + canvas.addGLEventListener(listener); + if (useAnimator) { + animator = new CustomAnimator(canvas); + animator.start(); } - }}); - } catch (final Throwable t) { - t.printStackTrace(); - Assume.assumeNoException(t); + initialized = true; } + void restart() throws InterruptedException, InvocationTargetException { + System.out.println("Restarting surface..."); - frame.add(this); - frame.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent e) { - try { - dispose(); - } catch (final Exception ex) { - Assume.assumeNoException(ex); - } - } - }); + // Stopping animation, removing current canvas. + if (useAnimator) { + animator.stop(); + animator.remove(canvas); + } + canvas.disposeGLEventListener(listener, true); + this.remove(canvas); - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - @Override - public void run() { - frame.setVisible(true); - } } ); + capabilities = new GLCapabilities(profile); + capabilities.setSampleBuffers(true); + capabilities.setNumSamples(numSamples); - // Canvas setup ---------------------------------------------------------- + canvas = new GLCanvas(capabilities); + canvas.setBounds(0, 0, width, height); - profile = GLProfile.getDefault(); - capabilities = new GLCapabilities(profile); - capabilities.setSampleBuffers(true); - capabilities.setNumSamples(numSamples); - capabilities.setDepthBits(24); - // capabilities.setStencilBits(8); // No Stencil on OSX w/ hw-accel ! - capabilities.setAlphaBits(8); + // Setting up animation again + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + MiniPApplet.this.setLayout(new BorderLayout()); + MiniPApplet.this.add(canvas, BorderLayout.CENTER); + MiniPApplet.this.validate(); + } } ); + canvas.addMouseMotionListener(this); + canvas.addKeyListener(this); - canvas = new GLCanvas(capabilities); - canvas.setBounds(0, 0, width, height); + canvas.addGLEventListener(listener); + if (useAnimator) { + animator.add(canvas); + animator.start(); + } - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - @Override - public void run() { - MiniPApplet.this.setLayout(new BorderLayout()); - MiniPApplet.this.add(canvas, BorderLayout.CENTER); - MiniPApplet.this.validate(); - } } ); - canvas.addMouseMotionListener(this); - canvas.addKeyListener(this); - - // Setting up animation - listener = new SimpleListener(); - canvas.addGLEventListener(listener); - if (useAnimator) { - animator = new CustomAnimator(canvas); - animator.start(); + setFramerate = false; + restarted = true; + + System.out.println("Done"); } - initialized = true; - } - void restart() throws InterruptedException, InvocationTargetException { - System.out.println("Restarting surface..."); + void dispose() throws InterruptedException, InvocationTargetException { + if( null == frame ) { + return; + } - // Stopping animation, removing current canvas. - if (useAnimator) { - animator.stop(); - animator.remove(canvas); + // Stopping animation, removing current canvas. + if (useAnimator) { + animator.stop(); + animator.remove(canvas); + } + canvas.removeGLEventListener(listener); + if( EventQueue.isDispatchThread() ) { + MiniPApplet.this.remove(canvas); + frame.remove(MiniPApplet.this); + frame.validate(); + frame.dispose(); + frame = null; + } else { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + MiniPApplet.this.remove(canvas); + frame.remove(MiniPApplet.this); + frame.validate(); + frame.dispose(); + frame = null; + }}); + } } - canvas.disposeGLEventListener(listener, true); - this.remove(canvas); - capabilities = new GLCapabilities(profile); - capabilities.setSampleBuffers(true); - capabilities.setNumSamples(numSamples); + void draw(final GL2 gl) { + if( !osxCALayerAWTModBug || !justInitialized ) { + AWTEDTExecutor.singleton.invoke(true, new Runnable() { + @Override + public void run() { + frame.setTitle("frame " + frameCount); + } } ); + } - canvas = new GLCanvas(capabilities); - canvas.setBounds(0, 0, width, height); + if (printThreadInfo) System.out.println("Current thread at draw(): " + Thread.currentThread()); + + if (OPENGL_VENDOR == null) { + OPENGL_VENDOR = gl.glGetString(GL.GL_VENDOR); + OPENGL_RENDERER = gl.glGetString(GL.GL_RENDERER); + OPENGL_VERSION = gl.glGetString(GL.GL_VERSION); + OPENGL_EXTENSIONS = gl.glGetString(GL.GL_EXTENSIONS); + System.out.println(OPENGL_VENDOR); + System.out.println(OPENGL_RENDERER); + System.out.println(OPENGL_VERSION); + System.out.println(OPENGL_EXTENSIONS); + + final int[] temp = { 0 }; + gl.glGetIntegerv(GL.GL_MAX_SAMPLES, temp, 0); + System.out.println("Maximum number of samples supported by the hardware: " + temp[0]); + System.out.println("Frame: "+frame); + System.out.println("Applet: "+MiniPApplet.this); + System.out.println("GLCanvas: "+canvas); + System.out.println("GLDrawable: "+canvas.getDelegatedDrawable()); + } - // Setting up animation again - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - @Override - public void run() { - MiniPApplet.this.setLayout(new BorderLayout()); - MiniPApplet.this.add(canvas, BorderLayout.CENTER); - MiniPApplet.this.validate(); - } } ); - canvas.addMouseMotionListener(this); - canvas.addKeyListener(this); - - canvas.addGLEventListener(listener); - if (useAnimator) { - animator.add(canvas); - animator.start(); - } + if (currentSamples == -1) { + final int[] temp = { 0 }; + gl.glGetIntegerv(GL.GL_SAMPLES, temp, 0); + currentSamples = temp[0]; + if (numSamples != currentSamples) { + System.err.println("Requested sampling level " + numSamples + " not supported. Using " + currentSamples + " samples instead."); + } + } - setFramerate = false; - restarted = true; + if (!setFramerate) { + if (60 < frameRate) { + // Disables vsync + gl.setSwapInterval(0); + } else if (30 < frameRate) { + gl.setSwapInterval(1); + } else { + gl.setSwapInterval(2); + } + setFramerate = true; + } - System.out.println("Done"); - } + if (restarted) { + final int[] temp = { 0 }; + gl.glGetIntegerv(GL.GL_SAMPLES, temp, 0); + if (numSamples != temp[0]) { + System.err.println("Multisampling level requested " + numSamples + " not supported. Using " + temp[0] + "samples instead."); + } + } - void dispose() throws InterruptedException, InvocationTargetException { - if( null == frame ) { - return; + gl.glClearColor(0, 0, 0, 1); + gl.glClear(GL.GL_COLOR_BUFFER_BIT); + + theta += 0.01; + s = Math.sin(theta); + c = Math.cos(theta); + + gl.glBegin(GL.GL_TRIANGLES); + gl.glColor3f(1, 0, 0); + gl.glVertex2d(-c, -c); + gl.glColor3f(0, 1, 0); + gl.glVertex2d(0, c); + gl.glColor3f(0, 0, 1); + gl.glVertex2d(s, -s); + gl.glEnd(); + + gl.glFlush(); + + fcount += 1; + final int m = (int) (System.currentTimeMillis() - millisOffset); + if (m - lastm > 1000 * fint) { + frate = (float)(fcount) / fint; + fcount = 0; + lastm = m; + System.err.println("fps: " + frate); + } } - // Stopping animation, removing current canvas. - if (useAnimator) { - animator.stop(); - animator.remove(canvas); - } - canvas.removeGLEventListener(listener); - if( EventQueue.isDispatchThread() ) { - MiniPApplet.this.remove(canvas); - frame.remove(MiniPApplet.this); - frame.validate(); - frame.dispose(); - frame = null; - } else { - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - @Override - public void run() { - MiniPApplet.this.remove(canvas); - frame.remove(MiniPApplet.this); - frame.validate(); - frame.dispose(); - frame = null; - }}); + void clock() { + final long afterTime = Clock.currentNanos(); + final long timeDiff = afterTime - beforeTime; + final long sleepTime = (frameRatePeriod - timeDiff) - overSleepTime; + + if (sleepTime > 0) { // some time left in this cycle + try { + Thread.sleep(sleepTime / 1000000L, (int) (sleepTime % 1000000L)); + } catch (final InterruptedException ex) { } + + overSleepTime = (Clock.currentNanos() - afterTime) - sleepTime; + + } else { // sleepTime <= 0; the frame took longer than the period + overSleepTime = 0L; + } + + beforeTime = Clock.currentNanos(); } - } - void draw(final GL2 gl) { - if( !osxCALayerAWTModBug || !justInitialized ) { - AWTEDTExecutor.singleton.invoke(true, new Runnable() { - @Override - public void run() { - frame.setTitle("frame " + frameCount); - } } ); + class SimpleListener implements GLEventListener { + @Override + public void display(final GLAutoDrawable drawable) { + draw(drawable.getGL().getGL2()); + justInitialized = false; + } + + @Override + public void dispose(final GLAutoDrawable drawable) { } + + @Override + public void init(final GLAutoDrawable drawable) { + justInitialized = true; + } + + @Override + public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int w, final int h) { } } - if (printThreadInfo) System.out.println("Current thread at draw(): " + Thread.currentThread()); - - if (OPENGL_VENDOR == null) { - OPENGL_VENDOR = gl.glGetString(GL.GL_VENDOR); - OPENGL_RENDERER = gl.glGetString(GL.GL_RENDERER); - OPENGL_VERSION = gl.glGetString(GL.GL_VERSION); - OPENGL_EXTENSIONS = gl.glGetString(GL.GL_EXTENSIONS); - System.out.println(OPENGL_VENDOR); - System.out.println(OPENGL_RENDERER); - System.out.println(OPENGL_VERSION); - System.out.println(OPENGL_EXTENSIONS); - - final int[] temp = { 0 }; - gl.glGetIntegerv(GL.GL_MAX_SAMPLES, temp, 0); - System.out.println("Maximum number of samples supported by the hardware: " + temp[0]); - System.out.println("Frame: "+frame); - System.out.println("Applet: "+MiniPApplet.this); - System.out.println("GLCanvas: "+canvas); - System.out.println("GLDrawable: "+canvas.getDelegatedDrawable()); + @Override + public void mouseDragged(final MouseEvent ev) { + if (printEventInfo) { + System.err.println("Mouse dragged event: " + ev); + } } - if (currentSamples == -1) { - final int[] temp = { 0 }; - gl.glGetIntegerv(GL.GL_SAMPLES, temp, 0); - currentSamples = temp[0]; - if (numSamples != currentSamples) { - System.err.println("Requested sampling level " + numSamples + " not supported. Using " + currentSamples + " samples instead."); - } + @Override + public void mouseMoved(final MouseEvent ev) { + if (printEventInfo) { + System.err.println("Mouse moved event: " + ev); + } } - if (!setFramerate) { - if (60 < frameRate) { - // Disables vsync - gl.setSwapInterval(0); - } else if (30 < frameRate) { - gl.setSwapInterval(1); - } else { - gl.setSwapInterval(2); - } - setFramerate = true; + @Override + public void keyPressed(final KeyEvent ev) { + if (printEventInfo) { + System.err.println("Key pressed event: " + ev); + } } - if (restarted) { - final int[] temp = { 0 }; - gl.glGetIntegerv(GL.GL_SAMPLES, temp, 0); - if (numSamples != temp[0]) { - System.err.println("Multisampling level requested " + numSamples + " not supported. Using " + temp[0] + "samples instead."); - } + @Override + public void keyReleased(final KeyEvent ev) { + if (printEventInfo) { + System.err.println("Key released event: " + ev); + } } - gl.glClearColor(0, 0, 0, 1); - gl.glClear(GL.GL_COLOR_BUFFER_BIT); - - theta += 0.01; - s = Math.sin(theta); - c = Math.cos(theta); - - gl.glBegin(GL.GL_TRIANGLES); - gl.glColor3f(1, 0, 0); - gl.glVertex2d(-c, -c); - gl.glColor3f(0, 1, 0); - gl.glVertex2d(0, c); - gl.glColor3f(0, 0, 1); - gl.glVertex2d(s, -s); - gl.glEnd(); - - gl.glFlush(); - - fcount += 1; - final int m = (int) (System.currentTimeMillis() - millisOffset); - if (m - lastm > 1000 * fint) { - frate = (float)(fcount) / fint; - fcount = 0; - lastm = m; - System.err.println("fps: " + frate); + @Override + public void keyTyped(final KeyEvent ev) { + if (printEventInfo) { + System.err.println("Key typed event: " + ev); + } } - } - void clock() { - final long afterTime = Clock.currentNanos(); - final long timeDiff = afterTime - beforeTime; - final long sleepTime = (frameRatePeriod - timeDiff) - overSleepTime; + /** An Animator subclass which renders one frame at the time + * upon calls to the requestRender() method. + **/ + public static class CustomAnimator extends AnimatorBase { + private Timer timer = null; + private TimerTask task = null; + private volatile boolean shouldRun; - if (sleepTime > 0) { // some time left in this cycle - try { - Thread.sleep(sleepTime / 1000000L, (int) (sleepTime % 1000000L)); - } catch (final InterruptedException ex) { } + @Override + protected String getBaseName(final String prefix) { + return "Custom" + prefix + "Animator" ; + } - overSleepTime = (Clock.currentNanos() - afterTime) - sleepTime; + /** Creates an CustomAnimator with an initial drawable to + * animate. */ + public CustomAnimator(final GLAutoDrawable drawable) { + if (drawable != null) { + add(drawable); + } + } - } else { // sleepTime <= 0; the frame took longer than the period - overSleepTime = 0L; - } + public synchronized void requestRender() { + shouldRun = true; + } - beforeTime = Clock.currentNanos(); - } + @Override + public final synchronized boolean isStarted() { + return (timer != null); + } - class SimpleListener implements GLEventListener { - @Override - public void display(final GLAutoDrawable drawable) { - draw(drawable.getGL().getGL2()); - justInitialized = false; - } + @Override + public final synchronized boolean isAnimating() { + return (timer != null) && (task != null); + } - @Override - public void dispose(final GLAutoDrawable drawable) { } + private void startTask() { + if(null != task) { + return; + } - @Override - public void init(final GLAutoDrawable drawable) { - justInitialized = true; - } + task = new TimerTask() { + private boolean firstRun = true; + @Override + public void run() { + if (firstRun) { + Thread.currentThread().setName("OPENGL"); + firstRun = false; + } + if(CustomAnimator.this.shouldRun) { + CustomAnimator.this.animThread = Thread.currentThread(); + // display impl. uses synchronized block on the animator instance + display(); + synchronized (this) { + // done with current frame. + shouldRun = false; + } + } + } + }; - @Override - public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int w, final int h) { } - } + fpsCounter.resetFPSCounter(); + shouldRun = false; - @Override - public void mouseDragged(final MouseEvent ev) { - if (printEventInfo) { - System.err.println("Mouse dragged event: " + ev); - } - } + timer.schedule(task, 0, 1); + } - @Override - public void mouseMoved(final MouseEvent ev) { - if (printEventInfo) { - System.err.println("Mouse moved event: " + ev); - } - } + @Override + public synchronized boolean start() { + if (timer != null) { + return false; + } + timer = new Timer(); + startTask(); + return true; + } - @Override - public void keyPressed(final KeyEvent ev) { - if (printEventInfo) { - System.err.println("Key pressed event: " + ev); - } - } + /** Stops this CustomAnimator. */ + @Override + public synchronized boolean stop() { + if (timer == null) { + return false; + } + shouldRun = false; + if(null != task) { + task.cancel(); + task = null; + } + if(null != timer) { + timer.cancel(); + timer = null; + } + animThread = null; + try { + Thread.sleep(20); // ~ 1/60 hz wait, since we can't ctrl stopped threads / holding the lock is OK here! + } catch (final InterruptedException e) { } + return true; + } - @Override - public void keyReleased(final KeyEvent ev) { - if (printEventInfo) { - System.err.println("Key released event: " + ev); + @Override + public final synchronized boolean isPaused() { return false; } + @Override + public synchronized boolean resume() { return false; } + @Override + public synchronized boolean pause() { return false; } } - } + } - @Override - public void keyTyped(final KeyEvent ev) { - if (printEventInfo) { - System.err.println("Key typed event: " + ev); + @Test + public void test00() { + TestGLCanvasAWTActionDeadlock02AWT.MiniPApplet mini; + try { + final Class c = Thread.currentThread().getContextClassLoader().loadClass(TestGLCanvasAWTActionDeadlock02AWT.MiniPApplet.class.getName()); + mini = (TestGLCanvasAWTActionDeadlock02AWT.MiniPApplet) c.newInstance(); + } catch (final Exception e) { + throw new RuntimeException(e); + } + if (mini != null) { + try { + mini.run(); + } catch (final Exception ex) { + Assume.assumeNoException(ex); + } } - } - - /** An Animator subclass which renders one frame at the time - * upon calls to the requestRender() method. - **/ - public static class CustomAnimator extends AnimatorBase { - private Timer timer = null; - private TimerTask task = null; - private volatile boolean shouldRun; - - @Override - protected String getBaseName(final String prefix) { - return "Custom" + prefix + "Animator" ; - } - - /** Creates an CustomAnimator with an initial drawable to - * animate. */ - public CustomAnimator(final GLAutoDrawable drawable) { - if (drawable != null) { - add(drawable); - } - } - - public synchronized void requestRender() { - shouldRun = true; - } - - @Override - public final synchronized boolean isStarted() { - return (timer != null); - } - - @Override - public final synchronized boolean isAnimating() { - return (timer != null) && (task != null); - } - - private void startTask() { - if(null != task) { - return; - } - - task = new TimerTask() { - private boolean firstRun = true; - @Override - public void run() { - if (firstRun) { - Thread.currentThread().setName("OPENGL"); - firstRun = false; - } - if(CustomAnimator.this.shouldRun) { - CustomAnimator.this.animThread = Thread.currentThread(); - // display impl. uses synchronized block on the animator instance - display(); - synchronized (this) { - // done with current frame. - shouldRun = false; - } - } - } - }; - - fpsCounter.resetFPSCounter(); - shouldRun = false; - - timer.schedule(task, 0, 1); - } - - @Override - public synchronized boolean start() { - if (timer != null) { - return false; - } - timer = new Timer(); - startTask(); - return true; - } - - /** Stops this CustomAnimator. */ - @Override - public synchronized boolean stop() { - if (timer == null) { - return false; - } - shouldRun = false; - if(null != task) { - task.cancel(); - task = null; - } - if(null != timer) { - timer.cancel(); - timer = null; - } - animThread = null; - try { - Thread.sleep(20); // ~ 1/60 hz wait, since we can't ctrl stopped threads / holding the lock is OK here! - } catch (final InterruptedException e) { } - return true; - } - - @Override - public final synchronized boolean isPaused() { return false; } - @Override - public synchronized boolean resume() { return false; } - @Override - public synchronized boolean pause() { return false; } - } - } - - @Test - public void test00() { - TestGLCanvasAWTActionDeadlock02AWT.MiniPApplet mini; - try { - final Class c = Thread.currentThread().getContextClassLoader().loadClass(TestGLCanvasAWTActionDeadlock02AWT.MiniPApplet.class.getName()); - mini = (TestGLCanvasAWTActionDeadlock02AWT.MiniPApplet) c.newInstance(); - } catch (final Exception e) { - throw new RuntimeException(e); - } - if (mini != null) { - try { - mini.run(); - } catch (final Exception ex) { - Assume.assumeNoException(ex); - } } - } - public static void main(final String args[]) { - for(int i=0; i newtCanvasSWT1 ( glWindow1 ) // Index 1 -> newtCanvasSWT2 ( glWindow2 ) display.syncExec(new Runnable() { + @Override public void run() { final Listener swtListener0 = new Listener() { @Override @@ -335,6 +340,7 @@ public class TestGLCanvasSWTNewtCanvasSWTPosInTabs extends UITestCase { animator.add(glad2); display.syncExec(new Runnable() { + @Override public void run() { if( focusOnTab1 ) { canvas1.setFocus(); @@ -353,12 +359,14 @@ public class TestGLCanvasSWTNewtCanvasSWTPosInTabs extends UITestCase { glWindow2.addWindowListener(quitAdapter); final WindowListener wl = new WindowAdapter() { + @Override public void windowResized(final WindowEvent e) { final GLWindow glWindow = ( e.getSource() instanceof GLWindow ) ? (GLWindow)e.getSource() : null; if( null != glWindow ) { System.err.println("window resized: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()); } } + @Override public void windowMoved(final WindowEvent e) { final GLWindow glWindow = ( e.getSource() instanceof GLWindow ) ? (GLWindow)e.getSource() : null; if( null != glWindow ) { @@ -370,6 +378,7 @@ public class TestGLCanvasSWTNewtCanvasSWTPosInTabs extends UITestCase { glWindow2.addWindowListener(wl); final KeyListener kl = new KeyAdapter() { + @Override public void keyReleased(final KeyEvent e) { if( !e.isPrintableKey() || e.isAutoRepeat() ) { return; @@ -378,6 +387,7 @@ public class TestGLCanvasSWTNewtCanvasSWTPosInTabs extends UITestCase { if( null != glWindow ) { if(e.getKeyChar()=='f') { glWindow.invokeOnNewThread(null, false, new Runnable() { + @Override public void run() { final Thread t = glWindow.setExclusiveContextThread(null); System.err.println("[set fullscreen pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets()); @@ -413,12 +423,14 @@ public class TestGLCanvasSWTNewtCanvasSWTPosInTabs extends UITestCase { animator.setUpdateFPSFrames(60, null); display.syncExec(new Runnable() { + @Override public void run() { shell.open(); } } ); Assert.assertEquals(true, GLTestUtil.waitForRealized( focusOnTab1 ? glad1 : glad2, true, waitAction)); display.syncExec(new Runnable() { + @Override public void run() { final Canvas canvas = focusOnTab1 ? canvas1 : canvas2; System.err.println("Canvas pixel-units pos/siz.0: pos "+SWTAccessor.getLocationInPixels(canvas)+", size "+SWTAccessor.getSizeInPixels(canvas)); @@ -444,13 +456,14 @@ public class TestGLCanvasSWTNewtCanvasSWTPosInTabs extends UITestCase { generalWaitAction.run(); } display.syncExec( new Runnable() { - public void run() { - shell.setSize( rwsize.getWidth(), rwsize.getHeight() ); - final Canvas canvas = focusOnTab1 ? canvas1 : canvas2; - System.err.println("Canvas pixel-units pos/siz.1: pos "+SWTAccessor.getLocationInPixels(canvas)+", size "+SWTAccessor.getSizeInPixels(canvas)); - System.err.println("Canvas window-units pos/siz.1: pos "+canvas.getLocation()+", size "+canvas.getSize()); - System.err.println("Canvas LOS.1: "+canvas.toDisplay(0, 0)); - } } ); + @Override + public void run() { + shell.setSize( rwsize.getWidth(), rwsize.getHeight() ); + final Canvas canvas = focusOnTab1 ? canvas1 : canvas2; + System.err.println("Canvas pixel-units pos/siz.1: pos "+SWTAccessor.getLocationInPixels(canvas)+", size "+SWTAccessor.getSizeInPixels(canvas)); + System.err.println("Canvas window-units pos/siz.1: pos "+canvas.getLocation()+", size "+canvas.getSize()); + System.err.println("Canvas LOS.1: "+canvas.toDisplay(0, 0)); + } } ); if( useNewtCanvasSWT ) { final GLWindow glWindow = focusOnTab1 ? glWindow1 : glWindow2; final NewtCanvasSWT newtCanvasSWT = focusOnTab1 ? newtCanvasSWT1 : newtCanvasSWT2; @@ -471,6 +484,7 @@ public class TestGLCanvasSWTNewtCanvasSWTPosInTabs extends UITestCase { Assert.assertTrue( "NewtCanvasAWT2 LOS "+pNatWinLOS+" not >= sash-right "+pSashRightClient, pNatWinLOS.compareTo(pSashRightClient) >= 0 ); } else { display.syncExec(new Runnable() { + @Override public void run() { final org.eclipse.swt.graphics.Point los = glCanvas2.toDisplay(0, 0); pGLWinLOS[0] = new Point(los.x, los.y); @@ -501,12 +515,14 @@ public class TestGLCanvasSWTNewtCanvasSWTPosInTabs extends UITestCase { try { if( useNewtCanvasSWT ) { display.syncExec( new Runnable() { - public void run() { - newtCanvasSWT1.dispose(); - } } ); + @Override + public void run() { + newtCanvasSWT1.dispose(); + } } ); glWindow1.destroy(); Assert.assertEquals(true, NewtTestUtil.waitForRealized(glWindow1, false, null)); display.syncExec( new Runnable() { + @Override public void run() { newtCanvasSWT2.dispose(); } } ); @@ -514,6 +530,7 @@ public class TestGLCanvasSWTNewtCanvasSWTPosInTabs extends UITestCase { Assert.assertEquals(true, NewtTestUtil.waitForRealized(glWindow2, false, null)); } else { display.syncExec( new Runnable() { + @Override public void run() { glCanvas1.dispose(); glCanvas2.dispose(); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTJOGLGLCanvas01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTJOGLGLCanvas01GLn.java index 68c25fca2..d967e7e71 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTJOGLGLCanvas01GLn.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTJOGLGLCanvas01GLn.java @@ -93,11 +93,13 @@ public class TestSWTJOGLGLCanvas01GLn extends UITestCase { @Before public void init() { SWTAccessor.invokeOnOSTKThread(true, new Runnable() { + @Override public void run() { display = new Display(); Assert.assertNotNull( display ); }}); display.syncExec(new Runnable() { + @Override public void run() { shell = new Shell( display ); Assert.assertNotNull( shell ); @@ -115,14 +117,16 @@ public class TestSWTJOGLGLCanvas01GLn extends UITestCase { Assert.assertNotNull( composite ); try { display.syncExec(new Runnable() { - public void run() { - composite.dispose(); - shell.dispose(); - }}); + @Override + public void run() { + composite.dispose(); + shell.dispose(); + }}); SWTAccessor.invokeOnOSTKThread(true, new Runnable() { - public void run() { - display.dispose(); - }}); + @Override + public void run() { + display.dispose(); + }}); } catch( final Throwable throwable ) { throwable.printStackTrace(); @@ -141,23 +145,28 @@ public class TestSWTJOGLGLCanvas01GLn extends UITestCase { canvas.addGLEventListener( demo ); canvas.addGLEventListener(new GLEventListener() { - int displayCount = 0; - public void init(final GLAutoDrawable drawable) { } - public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { } - public void display(final GLAutoDrawable drawable) { - if(displayCount < 3) { - snapshot(displayCount++, null, drawable.getGL(), screenshot, TextureIO.PNG, null); - } - } - public void dispose(final GLAutoDrawable drawable) { } + int displayCount = 0; + @Override + public void init(final GLAutoDrawable drawable) { } + @Override + public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { } + @Override + public void display(final GLAutoDrawable drawable) { + if(displayCount < 3) { + snapshot(displayCount++, null, drawable.getGL(), screenshot, TextureIO.PNG, null); + } + } + @Override + public void dispose(final GLAutoDrawable drawable) { } }); display.syncExec(new Runnable() { - public void run() { - shell.setText( getSimpleTestName(".") ); - shell.setSize( 640, 480 ); - shell.open(); - } } ); + @Override + public void run() { + shell.setText( getSimpleTestName(".") ); + shell.setSize( 640, 480 ); + shell.open(); + } } ); final Animator anim = new Animator(); if(doAnimation) { @@ -180,9 +189,10 @@ public class TestSWTJOGLGLCanvas01GLn extends UITestCase { anim.stop(); display.syncExec(new Runnable() { - public void run() { - canvas.dispose(); - } } ); + @Override + public void run() { + canvas.dispose(); + } } ); } @Test diff --git a/src/test/com/jogamp/opengl/test/junit/newt/DemoCreateAndDisposeOnCloseNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/DemoCreateAndDisposeOnCloseNEWT.java index a5cd38909..4365d891c 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/DemoCreateAndDisposeOnCloseNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/DemoCreateAndDisposeOnCloseNEWT.java @@ -64,7 +64,7 @@ public class DemoCreateAndDisposeOnCloseNEWT { caps.setBackgroundOpaque(true); caps.setDoubleBuffered(true); caps.setDepthBits(16); - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); final GLWindow glWindow = GLWindow.create(caps); animator.add(glWindow); glWindow.addGLEventListener(new GLEventListener() { diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindowInvisiblePointer01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindowInvisiblePointer01NEWT.java index 709bad2a0..aa5b6d8cb 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindowInvisiblePointer01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindowInvisiblePointer01NEWT.java @@ -75,7 +75,7 @@ public class TestGLWindowInvisiblePointer01NEWT extends UITestCase { final GLWindow window1 = createWindow(null, caps); // local Assert.assertEquals(true,window1.isNativeValid()); Assert.assertEquals(true,window1.isVisible()); - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); animator.setUpdateFPSFrames(1, null); animator.add(window1); animator.start(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindowWarpPointer01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindowWarpPointer01NEWT.java index ec121f601..e198383de 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindowWarpPointer01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindowWarpPointer01NEWT.java @@ -88,7 +88,7 @@ public class TestGLWindowWarpPointer01NEWT extends UITestCase { final GLWindow window1 = createWindow(null, caps); // local Assert.assertEquals(true,window1.isNativeValid()); Assert.assertEquals(true,window1.isVisible()); - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); animator.setUpdateFPSFrames(1, null); animator.add(window1); animator.start(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java index 48700ab13..bbf43a4a4 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java @@ -149,7 +149,7 @@ public class TestGLWindows02NEWTAnimated extends UITestCase { final GLCapabilities caps = new GLCapabilities(glp); Assert.assertNotNull(caps); final GLWindow window = createWindow(null, caps, width, height, true /* onscreen */, false /* undecorated */, true /* vsync */); - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); animator.setUpdateFPSFrames(1, null); Assert.assertTrue(animator.start()); Thread.sleep(250); // give animator a chance to become paused @@ -191,7 +191,7 @@ public class TestGLWindows02NEWTAnimated extends UITestCase { final RectangleImmutable screenBoundsInWinU = screen.getViewportInWindowUnits(); window2.setPosition(screenBoundsInWinU.getWidth()-width, 0); - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); animator.setUpdateFPSFrames(1, null); Assert.assertEquals(false, animator.isStarted()); Assert.assertEquals(false, animator.isAnimating()); // zero drawables @@ -258,7 +258,7 @@ public class TestGLWindows02NEWTAnimated extends UITestCase { final RectangleImmutable screen2BoundsInWinU = screen2.getViewportInWindowUnits(); window2.setPosition(screen2BoundsInWinU.getWidth()-width, 0); - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); animator.setUpdateFPSFrames(1, null); Assert.assertEquals(false, animator.isStarted()); Assert.assertEquals(false, animator.isAnimating()); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java index e4438893f..414b35ddd 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java @@ -89,7 +89,7 @@ public class TestRemoteGLWindows01NEWT extends UITestCase { @Test public void testRemoteWindow01() throws InterruptedException { - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); final GLProfile glpLocal = GLProfile.getGL2ES1(); Assert.assertNotNull(glpLocal); final GLCapabilities capsLocal = new GLCapabilities(glpLocal); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestWindowAndPointerIconNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowAndPointerIconNEWT.java index 8e2d191b2..31e70cbca 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestWindowAndPointerIconNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestWindowAndPointerIconNEWT.java @@ -107,8 +107,7 @@ public class TestWindowAndPointerIconNEWT extends SingletonJunitCase { glWindow.setPointerIcon(pointerIcon); System.err.println("Set PointerIcon: "+glWindow.getPointerIcon()); - final Animator animator = new Animator(); - animator.setModeBits(false, AnimatorBase.MODE_EXPECT_AWT_RENDERING_THREAD); + final Animator animator = new Animator(0 /* w/o AWT */); animator.add(glWindow); animator.start(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestTranslucentChildWindowBug632NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestTranslucentChildWindowBug632NEWT.java index d24a95ffa..d26eac1bb 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestTranslucentChildWindowBug632NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestTranslucentChildWindowBug632NEWT.java @@ -89,7 +89,7 @@ public class TestTranslucentChildWindowBug632NEWT extends UITestCase { @Test public void testWindow00() throws InterruptedException { - final Animator animator = new Animator(); + final Animator animator = new Animator(0 /* w/o AWT */); final GLCapabilities caps = new GLCapabilities(glp); Assert.assertNotNull(caps); -- cgit v1.2.3