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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
content / test / data / gpu / pixel_video_test.js [blame]
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var video;
var totalVideoSwaps = 8;
var useTimer = 0;
var delayMs = 1000;
function logOutput(s) {
if (window.domAutomationController)
window.domAutomationController.log(s);
else
console.log(s);
}
const parsedString = (function (names) {
const pairs = {};
for (let i = 0; i < names.length; ++i) {
var keyValue = names[i].split('=', 2);
if (keyValue.length == 1)
pairs[keyValue[0]] = '';
else
pairs[keyValue[0]] = decodeURIComponent(keyValue[1].replace(/\+/g, ' '));
}
return pairs;
})(window.location.search.substr(1).split('&'));
function setVideoSize() {
let width = '240';
let height = '135';
let widthString = parsedString['width'];
let heightString = parsedString['height'];
if (widthString != undefined)
width = widthString;
if (heightString != undefined)
height = heightString;
video.width = width;
video.height = height;
logOutput(`Video size:${video.width}x${video.height}`);
}
function getParametersTesting() {
let swapsString = parsedString['swaps'];
if (swapsString != undefined)
totalVideoSwaps = swapsString;
let useTimerString = parsedString['use_timer'];
if (useTimerString != undefined)
useTimer = useTimerString;
}
function main() {
let t0Ms = performance.now();
video = document.getElementById('video');
video.loop = true;
video.muted = true; // No need to exercise audio paths.
setVideoSize(video);
getParametersTesting();
video.onerror = e => {
logOutput(`Video playback error occurred: ${e.message}`);
abort = true;
domAutomationController.send('FAIL');
};
logOutput('Playback started.');
video.play().catch(e => {
logOutput(`play() failed: ${e.message}`);
domAutomationController.send('FAIL');
});
// Used by the swap counter, without using the timer.
let testCompletion = false;
let videoFrameReady = false;
let swapCount = 0;
// These tests expect playback, so we intentionally don't request the frame
// callback before starting playback. Since these videos loop there should
// always be frames being generated.
video.requestVideoFrameCallback((_, f) => {
let timestamp = performance.now() - t0Ms;
logOutput(`First videoFrameCallback: TimeStamp:${timestamp}ms`);
if (useTimer == 1) {
setTimeout(_ => {
logOutput('Test complete.');
domAutomationController.send('SUCCESS');
}, delayMs);
} else {
video.requestVideoFrameCallback(rVF_function);
chrome.gpuBenchmarking.addSwapCompletionEventListener(
waitForSwapsToComplete);
}
});
function rVF_function() {
videoFrameReady = true;
if (!testCompletion) {
video.requestVideoFrameCallback(rVF_function);
}
}
// Must add "--enable-features=ReportFCPOnlyOnSuccessfulCommit" with
// gpu_benchmarking to ensure completion event callback in
// addSwapCompletionEventListener is sent only on a succdessful commit.
function waitForSwapsToComplete() {
if (videoFrameReady) {
if (swapCount == 0) {
let timestamp = performance.now() - t0Ms;
logOutput(`First video overlay swap: TimeStamp:${timestamp}ms`);
}
swapCount++;
videoFrameReady = false;
}
if (swapCount < totalVideoSwaps) {
chrome.gpuBenchmarking.addSwapCompletionEventListener(
waitForSwapsToComplete);
} else {
testCompletion = true;
let timestamp = performance.now() - t0Ms;
logOutput(`Total swaps: ~${totalVideoSwaps}. Timestamp:${timestamp}ms`);
logOutput('Test complete.');
domAutomationController.send('SUCCESS');
}
}
}