What Was I Trying to Do?
In rural and divisional schools in Bangladesh, online learning platforms often fail due to unstable 3G/4G bandwidth and low-end Android tablets. I wanted to design Omnidesk BD as a lightweight, zero-bloat collaborative learning environment where interactive math, geometry, and lecture slides render smoothly at 60 FPS even on budget devices.
The Canvas Architecture
User Touch/Pen Event ➔ Coordinate Smoothing (Catmull-Rom) ➔ Offscreen Canvas Buffer ➔ Direct Viewport Blit ➔ Micro-Delta Broadcast (WebSockets)
- Double-Buffering & Offscreen Canvas:
- Instead of rendering vectors directly to the visible DOM, all pen strokes are drawn to an in-memory
OffscreenCanvas. - The main rendering loop simply executes
ctx.drawImage(offscreenBuffer, 0, 0)onrequestAnimationFrame, eliminating layout thrashing.
- Instead of rendering vectors directly to the visible DOM, all pen strokes are drawn to an in-memory
- Bezier Path Smoothing:
- Raw pointer events arrive at irregular intervals. I implemented quadratic Bezier curve interpolation between consecutive sample points to avoid jagged polygonal strokes.
- Bandwidth Optimization:
- Instead of broadcasting raw mouse coordinates at 60Hz, pen strokes are bundled into compressed differential coordinate packets (
dx, dyrelative to stroke origin).
- Instead of broadcasting raw mouse coordinates at 60Hz, pen strokes are bundled into compressed differential coordinate packets (
Key Highlights & Performance
- Touch-to-Render Latency: Achieved sub-16ms drawing feedback (under 1 frame drop at 60Hz).
- Network Payload: Full session delta broadcast required less than 4.2 KB per active drawing minute.
- Local Fallback: Offline caching via IndexedDB allows full lecture note preservation when internet connectivity drops.
What I Learned
Vector memory will leak quickly in long drawing sessions if past strokes are kept as individual object instances. Flattening completed strokes onto a rasterized background layer after 15 seconds of inactivity reduced memory usage from 420MB down to a stable 48MB.