From ba8dd960e8c0c56013615c4ce4671f0c771c4283 Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Fri, 23 Mar 2012 11:58:03 -0400 Subject: [PATCH] Bug 738556 - Optimize frame time measurement and checkerboard time measurement in robocop a little. r=jmaher --- .../mobile/robocop/FennecNativeDriver.java.in | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/build/mobile/robocop/FennecNativeDriver.java.in b/build/mobile/robocop/FennecNativeDriver.java.in index 8cef7b0e3a54..dea231f04d82 100644 --- a/build/mobile/robocop/FennecNativeDriver.java.in +++ b/build/mobile/robocop/FennecNativeDriver.java.in @@ -70,6 +70,8 @@ import org.json.*; import com.jayway.android.robotium.solo.Solo; public class FennecNativeDriver implements Driver { + private static final int FRAME_TIME_THRESHOLD = 17; // allow 17ms per frame (~60fps) + // Map of IDs to element names. private HashMap mLocators = null; private Activity mActivity; @@ -225,21 +227,15 @@ public class FennecNativeDriver implements Driver { public int stopFrameRecording() { Class [] parameters = new Class[1]; parameters[0] = null; - List frames; try { Object [] params = null; - frames = (List)_stopFrameRecording.invoke(null, params); - Object [] framearray = frames.toArray(); - Long last = new Long(0); - Long threshold = new Long(17); + List frames = (List)_stopFrameRecording.invoke(null, params); int numDelays = 0; - for (int i=0; i < framearray.length; i++) { - Long val = (Long)framearray[i]; - if ((val - last) > threshold) { + for (int i = 1; i < frames.size(); i++) { + if (frames.get(i) - frames.get(i-1) > FRAME_TIME_THRESHOLD) { numDelays++; } - last = val; } return numDelays; } catch (IllegalAccessException e) { @@ -265,18 +261,15 @@ public class FennecNativeDriver implements Driver { public float stopCheckerboardRecording() { Class [] parameters = new Class[1]; parameters[0] = null; - List checkerboard; try { Object [] params = null; - checkerboard = (List)_stopCheckerboardRecording.invoke(null, params); - Object [] amountarray = checkerboard.toArray(); - double completeness = 0; - for (Object obj : amountarray) { - float val = (Float)obj; - completeness += (1.0 - (double)val) / (double)amountarray.length; + List checkerboard = (List)_stopCheckerboardRecording.invoke(null, params); + float completeness = 0; + for (float val : checkerboard) { + completeness += (1.0f - val); } - return (float)completeness; + return completeness / (float)checkerboard.size(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) {