mirror of
https://github.com/jech/galene.git
synced 2024-12-22 15:25:48 +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();
|
loadImageSegmenter();
|
||||||
|
|
||||||
onmessage = e => {
|
onmessage = e => {
|
||||||
|
let bitmap = e.data.bitmap;
|
||||||
|
if(!(bitmap instanceof ImageBitmap)) {
|
||||||
|
postMessage(new Error('Bad type for worker data'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(!imageSegmenter) {
|
if(!imageSegmenter) {
|
||||||
// not ready yet
|
// not ready yet
|
||||||
|
bitmap.close();
|
||||||
postMessage(null);
|
postMessage(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let bitmap = e.data.bitmap;
|
|
||||||
if(!(bitmap instanceof ImageBitmap))
|
|
||||||
throw new Error('Bad type for worker data');
|
|
||||||
let width = bitmap.width;
|
let width = bitmap.width;
|
||||||
let height = bitmap.height;
|
let height = bitmap.height;
|
||||||
imageSegmenter.segmentForVideo(
|
imageSegmenter.segmentForVideo(
|
||||||
|
@ -52,6 +56,7 @@ onmessage = e => {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
bitmap.close();
|
||||||
postMessage(e);
|
postMessage(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1252,6 +1252,7 @@ let filters = {
|
||||||
},
|
},
|
||||||
draw: async function(src, ctx) {
|
draw: async function(src, ctx) {
|
||||||
let bitmap = await createImageBitmap(src);
|
let bitmap = await createImageBitmap(src);
|
||||||
|
try {
|
||||||
let p = new Promise((resolve, reject) => {
|
let p = new Promise((resolve, reject) => {
|
||||||
this.userdata.worker.onmessage = e => {
|
this.userdata.worker.onmessage = e => {
|
||||||
if(e && e.data) {
|
if(e && e.data) {
|
||||||
|
@ -1292,6 +1293,11 @@ let filters = {
|
||||||
ctx.filter = 'none';
|
ctx.filter = 'none';
|
||||||
ctx.drawImage(result.bitmap, 0, 0);
|
ctx.drawImage(result.bitmap, 0, 0);
|
||||||
ctx.globalCompositeOperation = 'source-over';
|
ctx.globalCompositeOperation = 'source-over';
|
||||||
|
|
||||||
|
mask.close();
|
||||||
|
} finally {
|
||||||
|
bitmap.close();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue