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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!--
     2 Copyright (c) 2009 The Chromium Authors. All rights reserved.
     3 Use of this source code is governed by a BSD-style license that can be
     4 found in the LICENSE file.
     5 -->
     6 <!DOCTYPE html>
     7 <html>
     8 <head>
     9 <meta charset="utf-8">
    10 <title>WebGL Out Of VRAM Test</title>
    11 <link rel="stylesheet" href="../resources/js-test-style.css"/>
    12 <script src="../resources/desktop-gl-constants.js" type="text/javascript"></script>
    13 <script src="../resources/js-test-pre.js"></script>
    14 <script src="../conformance/resources/webgl-test.js"></script>
    15 <script src="../conformance/resources/webgl-test-utils.js"></script>
    16 </head>
    17 <body>
    18 <div id="description"></div>
    19 <div id="console"></div>
    20 <canvas id="canvas" width="2" height="2"> </canvas>
    21 <script>
    22 debug("This tests WebGL running out of vram.");
    24 debug("");
    25 debug("Canvas.getContext");
    27 var wtu = WebGLTestUtils;
    28 var canvas = document.getElementById("canvas");
    29 try {
    30   var gl = create3DContext(canvas);
    31 } catch(e) {
    32 }
    33 if (!gl) {
    34   testFailed("could not create context");
    35 } else {
    36   testPassed("context exists");
    38   var args = wtu.getUrlArguments();
    40   canvas.addEventListener('webglcontextlost', contextLost, false);
    42   function contextLost(e) {
    43     e.preventDefault();
    44     debug("***context lost***");
    45   }
    47   function contextRestored(e) {
    48     debug("***context restored***");
    49   }
    51   debug("");
    52   debug("Allocating textures.");
    54   var intervalId;
    55   var count = 0;
    56   var textureMem = 0;
    57   var textures = [];
    58   var size = 2048;
    59   var limit = (args.limit ? args.limit : 8192) * 1024 * 1024;
    61   debug("limit: " + InMB(limit))
    63   function InMB(v) {
    64     return "" + Math.floor(v / 1024 / 1024) + "MB";
    65   }
    67   function makeTexture() {
    68     if (gl.isContextLost()) {
    69       stop("out of memory");
    70       return;
    71     }
    72     ++count;
    73     textureMem += size * size * 4;
    74     if (textureMem > limit) {
    75       stop("reached limit");
    76       return;
    77     }
    78     debug ("creating texture #" + count + " mem = " + InMB(textureMem));
    79     var texture = gl.createTexture();
    80     textures.push(texture);
    81     gl.bindTexture(gl.TEXTURE_2D, texture);
    82     gl.texImage2D(gl.TEXTURE_2D,
    83                   0,                 // level
    84                   gl.RGBA,           // internalFormat
    85                   size,              // width
    86                   size,              // height
    87                   0,                 // border
    88                   gl.RGBA,           // format
    89                   gl.UNSIGNED_BYTE,  // type
    90                   null);             // data
    91     var err = gl.getError();
    92     if (err != gl.NO_ERROR) {
    93       stop("out of memory");
    94       return;
    95     }
    96   }
    98   intervalId = window.setInterval(makeTexture, 1000 / 15);
   100 }
   102 function stop(msg) {
   103   window.clearInterval(intervalId);
   104   testPassed(msg);
   105   finish();
   106 }
   108 function finish() {
   109   debug("");
   110   successfullyParsed = true;
   111 }
   113 </script>
   114 </body>
   115 </html>

mercurial