blob: 684d14ec5920d444ed5d8acad1a4847029789982 [file] [log] [blame]
Kevin Lubick933ea8c2020-01-06 08:10:05 -05001CanvasKit._extraInitializations = CanvasKit._extraInitializations || [];
2CanvasKit._extraInitializations.push(function() {
Kevin Lubicka4f218d2020-01-14 08:39:09 -05003 // data is a TypedArray or ArrayBuffer e.g. from fetch().then(resp.arrayBuffer())
4 CanvasKit.MakeSkPicture = function(data) {
5 data = new Uint8Array(data);
6
7 var iptr = CanvasKit._malloc(data.byteLength);
8 CanvasKit.HEAPU8.set(data, iptr);
9 var pic = CanvasKit._MakeSkPicture(iptr, data.byteLength);
10 if (!pic) {
11 SkDebug('Could not decode picture');
12 return null;
13 }
14 return pic;
15 }
16
Kevin Lubick933ea8c2020-01-06 08:10:05 -050017 // The serialized format of an SkPicture (informally called an "skp"), is not something
Kevin Lubicka4f218d2020-01-14 08:39:09 -050018 // that clients should ever rely on. The format may change at anytime and no promises
19 // are made for backwards or forward compatibility.
20 CanvasKit.SkPicture.prototype.saveAsFile = function(skpName) {
21 var data = this.serialize();
Kevin Lubick933ea8c2020-01-06 08:10:05 -050022 if (!data) {
23 SkDebug('Could not serialize to skpicture.');
24 return;
25 }
26 var bytes = CanvasKit.getSkDataBytes(data);
27 saveBytesToFile(bytes, skpName);
28 data.delete();
29 }
30});