Documentation for <wlr/types/wlr_buffer.h>

Back to index

Table of contents

struct wlr_buffer

struct wlr_buffer {
	const struct wlr_buffer_impl *impl;
	int width, height;
	bool dropped;
	size_t n_locks;
	bool accessing_data_ptr;
	struct {
		struct wl_signal destroy;
		struct wl_signal release;
	} events;
	struct wlr_addon_set addons;
};

A buffer containing pixel data.

A buffer has a single producer (the party who created the buffer) and multiple consumers (parties reading the buffer). When all consumers are done with the buffer, it gets released and can be re-used by the producer. When the producer and all consumers are done with the buffer, it gets destroyed.

wlr_buffer_begin_data_ptr_access()

bool wlr_buffer_begin_data_ptr_access(​struct wlr_buffer *buffer, uint32_t flags, void **data, uint32_t *format, size_t *stride);

Get a pointer to a region of memory referring to the buffer's underlying storage. The format and stride can be used to interpret the memory region contents.

The returned pointer should be pointing to a valid memory region for the operations specified in the flags. The returned pointer is only valid up to the next wlr_buffer_end_data_ptr_access() call.

enum wlr_buffer_cap

enum wlr_buffer_cap {
	WLR_BUFFER_CAP_DATA_PTR,
	WLR_BUFFER_CAP_DMABUF,
	WLR_BUFFER_CAP_SHM,
};

Buffer capabilities.

These bits indicate the features supported by a struct wlr_buffer. There is one bit per function in struct wlr_buffer_impl.

enum wlr_buffer_data_ptr_access_flag

enum wlr_buffer_data_ptr_access_flag {
	WLR_BUFFER_DATA_PTR_ACCESS_READ,
	WLR_BUFFER_DATA_PTR_ACCESS_WRITE,
};

Buffer data pointer access flags.

wlr_buffer_drop()

void wlr_buffer_drop(​struct wlr_buffer *buffer);

Unreference the buffer. This function should be called by producers when they are done with the buffer.

wlr_buffer_end_data_ptr_access()

void wlr_buffer_end_data_ptr_access(​struct wlr_buffer *buffer);

wlr_buffer_from_resource()

struct wlr_buffer *wlr_buffer_from_resource(​struct wl_resource *resource);

Transforms a struct wl_resource into a struct wlr_buffer and locks it. Once the caller is done with the buffer, they must call wlr_buffer_unlock().

The provided struct wl_resource must be a wl_buffer.

wlr_buffer_get_dmabuf()

bool wlr_buffer_get_dmabuf(​struct wlr_buffer *buffer, struct wlr_dmabuf_attributes *attribs);

Reads the DMA-BUF attributes of the buffer. If this buffer isn't a DMA-BUF, returns false.

The returned DMA-BUF attributes are valid for the lifetime of the struct wlr_buffer. The caller isn't responsible for cleaning up the DMA-BUF attributes.

wlr_buffer_get_shm()

bool wlr_buffer_get_shm(​struct wlr_buffer *buffer, struct wlr_shm_attributes *attribs);

Read shared memory attributes of the buffer. If this buffer isn't shared memory, returns false.

The returned shared memory attributes are valid for the lifetime of the struct wlr_buffer. The caller isn't responsible for cleaning up the shared memory attributes.

wlr_buffer_lock()

struct wlr_buffer *wlr_buffer_lock(​struct wlr_buffer *buffer);

Lock the buffer. This function should be called by consumers to make sure the buffer can be safely read from. Once the consumer is done with the buffer, they should call wlr_buffer_unlock().

wlr_buffer_unlock()

void wlr_buffer_unlock(​struct wlr_buffer *buffer);

Unlock the buffer. This function should be called by consumers once they are done with the buffer.

struct wlr_client_buffer

struct wlr_client_buffer {
	struct wlr_buffer base;
	struct wlr_texture *texture;
	struct wlr_buffer *source;
	struct wl_listener source_destroy;
	uint32_t shm_source_format;
};

A client buffer.

wlr_client_buffer_apply_damage()

bool wlr_client_buffer_apply_damage(​struct wlr_client_buffer *client_buffer, struct wlr_buffer *next, pixman_region32_t *damage);

Try to update the buffer's content.

Fails if there's more than one reference to the buffer or if the texture isn't mutable.

wlr_client_buffer_create()

struct wlr_client_buffer *wlr_client_buffer_create(​struct wlr_buffer *buffer, struct wlr_renderer *renderer);

Creates a struct wlr_client_buffer from a given struct wlr_buffer by creating a texture from it, and copying its struct wl_resource.

wlr_client_buffer_get()

struct wlr_client_buffer *wlr_client_buffer_get(​struct wlr_buffer *buffer);

Get a client buffer from a generic buffer. If the buffer isn't a client buffer, returns NULL.

wlr_resource_is_buffer()

bool wlr_resource_is_buffer(​struct wl_resource *resource);

Check if a resource is a wl_buffer resource.

struct wlr_shm_attributes

struct wlr_shm_attributes {
	int fd;
	uint32_t format;
	int width, height, stride;
	off_t offset;
};