1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69

content / test / data / gpu / webgl2-unpack-image-height.html [blame]

<html>
<head>
<script type="text/javascript">
let canvas;
let gl;
let timeout;

function send(result, message) {
  if (window.domAutomationController)
    window.domAutomationController.send(result);
  if (message)
    console.log(message);
  else if (!window.domAutomationController)
    console.log(result);
}

function near(val, expect) {
  return Math.abs(val - expect) < 2;
}

function onLoad() {
  send("LOADED");

  // Originally-reported problem occurred on AMD GPU on dual-GPU MacBook Pros.
  canvas = document.getElementById("canvas1");
  gl = canvas.getContext('webgl2', { powerPreference: 'high-performance' });

  gl.pixelStorei(gl.UNPACK_IMAGE_HEIGHT, 0xff);
  gl.bindTexture(gl.TEXTURE_2D_ARRAY, gl.createTexture());
  let ext = gl.getExtension('WEBGL_compressed_texture_s3tc');
  let format;
  if (ext) {
    format = ext.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  } else {
    ext = gl.getExtension('WEBGL_compressed_texture_etc');
    if (!ext) {
      send("FAILURE", "Desktop/mobile compressed texture formats not supported");
      return;
    }
    format = ext.COMPRESSED_RGBA8_ETC2_EAC;
  }
  gl.compressedTexImage3D(gl.TEXTURE_2D_ARRAY, 0, format, 4, 4, 4, 0, new Uint16Array(32));

  // Try clearing the canvas to solid green and see if it's read back successfully.
  // If the context was lost because of a GPU process crash in ASAN builds, this will fail.
  gl.clearColor(0, 1, 0, 1);
  gl.clear(gl.COLOR_BUFFER_BIT);
  let readback = new Uint8Array(4);
  gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, readback);
  if (near(readback[0], 0) &&
      near(readback[1], 255) &&
      near(readback[2], 0) &&
      near(readback[3], 255)) {
    send("SUCCESS");
  } else {
    send("FAILURE", "Expected solid green, got (" +
         readback[0] + ", " +
         readback[1] + ", " +
         readback[2] + ", " +
         readback[3] + ")");
  }
}
</script>
</head>
<body onload="onLoad()">
<canvas id="canvas1" width="64px" height="64px">
</canvas>
</body>
</html>