try out webgl canvas, draw fast, but copy pixels out slow

This commit is contained in:
rustdesk
2022-02-07 00:16:27 +08:00
parent 809719b8c2
commit 7e335b36f5
4 changed files with 67 additions and 12 deletions

23
yuv.js
View File

@@ -1,3 +1,8 @@
/*
var window = {};
importScripts('./yuv-canvas-1.2.6.js');
*/
var wasmExports;
fetch('yuv.wasm').then(function (res) { return res.arrayBuffer(); })
@@ -58,13 +63,27 @@ function I420ToARGB(yb) {
}
var currentFrame;
var canvas;
var yuvCanvas;
self.addEventListener('message', (e) => {
currentFrame = e.data;
if (e.data.canvas) {
canvas = e.data.canvas;
yuvCanvas = window.YUVCanvas.attach(canvas, { webGL: true });
} else {
if (yuvCanvas) {
var now = new Date().getTime();
yuvCanvas.drawFrame(e.data);
console.log(new Date().getTime() - now);
} else {
currentFrame = e.data;
}
}
});
function run() {
if (currentFrame) {
self.postMessage(I420ToARGB(currentFrame));
var data = I420ToARGB(currentFrame);
self.postMessage(data, [data.buffer]);
currentFrame = undefined;
}
setTimeout(run, 1);