content/canvas/test/webgl-conformance/conformance/textures/tex-image-and-sub-image-2d-with-video.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) 2011 The Chromium Authors. All rights reserved.
     3 Use of this source code is governed by a BSD-style license that can be
     4 found in the LICENSE file.
     5  -->
     6 <!DOCTYPE html>
     7 <html>
     8 <head>
     9 <meta charset="utf-8">
    10 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
    11 <script src="../../resources/js-test-pre.js"></script>
    12 <script src="../resources/webgl-test.js"></script>
    13 <script src="../resources/webgl-test-utils.js"></script>
    14 <script>
    15 var wtu = WebGLTestUtils;
    16 var gl = null;
    17 var textureLoc = null;
    18 var successfullyParsed = false;
    20 if (window.initNonKhronosFramework) {
    21     window.initNonKhronosFramework(true);
    22 }
    24 function init()
    25 {
    26     description('Verify texImage2D and texSubImage2D code paths taking Video Elements');
    28     gl = wtu.create3DContext("example");
    29     var program = wtu.setupTexturedQuad(gl);
    31     gl.clearColor(0,0,0,1);
    32     gl.clearDepth(1);
    34     textureLoc = gl.getUniformLocation(program, "tex");
    36     var video = document.getElementById("vid");
    37     video.addEventListener(
    38         "playing", function() { runTest(video); }, true);
    39     video.loop = true;
    40     video.play();
    41 }
    43 // These two declarations need to be global for "shouldBe" to see them
    44 var buf = null;
    45 var idx = 0;
    46 var pixel = [0, 0, 0];
    47 var correctColor = null;
    49 function runOneIteration(videoElement, useTexSubImage2D, flipY, topColor, bottomColor)
    50 {
    51     debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') +
    52           ' with flipY=' + flipY);
    53     gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    54     // Disable any writes to the alpha channel
    55     gl.colorMask(1, 1, 1, 0);
    56     var texture = gl.createTexture();
    57     // Bind the texture to texture unit 0
    58     gl.bindTexture(gl.TEXTURE_2D, texture);
    59     // Set up texture parameters
    60     gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
    61     gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
    62     gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
    63     gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
    64     // Set up pixel store parameters
    65     gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
    66     gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
    67     // Upload the videoElement into the texture
    68     if (useTexSubImage2D) {
    69         // Initialize the texture to black first
    70         gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA,
    71                       videoElement.videoWidth, videoElement.videoHeight, 0,
    72                       gl.RGBA, gl.UNSIGNED_BYTE, null);
    73         gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, videoElement);
    74     } else {
    75         gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, videoElement);
    76     }
    78     var c = document.createElement("canvas");
    79     c.width = 16;
    80     c.height = 16;
    81     c.style.border = "1px solid black";
    82     var ctx = c.getContext("2d");
    83     ctx.drawImage(videoElement, 0, 0, 16, 16);
    84     document.body.appendChild(c);
    86     // Point the uniform sampler to texture unit 0
    87     gl.uniform1i(textureLoc, 0);
    88     // Draw the triangles
    89     wtu.drawQuad(gl, [0, 0, 0, 255]);
    90     // Check a few pixels near the top and bottom and make sure they have
    91     // the right color.
    92     debug("Checking lower left corner");
    93     wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor,
    94                         "shouldBe " + bottomColor);
    95     debug("Checking upper left corner");
    96     wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor,
    97                         "shouldBe " + topColor);
    98 }
   100 function runTest(videoElement)
   101 {
   102     var red = [255, 0, 0];
   103     var green = [0, 255, 0];
   104     runOneIteration(videoElement, false, true, red, green);
   105     runOneIteration(videoElement, false, false, green, red);
   106     runOneIteration(videoElement, true, true, red, green);
   107     runOneIteration(videoElement, true, false, green, red);
   109     glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
   110     videoElement.removeEventListener("playing", runTest);
   111     finishTest();
   112 }
   113 </script>
   114 </head>
   115 <body onload="init()">
   116 <canvas id="example" width="32px" height="32px"></canvas>
   117 <div id="description"></div>
   118 <div id="console"></div>
   119 <video width="640" height="228" id="vid" controls>
   120   <source src="../resources/red-green.mp4"  type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
   121   <source src="../resources/red-green.webmvp8.webm" type='video/webm; codecs="vp8, vorbis"' />
   122   <source src="../resources/red-green.theora.ogv"  type='video/ogg; codecs="theora, vorbis"' />
   123 </video>
   124 </body>
   125 </html>

mercurial