1.18 <GdkDmabufTextureBuilder>

Class: <GdkDmabufTextureBuilder>

It derives from <GObject>.

Constructs <GdkTexture> 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 dmabuf-texture-builder: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

Properties

Property: dmabuf-texture-builder:color-state self

The color state of the texture.

Its value is a <GdkColorState>, or #f.

Set it with (set! (dmabuf-texture-builder:color-state self) value).

Property: dmabuf-texture-builder:display self

The display that this texture will be used on.

Its value is a <GdkDisplay>, or #f.

Set it with (set! (dmabuf-texture-builder:display self) value).

Property: dmabuf-texture-builder:fourcc self

The format of the texture, as a fourcc value.

Its value is an unsigned 32-bit integer.

Set it with (set! (dmabuf-texture-builder:fourcc self) value).

Property: dmabuf-texture-builder:height self

The height of the texture.

Its value is an unsigned 32-bit integer.

Set it with (set! (dmabuf-texture-builder:height self) value).

Property: dmabuf-texture-builder:modifier self

The modifier.

Its value is an unsigned 64-bit integer.

Set it with (set! (dmabuf-texture-builder:modifier self) value).

Property: dmabuf-texture-builder:n-planes self

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.

Its value is an unsigned 32-bit integer.

Set it with (set! (dmabuf-texture-builder:n-planes self) value).

Property: dmabuf-texture-builder:premultiplied self

Whether the alpha channel is premultiplied into the others.

Only relevant if the format has alpha.

Its value is a boolean.

Set it with (set! (dmabuf-texture-builder:premultiplied self) value).

Property: dmabuf-texture-builder:update-region self

The update region for dmabuf-texture-builder:update-texture.

Its value is a <CairoRegion>, or #f.

Set it with (set! (dmabuf-texture-builder:update-region self) value).

Property: dmabuf-texture-builder:update-texture self

The texture dmabuf-texture-builder:update-region is an update for.

Its value is a <GdkTexture>, or #f.

Set it with (set! (dmabuf-texture-builder:update-texture self) value).

Property: dmabuf-texture-builder:width self

The width of the texture.

Its value is an unsigned 32-bit integer.

Set it with (set! (dmabuf-texture-builder:width self) value).

Procedures

Method: dmabuf-texture-builder:build self [destroy] [data] ⇒ %return
Method: build self [destroy] [data] ⇒ %return

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 display:get-dmabuf-formats to get a list of supported formats. If the format is not supported by GTK, #f 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.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

destroy

Passed, or left out: a procedure, or #f.

destroy function to be called when the texture is released

See GDestroyNotify for how it is called.

data

Passed, or left out: a foreign pointer, or a bytevector, or #f.

user data to pass to the destroy function

%return

Returned: a <GdkTexture>, or #f.

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

Method: dmabuf-texture-builder:get-color-state self ⇒ %return
Method: get-color-state self ⇒ %return

Gets the color state previously set via dmabuf-texture-builder:set-color-state.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

%return

Returned: a <GdkColorState>, or #f.

the color state

Method: dmabuf-texture-builder:get-display self ⇒ %return
Method: get-display self ⇒ %return

Returns the display that this texture builder is associated with.

self

Passed: a <GdkDmabufTextureBuilder>.

a ‘GdkDmabufTextureBuilder

%return

Returned: a <GdkDisplay>.

the display

Method: dmabuf-texture-builder:get-fd self plane ⇒ %return
Method: get-fd self plane ⇒ %return

Gets the file descriptor for a plane or -1 if none.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

plane

Passed: an unsigned 32-bit integer.

the plane to get the fd for

%return

Returned: a 32-bit integer.

the file descriptor

Method: dmabuf-texture-builder:get-fourcc self ⇒ %return
Method: get-fourcc self ⇒ %return

Gets the format previously set via dmabuf-texture-builder:set-fourcc or 0 if the format wasn’t set.

The format is specified as a fourcc code.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

%return

Returned: an unsigned 32-bit integer.

The format

Method: dmabuf-texture-builder:get-height self ⇒ %return
Method: get-height self ⇒ %return

Gets the height previously set via dmabuf-texture-builder:set-height or 0 if the height wasn’t set.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

%return

Returned: an unsigned 32-bit integer.

The height

Method: dmabuf-texture-builder:get-modifier self ⇒ %return
Method: get-modifier self ⇒ %return

Gets the modifier value.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

%return

Returned: an unsigned 64-bit integer.

the modifier

Method: dmabuf-texture-builder:get-n-planes self ⇒ %return
Method: get-n-planes self ⇒ %return

Gets the number of planes.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

%return

Returned: an unsigned 32-bit integer.

The number of planes

Method: dmabuf-texture-builder:get-offset self plane ⇒ %return
Method: get-offset self plane ⇒ %return

Gets the offset value for a plane.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

plane

Passed: an unsigned 32-bit integer.

the plane to get the offset for

%return

Returned: an unsigned 32-bit integer.

the offset

Method: dmabuf-texture-builder:get-premultiplied? self ⇒ %return
Method: get-premultiplied? self ⇒ %return

Whether the data is premultiplied.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

%return

Returned: a boolean.

whether the data is premultiplied

Method: dmabuf-texture-builder:get-stride self plane ⇒ %return
Method: get-stride self plane ⇒ %return

Gets the stride value for a plane.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

plane

Passed: an unsigned 32-bit integer.

the plane to get the stride for

%return

Returned: an unsigned 32-bit integer.

the stride

Method: dmabuf-texture-builder:get-update-region self ⇒ %return
Method: get-update-region self ⇒ %return

Gets the region previously set via dmabuf-texture-builder:set-update-region or #f if none was set.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

%return

Returned: a <CairoRegion>, or #f.

The region

Method: dmabuf-texture-builder:get-update-texture self ⇒ %return
Method: get-update-texture self ⇒ %return

Gets the texture previously set via dmabuf-texture-builder:set-update-texture or #f if none was set.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

%return

Returned: a <GdkTexture>, or #f.

The texture

Method: dmabuf-texture-builder:get-width self ⇒ %return
Method: get-width self ⇒ %return

Gets the width previously set via dmabuf-texture-builder:set-width or 0 if the width wasn’t set.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

%return

Returned: an unsigned 32-bit integer.

The width

Procedure: dmabuf-texture-builder:new ⇒ %return

Creates a new texture builder.

%return

Returned: a <GdkDmabufTextureBuilder>.

the new GdkTextureBuilder

Method: dmabuf-texture-builder:set-color-state self [color-state]
Method: set-color-state self [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.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

color-state

Passed, or left out: a <GdkColorState>, or #f.

a <GdkColorState> or NULL to unset the colorstate.

Method: dmabuf-texture-builder:set-display self display
Method: set-display self display

Sets the display that this texture builder is associated with.

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

self

Passed: a <GdkDmabufTextureBuilder>.

a ‘GdkDmabufTextureBuilder

display

Passed: a <GdkDisplay>.

the display

Method: dmabuf-texture-builder:set-fd self plane fd
Method: set-fd self plane fd

Sets the file descriptor for a plane or to -1 to unset it.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

plane

Passed: an unsigned 32-bit integer.

the plane to set the fd for

fd

Passed: a 32-bit integer.

the file descriptor

Method: dmabuf-texture-builder:set-fourcc self fourcc
Method: set-fourcc self fourcc

Sets the format of the texture.

The format is specified as a fourcc code.

The format must be set before calling dmabuf-texture-builder:build.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

fourcc

Passed: an unsigned 32-bit integer.

the texture’s format or 0 to unset

Method: dmabuf-texture-builder:set-height self height
Method: set-height self height

Sets the height of the texture.

The height must be set before calling dmabuf-texture-builder:build.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

height

Passed: an unsigned 32-bit integer.

the texture’s height or 0 to unset

Method: dmabuf-texture-builder:set-modifier self modifier
Method: set-modifier self modifier

Sets the modifier.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

modifier

Passed: an unsigned 64-bit integer.

the modifier value

Method: dmabuf-texture-builder:set-n-planes self n-planes
Method: set-n-planes self n-planes

Sets the number of planes of the texture.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

n-planes

Passed: an unsigned 32-bit integer.

the number of planes

Method: dmabuf-texture-builder:set-offset self plane offset
Method: set-offset self plane offset

Sets the offset for a plane.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

plane

Passed: an unsigned 32-bit integer.

the plane to set the offset for

offset

Passed: an unsigned 32-bit integer.

the offset value

Method: dmabuf-texture-builder:set-premultiplied self premultiplied
Method: set-premultiplied self premultiplied

Sets whether the data is premultiplied.

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

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

premultiplied

Passed: a boolean.

whether the data is premultiplied

Method: dmabuf-texture-builder:set-stride self plane stride
Method: set-stride self plane stride

Sets the stride for a plane.

The stride must be set for all planes before calling dmabuf-texture-builder:build.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

plane

Passed: an unsigned 32-bit integer.

the plane to set the stride for

stride

Passed: an unsigned 32-bit integer.

the stride value

Method: dmabuf-texture-builder:set-update-region self [region]
Method: set-update-region self [region]

Sets the region to be updated by this texture. Together with dmabuf-texture-builder: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.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

region

Passed, or left out: a <CairoRegion>, or #f.

the region to update

Method: dmabuf-texture-builder:set-update-texture self [texture]
Method: set-update-texture self [texture]

Sets the texture to be updated by this texture. See dmabuf-texture-builder:set-update-region for an explanation.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

texture

Passed, or left out: a <GdkTexture>, or #f.

the texture to update

Method: dmabuf-texture-builder:set-width self width
Method: set-width self width

Sets the width of the texture.

The width must be set before calling dmabuf-texture-builder:build.

self

Passed: a <GdkDmabufTextureBuilder>.

a <GdkDmabufTextureBuilder>

width

Passed: an unsigned 32-bit integer.

The texture’s width or 0 to unset