summaryrefslogtreecommitdiffstats
path: root/content/test
diff options
context:
space:
mode:
Diffstat (limited to 'content/test')
-rw-r--r--content/test/data/gpu/mem_css3d.html52
-rw-r--r--content/test/data/gpu/mem_webgl.html136
2 files changed, 188 insertions, 0 deletions
diff --git a/content/test/data/gpu/mem_css3d.html b/content/test/data/gpu/mem_css3d.html
new file mode 100644
index 0000000..d1d3ead
--- /dev/null
+++ b/content/test/data/gpu/mem_css3d.html
@@ -0,0 +1,52 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>GPU Memory Test: Use N MB of GPU Memory with 3D CSS</title>
+<style>
+.block {
+ background: #FF0000;
+ font-size: 150px;
+ height: 512px;
+ position: absolute;
+ width: 512px;
+
+}
+.perspective
+{
+ border: 1px solid black;
+ height: 512px;
+ text-align: center;
+ width: 512px;
+ -webkit-perspective: 600px;
+ -webkit-perspective-origin: center center;
+ -webkit-transform-style: preserve-3d;
+}
+</style>
+<script type="text/javascript">
+// Generate n 3D CSS elements that are each about 1 MB in size
+function useGpuMemory(mb_to_use) {
+ n = mb_to_use;
+ var blocks = document.getElementById("blocks");
+ var blockArray = document.getElementsByClassName("block");
+ for (var i = 0; i < n; i++) {
+ var block = document.createElement("div");
+ block.className = "block";
+ block.style.WebkitTransform = "translate3d(0px, 0px, " + (i-n+1) + "px)";
+ block.style.opacity = 0.1;
+ block.style.background = "#00FF00";
+ block.textContent = i;
+ blocks.appendChild(block);
+ }
+
+ // Touch offsetTop to trigger a layout.
+ document.body.offsetTop;
+
+ // Signal back to the test runner that we're done allocating memory.
+ domAutomationController.send("DONE_USE_GPU_MEMORY");
+}
+</script>
+</head>
+<body>
+<div id="blocks" class="perspective"/>
+</body>
+</html>
diff --git a/content/test/data/gpu/mem_webgl.html b/content/test/data/gpu/mem_webgl.html
new file mode 100644
index 0000000..6246d34
--- /dev/null
+++ b/content/test/data/gpu/mem_webgl.html
@@ -0,0 +1,136 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>GPU Memory Test: Use N MB of GPU Memory with WebGL</title>
+
+<script id="vertex-shader" type="x-shader/x-vertex">
+attribute vec2 a_position;
+varying vec2 v_position;
+void main() {
+ v_position = a_position;
+ gl_Position = vec4(a_position, 0, 1);
+}
+</script>
+
+<script id="fragment-shader" type="x-shader/x-fragment">
+precision mediump float;
+uniform sampler2D u_image;
+varying vec2 v_position;
+void main() {
+ gl_FragColor = texture2D(u_image, v_position);
+}
+</script>
+
+<script>
+var gl = null;
+var shaderProgram = null;
+var textures = [];
+var fbos = [];
+var t = 0.0;
+var n = 1;
+
+// Create n textures of about 1MB each.
+function useGpuMemory(mb_to_use)
+{
+ n = mb_to_use;
+
+ var canvas = document.getElementById("canvas_id");
+ gl = canvas.getContext("experimental-webgl");
+ if (!gl) {
+ throw "Unable to fetch WebGL rendering context for Canvas";
+ }
+
+ // Create n textures that are each about 1MB and FBOs to render to them.
+ for (var i = 0; i < n; ++i) {
+ var texture = gl.createTexture();
+ var fbo = gl.createFramebuffer();
+ textures.push(texture);
+ fbos.push(fbo);
+
+ gl.bindTexture(gl.TEXTURE_2D, texture);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 512, 512, 0,
+ gl.RGBA, gl.UNSIGNED_BYTE, null)
+
+ gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
+ gl.framebufferTexture2D(gl.FRAMEBUFFER,
+ gl.COLOR_ATTACHMENT0,
+ gl.TEXTURE_2D,
+ texture,
+ 0);
+ }
+
+ // Create a shader that samples a 2D image.
+ var vertexShader = gl.createShader(gl.VERTEX_SHADER);
+ gl.shaderSource(vertexShader,
+ document.getElementById("vertex-shader").textContent);
+ gl.compileShader(vertexShader);
+
+ var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
+ gl.shaderSource(fragmentShader,
+ document.getElementById("fragment-shader").textContent);
+ gl.compileShader(fragmentShader);
+
+ shaderProgram = gl.createProgram();
+ gl.attachShader(shaderProgram, vertexShader);
+ gl.attachShader(shaderProgram, fragmentShader);
+ gl.linkProgram(shaderProgram);
+ gl.useProgram(shaderProgram);
+
+ // Bind a vertex buffer with a single triangle
+ var buffer = gl.createBuffer();
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
+ var bufferData = new Float32Array([-1.0, -1.0, 1.0, -1.0, -1.0, 1.0]);
+ gl.bufferData(gl.ARRAY_BUFFER, bufferData, gl.STATIC_DRAW);
+ gl.enableVertexAttribArray(shaderProgram.a_position);
+ gl.vertexAttribPointer(shaderProgram.a_position, 2, gl.FLOAT, false, 0, 0);
+
+ // Signal back to the test runner that we're done allocating memory.
+ domAutomationController.send("DONE_USE_GPU_MEMORY");
+
+ // Start the event loop.
+ tick();
+}
+
+function drawScene()
+{
+ // Render a solid color to each texture.
+ for (var i = 0; i < n; ++i) {
+ gl.bindFramebuffer(gl.FRAMEBUFFER, fbos[i]);
+ gl.viewport(0, 0, 512, 512);
+ gl.clearColor(0.0, Math.sin(t/60.0)*0.25 + 0.75*(i+1.0)/n, 0.0, 1.0);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+ }
+
+ // Draw these textures to the screen, offset by 1 pixel increments
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
+ gl.viewport(0, 0, 256, 256);
+ gl.clearColor(0.0, 0.0, 0.0, 1.0);
+ gl.clear(gl.COLOR_BUFFER_BIT);
+ for (var i = 0; i < n; ++i) {
+ gl.viewport(i, i, 256-i, 256-i);
+ gl.activeTexture(gl.TEXTURE0);
+ gl.bindTexture(gl.TEXTURE_2D, textures[i]);
+ gl.uniform1i(shaderProgram.u_image, 0);
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
+ }
+
+ t += 1;
+}
+
+function tick()
+{
+ window.webkitRequestAnimationFrame(tick);
+ drawScene();
+}
+</script>
+</head>
+
+<body>
+<canvas id="canvas_id" width=256px height=256px style="width:256px; height:256px;"/>
+</body>
+</html>
+