Skip to content

Commit 33b445e

Browse files
committed
Reflect recent changes
1 parent a5d0b01 commit 33b445e

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ Install [Pixman](https://pixman.org/) before selecting the corresponding rendere
8383

8484
`Mado` supports multiple graphics backends. Choose one based on your deployment scenario:
8585
- SDL: Cross-platform desktop development with hardware acceleration
86+
- WebAssembly: Lightweight browser deployment using native Canvas API
8687
- Linux framebuffer (fbdev): Direct hardware access for embedded Linux
8788
- VNC: Remote display via Virtual Network Computing protocol
8889
- Headless: Testing and automation without display output
8990

90-
`Mado` uses SDL2 as the primary development and demonstration backend, providing cross-platform graphics with hardware acceleration. For other backend options (Linux framebuffer, VNC, headless), see [docs/backends.md](docs/backends.md).
91+
`Mado` uses SDL2 as the primary development and demonstration backend, providing cross-platform graphics with hardware acceleration.
92+
For web deployment, a dedicated WebAssembly backend directly uses the browser's Canvas API without SDL dependency, significantly reducing binary size. For all backend options and detailed build instructions, see [docs/backends.md](docs/backends.md).
9193

9294
Install the [SDL2 library](https://www.libsdl.org/):
9395
* macOS: `brew install sdl2`

docs/backends.md

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,15 @@ All backends maintain the same application interface, so switching between them
77
## Available Backends
88

99
### SDL Backend
10-
The SDL (Simple DirectMedia Layer) backend provides cross-platform graphics output with hardware acceleration support.
11-
It also serves as the only backend supporting WebAssembly/Emscripten builds for browser deployment.
10+
The SDL (Simple DirectMedia Layer) backend provides cross-platform graphics output with hardware acceleration support for native desktop platforms.
1211

1312
Features:
1413
- Cross-platform (Windows, macOS, Linux, etc.)
15-
- WebAssembly/Emscripten support for browser deployment
1614
- Hardware-accelerated rendering when available
1715
- Full keyboard and mouse input support
1816
- Windowed and fullscreen modes
1917
- Audio support (if needed)
2018

21-
#### Native Builds
22-
2319
Dependencies:
2420
Install the [SDL2 library](https://www.libsdl.org/):
2521
* macOS: `brew install sdl2`
@@ -38,9 +34,22 @@ Run:
3834

3935
Once the window appears, you can move windows and interact with widgets.
4036

41-
#### WebAssembly/Emscripten Builds
37+
Use Cases:
38+
- Desktop applications
39+
- Cross-platform development
40+
- Primary development and testing platform
41+
42+
### WebAssembly Backend
43+
Native WebAssembly backend providing direct Canvas API integration without SDL dependency,
44+
optimized for browser deployment.
4245

43-
The SDL backend can be compiled to WebAssembly using Emscripten, enabling Mado applications to run in web browsers.
46+
Features:
47+
- Direct Canvas 2D API rendering via Emscripten inline assembly
48+
- Browser-native image decoding (JPEG/PNG)
49+
- Lightweight implementation (no SDL dependency)
50+
- Single-threaded design using requestAnimationFrame
51+
- Direct memory access for efficient rendering
52+
- Event handling through exported C functions
4453

4554
Dependencies:
4655
Install the [Emscripten SDK](https://emscripten.org/):
@@ -59,16 +68,15 @@ source ./emsdk_env.sh
5968

6069
Build:
6170
```shell
62-
# The build system auto-detects Emscripten when CC=emcc
71+
# The build system auto-detects Emscripten and selects WASM backend
6372
make defconfig
6473
make CC=emcc
6574
```
6675

6776
The build system automatically:
6877
- Detects Emscripten compiler via `scripts/detect-compiler.py`
69-
- Restricts backend selection to SDL only (VNC/fbdev incompatible with WebAssembly)
78+
- Selects WebAssembly backend (other backends incompatible with WebAssembly)
7079
- Disables incompatible features (Cairo-based font editor)
71-
- Uses Emscripten's SDL2 port (no manual installation needed)
7280
- Copies build artifacts to `assets/web/` directory
7381

7482
Run:
@@ -82,7 +90,7 @@ python3 scripts/serve-wasm.py
8290
```
8391

8492
The web interface (`assets/web/index.html`) provides:
85-
- Canvas-based rendering with SDL2
93+
- Canvas-based rendering using native browser APIs
8694
- Keyboard and mouse event handling
8795
- Console output for debugging
8896
- Error reporting and status display
@@ -93,18 +101,23 @@ Browser Requirements:
93101
- JavaScript enabled
94102
- Hardware acceleration recommended for better performance
95103

104+
Architecture:
105+
- C code maintains framebuffer in WebAssembly linear memory
106+
- JavaScript accesses framebuffer via Module.HEAPU32
107+
- Direct ARGB32 → RGBA conversion in JavaScript
108+
- Canvas ImageData updated via putImageData()
109+
- Event callbacks inject events through exported C functions
110+
96111
Known Limitations:
97112
- Single-threaded execution (no WebWorkers support yet)
98113
- No direct file system access (use Emscripten's virtual filesystem)
99114
- Initial load time proportional to binary size
100115

101116
Use Cases:
102-
- Desktop applications
103-
- Cross-platform development
104-
- Primary development and testing platform
105117
- Web-based demonstrations and interactive tutorials
106118
- Browser-based UI prototyping
107119
- Client-side graphics applications without installation
120+
- Online documentation with live examples
108121

109122
### Linux Framebuffer (fbdev)
110123
Direct framebuffer access for embedded Linux systems without X11/Wayland.
@@ -238,12 +251,7 @@ Use Cases:
238251
Backends are selected at compile time through the Kconfig-based build system.
239252

240253
WebAssembly Compatibility Note:
241-
When compiling with Emscripten (`CC=emcc`), the build system automatically restricts backend selection to SDL only.
242-
The following backends are incompatible with WebAssembly:
243-
- VNC Backend: Requires native networking APIs not available in WebAssembly
244-
- Framebuffer Backend: Requires direct Linux kernel interfaces (`/dev/fb0`, ioctls)
245-
- Headless Backend: Requires POSIX shared memory APIs (`shm_open`, `mmap`)
246-
254+
When compiling with Emscripten (`CC=emcc`), the build system automatically selects the WebAssembly backend.
247255
The Kconfig system automatically enforces these restrictions when Emscripten is detected.
248256

249257
### Configuration Methods
@@ -252,9 +260,7 @@ Mado uses [Kconfiglib](https://github.com/sysprog21/Kconfiglib) for configuratio
252260

253261
Method 1: Interactive Configuration (best for exploration)
254262
```shell
255-
make config # Terminal-based menu
256-
# or
257-
make menuconfig # Alternative terminal interface
263+
make config # Terminal-based menu configuration
258264
make
259265
```
260266

@@ -406,20 +412,18 @@ make CFLAGS="-fsanitize=address -g"
406412
Each backend may have specific configuration options:
407413

408414
### SDL Backend
409-
410-
Native Configuration:
411415
- Window size and position
412416
- Fullscreen mode toggle
413417
- Hardware acceleration preferences
414418
- VSync settings
415419

416-
WebAssembly Configuration:
420+
### WebAssembly Backend
417421
- Canvas element ID (default: `#canvas`, configured in `assets/web/index.html`)
418-
- Keyboard input element (set via `SDL_EMSCRIPTEN_KEYBOARD_ELEMENT`)
419422
- Initial canvas size (640x480 default, configurable in HTML)
420423
- Browser console logging (enabled by default for debugging)
421424
- Main loop timing (managed by `emscripten_set_main_loop_arg`)
422425
- Memory allocation limits (configurable via Emscripten linker flags)
426+
- Framebuffer format conversion (ARGB32 → RGBA handled in JavaScript)
423427

424428
### Framebuffer Backend
425429
- Device path (default: `/dev/fb0`)

0 commit comments

Comments
 (0)