1 | // [Blend2D] |
2 | // 2D Vector Graphics Powered by a JIT Compiler. |
3 | // |
4 | // [License] |
5 | // Zlib - See LICENSE.md file in the package. |
6 | |
7 | #ifndef BLEND2D_BLRUNTIME_H |
8 | #define BLEND2D_BLRUNTIME_H |
9 | |
10 | #include "./blapi.h" |
11 | |
12 | //! \addtogroup blend2d_api_runtime |
13 | //! \{ |
14 | |
15 | // ============================================================================ |
16 | // [Constants] |
17 | // ============================================================================ |
18 | |
19 | //! Blend2D runtime limits. |
20 | //! |
21 | //! \note These constanst are used across Blend2D, but they are not designed to |
22 | //! be ABI stable. New versions of Blend2D can increase certain limits without |
23 | //! notice. Use runtime to query the limits dynamically, see `BLRuntimeBuildInfo`. |
24 | BL_DEFINE_ENUM(BLRuntimeLimits) { |
25 | //! Maximum width and height of an image. |
26 | BL_RUNTIME_MAX_IMAGE_SIZE = 65535, |
27 | //! Maximum number of threads for asynchronous operations (including rendering). |
28 | BL_RUNTIME_MAX_THREAD_COUNT = 32 |
29 | }; |
30 | |
31 | //! Type of runtime information that can be queried through `blRuntimeQueryInfo()`. |
32 | BL_DEFINE_ENUM(BLRuntimeInfoType) { |
33 | //! Blend2D build information. |
34 | BL_RUNTIME_INFO_TYPE_BUILD = 0, |
35 | //! System information (includes CPU architecture, features, cores, etc...). |
36 | BL_RUNTIME_INFO_TYPE_SYSTEM = 1, |
37 | //! Runtime information regarding memory used, reserved, etc... |
38 | BL_RUNTIME_INFO_TYPE_MEMORY = 2, |
39 | |
40 | //! Count of runtime information types. |
41 | BL_RUNTIME_INFO_TYPE_COUNT = 3 |
42 | }; |
43 | |
44 | //! Blend2D runtime build type. |
45 | BL_DEFINE_ENUM(BLRuntimeBuildType) { |
46 | //! Describes a Blend2D debug build. |
47 | BL_RUNTIME_BUILD_TYPE_DEBUG = 0, |
48 | //! Describes a Blend2D release build. |
49 | BL_RUNTIME_BUILD_TYPE_RELEASE = 1 |
50 | }; |
51 | |
52 | //! CPU architecture that can be queried by `BLRuntime::querySystemInfo()`. |
53 | BL_DEFINE_ENUM(BLRuntimeCpuArch) { |
54 | //! Unknown architecture. |
55 | BL_RUNTIME_CPU_ARCH_UNKNOWN = 0, |
56 | //! 32-bit or 64-bit X86 architecture. |
57 | BL_RUNTIME_CPU_ARCH_X86 = 1, |
58 | //! 32-bit or 64-bit ARM architecture. |
59 | BL_RUNTIME_CPU_ARCH_ARM = 2, |
60 | //! 32-bit or 64-bit MIPS architecture. |
61 | BL_RUNTIME_CPU_ARCH_MIPS = 3 |
62 | }; |
63 | |
64 | //! CPU features Blend2D supports. |
65 | BL_DEFINE_ENUM(BLRuntimeCpuFeatures) { |
66 | BL_RUNTIME_CPU_FEATURE_X86_SSE2 = 0x00000001u, |
67 | BL_RUNTIME_CPU_FEATURE_X86_SSE3 = 0x00000002u, |
68 | BL_RUNTIME_CPU_FEATURE_X86_SSSE3 = 0x00000004u, |
69 | BL_RUNTIME_CPU_FEATURE_X86_SSE4_1 = 0x00000008u, |
70 | BL_RUNTIME_CPU_FEATURE_X86_SSE4_2 = 0x00000010u, |
71 | BL_RUNTIME_CPU_FEATURE_X86_AVX = 0x00000020u, |
72 | BL_RUNTIME_CPU_FEATURE_X86_AVX2 = 0x00000040u |
73 | }; |
74 | |
75 | //! Runtime cleanup flags that can be used through `BLRuntime::cleanup()`. |
76 | BL_DEFINE_ENUM(BLRuntimeCleanupFlags) { |
77 | //! Cleanup object memory pool. |
78 | BL_RUNTIME_CLEANUP_OBJECT_POOL = 0x00000001u, |
79 | //! Cleanup zeroed memory pool. |
80 | BL_RUNTIME_CLEANUP_ZEROED_POOL = 0x00000002u, |
81 | //! Cleanup thread pool (would join unused threads). |
82 | BL_RUNTIME_CLEANUP_THREAD_POOL = 0x00000010u, |
83 | |
84 | //! Cleanup everything. |
85 | BL_RUNTIME_CLEANUP_EVERYTHING = 0xFFFFFFFFu |
86 | }; |
87 | |
88 | // ============================================================================ |
89 | // [BLRuntime - BuildInfo] |
90 | // ============================================================================ |
91 | |
92 | //! Blend2D build information. |
93 | struct BLRuntimeBuildInfo { |
94 | union { |
95 | //! Blend2D version stored as `((MAJOR << 16) | (MINOR << 8) | PATCH)`. |
96 | uint32_t version; |
97 | |
98 | //! Decomposed Blend2D version so it's easier to access without bit shifting. |
99 | struct { |
100 | #if BL_BYTE_ORDER == 1234 |
101 | uint8_t patchVersion; |
102 | uint8_t minorVersion; |
103 | uint16_t majorVersion; |
104 | #else |
105 | uint16_t majorVersion; |
106 | uint8_t minorVersion; |
107 | uint8_t patchVersion; |
108 | #endif |
109 | }; |
110 | }; |
111 | |
112 | //! Blend2D build type, see `BLRuntimeBuildType`. |
113 | uint32_t buildType; |
114 | |
115 | //! Baseline CPU features, see `BLRuntimeCpuFeatures`. |
116 | //! |
117 | //! These features describe CPU features that were detected at compile-time. |
118 | //! Baseline features are used to compile all source files so they represent |
119 | //! the minimum feature-set the target CPU must support to run Blend2D. |
120 | //! |
121 | //! Official Blend2D builds set baseline at SSE2 on X86 target and NEON on |
122 | //! ARM target. Custom builds can set use different baseline, which can be |
123 | //! read through `BLRuntimeBuildInfo`. |
124 | uint32_t baselineCpuFeatures; |
125 | |
126 | //! Supported CPU features, see `BLRuntimeCpuFeatures`. |
127 | //! |
128 | //! These features do not represent the features that the host CPU must support, |
129 | //! instead, they represent all features that Blend2D can take advantage of in |
130 | //! C++ code that uses instruction intrinsics. For example if AVX2 is part of |
131 | //! `supportedCpuFeatures` it means that Blend2D can take advantage of it if |
132 | //! there is a separate code-path. |
133 | uint32_t supportedCpuFeatures; |
134 | |
135 | //! Maximum size of an image (both width and height). |
136 | uint32_t maxImageSize; |
137 | |
138 | //! Maximum number of threads for asynchronous operations, including rendering. |
139 | uint32_t maxThreadCount; |
140 | |
141 | //! Reserved, must be zero. |
142 | uint32_t reserved[2]; |
143 | |
144 | //! Identification of the C++ compiler used to build Blend2D. |
145 | char compilerInfo[32]; |
146 | |
147 | // -------------------------------------------------------------------------- |
148 | #ifdef __cplusplus |
149 | BL_INLINE void reset() noexcept { memset(this, 0, sizeof(*this)); } |
150 | #endif |
151 | // -------------------------------------------------------------------------- |
152 | }; |
153 | |
154 | // ============================================================================ |
155 | // [BLRuntime - SystemInfo] |
156 | // ============================================================================ |
157 | |
158 | //! System information queried by the runtime. |
159 | struct BLRuntimeSystemInfo { |
160 | //! Host CPU architecture, see `BLRuntimeCpuArch`. |
161 | uint32_t cpuArch; |
162 | //! Host CPU features, see `BLRuntimeCpuFeatures`. |
163 | uint32_t cpuFeatures; |
164 | //! Number of cores of the host CPU/CPUs. |
165 | uint32_t coreCount; |
166 | //! Number of threads of the host CPU/CPUs. |
167 | uint32_t threadCount; |
168 | |
169 | //! Minimum stack size of threads. |
170 | uint32_t minThreadStackSize; |
171 | //! Minimum stack size of worker threads used by Blend2D. |
172 | uint32_t minWorkerStackSize; |
173 | //! Allocation granularity of virtual memory (includes thread's stack). |
174 | uint32_t allocationGranularity; |
175 | //! Reserved for future use. |
176 | uint32_t reserved[5]; |
177 | |
178 | // -------------------------------------------------------------------------- |
179 | #ifdef __cplusplus |
180 | BL_INLINE void reset() noexcept { memset(this, 0, sizeof(*this)); } |
181 | #endif |
182 | // -------------------------------------------------------------------------- |
183 | }; |
184 | |
185 | // ============================================================================ |
186 | // [BLRuntime - MemoryInfo] |
187 | // ============================================================================ |
188 | |
189 | //! Blend2D memory information that provides how much memory Blend2D allocated |
190 | //! and some other details about memory use. |
191 | struct BLRuntimeMemoryInfo { |
192 | //! Virtual memory used at this time. |
193 | size_t vmUsed; |
194 | //! Virtual memory reserved (allocated internally). |
195 | size_t vmReserved; |
196 | //! Overhead required to manage virtual memory allocations. |
197 | size_t vmOverhead; |
198 | //! Number of blocks of virtual memory allocated. |
199 | size_t vmBlockCount; |
200 | |
201 | //! Zeroed memory used at this time. |
202 | size_t zmUsed; |
203 | //! Zeroed memory reserved (allocated internally). |
204 | size_t zmReserved; |
205 | //! Overhead required to manage zeroed memory allocations. |
206 | size_t zmOverhead; |
207 | //! Number of blocks of zeroed memory allocated. |
208 | size_t zmBlockCount; |
209 | |
210 | //! Count of dynamic pipelines created and cached. |
211 | size_t dynamicPipelineCount; |
212 | |
213 | // -------------------------------------------------------------------------- |
214 | #ifdef __cplusplus |
215 | BL_INLINE void reset() noexcept { memset(this, 0, sizeof(*this)); } |
216 | #endif |
217 | // -------------------------------------------------------------------------- |
218 | }; |
219 | |
220 | // ============================================================================ |
221 | // [BLRuntime - C++ API] |
222 | // ============================================================================ |
223 | |
224 | #ifdef __cplusplus |
225 | //! Interface to access Blend2D runtime (wraps C-API). |
226 | namespace BLRuntime { |
227 | |
228 | static BL_INLINE BLResult cleanup(uint32_t cleanupFlags) noexcept { |
229 | return blRuntimeCleanup(cleanupFlags); |
230 | } |
231 | |
232 | static BL_INLINE BLResult queryBuildInfo(BLRuntimeBuildInfo* out) noexcept { |
233 | return blRuntimeQueryInfo(BL_RUNTIME_INFO_TYPE_BUILD, out); |
234 | } |
235 | |
236 | static BL_INLINE BLResult querySystemInfo(BLRuntimeSystemInfo* out) noexcept { |
237 | return blRuntimeQueryInfo(BL_RUNTIME_INFO_TYPE_SYSTEM, out); |
238 | } |
239 | |
240 | static BL_INLINE BLResult queryMemoryInfo(BLRuntimeMemoryInfo* out) noexcept { |
241 | return blRuntimeQueryInfo(BL_RUNTIME_INFO_TYPE_MEMORY, out); |
242 | } |
243 | |
244 | static BL_INLINE BLResult message(const char* msg) noexcept { |
245 | return blRuntimeMessageOut(msg); |
246 | } |
247 | |
248 | template<typename... Args> |
249 | static BL_INLINE BLResult message(const char* fmt, Args&&... args) noexcept { |
250 | return blRuntimeMessageFmt(fmt, std::forward<Args>(args)...); |
251 | } |
252 | |
253 | static BL_INLINE uint32_t getTickCount() noexcept { |
254 | return blRuntimeGetTickCount(); |
255 | } |
256 | |
257 | } // {BLRuntime} |
258 | #endif |
259 | |
260 | //! \} |
261 | |
262 | #endif // BLEND2D_BLRUNTIME_H |
263 | |