# servo/webrender architecture

> Architecture diagram of the GitHub repository servo/webrender, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/servo/webrender
- Repository: https://github.com/servo/webrender

## Overview

##### Main Components Identification

The system should be divided into these major components:

a) Core Rendering Pipeline:
- API Layer (webrender_api/)
- Scene Building (webrender/src/scene_builder_thread.rs)
- Frame Building (webrender/src/frame_builder.rs)
- Rendering Backend (webrender/src/render_backend.rs)
- GPU Renderer (webrender/src/renderer/)

b) Support Systems:
- Resource Management (webrender/src/resource_cache.rs)
- GPU Cache (webrender/src/gpu_cache.rs)
- Texture Cache (webrender/src/texture_cache.rs)
- Compositor Integration (webrender/src/compositor/)

##### Component Relationships

**[Client Application] → [WebRender API] → [Scene Builder] → [Frame Builder] → [Render Backend] → [GPU Renderer] → [Display]**

With parallel systems:
**[Resource Cache] ↔ [GPU Cache]**
**[Texture Cache] ↔ [GPU Renderer]**
**[Compositor] ↔ [GPU Renderer]**

##### Specific Implementation Details

Specialized components:
- Primitive handling (webrender/src/prim_store/)
- Picture caching (webrender/src/picture.rs)
- Tile caching (webrender/src/tile_cache.rs)
- Shader management (webrender/src/device/)

##### Architectural Patterns

Highlight:
- Pipeline architecture for rendering
- Command pattern for GPU operations
- Cache systems for performance
- Thread isolation for stability

##### Integration Points

External interfaces:
- OpenGL API integration
- Platform compositor integration
- Client API surface
- Resource loading interfaces

- Thread boundaries
- Data flow directions
- Component responsibilities
- Cache interactions
- External system interfaces

This will provide a clear understanding of WebRender's architecture while capturing its essential complexity as a modern GPU-based rendering engine.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef api fill:#a8d1f0,stroke:#333
    classDef core fill:#90EE90,stroke:#333
    classDef resource fill:#FFB347,stroke:#333
    classDef gpu fill:#FF6961,stroke:#333
    classDef support fill:#DDA0DD,stroke:#333
    
    %% Client and API Layer
    Client["Client Application"]
    API["WebRender API"]:::api
    
    %% Core Pipeline
    subgraph CorePipeline
        Scene["Scene Builder"]:::core
        Frame["Frame Builder"]:::core
        RenderBackend["Render Backend"]:::core
        GPURenderer["GPU Renderer"]:::gpu
    end
    
    %% Resource Management
    subgraph Resources
        ResourceCache["Resource Cache"]:::resource
        GPUCache["GPU Cache"]:::resource
        TextureCache["Texture Cache"]:::resource
    end
    
    %% Specialized Components
    subgraph Specialized
        PrimStore["Primitive Store"]:::core
        PicCache["Picture Cache"]:::core
        TileCache["Tile Cache"]:::core
        ShaderMgmt["Shader Management"]:::gpu
    end
    
    %% Support Systems
    subgraph Support
        Compositor["Compositor"]:::support
    end
    
    %% External Systems
    Display["Display Output"]
    OpenGL["OpenGL API"]:::gpu
    
    %% Relationships
    Client --> API
    API --> Scene
    Scene --> Frame
    Frame --> RenderBackend
    RenderBackend --> GPURenderer
    GPURenderer --> Display
    
    ResourceCache <--> GPUCache
    TextureCache <--> GPURenderer
    Compositor <--> GPURenderer
    
    GPURenderer <--> OpenGL
    
    Frame <--> PrimStore
    Frame <--> PicCache
    Frame <--> TileCache
    GPURenderer <--> ShaderMgmt
    
    %% Click Events
    click API "https://github.com/servo/webrender/blob/main/webrender_api/src/lib.rs"
    click Scene "https://github.com/servo/webrender/blob/main/webrender/src/scene_builder_thread.rs"
    click Frame "https://github.com/servo/webrender/blob/main/webrender/src/frame_builder.rs"
    click RenderBackend "https://github.com/servo/webrender/blob/main/webrender/src/render_backend.rs"
    click GPURenderer "https://github.com/servo/webrender/blob/main/webrender/src/renderer/mod.rs"
    click ResourceCache "https://github.com/servo/webrender/blob/main/webrender/src/resource_cache.rs"
    click GPUCache "https://github.com/servo/webrender/blob/main/webrender/src/gpu_cache.rs"
    click TextureCache "https://github.com/servo/webrender/blob/main/webrender/src/texture_cache.rs"
    click Compositor "https://github.com/servo/webrender/blob/main/webrender/src/compositor/mod.rs"
    click PrimStore "https://github.com/servo/webrender/blob/main/webrender/src/prim_store/mod.rs"
    click PicCache "https://github.com/servo/webrender/blob/main/webrender/src/picture.rs"
    click TileCache "https://github.com/servo/webrender/blob/main/webrender/src/tile_cache.rs"
    click ShaderMgmt "https://github.com/servo/webrender/blob/main/webrender/src/device/mod.rs"
    
    %% Legend
    subgraph Legend
        L1["API Component"]:::api
        L2["Core Component"]:::core
        L3["Resource Component"]:::resource
        L4["GPU Component"]:::gpu
        L5["Support Component"]:::support
    end
```
