skia2/modules/canvaskit/debugger.js
Nathaniel Nifong 3bf76ab829 Add debugger as an optional module in canvaskit
Change-Id: I7d866aab2a74bbb4c8d4f2cf7901d4b679c0cbe9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/515516
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Nathaniel Nifong <nifong@google.com>
2022-03-03 21:06:17 +00:00

27 lines
1.0 KiB
JavaScript

(function(CanvasKit){
CanvasKit.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(CanvasKit.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";