2019-02-28 15:06:18 +00:00
|
|
|
// Adds compile-time JS functions to augment the CanvasKit interface.
|
|
|
|
// Specifically, anything that should only be on the Skottie builds of canvaskit.
|
|
|
|
|
2019-11-27 15:34:18 +00:00
|
|
|
// assets is a dictionary of named blobs: { key: ArrayBuffer, ... }
|
|
|
|
// The keys should be well-behaved strings - they're turned into null-terminated
|
|
|
|
// strings for the native side.
|
2019-02-28 22:48:31 +00:00
|
|
|
CanvasKit.MakeManagedAnimation = function(json, assets) {
|
2019-02-28 15:06:18 +00:00
|
|
|
if (!CanvasKit._MakeManagedAnimation) {
|
|
|
|
throw 'Not compiled with MakeManagedAnimation';
|
|
|
|
}
|
2019-02-28 22:48:31 +00:00
|
|
|
if (!assets) {
|
|
|
|
return CanvasKit._MakeManagedAnimation(json, 0, nullptr, nullptr, nullptr);
|
2019-02-28 15:06:18 +00:00
|
|
|
}
|
2019-02-28 22:48:31 +00:00
|
|
|
var assetNamePtrs = [];
|
|
|
|
var assetDataPtrs = [];
|
|
|
|
var assetSizes = [];
|
|
|
|
|
|
|
|
var assetKeys = Object.keys(assets || {});
|
|
|
|
for (var i = 0; i < assetKeys.length; i++) {
|
|
|
|
var key = assetKeys[i];
|
|
|
|
var buffer = assets[key];
|
2019-02-28 15:06:18 +00:00
|
|
|
var data = new Uint8Array(buffer);
|
|
|
|
|
|
|
|
var iptr = CanvasKit._malloc(data.byteLength);
|
|
|
|
CanvasKit.HEAPU8.set(data, iptr);
|
2019-02-28 22:48:31 +00:00
|
|
|
assetDataPtrs.push(iptr);
|
|
|
|
assetSizes.push(data.byteLength);
|
2019-02-28 15:06:18 +00:00
|
|
|
|
|
|
|
// lengthBytesUTF8 and stringToUTF8Array are defined in the emscripten
|
|
|
|
// JS. See https://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html#stringToUTF8
|
|
|
|
// Add 1 for null terminator
|
|
|
|
var strLen = lengthBytesUTF8(key) + 1;
|
|
|
|
var strPtr = CanvasKit._malloc(strLen);
|
|
|
|
|
|
|
|
stringToUTF8(key, strPtr, strLen);
|
2019-02-28 22:48:31 +00:00
|
|
|
assetNamePtrs.push(strPtr);
|
2019-02-28 21:05:09 +00:00
|
|
|
}
|
|
|
|
|
2019-02-28 15:06:18 +00:00
|
|
|
// Not entirely sure if it matters, but the uintptr_t are 32 bits
|
|
|
|
// we want to copy our array of uintptr_t into the right size memory.
|
2019-02-28 22:48:31 +00:00
|
|
|
var namesPtr = copy1dArray(assetNamePtrs, CanvasKit.HEAPU32);
|
|
|
|
var assetsPtr = copy1dArray(assetDataPtrs, CanvasKit.HEAPU32);
|
|
|
|
var assetSizesPtr = copy1dArray(assetSizes, CanvasKit.HEAPU32);
|
2019-02-28 21:05:09 +00:00
|
|
|
|
2019-02-28 22:48:31 +00:00
|
|
|
var anim = CanvasKit._MakeManagedAnimation(json, assetKeys.length, namesPtr,
|
|
|
|
assetsPtr, assetSizesPtr);
|
2019-02-28 15:06:18 +00:00
|
|
|
|
2019-11-27 15:34:18 +00:00
|
|
|
// The C++ code has made copies of the asset and string data, so free our copies.
|
2019-02-28 22:48:31 +00:00
|
|
|
CanvasKit._free(namesPtr);
|
|
|
|
CanvasKit._free(assetsPtr);
|
|
|
|
CanvasKit._free(assetSizesPtr);
|
2019-02-28 15:06:18 +00:00
|
|
|
|
|
|
|
return anim;
|
|
|
|
};
|
2020-05-04 20:46:17 +00:00
|
|
|
|
|
|
|
(function(CanvasKit){
|
|
|
|
CanvasKit._extraInitializations = CanvasKit._extraInitializations || [];
|
|
|
|
CanvasKit._extraInitializations.push(function() {
|
|
|
|
|
|
|
|
CanvasKit.ManagedAnimation.prototype.setColor = function(key, color) {
|
|
|
|
var cPtr = copy1dArray(color, CanvasKit.HEAPF32);
|
|
|
|
this._setColor(key, cPtr);
|
|
|
|
CanvasKit._free(cPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}(Module)); // When this file is loaded in, the high level object is "Module";
|