Remove linux_chromium_gn_dbg from the chromium CQ.
[chromium-blink-merge.git] / tools / perf / page_sets / tough_animation_cases / balls_css_keyframe_animations.html
blob4163cf515cb06fe5762594285169d68f6c0a1b8b
1 <!--
2 Copyright (c) 2012 Cameron Adams. All rights reserved.
3 Copyright (c) 2012 Code Aurora Forum. All rights reserved.
4 Copyright (C) 2013 Google Inc. All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
8 met:
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above
12 copyright notice, this list of conditions and the following disclaimer
13 in the documentation and/or other materials provided with the
14 distribution.
15 * Neither the name of Code Aurora Forum Inc., Google Inc. nor the
16 names of its contributors may be used to endorse or promote products
17 derived from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 This test is based on code written by Cameron Adams and imported from
32 http://themaninblue.com/experiment/AnimationBenchmark/html
33 -->
35 <!doctype html>
36 <head>
37 <title>Benchmark - Balls Animation using CSS Animations</title>
38 <style>
39 html {
40 height: 100%;
43 body {
44 width: 100%;
45 height: 100%;
46 overflow: hidden;
47 margin: 0;
48 padding: 0;
51 span {
52 position: absolute;
53 width: 12px;
54 height: 12px;
55 border-radius: 6px;
57 </style>
58 <script src="resources/perf_test_helper.js"></script>
59 <script>
60 var measurementReady = false;
61 var stageWidth = 600;
62 var stageHeight = 600;
63 var maxParticles = 2500;
64 var minVelocity = 50;
65 var maxVelocity = 500;
66 var particleRadius = 6;
67 var colors = ["#cc0000", "#ffcc00", "#aaff00", "#0099cc", "#194c99", "#661999"];
68 var animationDuration = 10;
70 var particles = [];
72 window.onload = function () {
73 generateStyleElement();
75 // Create the particles
76 for (var i = 0; i < maxParticles; i++) {
77 var particle = new Particle(i);
78 particle.start();
79 particles.push(particle);
82 measurementReady = true;
85 function generateStyleElement() {
86 var allParticleKeyframes = '';
87 for (var i = 0; i < maxParticles; i++)
88 allParticleKeyframes += generateParticleKeyframes(i);
89 document.querySelector('#keyframes').innerHTML = allParticleKeyframes;
92 function generateParticleKeyframes(index) {
93 var keyframes = '@-webkit-keyframes ' + animationNameForIndex(index) + '{\n';
95 var angle = Math.PI * 2 * PerfTestHelper.random();
96 var velocity = minVelocity + ((maxVelocity - minVelocity) * PerfTestHelper.random());
97 var x = stageWidth / 2 - particleRadius;
98 var y = stageHeight / 2 - particleRadius;
99 var dx = Math.cos(angle) * velocity;
100 var dy = Math.sin(angle) * velocity;
102 function detectCollision(lineX, normalX, lineY, normalY) {
103 var dtx = Infinity;
104 var dty = Infinity;
105 if (dx * normalX < 0)
106 dtx = (lineX - x) / dx;
107 if (dy * normalY < 0)
108 dty = (lineY - y) / dy;
109 var dt = Math.min(dtx, dty);
110 var hitX = (dtx < dty);
111 return {
112 dt: dt,
113 x: hitX ? lineX : x + (dx * dt),
114 y: hitX ? y + (dy * dt) : lineY,
115 dx: hitX ? -dx : dx,
116 dy: hitX ? dy : -dy,
120 var t = 0;
121 keyframes += generateKeyframe(0, x, y);
122 while (t < animationDuration) {
123 var collisionA = detectCollision(0, 1, 0, 1);
124 var collisionB = detectCollision(stageWidth, -1, stageHeight, -1);
125 var collision = collisionA.dt < collisionB.dt ? collisionA : collisionB;
126 if (t + collision.dt > animationDuration) {
127 var dt = animationDuration - t;
128 t = animationDuration;
129 x += dx * dt;
130 y += dy * dt;
131 } else {
132 t += collision.dt;
133 x = collision.x;
134 y = collision.y;
135 dx = collision.dx;
136 dy = collision.dy;
138 keyframes += generateKeyframe(t, x, y);
141 keyframes += '}\n';
142 return keyframes;
145 function generateKeyframe(t, x, y) {
146 return (100 * t / animationDuration) + '% { left: ' + x + 'px; top: ' + y + 'px; }\n';
149 function animationNameForIndex(index) {
150 return 'animation-' + index;
153 function Particle(index)
155 // Create visual element for the particle.
156 var domNode = document.createElement('span');
157 document.body.appendChild(domNode);
159 // Set colour of element.
160 domNode.style.backgroundColor = colors[Math.floor(PerfTestHelper.random() * colors.length)];
161 domNode.style.webkitAnimationTimingFunction = 'linear';
162 domNode.style.webkitAnimationIterationCount = 'infinite';
163 domNode.style.webkitAnimationDirection = 'alternate';
164 domNode.style.webkitAnimationDuration = animationDuration + 's';
166 function start() {
167 domNode.style.webkitAnimationName = animationNameForIndex(index);
170 function destroy()
172 document.body.removeChild(domNode);
175 this.start = start;
176 this.destroy = destroy;
178 </script>
179 <style id="keyframes"></style>
180 </head>
181 </html>