How tencent/tgfx works
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: Canvas.cpp Canvas drawing · main.cpp Hello2D host · RenderPipeline.cpp Render pipelines · Surface.cpp Render surface
Components 23
Application and layers
- Hello2D host
linux/src/main.cpp - Layer builder
hello2d/src/base/LayerBuilder.cpp - Display list
include/tgfx/layers/DisplayList.h - Layer system
include/tgfx/layers/Layer.h - Layer effects
src/layers/BackgroundHandler.cpp
Graphics core
- Canvas drawing
src/core/Canvas.cpp - Render surface
src/core/Surface.cpp - Image handling
src/core/images/Image.cpp - Text and fonts
src/core/Font.cpp - Paths and vectors
src/core/Path.cpp - Surface readback
src/core/SurfaceReadback.cpp
GPU rendering
- GPU context and device
src/gpu/Context.cpp - Render pipelines
src/gpu/RenderPipeline.cpp - OpenGL backend
src/gpu/opengl/GLRenderPipeline.cpp - Vulkan backend
src/gpu/vulkan/VulkanRenderPipeline.cpp - WebGPU backend
src/gpu/webgpu/WebGPURenderPipeline.cpp - Direct3D 12 backend
src/gpu/d3d12/D3D12RenderPipeline.cpp
Formats and export
- SVG import and export
src/svg/SVGExportContext.cpp - PDF export
src/pdf/PDFExportContext.cpp - Image codecs
src/core/ImageCodec.cpp
Platform adapters
- Android integration
src/platform/android/HandlerThread.cpp - Web integration
src/platform/web/WebScalerContext.cpp
Other components
- Application
Connections 25
- Application → Hello2D host: runs demo
- Hello2D host → Layer builder: builds layers
linux/src/main.cpp - Hello2D host → Display list: renders list
linux/src/main.cpp - Hello2D host → Render surface: creates surface
linux/src/main.cpp - Hello2D host → GPU context and device: creates device
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
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
src/gpu/vulkan/VulkanRenderPipeline.cpp - Render pipelines → WebGPU backend: implemented by
src/gpu/webgpu/WebGPURenderPipeline.cpp - Render pipelines → Direct3D 12 backend: implemented by
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