summaryrefslogtreecommitdiffstats
path: root/testing/talos/talos/tests/offscreencanvas/benchmarks/video/helper_worker.js
blob: 3b6d5aefe6d334c3e4a9974a3ebe2a87029d04f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

function runTest(testName, canvasType, worker, videoUri) {
  const canvas = document.createElement("canvas");
  canvas.width = 1920;
  canvas.height = 1080;
  document.body.appendChild(canvas);

  const offscreenCanvas = canvas.transferControlToOffscreen();

  return new Promise((resolve, reject) => {
    worker.onmessage = e => {
      if (e.data.errorMessage) {
        reject(e.data.errorMessage);
      } else {
        resolve(e.data);
      }
    };

    worker.postMessage({ offscreenCanvas, testName, canvasType, videoUri }, [
      offscreenCanvas,
    ]);
  })
    .then(result => {
      let name =
        result.testName +
        " Mean time across " +
        result.totalFrames +
        " frames: ";
      let value = result.elapsed / result.totalFrames;
      let msg = name + value + "\n";
      dump("[talos offscreen-canvas-webcodecs result] " + msg);

      if (window.tpRecordTime) {
        // Within talos - report the results
        tpRecordTime(value, 0, name);
      } else {
        alert(msg);
      }
    })
    .catch(e => {
      let msg = "caught error " + e;
      dump("[talos offscreen-canvas-webcodecs result] " + msg);
      if (window.tpRecordTime) {
        // Within talos - report the results
        tpRecordTime("", 0, "");
      } else {
        alert(msg);
      }
    });
}