buffer: add wlr_buffer_get_dmabuf

This commit is contained in:
Simon Ser 2019-04-29 22:33:46 +03:00 committed by Drew DeVault
parent 6dbdf5db34
commit 493804e421
2 changed files with 25 additions and 0 deletions

View file

@ -11,6 +11,7 @@
#include <pixman.h>
#include <wayland-server.h>
#include <wlr/render/dmabuf.h>
/**
* A client buffer.
@ -67,5 +68,11 @@ void wlr_buffer_unref(struct wlr_buffer *buffer);
*/
struct wlr_buffer *wlr_buffer_apply_damage(struct wlr_buffer *buffer,
struct wl_resource *resource, pixman_region32_t *damage);
/**
* 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);
#endif

View file

@ -203,3 +203,21 @@ struct wlr_buffer *wlr_buffer_apply_damage(struct wlr_buffer *buffer,
buffer->released = true;
return buffer;
}
bool wlr_buffer_get_dmabuf(struct wlr_buffer *buffer,
struct wlr_dmabuf_attributes *attribs) {
if (buffer->resource == NULL) {
return false;
}
struct wl_resource *buffer_resource = buffer->resource;
if (!wlr_dmabuf_v1_resource_is_buffer(buffer_resource)) {
return false;
}
struct wlr_dmabuf_v1_buffer *dmabuf_buffer =
wlr_dmabuf_v1_buffer_from_buffer_resource(buffer_resource);
memcpy(attribs, &dmabuf_buffer->attributes,
sizeof(struct wlr_dmabuf_attributes));
return true;
}