Loading...
Searching...
No Matches
CAPI_Platform.h
Go to the documentation of this file.
1/**************************************************************************************************
2 * This file is a part of Ultralight. *
3 * *
4 * See <https://ultralig.ht> for licensing and more. *
5 * *
6 * (C) 2024 Ultralight, Inc. *
7 **************************************************************************************************/
8
9///
10/// @file CAPI_Platform.h
11///
12/// Global platform singleton, manages user-defined platform handlers..
13///
14/// `#include <Ultralight/CAPI/CAPI_Platform.h>`
15///
16/// The library uses the Platform API for most platform-specific operations (eg, file access,
17/// clipboard, font loading, GPU access, pixel buffer transport, etc.).
18///
19/// ## Motivation
20///
21/// Ultralight is designed to work in as many platforms and environments as possible. To achieve
22/// this, we've factored out most platform-specific code into a set of interfaces that you can
23/// implement and set on the Platform singleton.
24///
25/// ## Default Implementations
26///
27/// We provide a number of default implementations for desktop platforms (eg, Windows, macOS, Linux)
28/// for you when you call ulCreateApp(). These implementations are defined in the
29/// [AppCore repository](https://github.com/ultralight-ux/AppCore/tree/master/src), we recommend
30/// using their source code as a starting point for your own implementations.
31///
32/// ## Required Handlers
33///
34/// When using ulCreateRenderer() directly, you'll need to provide your own implementations for
35/// ULFileSystem and ULFontLoader at a minimum.
36///
37/// @par Overview of which platform handlers are required / optional / provided:
38///
39/// | | ulCreateRenderer() | ulCreateApp() |
40/// |---------------------|--------------------|---------------|
41/// | ULFileSystem | **Required** | *Provided* |
42/// | ULFontLoader | **Required** | *Provided* |
43/// | ULClipboard | *Optional* | *Provided* |
44/// | ULGPUDriver | *Optional* | *Provided* |
45/// | ULLogger | *Optional* | *Provided* |
46/// | ULSurfaceDefinition | *Provided* | *Provided* |
47///
48/// @note This singleton should be set up before creating the Renderer or App.
49///
50#ifndef ULTRALIGHT_CAPI_PLATFORM_H
51#define ULTRALIGHT_CAPI_PLATFORM_H
52
60
61#ifdef __cplusplus
62extern "C" {
63#endif
64
65/******************************************************************************
66 * Platform
67 *****************************************************************************/
68
69///
70/// Set a custom Logger implementation.
71///
72/// This is used to log debug messages to the console or to a log file.
73///
74/// You should call this before ulCreateRenderer() or ulCreateApp().
75///
76/// @note ulCreateApp() will use the default logger if you never call this.
77///
78/// @note If you're not using ulCreateApp(), (eg, using ulCreateRenderer()) you can still use the
79/// default logger by calling ulEnableDefaultLogger() (@see <AppCore/CAPI.h>)
80///
82
83///
84/// Set a custom FileSystem implementation.
85///
86/// The library uses this to load all file URLs (eg, <file:///page.html>).
87///
88/// You can provide the library with your own FileSystem implementation so that file assets are
89/// loaded from your own pipeline.
90///
91/// You should call this before ulCreateRenderer() or ulCreateApp().
92///
93/// @warning This is required to be defined before calling ulCreateRenderer()
94///
95/// @note ulCreateApp() will use the default platform file system if you never call this.
96///
97/// @note If you're not using ulCreateApp(), (eg, using ulCreateRenderer()) you can still use the
98/// default platform file system by calling ulEnablePlatformFileSystem()'
99/// (@see <AppCore/CAPI.h>)
100///
102
103///
104/// Set a custom FontLoader implementation.
105///
106/// The library uses this to load all system fonts.
107///
108/// Every operating system has its own library of installed system fonts. The FontLoader interface
109/// is used to lookup these fonts and fetch the actual font data (raw TTF/OTF file data) for a given
110/// given font description.
111///
112/// You should call this before ulCreateRenderer() or ulCreateApp().
113///
114/// @warning This is required to be defined before calling ulCreateRenderer()
115///
116/// @note ulCreateApp() will use the default platform font loader if you never call this.
117///
118/// @note If you're not using ulCreateApp(), (eg, using ulCreateRenderer()) you can still use the
119/// default platform font loader by calling ulEnablePlatformFontLoader()'
120/// (@see <AppCore/CAPI.h>)
121///
123
124///
125/// Set a custom Surface implementation.
126///
127/// This can be used to wrap a platform-specific GPU texture, Windows DIB, macOS CGImage, or any
128/// other pixel buffer target for display on screen.
129///
130/// By default, the library uses a bitmap surface for all surfaces but you can override this by
131/// providing your own surface definition here.
132///
133/// You should call this before ulCreateRenderer() or ulCreateApp().
134///
136
137///
138/// Set a custom GPUDriver implementation.
139///
140/// This should be used if you have enabled the GPU renderer in the Config and are using
141/// ulCreateRenderer() (which does not provide its own GPUDriver implementation).
142///
143/// The GPUDriver interface is used by the library to dispatch GPU calls to your native GPU context
144/// (eg, D3D11, Metal, OpenGL, Vulkan, etc.) There are reference implementations for this interface
145/// in the AppCore repo.
146///
147/// You should call this before ulCreateRenderer().
148///
150
151///
152/// Set a custom Clipboard implementation.
153///
154/// This should be used if you are using ulCreateRenderer() (which does not provide its own
155/// clipboard implementation).
156///
157/// The Clipboard interface is used by the library to make calls to the system's native clipboard
158/// (eg, cut, copy, paste).
159///
160/// You should call this before ulCreateRenderer().
161///
163
164#ifdef __cplusplus
165} // extern "C"
166#endif
167
168#endif // ULTRALIGHT_CAPI_PLATFORM_H
User-defined clipboard interface.
Various defines and utility functions for the C API.
#define ULExport
Definition CAPI_Defines.h:38
User-defined file system interface.
User-defined font loader interface.
User-defined GPU driver interface.
User-defined logging interface.
ULExport void ulPlatformSetFileSystem(ULFileSystem file_system)
Set a custom FileSystem implementation.
ULExport void ulPlatformSetClipboard(ULClipboard clipboard)
Set a custom Clipboard implementation.
ULExport void ulPlatformSetLogger(ULLogger logger)
Set a custom Logger implementation.
ULExport void ulPlatformSetFontLoader(ULFontLoader font_loader)
Set a custom FontLoader implementation.
ULExport void ulPlatformSetSurfaceDefinition(ULSurfaceDefinition surface_definition)
Set a custom Surface implementation.
ULExport void ulPlatformSetGPUDriver(ULGPUDriver gpu_driver)
Set a custom GPUDriver implementation.
User-defined pixel buffer surface.
User-defined clipboard interface.
Definition CAPI_Clipboard.h:56
User-defined file system interface.
Definition CAPI_FileSystem.h:83
User-defined font loader interface.
Definition CAPI_FontLoader.h:89
User-defined GPU driver interface.
Definition CAPI_GPUDriver.h:442
Definition CAPI_Logger.h:42
User-defined surface interface.
Definition CAPI_Surface.h:234