OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Perform various "gestures" and calculate average frame rate. | 6 * @fileoverview Perform various "gestures" and calculate average frame rate. |
7 * "Gestures" are recorded scrolling behaviors in terms of time (ms) and | 7 * "Gestures" are recorded scrolling behaviors in terms of time (ms) and |
8 * absolute positions. | 8 * absolute positions. |
9 * | 9 * |
10 * How to run a single gesture: | 10 * How to run a single gesture: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 var __t_est_total; | 45 var __t_est_total; |
46 var __t_est_squared_total; | 46 var __t_est_squared_total; |
47 var __t_count; | 47 var __t_count; |
48 var __t_start; | 48 var __t_start; |
49 | 49 |
50 var __queued_gesture_functions; | 50 var __queued_gesture_functions; |
51 var __results; | 51 var __results; |
52 | 52 |
53 var __recording = []; | 53 var __recording = []; |
54 var __advance_gesture; | 54 var __advance_gesture; |
55 var __animation = function() {return false;} | |
55 var __gestures = { | 56 var __gestures = { |
56 none: [ | 57 none: [ |
57 {"time_ms":1, "y":0}, | 58 {"time_ms":1, "y":0}, |
58 {"time_ms":5000, "y":0} | 59 {"time_ms":5000, "y":0} |
59 ], | 60 ], |
60 steady: [ | 61 steady: [ |
61 {"time_ms":1, "y":0}, | 62 {"time_ms":1, "y":0}, |
62 {"time_ms":5, "y":10} | 63 {"time_ms":5, "y":10} |
63 ], | 64 ], |
64 reading: [ | 65 reading: [ |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 {"time_ms":911, "y":1273}, | 155 {"time_ms":911, "y":1273}, |
155 {"time_ms":941, "y":1275}, | 156 {"time_ms":941, "y":1275}, |
156 {"time_ms":958, "y":1282}, | 157 {"time_ms":958, "y":1282}, |
157 {"time_ms":976, "y":1288}, | 158 {"time_ms":976, "y":1288}, |
158 {"time_ms":993, "y":1291}, | 159 {"time_ms":993, "y":1291}, |
159 {"time_ms":1022, "y":1294}, | 160 {"time_ms":1022, "y":1294}, |
160 {"time_ms":1055, "y":1302} | 161 {"time_ms":1055, "y":1302} |
161 ], | 162 ], |
162 }; | 163 }; |
163 | 164 |
165 var __builtin_gestures = { | |
166 init: [ | |
167 {"time_ms":1, "y":0}, | |
168 {"time_ms":5, "y":10} | |
Justin Novosad
2011/09/27 19:56:13
factored this out of __gestures so that we don't h
| |
169 ], | |
170 }; | |
171 | |
164 function __init_stats() { | 172 function __init_stats() { |
165 __t_last = undefined; | 173 __t_last = undefined; |
166 __t_est = undefined; | 174 __t_est = undefined; |
167 __t_est_total = 0; | 175 __t_est_total = 0; |
168 __t_est_squared_total = 0; | 176 __t_est_squared_total = 0; |
169 __t_count = 0; | 177 __t_count = 0; |
170 } | 178 } |
171 __init_stats(); | 179 __init_stats(); |
172 | 180 |
173 function __calc_results() { | 181 function __calc_results() { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 function __sched_update() { | 338 function __sched_update() { |
331 if (!__raf) { | 339 if (!__raf) { |
332 if ("webkitRequestAnimationFrame" in window) | 340 if ("webkitRequestAnimationFrame" in window) |
333 __raf = webkitRequestAnimationFrame; | 341 __raf = webkitRequestAnimationFrame; |
334 else if ("mozRequestAnimationFrame" in window) | 342 else if ("mozRequestAnimationFrame" in window) |
335 __raf = mozRequestAnimationFrame; | 343 __raf = mozRequestAnimationFrame; |
336 } | 344 } |
337 __raf(function() { | 345 __raf(function() { |
338 __raf_is_live = true; | 346 __raf_is_live = true; |
339 if (__running) { | 347 if (__running) { |
340 // Only update the FPS if a gesture movement occurs. Otherwise, the frame | 348 // Only update the FPS if a gesture movement or animation occurs. |
341 // rate average becomes inaccurate after any pause. | 349 // Otherwise, the frame rate average becomes inaccurate after any pause. |
342 if (__advance_gesture()) | 350 var animated = __animation(); |
351 if (__advance_gesture() || animated) | |
343 __update_fps(); | 352 __update_fps(); |
344 else | 353 else |
345 __t_last = new Date().getTime(); | 354 __t_last = new Date().getTime(); |
346 } | 355 } |
347 __sched_update(); | 356 __sched_update(); |
348 }, document.body); | 357 }, document.body); |
349 } | 358 } |
350 | 359 |
351 function __start_recording() { | 360 function __start_recording() { |
352 __start(__advance_gesture_recording); | 361 __start(__advance_gesture_recording); |
353 } | 362 } |
354 | 363 |
355 function __make_body_composited() { | 364 function __make_body_composited() { |
356 document.body.style.webkitTransform = "translateZ(0)"; | 365 document.body.style.webkitTransform = "translateZ(0)"; |
357 } | 366 } |
358 | 367 |
359 function __start(gesture_function) { | 368 function __start(gesture_function) { |
360 if (__running) | 369 if (__running) |
361 return; | 370 return; |
362 // Attempt to create a gesture function from a string name. | 371 // Attempt to create a gesture function from a string name. |
363 if (typeof gesture_function == "string") { | 372 if (typeof gesture_function == "string") { |
364 if (!__gestures[gesture_function]) | 373 if (!__gestures[gesture_function]) { |
365 throw new Error("Unrecognized gesture name"); | 374 if (!__builtin_gestures[gesture_function]) |
375 throw new Error("Unrecognized gesture name"); | |
376 else | |
377 gesture_function = __create_repeating_gesture_function( | |
378 __builtin_gestures[gesture_function]); | |
379 } | |
366 else | 380 else |
367 gesture_function = __create_repeating_gesture_function( | 381 gesture_function = __create_repeating_gesture_function( |
368 __gestures[gesture_function]); | 382 __gestures[gesture_function]); |
369 } | 383 } |
370 else if (typeof gesture_function != "function") | 384 else if (typeof gesture_function != "function") |
371 throw new Error("Argument is not a function or gesture name"); | 385 throw new Error("Argument is not a function or gesture name"); |
372 | 386 |
373 __old_title = document.title; | 387 __old_title = document.title; |
374 __advance_gesture = gesture_function; | 388 __advance_gesture = gesture_function; |
375 __t_start = new Date().getTime(); | 389 __t_start = new Date().getTime(); |
376 __running = true; | 390 __running = true; |
377 if (!__raf_is_live) { | 391 if (!__raf_is_live) { |
378 __sched_update(); | 392 __sched_update(); |
379 } | 393 } |
380 } | 394 } |
381 | 395 |
382 function __start_all() { | 396 function __start_all() { |
383 __queued_gesture_functions = []; | 397 __queued_gesture_functions = []; |
384 __results = { | 398 __results = { |
385 gestures: [], | 399 gestures: [], |
386 means: [], | 400 means: [], |
387 sigmas: [], | 401 sigmas: [], |
388 }; | 402 }; |
389 | 403 |
390 for (var gesture in __gestures) { | 404 for (var gesture in __gestures) { |
391 __results.gestures.push(gesture); | 405 __results.gestures.push(gesture); |
392 __queued_gesture_functions.push(gesture); | 406 __queued_gesture_functions.push(gesture); |
393 } | 407 } |
394 __running_all = true; | 408 __running_all = true; |
395 // Run steady gesture once to cache the webpage layout for subsequent tests. | 409 // Run init gesture once to cache the webpage layout for subsequent tests. |
396 __start("steady"); | 410 __start("init"); |
397 } | 411 } |
398 | 412 |
399 function __stop() { | 413 function __stop() { |
400 __running = false; | 414 __running = false; |
401 document.title = __old_title; | 415 document.title = __old_title; |
402 window.__scrolledTo = undefined; | 416 window.__scrolledTo = undefined; |
403 | 417 |
404 if (__running_all) { | 418 if (__running_all) { |
405 var results = __calc_results(); | 419 var results = __calc_results(); |
406 __results.means.push(results.mean); | 420 __results.means.push(results.mean); |
(...skipping 13 matching lines...) Expand all Loading... | |
420 __running = false; | 434 __running = false; |
421 __running_all = false; | 435 __running_all = false; |
422 document.title = __old_title; | 436 document.title = __old_title; |
423 document.body.scrollTop = 0; | 437 document.body.scrollTop = 0; |
424 __init_stats(); | 438 __init_stats(); |
425 } | 439 } |
426 | 440 |
427 function __force_compositor() { | 441 function __force_compositor() { |
428 document.body.style.webkitTransform = "translateZ(0)"; | 442 document.body.style.webkitTransform = "translateZ(0)"; |
429 } | 443 } |
OLD | NEW |