2020-01-06 13:10:05 +00:00
|
|
|
CanvasKit._extraInitializations = CanvasKit._extraInitializations || [];
|
|
|
|
CanvasKit._extraInitializations.push(function() {
|
2020-01-14 13:39:09 +00:00
|
|
|
// data is a TypedArray or ArrayBuffer e.g. from fetch().then(resp.arrayBuffer())
|
|
|
|
CanvasKit.MakeSkPicture = function(data) {
|
|
|
|
data = new Uint8Array(data);
|
|
|
|
|
|
|
|
var iptr = CanvasKit._malloc(data.byteLength);
|
|
|
|
CanvasKit.HEAPU8.set(data, iptr);
|
|
|
|
var pic = CanvasKit._MakeSkPicture(iptr, data.byteLength);
|
|
|
|
if (!pic) {
|
|
|
|
SkDebug('Could not decode picture');
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return pic;
|
|
|
|
}
|
|
|
|
|
2020-01-06 13:10:05 +00:00
|
|
|
// The serialized format of an SkPicture (informally called an "skp"), is not something
|
2020-01-14 13:39:09 +00:00
|
|
|
// that clients should ever rely on. The format may change at anytime and no promises
|
|
|
|
// are made for backwards or forward compatibility.
|
|
|
|
CanvasKit.SkPicture.prototype.saveAsFile = function(skpName) {
|
|
|
|
var data = this.serialize();
|
2020-01-06 13:10:05 +00:00
|
|
|
if (!data) {
|
|
|
|
SkDebug('Could not serialize to skpicture.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var bytes = CanvasKit.getSkDataBytes(data);
|
|
|
|
saveBytesToFile(bytes, skpName);
|
|
|
|
data.delete();
|
|
|
|
}
|
|
|
|
});
|