# tencent/tgfx architecture

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

- Interactive diagram: https://gitdiagram.com/tencent/tgfx
- Repository: https://github.com/tencent/tgfx

## Overview

TGFX is a cross-platform C++ graphics library for rendering text, images, and vector graphics through modern GPU backends. The principal flow is an application building a layer/display list, rendering it onto a surface, and optionally reading back or exporting the result. The graph also preserves its documented SVG, PDF, codec, and platform capabilities. Several links are documented only at the API level; dashed edges mark architecture relationships not shown in the sampled implementation excerpts.

Main entry points: [`src/core/Canvas.cpp`](https://github.com/tencent/tgfx/blob/main/src/core/Canvas.cpp) (Canvas drawing), [`linux/src/main.cpp`](https://github.com/tencent/tgfx/blob/main/linux/src/main.cpp) (Hello2D host), [`src/gpu/RenderPipeline.cpp`](https://github.com/tencent/tgfx/blob/main/src/gpu/RenderPipeline.cpp) (Render pipelines), [`src/core/Surface.cpp`](https://github.com/tencent/tgfx/blob/main/src/core/Surface.cpp) (Render surface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application and layers"]
  node_demo["Hello2D host<br/>[main.cpp]"]
  node_builder["Layer builder<br/>[LayerBuilder.cpp]"]
  node_display["Display list<br/>[DisplayList.h]"]
  node_layers["Layer system<br/>[Layer.h]"]
  node_filters["Layer effects"]
end

subgraph group_core["Graphics core"]
  node_canvas["Canvas drawing<br/>[Canvas.cpp]"]
  node_surface["Render surface<br/>[Surface.cpp]"]
  node_images["Image handling<br/>[Image.cpp]"]
  node_text["Text and fonts<br/>[Font.cpp]"]
  node_vector["Paths and vectors<br/>[Path.cpp]"]
  node_readback["Surface readback"]
end

subgraph group_gpu["GPU rendering"]
  node_gpuapi["GPU context and device<br/>[Context.cpp]"]
  node_pipeline["Render pipelines<br/>[RenderPipeline.cpp]"]
  node_gl["OpenGL backend"]
  node_vulkan["Vulkan backend"]
  node_webgpu["WebGPU backend"]
  node_d3d12["Direct3D 12 backend"]
end

subgraph group_formats["Formats and export"]
  node_svg["SVG import and export"]
  node_pdf["PDF export"]
  node_codecs["Image codecs<br/>[ImageCodec.cpp]"]
end

subgraph group_platform["Platform adapters"]
  node_android["Android integration<br/>[HandlerThread.cpp]"]
  node_web["Web integration"]
end

node_developer(("Application"))

node_developer -->|"runs demo"| node_demo
node_demo -->|"builds layers"| node_builder
node_demo -->|"renders list"| node_display
node_demo -->|"creates surface"| node_surface
node_demo -->|"creates device"| node_gpuapi
node_builder -->|"builds tree"| node_layers
node_builder -->|"uses canvas"| node_canvas
node_display -.->|"renders layers"| node_layers
node_display -->|"renders to"| node_surface
node_surface -->|"provides canvas"| node_canvas
node_surface -->|"reads pixels"| node_readback
node_layers -.->|"applies styles"| node_filters
node_canvas -.->|"draws images"| node_images
node_canvas -.->|"draws text"| node_text
node_canvas -.->|"draws paths"| node_vector
node_gpuapi -.->|"creates pipelines"| node_pipeline
node_pipeline -.->|"implemented by"| node_gl
node_pipeline -->|"implemented by"| node_vulkan
node_pipeline -->|"implemented by"| node_webgpu
node_pipeline -->|"implemented by"| node_d3d12
node_images -.->|"decodes images"| node_codecs
node_canvas -.->|"exports graphics"| node_svg
node_canvas -.->|"exports documents"| node_pdf
node_android -.->|"platform support"| node_gpuapi
node_web -.->|"platform support"| node_gpuapi

click node_demo "https://github.com/tencent/tgfx/blob/main/linux/src/main.cpp"
click node_builder "https://github.com/tencent/tgfx/blob/main/hello2d/src/base/LayerBuilder.cpp"
click node_display "https://github.com/tencent/tgfx/blob/main/include/tgfx/layers/DisplayList.h"
click node_layers "https://github.com/tencent/tgfx/blob/main/include/tgfx/layers/Layer.h"
click node_canvas "https://github.com/tencent/tgfx/blob/main/src/core/Canvas.cpp"
click node_surface "https://github.com/tencent/tgfx/blob/main/src/core/Surface.cpp"
click node_images "https://github.com/tencent/tgfx/blob/main/src/core/images/Image.cpp"
click node_text "https://github.com/tencent/tgfx/blob/main/src/core/Font.cpp"
click node_vector "https://github.com/tencent/tgfx/blob/main/src/core/Path.cpp"
click node_filters "https://github.com/tencent/tgfx/blob/main/src/layers/BackgroundHandler.cpp"
click node_gpuapi "https://github.com/tencent/tgfx/blob/main/src/gpu/Context.cpp"
click node_pipeline "https://github.com/tencent/tgfx/blob/main/src/gpu/RenderPipeline.cpp"
click node_gl "https://github.com/tencent/tgfx/blob/main/src/gpu/opengl/GLRenderPipeline.cpp"
click node_vulkan "https://github.com/tencent/tgfx/blob/main/src/gpu/vulkan/VulkanRenderPipeline.cpp"
click node_webgpu "https://github.com/tencent/tgfx/blob/main/src/gpu/webgpu/WebGPURenderPipeline.cpp"
click node_d3d12 "https://github.com/tencent/tgfx/blob/main/src/gpu/d3d12/D3D12RenderPipeline.cpp"
click node_svg "https://github.com/tencent/tgfx/blob/main/src/svg/SVGExportContext.cpp"
click node_pdf "https://github.com/tencent/tgfx/blob/main/src/pdf/PDFExportContext.cpp"
click node_codecs "https://github.com/tencent/tgfx/blob/main/src/core/ImageCodec.cpp"
click node_readback "https://github.com/tencent/tgfx/blob/main/src/core/SurfaceReadback.cpp"
click node_android "https://github.com/tencent/tgfx/blob/main/src/platform/android/HandlerThread.cpp"
click node_web "https://github.com/tencent/tgfx/blob/main/src/platform/web/WebScalerContext.cpp"

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_demo,node_builder,node_display,node_layers,node_filters toneBlue
class node_canvas,node_surface,node_images,node_text,node_vector,node_readback toneAmber
class node_gpuapi,node_pipeline,node_gl,node_vulkan,node_webgpu,node_d3d12 toneMint
class node_svg,node_pdf,node_codecs toneRose
class node_android,node_web,node_developer toneIndigo
```

## Components

### Application and layers

- [Hello2D host](https://github.com/tencent/tgfx/blob/main/linux/src/main.cpp): `linux/src/main.cpp`
- [Layer builder](https://github.com/tencent/tgfx/blob/main/hello2d/src/base/LayerBuilder.cpp): `hello2d/src/base/LayerBuilder.cpp`
- [Display list](https://github.com/tencent/tgfx/blob/main/include/tgfx/layers/DisplayList.h): `include/tgfx/layers/DisplayList.h`
- [Layer system](https://github.com/tencent/tgfx/blob/main/include/tgfx/layers/Layer.h): `include/tgfx/layers/Layer.h`
- [Layer effects](https://github.com/tencent/tgfx/blob/main/src/layers/BackgroundHandler.cpp): `src/layers/BackgroundHandler.cpp`

### Graphics core

- [Canvas drawing](https://github.com/tencent/tgfx/blob/main/src/core/Canvas.cpp): `src/core/Canvas.cpp`
- [Render surface](https://github.com/tencent/tgfx/blob/main/src/core/Surface.cpp): `src/core/Surface.cpp`
- [Image handling](https://github.com/tencent/tgfx/blob/main/src/core/images/Image.cpp): `src/core/images/Image.cpp`
- [Text and fonts](https://github.com/tencent/tgfx/blob/main/src/core/Font.cpp): `src/core/Font.cpp`
- [Paths and vectors](https://github.com/tencent/tgfx/blob/main/src/core/Path.cpp): `src/core/Path.cpp`
- [Surface readback](https://github.com/tencent/tgfx/blob/main/src/core/SurfaceReadback.cpp): `src/core/SurfaceReadback.cpp`

### GPU rendering

- [GPU context and device](https://github.com/tencent/tgfx/blob/main/src/gpu/Context.cpp): `src/gpu/Context.cpp`
- [Render pipelines](https://github.com/tencent/tgfx/blob/main/src/gpu/RenderPipeline.cpp): `src/gpu/RenderPipeline.cpp`
- [OpenGL backend](https://github.com/tencent/tgfx/blob/main/src/gpu/opengl/GLRenderPipeline.cpp): `src/gpu/opengl/GLRenderPipeline.cpp`
- [Vulkan backend](https://github.com/tencent/tgfx/blob/main/src/gpu/vulkan/VulkanRenderPipeline.cpp): `src/gpu/vulkan/VulkanRenderPipeline.cpp`
- [WebGPU backend](https://github.com/tencent/tgfx/blob/main/src/gpu/webgpu/WebGPURenderPipeline.cpp): `src/gpu/webgpu/WebGPURenderPipeline.cpp`
- [Direct3D 12 backend](https://github.com/tencent/tgfx/blob/main/src/gpu/d3d12/D3D12RenderPipeline.cpp): `src/gpu/d3d12/D3D12RenderPipeline.cpp`

### Formats and export

- [SVG import and export](https://github.com/tencent/tgfx/blob/main/src/svg/SVGExportContext.cpp): `src/svg/SVGExportContext.cpp`
- [PDF export](https://github.com/tencent/tgfx/blob/main/src/pdf/PDFExportContext.cpp): `src/pdf/PDFExportContext.cpp`
- [Image codecs](https://github.com/tencent/tgfx/blob/main/src/core/ImageCodec.cpp): `src/core/ImageCodec.cpp`

### Platform adapters

- [Android integration](https://github.com/tencent/tgfx/blob/main/src/platform/android/HandlerThread.cpp): `src/platform/android/HandlerThread.cpp`
- [Web integration](https://github.com/tencent/tgfx/blob/main/src/platform/web/WebScalerContext.cpp): `src/platform/web/WebScalerContext.cpp`

### Other components

- **Application**

## Connections

- Application → Hello2D host: runs demo
- Hello2D host → Layer builder: builds layers (evidence: `linux/src/main.cpp`)
- Hello2D host → Display list: renders list (evidence: `linux/src/main.cpp`)
- Hello2D host → Render surface: creates surface (evidence: `linux/src/main.cpp`)
- Hello2D host → GPU context and device: creates device (evidence: `linux/src/main.cpp`)
- Layer builder → Layer system: builds tree
- Layer builder → Canvas drawing: uses canvas
- Display list → Layer system: renders layers
- Display list → Render surface: renders to
- Render surface → Canvas drawing: provides canvas
- Render surface → Surface readback: reads pixels
- Layer system → Layer effects: applies styles (evidence: `src/layers/BackgroundHandler.cpp`)
- Canvas drawing → Image handling: draws images
- Canvas drawing → Text and fonts: draws text
- Canvas drawing → Paths and vectors: draws paths
- GPU context and device → Render pipelines: creates pipelines
- Render pipelines → OpenGL backend: implemented by
- Render pipelines → Vulkan backend: implemented by (evidence: `src/gpu/vulkan/VulkanRenderPipeline.cpp`)
- Render pipelines → WebGPU backend: implemented by (evidence: `src/gpu/webgpu/WebGPURenderPipeline.cpp`)
- Render pipelines → Direct3D 12 backend: implemented by (evidence: `src/gpu/d3d12/D3D12RenderPipeline.cpp`)
- Image handling → Image codecs: decodes images
- Canvas drawing → SVG import and export: exports graphics
- Canvas drawing → PDF export: exports documents
- Android integration → GPU context and device: platform support
- Web integration → GPU context and device: platform support
