Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Unified Diff: chrome/test/data/perf/frame_rate/head.js

Issue 8052016: Adding support for animated pages in the FrameRate tests (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/perf/frame_rate/head.js
===================================================================
--- chrome/test/data/perf/frame_rate/head.js (revision 102775)
+++ chrome/test/data/perf/frame_rate/head.js (working copy)
@@ -38,6 +38,7 @@
var __running_all = false;
var __old_title = "";
var __raf_is_live = false;
+var __platform_raf;
var __raf;
var __t_last;
@@ -52,14 +53,16 @@
var __recording = [];
var __advance_gesture;
-var __gestures = {
- none: [
+var __animation = function() {return false;}
+
+var __gesture_library = {
+ init: [
{"time_ms":1, "y":0},
- {"time_ms":5000, "y":0}
+ {"time_ms":5, "y":10}
],
- steady: [
+ stationary: [
{"time_ms":1, "y":0},
- {"time_ms":5, "y":10}
+ {"time_ms":5000, "y":0}
],
reading: [
{"time_ms":1, "y":0},
@@ -161,6 +164,36 @@
],
};
+// Creat an alternate version of a gesture that
+// runs without using requestAnimationFrame
+function __gesture_disable_raf(gesture) {
+ // clone the gesture
+ var new_gesture = JSON.parse(JSON.stringify(gesture));
+ new_gesture[0].raf = false;
+ return new_gesture;
+}
+
+// Stretch the duration of a gesture by a given factor
+function __gesture_stretch(gesture, stretch_factor) {
+ // clone the gesture
+ var new_gesture = JSON.parse(JSON.stringify(gesture));
+ for (var i = 0; i < new_gesture.length; ++i) {
+ new_gesture[i].time_ms *= stretch_factor;
+ }
+ return new_gesture;
+}
+
+
+// Gesture set to use for testing, initialized with default gesture set.
+// Redefine in test file to use a different set of gestures.
+var __gestures = {
+ none: __gesture_library["stationary"],
+ steady: __gesture_library["init"],
+ reading: __gesture_library["reading"],
+ mouse_wheel: __gesture_library["mouse_wheel"],
+ mac_fling: __gesture_library["mac_fling"],
+};
+
function __init_stats() {
__t_last = undefined;
__t_est = undefined;
@@ -170,6 +203,36 @@
}
__init_stats();
+function __init_raf(use_raf) {
+ if (use_raf) {
+ if (!__platform_raf) {
+ if ("requestAnimationFrame" in window)
nduca 2011/10/10 23:11:19 Nice!
+ __platform_raf = requestAnimationFrame;
+ else if ("webkitRequestAnimationFrame" in window)
+ __platform_raf = webkitRequestAnimationFrame;
+ else if ("mozRequestAnimationFrame" in window)
+ __platform_raf = mozRequestAnimationFrame;
+ else if ("oRequestAnimationFrame" in window)
+ __platform_raf = oRequestAnimationFrame;
+ else if ("msRequestAnimationFrame" in window)
+ __platform_raf = msRequestAnimationFrame;
+ else
+ // No raf implementation available, fake it with 16ms timeouts
+ __platform_raf = function(callback, element) {
+ setTimeout(callback, 16);
+ }
+ }
+ __raf = __platform_raf;
+ }
+ else {
+ // raf disabled: Using a 0ms timeout to render as fast as possible
+ __raf = function(callback, element) {
+ setTimeout(callback,0);
+ }
+ }
+}
+__init_raf(true);
nduca 2011/10/10 23:11:19 Init raf here? Really?
+
function __calc_results() {
var M = __t_est_total / __t_count;
var X = __t_est_squared_total / __t_count;
@@ -269,6 +332,7 @@
// Returns true if a gesture movement occured.
function __create_gesture_function(gestures) {
var i0 = 0;
+ var use_raf = true;
nduca 2011/10/10 23:11:19 Did you consider doing this feature outside of the
return function() {
if (i0 >= gestures.length) {
__stop();
@@ -278,13 +342,24 @@
if (time_cur <= gestures[i0].time_ms)
return false;
- // Skip any keyframes that we missed
- for (i0; i0 < gestures.length && gestures[i0].time_ms < time_cur; ++i0);
+ // Skip any keyframes that we missed and track changes to raf state
+ var new_use_raf = use_raf;
+ for (i0; i0 < gestures.length && gestures[i0].time_ms < time_cur; ++i0) {
+ if ("raf" in gestures[i0]) {
+ new_use_raf = gestures[i0].raf;
+ }
+ }
// This loop overshoots by 1, so move back in time by 1
i0--;
var i1 = i0 + 1;
+ // Toggle usage of request animantion frame
nduca 2011/10/10 23:11:19 I'm struggling to understand this code... and the
+ if (new_use_raf != use_raf){
+ use_raf = new_use_raf;
+ __init_raf(use_raf);
+ }
+
if (i1 < gestures.length) {
// If i1 exists, interpolate between i0 and i1 y based on time_cur -
// gestures[i0].time_ms
@@ -328,23 +403,21 @@
}
function __sched_update() {
- if (!__raf) {
- if ("webkitRequestAnimationFrame" in window)
- __raf = webkitRequestAnimationFrame;
- else if ("mozRequestAnimationFrame" in window)
- __raf = mozRequestAnimationFrame;
- }
__raf(function() {
__raf_is_live = true;
+ // In case __raf falls back to using setTimeout, we must schedule the next
+ // update before rendering the current update to help maintain the
+ // regularity of update intervals.
+ __sched_update();
if (__running) {
- // Only update the FPS if a gesture movement occurs. Otherwise, the frame
- // rate average becomes inaccurate after any pause.
- if (__advance_gesture())
+ // Only update the FPS if a gesture movement or animation occurs.
+ // Otherwise, the frame rate average becomes inaccurate after any pause.
+ var animated = __animation();
nduca 2011/10/10 23:11:19 Is there any merit to this rather than just having
+ if (__advance_gesture() || animated)
__update_fps();
else
__t_last = new Date().getTime();
}
- __sched_update();
}, document.body);
}
@@ -359,10 +432,19 @@
function __start(gesture_function) {
if (__running)
return;
+
+ // By default, all gestures start with raf enabled
+ __init_raf(true);
nduca 2011/10/10 23:11:19 We init_raf at the global scope too? Is that one r
+
// Attempt to create a gesture function from a string name.
if (typeof gesture_function == "string") {
- if (!__gestures[gesture_function])
- throw new Error("Unrecognized gesture name");
+ if (!__gestures[gesture_function]) {
+ if (!__gesture_library[gesture_function])
+ throw new Error("Unrecognized gesture name");
+ else
+ gesture_function = __create_repeating_gesture_function(
+ __gesture_library[gesture_function]);
+ }
else
gesture_function = __create_repeating_gesture_function(
__gestures[gesture_function]);
@@ -392,8 +474,8 @@
__queued_gesture_functions.push(gesture);
}
__running_all = true;
- // Run steady gesture once to cache the webpage layout for subsequent tests.
- __start("steady");
+ // Run init gesture once to cache the webpage layout for subsequent tests.
+ __start("init");
nduca 2011/10/10 23:11:19 Not that this is your fault, but since we're here,
}
function __stop() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698