Constructs [classGdk.Texture] objects from DMA buffers.
DMA buffers are commonly called dma-bufs.
DMA buffers are a feature of the Linux kernel to enable efficient buffer and memory sharing between hardware such as codecs, GPUs, displays, cameras and the kernel drivers controlling them. For example, a decoder may want its output to be directly shared with the display server for rendering without a copy.
Any device driver which participates in DMA buffer sharing, can do so as either the exporter or importer of buffers (or both).
The memory that is shared via DMA buffers is usually stored in non-system memory (maybe in device's local memory or something else not directly accessible by the CPU), and accessing this memory from the CPU may have higher-than-usual overhead.
In particular for graphics data, it is not uncommon that data consists of multiple separate blocks of memory, for example one block for each of the red, green and blue channels. These blocks are called planes. DMA buffers can have up to four planes. Even if the memory is a single block, the data can be organized in multiple planes, by specifying offsets from the beginning of the data.
DMA buffers are exposed to user-space as file descriptors allowing to pass them between processes. If a DMA buffer has multiple planes, more than one file descriptor may be present, up to the number of planes. If the number of file descriptors is less than the number of planes, the remaining ones should be set to -1.
The format of the data (for graphics data, essentially its colorspace) is described by a 32-bit integer. These format identifiers are defined in the header file drm_fourcc.h and commonly referred to as fourcc values, since they are identified by 4 ASCII characters. Additionally, each DMA buffer has a modifier, which is a 64-bit integer that describes driver-specific details of the memory layout, such as tiling or compression.
For historical reasons, some producers of dma-bufs don't provide an explicit modifier, but instead return DMA_FORMAT_MOD_INVALID to indicate that their modifier is implicit. GTK tries to accommodate this situation by accepting DMA_FORMAT_MOD_INVALID as modifier.
The operation of GdkDmabufTextureBuilder is quite simple: Create a texture builder, set all the necessary properties, and then call [methodGdk.DmabufTextureBuilder.build] to create the new texture.
The required properties for a dma-buf texture are
The width and height in pixels
The fourcc code and modifier which identify the format and memory
layout of the dma-buf
The file descriptor, offset and stride for each of the planes
GdkDmabufTextureBuilder can be used for quick one-shot construction of textures as well as kept around and reused to construct multiple textures.
For further information, see
The Linux kernel
documentation
The header file
drm_fourcc.h
function Build
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Destroy : Glib.G_Destroy_Notify_Address;
Data : System.Address;
Error : out Glib.Error.GError) return Gdk.Texture.Gdk_Texture
Builds a new GdkTexture with the values set up in the builder. It is a programming error to call this function if any mandatory property has not been set. Not all formats defined in the drm_fourcc.h header are supported. You can use [methodGdk.Display.get_dmabuf_formats] to get a list of supported formats. If the format is not supported by GTK, null will be returned and Error will be set. The destroy function gets called when the returned texture gets released. It is the responsibility of the caller to keep the file descriptors for the planes open until the created texture is no longer used, and close them afterwards (possibly using the Destroy notify). It is possible to call this function multiple times to create multiple textures, possibly with changing properties in between. Since: gtk+ 4.14
destroy function to be called when the texture is released
user data to pass to the destroy function
the return location for a recoverable error
a newly built GdkTexture or NULL if the format is not supported. Has transfer-ownership='full'.
Color_State_Property : constant Glib.Properties.Property_Boxed;
Type: Color_State The color state of the texture.
Display_Property : constant Glib.Properties.Property_Boxed;
Type: Display The display that this texture will be used on.
Fourcc_Property : constant Glib.Properties.Property_Uint;
The format of the texture, as a fourcc value.
type Gdk_Dmabuf_Texture_Builder is access all Gdk_Dmabuf_Texture_Builder_Record'Class;
function Gdk_Dmabuf_Texture_Builder_New return Gdk_Dmabuf_Texture_Builder
Creates a new texture builder. Since: gtk+ 4.14
type Gdk_Dmabuf_Texture_Builder_Record is new GObject_Record with null record;
procedure Gdk_New (Self : out Gdk_Dmabuf_Texture_Builder)
Creates a new texture builder. Since: gtk+ 4.14
function Get_Color_State
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record)
return Gdk.Color_State.Gdk_Color_State
Gets the color state previously set via Gdk.Dmabuf_Texture_Builder.Set_Color_State. Since: gtk+ 4.16
the color state. Has transfer-ownership='none'.
function Get_Display
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record)
return Gdk.Gdk_Display
Returns the display that this texture builder is associated with. Since: gtk+ 4.14
the display. Has transfer-ownership='none'.
function Get_Fd
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Plane : Guint) return Glib.Gint
Gets the file descriptor for a plane or -1 if none. Since: gtk+ 4.14
the plane to get the fd for
the file descriptor
function Get_Fourcc
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record)
return Guint32
Gets the format previously set via Gdk.Dmabuf_Texture_Builder.Set_Fourcc or 0 if the format wasn't set. The format is specified as a fourcc code. Since: gtk+ 4.14
The format
function Get_Height
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record)
return Guint
Gets the height previously set via Gdk.Dmabuf_Texture_Builder.Set_Height or 0 if the height wasn't set. Since: gtk+ 4.14
The height
function Get_Modifier
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record)
return Guint64
Gets the modifier value. Since: gtk+ 4.14
the modifier
function Get_N_Planes
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record)
return Guint
Gets the number of planes. Since: gtk+ 4.14
The number of planes
function Get_Offset
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Plane : Guint) return Guint
Gets the offset value for a plane. Since: gtk+ 4.14
the plane to get the offset for
the offset
function Get_Premultiplied
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record)
return Boolean
Whether the data is premultiplied. Since: gtk+ 4.14
whether the data is premultiplied
function Get_Stride
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Plane : Guint) return Guint
Gets the stride value for a plane. Since: gtk+ 4.14
the plane to get the stride for
the stride
function Get_Type return Glib.GType
function Get_Update_Region
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record)
return Cairo.Region.Cairo_Region
Gets the region previously set via Gdk.Dmabuf_Texture_Builder.Set_Update_Region or null if none was set. Since: gtk+ 4.14
The region
function Get_Update_Texture
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record)
return Gdk.Texture.Gdk_Texture
Gets the texture previously set via Gdk.Dmabuf_Texture_Builder.Set_Update_Texture or null if none was set. Since: gtk+ 4.14
The texture. Has transfer-ownership='none'.
function Get_Width
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record)
return Guint
Gets the width previously set via Gdk.Dmabuf_Texture_Builder.Set_Width or 0 if the width wasn't set. Since: gtk+ 4.14
The width
Height_Property : constant Glib.Properties.Property_Uint;
The height of the texture.
procedure Initialize
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record'Class)
Creates a new texture builder. Since: gtk+ 4.14 Initialize does nothing if the object was already created with another call to Initialize* or G_New.
Modifier_Property : constant Glib.Properties.Property_Uint;
Type: Guint64 The modifier.
N_Planes_Property : constant Glib.Properties.Property_Uint;
The number of planes of the texture.
Note that you can set properties for other planes, but they will be ignored when constructing the texture.
Premultiplied_Property : constant Glib.Properties.Property_Boolean;
Whether the alpha channel is premultiplied into the others.
Only relevant if the format has alpha.
procedure Set_Color_State
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Color_State : Gdk.Color_State.Gdk_Color_State)
Sets the color state for the texture. By default, the colorstate is NULL. In that case, GTK will choose the correct colorstate based on the format. If you don't know what colorstates are, this is probably the right thing. Since: gtk+ 4.16
a GdkColorState or NULL to unset the colorstate.
procedure Set_Display
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Display : not null access Gdk.Display.Gdk_Display_Record'Class)
Sets the display that this texture builder is associated with. The display is used to determine the supported dma-buf formats. Since: gtk+ 4.14
the display
procedure Set_Fd
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Plane : Guint;
Fd : Glib.Gint)
Sets the file descriptor for a plane or to -1 to unset it. Since: gtk+ 4.14
the plane to set the fd for
the file descriptor
procedure Set_Fourcc
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Fourcc : Guint32)
Sets the format of the texture. The format is specified as a fourcc code. The format must be set before calling [methodGdk.DmabufTextureBuilder.build]. Since: gtk+ 4.14
the texture's format or 0 to unset
procedure Set_Height
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Height : Guint)
Sets the height of the texture. The height must be set before calling [methodGdk.DmabufTextureBuilder.build]. Since: gtk+ 4.14
the texture's height or 0 to unset
procedure Set_Modifier
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Modifier : Guint64)
Sets the modifier. Since: gtk+ 4.14
the modifier value
procedure Set_N_Planes
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
N_Planes : Guint)
Sets the number of planes of the texture. Since: gtk+ 4.14
the number of planes
procedure Set_Offset
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Plane : Guint;
Offset : Guint)
Sets the offset for a plane. Since: gtk+ 4.14
the plane to set the offset for
the offset value
procedure Set_Premultiplied
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Premultiplied : Boolean)
Sets whether the data is premultiplied. Unless otherwise specified, all formats including alpha channels are assumed to be premultiplied. Since: gtk+ 4.14
whether the data is premultiplied
procedure Set_Stride
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Plane : Guint;
Stride : Guint)
Sets the stride for a plane. The stride must be set for all planes before calling [methodGdk.DmabufTextureBuilder.build]. Since: gtk+ 4.14
the plane to set the stride for
the stride value
procedure Set_Update_Region
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Region : Cairo.Region.Cairo_Region)
Sets the region to be updated by this texture. Together with [propertyGdk.DmabufTextureBuilder:update-texture] this describes an update of a previous texture. When rendering animations of large textures, it is possible that consecutive textures are only updating contents in parts of the texture. It is then possible to describe this update via these two properties, so that GTK can avoid rerendering parts that did not change. An example would be a screen recording where only the mouse pointer moves. Since: gtk+ 4.14
the region to update
procedure Set_Update_Texture
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Texture : access Gdk.Texture.Gdk_Texture_Record'Class)
Sets the texture to be updated by this texture. See [methodGdk.DmabufTextureBuilder.set_update_region] for an explanation. Since: gtk+ 4.14
the texture to update
procedure Set_Width
(Self : not null access Gdk_Dmabuf_Texture_Builder_Record;
Width : Guint)
Sets the width of the texture. The width must be set before calling [methodGdk.DmabufTextureBuilder.build]. Since: gtk+ 4.14
The texture's width or 0 to unset
Update_Region_Property : constant Glib.Properties.Property_Boxed;
Type: cairo.Region The update region for [propertyGdk.DmabufTextureBuilder:update-texture].
Update_Texture_Property : constant Glib.Properties.Property_Boxed;
Type: Texture The texture [propertyGdk.DmabufTextureBuilder:update-region] is an update for.
Width_Property : constant Glib.Properties.Property_Uint;
The width of the texture.