blob: b83b4fe65599a75c377310b013b8522e03d538f5 [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/runner.js"></script>
<script src="resources/canvas_runner.js"></script>
var canvas2D = document.createElement("canvas");
var ctx2D = canvas2D.getContext("2d");
var canvas3D = document.createElement('canvas');
var gl = canvas3D.getContext('experimental-webgl');
if (!gl)
CanvasRunner.logFatalError("\nWebGL is not supported or enabled on this platform!\n");
function setSize(canvas2DWidth, canvas2DHeight, webglWidth, webglHeight) {
canvas2D.width = canvas2DWidth;
canvas2D.height = canvas2DHeight;
canvas3D.width = webglWidth;
canvas3D.height = webglHeight;
function rand(range) {
return Math.floor(Math.random() * range);
function renderWebGL(gl) {
gl.scissor(rand(1024), rand(1024), rand(1024), rand(1024));
gl.clearColor(Math.random(), Math.random(), Math.random(), 1);
function doRun() {
// draw static WebGL
ctx2D.drawImage(canvas3D, 0, 0);
function ensureComplete() {
// Calling getImageData() is just to flush out the content when
// accelerated 2D canvas is in use. The cost of reading 1x1 pixels is low.
ctx2D.getImageData(0, 0, 1, 1);
window.onload = function () {
// It should use setMinimumAccelerated2dCanvasSize() to enable accelerated Canvas for a specified size
// but this API is not available in JS or WebPage. Assume the threshold size is 256x257
// and the dest canvas is HW accelerated Canvas when setting its size to 1024x1024.
setSize(1024, 1024, 1024, 1024);
description: "This bench test checks the speed on drawing static WebGL(1024x1024) to HW accelerated Canvas2D(1024x1024).",
doRun: doRun,
ensureComplete: ensureComplete});