content/canvas/test/webgl-conformance/extra/out-of-vram.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/test/webgl-conformance/extra/out-of-vram.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,115 @@
     1.4 +<!--
     1.5 +Copyright (c) 2009 The Chromium Authors. All rights reserved.
     1.6 +Use of this source code is governed by a BSD-style license that can be
     1.7 +found in the LICENSE file.
     1.8 +-->
     1.9 +<!DOCTYPE html>
    1.10 +<html>
    1.11 +<head>
    1.12 +<meta charset="utf-8">
    1.13 +<title>WebGL Out Of VRAM Test</title>
    1.14 +<link rel="stylesheet" href="../resources/js-test-style.css"/>
    1.15 +<script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
    1.16 +<script src="../resources/js-test-pre.js"></script>
    1.17 +<script src="../conformance/resources/webgl-test.js"></script>
    1.18 +<script src="../conformance/resources/webgl-test-utils.js"></script>
    1.19 +</head>
    1.20 +<body>
    1.21 +<div id="description"></div>
    1.22 +<div id="console"></div>
    1.23 +<canvas id="canvas" width="2" height="2"> </canvas>
    1.24 +<script>
    1.25 +debug("This tests WebGL running out of vram.");
    1.26 +
    1.27 +debug("");
    1.28 +debug("Canvas.getContext");
    1.29 +
    1.30 +var wtu = WebGLTestUtils;
    1.31 +var canvas = document.getElementById("canvas");
    1.32 +try {
    1.33 +  var gl = create3DContext(canvas);
    1.34 +} catch(e) {
    1.35 +}
    1.36 +if (!gl) {
    1.37 +  testFailed("could not create context");
    1.38 +} else {
    1.39 +  testPassed("context exists");
    1.40 +
    1.41 +  var args = wtu.getUrlArguments();
    1.42 +
    1.43 +  canvas.addEventListener('webglcontextlost', contextLost, false);
    1.44 +
    1.45 +  function contextLost(e) {
    1.46 +    e.preventDefault();
    1.47 +    debug("***context lost***");
    1.48 +  }
    1.49 +
    1.50 +  function contextRestored(e) {
    1.51 +    debug("***context restored***");
    1.52 +  }
    1.53 +
    1.54 +  debug("");
    1.55 +  debug("Allocating textures.");
    1.56 +
    1.57 +  var intervalId;
    1.58 +  var count = 0;
    1.59 +  var textureMem = 0;
    1.60 +  var textures = [];
    1.61 +  var size = 2048;
    1.62 +  var limit = (args.limit ? args.limit : 8192) * 1024 * 1024;
    1.63 +
    1.64 +  debug("limit: " + InMB(limit))
    1.65 +
    1.66 +  function InMB(v) {
    1.67 +    return "" + Math.floor(v / 1024 / 1024) + "MB";
    1.68 +  }
    1.69 +
    1.70 +  function makeTexture() {
    1.71 +    if (gl.isContextLost()) {
    1.72 +      stop("out of memory");
    1.73 +      return;
    1.74 +    }
    1.75 +    ++count;
    1.76 +    textureMem += size * size * 4;
    1.77 +    if (textureMem > limit) {
    1.78 +      stop("reached limit");
    1.79 +      return;
    1.80 +    }
    1.81 +    debug ("creating texture #" + count + " mem = " + InMB(textureMem));
    1.82 +    var texture = gl.createTexture();
    1.83 +    textures.push(texture);
    1.84 +    gl.bindTexture(gl.TEXTURE_2D, texture);
    1.85 +    gl.texImage2D(gl.TEXTURE_2D,
    1.86 +                  0,                 // level
    1.87 +                  gl.RGBA,           // internalFormat
    1.88 +                  size,              // width
    1.89 +                  size,              // height
    1.90 +                  0,                 // border
    1.91 +                  gl.RGBA,           // format
    1.92 +                  gl.UNSIGNED_BYTE,  // type
    1.93 +                  null);             // data
    1.94 +    var err = gl.getError();
    1.95 +    if (err != gl.NO_ERROR) {
    1.96 +      stop("out of memory");
    1.97 +      return;
    1.98 +    }
    1.99 +  }
   1.100 +
   1.101 +  intervalId = window.setInterval(makeTexture, 1000 / 15);
   1.102 +
   1.103 +}
   1.104 +
   1.105 +function stop(msg) {
   1.106 +  window.clearInterval(intervalId);
   1.107 +  testPassed(msg);
   1.108 +  finish();
   1.109 +}
   1.110 +
   1.111 +function finish() {
   1.112 +  debug("");
   1.113 +  successfullyParsed = true;
   1.114 +}
   1.115 +
   1.116 +</script>
   1.117 +</body>
   1.118 +</html>

mercurial