aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/wlr/types/wlr_buffer.h7
-rw-r--r--types/wlr_buffer.c18
2 files changed, 25 insertions, 0 deletions
diff --git a/include/wlr/types/wlr_buffer.h b/include/wlr/types/wlr_buffer.h
index 0c987b17..11b36596 100644
--- a/include/wlr/types/wlr_buffer.h
+++ b/include/wlr/types/wlr_buffer.h
@@ -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
diff --git a/types/wlr_buffer.c b/types/wlr_buffer.c
index cec3475c..9d079b9a 100644
--- a/types/wlr_buffer.c
+++ b/types/wlr_buffer.c
@@ -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;
+}