docs
Loading...
Searching...
No Matches
Platform.h
Go to the documentation of this file.
1///
2/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3/// A license is required for commercial use. https://ultralig.ht
4///
5#pragma once
7
8namespace ultralight {
9
10struct Config;
11class Logger;
12class GPUDriver;
13class FontLoader;
14class FileSystem;
15class Clipboard;
16class Profiler;
17class SurfaceFactory;
18class ThreadFactory;
19class AudioOutput;
20
21///
22/// Global platform singleton, manages user-defined platform handlers and global config.
23///
24/// The library uses the Platform API for most platform-specific operations (eg, file access,
25/// clipboard, font loading, GPU access, pixel buffer transport, etc.).
26///
27/// ## Motivation
28///
29/// Ultralight is designed to work in as many platforms and environments as possible. To achieve
30/// this, we've factored out most platform-specific code into a set of interfaces that you can
31/// implement and set on the Platform singleton.
32///
33/// ## Default Implementations
34///
35/// We provide a number of default implementations for desktop platforms (eg, Windows, macOS, Linux)
36/// for you when you call App::Create(). These implementations ship as Zlib-licensed source in
37/// the SDK's `platform` folder, we recommend using their source code as a starting point for your
38/// own implementations.
39///
40/// ## Required Handlers
41///
42/// When using Renderer::Create() directly, you'll need to provide your own implementations for
43/// FileSystem and FontLoader at a minimum.
44///
45/// @par Overview of which platform handlers are required / optional / provided:
46///
47/// | | Renderer::Create() | App::Create() |
48/// |----------------|--------------------|---------------|
49/// | FileSystem | **Required** | *Provided* |
50/// | FontLoader | **Required** | *Provided* |
51/// | Clipboard | *Optional* | *Provided* |
52/// | GPUDriver | *Optional* | *Provided* |
53/// | Logger | *Optional* | *Provided* |
54/// | SurfaceFactory | *Provided* | *Provided* |
55/// | ThreadFactory | *Optional* | *Optional* |
56/// | Profiler | *Optional* | *Optional* |
57/// | AudioOutput | *Optional* | *Provided* |
58///
59/// @note This singleton should be set up before creating the Renderer or App.
60///
62 public:
63 ///
64 /// Get the Platform singleton
65 ///
66 static Platform& instance();
67
68 virtual ~Platform();
69
70 ///
71 /// Set the Config
72 ///
73 /// @note The Config is copied, it's safe to pass a stack-allocated Config here.
74 ///
75 virtual void set_config(const Config& config) = 0;
76
77 ///
78 /// Get the Config
79 ///
80 virtual const Config& config() const = 0;
81
82 ///
83 /// Set the Logger (to handle error messages and debug output).
84 ///
85 /// @param logger A user-defined Logger implementation, ownership remains with the caller.
86 ///
87 /// @note The library may call the Logger from any thread, so your implementation must be
88 /// thread-safe.
89 ///
90 virtual void set_logger(Logger* logger) = 0;
91
92 ///
93 /// Get the Logger
94 ///
95 virtual Logger* logger() const = 0;
96
97 ///
98 /// Set the GPU Driver (will handle all rendering)
99 ///
100 /// @param gpu_driver A user-defined GPUDriver implementation, ownership remains with the
101 /// caller.
102 ///
104
105 ///
106 /// Get the GPU Driver
107 ///
108 virtual GPUDriver* gpu_driver() const = 0;
109
110 ///
111 /// Set the Font Loader (will be used to map font families to actual fonts)
112 ///
113 /// @param font_loader A user-defined FontLoader implementation, ownership remains with the
114 /// caller.
115 ///
117
118 ///
119 /// Get the Font Loader
120 ///
121 virtual FontLoader* font_loader() const = 0;
122
123 ///
124 /// Set the File System (will be used for all file system operations)
125 ///
126 /// @param file_system A user-defined FileSystem implementation, ownership remains with the
127 /// caller.
128 ///
130
131 ///
132 /// Get the File System
133 ///
134 virtual FileSystem* file_system() const = 0;
135
136 ///
137 /// Set the Clipboard (will be used for all clipboard operations)
138 ///
139 /// @param clipboard A user-defined Clipboard implementation, ownership remains with the
140 /// caller.
141 ///
143
144 ///
145 /// Get the Clipboard
146 ///
147 virtual Clipboard* clipboard() const = 0;
148
149 ///
150 /// Set the SurfaceFactory
151 ///
152 /// This can be used to provide a platform-specific bitmap surface for View to paint into when
153 /// the CPU renderer is enabled. See View::surface().
154 ///
155 /// @param surface_factory A user-defined SurfaceFactory implementation, ownership remains with
156 /// the caller.
157 ///
158 /// @note A default BitmapSurfaceFactory is defined if you never call this, View::surface() can
159 /// be safely cast to BitmapSurface.
160 ///
162
163 ///
164 /// Get the SurfaceFactory
165 ///
166 /// @note A default BitmapSurfaceFactory is set by default, View::surface() can be safely cast
167 /// to BitmapSurface if you don't define your own.
168 ///
169 virtual SurfaceFactory* surface_factory() const = 0;
170
171 ///
172 /// Set the ThreadFactory
173 ///
174 /// This can be used to provide a platform-specific ThreadFactory implementation for the library
175 /// to use when creating threads.
176 ///
177 /// @param thread_factory A user-defined ThreadFactory implementation, ownership remains with the
178 /// caller.
179 ///
181
182 ///
183 /// Get the ThreadFactory
184 ///
185 virtual ThreadFactory* thread_factory() const = 0;
186
187#if UL_HAS(MEDIA)
188 ///
189 /// Set the AudioOutput (will handle PCM playback for `<video>`/`<audio>` elements).
190 ///
191 /// The library streams decoded audio to this implementation during media playback. If not set,
192 /// media plays without sound.
193 ///
194 /// @param audio_output A user-defined AudioOutput implementation, ownership remains with
195 /// the caller.
196 ///
197 /// @pre Requires the Pro edition or higher.
198 ///
200
201 ///
202 /// Get the AudioOutput, if any.
203 ///
204 virtual AudioOutput* audio_output() const = 0;
205#endif // UL_HAS(MEDIA)
206
207#if UL_HAS(PROFILER)
208 ///
209 /// Set the Profiler (to receive profiling callbacks for performance analysis).
210 ///
211 /// When set, the library emits structured timing data (scopes, events, counters) at key
212 /// internal boundaries that can be forwarded to any profiling tool or trace format.
213 ///
214 /// @param profiler A user-defined Profiler implementation, ownership remains with the caller.
215 /// Must outlive the Renderer/App.
216 ///
217 /// @pre Requires the Pro edition or higher.
218 ///
219 virtual void set_profiler(Profiler* profiler) = 0;
220
221 ///
222 /// Get the Profiler, if any.
223 ///
224 virtual Profiler* profiler() const = 0;
225#endif // UL_HAS(PROFILER)
226};
227
228} // namespace ultralight
#define UExport
Definition Exports.h:22
User-defined audio output interface.
Definition AudioOutput.h:84
User-defined clipboard interface.
Definition Clipboard.h:33
User-defined file system interface.
Definition FileSystem.h:42
User-defined font loader interface.
Definition FontLoader.h:108
User-defined GPU driver interface.
Definition GPUDriver.h:564
User-defined logging interface.
Definition Logger.h:60
Global platform singleton, manages user-defined platform handlers and global config.
Definition Platform.h:61
virtual void set_font_loader(FontLoader *font_loader)=0
Set the Font Loader (will be used to map font families to actual fonts).
virtual Logger * logger() const =0
Get the Logger.
virtual SurfaceFactory * surface_factory() const =0
Get the SurfaceFactory.
virtual void set_clipboard(Clipboard *clipboard)=0
Set the Clipboard (will be used for all clipboard operations).
static Platform & instance()
Get the Platform singleton.
virtual void set_file_system(FileSystem *file_system)=0
Set the File System (will be used for all file system operations).
virtual const Config & config() const =0
Get the Config.
virtual ThreadFactory * thread_factory() const =0
Get the ThreadFactory.
virtual Clipboard * clipboard() const =0
Get the Clipboard.
virtual void set_surface_factory(SurfaceFactory *surface_factory)=0
Set the SurfaceFactory.
virtual GPUDriver * gpu_driver() const =0
Get the GPU Driver.
virtual void set_gpu_driver(GPUDriver *gpu_driver)=0
Set the GPU Driver (will handle all rendering).
virtual void set_config(const Config &config)=0
Set the Config.
virtual void set_logger(Logger *logger)=0
Set the Logger (to handle error messages and debug output).
virtual void set_profiler(Profiler *profiler)=0
Set the Profiler (to receive profiling callbacks for performance analysis).
virtual Profiler * profiler() const =0
Get the Profiler, if any.
virtual FileSystem * file_system() const =0
Get the File System.
virtual AudioOutput * audio_output() const =0
Get the AudioOutput, if any.
virtual void set_audio_output(AudioOutput *audio_output)=0
Set the AudioOutput (will handle PCM playback for <video>/<audio> elements).
virtual void set_thread_factory(ThreadFactory *thread_factory)=0
Set the ThreadFactory.
virtual FontLoader * font_loader() const =0
Get the Font Loader.
User-defined profiling interface.
Definition Profiler.h:41
User-defined factory to provide your own surface implementation.
Definition Surface.h:246
User-defined factory for creating new threads.
Definition Thread.h:77
Root namespace for every public Ultralight type, function, and enumeration.
Core configuration for the renderer.
Definition Config.h:296