Skip to content

Gdk.MemoryTextureBuilder

class — extends GObject.Object

Constructs Texture objects from system memory provided via GLib.Bytes.

The operation is quite simple: Create a texture builder, set all the necessary properties - keep in mind that the properties MemoryTextureBuilder.bytes, MemoryTextureBuilder.stride, MemoryTextureBuilder.width, and MemoryTextureBuilder.height are mandatory - and then call MemoryTextureBuilder.build to create the new texture.

GdkMemoryTextureBuilder can be used for quick one-shot construction of textures as well as kept around and reused to construct multiple textures.

Constructors

new

@classmethod
def new(cls) -> MemoryTextureBuilder

Creates a new texture builder.

Methods

build

def build(self) -> Texture

Builds a new GdkTexture with the values set up in the builder.

Note that it is a programming error to call this function if any mandatory property has not been set.

It is possible to call this function multiple times to create multiple textures, possibly with changing properties in between.

get_bytes

def get_bytes(self) -> bytes | None

Gets the bytes previously set via MemoryTextureBuilder.set_bytes or None if none was set.

get_color_state

def get_color_state(self) -> ColorState

Gets the colorstate previously set via MemoryTextureBuilder.set_color_state.

get_format

def get_format(self) -> MemoryFormat

Gets the format previously set via MemoryTextureBuilder.set_format.

get_height

def get_height(self) -> int

Gets the height previously set via MemoryTextureBuilder.set_height or 0 if the height wasn't set.

get_offset

def get_offset(self, plane: int) -> int

Gets the offset previously set via MemoryTextureBuilder.set_offset.

Parameters:

  • plane — a plane

get_stride

def get_stride(self) -> int

Gets the stride previously set via MemoryTextureBuilder.set_stride.

get_stride_for_plane

def get_stride_for_plane(self, plane: int) -> int

Gets the stride previously set via MemoryTextureBuilder.set_stride_for_plane.

Parameters:

  • plane — a plane

get_update_region

def get_update_region(self) -> cairo.Region | None

Gets the region previously set via MemoryTextureBuilder.set_update_region or None if none was set.

get_update_texture

def get_update_texture(self) -> Texture | None

Gets the texture previously set via MemoryTextureBuilder.set_update_texture or None if none was set.

get_width

def get_width(self) -> int

Gets the width previously set via MemoryTextureBuilder.set_width or 0 if the width wasn't set.

set_bytes

def set_bytes(self, bytes: bytes | None = ...) -> None

Sets the data to be shown but the texture.

The bytes must be set before calling MemoryTextureBuilder.build.

Parameters:

  • bytes — The bytes the texture shows or None to unset

set_color_state

def set_color_state(self, color_state: ColorState) -> None

Sets the colorstate describing the data.

By default, the sRGB colorstate is used. If you don't know what colorstates are, this is probably the right thing.

Parameters:

  • color_state — The colorstate describing the data

set_format

def set_format(self, format: MemoryFormat | int) -> None

Sets the format of the bytes.

The default is GDK_MEMORY_R8G8B8A8_PREMULTIPLIED.

Parameters:

  • format — The texture's format

set_height

def set_height(self, height: int) -> None

Sets the height of the texture.

The height must be set before calling MemoryTextureBuilder.build and conform to size requirements of the provided format.

Parameters:

  • height — The texture's height or 0 to unset

set_offset

def set_offset(self, plane: int, offset: int) -> None

Sets the offset of the texture for plane.

Parameters:

  • plane — a plane
  • offset — the texture's offset for plane

set_stride

def set_stride(self, stride: int) -> None

Sets the rowstride of the bytes used.

The rowstride must be set before calling MemoryTextureBuilder.build.

Parameters:

  • stride — the stride or 0 to unset

set_stride_for_plane

def set_stride_for_plane(self, plane: int, stride: int) -> None

Sets the stride of the texture for plane.

Parameters:

  • plane — a plane
  • stride — the texture's stride for plane

set_update_region

def set_update_region(self, region: cairo.Region | None = ...) -> None

Sets the region to be updated by this texture.

Together with MemoryTextureBuilder.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.

Parameters:

  • region — the region to update

set_update_texture

def set_update_texture(self, texture: Texture | None = ...) -> None

Sets the texture to be updated by this texture.

See MemoryTextureBuilder.set_update_region for an explanation.

Parameters:

  • texture — the texture to update

set_width

def set_width(self, width: int) -> None

Sets the width of the texture.

The width must be set before calling MemoryTextureBuilder.build and conform to size requirements of the provided format.

Parameters:

  • width — The texture's width or 0 to unset

Properties

bytes

bytes: bytes  # read/write

The bytes holding the data.

color_state

color_state: ColorState  # read/write

The colorstate describing the data.

format

format: MemoryFormat | int  # read/write

The format of the data.

height

height: int  # read/write

The height of the texture.

stride

stride: int  # read/write

The rowstride of the texture.

The rowstride is the number of bytes between the first pixel in a row of image data, and the first pixel in the next row.

update_region

update_region: cairo.Region  # read/write

The update region for MemoryTextureBuilder.update-texture.

update_texture

update_texture: Texture  # read/write

The texture MemoryTextureBuilder.update-region is an update for.

width

width: int  # read/write

The width of the texture.