| Kevin Lubick | 933ea8c | 2020-01-06 08:10:05 -0500 | [diff] [blame] | 1 | CanvasKit._extraInitializations = CanvasKit._extraInitializations || []; |
| 2 | CanvasKit._extraInitializations.push(function() { |
| Kevin Lubick | a4f218d | 2020-01-14 08:39:09 -0500 | [diff] [blame] | 3 | // 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 Lubick | 933ea8c | 2020-01-06 08:10:05 -0500 | [diff] [blame] | 17 | // The serialized format of an SkPicture (informally called an "skp"), is not something |
| Kevin Lubick | a4f218d | 2020-01-14 08:39:09 -0500 | [diff] [blame] | 18 | // 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 Lubick | 933ea8c | 2020-01-06 08:10:05 -0500 | [diff] [blame] | 22 | 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 | }); |