From b264ec7767ab3e3fdfe0d1cf2372c26403787245 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 9 Dec 2022 18:06:26 +0100 Subject: [PATCH] linux-dmabuf-v1: add basic helpers for feedback --- include/wlr/types/wlr_linux_dmabuf_v1.h | 13 +++++++++++++ types/wlr_linux_dmabuf_v1.c | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/wlr/types/wlr_linux_dmabuf_v1.h b/include/wlr/types/wlr_linux_dmabuf_v1.h index e850ea6b..94fffe98 100644 --- a/include/wlr/types/wlr_linux_dmabuf_v1.h +++ b/include/wlr/types/wlr_linux_dmabuf_v1.h @@ -98,4 +98,17 @@ bool wlr_linux_dmabuf_v1_set_surface_feedback( struct wlr_linux_dmabuf_v1 *linux_dmabuf, struct wlr_surface *surface, const struct wlr_linux_dmabuf_feedback_v1 *feedback); +/** + * Append a tranche at the end of the DMA-BUF feedback list. + * + * Tranches must be added with decreasing priority. + */ +struct wlr_linux_dmabuf_feedback_v1_tranche *wlr_linux_dmabuf_feedback_add_tranche( + struct wlr_linux_dmabuf_feedback_v1 *feedback); + +/** + * Release resources allocated by a DMA-BUF feedback object. + */ +void wlr_linux_dmabuf_feedback_v1_finish(struct wlr_linux_dmabuf_feedback_v1 *feedback); + #endif diff --git a/types/wlr_linux_dmabuf_v1.c b/types/wlr_linux_dmabuf_v1.c index 52135b08..07f62909 100644 --- a/types/wlr_linux_dmabuf_v1.c +++ b/types/wlr_linux_dmabuf_v1.c @@ -1056,3 +1056,23 @@ bool wlr_linux_dmabuf_v1_set_surface_feedback( return true; } + +struct wlr_linux_dmabuf_feedback_v1_tranche *wlr_linux_dmabuf_feedback_add_tranche( + struct wlr_linux_dmabuf_feedback_v1 *feedback) { + struct wlr_linux_dmabuf_feedback_v1_tranche *tranche = + wl_array_add(&feedback->tranches, sizeof(*tranche)); + if (tranche == NULL) { + wlr_log_errno(WLR_ERROR, "Allocation failed"); + return NULL; + } + memset(tranche, 0, sizeof(*tranche)); + return tranche; +} + +void wlr_linux_dmabuf_feedback_v1_finish(struct wlr_linux_dmabuf_feedback_v1 *feedback) { + struct wlr_linux_dmabuf_feedback_v1_tranche *tranche; + wl_array_for_each(tranche, &feedback->tranches) { + wlr_drm_format_set_finish(&tranche->formats); + } + wl_array_release(&feedback->tranches); +}