Blend2D
2D Vector Graphics Engine
Object Model & Memory Layout.
Blend2D object model is a foundation of all Blend2D objects. It was designed only for Blend2D and it's not supposed to be used as a foundation of other libraries. The object model provides runtime reflection, small size optimization (SSO), and good performance. In general, it focuses on optimizing memory footprint by taking advantage of SSO storage, however, this makes the implementation more complex compared to a traditional non-SSO model.
Blend2D object model used by BLObjectCore consists of 16 bytes that have the following layout:
Which allows to have either static or dynamic instances:
impl
is not a valid pointer and cannot be accessed.impl
pointer having a content, which type depends on BLObjectType.The layout was designed to provide the following properties:
32-bit Floating Point is represented the following way (32 bits):
Where:
Blend2D uses a sign bit to determine whether the data is BLRgba or object compatible. This design has been chosen, because we don't allow alpha values to be negative. When the sign bit is set it means that it's a type inherited from BLObjectCore. When the sign bit is not set the whole payload represents 128-bit BLRgba color, where alpha is not a negative number. It's designed in a way that 31 bits out of 32 can be used as payload that represents object type, object info flags, and additional type-dependent payload.
Object info value looks like this (also compared with floating point):
Where:
Common meaning of payload fields:
If the 'D' flag is '1' the following payload fields are used by the allocator (and thus cannot be used by the object):
Not all object support all defined flags, here is a little overview:
A function callback that is called when an Impl that holds external data is going to be destroyed. It's often used as a notification that a data passed to a certain Impl is no longer in use by Blend2D.
Defines a mask of each field of the object info.
Constant | Description |
---|---|
BL_OBJECT_INFO_P_MASK | Mask describing 'P' payload (8 bits). |
BL_OBJECT_INFO_Q_MASK | Mask describing 'Q' payload (8 bits aliased with 'bbbbcccc' bits). |
BL_OBJECT_INFO_C_MASK | Mask describing 'C' payload (4 bits). |
BL_OBJECT_INFO_B_MASK | Mask describing 'B' payload (4 bits). |
BL_OBJECT_INFO_A_MASK | Mask describing 'A' payload (6 bits). |
BL_OBJECT_INFO_FIELDS_MASK | Mask of all payload fields combined, except 'M', 'T', type identification, and 'R' (RefCounted marker). |
BL_OBJECT_INFO_TYPE_MASK | Mask describing object type (8 bits), see BLObjectType. |
BL_OBJECT_INFO_R_FLAG | Flag describing a ref-counted object (if set together with 'D' flag)
|
BL_OBJECT_INFO_D_FLAG | Flag describing a dynamic object - if this flag is not set, it means the object is in SSO mode. |
BL_OBJECT_INFO_M_FLAG | Flag describing a valid object compatible with BLObjectCore interface (otherwise it's most likely BLRgba). |
BL_OBJECT_INFO_MD_FLAGS | A combination of |
BL_OBJECT_INFO_MDR_FLAGS | A combination of |
Object type identifier.
Constant | Description |
---|---|
BL_OBJECT_TYPE_RGBA | Object represents a BLRgba value stored as four 32-bit floating point components (can be used as Style). |
BL_OBJECT_TYPE_RGBA32 | Object represents a BLRgba32 value stored as 32-bit integer in |
BL_OBJECT_TYPE_RGBA64 | Object represents a BLRgba64 value stored as 64-bit integer in |
BL_OBJECT_TYPE_NULL | Object is |
BL_OBJECT_TYPE_PATTERN | Object is BLPattern (can be used as style). |
BL_OBJECT_TYPE_GRADIENT | Object is BLGradient (can be used as style). |
BL_OBJECT_TYPE_IMAGE | Object is BLImage. |
BL_OBJECT_TYPE_PATH | Object is BLPath. |
BL_OBJECT_TYPE_FONT | Object is BLFont. |
BL_OBJECT_TYPE_FONT_FEATURE_SETTINGS | Object is BLFontFeatureSettings. |
BL_OBJECT_TYPE_FONT_VARIATION_SETTINGS | Object is BLFontVariationSettings. |
BL_OBJECT_TYPE_BIT_ARRAY | Object is BLBitArray. |
BL_OBJECT_TYPE_BIT_SET | Object is BLBitSet. |
BL_OBJECT_TYPE_BOOL | Object represents a boolean value. |
BL_OBJECT_TYPE_INT64 | Object represents a 64-bit signed integer value. |
BL_OBJECT_TYPE_UINT64 | Object represents a 64-bit unsigned integer value. |
BL_OBJECT_TYPE_DOUBLE | Object represents a 64-bit floating point value. |
BL_OBJECT_TYPE_STRING | Object is BLString. |
BL_OBJECT_TYPE_ARRAY_OBJECT | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_INT8 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_UINT8 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_INT16 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_UINT16 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_INT32 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_UINT32 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_INT64 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_UINT64 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_FLOAT32 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_FLOAT64 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_STRUCT_1 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_STRUCT_2 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_STRUCT_3 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_STRUCT_4 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_STRUCT_6 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_STRUCT_8 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_STRUCT_10 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_STRUCT_12 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_STRUCT_16 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_STRUCT_20 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_STRUCT_24 | Object is BLArray<T> where |
BL_OBJECT_TYPE_ARRAY_STRUCT_32 | Object is BLArray<T> where |
BL_OBJECT_TYPE_CONTEXT | Object is BLContext. |
BL_OBJECT_TYPE_IMAGE_CODEC | Object is BLImageCodec. |
BL_OBJECT_TYPE_IMAGE_DECODER | Object is BLImageDecoder. |
BL_OBJECT_TYPE_IMAGE_ENCODER | Object is BLImageEncoder. |
BL_OBJECT_TYPE_FONT_FACE | Object is BLFontFace. |
BL_OBJECT_TYPE_FONT_DATA | Object is BLFontData. |
BL_OBJECT_TYPE_FONT_MANAGER | Object is BLFontManager. |
BL_OBJECT_TYPE_MIN_ARRAY | Minimum object type of an array object. |
BL_OBJECT_TYPE_MAX_ARRAY | Maximum object type of an array object. |
BL_OBJECT_TYPE_MIN_STYLE | Minimum object type identifier that can be used as a style. |
BL_OBJECT_TYPE_MAX_STYLE | Maximum object type identifier that can be used as a style. |
BL_OBJECT_TYPE_MIN_VIRTUAL | Minimum object type of an object with virtual function table. |
BL_OBJECT_TYPE_MAX_VIRTUAL | Maximum object type of an object with virtual function table. |
BL_OBJECT_TYPE_MAX_VALUE | Maximum possible value of an object type, including identifiers reserved for the future. |