onmessage = function(event) { var bitmap = event.data.bitmap;
ok(!!bitmap, "Get the ImageBitmap from the main script.");
var offscreenCanvas = new OffscreenCanvas(64, 64); var ctx = offscreenCanvas.getContext('bitmaprenderer');
ok(!!ctx, "Get bitmaprenderer context on worker.");
function createCanvas(width, height) { var htmlCanvas = document.createElement('canvas');
htmlCanvas.width = width;
htmlCanvas.height = height;
document.body.appendChild(htmlCanvas);
return htmlCanvas;
}
function runTest(canvasWidth, canvasHeight, nextTest) { var canvas1 = createCanvas(canvasWidth, canvasHeight); var ctx = canvas1.getContext("2d");
ctx.fillStyle = "#00FF00";
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
var canvasRef = createCanvas(canvasWidth, canvasHeight); var ctx = canvasRef.getContext("2d");
// Clear with black transparent first
ctx.fillStyle = "rgba(0, 0, 0, 0)";
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
// bitmaprenderers use an ImageLayer whereas a normal 2d canvas uses a canvas layer. This
// can result in some anti-aliasing differences on the edge. We consider slight AA differences
// to be reasonable when using different codepaths so fuzz a little bit. var fuzz = { numDifferentPixels: 0,
maxDifference: 0 };
if (SpecialPowers.Services.appinfo.widgetToolkit == "android") {
fuzz.maxDifference = 2;
fuzz.numDifferentPixels = 131;
} var results = compareSnapshots(snapshot, snapshotRef, true, fuzz);
ok(results[0], "Screenshots should be the same");
function runTestOnWorker() { var canvas1 = createCanvas(64, 64); var ctx = canvas1.getContext("2d");
ctx.fillStyle = "#00FF00";
ctx.fillRect(0, 0, 64, 64);
var blob = new Blob(Array.prototype.map.call(document.querySelectorAll("script[type=\"text\/js-worker\"]"), function (oScript) { return oScript.textContent; }),{type: "text/javascript"});
var worker = new Worker(window.URL.createObjectURL(blob));
createImageBitmap(canvas1).then(function(bmp) {
worker.postMessage({bitmap: bmp}, [bmp]);
worker.onmessage = function(event) {
if (event.data.type == "status") {
ok(event.data.status, event.data.msg);
} else if (event.data.type == "bitmap") { var canvas2 = createCanvas(64, 64); var ctx2 = canvas2.getContext('bitmaprenderer');
ctx2.transferFromImageBitmap(event.data.bitmap);
ok(canvas1.toDataURL() == canvas2.toDataURL(), 'toDataURL should be the same');
SimpleTest.finish();
}
}
});
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.