Commit 6d6574c4 authored by Aaron Krajeski's avatar Aaron Krajeski Committed by Commit Bot

Add perf test for converting to blob in worker

We currently test toblob, but only on the main thread. It looks as
though we can be at the mercy of the scheduler here, so it would be
worthwhile to at least keep track of it.

See: crbug.com/1053477

Bug: 1065481
Change-Id: I42ee1f9ae20dbedea45952e7a79ada10d7f9b19b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2124971Reviewed-by: default avatarBrian Sheedy <bsheedy@chromium.org>
Reviewed-by: default avatarYi Xu <yiyix@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Reviewed-by: default avatarJuanmi Huertas <juanmihd@chromium.org>
Commit-Queue: Aaron Krajeski <aaronhk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756038}
parent 7921c51d
<!DOCTYPE html>
<html>
<body>
<script src = "../resources/runner.js"></script>
<script type="text/javascript" id="worker">
/*
Because of task scheduling worker toBlob operations can be take an
unexpectedly long time, even for small canvases. crbug.com/1053477
*/
function offscreenCanvasToBlobOnWorker() {
const offscreenCanvas = new OffscreenCanvas(32, 32);
const ctx = offscreenCanvas.getContext("2d");
ctx.fillStyle = "red";
ctx.fillRect(0, 0, 32, 32);
const startTime = performance.now();
offscreenCanvas.convertToBlob({type: "image/png"}).then((blob) => {
postMessage(performance.now() - startTime);
});
}
self.addEventListener("message", (e) => {
if (e.data == "load") {
postMessage("loaded");
}
if (e.data == "start") {
offscreenCanvasToBlobOnWorker();
}
});
</script>
<script>
var isDone = false;
function invokeToBlobInWorker() {
const worker = new Worker(
URL.createObjectURL(
new Blob(
[document.querySelector("#worker").textContent],
{type: 'text/javascript'}
)
)
);
worker.postMessage("load");
worker.onmessage = e => {
if (e.data === "loaded")
worker.postMessage("start");
else {
PerfTestRunner.measureValueAsync(e.data);
if (!isDone) runTest();
}
}
}
function runTest() {
invokeToBlobInWorker();
}
window.onload = function () {
PerfTestRunner.startMeasureValuesAsync({
unit: 'ms',
done: function () {
isDone = true;
},
run: function() {
runTest();
},
description: "Measures the time for executing toBlob in a worker."
});
};
</script>
</body>
</html>
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
"putImageData.html", "putImageData.html",
"toBlob_duration.html", "toBlob_duration.html",
"toBlob_duration_jpeg.html", "toBlob_duration_jpeg.html",
"toBlob-small-canvas-in-worker.html",
"transferFromImageBitmap.html", "transferFromImageBitmap.html",
"upload-canvas-2d-to-texture.html", "upload-canvas-2d-to-texture.html",
"upload-video-to-sub-texture.html", "upload-video-to-sub-texture.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