odin-blend2d

Odin bindings to Blend2D
Log | Files | Refs | README | LICENSE

runtime.odin (6479B)


      1 // This file is part of Blend2D project <https://blend2d.com>
      2 //
      3 // See blend2d.h or LICENSE.md for license and copyright information
      4 // SPDX-License-Identifier: Zlib
      5 package blend2d
      6 
      7 import "core:c"
      8 
      9 when ODIN_OS == .Windows {
     10 	foreign import lib "blend2d.lib"
     11 } else when ODIN_OS == .Darwin {
     12 	foreign import lib "libblend2d.a"
     13 } else when ODIN_OS == .Linux {
     14 	foreign import lib "libblend2d.a"
     15 }
     16 
     17 
     18 //! Blend2D runtime limits.
     19 //!
     20 //! \note These constants are used across Blend2D, but they are not designed to be ABI stable. New versions of Blend2D
     21 //! can increase certain limits without notice. Use runtime to query the limits dynamically, see \ref BLRuntimeBuildInfo.
     22 RuntimeLimits :: enum u32 {
     23 	//! Maximum width and height of an image.
     24 	IMAGE_SIZE   = 65535,
     25 
     26 	//! Maximum number of threads for asynchronous operations (including rendering).
     27 	THREAD_COUNT = 32,
     28 }
     29 
     30 //! Type of runtime information that can be queried through \ref bl_runtime_query_info().
     31 RuntimeInfoType :: enum u32 {
     32 	//! Blend2D build information.
     33 	BUILD      = 0,
     34 
     35 	//! System information (includes CPU architecture, features, core count, etc...).
     36 	SYSTEM     = 1,
     37 
     38 	//! Resources information (includes Blend2D memory consumption)
     39 	RESOURCE   = 2,
     40 
     41 	//! Count of runtime information types.
     42 	MAX_VALUE  = 2,
     43 	FORCE_UINT = 4294967295,
     44 }
     45 
     46 //! Blend2D runtime build type.
     47 RuntimeBuildType :: enum u32 {
     48 	//! Describes a Blend2D debug build.
     49 	DEBUG      = 0,
     50 
     51 	//! Describes a Blend2D release build.
     52 	RELEASE    = 1,
     53 	FORCE_UINT = 4294967295,
     54 }
     55 
     56 //! CPU architecture that can be queried by `BLRuntime::query_system_info()`.
     57 RuntimeCpuArch :: enum u32 {
     58 	//! Unknown architecture.
     59 	UNKNOWN    = 0,
     60 
     61 	//! 32-bit or 64-bit X86 architecture.
     62 	X86        = 1,
     63 
     64 	//! 32-bit or 64-bit ARM architecture.
     65 	ARM        = 2,
     66 
     67 	//! 32-bit or 64-bit MIPS architecture.
     68 	MIPS       = 3,
     69 	FORCE_UINT = 4294967295,
     70 }
     71 
     72 //! CPU features Blend2D supports.
     73 RuntimeCpuFeatures :: enum u32 {
     74 	X86_SSE2   = 1,
     75 	X86_SSE3   = 2,
     76 	X86_SSSE3  = 4,
     77 	X86_SSE4_1 = 8,
     78 	X86_SSE4_2 = 16,
     79 	X86_AVX    = 32,
     80 	X86_AVX2   = 64,
     81 	X86_AVX512 = 128,
     82 	ARM_ASIMD  = 1,
     83 	ARM_CRC32  = 2,
     84 	ARM_PMULL  = 4,
     85 	FORCE_UINT = 4294967295,
     86 }
     87 
     88 //! Runtime cleanup flags that can be used through `BLRuntime::cleanup()`.
     89 RuntimeCleanupFlags :: enum u32 {
     90 	//! No flags.
     91 	NO_FLAGS        = 0,
     92 
     93 	//! Cleanup object memory pool.
     94 	OBJECT_POOL     = 1,
     95 
     96 	//! Cleanup zeroed memory pool.
     97 	ZEROED_POOL     = 2,
     98 
     99 	//! Cleanup thread pool (would join unused threads).
    100 	THREAD_POOL     = 16,
    101 
    102 	//! Cleanup everything.
    103 	EVERYTHING      = 4294967295,
    104 	FLAG_FORCE_UINT = 4294967295,
    105 }
    106 
    107 //! Blend2D build information.
    108 RuntimeBuildInfo :: struct {
    109 	//! Major version number.
    110 	major_version: u32,
    111 
    112 	//! Minor version number.
    113 	minor_version: u32,
    114 
    115 	//! Patch version number.
    116 	patch_version: u32,
    117 
    118 	//! Blend2D build type, see \ref BLRuntimeBuildType.
    119 	build_type: u32,
    120 
    121 	//! Baseline CPU features, see \ref BLRuntimeCpuFeatures.
    122 	//!
    123 	//! These features describe CPU features that were detected at compile-time. Baseline features are used to compile
    124 	//! all source files so they represent the minimum feature-set the target CPU must support to run Blend2D.
    125 	//!
    126 	//! Official Blend2D builds set baseline at SSE2 on X86 target and NEON on ARM target. Custom builds can set use
    127 	//! a different baseline, which can be read through `BLRuntimeBuildInfo`.
    128 	baseline_cpu_features: u32,
    129 
    130 	//! Supported CPU features, see \ref BLRuntimeCpuFeatures.
    131 	//!
    132 	//! These features do not represent the features that the host CPU must support, instead, they represent all features
    133 	//! that Blend2D can take advantage of in C++ code that uses instruction intrinsics. For example if AVX2 is part of
    134 	//! `supported_cpu_features` it means that Blend2D can take advantage of it if there is a specialized code-path.
    135 	supported_cpu_features: u32,
    136 
    137 	//! Maximum size of an image (both width and height).
    138 	max_image_size: u32,
    139 
    140 	//! Maximum number of threads for asynchronous operations, including rendering.
    141 	max_thread_count: u32,
    142 
    143 	//! Reserved, must be zero.
    144 	reserved: [2]u32,
    145 
    146 	//! Identification of the C++ compiler used to build Blend2D.
    147 	compiler_info: [32]i8,
    148 }
    149 
    150 //! System information queried by the runtime.
    151 RuntimeSystemInfo :: struct {
    152 	//! Host CPU architecture, see \ref BLRuntimeCpuArch.
    153 	cpu_arch: u32,
    154 
    155 	//! Host CPU features, see \ref BLRuntimeCpuFeatures.
    156 	cpu_features: u32,
    157 
    158 	//! Number of cores of the host CPU/CPUs.
    159 	core_count: u32,
    160 
    161 	//! Number of threads of the host CPU/CPUs.
    162 	thread_count: u32,
    163 
    164 	//! Minimum stack size of a worker thread used by Blend2D.
    165 	thread_stack_size: u32,
    166 
    167 	//! Removed field.
    168 	removed: u32,
    169 
    170 	//! Allocation granularity of virtual memory (includes thread's stack).
    171 	allocation_granularity: u32,
    172 
    173 	//! Reserved for future use.
    174 	reserved: [5]u32,
    175 
    176 	//! Host CPU vendor string such "AMD", "APPLE", "INTEL", "SAMSUNG", etc...
    177 	cpu_vendor: [16]i8,
    178 
    179 	//! Host CPU brand string or empty string if not detected properly.
    180 	cpu_brand: [64]i8,
    181 }
    182 
    183 //! Provides information about resources allocated by Blend2D.
    184 RuntimeResourceInfo :: struct {
    185 	//! Virtual memory used at this time.
    186 	vm_used: c.size_t,
    187 
    188 	//! Virtual memory reserved (allocated internally).
    189 	vm_reserved: c.size_t,
    190 
    191 	//! Overhead required to manage virtual memory allocations.
    192 	vm_overhead: c.size_t,
    193 
    194 	//! Number of blocks of virtual memory allocated.
    195 	vm_block_count: c.size_t,
    196 
    197 	//! Zeroed memory used at this time.
    198 	zm_used: c.size_t,
    199 
    200 	//! Zeroed memory reserved (allocated internally).
    201 	zm_reserved: c.size_t,
    202 
    203 	//! Overhead required to manage zeroed memory allocations.
    204 	zm_overhead: c.size_t,
    205 
    206 	//! Number of blocks of zeroed memory allocated.
    207 	zm_block_count: c.size_t,
    208 
    209 	//! Count of dynamic pipelines created and cached.
    210 	dynamic_pipeline_count: c.size_t,
    211 
    212 	//! Reserved for future use.
    213 	reserved: [7]c.size_t,
    214 }
    215 
    216 @(default_calling_convention="c", link_prefix="bl_")
    217 foreign lib {
    218 	//! Initialized Blend2D runtime
    219 	runtime_init :: proc() -> Result ---
    220 
    221 	//! Shuts down Blend2D runtime
    222 	runtime_shutdown        :: proc() -> Result ---
    223 	runtime_cleanup         :: proc(cleanup_flags: RuntimeCleanupFlags) -> Result ---
    224 	runtime_query_info      :: proc(info_type: RuntimeInfoType, info_out: rawptr) -> Result ---
    225 	runtime_message_out     :: proc(msg: cstring) -> Result ---
    226 	runtime_message_fmt     :: proc(fmt: cstring, #c_vararg _: ..any) -> Result ---
    227 	runtime_message_vfmt    :: proc(fmt: cstring, ap: i32) -> Result ---
    228 	result_from_posix_error :: proc(e: i32) -> Result ---
    229 }
    230