chromium/tools/perf/page_sets/simple_canvas/canvas2d_to_texture.html

<!DOCTYPE html>
<html>
<body>
<script>

var canvas2D = document.createElement("canvas");
var ctx2D = canvas2D.getContext("2d");
var canvas3D = document.createElement('canvas');
var gl = canvas3D.getContext('webgl');
document.body.appendChild(canvas2D);
document.body.appendChild(canvas3D);

if(!gl)
    CanvasRunner.logFatalError("WebGL is not supported or enabled on this platform!");
var tex = null;

function setSize(width, height) {
    canvas2D.width = width;
    canvas2D.height = height;
    canvas3D.width = width;
    canvas3D.height = height;
}

function rand(range) {
    return Math.floor(Math.random() * range);
}

function fillCanvas(ctx2d, canvas2d) {
    ctx2d.fillStyle = "rgba(" + rand(256) + "," + rand(256) + "," + rand(256)  + "," + rand(256) + ")";
    ctx2d.fillRect(0, 0, canvas2d.width, canvas2d.height);
}

function doRun() {
    const pixel = new Uint8Array([0, 0, 255, 255]);
    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2D);
}

function ensureComplete() {
    gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(4));
}

function startPerf() {
    fillCanvas(ctx2D, canvas2D);
    doRun();
    ensureComplete();
    requestAnimationFrame(startPerf);
}

window.onload = function () {
    setSize(1024, 1024);
    tex = gl.createTexture();
    gl.bindTexture(gl.TEXTURE_2D, tex);
    startPerf();
}

</script>
</body>
</html>