tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

readpixels-4gb-wasm-memory.html (1916B)


      1 <!--
      2 Copyright (c) 2023 The Khronos Group Inc.
      3 Use of this source code is governed by an MIT-style license that can be
      4 found in the LICENSE.txt file.
      5 -->
      6 <!DOCTYPE html>
      7 <html>
      8 <head>
      9 <meta charset="utf-8">
     10 <title>gl.readPixels() test to Wasm Memory 4GB in size.</title>
     11 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
     12 <script src="../../js/js-test-pre.js"></script>
     13 <script src="../../js/webgl-test-utils.js"> </script>
     14 </head>
     15 <body>
     16 <canvas id="canvas" width="2" height="2" style="width: 40px; height: 40px;"></canvas>
     17 <div id="description"></div>
     18 <div id="console"></div>
     19 <script>
     20 "use strict";
     21 description(document.title);
     22 debug("Tests that gl.readPixels() can be called on WebAssembly Memory of 4GB in size.");
     23 debug("");
     24 let wtu = WebGLTestUtils;
     25 let gl = wtu.create3DContext("canvas", undefined, 2);
     26 
     27 const PAGE = 65536;
     28 const SIZE = 4*1024*1024*1024 - PAGE; // when uint32_t size is max, we can only reach one page short of full 4GB
     29 let view = new Uint8Array(new WebAssembly.Memory({ initial: SIZE/PAGE }).buffer);
     30 
     31 // Clear the canvas to a specific color
     32 const expectedColor = [42, 84, 128, 255];
     33 gl.clearColor(expectedColor[0]/255.0, expectedColor[1]/255.0, expectedColor[2]/255.0, expectedColor[3]/255.0);
     34 gl.clear(gl.COLOR_BUFFER_BIT);
     35 
     36 // Test that gl.readPixels() can be called with a high offset to Memory
     37 const offset = SIZE - 4;
     38 view.set([0,0,0,0], offset); // For good measure, clear data at offset before reading
     39 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, view, offset);
     40 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
     41 let obtainedColor = view.subarray(offset, offset+4);
     42 shouldBe('obtainedColor[0]', 'expectedColor[0]');
     43 shouldBe('obtainedColor[1]', 'expectedColor[1]');
     44 shouldBe('obtainedColor[2]', 'expectedColor[2]');
     45 shouldBe('obtainedColor[3]', 'expectedColor[3]');
     46 var successfullyParsed = true;
     47 </script>
     48 <script src="../../js/js-test-post.js"></script>
     49 </body>
     50 </html>