From 0cd9a65497b91722f684cf176c42e9cc67dcdcb3 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/74] 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
|