skia2/tools/lottie-web-perf/lottie-web-perf.html
Ravi Mistry b2be410c57 [lottie-web-perf] Use SVG renderer and turn on chrome tracing
Parse lottie file to calculate number of frames instead of doing it in the HTML (which would interfere with tracing numbers).

NoTry: true
Bug: skia:9237
Change-Id: Ie965591206b888919fd2c104f329d703bd099c11
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/225896
Reviewed-by: Joe Gregorio <jcgregorio@google.com>
Commit-Queue: Ravi Mistry <rmistry@google.com>
2019-07-08 20:47:44 +00:00

71 lines
2.1 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Lottie-Web Perf</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=egde,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="/res/lottie.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css" media="screen">
body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<main>
<div style="width:1000px;height:1000px" class=anim></div>
</main>
<script type="text/javascript" charset="utf-8">
(function () {
const PATH = '/res/lottie.json';
const RENDERER = 'svg';
const FRAMES = 25;
// Get total number of frames of the animation from the hash.
const hash = window.location.hash;
const totalFrames = hash.slice(1);
console.log("Lottie has " + totalFrames + "total frames");
// Load the animation with autoplay false. We will control which
// frame to seek to and then will measure performance.
let anim = lottie.loadAnimation({
container: document.querySelector('.anim'),
renderer: RENDERER,
loop: false,
autoplay: false,
path: PATH,
rendererSettings: {
preserveAspectRatio:'xMidYMid meet'
},
});
const t_rate = 1.0 / (FRAMES - 1);
let frame = 0;
const drawFrame = () => {
if (frame >= FRAMES) {
// These are global variables to talk with puppeteer.
window._lottieWebDone = true;
return;
}
let t1 = Math.max(Math.min(t_rate * frame, 1.0), 0.0);
let seekToFrame = totalFrames * t1;
if (seekToFrame >= totalFrames-1) {
// bodymovin player sometimes draws blank when requesting
// to draw the very last frame. Subtracting a small value
// seems to fix this and make it draw the last frame.
seekToFrame -= .001;
}
anim.goToAndStop(seekToFrame, true /* isFrame */);
frame++;
window.requestAnimationFrame(drawFrame);
};
window.requestAnimationFrame(drawFrame);
})();
</script>
</body>
</html>