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

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial