Files
kryon/cmd/krb-web/node-capture.js
T
waozi f2e86d9f0d krb-web: native web engine — kry_sw compiled to wasm, blitted to ImageData
Plan 11 phase 3, wasm-first variant (pixel-identical to native):

- cmd/krb-web/main.c: emscripten host running the KRB runtime + kry_sw
  rasterizer; each frame blits the RGBA buffer into an ImageData via
  EM_ASM. Cartridge preloaded at /app.krb, canvas mouse events fed back
  through exported krb_web_mouse/krb_web_button.
- cmd/krb-web/shell.html: minimal shell wiring Module.canvas and input.
- cmd/krb-web/node-capture.js: pre-js for the KRB_WEB_ONESHOT node
  build; stubs a canvas 2D context and dumps the blitted frame to stdout
  so the wasm blit path is testable without a browser.
- make krb-web KRB=examples/xx.kry builds the cartridge + bundle
  (needs emcc on PATH, e.g. source ~/emsdk/emsdk_env.sh).

Verified: node oneshot capture of examples/02_buttons.kry at 800x600 is
byte-identical (sha256) to the native krb-run render; page loads and
runs in a browser.
2026-08-16 20:21:36 -03:00

34 lines
1.1 KiB
JavaScript

/* Pre-js for the KRB_WEB_ONESHOT node build: stubs a canvas whose 2D
* context records the blitted ImageData, so the wasm blit path can be
* byte-compared against the native kry_sw frame without a browser. */
var Module = {
printErr: function(t) { console.error(t); },
canvas: {
getContext: function() {
return {
createImageData: function(w, h) {
return { width: w, height: h,
data: new Uint8ClampedArray(w * h * 4) };
},
putImageData: function(img) {
if (globalThis.__krb_frame)
return;
globalThis.__krb_frame = Buffer.from(img.data);
}
};
}
},
onRuntimeInitialized: function() {
var FS = Module.FS;
if (FS)
console.error('FS root: ' + FS.readdir('/').join(','));
},
onExit: function() {
if (!globalThis.__krb_frame) {
console.error('node-capture: no frame captured');
process.exit(1);
}
process.stdout.write(globalThis.__krb_frame);
}
};