Merge pull request #2783 from knenkne/fix/worker-own-canvas
[Canvas worker] pass own canvas fix
diff --git a/player/js/worker_wrapper.js b/player/js/worker_wrapper.js
index 21cdbed..710a0cd 100644
--- a/player/js/worker_wrapper.js
+++ b/player/js/worker_wrapper.js
@@ -714,16 +714,23 @@
animation.container = animationParams.container;
delete animationParams.container;
}
- if (animationParams.renderer === 'canvas' && !animationParams.rendererSettings.canvas) {
- var canvas = document.createElement('canvas');
- animation.container.appendChild(canvas);
- canvas.width = animationParams.animationData.w;
- canvas.height = animationParams.animationData.h;
- canvas.style.width = '100%';
- canvas.style.height = '100%';
- var offscreen = canvas.transferControlToOffscreen();
- transferedObjects.push(offscreen);
+ if (animationParams.renderer === 'canvas') {
+ var canvas = animationParams.rendererSettings.canvas;
+
+ // If no custom canvas was passed
+ if (!canvas) {
+ canvas = document.createElement('canvas');
+ animation.container.appendChild(canvas);
+ canvas.width = animationParams.animationData.w;
+ canvas.height = animationParams.animationData.h;
+ canvas.style.width = '100%';
+ canvas.style.height = '100%';
+ }
+
+ // Transfer control to offscreen if it's not already
+ var offscreen = canvas instanceof OffscreenCanvas ? canvas : canvas.transferControlToOffscreen();
animationParams.rendererSettings.canvas = offscreen;
+ transferedObjects.push(animationParams.rendererSettings.canvas);
}
animations[animationId] = animation;
workerInstance.postMessage({