Gdk.DmabufTextureBuilder

g GObject.Object GObject.Object Gdk.DmabufTextureBuilder Gdk.DmabufTextureBuilder GObject.Object->Gdk.DmabufTextureBuilder

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new ()

build (destroy, data)

get_color_state ()

get_display ()

get_fd (plane)

get_fourcc ()

get_height ()

get_modifier ()

get_n_planes ()

get_offset (plane)

get_premultiplied ()

get_stride (plane)

get_update_region ()

get_update_texture ()

get_width ()

set_color_state (color_state)

set_display (display)

set_fd (plane, fd)

set_fourcc (fourcc)

set_height (height)

set_modifier (modifier)

set_n_planes (n_planes)

set_offset (plane, offset)

set_premultiplied (premultiplied)

set_stride (plane, stride)

set_update_region (region)

set_update_texture (texture)

set_width (width)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

color-state

Gdk.ColorState

r/w/en

display

Gdk.Display

r/w/en

fourcc

int

r/w/en

height

int

r/w/en

modifier

int

r/w/en

n-planes

int

r/w/en

premultiplied

bool

r/w/en

update-region

cairo.Region

r/w/en

update-texture

Gdk.Texture

r/w/en

width

int

r/w/en

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Gdk.DmabufTextureBuilder(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Gdk.DmabufTextureBuilderClass

GdkDmabufTextureBuilder is a builder used to construct [class`Gdk`.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, there is one file descriptor per plane.

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 [method`Gdk`.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

New in version 4.14.

classmethod new()[source]
Returns:

the new GdkTextureBuilder

Return type:

Gdk.DmabufTextureBuilder

Creates a new texture builder.

New in version 4.14.

build(destroy, data)[source]
Parameters:
  • destroy (GLib.DestroyNotify or None) – destroy function to be called when the texture is released

  • data (object or None) – user data to pass to the destroy function

Raises:

GLib.Error

Returns:

a newly built GdkTexture or NULL if the format is not supported

Return type:

Gdk.Texture or None

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 [method`Gdk`.Display.get_dmabuf_formats] to get a list of supported formats. If the format is not supported by GTK, None 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.

New in version 4.14.

get_color_state()[source]
Returns:

the color state

Return type:

Gdk.ColorState or None

Gets the color state previously set via Gdk.DmabufTextureBuilder.set_color_state().

New in version 4.16.

get_display()[source]
Returns:

the display

Return type:

Gdk.Display

Returns the display that this texture builder is associated with.

New in version 4.14.

get_fd(plane)[source]
Parameters:

plane (int) – the plane to get the fd for

Returns:

the file descriptor

Return type:

int

Gets the file descriptor for a plane.

New in version 4.14.

get_fourcc()[source]
Returns:

The format

Return type:

int

Gets the format previously set via Gdk.DmabufTextureBuilder.set_fourcc() or 0 if the format wasn’t set.

The format is specified as a fourcc code.

New in version 4.14.

get_height()[source]
Returns:

The height

Return type:

int

Gets the height previously set via Gdk.DmabufTextureBuilder.set_height() or 0 if the height wasn’t set.

New in version 4.14.

get_modifier()[source]
Returns:

the modifier

Return type:

int

Gets the modifier value.

New in version 4.14.

get_n_planes()[source]
Returns:

The number of planes

Return type:

int

Gets the number of planes.

New in version 4.14.

get_offset(plane)[source]
Parameters:

plane (int) – the plane to get the offset for

Returns:

the offset

Return type:

int

Gets the offset value for a plane.

New in version 4.14.

get_premultiplied()[source]
Returns:

whether the data is premultiplied

Return type:

bool

Whether the data is premultiplied.

New in version 4.14.

get_stride(plane)[source]
Parameters:

plane (int) – the plane to get the stride for

Returns:

the stride

Return type:

int

Gets the stride value for a plane.

New in version 4.14.

get_update_region()[source]
Returns:

The region

Return type:

cairo.Region or None

Gets the region previously set via Gdk.DmabufTextureBuilder.set_update_region() or None if none was set.

New in version 4.14.

get_update_texture()[source]
Returns:

The texture

Return type:

Gdk.Texture or None

Gets the texture previously set via Gdk.DmabufTextureBuilder.set_update_texture() or None if none was set.

New in version 4.14.

get_width()[source]
Returns:

The width

Return type:

int

Gets the width previously set via Gdk.DmabufTextureBuilder.set_width() or 0 if the width wasn’t set.

New in version 4.14.

set_color_state(color_state)[source]
Parameters:

color_state (Gdk.ColorState or None) – a GdkColorState or NULL to unset the colorstate.

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.

New in version 4.16.

set_display(display)[source]
Parameters:

display (Gdk.Display) – the display

Sets the display that this texture builder is associated with.

The display is used to determine the supported dma-buf formats.

New in version 4.14.

set_fd(plane, fd)[source]
Parameters:
  • plane (int) – the plane to set the fd for

  • fd (int) – the file descriptor

Sets the file descriptor for a plane.

New in version 4.14.

set_fourcc(fourcc)[source]
Parameters:

fourcc (int) – the texture’s format or 0 to unset

Sets the format of the texture.

The format is specified as a fourcc code.

The format must be set before calling [method`Gdk`.DmabufTextureBuilder.build].

New in version 4.14.

set_height(height)[source]
Parameters:

height (int) – the texture’s height or 0 to unset

Sets the height of the texture.

The height must be set before calling [method`Gdk`.DmabufTextureBuilder.build].

New in version 4.14.

set_modifier(modifier)[source]
Parameters:

modifier (int) – the modifier value

Sets the modifier.

New in version 4.14.

set_n_planes(n_planes)[source]
Parameters:

n_planes (int) – the number of planes

Sets the number of planes of the texture.

New in version 4.14.

set_offset(plane, offset)[source]
Parameters:
  • plane (int) – the plane to set the offset for

  • offset (int) – the offset value

Sets the offset for a plane.

New in version 4.14.

set_premultiplied(premultiplied)[source]
Parameters:

premultiplied (bool) – whether the data is premultiplied

Sets whether the data is premultiplied.

Unless otherwise specified, all formats including alpha channels are assumed to be premultiplied.

New in version 4.14.

set_stride(plane, stride)[source]
Parameters:
  • plane (int) – the plane to set the stride for

  • stride (int) – the stride value

Sets the stride for a plane.

The stride must be set for all planes before calling [method`Gdk`.DmabufTextureBuilder.build].

New in version 4.14.

set_update_region(region)[source]
Parameters:

region (cairo.Region or None) – the region to update

Sets the region to be updated by this texture. Together with [property`Gdk`.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.

New in version 4.14.

set_update_texture(texture)[source]
Parameters:

texture (Gdk.Texture or None) – the texture to update

Sets the texture to be updated by this texture. See [method`Gdk`.DmabufTextureBuilder.set_update_region] for an explanation.

New in version 4.14.

set_width(width)[source]
Parameters:

width (int) – The texture’s width or 0 to unset

Sets the width of the texture.

The width must be set before calling [method`Gdk`.DmabufTextureBuilder.build].

New in version 4.14.

Property Details

Gdk.DmabufTextureBuilder.props.color_state
Name:

color-state

Type:

Gdk.ColorState

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The color state of the texture.

New in version 4.16.

Gdk.DmabufTextureBuilder.props.display
Name:

display

Type:

Gdk.Display

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The display that this texture will be used on.

New in version 4.14.

Gdk.DmabufTextureBuilder.props.fourcc
Name:

fourcc

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The format of the texture, as a fourcc value.

New in version 4.14.

Gdk.DmabufTextureBuilder.props.height
Name:

height

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The height of the texture.

New in version 4.14.

Gdk.DmabufTextureBuilder.props.modifier
Name:

modifier

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The modifier.

New in version 4.14.

Gdk.DmabufTextureBuilder.props.n_planes
Name:

n-planes

Type:

int

Default Value:

1

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

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.

New in version 4.14.

Gdk.DmabufTextureBuilder.props.premultiplied
Name:

premultiplied

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether the alpha channel is premultiplied into the others.

Only relevant if the format has alpha.

New in version 4.14.

Gdk.DmabufTextureBuilder.props.update_region
Name:

update-region

Type:

cairo.Region

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The update region for [property`Gdk`.DmabufTextureBuilder:update-texture].

New in version 4.14.

Gdk.DmabufTextureBuilder.props.update_texture
Name:

update-texture

Type:

Gdk.Texture

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The texture [property`Gdk`.DmabufTextureBuilder:update-region] is an update for.

New in version 4.14.

Gdk.DmabufTextureBuilder.props.width
Name:

width

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The width of the texture.

New in version 4.14.