wlroots/include/wlr/types/wlr_buffer.h

129 lines
3.6 KiB
C
Raw Normal View History

/*
* This an unstable interface of wlroots. No guarantees are made regarding the
* future consistency of this API.
*/
#ifndef WLR_USE_UNSTABLE
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
#endif
2018-06-08 19:06:13 +00:00
#ifndef WLR_TYPES_WLR_BUFFER_H
#define WLR_TYPES_WLR_BUFFER_H
#include <pixman.h>
#include <wayland-server-core.h>
2019-04-29 19:33:46 +00:00
#include <wlr/render/dmabuf.h>
2018-06-08 19:06:13 +00:00
struct wlr_buffer;
struct wlr_buffer_impl {
void (*destroy)(struct wlr_buffer *buffer);
bool (*get_dmabuf)(struct wlr_buffer *buffer,
struct wlr_dmabuf_attributes *attribs);
};
/**
* 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.
*/
struct wlr_buffer {
const struct wlr_buffer_impl *impl;
bool dropped;
size_t n_locks;
2020-02-28 12:14:06 +00:00
struct {
struct wl_signal destroy;
struct wl_signal release;
2020-02-28 12:14:06 +00:00
} events;
};
/**
* Initialize a buffer. This function should be called by producers. The
* initialized buffer is referenced: once the producer is done with the buffer
* they should call wlr_buffer_drop.
*/
void wlr_buffer_init(struct wlr_buffer *buffer,
const struct wlr_buffer_impl *impl);
/**
* Unreference the buffer. This function should be called by producers when
* they are done with the buffer.
*/
void wlr_buffer_drop(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.
*/
struct wlr_buffer *wlr_buffer_lock(struct wlr_buffer *buffer);
/**
* Unlock the buffer. This function should be called by consumers once they are
* done with the buffer.
*/
void wlr_buffer_unlock(struct wlr_buffer *buffer);
/**
* Reads the DMA-BUF attributes of the buffer. If this buffer isn't a DMA-BUF,
* returns false.
*/
bool wlr_buffer_get_dmabuf(struct wlr_buffer *buffer,
struct wlr_dmabuf_attributes *attribs);
2018-06-08 19:28:57 +00:00
/**
* A client buffer.
*/
struct wlr_client_buffer {
struct wlr_buffer base;
/**
* The buffer resource, if any. Will be NULL if the client destroys it.
*/
struct wl_resource *resource;
/**
* Whether a release event has been sent to the resource.
*/
bool resource_released;
/**
* The buffer's texture, if any. A buffer will not have a texture if the
* client destroys the buffer before it has been released.
*/
struct wlr_texture *texture;
2018-06-08 19:06:13 +00:00
struct wl_listener resource_destroy;
struct wl_listener release;
2018-06-08 19:06:13 +00:00
};
struct wlr_renderer;
2018-06-08 19:28:57 +00:00
/**
* Check if a resource is a wl_buffer resource.
*/
2018-06-08 19:06:13 +00:00
bool wlr_resource_is_buffer(struct wl_resource *resource);
2018-06-08 19:28:57 +00:00
/**
* Get the size of a wl_buffer resource.
*/
bool wlr_resource_get_buffer_size(struct wl_resource *resource,
2018-06-08 19:06:13 +00:00
struct wlr_renderer *renderer, int *width, int *height);
2018-06-08 19:28:57 +00:00
/**
* Import a client buffer and lock it.
*
* Once the caller is done with the buffer, they must call wlr_buffer_unlock.
2018-06-08 19:28:57 +00:00
*/
struct wlr_client_buffer *wlr_client_buffer_import(
struct wlr_renderer *renderer, struct wl_resource *resource);
2018-06-08 19:28:57 +00:00
/**
* Try to update the buffer's content. On success, returns the updated buffer
* and destroys the provided `buffer`. On error, `buffer` is intact and NULL is
* returned.
*
* Fails if there's more than one reference to the buffer or if the texture
* isn't mutable.
*/
struct wlr_client_buffer *wlr_client_buffer_apply_damage(
struct wlr_client_buffer *buffer, struct wl_resource *resource,
pixman_region32_t *damage);
2018-06-08 19:06:13 +00:00
#endif