From 81af53327625cb8b0346cde5c2dfc35062a3f0ec Mon Sep 17 00:00:00 2001
|
From: Jeffy Chen <jeffy.chen@rock-chips.com>
|
Date: Sat, 9 Oct 2021 12:33:33 +0800
|
Subject: [PATCH 50/69] HACK: pixman-renderer: Support passing dma fd to pixman
|
|
Usage:
|
pixman_image_set_destroy_function(image, NULL, (void *)(ptrdiff_t)dma_fd)
|
|
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
|
---
|
libweston/backend-drm/drm-internal.h | 1 +
|
libweston/backend-drm/drm.c | 3 +++
|
libweston/backend-drm/fb.c | 15 +++++++++++++++
|
libweston/pixman-renderer.c | 2 ++
|
libweston/pixman-renderer.h | 4 ++++
|
5 files changed, 25 insertions(+)
|
|
diff --git a/libweston/backend-drm/drm-internal.h b/libweston/backend-drm/drm-internal.h
|
index e4d51e130..e3f65db1f 100644
|
--- a/libweston/backend-drm/drm-internal.h
|
+++ b/libweston/backend-drm/drm-internal.h
|
@@ -386,6 +386,7 @@ struct drm_fb {
|
uint64_t modifier;
|
int width, height;
|
int fd;
|
+ int dma_fd;
|
|
uint32_t plane_mask;
|
|
diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c
|
index 6517bfde8..a39342918 100644
|
--- a/libweston/backend-drm/drm.c
|
+++ b/libweston/backend-drm/drm.c
|
@@ -1634,6 +1634,9 @@ drm_output_init_pixman(struct drm_output *output, struct drm_backend *b)
|
output->dumb[i]->strides[0]);
|
if (!output->image[i])
|
goto err;
|
+
|
+ pixman_image_set_dma_fd(output->image[i],
|
+ output->dumb[i]->dma_fd);
|
}
|
|
if (pixman_renderer_output_create(&output->base, &options) < 0)
|
diff --git a/libweston/backend-drm/fb.c b/libweston/backend-drm/fb.c
|
index 4474e0cc9..5506ef8b8 100644
|
--- a/libweston/backend-drm/fb.c
|
+++ b/libweston/backend-drm/fb.c
|
@@ -58,6 +58,9 @@ drm_fb_destroy_dumb(struct drm_fb *fb)
|
|
assert(fb->type == BUFFER_PIXMAN_DUMB);
|
|
+ if (fb->dma_fd >= 0)
|
+ close(fb->dma_fd);
|
+
|
if (fb->map && fb->size > 0)
|
munmap(fb->map, fb->size);
|
|
@@ -121,6 +124,7 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,
|
struct drm_mode_create_dumb create_arg;
|
struct drm_mode_destroy_dumb destroy_arg;
|
struct drm_mode_map_dumb map_arg;
|
+ struct drm_prime_handle prime_arg;
|
|
fb = zalloc(sizeof *fb);
|
if (!fb)
|
@@ -175,8 +179,19 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,
|
if (fb->map == MAP_FAILED)
|
goto err_add_fb;
|
|
+ memset(&prime_arg, 0, sizeof(prime_arg));
|
+ prime_arg.fd = -1;
|
+ prime_arg.handle = fb->handles[0];
|
+ ret = drmIoctl(fb->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &prime_arg);
|
+ if (ret)
|
+ goto err_unmap_fb;
|
+
|
+ fb->dma_fd = prime_arg.fd;
|
+
|
return fb;
|
|
+err_unmap_fb:
|
+ munmap(fb->map, fb->size);
|
err_add_fb:
|
drmModeRmFB(b->drm.fd, fb->fb_id);
|
err_bo:
|
diff --git a/libweston/pixman-renderer.c b/libweston/pixman-renderer.c
|
index 6b9e4a14e..0cfba581e 100644
|
--- a/libweston/pixman-renderer.c
|
+++ b/libweston/pixman-renderer.c
|
@@ -741,6 +741,8 @@ pixman_renderer_attach_dmabuf(struct weston_surface *es,
|
data->ptr + attributes->offset[0],
|
attributes->stride[0]);
|
|
+ pixman_image_set_dma_fd(ps->image, attributes->fd[0]);
|
+
|
ps->buffer_destroy_listener.notify =
|
buffer_state_handle_buffer_destroy;
|
wl_signal_add(&buffer->destroy_signal,
|
diff --git a/libweston/pixman-renderer.h b/libweston/pixman-renderer.h
|
index 2b81dde51..bcd248fb0 100644
|
--- a/libweston/pixman-renderer.h
|
+++ b/libweston/pixman-renderer.h
|
@@ -29,6 +29,10 @@
|
#include "backend.h"
|
#include "libweston-internal.h"
|
|
+/* HACK: Pass dma fd to pixman through destroy data */
|
+#define pixman_image_set_dma_fd(image, fd) \
|
+ pixman_image_set_destroy_function(image, NULL, (void *)(ptrdiff_t)fd)
|
+
|
int
|
pixman_renderer_init(struct weston_compositor *ec);
|
|
--
|
2.20.1
|