diff options
author | Sven Gothel <[email protected]> | 2012-02-23 16:41:47 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-02-23 16:41:47 +0100 |
commit | 5b05aa83f57b7492b2705529033a7eaa09cf4463 (patch) | |
tree | 788e7a5d16ebce1a984f20f2b94faf96d5c62126 /src/newt/classes/jogamp | |
parent | 352013de5564013fe2b6444e6469ef2886f1adb9 (diff) |
NEWT: Add time costs in DEBUG mode. NEWT/XRandR: Reuse XRRScreenConfiguration to reduce perf hit on Linux ARM Omap4.
On Linux ARM Omap4, we experience a performance hit when using XRandR:
1st call of XRRSizes: ~ 1668 ms
Each call of XRRGetScreenInfo: ~ 1109 ms
Even though XRRGetScreenInfo is cached in NEWT's X11Screen initialization,
overall init time is ~2s, far too expensive.
Diffstat (limited to 'src/newt/classes/jogamp')
-rw-r--r-- | src/newt/classes/jogamp/newt/ScreenImpl.java | 54 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/WindowImpl.java | 9 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/x11/X11Screen.java | 101 |
3 files changed, 101 insertions, 63 deletions
diff --git a/src/newt/classes/jogamp/newt/ScreenImpl.java b/src/newt/classes/jogamp/newt/ScreenImpl.java index a6bd960b7..6c78a9653 100644 --- a/src/newt/classes/jogamp/newt/ScreenImpl.java +++ b/src/newt/classes/jogamp/newt/ScreenImpl.java @@ -74,7 +74,7 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { protected static volatile boolean usrSizeQueried = false; private static AccessControlContext localACC = AccessController.getContext(); private ArrayList<ScreenModeListener> referencedScreenModeListener = new ArrayList<ScreenModeListener>(); - long t0; // creationTime + private long tCreated; // creationTime static { AccessController.doPrivileged(new PrivilegedAction<Object>() { @@ -177,21 +177,26 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { public synchronized final void createNative() throws NativeWindowException - { + { if(null == aScreen) { if(DEBUG) { + tCreated = System.nanoTime(); System.err.println("Screen.createNative() START ("+DisplayImpl.getThreadName()+", "+this+")"); + } else { + tCreated = 0; } - t0 = System.currentTimeMillis(); + display.addReference(); + createNativeImpl(); if(null == aScreen) { throw new NativeWindowException("Screen.createNative() failed to instanciate an AbstractGraphicsScreen"); } + initScreenModeStatus(); updateVirtualScreenOriginAndSize(); if(DEBUG) { - System.err.println("Screen.createNative() END ("+DisplayImpl.getThreadName()+", "+this+")"); + System.err.println("Screen.createNative() END ("+DisplayImpl.getThreadName()+", "+this+"), total "+ (System.nanoTime()-tCreated)/1e6 +"ms"); } synchronized(screenList) { screensActive++; @@ -361,7 +366,7 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { ScreenMode smU = getScreenModesOrig().get(screenMode); // unify via value hash if(smU.equals(smC)) { if(DEBUG) { - System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): 0.0 is-current (skip) "+smU+" == "+smC); + System.err.println("Screen.setCurrentScreenMode ("+(System.nanoTime()-tCreated)+"): 0.0 is-current (skip) "+smU+" == "+smC); } return true; } @@ -372,32 +377,26 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { boolean success; sms.lock(); try { - long t0=0, t1=0; + final long tStart; if(DEBUG) { - System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): 0.0 "+smU); - t0 = System.currentTimeMillis(); - } - + tStart = System.nanoTime(); + } else { + tStart = 0; + } + sms.fireScreenModeChangeNotify(smU); - if(DEBUG) { - System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): 0.1 "+smU); - t1 = System.currentTimeMillis(); + System.err.println("Screen.setCurrentScreenMode ("+(System.nanoTime()-tStart)/1e6+"ms): fireScreenModeChangeNotify() "+smU); } - success = setCurrentScreenModeImpl(smU); - + success = setCurrentScreenModeImpl(smU); if(DEBUG) { - t1 = System.currentTimeMillis() - t1; - System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): X.0 "+smU+", success: "+success); + System.err.println("Screen.setCurrentScreenMode ("+(System.nanoTime()-tStart)/1e6+"ms): setCurrentScreenModeImpl() "+smU+", success: "+success); } - sms.fireScreenModeChanged(smU, success); - + sms.fireScreenModeChanged(smU, success); if(DEBUG) { - t0 = System.currentTimeMillis() - t0; - System.err.println("Screen.setCurrentScreenMode ("+(System.currentTimeMillis()-t0)+"): X.X "+smU+", success: "+success+ - " - dt0 "+t0+"ms, dt1 "+t1+"ms"); + System.err.println("Screen.setCurrentScreenMode ("+(System.nanoTime()-tStart)/1e6+"ms): X.X "+smU+", success: "+success); } } finally { sms.unlock(); @@ -514,6 +513,14 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { } private ScreenModeStatus initScreenModeStatus() { + long t0; + if(DEBUG) { + t0 = System.nanoTime(); + System.err.println("Screen.initScreenModeStatus() START ("+DisplayImpl.getThreadName()+", "+this+")"); + } else { + t0 = 0; + } + ScreenModeStatus sms; ScreenModeStatus.lockScreenModeStatus(); try { @@ -545,6 +552,9 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener { } finally { ScreenModeStatus.unlockScreenModeStatus(); } + if(DEBUG) { + System.err.println("Screen.initScreenModeStatus() END dt "+ (System.nanoTime()-t0)/1e6 +"ms"); + } return sms; } diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 9d15ae8c7..62e42c185 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -273,9 +273,14 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } private boolean createNative() { + long tStart; if(DEBUG_IMPLEMENTATION) { + tStart = System.nanoTime(); System.err.println("Window.createNative() START ("+getThreadName()+", "+this+")"); - } + } else { + tStart = 0; + } + if( null != parentWindow && NativeSurface.LOCK_SURFACE_NOT_READY >= parentWindow.lockSurface() ) { throw new NativeWindowException("Parent surface lock: not ready: "+parentWindow); @@ -322,7 +327,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+")"); + System.err.println("Window.createNative() END ("+getThreadName()+", "+this+") total "+ (System.nanoTime()-tStart)/1e6 +"ms"); } return isNativeValid() ; } diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java b/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java index ed5ebc04e..9dbac5d7f 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java +++ b/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java @@ -175,31 +175,42 @@ public class X11Screen extends ScreenImpl { protected ScreenMode getCurrentScreenModeImpl() { return runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<ScreenMode>() { public ScreenMode run(long dpy) { - int resNumber = getNumScreenModeResolutions0(dpy, screen_idx); - if(0==resNumber) { + long screenConfigHandle = getScreenConfiguration0(dpy, screen_idx); + if(0 == screenConfigHandle) { return null; } - int resIdx = getCurrentScreenResolutionIndex0(dpy, screen_idx); - if(0>resIdx) { - return null; - } - if(resIdx>=resNumber) { - throw new RuntimeException("Invalid resolution index: ! "+resIdx+" < "+resNumber); - } - int[] res = getScreenModeResolution0(dpy, screen_idx, resIdx); - if(null==res || 0==res.length) { - return null; - } - if(0>=res[0] || 0>=res[1]) { - throw new InternalError("invalid resolution: "+res[0]+"x"+res[1]+" for res idx "+resIdx+"/"+resNumber); - } - int rate = getCurrentScreenRate0(dpy, screen_idx); - if(0>rate) { - return null; - } - int rot = getCurrentScreenRotation0(dpy, screen_idx); - if(0>rot) { - return null; + int[] res; + int rate, rot; + try { + int resNumber = getNumScreenModeResolutions0(dpy, screen_idx); + if(0==resNumber) { + return null; + } + + int resIdx = getCurrentScreenResolutionIndex0(screenConfigHandle); + if(0>resIdx) { + return null; + } + if(resIdx>=resNumber) { + throw new RuntimeException("Invalid resolution index: ! "+resIdx+" < "+resNumber); + } + res = getScreenModeResolution0(dpy, screen_idx, resIdx); + if(null==res || 0==res.length) { + return null; + } + if(0>=res[0] || 0>=res[1]) { + throw new InternalError("invalid resolution: "+res[0]+"x"+res[1]+" for res idx "+resIdx+"/"+resNumber); + } + rate = getCurrentScreenRate0(screenConfigHandle); + if(0>rate) { + return null; + } + rot = getCurrentScreenRotation0(screenConfigHandle); + if(0>rot) { + return null; + } + } finally { + freeScreenConfiguration0(screenConfigHandle); } int[] props = new int[ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL]; int i = 0; @@ -226,21 +237,30 @@ public class X11Screen extends ScreenImpl { boolean done = runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Boolean>() { public Boolean run(long dpy) { boolean done = false; - int resNumber = getNumScreenModeResolutions0(dpy, screen_idx); - int resIdx = getScreenModesIdx2NativeIdx().get(screenModeIdx); - if(0>resIdx || resIdx>=resNumber) { - throw new RuntimeException("Invalid resolution index: ! 0 < "+resIdx+" < "+resNumber+", screenMode["+screenModeIdx+"] "+screenMode); + long screenConfigHandle = getScreenConfiguration0(dpy, screen_idx); + if(0 == screenConfigHandle) { + return Boolean.valueOf(done); } - - final int f = screenMode.getMonitorMode().getRefreshRate(); - final int r = screenMode.getRotation(); - if( setCurrentScreenModeStart0(dpy, screen_idx, resIdx, f, r) ) { - while(!done && System.currentTimeMillis()-t0 < SCREEN_MODE_CHANGE_TIMEOUT) { - done = setCurrentScreenModePollEnd0(dpy, screen_idx, resIdx, f, r); - if(!done) { - try { Thread.sleep(10); } catch (InterruptedException e) { } + try { + int resNumber = getNumScreenModeResolutions0(dpy, screen_idx); + int resIdx = getScreenModesIdx2NativeIdx().get(screenModeIdx); + if(0>resIdx || resIdx>=resNumber) { + throw new RuntimeException("Invalid resolution index: ! 0 < "+resIdx+" < "+resNumber+", screenMode["+screenModeIdx+"] "+screenMode); + } + + final int f = screenMode.getMonitorMode().getRefreshRate(); + final int r = screenMode.getRotation(); + + if( setCurrentScreenModeStart0(dpy, screen_idx, screenConfigHandle, resIdx, f, r) ) { + while(!done && System.currentTimeMillis()-t0 < SCREEN_MODE_CHANGE_TIMEOUT) { + done = setCurrentScreenModePollEnd0(dpy, screen_idx, resIdx, f, r); + if(!done) { + try { Thread.sleep(10); } catch (InterruptedException e) { } + } } } + } finally { + freeScreenConfiguration0(screenConfigHandle); } return Boolean.valueOf(done); } @@ -321,11 +341,14 @@ public class X11Screen extends ScreenImpl { private static native int[] getScreenModeRates0(long display, int screen_index, int mode_index); - private static native int getCurrentScreenResolutionIndex0(long display, int screen_index); - private static native int getCurrentScreenRate0(long display, int screen_index); - private static native int getCurrentScreenRotation0(long display, int screen_index); + private static native long getScreenConfiguration0(long display, int screen_index); + private static native void freeScreenConfiguration0(long screenConfiguration); + + private static native int getCurrentScreenResolutionIndex0(long screenConfiguration); + private static native int getCurrentScreenRate0(long screenConfiguration); + private static native int getCurrentScreenRotation0(long screenConfiguration); /** needs own Display connection for XRANDR event handling */ - private static native boolean setCurrentScreenModeStart0(long display, int screen_index, int mode_index, int freq, int rot); + private static native boolean setCurrentScreenModeStart0(long display, int screen_index, long screenConfiguration, int mode_index, int freq, int rot); private static native boolean setCurrentScreenModePollEnd0(long display, int screen_index, int mode_index, int freq, int rot); } |