[Canvas worker] transfer control only if needed
diff --git a/player/js/worker_wrapper.js b/player/js/worker_wrapper.js
index 97f5e42..a52ac7a 100644
--- a/player/js/worker_wrapper.js
+++ b/player/js/worker_wrapper.js
@@ -715,17 +715,22 @@
delete animationParams.container;
}
if (animationParams.renderer === 'canvas') {
+ var canvas = document.createElement('canvas');
+
+ // If no custom canvas was passed
if (!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();
- animationParams.rendererSettings.canvas = offscreen;
+ } else {
+ canvas = animationParams.rendererSettings.canvas;
}
+ // 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;