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())
|
2020-10-07 20:09:22 +00:00
|
|
|
CanvasKit.MakePicture = function(data) {
|
2020-01-14 13:39:09 +00:00
|
|
|
data = new Uint8Array(data);
|
|
|
|
|
|
|
|
var iptr = CanvasKit._malloc(data.byteLength);
|
|
|
|
CanvasKit.HEAPU8.set(data, iptr);
|
2020-10-07 20:09:22 +00:00
|
|
|
var pic = CanvasKit._MakePicture(iptr, data.byteLength);
|
2020-01-14 13:39:09 +00:00
|
|
|
if (!pic) {
|
2020-10-07 20:09:22 +00:00
|
|
|
Debug('Could not decode picture');
|
2020-01-14 13:39:09 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return pic;
|
|
|
|
}
|
|
|
|
|
2020-10-07 20:09:22 +00:00
|
|
|
// The serialized format of an Picture (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.
|
2020-10-07 20:09:22 +00:00
|
|
|
CanvasKit.Picture.prototype.saveAsFile = function(skpName) {
|
2020-01-14 13:39:09 +00:00
|
|
|
var data = this.serialize();
|
2020-01-06 13:10:05 +00:00
|
|
|
if (!data) {
|
2020-10-07 20:09:22 +00:00
|
|
|
Debug('Could not serialize to skpicture.');
|
2020-01-06 13:10:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-10-07 20:09:22 +00:00
|
|
|
var bytes = CanvasKit.getDataBytes(data);
|
2020-01-06 13:10:05 +00:00
|
|
|
saveBytesToFile(bytes, skpName);
|
|
|
|
data.delete();
|
|
|
|
}
|
2020-10-07 20:09:22 +00:00
|
|
|
});
|