Skip to content

Commit

Permalink
added canvas methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bodymovin committed Nov 8, 2021
1 parent d33c526 commit 65e5a81
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions player/js/module_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function workerContent() {
wrapper = document.createElement('div');
params.container = wrapper;
} else {
var canvas = params.canvas;
var canvas = params.rendererSettings.canvas;
var ctx = canvas.getContext('2d');
params.rendererSettings.context = ctx;
}
Expand Down Expand Up @@ -335,6 +335,10 @@ function workerContent() {
animations[payload.id].destroy();
animations[payload.id] = null;
}
} else if (type === 'resize') {
if (animations[payload.id]) {
animations[payload.id].resize();
}
}
};
}
Expand Down Expand Up @@ -602,22 +606,42 @@ var lottie = (function () {
},
});
},
resize: function () {
workerInstance.postMessage({
type: 'resize',
payload: {
id: animationId,
},
});
},
};
animation.animInstance = animInstance;
resolveAnimationData(params)
.then(function (animationParams) {
var transferedObjects = [];
if (animationParams.container) {
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);
animationParams.rendererSettings.canvas = offscreen;
}
animations[animationId] = animation;
workerInstance.postMessage({
type: 'load',
payload: {
params: animationParams,
id: animationId,
},
});
}, transferedObjects);
});
return animInstance;
}
Expand Down

0 comments on commit 65e5a81

Please sign in to comment.