Skip to content

wayland.client.memory_pool ¤

SharedMemoryPool ¤

SharedMemoryPool(shm: wl_shm)

A helper that provides a simple method of managing surface memory pools and buffers.

Simply call create_buffer(width, height) any time a buffer is required for updating a surface. A wayland.wl_buffer instance and a pointer to the buffer are returned. This class handles everything else, double buffering (quad-buffering by default in fact), pool resizing, etc.

See examples/30-main-window.py for an example using SharedMemoryPool to display a main application window surface.

Parameters:

  • shm ¤

    (wl_shm) –

    Wayland shared memory object.

Methods:

  • create_buffer

    Get a pointer to a buffer, creating it if necessary.

bytes_per_pixel instance-attribute ¤

bytes_per_pixel = 4

force_release_frames instance-attribute ¤

force_release_frames = 3

hysteresis_threshold instance-attribute ¤

hysteresis_threshold = 0.1

number_of_buffers instance-attribute ¤

number_of_buffers = 4

waste_threshold instance-attribute ¤

waste_threshold = 5.5

create_buffer ¤

create_buffer(
    width: int, height: int, pixel_format: format = argb8888
) -> tuple[wl_buffer, POINTER[c_uint8]] | tuple[None, None]

Get a pointer to a buffer, creating it if necessary.

The buffer pointer returned is cast to ctypes.c_uint8 (unsigned byte), it is suitable for directly writing into, either from Python or with an external library, such as cv2, pillow, etc.

Parameters:

  • width ¤

    (int) –

    Width of the buffer in pixels

  • height ¤

    (int) –

    Height of the buffer in pixels

  • pixel_format ¤

    (format, default: argb8888 ) –

    The pixel format of the surface.

Returns:

SharedMemoryPoolError ¤

Exception for SharedMemoryPool errors.