Skip to content

Commit 62aaf7e

Browse files
committed
Reflect recent changes
1 parent 3ec1f5e commit 62aaf7e

File tree

1 file changed

+109
-23
lines changed

1 file changed

+109
-23
lines changed

docs/backends.md

Lines changed: 109 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,119 @@ All backends maintain the same application interface, so switching between them
88

99
### SDL Backend
1010
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.
1112

12-
**Features:**
13+
Features:
1314
- Cross-platform (Windows, macOS, Linux, etc.)
15+
- WebAssembly/Emscripten support for browser deployment
1416
- Hardware-accelerated rendering when available
1517
- Full keyboard and mouse input support
1618
- Windowed and fullscreen modes
1719
- Audio support (if needed)
1820

19-
**Dependencies:**
21+
#### Native Builds
22+
23+
Dependencies:
2024
Install the [SDL2 library](https://www.libsdl.org/):
2125
* macOS: `brew install sdl2`
2226
* Ubuntu Linux / Debian: `sudo apt install libsdl2-dev`
2327

24-
**Build:**
28+
Build:
2529
```shell
2630
make defconfig # SDL backend is enabled by default
2731
make
2832
```
2933

30-
**Run:**
34+
Run:
3135
```shell
3236
./demo-sdl
3337
```
3438

3539
Once the window appears, you can move windows and interact with widgets.
3640

37-
**Use Cases:**
41+
#### WebAssembly/Emscripten Builds
42+
43+
The SDL backend can be compiled to WebAssembly using Emscripten, enabling Mado applications to run in web browsers.
44+
45+
Dependencies:
46+
Install the [Emscripten SDK](https://emscripten.org/):
47+
```shell
48+
# Clone the Emscripten SDK
49+
git clone https://github.com/emscripten-core/emsdk
50+
cd emsdk
51+
52+
# Install and activate the latest version
53+
./emsdk install latest
54+
./emsdk activate latest
55+
56+
# Add Emscripten to your PATH (add to ~/.bashrc or ~/.zshrc)
57+
source ./emsdk_env.sh
58+
```
59+
60+
Build:
61+
```shell
62+
# The build system auto-detects Emscripten when CC=emcc
63+
make defconfig
64+
make CC=emcc
65+
```
66+
67+
The build system automatically:
68+
- Detects Emscripten compiler via `scripts/detect-compiler.py`
69+
- Restricts backend selection to SDL only (VNC/fbdev incompatible with WebAssembly)
70+
- Disables incompatible features (Cairo-based font editor)
71+
- Uses Emscripten's SDL2 port (no manual installation needed)
72+
- Copies build artifacts to `assets/web/` directory
73+
74+
Run:
75+
```shell
76+
# Start the development server
77+
./scripts/serve-wasm.py --open
78+
79+
# Or manually:
80+
python3 scripts/serve-wasm.py
81+
# Then open http://localhost:8080 in your browser
82+
```
83+
84+
The web interface (`assets/web/index.html`) provides:
85+
- Canvas-based rendering with SDL2
86+
- Keyboard and mouse event handling
87+
- Console output for debugging
88+
- Error reporting and status display
89+
- Automatic module loading and initialization
90+
91+
Browser Requirements:
92+
- Modern browser with WebAssembly support (Chrome 57+, Firefox 52+, Safari 11+, Edge 16+)
93+
- JavaScript enabled
94+
- Hardware acceleration recommended for better performance
95+
96+
Known Limitations:
97+
- Single-threaded execution (no WebWorkers support yet)
98+
- No direct file system access (use Emscripten's virtual filesystem)
99+
- Initial load time proportional to binary size
100+
101+
Use Cases:
38102
- Desktop applications
39103
- Cross-platform development
40104
- Primary development and testing platform
105+
- Web-based demonstrations and interactive tutorials
106+
- Browser-based UI prototyping
107+
- Client-side graphics applications without installation
41108

42109
### Linux Framebuffer (fbdev)
43110
Direct framebuffer access for embedded Linux systems without X11/Wayland.
44111

45-
**Features:**
112+
Features:
46113
- Direct hardware access
47114
- Minimal dependencies
48115
- Built-in cursor support
49116
- Linux input subsystem integration
50117
- Virtual terminal switching support
51118

52-
**Dependencies:**
119+
Dependencies:
53120
Install `libudev` and `libuuid`:
54121
* Ubuntu Linux / Debian: `sudo apt install libudev-dev uuid-dev`
55122

56-
**Build:**
123+
Build:
57124
```shell
58125
make defconfig
59126
python3 tools/kconfig/setconfig.py --kconfig configs/Kconfig \
@@ -62,7 +129,7 @@ python3 tools/kconfig/setconfig.py --kconfig configs/Kconfig \
62129
make
63130
```
64131

65-
**Run:**
132+
Run:
66133
```shell
67134
sudo ./demo-fbdev
68135
```
@@ -74,7 +141,7 @@ sudo usermod -a -G video $USERNAME
74141

75142
The framebuffer device can be assigned via the environment variable `FRAMEBUFFER`.
76143

77-
**Use Cases:**
144+
Use Cases:
78145
- Embedded Linux systems
79146
- Kiosk applications
80147
- Boot splash screens
@@ -83,20 +150,20 @@ The framebuffer device can be assigned via the environment variable `FRAMEBUFFER
83150
### VNC Backend
84151
Provides remote display capabilities through the VNC (Virtual Network Computing) protocol.
85152

86-
**Features:**
153+
Features:
87154
- Remote access over network
88155
- Multiple client support
89156
- Platform-independent clients
90157
- Built-in authentication
91158
- Compression support
92159

93-
**Dependencies:**
160+
Dependencies:
94161
Install [neatvnc](https://github.com/any1/neatvnc). Note: The VNC backend has only been tested on GNU/Linux, and prebuilt packages might be outdated. To ensure the latest version, build from source:
95162
```shell
96163
tools/build-neatvnc.sh
97164
```
98165

99-
**Build:**
166+
Build:
100167
```shell
101168
make defconfig
102169
python3 tools/kconfig/setconfig.py --kconfig configs/Kconfig \
@@ -105,7 +172,7 @@ python3 tools/kconfig/setconfig.py --kconfig configs/Kconfig \
105172
make
106173
```
107174

108-
**Run:**
175+
Run:
109176
```shell
110177
./demo-vnc
111178
```
@@ -114,7 +181,7 @@ This starts the VNC server. Connect using any VNC client with the specified IP a
114181
- IP address: Set via `MADO_VNC_HOST` environment variable
115182
- Port: Set via `MADO_VNC_PORT` environment variable
116183

117-
**Use Cases:**
184+
Use Cases:
118185
- Remote desktop applications
119186
- Server-side rendering
120187
- Thin client deployments
@@ -123,17 +190,17 @@ This starts the VNC server. Connect using any VNC client with the specified IP a
123190
### Headless Backend
124191
Renders to a memory buffer without any display output, ideal for testing and automation.
125192

126-
**Features:**
193+
Features:
127194
- No display dependencies
128195
- Shared memory architecture
129196
- Screenshot capability
130197
- Event injection for testing
131198
- Memory debugging friendly
132199

133-
**Dependencies:**
200+
Dependencies:
134201
No additional dependencies required. This backend uses shared memory for rendering.
135202

136-
**Build:**
203+
Build:
137204
```shell
138205
# Using setconfig.py (recommended)
139206
make defconfig
@@ -149,7 +216,7 @@ make config # Select "Headless backend" and "Headless control tool"
149216
make
150217
```
151218

152-
**Run:**
219+
Run:
153220
```shell
154221
./demo-headless &
155222
./headless-ctl status # Check backend status
@@ -159,7 +226,7 @@ make
159226

160227
The headless backend uses shared memory for rendering without display output. Use `headless-ctl` to monitor, control, and capture screenshots.
161228

162-
**Use Cases:**
229+
Use Cases:
163230
- Automated testing
164231
- CI/CD pipelines
165232
- Memory analysis with Valgrind or AddressSanitizer
@@ -170,19 +237,28 @@ The headless backend uses shared memory for rendering without display output. Us
170237

171238
Backends are selected at compile time through the Kconfig-based build system.
172239

240+
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+
247+
The Kconfig system automatically enforces these restrictions when Emscripten is detected.
248+
173249
### Configuration Methods
174250

175251
Mado uses [Kconfiglib](https://github.com/sysprog21/Kconfiglib) for configuration management, providing several methods to configure backends:
176252

177-
**Method 1: Interactive Configuration** (best for exploration)
253+
Method 1: Interactive Configuration (best for exploration)
178254
```shell
179255
make config # Terminal-based menu
180256
# or
181257
make menuconfig # Alternative terminal interface
182258
make
183259
```
184260

185-
**Method 2: Using `setconfig.py`** (best for scripting)
261+
Method 2: Using `setconfig.py` (best for scripting)
186262
```shell
187263
make defconfig
188264
python3 tools/kconfig/setconfig.py --kconfig configs/Kconfig \
@@ -196,7 +272,7 @@ Advantages:
196272
- No need to manually edit `.config`
197273
- Symbol names don't require `CONFIG_` prefix
198274

199-
**Method 3: Configuration Fragments** (best for CI/CD)
275+
Method 3: Configuration Fragments (best for CI/CD)
200276
```shell
201277
# Create a fragment file (e.g., configs/mybackend.fragment)
202278
# Contents: CONFIG_BACKEND_SDL=y
@@ -330,11 +406,21 @@ make CFLAGS="-fsanitize=address -g"
330406
Each backend may have specific configuration options:
331407

332408
### SDL Backend
409+
410+
Native Configuration:
333411
- Window size and position
334412
- Fullscreen mode toggle
335413
- Hardware acceleration preferences
336414
- VSync settings
337415

416+
WebAssembly Configuration:
417+
- Canvas element ID (default: `#canvas`, configured in `assets/web/index.html`)
418+
- Keyboard input element (set via `SDL_EMSCRIPTEN_KEYBOARD_ELEMENT`)
419+
- Initial canvas size (640x480 default, configurable in HTML)
420+
- Browser console logging (enabled by default for debugging)
421+
- Main loop timing (managed by `emscripten_set_main_loop_arg`)
422+
- Memory allocation limits (configurable via Emscripten linker flags)
423+
338424
### Framebuffer Backend
339425
- Device path (default: `/dev/fb0`)
340426
- Input device configuration

0 commit comments

Comments
 (0)