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

Side by Side 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, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 16 matching lines...) Expand all
27 * 5) Copy the output from "JSON.stringify(__recording)" in the console. 27 * 5) Copy the output from "JSON.stringify(__recording)" in the console.
28 * 6) Paste the output in this file as a new member of __gestures. 28 * 6) Paste the output in this file as a new member of __gestures.
29 * 7) Copy the formatting from other gestures. 29 * 7) Copy the formatting from other gestures.
30 * Example: 30 * Example:
31 * new_gesture_name: [ 31 * new_gesture_name: [
32 * {"time_ms":1, "y":0}, 32 * {"time_ms":1, "y":0},
33 * ... pasted output ... 33 * ... pasted output ...
34 * ], 34 * ],
35 */ 35 */
36 36
37 var __initialized = true;
37 var __running = false; 38 var __running = false;
38 var __running_all = false; 39 var __running_all = false;
39 var __old_title = ""; 40 var __old_title = "";
40 var __raf_is_live = false; 41 var __raf_is_live = false;
41 var __raf; 42 var __raf;
42 43
43 var __t_last; 44 var __t_last;
44 var __t_est; 45 var __t_est;
45 var __t_est_total; 46 var __t_est_total;
46 var __t_est_squared_total; 47 var __t_est_squared_total;
47 var __t_count; 48 var __t_count;
48 var __t_start; 49 var __t_start;
49 50
50 var __queued_gesture_functions; 51 var __queued_gesture_functions;
51 var __results; 52 var __results;
52 53
53 var __recording = []; 54 var __recording = [];
54 var __advance_gesture; 55 var __advance_gesture;
55 var __gestures = { 56 var __animation = false;
nduca 2011/10/14 21:01:46 Add comment explaining what it does? Just declare
56 none: [ 57
58 var __gesture_library = {
59 init: [
60 {"time_ms":1, "y":0},
61 {"time_ms":5, "y":10}
62 ],
63 stationary: [
57 {"time_ms":1, "y":0}, 64 {"time_ms":1, "y":0},
58 {"time_ms":5000, "y":0} 65 {"time_ms":5000, "y":0}
59 ], 66 ],
60 steady: [
61 {"time_ms":1, "y":0},
62 {"time_ms":5, "y":10}
63 ],
64 reading: [ 67 reading: [
65 {"time_ms":1, "y":0}, 68 {"time_ms":1, "y":0},
66 {"time_ms":842, "y":40}, 69 {"time_ms":842, "y":40},
67 {"time_ms":858, "y":67}, 70 {"time_ms":858, "y":67},
68 {"time_ms":874, "y":94}, 71 {"time_ms":874, "y":94},
69 {"time_ms":890, "y":149}, 72 {"time_ms":890, "y":149},
70 {"time_ms":907, "y":203}, 73 {"time_ms":907, "y":203},
71 {"time_ms":923, "y":257}, 74 {"time_ms":923, "y":257},
72 {"time_ms":939, "y":311}, 75 {"time_ms":939, "y":311},
73 {"time_ms":955, "y":393}, 76 {"time_ms":955, "y":393},
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 {"time_ms":911, "y":1273}, 157 {"time_ms":911, "y":1273},
155 {"time_ms":941, "y":1275}, 158 {"time_ms":941, "y":1275},
156 {"time_ms":958, "y":1282}, 159 {"time_ms":958, "y":1282},
157 {"time_ms":976, "y":1288}, 160 {"time_ms":976, "y":1288},
158 {"time_ms":993, "y":1291}, 161 {"time_ms":993, "y":1291},
159 {"time_ms":1022, "y":1294}, 162 {"time_ms":1022, "y":1294},
160 {"time_ms":1055, "y":1302} 163 {"time_ms":1055, "y":1302}
161 ], 164 ],
162 }; 165 };
163 166
167 // Stretch the duration of a gesture by a given factor
168 function __gesture_stretch(gesture, stretch_factor) {
169 // clone the gesture
170 var new_gesture = JSON.parse(JSON.stringify(gesture));
171 for (var i = 0; i < new_gesture.length; ++i) {
172 new_gesture[i].time_ms *= stretch_factor;
173 }
174 return new_gesture;
175 }
176
177 // Gesture set to use for testing, initialized with default gesture set.
178 // Redefine in test file to use a different set of gestures.
179 var __gestures = {
180 none: __gesture_library["stationary"],
181 steady: __gesture_library["init"],
182 reading: __gesture_library["reading"],
183 mouse_wheel: __gesture_library["mouse_wheel"],
184 mac_fling: __gesture_library["mac_fling"],
185 };
186
164 function __init_stats() { 187 function __init_stats() {
165 __t_last = undefined; 188 __t_last = undefined;
166 __t_est = undefined; 189 __t_est = undefined;
167 __t_est_total = 0; 190 __t_est_total = 0;
168 __t_est_squared_total = 0; 191 __t_est_squared_total = 0;
169 __t_count = 0; 192 __t_count = 0;
170 } 193 }
171 __init_stats(); 194 __init_stats();
172 195
196 function __init_raf(use_raf) {
197 if (use_raf) {
198 if ("requestAnimationFrame" in window)
199 __raf = requestAnimationFrame;
200 else if ("webkitRequestAnimationFrame" in window)
201 __raf = webkitRequestAnimationFrame;
202 else if ("mozRequestAnimationFrame" in window)
203 __raf = mozRequestAnimationFrame;
204 else if ("oRequestAnimationFrame" in window)
205 __raf = oRequestAnimationFrame;
206 else if ("msRequestAnimationFrame" in window)
207 __raf = msRequestAnimationFrame;
208 else
209 // No raf implementation available, fake it with 16ms timeouts
210 __raf = function(callback, element) {
211 setTimeout(callback, 16);
212 }
213 }
214 else
215 // raf disabled: render as fast as possible.
216 __raf = function(callback, element) {
217 setTimeout(callback, 0);
218 }
219 }
220 __init_raf(true);
221
173 function __calc_results() { 222 function __calc_results() {
174 var M = __t_est_total / __t_count; 223 var M = __t_est_total / __t_count;
175 var X = __t_est_squared_total / __t_count; 224 var X = __t_est_squared_total / __t_count;
176 var V = X - M * M; 225 var V = X - M * M;
177 var S = Math.sqrt(V); 226 var S = Math.sqrt(V);
178 227
179 var R = new Object(); 228 var R = new Object();
180 R.mean = 1000.0 / M; 229 R.mean = 1000.0 / M;
181 R.sigma = R.mean - 1000.0 / (M + S); 230 R.sigma = R.mean - 1000.0 / (M + S);
182 return R; 231 return R;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 y = gestures[i].y + dy; 370 y = gestures[i].y + dy;
322 gestures.push({ 371 gestures.push({
323 time_ms: gestures[i].time_ms + dtime_ms, 372 time_ms: gestures[i].time_ms + dtime_ms,
324 y: y, 373 y: y,
325 }); 374 });
326 } 375 }
327 return __create_gesture_function(gestures); 376 return __create_gesture_function(gestures);
328 } 377 }
329 378
330 function __sched_update() { 379 function __sched_update() {
331 if (!__raf) {
332 if ("webkitRequestAnimationFrame" in window)
333 __raf = webkitRequestAnimationFrame;
334 else if ("mozRequestAnimationFrame" in window)
335 __raf = mozRequestAnimationFrame;
336 }
337 __raf(function() { 380 __raf(function() {
338 __raf_is_live = true; 381 __raf_is_live = true;
382 // In case __raf falls back to using setTimeout, we must schedule the next
383 // update before rendering the current update to help maintain the
384 // regularity of update intervals.
385 __sched_update();
339 if (__running) { 386 if (__running) {
340 // Only update the FPS if a gesture movement occurs. Otherwise, the frame 387 // Only update the FPS if a gesture movement occurs. Otherwise, the frame
341 // rate average becomes inaccurate after any pause. 388 // rate average becomes inaccurate after any pause.
342 if (__advance_gesture()) 389 if (__advance_gesture())
343 __update_fps(); 390 __update_fps();
344 else 391 else
345 __t_last = new Date().getTime(); 392 __t_last = new Date().getTime();
346 } 393 }
347 __sched_update();
348 }, document.body); 394 }, document.body);
349 } 395 }
350 396
351 function __start_recording() { 397 function __start_recording() {
352 __start(__advance_gesture_recording); 398 __start(__advance_gesture_recording);
353 } 399 }
354 400
355 function __make_body_composited() { 401 function __make_body_composited() {
356 document.body.style.webkitTransform = "translateZ(0)"; 402 document.body.style.webkitTransform = "translateZ(0)";
357 } 403 }
358 404
359 function __start(gesture_function) { 405 function __start(gesture_function) {
360 if (__running) 406 if (__running)
361 return; 407 return;
362 // Attempt to create a gesture function from a string name. 408 // Attempt to create a gesture function from a string name.
363 if (typeof gesture_function == "string") { 409 if (typeof gesture_function == "string") {
364 if (!__gestures[gesture_function]) 410 if (!__gestures[gesture_function]) {
365 throw new Error("Unrecognized gesture name"); 411 if (!__gesture_library[gesture_function])
412 throw new Error("Unrecognized gesture name");
413 else
414 gesture_function = __create_repeating_gesture_function(
415 __gesture_library[gesture_function]);
416 }
366 else 417 else
367 gesture_function = __create_repeating_gesture_function( 418 gesture_function = __create_repeating_gesture_function(
368 __gestures[gesture_function]); 419 __gestures[gesture_function]);
369 } 420 }
370 else if (typeof gesture_function != "function") 421 else if (typeof gesture_function != "function")
371 throw new Error("Argument is not a function or gesture name"); 422 throw new Error("Argument is not a function or gesture name");
372 423
373 __old_title = document.title; 424 __old_title = document.title;
374 __advance_gesture = gesture_function; 425 __advance_gesture = gesture_function;
375 __t_start = new Date().getTime(); 426 __t_start = new Date().getTime();
376 __running = true; 427 __running = true;
377 if (!__raf_is_live) { 428 if (!__raf_is_live && !__animation) {
378 __sched_update(); 429 __sched_update();
379 } 430 }
380 } 431 }
381 432
382 function __start_all() { 433 function __start_all() {
383 __queued_gesture_functions = []; 434 __queued_gesture_functions = [];
384 __results = { 435 __results = {
385 gestures: [], 436 gestures: [],
386 means: [], 437 means: [],
387 sigmas: [], 438 sigmas: [],
388 }; 439 };
389 440
390 for (var gesture in __gestures) { 441 for (var gesture in __gestures) {
391 __results.gestures.push(gesture); 442 __results.gestures.push(gesture);
392 __queued_gesture_functions.push(gesture); 443 __queued_gesture_functions.push(gesture);
393 } 444 }
394 __running_all = true; 445 __running_all = true;
395 // Run steady gesture once to cache the webpage layout for subsequent tests. 446 // Run init gesture once to cache the webpage layout for subsequent tests.
396 __start("steady"); 447 __start("init");
397 } 448 }
nduca 2011/10/14 21:01:46 Did we file a bug to move the multiple-geseture st
398 449
399 function __stop() { 450 function __stop() {
400 __running = false; 451 __running = false;
401 document.title = __old_title; 452 document.title = __old_title;
402 window.__scrolledTo = undefined; 453 window.__scrolledTo = undefined;
403 454
404 if (__running_all) { 455 if (__running_all) {
405 var results = __calc_results(); 456 var results = __calc_results();
406 __results.means.push(results.mean); 457 __results.means.push(results.mean);
407 __results.sigmas.push(results.sigma); 458 __results.sigmas.push(results.sigma);
(...skipping 12 matching lines...) Expand all
420 __running = false; 471 __running = false;
421 __running_all = false; 472 __running_all = false;
422 document.title = __old_title; 473 document.title = __old_title;
423 document.body.scrollTop = 0; 474 document.body.scrollTop = 0;
424 __init_stats(); 475 __init_stats();
425 } 476 }
426 477
427 function __force_compositor() { 478 function __force_compositor() {
428 document.body.style.webkitTransform = "translateZ(0)"; 479 document.body.style.webkitTransform = "translateZ(0)";
429 } 480 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/perf/frame_rate/head_animation.js » ('j') | chrome/test/data/perf/frame_rate/head_animation.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698