# ubisoft/chroma architecture

> Architecture diagram of the GitHub repository ubisoft/chroma, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ubisoft/chroma
- Repository: https://github.com/ubisoft/chroma

## Overview

##### Main Components
a. Operating System & Graphics Stack
- Windows 10/11 Desktop
- Direct3D 11 GPU driver & runtime
b. Chroma Application (single executable)
1. UI Layer
– Configuration UI (menus, sliders, screenshot button)
– INI Parser (reads/writes user settings)
2. Input/Control Layer
– HotKeyManager (registers global hotkeys)
– InputHelper (processes keyboard/mouse events)
3. Screen Capture Layer
– SimpleCapture (captures frame buffers via Win32/Direct3D APIs)
– Win32WindowEnumeration (locates the target window/monitor)
– capture.interop/composition.interop (CPPWinRT wrappers)
4. Shader Processing Layer
– Shader Loader/Compiler (hlsl → GPU bytecode)
– PixelShader modules (Default, Protanopia, Deutanopia, Tritanopia, Tritan, Greyscale)
– Vertex Shader (fullscreen quad)
5. Rendering/Output Layer
– D3D11 Swap Chain (presents the processed frame back on screen)
6. External Dependencies
– ManagedWrapper.lib (third‑party interop code)
– CPPWinRT (for composition/capture interop)

##### Relationships & Data Flow
– UI Layer ↔ INI Parser (load/save settings)
– Input Layer → UI Layer & Capture/Shader layers (hotkey toggles simulation on/off, screenshot trigger)

##### Architectural Patterns
- Modular layering: capture, processing, output decoupled behind well‑defined interfaces
- Separation of concerns: UI, input, capture, processing, rendering
- Use of external wrapper for WinRT interop and of resource files (.rc, shaders)

##### Technologies & Frameworks
- C++17, Windows SDK
- Direct3D 11 API (d3dHelpers, direct3d11.interop)
- CPPWinRT for composition/capture interop
- HLSL for pixel shaders
- Win32 APIs for window enumeration & input
- MSBuild/CMake & Visual Studio solution file

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% OS & Graphics Stack
    Windows["Windows 10/11 Desktop"]:::os
    D3D11["Direct3D11 GPU Driver & Runtime"]:::os

    %% Screen Capture Layer
    subgraph "Screen Capture Layer"
        direction TB
        SimpleCapture["SimpleCapture"]:::capture
        WinEnum["Win32WindowEnumeration"]:::capture
        subgraph "CPPWinRT Interop"
            direction TB
            CaptureInterop["capture.interop"]:::capture
            CompositionInterop["composition.interop"]:::capture
        end
        D3DHelpers["d3dHelpers & direct3d11.interop"]:::capture
        ManagedWrapper["ManagedWrapper.lib"]:::ext
    end

    %% Shader Processing Layer
    subgraph "Shader Processing Layer"
        direction TB
        ShaderLoader["Shader Loader/Compiler"]:::processing
        subgraph "PixelShader Modules"
            direction TB
            DefaultPS["Default"]:::processing
            ProtanPS["Protanopia"]:::processing
            DeutanPS["Deutanopia"]:::processing
            TritanPS["Tritanopia"]:::processing
            GreyPS["Greyscale"]:::processing
        end
        VertexShader["Vertex Shader"]:::processing
    end

    %% Rendering/Output Layer
    D3DChain["D3D11 Swap Chain"]:::capture

    %% UI/Input Layer
    subgraph "UI & Input Layer"
        direction TB
        subgraph "UI Layer"
            ConfigUI["Configuration UI"]:::ui
            IniParser["INI Parser"]:::ui
        end
        subgraph "Input/Control Layer"
            HotKeyManager["HotKeyManager"]:::ui
            InputHelper["InputHelper"]:::ui
        end
    end

    %% Relationships - Data Flow
    Windows -->|data| SimpleCapture
    D3D11 -->|data| SimpleCapture
    SimpleCapture -->|frame| VertexShader
    VertexShader -->|verts| DefaultPS
    VertexShader -->|verts| ProtanPS
    VertexShader -->|verts| DeutanPS
    VertexShader -->|verts| TritanPS
    VertexShader -->|verts| GreyPS
    DefaultPS -->|pixels| D3DChain
    ProtanPS -->|pixels| D3DChain
    DeutanPS -->|pixels| D3DChain
    TritanPS -->|pixels| D3DChain
    GreyPS -->|pixels| D3DChain

    %% Control & Config Flow (dashed)
    HotKeyManager -. control .-> ConfigUI
    HotKeyManager -. control .-> SimpleCapture
    HotKeyManager -. control .-> ShaderLoader
    InputHelper -. control .-> ConfigUI
    ConfigUI <.->|"load/save"| IniParser
    ConfigUI -. config .-> ShaderLoader

    %% External Dependencies
    Windows --> ManagedWrapper
    SimpleCapture --> CaptureInterop
    SimpleCapture --> CompositionInterop
    SimpleCapture --> D3DHelpers

    %% Legend
    subgraph Legend
        direction TB
        OS["Gray: OS/Dependencies"]:::os
        Capture["Blue: Capture"]:::capture
        Processing["Yellow: Processing"]:::processing
        UI["Green: UI/Input"]:::ui
        Solid["Solid Arrow: Data Flow"]
        Dashed["Dashed Arrow: Control/Config"]
    end

    %% Click Events - UI Layer
    click ConfigUI "https://github.com/ubisoft/chroma/blob/main/source/source/UbiChroma.cpp"
    click ConfigUI "https://github.com/ubisoft/chroma/blob/main/source/UbiChroma.rc"
    click ConfigUI "https://github.com/ubisoft/chroma/blob/main/source/headers/Resource.h"
    click ConfigUI "https://github.com/ubisoft/chroma/blob/main/source/resource/banner.bmp"
    click IniParser "https://github.com/ubisoft/chroma/blob/main/source/headers/IniParser.h"
    click IniParser "https://github.com/ubisoft/chroma/blob/main/source/source/IniParser.cpp"

    %% Click Events - Input Layer
    click HotKeyManager "https://github.com/ubisoft/chroma/blob/main/source/headers/HotKeyManager.h"
    click HotKeyManager "https://github.com/ubisoft/chroma/blob/main/source/source/HotKeyManager.cpp"
    click HotKeyManager "https://github.com/ubisoft/chroma/blob/main/source/headers/HotKey.h"
    click HotKeyManager "https://github.com/ubisoft/chroma/blob/main/source/source/HotKey.cpp"
    click InputHelper "https://github.com/ubisoft/chroma/blob/main/source/headers/InputHelper.h"
    click InputHelper "https://github.com/ubisoft/chroma/blob/main/source/source/InputHelper.cpp"

    %% Click Events - Capture Layer
    click SimpleCapture "https://github.com/ubisoft/chroma/blob/main/source/headers/SimpleCapture.h"
    click SimpleCapture "https://github.com/ubisoft/chroma/blob/main/source/source/SimpleCapture.cpp"
    click WinEnum "https://github.com/ubisoft/chroma/blob/main/source/headers/Win32WindowEnumeration.h"
    click CaptureInterop "https://github.com/ubisoft/chroma/blob/main/source/headers/capture.interop.h"
    click CompositionInterop "https://github.com/ubisoft/chroma/blob/main/source/headers/composition.interop.h"
    click D3DHelpers "https://github.com/ubisoft/chroma/blob/main/source/headers/d3dHelpers.h"
    click D3DHelpers "https://github.com/ubisoft/chroma/blob/main/source/headers/direct3d11.interop.h"

    %% Click Events - External
    click ManagedWrapper "https://github.com/ubisoft/chroma/blob/main/source/Extlibs/ManagedWrapper.lib"

    %% Click Events - Shader Layer
    click ShaderLoader "https://github.com/ubisoft/chroma/blob/main/source/headers/PixelShader.h"
    click ShaderLoader "https://github.com/ubisoft/chroma/blob/main/source/shaders/PixelShader.hlsl"
    click DefaultPS "https://github.com/ubisoft/chroma/blob/main/source/shaders/DefaultPixelShader.h"
    click DefaultPS "https://github.com/ubisoft/chroma/blob/main/source/shaders/DefaultPixelShader.hlsl"
    click ProtanPS "https://github.com/ubisoft/chroma/blob/main/source/shaders/ProtanPixelShader.h"
    click ProtanPS "https://github.com/ubisoft/chroma/blob/main/source/shaders/ProtanPixelShader.hlsl"
    click DeutanPS "https://github.com/ubisoft/chroma/blob/main/source/shaders/DeutanPixelShader.h"
    click DeutanPS "https://github.com/ubisoft/chroma/blob/main/source/shaders/DeutanPixelShader.hlsl"
    click TritanPS "https://github.com/ubisoft/chroma/blob/main/source/shaders/TritanPixelShader.h"
    click TritanPS "https://github.com/ubisoft/chroma/blob/main/source/shaders/TritanPixelShader.hlsl"
    click GreyPS "https://github.com/ubisoft/chroma/blob/main/source/shaders/GreyscalePixelShader.h"
    click GreyPS "https://github.com/ubisoft/chroma/blob/main/source/shaders/GreyscalePixelShader.hlsl"
    click VertexShader "https://github.com/ubisoft/chroma/blob/main/source/shaders/Vertex.h"
    click VertexShader "https://github.com/ubisoft/chroma/blob/main/source/shaders/Vertex.hlsl"

    %% Click Events - Rendering Layer
    click D3DChain "https://github.com/ubisoft/chroma/blob/main/source/source/UbiChroma.cpp"
    click D3DChain "https://github.com/ubisoft/chroma/blob/main/source/headers/d3dHelpers.h"
    click D3DChain "https://github.com/ubisoft/chroma/blob/main/source/headers/direct3d11.interop.h"

    %% Click Events - Build Artifacts
    click Windows "https://github.com/ubisoft/chroma/blob/main/source/UbiChroma.sln"
    click Windows "https://github.com/ubisoft/chroma/blob/main/source/UbiChroma.vcxproj"
    click Windows "https://github.com/ubisoft/chroma/blob/main/source/UbiChroma.vcxproj.filters"
    click Windows "https://github.com/ubisoft/chroma/blob/main/source/UbiChroma.vcxproj.user"

    %% Styles
    classDef os fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef capture fill:#BBE1FA,stroke:#333,stroke-width:1px
    classDef processing fill:#FFE699,stroke:#333,stroke-width:1px
    classDef ui fill:#C8E6C9,stroke:#333,stroke-width:1px
    classDef ext fill:#D3D3D3,stroke-dasharray: 5 5,stroke:#333,stroke-width:1px
```
