object.odin (12552B)
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 ObjectImpl :: struct {} 18 19 //! \cond INTERNAL 20 //! Defines a start offset of each field or flag in object info - the shift can be then used to get/set value from/to 21 //! info bits. 22 ObjectInfoShift :: enum u32 { 23 P_SHIFT = 0, 24 Q_SHIFT = 8, 25 C_SHIFT = 8, 26 B_SHIFT = 12, 27 A_SHIFT = 16, 28 TYPE_SHIFT = 22, 29 R_SHIFT = 29, 30 D_SHIFT = 30, 31 M_SHIFT = 31, 32 SHIFT_FORCE_UINT = 4294967295, 33 } 34 35 //! Defines a mask of each field of the object info. 36 //! 37 //! \note This is part of the official documentation, however, users should not use these enumerations in any context. 38 ObjectInfoBits :: enum u32 { 39 //! Mask describing 'P' payload (8 bits). 40 P_MASK = 255, // [........|........|........|pppppppp] 41 42 //! Mask describing 'Q' payload (8 bits aliased with 'bbbbcccc' bits). 43 Q_MASK = 65280, // [........|........|qqqqqqqq|........] 44 45 //! Mask describing 'C' payload (4 bits). 46 C_MASK = 3840, // [........|........|....cccc|........] 47 48 //! Mask describing 'B' payload (4 bits). 49 B_MASK = 61440, // [........|........|bbbb....|........] 50 51 //! Mask describing 'A' payload (6 bits). 52 A_MASK = 4128768, // [........|..aaaaaa|........|........] 53 54 //! Mask of all payload fields combined, except 'M', 'T', type identification, and 'R' (RefCounted marker). 55 FIELDS_MASK = 4194303, 56 57 //! Mask describing object type (8 bits), see \ref BLObjectType. 58 TYPE_MASK = 532676608, // [...ttttt|tt......|........|........] 59 60 //! Flag describing a ref-counted object (if set together with 'D' flag) 61 //! 62 //! \note This flag is free for use by SSO, it has no meaning when 'D' flag is not set). 63 R_FLAG = 536870912, // [..R.....|........|........|........] 64 65 //! Flag describing a dynamic object - if this flag is not set, it means the object is in SSO mode. 66 D_FLAG = 1073741824, // [.D......|........|........|........] 67 68 //! Flag describing a valid object compatible with \ref BLObjectCore interface (otherwise it's most likely \ref BLRgba). 69 M_FLAG = 2147483648, // [M.......|........|........|........] 70 71 //! A combination of `BL_OBJECT_INFO_M_FLAG` and `BL_OBJECT_INFO_D_FLAG` flags. 72 MD_FLAGS = 3221225472, 73 74 //! A combination of `BL_OBJECT_INFO_M_FLAG`, `BL_OBJECT_INFO_D_FLAG`, `BL_OBJECT_INFO_R_FLAG` flags. 75 MDR_FLAGS = 3758096384, 76 BITS_FORCE_UINT = 4294967295, 77 } 78 79 //! Object type identifier. 80 ObjectType :: enum u32 { 81 //! Object represents a \ref BLRgba value stored as four 32-bit floating point components (can be used as Style). 82 RGBA = 0, 83 84 //! Object represents a \ref BLRgba32 value stored as 32-bit integer in `0xAARRGGBB` form. 85 RGBA32 = 1, 86 87 //! Object represents a \ref BLRgba64 value stored as 64-bit integer in `0xAAAARRRRGGGGBBBB` form. 88 RGBA64 = 2, 89 90 //! Object is `Null` (can be used as style). 91 NULL = 3, 92 93 //! Object is \ref BLPattern (can be used as style). 94 PATTERN = 4, 95 96 //! Object is \ref BLGradient (can be used as style). 97 GRADIENT = 5, 98 99 //! Object is \ref BLImage. 100 IMAGE = 9, 101 102 //! Object is \ref BLPath. 103 PATH = 10, 104 105 //! Object is \ref BLFont. 106 FONT = 16, 107 108 //! Object is \ref BLFontFeatureSettings. 109 FONT_FEATURE_SETTINGS = 17, 110 111 //! Object is \ref BLFontVariationSettings. 112 FONT_VARIATION_SETTINGS = 18, 113 114 //! Object is \ref BLBitArray. 115 BIT_ARRAY = 25, 116 117 //! Object is \ref BLBitSet. 118 BIT_SET = 26, 119 120 //! Object represents a boolean value. 121 BOOL = 28, 122 123 //! Object represents a 64-bit signed integer value. 124 INT64 = 29, 125 126 //! Object represents a 64-bit unsigned integer value. 127 UINT64 = 30, 128 129 //! Object represents a 64-bit floating point value. 130 DOUBLE = 31, 131 132 //! Object is \ref BLString. 133 STRING = 32, 134 135 //! Object is \ref BLArray<T> where `T` is a `BLObject` compatible type. 136 ARRAY_OBJECT = 33, 137 138 //! Object is \ref BLArray<T> where `T` matches 8-bit signed integral type. 139 ARRAY_INT8 = 34, 140 141 //! Object is \ref BLArray<T> where `T` matches 8-bit unsigned integral type. 142 ARRAY_UINT8 = 35, 143 144 //! Object is \ref BLArray<T> where `T` matches 16-bit signed integral type. 145 ARRAY_INT16 = 36, 146 147 //! Object is \ref BLArray<T> where `T` matches 16-bit unsigned integral type. 148 ARRAY_UINT16 = 37, 149 150 //! Object is \ref BLArray<T> where `T` matches 32-bit signed integral type. 151 ARRAY_INT32 = 38, 152 153 //! Object is \ref BLArray<T> where `T` matches 32-bit unsigned integral type. 154 ARRAY_UINT32 = 39, 155 156 //! Object is \ref BLArray<T> where `T` matches 64-bit signed integral type. 157 ARRAY_INT64 = 40, 158 159 //! Object is \ref BLArray<T> where `T` matches 64-bit unsigned integral type. 160 ARRAY_UINT64 = 41, 161 162 //! Object is \ref BLArray<T> where `T` matches 32-bit floating point type. 163 ARRAY_FLOAT32 = 42, 164 165 //! Object is \ref BLArray<T> where `T` matches 64-bit floating point type. 166 ARRAY_FLOAT64 = 43, 167 168 //! Object is \ref BLArray<T> where `T` is a struct of size 1. 169 ARRAY_STRUCT_1 = 44, 170 171 //! Object is \ref BLArray<T> where `T` is a struct of size 2. 172 ARRAY_STRUCT_2 = 45, 173 174 //! Object is \ref BLArray<T> where `T` is a struct of size 3. 175 ARRAY_STRUCT_3 = 46, 176 177 //! Object is \ref BLArray<T> where `T` is a struct of size 4. 178 ARRAY_STRUCT_4 = 47, 179 180 //! Object is \ref BLArray<T> where `T` is a struct of size 6. 181 ARRAY_STRUCT_6 = 48, 182 183 //! Object is \ref BLArray<T> where `T` is a struct of size 8. 184 ARRAY_STRUCT_8 = 49, 185 186 //! Object is \ref BLArray<T> where `T` is a struct of size 10. 187 ARRAY_STRUCT_10 = 50, 188 189 //! Object is \ref BLArray<T> where `T` is a struct of size 12. 190 ARRAY_STRUCT_12 = 51, 191 192 //! Object is \ref BLArray<T> where `T` is a struct of size 16. 193 ARRAY_STRUCT_16 = 52, 194 195 //! Object is \ref BLArray<T> where `T` is a struct of size 20. 196 ARRAY_STRUCT_20 = 53, 197 198 //! Object is \ref BLArray<T> where `T` is a struct of size 24. 199 ARRAY_STRUCT_24 = 54, 200 201 //! Object is \ref BLArray<T> where `T` is a struct of size 32. 202 ARRAY_STRUCT_32 = 55, 203 204 //! Object is \ref BLContext. 205 CONTEXT = 100, 206 207 //! Object is \ref BLImageCodec. 208 IMAGE_CODEC = 101, 209 210 //! Object is \ref BLImageDecoder. 211 IMAGE_DECODER = 102, 212 213 //! Object is \ref BLImageEncoder. 214 IMAGE_ENCODER = 103, 215 216 //! Object is \ref BLFontFace. 217 FONT_FACE = 104, 218 219 //! Object is \ref BLFontData. 220 FONT_DATA = 105, 221 222 //! Object is \ref BLFontManager. 223 FONT_MANAGER = 106, 224 225 //! Minimum object type of an array object. 226 MIN_ARRAY = 33, 227 228 //! Maximum object type of an array object. 229 MAX_ARRAY = 55, 230 231 //! Minimum object type identifier that can be used as a style. 232 MIN_STYLE = 0, 233 234 //! Maximum object type identifier that can be used as a style. 235 MAX_STYLE = 5, 236 237 //! Minimum object type of an object with virtual function table. 238 MIN_VIRTUAL = 100, 239 240 //! Maximum object type of an object with virtual function table. 241 MAX_VIRTUAL = 127, 242 243 //! Maximum possible value of an object type, including identifiers reserved for the future. 244 MAX_VALUE = 127, 245 FORCE_UINT = 4294967295, 246 } 247 248 //! Information bits used by \ref BLObjectCore and all Blend2D compatible objects inheriting it. 249 ObjectInfo :: struct { 250 //! \name Members 251 //! \{ 252 253 //! Stores all object info bits. 254 bits: u32, 255 } 256 257 //! Defines a BLObject layout that all objects must use. 258 ObjectDetail :: struct #raw_union { 259 impl: ^ObjectImpl, 260 char_data: [16]i8, 261 i8_data: [16]i8, 262 u8_data: [16]u8, 263 i16_data: [8]i16, 264 u16_data: [8]u16, 265 i32_data: [4]i32, 266 u32_data: [4]u32, 267 i64_data: [2]i64, 268 u64_data: [2]u64, 269 f32_data: [4]f32, 270 f64_data: [2]f64, 271 rgba: Rgba, 272 rgba32: Rgba32, 273 rgba64: Rgba64, 274 275 using _: struct { 276 u32_data_overlap: [2]u32, 277 impl_payload: u32, 278 info: ObjectInfo, 279 }, 280 } 281 282 //! A function callback that is called when an Impl that holds external data is going to be destroyed. It's 283 //! often used as a notification that a data passed to a certain Impl is no longer in use by Blend2D. 284 DestroyExternalDataFunc :: proc "c" (impl: rawptr, external_data: rawptr, user_data: rawptr) 285 286 //! Base members of \ref BLObjectVirt. 287 //! 288 //! The reason for this struct is to make C API the same as C++ API in terms of struct members. In C++ mode we use 289 //! inheritance so `Virt` structs actually inherit from \ref BLObjectVirt, but in every case all base members are 290 //! provided by `base`. 291 ObjectVirtBase :: struct { 292 destroy: proc "c" (impl: ^ObjectImpl) -> Result, 293 get_property: proc "c" (impl: ^ObjectImpl, name: cstring, name_size: c.size_t, value_out: ^VarCore) -> Result, 294 set_property: proc "c" (impl: ^ObjectImpl, name: cstring, name_size: c.size_t, value: ^VarCore) -> Result, 295 } 296 297 //! BLObject [Virtual Function Table]. 298 //! 299 //! Virtual function table is only present when object type is greater than \ref BL_OBJECT_TYPE_MIN_VIRTUAL. 300 //! Objects can extend the function table, but it has to always start with members defined by `BLObjectVirt`. 301 ObjectVirt :: struct { 302 base: ObjectVirtBase, 303 } 304 305 //! Base class used by all Blend2D objects. 306 ObjectCore :: struct { 307 _d: ObjectDetail, 308 } 309 310 @(default_calling_convention="c", link_prefix="bl_") 311 foreign lib { 312 object_alloc_impl :: proc(self: ^ObjectCore, object_info: u32, impl_size: c.size_t) -> Result --- 313 object_alloc_impl_aligned :: proc(self: ^ObjectCore, object_info: u32, impl_size: c.size_t, impl_alignment: c.size_t) -> Result --- 314 object_alloc_impl_external :: proc(self: ^ObjectCore, object_info: u32, impl_size: c.size_t, immutable: i32, destroy_func: DestroyExternalDataFunc, user_data: rawptr) -> Result --- 315 object_free_impl :: proc(impl: ^ObjectImpl) -> Result --- 316 object_init_move :: proc(self: ^Unknown, other: ^Unknown) -> Result --- 317 object_init_weak :: proc(self: ^Unknown, other: ^Unknown) -> Result --- 318 object_reset :: proc(self: ^Unknown) -> Result --- 319 object_assign_move :: proc(self: ^Unknown, other: ^Unknown) -> Result --- 320 object_assign_weak :: proc(self: ^Unknown, other: ^Unknown) -> Result --- 321 object_get_property :: proc(self: ^Unknown, name: cstring, name_size: c.size_t, value_out: ^VarCore) -> Result --- 322 object_get_property_bool :: proc(self: ^Unknown, name: cstring, name_size: c.size_t, value_out: ^i32) -> Result --- 323 object_get_property_int32 :: proc(self: ^Unknown, name: cstring, name_size: c.size_t, value_out: ^i32) -> Result --- 324 object_get_property_int64 :: proc(self: ^Unknown, name: cstring, name_size: c.size_t, value_out: ^i64) -> Result --- 325 object_get_property_uint32 :: proc(self: ^Unknown, name: cstring, name_size: c.size_t, value_out: ^u32) -> Result --- 326 object_get_property_uint64 :: proc(self: ^Unknown, name: cstring, name_size: c.size_t, value_out: ^u64) -> Result --- 327 object_get_property_double :: proc(self: ^Unknown, name: cstring, name_size: c.size_t, value_out: ^f64) -> Result --- 328 object_set_property :: proc(self: ^Unknown, name: cstring, name_size: c.size_t, value: ^Unknown) -> Result --- 329 object_set_property_bool :: proc(self: ^Unknown, name: cstring, name_size: c.size_t, value: i32) -> Result --- 330 object_set_property_int32 :: proc(self: ^Unknown, name: cstring, name_size: c.size_t, value: i32) -> Result --- 331 object_set_property_int64 :: proc(self: ^Unknown, name: cstring, name_size: c.size_t, value: i64) -> Result --- 332 object_set_property_uint32 :: proc(self: ^Unknown, name: cstring, name_size: c.size_t, value: u32) -> Result --- 333 object_set_property_uint64 :: proc(self: ^Unknown, name: cstring, name_size: c.size_t, value: u64) -> Result --- 334 object_set_property_double :: proc(self: ^Unknown, name: cstring, name_size: c.size_t, value: f64) -> Result --- 335 } 336