blob: 9e2a202a13866ab6cfade9b74661ae7e9f124019 [file] [log] [blame]
Nathaniel Nifong298390e2019-04-05 13:39:31 -04001// Adds compile-time JS functions to augment the DebuggerView interface.
2(function(DebuggerView){
3
4 DebuggerView.SkpFilePlayer = function(file_arraybuf) {
5 // Create the instance of SkpDebugPlayer
6 var player = new this.SkpDebugPlayer();
7 // Convert file (an ArrayBuffer) into a typedarray,
8 // otherwise fileMem.set() below seems to have no effect.
9 var fileContents = new Uint8Array(file_arraybuf);
10 var size = fileContents.byteLength;
11 // Allocate memory in wasm to hold the skp file selected by the user.
12 var fileMemPtr = this._malloc(size);
13 // Make a typed array view of that memory
Kevin Lubick957bf972019-10-10 07:35:05 -040014 var fileMem = new Uint8Array(DebuggerView.HEAPU8.buffer, fileMemPtr, size);
Nathaniel Nifong298390e2019-04-05 13:39:31 -040015 // Copy the file into it
16 fileMem.set(fileContents);
17 // Hand off pointer to wasm
18 player.loadSkp(fileMemPtr, size);
19 // Free the memory that was used to hold the file, since it is now represented as an SkPicture
20 this._free(fileMemPtr)
21 return player;
22 }
23
24}(Module)); // When this file is loaded in, the high level object is "Module";