bffc116a4a
To load in the resources, we have the Node JS script find all files in the provided resources directory and serve that as a JSON file (the HTML JS can't list files easily). The HTML JS reads that file, then loads all those files as ArrayBuffers. After the testing WASM and the resources all load, we pre-load them into the WASM memory, assigned with their name. This is just a map of name -> SkData. The WASM code can't (easily) make fetch calls, so rather than load these resources on demand like we would in a real file system, we pre-load them all and serve them from RAM. For simplicity (and consistency with the known_hashes), this map is a global. Finally, to connect the resources to the GMs, we overwrite the gResourceFactory (defined in ResourceFactory.h) which is used by tools/Resources.cpp to load any resource file (in theory). One more change is to write some progress steps to window._log so it can be read by puppeteer and dumped to disk to aid in debugging. Bug: skia:10812 Change-Id: Ie22c7f4b8d7cbbd18173b4e2ed755105c1b45249 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/328901 Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
// When this file is loaded in, the high level object is "Module";
|
|
var WasmGMTests = Module;
|
|
WasmGMTests.onRuntimeInitialized = function() {
|
|
|
|
WasmGMTests.GetWebGLContext = function(canvas, webGLVersion) {
|
|
if (!canvas) {
|
|
throw 'null canvas passed into makeWebGLContext';
|
|
}
|
|
if (webGLVersion !== 1 && webGLVersion !== 2 ) {
|
|
throw 'invalid webGLVersion';
|
|
}
|
|
var contextAttributes = {
|
|
'alpha': 1,
|
|
'depth': 0, // can be 0 because off-screen.
|
|
'stencil': 0, // can be 0 because off-screen.
|
|
'antialias': 0,
|
|
'premultipliedAlpha': 1,
|
|
'preserveDrawingBuffer': 0,
|
|
'preferLowPowerToHighPerformance': 0,
|
|
'failIfMajorPerformanceCaveat': 0,
|
|
'enableExtensionsByDefault': 1,
|
|
'explicitSwapControl': 0,
|
|
'renderViaOffscreenBackBuffer': 0,
|
|
'majorVersion': webGLVersion,
|
|
};
|
|
|
|
// Creates a WebGL context and sets it to be the current context.
|
|
// These functions are defined in emscripten's library_webgl.js
|
|
var handle = GL.createContext(canvas, contextAttributes);
|
|
if (!handle) {
|
|
return 0;
|
|
}
|
|
GL.makeContextCurrent(handle);
|
|
return handle;
|
|
};
|
|
|
|
WasmGMTests.LoadResource = function(name, buffer) {
|
|
// The WASM memory will take ownership of this pointer.
|
|
var bytePtr = copyArrayBuffer(buffer);
|
|
WasmGMTests._LoadResource(name, bytePtr, buffer.byteLength);
|
|
}
|
|
|
|
function copyArrayBuffer(buffer) {
|
|
var ptr = WasmGMTests._malloc(buffer.byteLength);
|
|
WasmGMTests.HEAPU8.set(new Uint8Array(buffer), ptr);
|
|
return ptr;
|
|
}
|
|
|
|
}
|