content/canvas/test/webgl-conformance/extra/canvas-compositing-test.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!--
michael@0 2 Copyright (C) 2009 Apple Computer, Inc. All rights reserved.
michael@0 3
michael@0 4 Redistribution and use in source and binary forms, with or without
michael@0 5 modification, are permitted provided that the following conditions
michael@0 6 are met:
michael@0 7 1. Redistributions of source code must retain the above copyright
michael@0 8 notice, this list of conditions and the following disclaimer.
michael@0 9 2. Redistributions in binary form must reproduce the above copyright
michael@0 10 notice, this list of conditions and the following disclaimer in the
michael@0 11 documentation and/or other materials provided with the distribution.
michael@0 12
michael@0 13 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
michael@0 14 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 15 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
michael@0 16 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
michael@0 17 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
michael@0 18 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
michael@0 19 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
michael@0 20 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
michael@0 21 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 24 -->
michael@0 25
michael@0 26 <!DOCTYPE html>
michael@0 27 <html>
michael@0 28 <head>
michael@0 29 <meta charset="utf-8">
michael@0 30 <title>Canvas Compositing Test</title>
michael@0 31 <link rel="stylesheet" href="../resources/js-test-style.css"/>
michael@0 32 <script src="../resources/js-test-pre.js"></script>
michael@0 33 <script src="../conformance/resources/webgl-test.js"> </script>
michael@0 34 </head>
michael@0 35 <body>
michael@0 36 Below are 2 50x50 pixel canvas but using CSS to display them at 100x100 pixels. <br/>
michael@0 37 They are solid black with a red triangle<br/>
michael@0 38 They each have a 10px CSS solid black border around them.<br/>
michael@0 39 Depending on how the browser composites the canvas with the page they will get
michael@0 40 a white outline<hr/>
michael@0 41 <div>
michael@0 42 2d canvas<br/>
michael@0 43 <canvas id="example2" width="50" height="50" style="width: 100px; height: 100px; border: 10px solid black;"></canvas>
michael@0 44 </div>
michael@0 45 <hr/>
michael@0 46 3d canvas<br/>
michael@0 47 <div>
michael@0 48 <canvas id="example" width="50" height="50" style="width: 100px; height: 100px; border: 10px solid black;"></canvas>
michael@0 49 </div>
michael@0 50 <hr/>
michael@0 51 img tag<br/>
michael@0 52 <img src="50x50pixel-black-with-red-triangle.png" style="width: 100px; height: 100px; border: 10px solid black;"/>
michael@0 53 <div id="description"></div>
michael@0 54 <div id="console"></div>
michael@0 55 <script id="vshader" type="x-shader/x-vertex">
michael@0 56 attribute vec4 vPosition;
michael@0 57 void main()
michael@0 58 {
michael@0 59 gl_Position = vPosition;
michael@0 60 }
michael@0 61 </script>
michael@0 62
michael@0 63 <script id="fshader" type="x-shader/x-fragment">
michael@0 64 void main()
michael@0 65 {
michael@0 66 gl_FragColor = vec4(1.0,0.0,0.0,1.0);
michael@0 67 }
michael@0 68 </script>
michael@0 69
michael@0 70 <script>
michael@0 71 function fail(x,y, buf, shouldBe)
michael@0 72 {
michael@0 73 var i = (y*50+x) * 4;
michael@0 74 var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+","+buf[i+3]+"), should be "+shouldBe;
michael@0 75 testFailed(reason);
michael@0 76 }
michael@0 77
michael@0 78 function pass()
michael@0 79 {
michael@0 80 testPassed("drawing is correct");
michael@0 81 }
michael@0 82
michael@0 83 function init()
michael@0 84 {
michael@0 85 var canvas2d = document.getElementById("example2");
michael@0 86 var ctx2d = canvas2d.getContext("2d");
michael@0 87 ctx2d.fillStyle = "rgba(0, 0, 0, 255)"
michael@0 88 ctx2d.fillRect(0, 0, 50, 50);
michael@0 89 ctx2d.fillStyle = "rgba(255, 0, 0, 255)"
michael@0 90 ctx2d.beginPath();
michael@0 91 ctx2d.moveTo(25, 12.5);
michael@0 92 ctx2d.lineTo(12.5, 37.5);
michael@0 93 ctx2d.lineTo(37.5, 37.5);
michael@0 94 ctx2d.lineTo(25, 12.5);
michael@0 95 ctx2d.fill();
michael@0 96
michael@0 97
michael@0 98 if (window.initNonKhronosFramework) {
michael@0 99 window.initNonKhronosFramework(false);
michael@0 100 }
michael@0 101
michael@0 102 gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0, 0, 0, 1 ], 1);
michael@0 103 gl.viewport(0, 0, 50, 50);
michael@0 104
michael@0 105 var vertexObject = gl.createBuffer();
michael@0 106 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
michael@0 107 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
michael@0 108 gl.enableVertexAttribArray(0);
michael@0 109 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
michael@0 110
michael@0 111 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
michael@0 112 gl.drawArrays(gl.TRIANGLES, 0, 3);
michael@0 113 }
michael@0 114
michael@0 115 init();
michael@0 116 successfullyParsed = true;
michael@0 117 </script>
michael@0 118 </body>
michael@0 119 <script>finishTest();</script>
michael@0 120
michael@0 121 <script>
michael@0 122 </script>
michael@0 123
michael@0 124 </body>
michael@0 125 </html>

mercurial