mozilla/gecko-dev
Graphics and WebRender
gfx/ implements 2D graphics, font rendering, and the GPU-accelerated compositor. The compositor is WebRender (gfx/wr/), a Rust crate originally part of the Servo project, now the production compositor for Firefox.
Purpose
Translate layout's display lists into pixels using the GPU. Manage textures, glyph caches, image decoding hand-off, scrolling, and animation.
Major directories
| Path | Role |
|---|---|
gfx/wr/ |
The WebRender compositor (Rust) |
gfx/2d/ |
Moz2D: cross-platform 2D drawing API |
gfx/thebes/ |
Legacy gfx primitives (gfxContext, gfxFont) |
gfx/layers/ |
The compositor abstraction; WebRender bridge |
gfx/webrender_bindings/ |
C++ ↔ Rust glue for WebRender |
gfx/skia/ |
Vendored Skia (used for Canvas2D and font rasterization) |
gfx/cairo/ |
Vendored Cairo (legacy, partly retained) |
gfx/harfbuzz/ |
Vendored HarfBuzz text shaping |
gfx/angle/ |
Vendored ANGLE (WebGL → D3D translation) |
gfx/qcms/ |
Color management |
gfx/vr/ |
Headset / VR |
gfx/ipc/ |
gfx process actors (PCompositor, PRenderRoot, PVsync) |
gfx/config/ |
Per-driver feature gating, gfxFeature, blocklists |
gfx/fonts/ |
Bundled fonts |
Compositor architecture
graph TD
Content[Content process<br/>nsDisplayList] -->|IPC: PWebRenderBridge| GPU[GPU process<br/>WebRender]
GPU --> WRAPI[WebRender Rust API]
WRAPI --> SceneBuilder[Scene builder]
SceneBuilder --> RenderBackend[Render backend]
RenderBackend --> Renderer[Renderer + GL]
Renderer --> SurfaceCompositor[Native surface compositor]
SurfaceCompositor --> Display[Display]Content processes build display lists in C++ → translate them to WebRender display items → ship them across IPC to the GPU process → WebRender batches them into draw calls.
Webrender pipeline
WebRender thinks in terms of display lists (high-level) → scene (built once) → frames (built each animation tick from the scene + dynamic state). Key Rust modules in gfx/wr/webrender/:
scene_builder.rs— turns display lists into a render tree.picture.rs— picture caching for invalidation.tile_cache.rs— tile-based partial repaint.renderer/— submits draw calls viagleam.prim_store/— primitive types (text, image, gradient, …).
C++ ↔ Rust glue
gfx/webrender_bindings/ defines the extern "C" API the C++ side calls. The C++ code uses WebRenderAPI, WebRenderBridgeChild, WebRenderBridgeParent to manage the render-root and submit display items.
Process model
- Compositor in the GPU process. WebRender + the OS GL/D3D context live in the GPU process.
- APZ (Async Pan/Zoom) runs in the GPU process and lets scrolling proceed without waiting on content. See
gfx/layers/apz/. - Vsync signals are routed via
PVsyncIPDL.
Canvas
<canvas> 2D and WebGL implementations live in dom/canvas/. They use Skia (Canvas2D) and ANGLE / native WebGL drivers. WebGPU is implemented partly in dom/webgpu/ on top of wgpu (vendored Rust).
Text
- Shaping: HarfBuzz (
gfx/harfbuzz/). - Fonts: per-platform back-ends (CoreText on macOS, DirectWrite on Windows, FreeType on Linux).
- Glyph caching: by WebRender's text primitive store.
Related
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.