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

content / test / data / gpu / pixel_video_context_loss.html [blame]

<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="initial-scale=1">
<title>Video Context Loss Test</title>
<style type="text/css">
.nomargin {
  margin: 0px auto;
}
</style>
<script>
var video;

var QueryString = function() {
  // Allows access to query parameters on the URL; e.g., given a URL like:
  //    http://<server>/my.html?test=123&bob=123
  // Parameters can then be accessed via QueryString.test or QueryString.bob.
  var params = {};
  // RegEx to split out values by &.
  var r = /([^&=]+)=?([^&]*)/g;
  // Lambda function for decoding extracted match values. Replaces '+' with
  // space so decodeURIComponent functions properly.
  function d(s) { return decodeURIComponent(s.replace(/\+/g, ' ')); }
  var match;
  while (match = r.exec(window.location.search.substring(1)))
    params[d(match[1])] = d(match[2]);
  return params;
}();

function CrashGpuProcess() {
  // Ensure we only get one crash in case of multiple canplaythrough events.
  video.removeEventListener('canplaythrough', CrashGpuProcess, false);

  // Create a canvas element and webgl context -- without a context, we won't
  // get a webglcontextlost event.
  var canvas = document.createElement('canvas');
  var gl = canvas.getContext('webgl');

  // webglcontextlost may not be invoked unless we actually try to execute a GL
  // command, so use a repeating function to tickle the context.
  var tickle = setInterval(function() { gl.getParameter(gl.VERSION); }, 250);

  // Now wait for the context loss before starting video playback.
  canvas.addEventListener('webglcontextlost', function(e) {
    clearInterval(tickle);

    // Now wait for the video to play until the end, by which point a frame
    // should be visible on screen.
    video.addEventListener('ended', function(e) {
      domAutomationController.send('SUCCESS');
    }, false);
    video.play();
  }, false);

  // Invokes chrome://gpucrash, which triggers a webglcontextlost event above.
  chrome.gpuBenchmarking.crashGpuProcess();
}

function Main() {
  video = document.getElementById('video');

  // Wait until we're sure a frame has been displayed before crashing GPU.
  video.addEventListener('canplaythrough', CrashGpuProcess, false);

  // Add an error listener to avoid timeouts if playback fails.
  video.addEventListener('error', function(e) {
    console.log('Video playback failed: ' + e.code + ', "' + e.message + '"');
    domAutomationController.send('ERROR');
  }, false);

  // We set a poster and preload=metadata to ensure that no frames are decoded
  // before the gpu crash -- otherwise the media pipeline can't guarantee that
  // we'll fall over to the software decoder.
  video.poster = 'single_face.jpg';
  video.preload = 'metadata';

  // src needs to be set after listeners are added.
  video.src = QueryString.src;
}
</script>
</head>
<body onload="Main()">
<div id="container" style="position:absolute; top:0px; left:0px">
<video class="nomargin" id="video" width="240" height="135"></video>
</div>
</body>
</html>