new/yocto/meta-rockchip/recipes-graphics/wayland/weston_10.0.2/0057-backend-drm-Support-getting-drm-fb-from-dmabuf-direc.patch
2025-05-10 21:58:58 +08:00

89 lines
2.6 KiB
Diff

From 1ae29ca69d05cb28e60488ba90811ff9fe5fadbf Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Mon, 7 Mar 2022 15:56:19 +0800
Subject: [PATCH 57/79] backend-drm: Support getting drm fb from dmabuf
directly
Try to import dmabuf to drm fb directly when GBM fd-import not working.
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
libweston/backend-drm/fb.c | 46 ++++++++++++++++++++++++--------------
1 file changed, 29 insertions(+), 17 deletions(-)
diff --git a/libweston/backend-drm/fb.c b/libweston/backend-drm/fb.c
index 3790a73..aba17bf 100644
--- a/libweston/backend-drm/fb.c
+++ b/libweston/backend-drm/fb.c
@@ -224,10 +224,18 @@ drm_fb_destroy_gbm(struct gbm_bo *bo, void *data)
static void
drm_fb_destroy_dmabuf(struct drm_fb *fb)
{
- /* We deliberately do not close the GEM handles here; GBM manages
- * their lifetime through the BO. */
- if (fb->bo)
+ if (fb->bo) {
+ /* We deliberately do not close the GEM handles here; GBM manages
+ * their lifetime through the BO. */
gbm_bo_destroy(fb->bo);
+ } else {
+ int i;
+ for (i = 0; i < fb->num_planes; i++) {
+ struct drm_gem_close arg = { fb->handles[i], };
+ drmIoctl(fb->fd, DRM_IOCTL_GEM_CLOSE, &arg);
+ }
+ }
+
drm_fb_destroy(fb);
}
@@ -293,13 +301,6 @@ drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf,
fb->bo = gbm_bo_import(backend->gbm, GBM_BO_IMPORT_FD_MODIFIER,
&import_mod, GBM_BO_USE_SCANOUT);
- if (!fb->bo) {
- if (try_view_on_plane_failure_reasons)
- *try_view_on_plane_failure_reasons |=
- FAILURE_REASONS_GBM_BO_IMPORT_FAILED;
- goto err_free;
- }
-
fb->width = dmabuf->attributes.width;
fb->height = dmabuf->attributes.height;
fb->modifier = dmabuf->attributes.modifier[0];
@@ -328,13 +329,24 @@ drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf,
}
fb->num_planes = dmabuf->attributes.n_planes;
- for (i = 0; i < dmabuf->attributes.n_planes; i++) {
- union gbm_bo_handle handle;
-
- handle = gbm_bo_get_handle_for_plane(fb->bo, i);
- if (handle.s32 == -1)
- goto err_free;
- fb->handles[i] = handle.u32;
+ if (fb->bo) {
+ for (i = 0; i < fb->num_planes; i++) {
+ union gbm_bo_handle handle;
+
+ handle = gbm_bo_get_handle_for_plane(fb->bo, i);
+ if (handle.s32 == -1)
+ goto err_free;
+ fb->handles[i] = handle.u32;
+ }
+ } else {
+ for (i = 0; i < fb->num_planes; i++) {
+ if (drmPrimeFDToHandle(fb->fd, import_mod.fds[i],
+ &fb->handles[i])) {
+ *try_view_on_plane_failure_reasons |=
+ FAILURE_REASONS_GBM_BO_IMPORT_FAILED;
+ goto err_free;
+ }
+ }
}
if (drm_fb_addfb(backend, fb) != 0) {
--
2.20.1