Loading...
Searching...
No Matches
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#pragma once
10
11namespace ultralight {
12
13struct Config;
14class Logger;
15class GPUDriver;
16class FontLoader;
17class FileSystem;
18class Clipboard;
19class SurfaceFactory;
20class ThreadFactory;
21
22///
23/// Global platform singleton, manages user-defined platform handlers and global config.
24///
25/// The library uses the Platform API for most platform-specific operations (eg, file access,
26/// clipboard, font loading, GPU access, pixel buffer transport, etc.).
27///
28/// ## Motivation
29///
30/// Ultralight is designed to work in as many platforms and environments as possible. To achieve
31/// this, we've factored out most platform-specific code into a set of interfaces that you can
32/// implement and set on the Platform singleton.
33///
34/// ## Default Implementations
35///
36/// We provide a number of default implementations for desktop platforms (eg, Windows, macOS, Linux)
37/// for you when you call App::Create(). These implementations are defined in the
38/// [AppCore repository](https://github.com/ultralight-ux/AppCore/tree/master/src), we recommend
39/// using their source code as a starting point for your own implementations.
40///
41/// ## Required Handlers
42///
43/// When using Renderer::Create() directly, you'll need to provide your own implementations for
44/// FileSystem and FontLoader at a minimum.
45///
46/// @par Overview of which platform handlers are required / optional / provided:
47///
48/// | | Renderer::Create() | App::Create() |
49/// |----------------|--------------------|---------------|
50/// | FileSystem | **Required** | *Provided* |
51/// | FontLoader | **Required** | *Provided* |
52/// | Clipboard | *Optional* | *Provided* |
53/// | GPUDriver | *Optional* | *Provided* |
54/// | Logger | *Optional* | *Provided* |
55/// | SurfaceFactory | *Provided* | *Provided* |
56/// | ThreadFactory | *Optional* | *Optional* |
57///
58/// @note This singleton should be set up before creating the Renderer or App.
59///
61 public:
62 ///
63 /// Get the Platform singleton
64 ///
65 static Platform& instance();
66
67 virtual ~Platform();
68
69 ///
70 /// Set the Config
71 ///
72 virtual void set_config(const Config& config) = 0;
73
74 ///
75 /// Get the Config
76 ///
77 virtual const Config& config() const = 0;
78
79 ///
80 /// Set the Logger (to handle error messages and debug output).
81 ///
82 /// @param logger A user-defined Logger implementation, ownership remains with the caller.
83 ///
84 virtual void set_logger(Logger* logger) = 0;
85
86 ///
87 /// Get the Logger
88 ///
89 virtual Logger* logger() const = 0;
90
91 ///
92 /// Set the GPU Driver (will handle all rendering)
93 ///
94 /// @param gpu_driver A user-defined GPUDriver implementation, ownership remains with the
95 /// caller.
96 ///
97 virtual void set_gpu_driver(GPUDriver* gpu_driver) = 0;
98
99 ///
100 /// Get the GPU Driver
101 ///
102 virtual GPUDriver* gpu_driver() const = 0;
103
104 ///
105 /// Set the Font Loader (will be used to map font families to actual fonts)
106 ///
107 /// @param font_loader A user-defined FontLoader implementation, ownership remains with the
108 /// caller.
109 ///
110 virtual void set_font_loader(FontLoader* font_loader) = 0;
111
112 ///
113 /// Get the Font Loader
114 ///
115 virtual FontLoader* font_loader() const = 0;
116
117 ///
118 /// Set the File System (will be used for all file system operations)
119 ///
120 /// @param file_system A user-defined FileSystem implementation, ownership remains with the
121 /// caller.
122 ///
123 virtual void set_file_system(FileSystem* file_system) = 0;
124
125 ///
126 /// Get the File System
127 ///
128 virtual FileSystem* file_system() const = 0;
129
130 ///
131 /// Set the Clipboard (will be used for all clipboard operations)
132 ///
133 /// @param clipboard A user-defined Clipboard implementation, ownership remains with the
134 /// caller.
135 ///
136 virtual void set_clipboard(Clipboard* clipboard) = 0;
137
138 ///
139 /// Get the Clipboard
140 ///
141 virtual Clipboard* clipboard() const = 0;
142
143 ///
144 /// Set the SurfaceFactory
145 ///
146 /// This can be used to provide a platform-specific bitmap surface for View to paint into when
147 /// the CPU renderer is enabled. See View::surface().
148 ///
149 /// @param surface_factory A user-defined SurfaceFactory implementation, ownership remains with
150 /// the caller.
151 ///
152 /// @note A default BitmapSurfaceFactory is defined if you never call this, View::surface() can
153 /// be safely cast to BitmapSurface.
154 ///
155 virtual void set_surface_factory(SurfaceFactory* surface_factory) = 0;
156
157 ///
158 /// Get the SurfaceFactory
159 ///
160 /// @note A default BitmapSurfaceFactory is set by default, View::surface() can be safely cast
161 /// to BitmapSurface if you don't define your own.
162 ///
163 virtual SurfaceFactory* surface_factory() const = 0;
164
165 ///
166 /// Set the ThreadFactory
167 ///
168 /// This can be used to provide a platform-specific ThreadFactory implementation for the library
169 /// to use when creating threads.
170 ///
171 /// @param thread_factory A user-defined ThreadFactory implementation, ownership remains with the
172 /// caller.
173 ///
174 virtual void set_thread_factory(ThreadFactory* thread_factory) = 0;
175
176 ///
177 /// Get the ThreadFactory
178 ///
179 virtual ThreadFactory* thread_factory() const = 0;
180};
181
182} // namespace ultralight
#define UExport
Definition Exports.h:25
User-defined clipboard interface.
Definition Clipboard.h:25
User-defined file system interface.
Definition FileSystem.h:38
User-defined font loader interface.
Definition FontLoader.h:86
User-defined GPU driver interface.
Definition GPUDriver.h:278
User-defined logging interface.
Definition Logger.h:32
Global platform singleton, manages user-defined platform handlers and global config.
Definition Platform.h:60
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 FileSystem * file_system() const =0
Get the File System.
virtual void set_thread_factory(ThreadFactory *thread_factory)=0
Set the ThreadFactory.
virtual FontLoader * font_loader() const =0
Get the Font Loader.
User-defined factory to provide your own surface implementation.
Definition Surface.h:144
User-defined factory for creating new threads.
Definition Thread.h:74
Definition App.h:14
Core configuration for the renderer.
Definition Config.h:95