content/canvas/test/webgl-conformance/extra/out-of-resources.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-resources.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    1.10 +  "http://www.w3.org/TR/html4/loose.dtd">
    1.11 +<html>
    1.12 +<head>
    1.13 +<meta charset="utf-8">
    1.14 +<title>WebGL Out Of Resources Test</title>
    1.15 +<link rel="stylesheet" href="../resources/js-test-style.css"/>
    1.16 +<script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
    1.17 +<script src="../../debug/webgl-debug.js"></script>
    1.18 +<script src="../resources/js-test-pre.js"></script>
    1.19 +<script src="../conformance/resources/webgl-test.js"></script>
    1.20 +</head>
    1.21 +<body>
    1.22 +<div id="description"></div>
    1.23 +<div id="console"></div>
    1.24 +<canvas id="canvas" width="2" height="2"> </canvas>
    1.25 +<canvas id="canvas2" width="2" height="2"> </canvas>
    1.26 +<script>
    1.27 +window.onload = init;
    1.28 +debug("Tests a WebGL program that tries to use all of vram.");
    1.29 +
    1.30 +function init() {
    1.31 +  if (confirm(
    1.32 +      "after clicking ok your machine may be come unresponsive or crash")) {
    1.33 +    main();
    1.34 +  } else {
    1.35 +    debug("cancelled");
    1.36 +  }
    1.37 +}
    1.38 +
    1.39 +function main() {
    1.40 +  debug("");
    1.41 +  debug("Canvas.getContext");
    1.42 +
    1.43 +  var gl = create3DContext(document.getElementById("canvas"));
    1.44 +  if (!gl) {
    1.45 +    testFailed("context does not exist");
    1.46 +  } else {
    1.47 +    testPassed("context exists");
    1.48 +
    1.49 +    debug("");
    1.50 +    debug("Checking for out of memory handling.");
    1.51 +
    1.52 +    var size = gl.getParameter(gl.MAX_RENDERBUFFER_SIZE);
    1.53 +    debug("max render buffer size: " + size);
    1.54 +
    1.55 +    var allocateFramebuffers = true;
    1.56 +    var itervalId;
    1.57 +    var count = 0;
    1.58 +
    1.59 +    gl = WebGLDebugUtils.makeDebugContext(gl, function(err, functionName, args) {
    1.60 +          window.clearInterval(intervalId);
    1.61 +          assertMsg(err == gl.OUT_OF_MEMORY,
    1.62 +                    "correctly returns gl.OUT_OF_MEMORY when out of memory");
    1.63 +          finish();
    1.64 +        });
    1.65 +
    1.66 +    intervalId = window.setInterval(function() {
    1.67 +      ++count;
    1.68 +      var mem = count * size * size * 4;
    1.69 +      debug("#" + count + " : memory allocated so far " + (mem / 1024 / 1024) + "MB");
    1.70 +      var tex = gl.createTexture();
    1.71 +      gl.bindTexture(gl.TEXTURE_2D, tex);
    1.72 +      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
    1.73 +      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
    1.74 +      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
    1.75 +      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
    1.76 +      gl.texImage2D(gl.TEXTURE_2D,
    1.77 +                    0,                 // level
    1.78 +                    gl.RGBA,           // internalFormat
    1.79 +                    size,              // width
    1.80 +                    size,              // height
    1.81 +                    0,                 // border
    1.82 +                    gl.RGBA,           // format
    1.83 +                    gl.UNSIGNED_BYTE,  // type
    1.84 +                    null);             // data
    1.85 +      if (allocateFrameBuffers) {
    1.86 +        var fb = gl.createFramebuffer();
    1.87 +        gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
    1.88 +        gl.framebufferTexture2D(
    1.89 +            gl.FRAMEBUFFER,
    1.90 +            gl.COLOR_ATTACHMENT0,
    1.91 +            gl.TEXTURE_2D,
    1.92 +            tex,
    1.93 +            0);
    1.94 +        var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
    1.95 +        if (status != gl.FRAMEBUFFER_COMPLETE) {
    1.96 +          testFailed("gl.checkFramebufferStatus() returned " + WebGLDebugUtils.glEnumToString(status) +
    1.97 +                     " should have gotten gl.OUT_OF_MEMORY before getting this.");
    1.98 +          window.clearInterval(intervalId);
    1.99 +          finish();
   1.100 +        }
   1.101 +      }
   1.102 +    }, 1000/10);
   1.103 +  }
   1.104 +
   1.105 +  function finish() {
   1.106 +    debug("");
   1.107 +    successfullyParsed = true;
   1.108 +  }
   1.109 +}
   1.110 +</script>
   1.111 +</body>
   1.112 +</html>

mercurial