Nathaniel Nifong | 298390e | 2019-04-05 13:39:31 -0400 | [diff] [blame^] | 1 | // 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 |
| 14 | var fileMem = new Uint8Array(this.buffer, fileMemPtr, size); |
| 15 | // 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"; |