Ultralight C++ API 1.3.0
Loading...
Searching...
No Matches
Platform.h
Go to the documentation of this file.
1/******************************************************************************
2 * This file is a part of Ultralight, an ultra-portable web-browser engine. *
3 * *
4 * See <https://ultralig.ht> for licensing and more. *
5 * *
6 * (C) 2023 Ultralight, Inc. *
7 *****************************************************************************/
8#pragma once
10
11namespace ultralight {
12
13struct Config;
14class Logger;
15class GPUDriver;
16class FontLoader;
17class FileSystem;
18class Clipboard;
19class SurfaceFactory;
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, etc.).
26///
27/// @par Overview of which platform handlers are required / optional / provided:
28///
29/// | | Renderer::Create() | App::Create() |
30/// |----------------|--------------------|---------------|
31/// | FileSystem | **Required** | *Provided* |
32/// | FontLoader | **Required** | *Provided* |
33/// | Clipboard | *Optional* | *Provided* |
34/// | GPUDriver | *Optional* | *Provided* |
35/// | Logger | *Optional* | *Provided* |
36/// | SurfaceFactory | *Provided* | *Provided* |
37///
38/// @note This singleton should be set up before creating the Renderer or App.
39///
41 public:
42 ///
43 /// Get the Platform singleton
44 ///
45 static Platform& instance();
46
47 virtual ~Platform();
48
49 ///
50 /// Set the Config
51 ///
52 virtual void set_config(const Config& config) = 0;
53
54 ///
55 /// Get the Config
56 ///
57 virtual const Config& config() const = 0;
58
59 ///
60 /// Set the Logger (to handle error messages and debug output).
61 ///
62 /// @param logger A user-defined Logger implementation, ownership remains with the caller.
63 ///
64 virtual void set_logger(Logger* logger) = 0;
65
66 ///
67 /// Get the Logger
68 ///
69 virtual Logger* logger() const = 0;
70
71 ///
72 /// Set the GPU Driver (will handle all rendering)
73 ///
74 /// @param gpu_driver A user-defined GPUDriver implementation, ownership remains with the
75 /// caller.
76 ///
77 virtual void set_gpu_driver(GPUDriver* gpu_driver) = 0;
78
79 ///
80 /// Get the GPU Driver
81 ///
82 virtual GPUDriver* gpu_driver() const = 0;
83
84 ///
85 /// Set the Font Loader (will be used to map font families to actual fonts)
86 ///
87 /// @param font_loader A user-defined FontLoader implementation, ownership remains with the
88 /// caller.
89 ///
90 virtual void set_font_loader(FontLoader* font_loader) = 0;
91
92 ///
93 /// Get the Font Loader
94 ///
95 virtual FontLoader* font_loader() const = 0;
96
97 ///
98 /// Set the File System (will be used for all file system operations)
99 ///
100 /// @param file_system A user-defined FileSystem implementation, ownership remains with the
101 /// caller.
102 ///
103 virtual void set_file_system(FileSystem* file_system) = 0;
104
105 ///
106 /// Get the File System
107 ///
108 virtual FileSystem* file_system() const = 0;
109
110 ///
111 /// Set the Clipboard (will be used for all clipboard operations)
112 ///
113 /// @param clipboard A user-defined Clipboard implementation, ownership remains with the
114 /// caller.
115 ///
116 virtual void set_clipboard(Clipboard* clipboard) = 0;
117
118 ///
119 /// Get the Clipboard
120 ///
121 virtual Clipboard* clipboard() const = 0;
122
123 ///
124 /// Set the SurfaceFactory
125 ///
126 /// This can be used to provide a platform-specific bitmap surface for View to paint into when
127 /// the CPU renderer is enabled. See View::surface().
128 ///
129 /// @param surface_factory A user-defined SurfaceFactory implementation, ownership remains with
130 /// the caller.
131 ///
132 /// @note A default BitmapSurfaceFactory is defined if you never call this, View::surface() can
133 /// be safely cast to BitmapSurface.
134 ///
135 virtual void set_surface_factory(SurfaceFactory* surface_factory) = 0;
136
137 ///
138 /// Get the SurfaceFactory
139 ///
140 /// @note A default BitmapSurfaceFactory is set by default, View::surface() can be safely cast
141 /// to BitmapSurface if you don't define your own.
142 ///
143 virtual SurfaceFactory* surface_factory() const = 0;
144};
145
146} // namespace ultralight
#define UExport
Definition Defines.h:65
User-defined clipboard interface.
Definition Clipboard.h:25
User-defined file system interface.
Definition FileSystem.h:37
User-defined font loader interface.
Definition FontLoader.h:82
User-defined GPU driver interface.
Definition GPUDriver.h:199
User-defined logging interface.
Definition Logger.h:32
Global platform singleton, manages user-defined platform handlers and global config.
Definition Platform.h:40
virtual void set_clipboard(Clipboard *clipboard)=0
Set the Clipboard (will be used for all clipboard operations)
virtual const Config & config() const =0
Get the Config.
virtual void set_gpu_driver(GPUDriver *gpu_driver)=0
Set the GPU Driver (will handle all rendering)
virtual void set_surface_factory(SurfaceFactory *surface_factory)=0
Set the SurfaceFactory.
virtual Clipboard * clipboard() const =0
Get the Clipboard.
virtual void set_logger(Logger *logger)=0
Set the Logger (to handle error messages and debug output).
virtual void set_font_loader(FontLoader *font_loader)=0
Set the Font Loader (will be used to map font families to actual fonts)
virtual FileSystem * file_system() const =0
Get the File System.
virtual void set_config(const Config &config)=0
Set the Config.
virtual SurfaceFactory * surface_factory() const =0
Get the SurfaceFactory.
virtual GPUDriver * gpu_driver() const =0
Get the GPU Driver.
virtual FontLoader * font_loader() const =0
Get the Font Loader.
virtual Logger * logger() const =0
Get the Logger.
virtual void set_file_system(FileSystem *file_system)=0
Set the File System (will be used for all file system operations)
static Platform & instance()
Get the Platform singleton.
SurfaceFactory can be used to provide your own native Surface implementation.
Definition Surface.h:127
Definition App.h:14
Global config for Ultralight.
Definition Config.h:72