dom/canvas/test/webgl-mochitest/test_tex_large_uploads.html
author Mozilla Releng Treescript <release+treescript@mozilla.org>
Tue, 09 Aug 2022 06:59:02 +0000
changeset 626480 5761a15f36078c1ff69499321706dfaad8da84c3
parent 576449 758d677f4da15a88ff63d3bdc656ce1eeb3e95e3
permissions -rw-r--r--
no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD gd -> fe6d5c417ddee1ef85d8c83ebea768facee14b5a nb-NO -> 0d47d560228111600cfcb93cad0ad45485f3638f

<!DOCTYPE HTML>
<html>
  <head>
    <meta charset='UTF-8'>
    <script src='/tests/SimpleTest/SimpleTest.js'></script>
    <link rel='stylesheet' href='/tests/SimpleTest/test.css'>
  </head>
  <body>
    <img id='e_blank_15000x10000' src='blank_15000x10000.png'>
    <script>

function shouldBe(testStr, refStr) {
  ok(testStr == refStr, 'Expected "' + refStr + '", was "' + testStr + '".');
}

function getErrorStr(gl, err) {
  if (!err) return "NO_ERROR";
  for (const k in gl) {
    const v = gl[k];
    if (v == err) {
      return k;
    }
  }
  return `<${err}>`;
}

function glErrorShouldBe(gl, expected, opt_info) {
  if (opt_info) {
    opt_info = opt_info + ': '
  } else {
    opt_info = '';
  }

  if (!expected.length) {
    expected = [expected];
  }
  expected = expected.map(x => getErrorStr(gl, x));
  let was = gl.getError();
  was = getErrorStr(gl, was);
  ok(expected.includes(was),
    `${opt_info}Expected gl.getError() in [${expected}], was ${was}.`);
}
SimpleTest.waitForExplicitFinish();
(async () => {
  const gl = document.createElement('canvas').getContext('webgl2');
  window.gl = gl;
  if (!gl) {
    todo(false, 'No webgl2, skipping...');
    return;
  }
  const tex = gl.createTexture();
  gl.bindTexture(gl.TEXTURE_2D, tex);

  const TESTS = [
    //{w: 16000, h: 8000}, // TODO: This asserts.
    //{w: 8000, h: 16000}, // TODO: This asserts.
    {w: 8000, h: 4000},
    {w: 4000, h: 8000},
    {w: 4000, h: 4000},
  ];
  const src = document.createElement('canvas').getContext('webgl',
    {antialias:false, depth:false});
  const maxTexSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
  for (const t of TESTS) {
    ok(true, 'canvas: ' + JSON.stringify(t));
    if (t.w > maxTexSize || t.h > maxTexSize) {
      ok(true, `Larger than MAX_TEXTURE_SIZE of ${maxTexSize}`);
      continue;
    }
    src.canvas.width = t.w;
    src.canvas.height = t.h;
    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE,
                  src.canvas);

    glErrorShouldBe(gl, [0, gl.OUT_OF_MEMORY], `after texImage(${JSON.stringify(t)})`);

    src.canvas.width = src.canvas.height = 1;
  }

  if (15000 > maxTexSize) {
    ok(true, `e_blank_15000x10000 larger than MAX_TEXTURE_SIZE of ${maxTexSize}, skipping.`);
  } else {
    await e_blank_15000x10000.decode(); // Otherwise it will not have loaded yet.
    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE,
                  e_blank_15000x10000);
    glErrorShouldBe(gl, [0, gl.OUT_OF_MEMORY], `after texImage(e_blank_15000x10000)`);
    ok(!gl.isContextLost(), '!gl.isContextLost()');
  }

  SimpleTest.finish();
})();
    </script>
  </body>
</html>