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.

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

mercurial