skia2/experimental/wasm-skp-debugger/helper.js
Nathaniel Nifong 00bb722628 missed minification bug
Check SKP file version, return error string to JS caller

Change-Id: I063920259e3ead102a4c7173d7015ff98992bbf2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/310338
Reviewed-by: Nathaniel Nifong <nifong@google.com>
Commit-Queue: Nathaniel Nifong <nifong@google.com>
2020-08-14 17:06:05 +00:00

28 lines
1.1 KiB
JavaScript

// Adds compile-time JS functions to augment the DebuggerView interface.
(function(DebuggerView){
DebuggerView.SkpFilePlayer = function(file_arraybuf) {
// Create the instance of SkpDebugPlayer
var player = new this.SkpDebugPlayer();
// Convert file (an ArrayBuffer) into a typedarray,
// otherwise fileMem.set() below seems to have no effect.
var fileContents = new Uint8Array(file_arraybuf);
var size = fileContents.byteLength;
// Allocate memory in wasm to hold the skp file selected by the user.
var fileMemPtr = this._malloc(size);
// Make a typed array view of that memory
var fileMem = new Uint8Array(DebuggerView.HEAPU8.buffer, fileMemPtr, size);
// Copy the file into it
fileMem.set(fileContents);
// Hand off pointer to wasm
var error = player.loadSkp(fileMemPtr, size);
// Free the memory that was used to hold the file, since it is now represented as an SkPicture
this._free(fileMemPtr)
return {
'error': error,
'player': player
};
}
}(Module)); // When this file is loaded in, the high level object is "Module";