src/backend/canvas_backend.c now exists: the full required surface against a 2d canvas context through EM_JS. Draws are canvas paths, textures are offscreen canvases (putImageData/drawImage stay synchronous), text is glyph atlases rasterized from FontFace data (EM_ASYNC_JS awaits face loading), input flows through the KryonBackendRaw_* hooks fed by JS listeners, and the shared front-ends (kry_instance, kry_screenshot, kry_input) are honored via the KryonRaylibBackend_* seam names. Images decode through kryon's own kry_sw PNG decoder; no raylib anywhere in the link. The app while-loop survives the browser via -sASYNCIFY with a frame-end yield. make canvas-test builds a complete app with this backend under emcc and verifies the draw-call sequence in node against a recording Canvas2D shim (glyph rasterize, atlas upload, and per-glyph drawImage included); it skips cleanly where emcc is absent. Approximations documented in BACKENDS.md: square rounded rects, mid-radius ring strokes, no clipboard bridge, alpha-only tint.
48 lines
1.4 KiB
Bash
Executable File
48 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
# canvas backend test — builds a full kryon app with KRYON_BACKEND=canvas
|
|
# under emcc (no raylib) and runs it in node against a recording Canvas2D
|
|
# shim, asserting the draw call sequence. Requires emcc + node.
|
|
set -eu
|
|
|
|
root=$(cd "$(dirname "$0")/.." && pwd)
|
|
work=${TMPDIR:-/tmp}/kryon-canvas-test.$$
|
|
cleanup() { rm -rf "$work"; }
|
|
trap cleanup EXIT INT TERM
|
|
|
|
if ! command -v emcc >/dev/null 2>&1; then
|
|
if [ -x "$HOME/emsdk/upstream/emscripten/emcc" ]; then
|
|
PATH="$HOME/emsdk/upstream/emscripten:$PATH"
|
|
export PATH
|
|
fi
|
|
fi
|
|
if ! command -v emcc >/dev/null 2>&1; then
|
|
echo "canvas test: emcc not found (source ~/emsdk/emsdk_env.sh) — skipping" >&2
|
|
exit 0
|
|
fi
|
|
if ! command -v node >/dev/null 2>&1; then
|
|
echo "canvas test: node not found — skipping" >&2
|
|
exit 0
|
|
fi
|
|
|
|
mkdir -p "$work"
|
|
cp "$root/tests/canvas_smoke_main.c" "$work/main.c"
|
|
cp "$root/tests/canvas_smoke_run.js" "$work/run.js"
|
|
|
|
assets=""
|
|
for f in "$root"/build/*/embedded_asset_data.c; do
|
|
[ -f "$f" ] && assets=$f
|
|
done
|
|
if [ -z "$assets" ]; then
|
|
echo "canvas test: no embedded_asset_data.c (run 'make' once first) — skipping" >&2
|
|
exit 0
|
|
fi
|
|
|
|
srcs=$(find "$root/src" -name '*.c' ! -path '*/ksync/*' | sort | tr '\n' ' ')
|
|
|
|
emcc -I"$root/include" -I"$root/vendor/box2d/include" -O1 \
|
|
-sASYNCIFY -sENVIRONMENT=node,web -sINITIAL_MEMORY=64MB \
|
|
-o "$work/canvas_smoke.js" "$work/main.c" $srcs "$assets"
|
|
|
|
(cd "$work" && node run.js)
|
|
echo "canvas backend test ok"
|