Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function generateTest(internalFormat, pixelFormat, pixelType, prologue, resource
var gl = null;
var successfullyParsed = false;

function init()
async function init()
{
description('Verify texImage2D and texSubImage2D code paths taking ImageBitmap created from a Blob (' + internalFormat + '/' + pixelFormat + '/' + pixelType + ')');

Expand All @@ -31,17 +31,18 @@ function generateTest(internalFormat, pixelFormat, pixelType, prologue, resource
gl.clearColor(0,0,0,1);
gl.clearDepth(1);

var xhr = new XMLHttpRequest();
xhr.open("GET", resourcePath + "red-green-semi-transparent.png");
xhr.responseType = 'blob';
xhr.onload = function() {
var blob = xhr.response;
runImageBitmapTest(blob, 0.5, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, false)
.then(() => {
finishTest();
});
};
xhr.send();
debug('*** Running tests against red-green-semi-transparent.png ***');
let response = await fetch(resourcePath + "red-green-semi-transparent.png");
let blob = await response.blob();
await runImageBitmapTest(blob, 0.5, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, false);
debug('*** Running tests against red-green-128x128-linear-profile.jpg ***');
response = await fetch(resourcePath + "red-green-128x128-linear-profile.jpg");
blob = await response.blob();
// This test requires a huge tolerance because browsers - at least currently - vary
// widely in the colorspace conversion results for this image.
let tolerance = 120;
await runImageBitmapTest(blob, 1.0, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, false, tolerance);
finishTest();
}

return init;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ found in the LICENSE.txt file.


function runOneIterationImageBitmapTest(useTexSubImage, bindingTarget, program, bitmap, flipY, premultiplyAlpha, optionsVal,
internalFormat, pixelFormat, pixelType, gl, tiu, wtu)
internalFormat, pixelFormat, pixelType, gl, tiu, wtu, tolerance)
{
var halfRed = [128, 0, 0];
var halfGreen = [0, 128, 0];
Expand Down Expand Up @@ -125,7 +125,6 @@ function runOneIterationImageBitmapTest(useTexSubImage, bindingTarget, program,
loc = gl.getUniformLocation(program, "face");
}

var tolerance = 10;
for (var tt = 0; tt < targets.length; ++tt) {
if (bindingTarget == gl.TEXTURE_CUBE_MAP) {
gl.uniform1i(loc, targets[tt]);
Expand All @@ -136,11 +135,11 @@ function runOneIterationImageBitmapTest(useTexSubImage, bindingTarget, program,
// Check the top pixel and bottom pixel and make sure they have
// the right color.
bufferedLogToConsole("Checking " + (flipY ? "top" : "bottom"));
wtu.checkCanvasRect(gl, left, bottom, 2, 2, tl, "shouldBe " + tl, tolerance);
wtu.checkCanvasRect(gl, right, bottom, 2, 2, tr, "shouldBe " + tr, tolerance);
wtu.checkCanvasRect(gl, left, bottom, 2, 2, tl, "shouldBe " + tl + " +/-" + tolerance, tolerance);
wtu.checkCanvasRect(gl, right, bottom, 2, 2, tr, "shouldBe " + tr + " +/-" + tolerance, tolerance);
bufferedLogToConsole("Checking " + (flipY ? "bottom" : "top"));
wtu.checkCanvasRect(gl, left, top, 2, 2, bl, "shouldBe " + bl, tolerance);
wtu.checkCanvasRect(gl, right, top, 2, 2, br, "shouldBe " + br, tolerance);
wtu.checkCanvasRect(gl, left, top, 2, 2, bl, "shouldBe " + bl + " +/-" + tolerance, tolerance);
wtu.checkCanvasRect(gl, right, top, 2, 2, br, "shouldBe " + br + " +/-" + tolerance, tolerance);
}
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
}
Expand All @@ -155,7 +154,7 @@ function resetUnpackParams(gl)
}

function runOneIterationImageBitmapTestSubSource(useTexSubImage, bindingTarget, program, bitmap, flipY, premultiplyAlpha, optionsVal,
internalFormat, pixelFormat, pixelType, gl, tiu, wtu)
internalFormat, pixelFormat, pixelType, gl, tiu, wtu, tolerance)
{
var halfRed = [128, 0, 0];
var halfGreen = [0, 128, 0];
Expand Down Expand Up @@ -310,30 +309,28 @@ function runOneIterationImageBitmapTestSubSource(useTexSubImage, bindingTarget,
var top = flipY ? quarterHeight : (height - halfHeight + quarterHeight);
var bottom = flipY ? (height - halfHeight + quarterHeight) : quarterHeight;


var tolerance = 10;
// Draw the triangles
wtu.clearAndDrawUnitQuad(gl, [0, 0, 0, 255]);

// Check the top pixel and bottom pixel and make sure they have
// the right color.
// For right side, check pixels closer to left to avoid border in the video tests.
bufferedLogToConsole("Checking " + (flipY ? "top" : "bottom"));
wtu.checkCanvasRect(gl, quarterWidth, bottom, 2, 2, tl, "shouldBe " + tl, tolerance);
wtu.checkCanvasRect(gl, halfWidth + quarterWidth / 2, bottom, 2, 2, tr, "shouldBe " + tr, tolerance);
wtu.checkCanvasRect(gl, quarterWidth, bottom, 2, 2, tl, "shouldBe " + tl + " +/-" + tolerance, tolerance);
wtu.checkCanvasRect(gl, halfWidth + quarterWidth / 2, bottom, 2, 2, tr, "shouldBe " + tr + " +/-" + tolerance, tolerance);
bufferedLogToConsole("Checking " + (flipY ? "bottom" : "top"));
wtu.checkCanvasRect(gl, quarterWidth, top, 2, 2, bl, "shouldBe " + bl, tolerance);
wtu.checkCanvasRect(gl, halfWidth + quarterWidth / 2, top, 2, 2, br, "shouldBe " + br, tolerance);
wtu.checkCanvasRect(gl, quarterWidth, top, 2, 2, bl, "shouldBe " + bl + " +/-" + tolerance, tolerance);
wtu.checkCanvasRect(gl, halfWidth + quarterWidth / 2, top, 2, 2, br, "shouldBe " + br + " +/-" + tolerance, tolerance);

wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
}

function runTestOnBindingTargetImageBitmap(bindingTarget, program, cases, optionsVal,
internalFormat, pixelFormat, pixelType, gl, tiu, wtu)
internalFormat, pixelFormat, pixelType, gl, tiu, wtu, tolerance)
{
cases.forEach(x => {
runOneIterationImageBitmapTest(x.sub, bindingTarget, program, x.bitmap,
x.bitmap.flipY, x.bitmap.premultiply, optionsVal, internalFormat, pixelFormat, pixelType, gl, tiu, wtu);
x.bitmap.flipY, x.bitmap.premultiply, optionsVal, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, tolerance);
});

if (wtu.getDefault3DContextVersion() <= 1 ||
Expand All @@ -346,11 +343,11 @@ function runTestOnBindingTargetImageBitmap(bindingTarget, program, cases, option

cases.forEach(x => {
runOneIterationImageBitmapTestSubSource(x.sub, bindingTarget, program, x.bitmap,
x.bitmap.flipY, x.bitmap.premultiply, optionsVal, internalFormat, pixelFormat, pixelType, gl, tiu, wtu);
x.bitmap.flipY, x.bitmap.premultiply, optionsVal, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, tolerance);
});
}

function runImageBitmapTestInternal(bitmaps, alphaVal, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, is3D)
function runImageBitmapTestInternal(bitmaps, alphaVal, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, is3D, tolerance)
{
var cases = [];
bitmaps.forEach(bitmap => {
Expand All @@ -363,29 +360,32 @@ function runImageBitmapTestInternal(bitmaps, alphaVal, internalFormat, pixelForm
if (is3D) {
program = tiu.setupTexturedQuadWith3D(gl, internalFormat);
runTestOnBindingTargetImageBitmap(gl.TEXTURE_3D, program, cases, optionsVal,
internalFormat, pixelFormat, pixelType, gl, tiu, wtu);
internalFormat, pixelFormat, pixelType, gl, tiu, wtu, tolerance);
} else {
program = tiu.setupTexturedQuad(gl, internalFormat);
runTestOnBindingTargetImageBitmap(gl.TEXTURE_2D, program, cases, optionsVal,
internalFormat, pixelFormat, pixelType, gl, tiu, wtu);
internalFormat, pixelFormat, pixelType, gl, tiu, wtu, tolerance);
}

// cube map texture must be square
if (bitmaps[0].width == bitmaps[0].height) {
if (is3D) {
program = tiu.setupTexturedQuadWith2DArray(gl, internalFormat);
runTestOnBindingTargetImageBitmap(gl.TEXTURE_2D_ARRAY, program, cases, optionsVal,
internalFormat, pixelFormat, pixelType, gl, tiu, wtu);
internalFormat, pixelFormat, pixelType, gl, tiu, wtu, tolerance);
} else {
program = tiu.setupTexturedQuadWithCubeMap(gl, internalFormat);
runTestOnBindingTargetImageBitmap(gl.TEXTURE_CUBE_MAP, program, cases, optionsVal,
internalFormat, pixelFormat, pixelType, gl, tiu, wtu);
internalFormat, pixelFormat, pixelType, gl, tiu, wtu, tolerance);
}
}
}

function runImageBitmapTest(source, alphaVal, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, is3D)
function runImageBitmapTest(source, alphaVal, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, is3D, opt_tolerance)
{
if (opt_tolerance === undefined) {
opt_tolerance = 10;
}
var p1 = createImageBitmap(source, {imageOrientation: "none", premultiplyAlpha: "premultiply"})
.then(cur => { cur.flipY = false; cur.premultiply = true; return cur; });
var p2 = createImageBitmap(source, {imageOrientation: "none", premultiplyAlpha: "none"})
Expand All @@ -402,7 +402,7 @@ function runImageBitmapTest(source, alphaVal, internalFormat, pixelFormat, pixel
return Promise.all([p]);
}).then( bitmaps => {
bufferedLogToConsole("All createImageBitmap promises are resolved");
runImageBitmapTestInternal(bitmaps, alphaVal, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, is3D);
runImageBitmapTestInternal(bitmaps, alphaVal, internalFormat, pixelFormat, pixelType, gl, tiu, wtu, is3D, opt_tolerance);
}, (e) => {
// This will fail here when running from file:// instead of https://.
testFailed("createImageBitmap(source) failed: \"" + e.message + "\"");
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.