diff options
11 files changed, 143 insertions, 82 deletions
diff --git a/make/scripts/tests-win.bat b/make/scripts/tests-win.bat index 1a68ad186..cfdef2de6 100755 --- a/make/scripts/tests-win.bat +++ b/make/scripts/tests-win.bat @@ -21,7 +21,7 @@ REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestLa REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestElektronenMultipliziererNEWT %* REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.demos.gl3.newt.TestGeomShader01TextureGL3NEWT %* -scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieSimple %* +REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieSimple %* REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube %* REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.demos.es2.TexCubeES2 %* @@ -218,6 +218,7 @@ REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.offscreen.TestOffscre REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.offscreen.TestOffscreen02BitmapNEWT REM scripts\java-win.bat com.jogamp.opengl.test.junit.graph.TestRegionRendererNEWT01 +scripts\java-win.bat com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT00 REM scripts\java-win.bat com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT01 REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.glsl.TestGLSLShaderState02NEWT REM scripts\java-win.bat com.jogamp.opengl.test.junit.jogl.glsl.TestGLSLShaderState02NEWT diff --git a/src/jogl/classes/jogamp/opengl/FPSCounterImpl.java b/src/jogl/classes/jogamp/opengl/FPSCounterImpl.java index 7f8f262e9..61d6d965b 100644 --- a/src/jogl/classes/jogamp/opengl/FPSCounterImpl.java +++ b/src/jogl/classes/jogamp/opengl/FPSCounterImpl.java @@ -30,16 +30,26 @@ package jogamp.opengl; import java.io.PrintStream; import java.util.concurrent.TimeUnit; +import com.jogamp.common.os.Clock; import com.jogamp.opengl.FPSCounter; /** * Default implementation of FPSCounter to be used for FPSCounter implementing renderer. */ public class FPSCounterImpl implements FPSCounter { - private int fpsUpdateFramesInterval; private PrintStream fpsOutputStream ; - private long fpsStartTime, fpsLastUpdateTime, fpsLastPeriod, fpsTotalDuration; + + // counter in [ns] + private long fpsStartTimeNS, fpsLastUpdateTimeNS; + + // counter in [ms] + private long fpsLastPeriodMS, fpsTotalDurationMS; + + // counter in events + private int fpsUpdateFramesInterval; private int fpsTotalFrames; + + // counter in fps private float fpsLast, fpsTotal; /** Creates a disabled instance */ @@ -52,25 +62,24 @@ public class FPSCounterImpl implements FPSCounter { * update interval is reached.<br> * * Shall be called by actual FPSCounter implementing renderer, after display a new frame. - * */ public final synchronized void tickFPS() { fpsTotalFrames++; if(fpsUpdateFramesInterval>0 && fpsTotalFrames%fpsUpdateFramesInterval == 0) { - final long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); - fpsLastPeriod = now - fpsLastUpdateTime; - fpsLastPeriod = Math.max(fpsLastPeriod, 1); // div 0 - fpsLast = ( fpsUpdateFramesInterval * 1000f ) / ( fpsLastPeriod ) ; + final long now = Clock.currentNanos(); + fpsLastPeriodMS = TimeUnit.NANOSECONDS.toMillis(now - fpsLastUpdateTimeNS); + fpsLastPeriodMS = Math.max(fpsLastPeriodMS, 1); // div 0 + fpsLast = ( fpsUpdateFramesInterval * 1000f ) / ( fpsLastPeriodMS ) ; - fpsTotalDuration = now - fpsStartTime; - fpsTotalDuration = Math.max(fpsTotalDuration, 1); // div 0 - fpsTotal= ( fpsTotalFrames * 1000f ) / ( fpsTotalDuration ) ; + fpsTotalDurationMS = TimeUnit.NANOSECONDS.toMillis(now - fpsStartTimeNS); + fpsTotalDurationMS = Math.max(fpsTotalDurationMS, 1); // div 0 + fpsTotal= ( fpsTotalFrames * 1000f ) / ( fpsTotalDurationMS ) ; if(null != fpsOutputStream) { fpsOutputStream.println(toString()); } - fpsLastUpdateTime = now; + fpsLastUpdateTimeNS = now; } } @@ -82,8 +91,8 @@ public class FPSCounterImpl implements FPSCounter { fpsLastS = fpsLastS.substring(0, fpsLastS.indexOf('.') + 2); String fpsTotalS = String.valueOf(fpsTotal); fpsTotalS = fpsTotalS.substring(0, fpsTotalS.indexOf('.') + 2); - sb.append(fpsTotalDuration/1000 +" s: "+ fpsUpdateFramesInterval+" f / "+ fpsLastPeriod+" ms, " + fpsLastS+" fps, "+ fpsLastPeriod/fpsUpdateFramesInterval+" ms/f; "+ - "total: "+ fpsTotalFrames+" f, "+ fpsTotalS+ " fps, "+ fpsTotalDuration/fpsTotalFrames+" ms/f"); + sb.append(fpsTotalDurationMS/1000 +" s: "+ fpsUpdateFramesInterval+" f / "+ fpsLastPeriodMS+" ms, " + fpsLastS+" fps, "+ fpsLastPeriodMS/fpsUpdateFramesInterval+" ms/f; "+ + "total: "+ fpsTotalFrames+" f, "+ fpsTotalS+ " fps, "+ fpsTotalDurationMS/fpsTotalFrames+" ms/f"); return sb; } @@ -101,12 +110,12 @@ public class FPSCounterImpl implements FPSCounter { @Override public final synchronized void resetFPSCounter() { - fpsStartTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); // overwrite startTime to real init one - fpsLastUpdateTime = fpsStartTime; - fpsLastPeriod = 0; + fpsStartTimeNS = Clock.currentNanos(); + fpsLastUpdateTimeNS = fpsStartTimeNS; + fpsLastPeriodMS = 0; fpsTotalFrames = 0; fpsLast = 0f; fpsTotal = 0f; - fpsLastPeriod = 0; fpsTotalDuration=0; + fpsLastPeriodMS = 0; fpsTotalDurationMS=0; } @Override @@ -116,17 +125,17 @@ public class FPSCounterImpl implements FPSCounter { @Override public final synchronized long getFPSStartTime() { - return fpsStartTime; + return TimeUnit.NANOSECONDS.toMillis(fpsStartTimeNS); } @Override public final synchronized long getLastFPSUpdateTime() { - return fpsLastUpdateTime; + return TimeUnit.NANOSECONDS.toMillis(fpsLastUpdateTimeNS); } @Override public final synchronized long getLastFPSPeriod() { - return fpsLastPeriod; + return fpsLastPeriodMS; } @Override @@ -141,7 +150,7 @@ public class FPSCounterImpl implements FPSCounter { @Override public final synchronized long getTotalFPSDuration() { - return fpsTotalDuration; + return fpsTotalDurationMS; } @Override diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java index d97e0e201..7964416fe 100644 --- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java @@ -50,6 +50,7 @@ import java.util.Map; import java.util.Set; import com.jogamp.common.ExceptionUtils; +import com.jogamp.common.os.Clock; import com.jogamp.common.os.DynamicLookupHelper; import com.jogamp.common.os.Platform; import com.jogamp.common.util.Bitfield; @@ -1200,7 +1201,7 @@ public abstract class GLContextImpl extends GLContext { if (DEBUG) { System.err.println(getThreadName() + ": createContextARB-MapGLVersions START (GLDesktop "+hasOpenGLDesktopSupport+", GLES "+hasOpenGLESSupport+", minorVersion "+hasMinorVersionSupport+") on "+device); } - final long t0 = ( DEBUG ) ? System.nanoTime() : 0; + final long t0 = ( DEBUG ) ? Clock.currentNanos() : 0; boolean success = false; // Following GLProfile.GL_PROFILE_LIST_ALL order of profile detection { GL4bc, GL3bc, GL2, GL4, GL3, GL2GL3, GLES2, GL2ES2, GLES1, GL2ES1 } boolean hasGL4bc = false; @@ -1350,7 +1351,7 @@ public abstract class GLContextImpl extends GLContext { GLContext.setAvailableGLVersionsSet(device, true); } if(DEBUG) { - final long t1 = System.nanoTime(); + final long t1 = Clock.currentNanos(); System.err.println(getThreadName() + ": createContextARB-MapGLVersions END (success "+success+") on "+device+", profileAliasing: "+PROFILE_ALIASING+", total "+(t1-t0)/1e6 +"ms"); if( success ) { System.err.println(GLContext.dumpAvailableGLVersions(null).toString()); diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index 6b102ea68..1435aa20a 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -73,6 +73,7 @@ import jogamp.opengl.GLContextImpl; import jogamp.opengl.GLDrawableImpl; import com.jogamp.common.GlueGenVersion; +import com.jogamp.common.os.Clock; import com.jogamp.common.util.SecurityUtil; import com.jogamp.common.util.VersionUtil; import com.jogamp.common.util.locks.RecursiveLock; @@ -679,7 +680,7 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind public synchronized void setVisibleActionPost(final boolean visible, final boolean nativeWindowCreated) { long t0; if(Window.DEBUG_IMPLEMENTATION) { - t0 = System.nanoTime(); + t0 = Clock.currentNanos(); System.err.println("GLWindow.setVisibleActionPost("+visible+", "+nativeWindowCreated+") "+WindowImpl.getThreadName()+", start"); } else { t0 = 0; @@ -710,7 +711,7 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind } } if(Window.DEBUG_IMPLEMENTATION) { - System.err.println("GLWindow.setVisibleActionPost("+visible+", "+nativeWindowCreated+") "+WindowImpl.getThreadName()+", fin: dt "+ (System.nanoTime()-t0)/1e6 +"ms"); + System.err.println("GLWindow.setVisibleActionPost("+visible+", "+nativeWindowCreated+") "+WindowImpl.getThreadName()+", fin: dt "+ (Clock.currentNanos()-t0)/1e6 +"ms"); } } diff --git a/src/newt/classes/jogamp/newt/ScreenImpl.java b/src/newt/classes/jogamp/newt/ScreenImpl.java index b41c28e27..78df525ee 100644 --- a/src/newt/classes/jogamp/newt/ScreenImpl.java +++ b/src/newt/classes/jogamp/newt/ScreenImpl.java @@ -43,7 +43,7 @@ import com.jogamp.nativewindow.NativeWindowException; import com.jogamp.nativewindow.util.Dimension; import com.jogamp.nativewindow.util.Rectangle; import com.jogamp.nativewindow.util.RectangleImmutable; - +import com.jogamp.common.os.Clock; import com.jogamp.common.util.ArrayHashSet; import com.jogamp.common.util.PropertyAccess; import com.jogamp.newt.Display; @@ -184,7 +184,7 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { { if(null == aScreen) { if(DEBUG) { - tCreated = System.nanoTime(); + tCreated = Clock.currentNanos(); System.err.println("Screen.createNative() START ("+Display.getThreadName()+", "+this+")"); } else { tCreated = 0; @@ -200,7 +200,7 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { synchronized(screenList) { screensActive++; if(DEBUG) { - System.err.println("Screen.createNative() END ("+Display.getThreadName()+", "+this+"), active "+screensActive+", total "+ (System.nanoTime()-tCreated)/1e6 +"ms"); + System.err.println("Screen.createNative() END ("+Display.getThreadName()+", "+this+"), active "+screensActive+", total "+ (Clock.currentNanos()-tCreated)/1e6 +"ms"); } } ScreenMonitorState.getScreenMonitorState(this.getFQName()).addListener(this); @@ -554,7 +554,7 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { private final ScreenMonitorState initMonitorState() { long t0; if(DEBUG) { - t0 = System.nanoTime(); + t0 = Clock.currentNanos(); System.err.println("Screen.initMonitorState() START ("+Display.getThreadName()+", "+this+")"); } else { t0 = 0; @@ -614,7 +614,7 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { ScreenMonitorState.unlockScreenMonitorState(); } if(DEBUG) { - System.err.println("Screen.initMonitorState() END dt "+ (System.nanoTime()-t0)/1e6 +"ms"); + System.err.println("Screen.initMonitorState() END dt "+ (Clock.currentNanos()-t0)/1e6 +"ms"); } if( !vScrnSizeUpdated ) { updateVirtualScreenOriginAndSize(); diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 45329bed9..c860e4c3e 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -66,6 +66,7 @@ import jogamp.nativewindow.SurfaceScaleUtils; import jogamp.nativewindow.SurfaceUpdatedHelper; import com.jogamp.common.ExceptionUtils; +import com.jogamp.common.os.Clock; import com.jogamp.common.util.ArrayHashSet; import com.jogamp.common.util.Bitfield; import com.jogamp.common.util.InterruptSource; @@ -738,7 +739,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer private boolean createNative() { long tStart; if(DEBUG_IMPLEMENTATION) { - tStart = System.nanoTime(); + tStart = Clock.currentNanos(); System.err.println("Window.createNative() START ("+getThreadName()+", "+this+")"); } else { tStart = 0; @@ -839,7 +840,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer ((DisplayImpl) screen.getDisplay()).dispatchMessagesNative(); // status up2date } if(DEBUG_IMPLEMENTATION) { - System.err.println("Window.createNative() END ("+getThreadName()+", "+this+") total "+ (System.nanoTime()-tStart)/1e6 +"ms"); + System.err.println("Window.createNative() END ("+getThreadName()+", "+this+") total "+ (Clock.currentNanos()-tStart)/1e6 +"ms"); } return isNativeValid() ; } diff --git a/src/test/com/jogamp/opengl/test/bugs/Bug735Inv0AppletAWT.java b/src/test/com/jogamp/opengl/test/bugs/Bug735Inv0AppletAWT.java index 7430dcd38..f30cda4f3 100644 --- a/src/test/com/jogamp/opengl/test/bugs/Bug735Inv0AppletAWT.java +++ b/src/test/com/jogamp/opengl/test/bugs/Bug735Inv0AppletAWT.java @@ -27,6 +27,7 @@ import com.jogamp.opengl.GLRunnable; import com.jogamp.opengl.GLUniformData; import com.jogamp.opengl.awt.GLCanvas; import com.jogamp.opengl.glu.GLU; +import com.jogamp.common.os.Clock; import com.jogamp.common.util.InterruptSource; import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.opengl.GLWindow; @@ -90,26 +91,29 @@ public class Bug735Inv0AppletAWT extends Applet implements Runnable { private int fcount = 0, lastm = 0; private final int fint = 1; - public void init() { + @Override +public void init() { setSize(APPLET_WIDTH, APPLET_HEIGHT); setPreferredSize(new Dimension(APPLET_WIDTH, APPLET_HEIGHT)); width = APPLET_WIDTH; height = APPLET_HEIGHT; } - public void start() { + @Override +public void start() { thread = new InterruptSource.Thread(null, this, "Animation Thread"); thread.start(); } - public void run() { + @Override +public void run() { int noDelays = 0; // Number of frames with a delay of 0 ms before the // animation thread yields to other running threads. final int NO_DELAYS_PER_YIELD = 15; final int TIMEOUT_SECONDS = 2; - long beforeTime = System.nanoTime(); + long beforeTime = Clock.currentNanos(); long overSleepTime = 0L; millisOffset = System.currentTimeMillis(); @@ -125,13 +129,14 @@ public class Bug735Inv0AppletAWT extends Applet implements Runnable { if (frameCount == 1) { EventQueue.invokeLater(new Runnable() { - public void run() { + @Override + public void run() { requestFocusInWindow(); } }); } - final long afterTime = System.nanoTime(); + 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 @@ -139,7 +144,7 @@ public class Bug735Inv0AppletAWT extends Applet implements Runnable { Thread.sleep(sleepTime / 1000000L, (int) (sleepTime % 1000000L)); noDelays = 0; // Got some sleep, not delaying anymore } catch (final InterruptedException ex) { } - overSleepTime = (System.nanoTime() - afterTime) - sleepTime; + overSleepTime = (Clock.currentNanos() - afterTime) - sleepTime; } else { // sleepTime <= 0; the frame took longer than the period overSleepTime = 0L; noDelays++; @@ -148,7 +153,7 @@ public class Bug735Inv0AppletAWT extends Applet implements Runnable { noDelays = 0; } } - beforeTime = System.nanoTime(); + beforeTime = Clock.currentNanos(); } } @@ -418,7 +423,8 @@ public class Bug735Inv0AppletAWT extends Applet implements Runnable { // This allows to close the frame. frame.addWindowListener(new WindowAdapter() { - public void windowClosing(final WindowEvent e) { + @Override + public void windowClosing(final WindowEvent e) { System.exit(0); } }); diff --git a/src/test/com/jogamp/opengl/test/bugs/Bug735Inv1AppletAWT.java b/src/test/com/jogamp/opengl/test/bugs/Bug735Inv1AppletAWT.java index b31a5f410..15826a8c0 100644 --- a/src/test/com/jogamp/opengl/test/bugs/Bug735Inv1AppletAWT.java +++ b/src/test/com/jogamp/opengl/test/bugs/Bug735Inv1AppletAWT.java @@ -27,6 +27,7 @@ import com.jogamp.opengl.GLRunnable; import com.jogamp.opengl.GLUniformData; import com.jogamp.opengl.awt.GLCanvas; import com.jogamp.opengl.glu.GLU; +import com.jogamp.common.os.Clock; import com.jogamp.common.util.InterruptSource; import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.opengl.GLWindow; @@ -92,26 +93,29 @@ public class Bug735Inv1AppletAWT extends Applet implements Runnable { private int fcount = 0, lastm = 0; private final int fint = 1; - public void init() { + @Override +public void init() { setSize(APPLET_WIDTH, APPLET_HEIGHT); setPreferredSize(new Dimension(APPLET_WIDTH, APPLET_HEIGHT)); width = APPLET_WIDTH; height = APPLET_HEIGHT; } - public void start() { + @Override +public void start() { thread = new InterruptSource.Thread(null, this, "Animation Thread"); thread.start(); } - public void run() { + @Override +public void run() { int noDelays = 0; // Number of frames with a delay of 0 ms before the // animation thread yields to other running threads. final int NO_DELAYS_PER_YIELD = 15; final int TIMEOUT_SECONDS = 2; - long beforeTime = System.nanoTime(); + long beforeTime = Clock.currentNanos(); long overSleepTime = 0L; millisOffset = System.currentTimeMillis(); @@ -127,13 +131,14 @@ public class Bug735Inv1AppletAWT extends Applet implements Runnable { if (frameCount == 1) { EventQueue.invokeLater(new Runnable() { - public void run() { + @Override + public void run() { requestFocusInWindow(); } }); } - final long afterTime = System.nanoTime(); + 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 @@ -141,7 +146,7 @@ public class Bug735Inv1AppletAWT extends Applet implements Runnable { Thread.sleep(sleepTime / 1000000L, (int) (sleepTime % 1000000L)); noDelays = 0; // Got some sleep, not delaying anymore } catch (final InterruptedException ex) { } - overSleepTime = (System.nanoTime() - afterTime) - sleepTime; + overSleepTime = (Clock.currentNanos() - afterTime) - sleepTime; } else { // sleepTime <= 0; the frame took longer than the period overSleepTime = 0L; noDelays++; @@ -150,7 +155,7 @@ public class Bug735Inv1AppletAWT extends Applet implements Runnable { noDelays = 0; } } - beforeTime = System.nanoTime(); + beforeTime = Clock.currentNanos(); } } @@ -417,7 +422,8 @@ public class Bug735Inv1AppletAWT extends Applet implements Runnable { // This allows to close the frame. frame.addWindowListener(new WindowAdapter() { - public void windowClosing(final WindowEvent e) { + @Override + public void windowClosing(final WindowEvent e) { System.exit(0); } }); diff --git a/src/test/com/jogamp/opengl/test/bugs/Bug735Inv2AppletAWT.java b/src/test/com/jogamp/opengl/test/bugs/Bug735Inv2AppletAWT.java index d0e4448cc..31ff4193c 100644 --- a/src/test/com/jogamp/opengl/test/bugs/Bug735Inv2AppletAWT.java +++ b/src/test/com/jogamp/opengl/test/bugs/Bug735Inv2AppletAWT.java @@ -20,6 +20,7 @@ import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLEventListener; import com.jogamp.opengl.GLProfile; import com.jogamp.opengl.awt.GLCanvas; +import com.jogamp.common.os.Clock; import com.jogamp.common.util.InterruptSource; import com.jogamp.junit.util.JunitTracer; import com.jogamp.newt.awt.NewtCanvasAWT; @@ -73,7 +74,8 @@ public class Bug735Inv2AppletAWT extends Applet implements Runnable { private final long frameRatePeriod = 1000000000L / TARGET_FPS; private int frameCount; - public void init() { + @Override +public void init() { setSize(APPLET_WIDTH, APPLET_HEIGHT); setPreferredSize(new Dimension(APPLET_WIDTH, APPLET_HEIGHT)); width = APPLET_WIDTH; @@ -81,27 +83,30 @@ public class Bug735Inv2AppletAWT extends Applet implements Runnable { initGL(); } - public void start() { + @Override +public void start() { initDraw(); thread = new InterruptSource.Thread(null, this, "Animation Thread"); thread.start(); } - public void run() { + @Override +public void run() { int noDelays = 0; // Number of frames with a delay of 0 ms before the // animation thread yields to other running threads. final int NO_DELAYS_PER_YIELD = 15; final int TIMEOUT_SECONDS = 2; - long beforeTime = System.nanoTime(); + long beforeTime = Clock.currentNanos(); long overSleepTime = 0L; frameCount = 1; while (Thread.currentThread() == thread) { if (frameCount == 1) { EventQueue.invokeLater(new Runnable() { - public void run() { + @Override + public void run() { requestFocusInWindow(); } }); @@ -117,7 +122,7 @@ public class Bug735Inv2AppletAWT extends Applet implements Runnable { e.printStackTrace(); } - final long afterTime = System.nanoTime(); + 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 @@ -125,7 +130,7 @@ public class Bug735Inv2AppletAWT extends Applet implements Runnable { Thread.sleep(sleepTime / 1000000L, (int) (sleepTime % 1000000L)); noDelays = 0; // Got some sleep, not delaying anymore } catch (final InterruptedException ex) { } - overSleepTime = (System.nanoTime() - afterTime) - sleepTime; + overSleepTime = (Clock.currentNanos() - afterTime) - sleepTime; } else { // sleepTime <= 0; the frame took longer than the period overSleepTime = 0L; noDelays++; @@ -134,7 +139,7 @@ public class Bug735Inv2AppletAWT extends Applet implements Runnable { noDelays = 0; } } - beforeTime = System.nanoTime(); + beforeTime = Clock.currentNanos(); } } @@ -262,7 +267,8 @@ public class Bug735Inv2AppletAWT extends Applet implements Runnable { // This allows to close the frame. frame.addWindowListener(new WindowAdapter() { - public void windowClosing(final WindowEvent e) { + @Override + public void windowClosing(final WindowEvent e) { System.exit(0); } }); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestGLCanvasAWTActionDeadlock02AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestGLCanvasAWTActionDeadlock02AWT.java index 58a7a72c1..35970bc1e 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestGLCanvasAWTActionDeadlock02AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestGLCanvasAWTActionDeadlock02AWT.java @@ -55,6 +55,7 @@ import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; +import com.jogamp.common.os.Clock; import com.jogamp.common.os.Platform; import com.jogamp.common.util.VersionNumber; import com.jogamp.common.util.awt.AWTEDTExecutor; @@ -216,12 +217,14 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { } // 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); @@ -235,6 +238,7 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { } try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { frame.setLayout(null); frame.add(applet); @@ -273,7 +277,8 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { frame.add(this); frame.addWindowListener(new WindowAdapter() { - public void windowClosing(final WindowEvent e) { + @Override + public void windowClosing(final WindowEvent e) { try { dispose(); } catch (final Exception ex) { @@ -283,6 +288,7 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { }); javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { frame.setVisible(true); } } ); @@ -301,6 +307,7 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { 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); @@ -339,6 +346,7 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { // 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); @@ -378,6 +386,7 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { frame = null; } else { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { MiniPApplet.this.remove(canvas); frame.remove(MiniPApplet.this); @@ -391,6 +400,7 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { void draw(final GL2 gl) { if( !osxCALayerAWTModBug || !justInitialized ) { AWTEDTExecutor.singleton.invoke(true, new Runnable() { + @Override public void run() { frame.setTitle("frame " + frameCount); } } ); @@ -409,7 +419,7 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { System.out.println(OPENGL_EXTENSIONS); final int[] temp = { 0 }; - gl.glGetIntegerv(GL2ES3.GL_MAX_SAMPLES, 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); @@ -475,7 +485,7 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { } void clock() { - final long afterTime = System.nanoTime(); + final long afterTime = Clock.currentNanos(); final long timeDiff = afterTime - beforeTime; final long sleepTime = (frameRatePeriod - timeDiff) - overSleepTime; @@ -484,13 +494,13 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { Thread.sleep(sleepTime / 1000000L, (int) (sleepTime % 1000000L)); } catch (final InterruptedException ex) { } - overSleepTime = (System.nanoTime() - afterTime) - sleepTime; + overSleepTime = (Clock.currentNanos() - afterTime) - sleepTime; } else { // sleepTime <= 0; the frame took longer than the period overSleepTime = 0L; } - beforeTime = System.nanoTime(); + beforeTime = Clock.currentNanos(); } class SimpleListener implements GLEventListener { @@ -512,31 +522,36 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int w, final int h) { } } - public void mouseDragged(final MouseEvent ev) { + @Override + public void mouseDragged(final MouseEvent ev) { if (printEventInfo) { System.err.println("Mouse dragged event: " + ev); } } - public void mouseMoved(final MouseEvent ev) { + @Override + public void mouseMoved(final MouseEvent ev) { if (printEventInfo) { System.err.println("Mouse moved event: " + ev); } } - public void keyPressed(final KeyEvent ev) { + @Override + public void keyPressed(final KeyEvent ev) { if (printEventInfo) { System.err.println("Key pressed event: " + ev); } } - public void keyReleased(final KeyEvent ev) { + @Override + public void keyReleased(final KeyEvent ev) { if (printEventInfo) { System.err.println("Key released event: " + ev); } } - public void keyTyped(final KeyEvent ev) { + @Override + public void keyTyped(final KeyEvent ev) { if (printEventInfo) { System.err.println("Key typed event: " + ev); } @@ -550,7 +565,8 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { private TimerTask task = null; private volatile boolean shouldRun; - protected String getBaseName(final String prefix) { + @Override + protected String getBaseName(final String prefix) { return "Custom" + prefix + "Animator" ; } @@ -566,11 +582,13 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { shouldRun = true; } - public final synchronized boolean isStarted() { + @Override + public final synchronized boolean isStarted() { return (timer != null); } - public final synchronized boolean isAnimating() { + @Override + public final synchronized boolean isAnimating() { return (timer != null) && (task != null); } @@ -581,7 +599,8 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { task = new TimerTask() { private boolean firstRun = true; - public void run() { + @Override + public void run() { if (firstRun) { Thread.currentThread().setName("OPENGL"); firstRun = false; @@ -604,7 +623,8 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { timer.schedule(task, 0, 1); } - public synchronized boolean start() { + @Override + public synchronized boolean start() { if (timer != null) { return false; } @@ -614,7 +634,8 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { } /** Stops this CustomAnimator. */ - public synchronized boolean stop() { + @Override + public synchronized boolean stop() { if (timer == null) { return false; } @@ -634,9 +655,12 @@ public class TestGLCanvasAWTActionDeadlock02AWT extends UITestCase { return true; } - public final synchronized boolean isPaused() { return false; } - public synchronized boolean resume() { return false; } - public synchronized boolean pause() { return false; } + @Override + public final synchronized boolean isPaused() { return false; } + @Override + public synchronized boolean resume() { return false; } + @Override + public synchronized boolean pause() { return false; } } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/ElektronenMultiplizierer.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/ElektronenMultiplizierer.java index 1956e6fb7..88e51db8b 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/ElektronenMultiplizierer.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/ElektronenMultiplizierer.java @@ -43,6 +43,7 @@ import com.jogamp.opengl.GLUniformData; import com.jogamp.opengl.fixedfunc.GLMatrixFunc; import com.jogamp.common.nio.Buffers; +import com.jogamp.common.os.Clock; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.opengl.GLWindow; @@ -158,6 +159,7 @@ public class ElektronenMultiplizierer implements GLEventListener { public boolean usesFullScreenMode() { return mUsesFullScreenMode; } class TimeShiftKeys extends KeyAdapter { + @Override public void keyPressed(final KeyEvent e) { if(KeyEvent.VK_RIGHT == e.getKeyCode()) { skipFrames(120); @@ -223,6 +225,7 @@ public class ElektronenMultiplizierer implements GLEventListener { return mCaps; } + @Override public void init(final GLAutoDrawable drawable) { if(drawable instanceof GLWindow) { final GLWindow glw = (GLWindow) drawable; @@ -308,16 +311,17 @@ public class ElektronenMultiplizierer implements GLEventListener { // if NO music is used sync to mainloop start ... // (add up current time due to possible turned back start time by skip frames) - mFrameSkipAverageFramerateTimeStart += System.nanoTime(); + mFrameSkipAverageFramerateTimeStart += Clock.currentNanos(); // mBaseMusic = new BaseMusic(BaseGlobalEnvironment.getInstance().getMusicFileName()); // mBaseMusic.init(); // mBaseMusic.play(); } + @Override public void display(final GLAutoDrawable drawable) { if (wantsFrameSkip()) { - mFrameSkipAverageFramerateTimeEnd = System.nanoTime(); + mFrameSkipAverageFramerateTimeEnd = Clock.currentNanos(); final double tDesiredFrameRate = getDesiredFramerate(); final double tSingleFrameTime = 1000000000.0f/tDesiredFrameRate; final double tElapsedTime = mFrameSkipAverageFramerateTimeEnd - mFrameSkipAverageFramerateTimeStart; @@ -342,7 +346,7 @@ public class ElektronenMultiplizierer implements GLEventListener { // //if music IS used sync to first second of music ... // if (BaseRoutineRuntime.getInstance().getBaseMusic().getPositionInMilliseconds()>0 && !mMusicSyncStartTimeInitialized) { // BaseLogging.getInstance().info("Synching to BaseMusic ..."); -// mFrameSkipAverageFramerateTimeStart = (long)(System.nanoTime()-((double)BaseRoutineRuntime.getInstance().getBaseMusic().getPositionInMilliseconds()*1000000.0d)); +// mFrameSkipAverageFramerateTimeStart = (long)(Clock.currentNanos()-((double)BaseRoutineRuntime.getInstance().getBaseMusic().getPositionInMilliseconds()*1000000.0d)); // mMusicSyncStartTimeInitialized = true; // } // } @@ -470,6 +474,7 @@ public class ElektronenMultiplizierer implements GLEventListener { mFrameCounter++; } + @Override public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { final GL2ES2 gl = drawable.getGL().getGL2ES2(); @@ -493,6 +498,7 @@ public class ElektronenMultiplizierer implements GLEventListener { gl.glViewport(0, 0, width, height); } + @Override public void dispose(final GLAutoDrawable drawable) { final GL2ES2 gl = drawable.getGL().getGL2ES2(); gl.glDeleteFramebuffers(1, new int[] { mFrameBufferObjectID }, 0); |