# rust-windowing/softbuffer architecture

> Architecture diagram of the GitHub repository rust-windowing/softbuffer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rust-windowing/softbuffer
- Repository: https://github.com/rust-windowing/softbuffer

## Overview

Softbuffer is a cross-platform CPU image presentation library: an application supplies a window/display handle, obtains a writable surface buffer, draws pixels, and presents it. The public API dispatches through a backend interface to platform-specific presentation implementations; the README describes compositor handoff and double buffering. Platform source is only sampled for some backends, so platform-specific internals and compositor links are limited to documented or excerpted relationships.

Main entry points: [`src/backends/mod.rs`](https://github.com/rust-windowing/softbuffer/blob/master/src/backends/mod.rs) (Platform Registry), [`src/util.rs`](https://github.com/rust-windowing/softbuffer/blob/master/src/util.rs) (Buffer Utilities), [`src/lib.rs`](https://github.com/rust-windowing/softbuffer/blob/master/src/lib.rs) (Context and Surface), [`src/backend_dispatch.rs`](https://github.com/rust-windowing/softbuffer/blob/master/src/backend_dispatch.rs) (Backend Dispatch)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API"]
  node_api["Context and Surface<br/>[lib.rs]"]
  node_buffer["Pixel Buffer<br/>[lib.rs]"]
end

subgraph group_core["Dispatch and Core"]
  node_dispatch["Backend Dispatch"]
  node_interface["Backend Interface"]
  node_registry["Platform Registry<br/>[mod.rs]"]
end

subgraph group_platforms["Platform Backends"]
  node_android["Android Backend<br/>[android.rs]"]
  node_coregraphics["CoreGraphics Backend<br/>[cg.rs]"]
  node_kms["DRM/KMS Backend<br/>[kms.rs]"]
  node_orbital["Orbital Backend<br/>[orbital.rs]"]
  node_wayland["Wayland Backend<br/>[mod.rs]"]
  node_waylandbuffer["Wayland Shared Buffer<br/>[buffer.rs]"]
  node_web["Web Backend<br/>[web.rs]"]
  node_win32["Win32 Backend<br/>[win32.rs]"]
  node_x11["X11 Backend<br/>[x11.rs]"]
end

subgraph group_support["Shared Support"]
  node_pixel["Pixel Type<br/>[pixel.rs]"]
  node_format["Pixel Format<br/>[format.rs]"]
  node_errors["Error Types<br/>[error.rs]"]
  node_utilities["Buffer Utilities<br/>[util.rs]"]
end

node_application(("Application"))
node_window(("Window Provider"))
node_compositor["Window Compositor"]

node_application -->|"creates surface"| node_api
node_window -->|"provides handles"| node_api
node_application -->|"draws pixels"| node_buffer
node_api -->|"delegates backend"| node_dispatch
node_api -->|"yields buffer"| node_buffer
node_buffer -->|"presents through"| node_dispatch
node_dispatch -->|"implements traits"| node_interface
node_dispatch -->|"selects backend"| node_registry
node_registry -->|"registers"| node_android
node_registry -->|"registers"| node_coregraphics
node_registry -->|"registers"| node_kms
node_registry -->|"registers"| node_orbital
node_registry -->|"registers"| node_wayland
node_registry -->|"registers"| node_web
node_registry -->|"registers"| node_win32
node_registry -->|"registers"| node_x11
node_wayland -->|"allocates buffers"| node_waylandbuffer
node_wayland -.->|"commits surface"| node_compositor
node_android -->|"uses helpers"| node_utilities
node_coregraphics -->|"uses helpers"| node_utilities
node_kms -->|"uses helpers"| node_utilities
node_orbital -->|"uses helpers"| node_utilities
node_web -->|"uses helpers"| node_utilities
node_win32 -->|"uses helpers"| node_utilities
node_x11 -->|"uses helpers"| node_utilities
node_buffer -->|"exposes pixels"| node_pixel

click node_api "https://github.com/rust-windowing/softbuffer/blob/master/src/lib.rs"
click node_buffer "https://github.com/rust-windowing/softbuffer/blob/master/src/lib.rs"
click node_dispatch "https://github.com/rust-windowing/softbuffer/blob/master/src/backend_dispatch.rs"
click node_interface "https://github.com/rust-windowing/softbuffer/blob/master/src/backend_interface.rs"
click node_registry "https://github.com/rust-windowing/softbuffer/blob/master/src/backends/mod.rs"
click node_android "https://github.com/rust-windowing/softbuffer/blob/master/src/backends/android.rs"
click node_coregraphics "https://github.com/rust-windowing/softbuffer/blob/master/src/backends/cg.rs"
click node_kms "https://github.com/rust-windowing/softbuffer/blob/master/src/backends/kms.rs"
click node_orbital "https://github.com/rust-windowing/softbuffer/blob/master/src/backends/orbital.rs"
click node_wayland "https://github.com/rust-windowing/softbuffer/blob/master/src/backends/wayland/mod.rs"
click node_waylandbuffer "https://github.com/rust-windowing/softbuffer/blob/master/src/backends/wayland/buffer.rs"
click node_web "https://github.com/rust-windowing/softbuffer/blob/master/src/backends/web.rs"
click node_win32 "https://github.com/rust-windowing/softbuffer/blob/master/src/backends/win32.rs"
click node_x11 "https://github.com/rust-windowing/softbuffer/blob/master/src/backends/x11.rs"
click node_pixel "https://github.com/rust-windowing/softbuffer/blob/master/src/pixel.rs"
click node_format "https://github.com/rust-windowing/softbuffer/blob/master/src/format.rs"
click node_errors "https://github.com/rust-windowing/softbuffer/blob/master/src/error.rs"
click node_utilities "https://github.com/rust-windowing/softbuffer/blob/master/src/util.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_buffer toneBlue
class node_dispatch,node_interface,node_registry toneAmber
class node_android,node_coregraphics,node_kms,node_orbital,node_wayland,node_waylandbuffer,node_web,node_win32,node_x11 toneMint
class node_pixel,node_format,node_errors,node_utilities toneRose
class node_application,node_window,node_compositor toneIndigo
```

## Components

### Public API

- [Context and Surface](https://github.com/rust-windowing/softbuffer/blob/master/src/lib.rs): `src/lib.rs`
- [Pixel Buffer](https://github.com/rust-windowing/softbuffer/blob/master/src/lib.rs): `src/lib.rs`

### Dispatch and Core

- [Backend Dispatch](https://github.com/rust-windowing/softbuffer/blob/master/src/backend_dispatch.rs): `src/backend_dispatch.rs`
- [Backend Interface](https://github.com/rust-windowing/softbuffer/blob/master/src/backend_interface.rs): `src/backend_interface.rs`
- [Platform Registry](https://github.com/rust-windowing/softbuffer/blob/master/src/backends/mod.rs): `src/backends/mod.rs`

### Platform Backends

- [Android Backend](https://github.com/rust-windowing/softbuffer/blob/master/src/backends/android.rs): `src/backends/android.rs`
- [CoreGraphics Backend](https://github.com/rust-windowing/softbuffer/blob/master/src/backends/cg.rs): `src/backends/cg.rs`
- [DRM/KMS Backend](https://github.com/rust-windowing/softbuffer/blob/master/src/backends/kms.rs): `src/backends/kms.rs`
- [Orbital Backend](https://github.com/rust-windowing/softbuffer/blob/master/src/backends/orbital.rs): `src/backends/orbital.rs`
- [Wayland Backend](https://github.com/rust-windowing/softbuffer/blob/master/src/backends/wayland/mod.rs): `src/backends/wayland/mod.rs`
- [Wayland Shared Buffer](https://github.com/rust-windowing/softbuffer/blob/master/src/backends/wayland/buffer.rs): `src/backends/wayland/buffer.rs`
- [Web Backend](https://github.com/rust-windowing/softbuffer/blob/master/src/backends/web.rs): `src/backends/web.rs`
- [Win32 Backend](https://github.com/rust-windowing/softbuffer/blob/master/src/backends/win32.rs): `src/backends/win32.rs`
- [X11 Backend](https://github.com/rust-windowing/softbuffer/blob/master/src/backends/x11.rs): `src/backends/x11.rs`

### Shared Support

- [Pixel Type](https://github.com/rust-windowing/softbuffer/blob/master/src/pixel.rs): `src/pixel.rs`
- [Pixel Format](https://github.com/rust-windowing/softbuffer/blob/master/src/format.rs): `src/format.rs`
- [Error Types](https://github.com/rust-windowing/softbuffer/blob/master/src/error.rs): `src/error.rs`
- [Buffer Utilities](https://github.com/rust-windowing/softbuffer/blob/master/src/util.rs): `src/util.rs`

### Other components

- **Application**
- **Window Provider**
- **Window Compositor**

## Connections

- Application → Context and Surface: creates surface (evidence: `README.md`)
- Window Provider → Context and Surface: provides handles (evidence: `README.md`)
- Application → Pixel Buffer: draws pixels (evidence: `README.md`)
- Context and Surface → Backend Dispatch: delegates backend (evidence: `src/lib.rs`)
- Context and Surface → Pixel Buffer: yields buffer (evidence: `README.md`)
- Pixel Buffer → Backend Dispatch: presents through (evidence: `src/lib.rs`)
- Backend Dispatch → Backend Interface: implements traits (evidence: `src/backend_dispatch.rs`)
- Backend Dispatch → Platform Registry: selects backend (evidence: `src/backend_dispatch.rs`)
- Platform Registry → Android Backend: registers (evidence: `src/backends/mod.rs`)
- Platform Registry → CoreGraphics Backend: registers (evidence: `src/backends/mod.rs`)
- Platform Registry → DRM/KMS Backend: registers (evidence: `src/backends/mod.rs`)
- Platform Registry → Orbital Backend: registers (evidence: `src/backends/mod.rs`)
- Platform Registry → Wayland Backend: registers (evidence: `src/backends/mod.rs`)
- Platform Registry → Web Backend: registers (evidence: `src/backends/mod.rs`)
- Platform Registry → Win32 Backend: registers (evidence: `src/backends/mod.rs`)
- Platform Registry → X11 Backend: registers (evidence: `src/backends/mod.rs`)
- Wayland Backend → Wayland Shared Buffer: allocates buffers (evidence: `src/backends/wayland/mod.rs`)
- Wayland Backend → Window Compositor: commits surface (evidence: `README.md`)
- Android Backend → Buffer Utilities: uses helpers (evidence: `src/backends/android.rs`)
- CoreGraphics Backend → Buffer Utilities: uses helpers (evidence: `src/backends/cg.rs`)
- DRM/KMS Backend → Buffer Utilities: uses helpers (evidence: `src/backends/kms.rs`)
- Orbital Backend → Buffer Utilities: uses helpers (evidence: `src/backends/orbital.rs`)
- Web Backend → Buffer Utilities: uses helpers (evidence: `src/backends/web.rs`)
- Win32 Backend → Buffer Utilities: uses helpers (evidence: `src/backends/win32.rs`)
- X11 Backend → Buffer Utilities: uses helpers (evidence: `src/backends/x11.rs`)
- Pixel Buffer → Pixel Type: exposes pixels (evidence: `src/lib.rs`)
