mirror of
https://github.com/jech/galene.git
synced 2024-12-22 07:15:47 +01:00
Use ImageBitmap.close when no longer needed.
This should free the underlying textures without waiting for a GC to happen.
This commit is contained in:
parent
6e10da0116
commit
39c063a9d5
2 changed files with 50 additions and 39 deletions
|
@ -23,16 +23,20 @@ async function loadImageSegmenter() {
|
|||
loadImageSegmenter();
|
||||
|
||||
onmessage = e => {
|
||||
let bitmap = e.data.bitmap;
|
||||
if(!(bitmap instanceof ImageBitmap)) {
|
||||
postMessage(new Error('Bad type for worker data'));
|
||||
return;
|
||||
}
|
||||
|
||||
if(!imageSegmenter) {
|
||||
// not ready yet
|
||||
bitmap.close();
|
||||
postMessage(null);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
let bitmap = e.data.bitmap;
|
||||
if(!(bitmap instanceof ImageBitmap))
|
||||
throw new Error('Bad type for worker data');
|
||||
let width = bitmap.width;
|
||||
let height = bitmap.height;
|
||||
imageSegmenter.segmentForVideo(
|
||||
|
@ -52,6 +56,7 @@ onmessage = e => {
|
|||
},
|
||||
);
|
||||
} catch(e) {
|
||||
bitmap.close();
|
||||
postMessage(e);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1252,6 +1252,7 @@ let filters = {
|
|||
},
|
||||
draw: async function(src, ctx) {
|
||||
let bitmap = await createImageBitmap(src);
|
||||
try {
|
||||
let p = new Promise((resolve, reject) => {
|
||||
this.userdata.worker.onmessage = e => {
|
||||
if(e && e.data) {
|
||||
|
@ -1292,6 +1293,11 @@ let filters = {
|
|||
ctx.filter = 'none';
|
||||
ctx.drawImage(result.bitmap, 0, 0);
|
||||
ctx.globalCompositeOperation = 'source-over';
|
||||
|
||||
mask.close();
|
||||
} finally {
|
||||
bitmap.close();
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue