- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / perf / frame_rate / head_animation.js
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
3 // found in the LICENSE file.
4
5 /**
6  * @fileoverview  FrameRateTest harness variant for benchmarking
7  * pages that contain content that is animated (e.g. canvas2d, webGL)
8  *
9  * How to instrument an animated web page for use with the frame rate test
10  * harness:
11  * 1. Include head.js followed by head_animation.js in the head of the test
12  *    page.
13  * 2. If the animation loop does not already use requestAnimationFrame,
14  *    convert it.
15  * 3. Replace calls to requestAnimationFrame with the __requestAnimationFrame
16  *    function defined below
17  * 4. If the test page needs to call requestAnimationFrame during an
18  *    initialization phase that should not be measured by the test, then
19  *    use __requestAnimationFrame_no_sampling
20  */
21
22 // default gestures for animated content
23 __gestures = {
24   none: __gesture_library["stationary"]
25 };
26
27 // Don't start benchmarking animated pages right away.
28 // wait for initialization to complete.
29 __initialized = false;
30
31 // Indicate to the test harness that the test page has its own
32 // animation loop.
33 __animation = true;
34
35 // Draw this many frames before starting test.
36 // This is a delay to allow caches and other resources to spin-up to reach a
37 // steady running state before benchmarking begins.
38 var __warmup_frames = 10;
39
40 function __did_render_frame() {
41   if (__warmup_frames > 0){
42     __warmup_frames--;
43     return;
44   }
45
46   // Signal that page is ready to begin benchamarking
47   __initialized = true;
48
49   if (__running) {
50     __advance_gesture();
51     __record_frame_time();
52   }
53 }
54
55 function __requestAnimationFrame(callback, element) {
56   __did_render_frame();
57   __raf(callback, element);
58 }
59
60 function __requestAnimationFrame_no_sampling(callback, element) {
61   __raf(callback, element);
62 }
63
64