Commit 572b06f7 authored by Reza.Zakerinasab's avatar Reza.Zakerinasab Committed by Commit Bot

Don't use hard coded reference pixels for ImageBitmap resize layout tests

This is a follow up CL for chromium-review.googlesource.com/c/chromium/src/+/895056.
This change:
 - removes hard coded reference pixels from video source layout test.
 - adds debug info for each tile to the console output.

Bug: 806994
Change-Id: I85d17fe1eb329282231b7843fbff94d31372cfb6
TBR: junov@chromium.org
Reviewed-on: https://chromium-review.googlesource.com/899662Reviewed-by: default avatarMohammad Reza Zakerinasab <zakerinasab@chromium.org>
Commit-Queue: Mohammad Reza Zakerinasab <zakerinasab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534094}
parent 938b1425
var refBufPremul = new Uint8Array([
255, 0, 0, 255, 192, 63, 0, 255, 61, 192, 0, 255, 0, 255, 2, 255,
192, 0, 60, 255, 157, 62, 62, 255, 96, 191, 67, 255, 62, 255, 70, 255,
62, 0, 184, 255, 93, 62, 187, 255, 160, 190, 191, 255, 192, 255, 194, 255,
0, 0, 252, 255, 58, 61, 255, 255, 195, 189, 255, 255, 255, 255, 255, 255]);
var refBufUnpremul = new Uint8Array([
255, 0, 0, 255, 192, 63, 0, 255, 61, 192, 0, 255, 0, 255, 2, 255,
192, 0, 60, 255, 157, 62, 62, 255, 96, 191, 67, 255, 62, 255, 70, 255,
62, 0, 184, 255, 93, 62, 187, 255, 160, 190, 191, 255, 192, 255, 194, 255,
0, 0, 252, 255, 58, 61, 255, 255, 195, 189, 255, 255, 255, 255, 255, 255]);
var refBufFlipY = new Uint8Array([
0, 0, 252, 255, 58, 61, 255, 255, 195, 189, 255, 255, 255, 255, 255, 255,
62, 0, 184, 255, 93, 62, 187, 255, 160, 190, 191, 255, 192, 255, 194, 255,
192, 0, 60, 255, 157, 62, 62, 255, 96, 191, 67, 255, 62, 255, 70, 255,
255, 0, 0, 255, 192, 63, 0, 255, 61, 192, 0, 255, 0, 255, 2, 255]);
var refBufUnpremulFlipY = new Uint8Array([
0, 0, 252, 255, 58, 61, 255, 255, 195, 189, 255, 255, 255, 255, 255, 255,
62, 0, 184, 255, 93, 62, 187, 255, 160, 190, 191, 255, 192, 255, 194, 255,
192, 0, 60, 255, 157, 62, 62, 255, 96, 191, 67, 255, 62, 255, 70, 255,
255, 0, 0, 255, 192, 63, 0, 255, 61, 192, 0, 255, 0, 255, 2, 255]);
function checkCanvas(buf, refBuf, tolerance, retVal)
{
if (buf.length != refBuf.length) {
retVal.testPassed = false;
return;
}
for (var p = 0; p < buf.length; p++) {
if (Math.abs(buf[p] - refBuf[p]) > tolerance) {
retVal.testPassed = false;
return;
}
}
}
function runOneIteration(useTexSubImage2D, bindingTarget, program, bitmap,
flipY, premultiplyAlpha, retVal, colorSpace = 'empty')
{
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
// Enable writes to the RGBA channels
gl.colorMask(1, 1, 1, 1);
var texture = gl.createTexture();
// Bind the texture to texture unit 0
gl.bindTexture(bindingTarget, texture);
// Set up texture parameters
gl.texParameteri(bindingTarget, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(bindingTarget, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
var targets = [gl.TEXTURE_2D];
if (bindingTarget == gl.TEXTURE_CUBE_MAP) {
targets = [gl.TEXTURE_CUBE_MAP_POSITIVE_X,
gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
gl.TEXTURE_CUBE_MAP_NEGATIVE_Z];
}
// Upload the image into the texture
for (var tt = 0; tt < targets.length; ++tt) {
if (useTexSubImage2D) {
// Initialize the texture to black first
gl.texImage2D(targets[tt], 0, gl[internalFormat], bitmap.width,
bitmap.height, 0, gl[pixelFormat], gl[pixelType], null);
gl.texSubImage2D(targets[tt], 0, 0, 0, gl[pixelFormat],
gl[pixelType], bitmap);
} else {
gl.texImage2D(targets[tt], 0, gl[internalFormat], gl[pixelFormat],
gl[pixelType], bitmap);
}
}
var width = gl.canvas.width;
var height = gl.canvas.height;
var loc;
if (bindingTarget == gl.TEXTURE_CUBE_MAP) {
loc = gl.getUniformLocation(program, "face");
}
var tolerance = (retVal.alpha == 0) ? 0 : 10;
for (var tt = 0; tt < targets.length; ++tt) {
if (bindingTarget == gl.TEXTURE_CUBE_MAP) {
gl.uniform1i(loc, targets[tt]);
}
// Draw the triangles
gl.clearColor(0, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES, 0, 6);
// Select the proper reference buffer
var refBuf = refBufPremul;
if (flipY && !premultiplyAlpha)
refBuf = refBufUnpremulFlipY;
else if (!premultiplyAlpha)
refBuf = refBufUnpremul;
else if (flipY)
refBuf = refBufFlipY;
// Check the pixels
var buf = new Uint8Array(width * height * 4);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
checkCanvas(buf, refBuf, tolerance, retVal);
}
}
function runTestOnBindingTarget(bindingTarget, program, bitmaps, retVal) {
var cases = [
{ sub: false, bitmap: bitmaps.defaultOption, flipY: false,
premultiply: true, colorSpace: 'empty' },
{ sub: true, bitmap: bitmaps.defaultOption, flipY: false,
premultiply: true, colorSpace: 'empty' },
{ sub: false, bitmap: bitmaps.noFlipYPremul, flipY: false,
premultiply: true, colorSpace: 'empty' },
{ sub: true, bitmap: bitmaps.noFlipYPremul, flipY: false,
premultiply: true, colorSpace: 'empty' },
{ sub: false, bitmap: bitmaps.noFlipYDefault, flipY: false,
premultiply: true, colorSpace: 'empty' },
{ sub: true, bitmap: bitmaps.noFlipYDefault, flipY: false,
premultiply: true, colorSpace: 'empty' },
{ sub: false, bitmap: bitmaps.noFlipYUnpremul, flipY: false,
premultiply: false, colorSpace: 'empty' },
{ sub: true, bitmap: bitmaps.noFlipYUnpremul, flipY: false,
premultiply: false, colorSpace: 'empty' },
{ sub: false, bitmap: bitmaps.flipYPremul, flipY: true,
premultiply: true, colorSpace: 'empty' },
{ sub: true, bitmap: bitmaps.flipYPremul, flipY: true,
premultiply: true, colorSpace: 'empty' },
{ sub: false, bitmap: bitmaps.flipYDefault, flipY: true,
premultiply: true, colorSpace: 'empty' },
{ sub: true, bitmap: bitmaps.flipYDefault, flipY: true,
premultiply: true, colorSpace: 'empty' },
{ sub: false, bitmap: bitmaps.flipYUnpremul, flipY: true,
premultiply: false, colorSpace: 'empty' },
{ sub: true, bitmap: bitmaps.flipYUnpremul, flipY: true,
premultiply: false, colorSpace: 'empty' },
{ sub: false, bitmap: bitmaps.colorSpaceDef, flipY: false,
premultiply: true,
colorSpace: retVal.colorSpaceEffect ? 'notprovided' : 'empty' },
{ sub: true, bitmap: bitmaps.colorSpaceDef, flipY: false,
premultiply: true,
colorSpace: retVal.colorSpaceEffect ? 'notprovided' : 'empty' },
{ sub: false, bitmap: bitmaps.colorSpaceNone, flipY: false,
premultiply: true,
colorSpace: retVal.colorSpaceEffect ? 'none' : 'empty' },
{ sub: true, bitmap: bitmaps.colorSpaceNone, flipY: false,
premultiply: true,
colorSpace: retVal.colorSpaceEffect ? 'none' : 'empty' },
{ sub: false, bitmap: bitmaps.colorSpaceDefault, flipY: false,
premultiply: true,
colorSpace: retVal.colorSpaceEffect ? 'default' : 'empty' },
{ sub: true, bitmap: bitmaps.colorSpaceDefault, flipY: false,
premultiply: true,
colorSpace: retVal.colorSpaceEffect ? 'default' : 'empty' },
];
for (var i in cases) {
runOneIteration(cases[i].sub, bindingTarget, program, cases[i].bitmap,
cases[i].flipY, cases[i].premultiply, retVal,
cases[i].colorSpace);
}
}
function runTest(bitmaps, alphaVal, colorSpaceEffective)
{
var retVal = {testPassed: true, alpha: alphaVal,
colorSpaceEffect: colorSpaceEffective};
var program = tiu.setupTexturedQuad(gl, internalFormat);
runTestOnBindingTarget(gl.TEXTURE_2D, program, bitmaps, retVal);
program = tiu.setupTexturedQuadWithCubeMap(gl, internalFormat);
runTestOnBindingTarget(gl.TEXTURE_CUBE_MAP, program, bitmaps, retVal);
return retVal.testPassed;
}
......@@ -62,7 +62,8 @@ function runOneIteration(useTexSubImage2D, bindingTarget, program, bitmap,
gl.drawArrays(gl.TRIANGLES, 0, 6);
var buf = new Uint8Array(width * height * 4);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
pixelsBuffer.push({quality: testOptions.resizeQuality, buffer: buf});
pixelsBuffer.unshift({quality: testOptions.resizeQuality, flip: flipY,
premul: premultiplyAlpha, buffer: buf});
}
}
......@@ -221,6 +222,12 @@ function prepareWebGLContext(testOptions) {
gl.clearDepth(1);
}
function PrintTileInfoForDebug(x, y, quality, premul, flip) {
var tileLog = "x: " + x + ", y: " + y + ", quality: " + quality +
", premul: " + premul + ", flip: " + flip;
console.log(tileLog);
}
function DrawResultsOnCanvas(testOptions) {
var resultsCanvas = testOptions.resultsCanvas;
var numTiles = Math.ceil(Math.sqrt(pixelsBuffer.length));
......@@ -240,6 +247,8 @@ function DrawResultsOnCanvas(testOptions) {
var x = (tileCounter * testOptions.resizeWidth) % width;
var y = Math.floor(tileCounter / numTiles) *
testOptions.resizeHeight;
PrintTileInfoForDebug(x, y, pixelsBuffer[j].quality,
pixelsBuffer[j].premultiply, pixelsBuffer[j].flip);
tileCounter++;
var imageData = new ImageData(Uint8ClampedArray.from(buffer),
testOptions.resizeWidth, testOptions.resizeHeight);
......
<!DOCTYPE html>
<html>
<head>
<script src="./resources/webgl-test-utils-full.js"></script>
<script src="./resources/tex-image-and-sub-image-utils.js"></script>
<script src="./resources/tex-image-and-sub-image-image-bitmap-utils-resize-video.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="./resources/tex-image-and-sub-image-image-bitmap-utils-resize.js"></script>
<body>
<script>
var wtu = WebGLTestUtils;
var tiu = TexImageUtils;
var gl = null;
var internalFormat = "RGBA";
var pixelFormat = "RGBA";
var pixelType = "UNSIGNED_BYTE";
function testImageBitmap()
{
var bitmaps = {};
var canvas = document.createElement('canvas');
canvas.width = 4;
canvas.height = 4;
document.body.appendChild(canvas);
gl = canvas.getContext("webgl");
gl.clearColor(0,0,0,1);
gl.clearDepth(1);
var options = {resizeWidth: 4, resizeHeight: 4, resizeQuality: "high"};
var p1 = createImageBitmap(video, options).then(
function(imageBitmap) { bitmaps.defaultOption = imageBitmap });
options.imageOrientation = "none";
options.premultiplyAlpha = "premultiply";
var p2 = createImageBitmap(video, options).then(
function(imageBitmap) { bitmaps.noFlipYPremul = imageBitmap });
options.premultiplyAlpha = "default";
var p3 = createImageBitmap(video, options).then(
function(imageBitmap) { bitmaps.noFlipYDefault = imageBitmap });
options.premultiplyAlpha = "none";
var p4 = createImageBitmap(video, options).then(
function(imageBitmap) { bitmaps.noFlipYUnpremul = imageBitmap });
options.imageOrientation = "flipY";
options.premultiplyAlpha = "premultiply";
var p5 = createImageBitmap(video, options).then(
function(imageBitmap) { bitmaps.flipYPremul = imageBitmap });
options.premultiplyAlpha = "default";
var p6 = createImageBitmap(video, options).then(
function(imageBitmap) { bitmaps.flipYDefault = imageBitmap });
options.premultiplyAlpha = "none";
var p7 = createImageBitmap(video, options).then(
function(imageBitmap) { bitmaps.flipYUnpremul = imageBitmap });
options = {resizeWidth: 4, resizeHeight: 4, resizeQuality: "high"};
var p8 = createImageBitmap(video, options).then(
function(imageBitmap) { bitmaps.colorSpaceDef = imageBitmap });
options.colorSpaceConversion = "none";
var p9 = createImageBitmap(video, options).then(
function(imageBitmap) { bitmaps.colorSpaceNone = imageBitmap });
if (window.testRunner) {
testRunner.dumpAsTextWithPixelResults();
testRunner.waitUntilDone();
}
options.colorSpaceConversion = "default";
var p10 = createImageBitmap(video, options).then(
function(imageBitmap) { bitmaps.colorSpaceDefault = imageBitmap });
var video = document.createElement("video");
var canvas = document.createElement('canvas');
canvas.width = 400;
canvas.height = 400;
document.body.appendChild(canvas);
return Promise.all([p1, p2, p3, p4, p5, p6, p7, p8, p9, p10]).then(
t.step_func_done(function() {
var alphaVal = 1;
var testPassed = runTest(bitmaps, alphaVal, false);
if (!testPassed)
assert_true(false, 'Test failed');
}), t.step_func_done(function() {
assert_true(false, 'Promise rejected');
}));
}
var testOptions = {sourceName: "HTMLVideoElement", imageSource: video,
sourceIsPremul: true, resizeWidth: 16, resizeHeight: 16,
resultsCanvas: canvas};
prepareWebGLContext(testOptions);
var t = async_test('createImageBitmap(HTMLVideoElement) with resize and other options');
video.oncanplaythrough = function() {
prepareResizedImageBitmapsAndRuntTests(testOptions);
};
var video = document.createElement("video");
video.oncanplaythrough = t.step_func(function() {
testImageBitmap();
});
video.src = "resources/red-green-blue-white-2x2.ogv";
</script>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment