qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 17/27] vhost-user-gpu: add vg_send_scanout_dmabuf()


From: marcandre . lureau
Subject: [PATCH 17/27] vhost-user-gpu: add vg_send_scanout_dmabuf()
Date: Fri, 12 Mar 2021 14:00:58 +0400

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 contrib/vhost-user-gpu/vugpu.h          |  8 ++++
 contrib/vhost-user-gpu/vhost-user-gpu.c | 57 +++++++++++++++++--------
 contrib/vhost-user-gpu/virgl.c          | 23 ++++------
 3 files changed, 56 insertions(+), 32 deletions(-)

diff --git a/contrib/vhost-user-gpu/vugpu.h b/contrib/vhost-user-gpu/vugpu.h
index e19abb670d..759de56502 100644
--- a/contrib/vhost-user-gpu/vugpu.h
+++ b/contrib/vhost-user-gpu/vugpu.h
@@ -180,5 +180,13 @@ bool    vg_recv_msg(VuGpu *g, uint32_t expect_req, 
uint32_t expect_size,
                     gpointer payload);
 
 void    vg_send_disable_scanout(VuGpu *g, int scanout_id);
+void    vg_send_dmabuf_scanout(VuGpu *g,
+                               const struct virtio_gpu_set_scanout *ss,
+                               uint32_t fd_width,
+                               uint32_t fd_height,
+                               uint32_t fd_stride,
+                               int fd_drm_fourcc,
+                               uint32_t fd_flags,
+                               int fd);
 
 #endif
diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c 
b/contrib/vhost-user-gpu/vhost-user-gpu.c
index 69fedd376b..8c3ee8aad8 100644
--- a/contrib/vhost-user-gpu/vhost-user-gpu.c
+++ b/contrib/vhost-user-gpu/vhost-user-gpu.c
@@ -587,6 +587,38 @@ vg_transfer_to_host_2d(VuGpu *g,
     }
 }
 
+void
+vg_send_dmabuf_scanout(VuGpu *g,
+                       const struct virtio_gpu_set_scanout *ss,
+                       uint32_t fd_width,
+                       uint32_t fd_height,
+                       uint32_t fd_stride,
+                       int fd_drm_fourcc,
+                       uint32_t fd_flags,
+                       int fd)
+{
+    VhostUserGpuMsg msg = {
+        .request = VHOST_USER_GPU_DMABUF_SCANOUT,
+        .size = sizeof(VhostUserGpuDMABUFScanout),
+        .payload.dmabuf_scanout = (VhostUserGpuDMABUFScanout) {
+            .scanout_id = ss->scanout_id,
+            .x = ss->r.x,
+            .y = ss->r.y,
+            .width = ss->r.width,
+            .height = ss->r.height,
+            .fd_width = fd_width,
+            .fd_height = fd_height,
+            .fd_stride = fd_stride,
+            .fd_drm_fourcc = fd_drm_fourcc,
+            .fd_flags = fd_flags,
+        }
+    };
+
+    g_debug("send dmabuf scanout: %d", ss->scanout_id);
+    vg_send_msg(g, &msg, fd);
+}
+
+
 static void
 vg_set_scanout(VuGpu *g,
                struct virtio_gpu_ctrl_command *cmd)
@@ -651,24 +683,15 @@ vg_set_scanout(VuGpu *g,
     struct vugbm_buffer *buffer = &res->buffer;
 
     if (vugbm_buffer_can_get_dmabuf_fd(buffer)) {
-        VhostUserGpuMsg msg = {
-            .request = VHOST_USER_GPU_DMABUF_SCANOUT,
-            .size = sizeof(VhostUserGpuDMABUFScanout),
-            .payload.dmabuf_scanout = (VhostUserGpuDMABUFScanout) {
-                .scanout_id = ss.scanout_id,
-                .x = ss.r.x,
-                .y = ss.r.y,
-                .width = ss.r.width,
-                .height = ss.r.height,
-                .fd_width = buffer->width,
-                .fd_height = buffer->height,
-                .fd_stride = buffer->stride,
-                .fd_drm_fourcc = buffer->format
-            }
-        };
-
         if (vugbm_buffer_get_dmabuf_fd(buffer, &fd)) {
-            vg_send_msg(g, &msg, fd);
+            vg_send_dmabuf_scanout(g,
+                                   &ss,
+                                   buffer->width,
+                                   buffer->height,
+                                   buffer->stride,
+                                   buffer->format,
+                                   0,
+                                   fd);
             close(fd);
         }
     } else {
diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c
index fe153425f5..0c7f118556 100644
--- a/contrib/vhost-user-gpu/virgl.c
+++ b/contrib/vhost-user-gpu/virgl.c
@@ -337,21 +337,14 @@ virgl_cmd_set_scanout(VuGpu *g,
             return;
         }
         assert(fd >= 0);
-        VhostUserGpuMsg msg = {
-            .request = VHOST_USER_GPU_DMABUF_SCANOUT,
-            .size = sizeof(VhostUserGpuDMABUFScanout),
-            .payload.dmabuf_scanout.scanout_id = ss.scanout_id,
-            .payload.dmabuf_scanout.x =  ss.r.x,
-            .payload.dmabuf_scanout.y =  ss.r.y,
-            .payload.dmabuf_scanout.width = ss.r.width,
-            .payload.dmabuf_scanout.height = ss.r.height,
-            .payload.dmabuf_scanout.fd_width = info.width,
-            .payload.dmabuf_scanout.fd_height = info.height,
-            .payload.dmabuf_scanout.fd_stride = info.stride,
-            .payload.dmabuf_scanout.fd_flags = info.flags,
-            .payload.dmabuf_scanout.fd_drm_fourcc = info.drm_fourcc
-        };
-        vg_send_msg(g, &msg, fd);
+        vg_send_dmabuf_scanout(g,
+                               &ss,
+                               info.width,
+                               info.height,
+                               info.stride,
+                               info.drm_fourcc,
+                               info.flags,
+                               fd);
         close(fd);
     } else {
         vg_send_disable_scanout(g, ss.scanout_id);
-- 
2.29.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]