docs
Loading...
Searching...
No Matches
CAPI_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
6///
7/// @file CAPI_Platform.h
8///
9/// Global platform singleton, manages user-defined platform handlers.
10///
11/// `#include <Ultralight/CAPI/CAPI_Platform.h>`
12///
13/// The library uses the Platform API for most platform-specific operations (eg, file access,
14/// clipboard, font loading, GPU access, pixel buffer transport, etc.).
15///
16/// ## Motivation
17///
18/// Ultralight is designed to work in as many platforms and environments as possible. To achieve
19/// this, we've factored out most platform-specific code into a set of interfaces that you can
20/// implement and set on the Platform singleton.
21///
22/// ## Default Implementations
23///
24/// We provide a number of default implementations for desktop platforms (eg, Windows, macOS, Linux)
25/// for you when you call ulCreateApp(). These implementations ship as Zlib-licensed source in
26/// the SDK's `platform` folder, we recommend using their source code as a starting point for your
27/// own implementations.
28///
29/// ## Required Handlers
30///
31/// When using ulCreateRenderer() directly, you'll need to provide your own implementations for
32/// ULFileSystem and ULFontLoader at a minimum.
33///
34/// @par Overview of which platform handlers are required / optional / provided:
35///
36/// | | ulCreateRenderer() | ulCreateApp() |
37/// |---------------------|--------------------|---------------|
38/// | ULFileSystem | **Required** | *Provided* |
39/// | ULFontLoader | **Required** | *Provided* |
40/// | ULClipboard | *Optional* | *Provided* |
41/// | ULGPUDriver | *Optional* | *Provided* |
42/// | ULLogger | *Optional* | *Provided* |
43/// | ULSurfaceDefinition | *Provided* | *Provided* |
44/// | ULThreadFactory | *Optional* | *Optional* |
45/// | ULAudioOutput | *Optional* | *Provided* |
46/// | ULProfiler | *Optional* | *Optional* |
47///
48/// ULAudioOutput and ULProfiler require the Pro edition or higher.
49///
50/// ## Setting Handlers
51///
52/// Each ulPlatformSet*() function copies the struct you pass it, so the struct can be a temporary.
53/// The function pointers in it must stay valid until the Renderer or App is destroyed.
54///
55/// Set each handler once, before calling ulCreateRenderer() or ulCreateApp(). A later call
56/// replaces a handler that the library may still be using.
57///
58#ifndef ULTRALIGHT_CAPI_PLATFORM_H
59#define ULTRALIGHT_CAPI_PLATFORM_H
60
71
72#ifdef __cplusplus
73extern "C" {
74#endif
75
76/******************************************************************************
77 * Platform
78 *****************************************************************************/
79
80///
81/// Set a custom Logger implementation.
82///
83/// This is used to log debug messages to the console or to a log file.
84///
85/// You should call this before ulCreateRenderer() or ulCreateApp().
86///
87/// \parblock
88/// @note ulCreateApp() will use the default logger if you never call this.
89/// \endparblock
90///
91/// \parblock
92/// @note If you're not using ulCreateApp(), (eg, using ulCreateRenderer()) you can still use the
93/// default logger by calling ulEnableDefaultLogger() (@see <AppCore/CAPI.h>)
94/// \endparblock
95///
97
98///
99/// Set a custom FileSystem implementation.
100///
101/// The library uses this to load all file URLs (eg, <file:///page.html>).
102///
103/// You can provide the library with your own FileSystem implementation so that file assets are
104/// loaded from your own pipeline.
105///
106/// You should call this before ulCreateRenderer() or ulCreateApp().
107///
108/// @warning This is required to be defined before calling ulCreateRenderer()
109///
110/// \parblock
111/// @note ulCreateApp() will use the default platform file system if you never call this.
112/// \endparblock
113///
114/// \parblock
115/// @note If you're not using ulCreateApp(), (eg, using ulCreateRenderer()) you can still use the
116/// default platform file system by calling ulEnablePlatformFileSystem()'
117/// (@see <AppCore/CAPI.h>)
118/// \endparblock
119///
121
122///
123/// Set a custom FontLoader implementation.
124///
125/// The library uses this to load all system fonts.
126///
127/// Every operating system has its own library of installed system fonts. The FontLoader interface
128/// is used to lookup these fonts and fetch the actual font data (raw TTF/OTF file data) for a given
129/// given font description.
130///
131/// You should call this before ulCreateRenderer() or ulCreateApp().
132///
133/// @warning This is required to be defined before calling ulCreateRenderer()
134///
135/// \parblock
136/// @note ulCreateApp() will use the default platform font loader if you never call this.
137/// \endparblock
138///
139/// \parblock
140/// @note If you're not using ulCreateApp(), (eg, using ulCreateRenderer()) you can still use the
141/// default platform font loader by calling ulEnablePlatformFontLoader()'
142/// (@see <AppCore/CAPI.h>)
143/// \endparblock
144///
146
147///
148/// Set a custom Surface implementation.
149///
150/// This can be used to wrap a platform-specific GPU texture, Windows DIB, macOS CGImage, or any
151/// other pixel buffer target for display on screen.
152///
153/// By default, the library uses a bitmap surface for all surfaces but you can override this by
154/// providing your own surface definition here.
155///
156/// You should call this before ulCreateRenderer() or ulCreateApp().
157///
159
160///
161/// Set a custom GPUDriver implementation.
162///
163/// This should be used if you are using ulCreateRenderer() (which does not provide its own
164/// GPUDriver implementation) and want Views rendered on the GPU. A View renders on the GPU when
165/// you create it with ulViewConfigSetIsAccelerated() set to true.
166///
167/// The GPUDriver interface is used by the library to dispatch GPU calls to your native GPU context
168/// (eg, D3D11, Metal, OpenGL, Vulkan, etc.) There are Zlib-licensed reference
169/// implementations for this interface in the SDK's `platform` folder.
170///
171/// You should call this before ulCreateRenderer().
172///
174
175///
176/// Set a custom Clipboard implementation.
177///
178/// This should be used if you are using ulCreateRenderer() (which does not provide its own
179/// clipboard implementation).
180///
181/// The Clipboard interface is used by the library to make calls to the system's native clipboard
182/// (eg, cut, copy, paste).
183///
184/// You should call this before ulCreateRenderer().
185///
187
188///
189/// Set a custom ThreadFactory implementation.
190///
191/// This can be used to provide a platform-specific thread creation implementation for the library
192/// to use when creating threads (useful for tracking thread creation, setting thread names, etc).
193///
194/// You should call this before ulCreateRenderer() or ulCreateApp().
195///
196/// @note The library creates threads using the default platform-specific thread creation
197/// functions if you never call this.
198///
200
201#if UL_HAS(MEDIA)
202///
203/// Set a custom AudioOutput implementation.
204///
205/// The library uses this to play decoded audio for `<video>` and `<audio>` elements. ulCreateApp()
206/// provides one for you unless you've set your own first. If you are using ulCreateRenderer() and
207/// don't set one, media plays without sound.
208///
209/// You should call this before ulCreateRenderer() or ulCreateApp(). The callbacks must remain
210/// valid until after the Renderer/App is destroyed.
211///
212/// @pre Requires the Pro edition or higher.
213///
215#endif // UL_HAS(MEDIA)
216
217#if UL_HAS(PROFILER)
218///
219/// Set a custom Profiler implementation.
220///
221/// When set, the library emits structured timing data (scopes, events, counters) at key
222/// internal boundaries that can be forwarded to any profiling tool or trace format.
223///
224/// You should call this before ulCreateRenderer() or ulCreateApp(). The profiler callbacks
225/// must remain valid until after the Renderer/App is destroyed.
226///
227/// @pre Requires the Pro edition or higher.
228///
230#endif // UL_HAS(PROFILER)
231
232#ifdef __cplusplus
233} // extern "C"
234#endif
235
236#endif // ULTRALIGHT_CAPI_PLATFORM_H
User-defined audio output interface.
User-defined clipboard interface.
User-defined file system interface.
User-defined font loader interface.
User-defined GPU driver interface.
User-defined logging interface.
void ulPlatformSetFontLoader(ULFontLoader font_loader)
Set a custom FontLoader implementation.
void ulPlatformSetAudioOutput(ULAudioOutput audio_output)
Set a custom AudioOutput implementation.
void ulPlatformSetClipboard(ULClipboard clipboard)
Set a custom Clipboard implementation.
void ulPlatformSetSurfaceDefinition(ULSurfaceDefinition surface_definition)
Set a custom Surface implementation.
void ulPlatformSetLogger(ULLogger logger)
Set a custom Logger implementation.
void ulPlatformSetProfiler(ULProfiler profiler)
Set a custom Profiler implementation.
void ulPlatformSetGPUDriver(ULGPUDriver gpu_driver)
Set a custom GPUDriver implementation.
void ulPlatformSetThreadFactory(ULThreadFactory thread_factory)
Set a custom ThreadFactory implementation.
void ulPlatformSetFileSystem(ULFileSystem file_system)
Set a custom FileSystem implementation.
User-defined profiling interface.
User-defined pixel buffer surface.
User-defined factory for creating new threads.
Various defines and utility functions for the C API.
#define ULExport
Definition CAPI_Defines.h:42
User-defined audio output interface.
Definition CAPI_AudioOutput.h:123
User-defined clipboard interface.
Definition CAPI_Clipboard.h:185
User-defined file system interface.
Definition CAPI_FileSystem.h:90
User-defined font loader interface.
Definition CAPI_FontLoader.h:97
User-defined GPU driver interface.
Definition CAPI_GPUDriver.h:660
User-defined logging interface.
Definition CAPI_Logger.h:89
Definition CAPI_Profiler.h:96
User-defined surface interface.
Definition CAPI_Surface.h:335
User-defined factory for creating new threads.
Definition CAPI_ThreadFactory.h:98