All of lore.kernel.org
 help / color / mirror / Atom feed
From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>, kraxel@redhat.com
Subject: [PATCH v2 16/20] ui: add egl dmabuf import to gtkglarea
Date: Thu,  4 Feb 2021 14:52:28 +0400	[thread overview]
Message-ID: <20210204105232.834642-17-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20210204105232.834642-1-marcandre.lureau@redhat.com>

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

GtkGLArea is used on wayland, where EGL is usually available.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/ui/gtk.h |  2 ++
 ui/gtk-gl-area.c | 18 ++++++++++++++++++
 ui/gtk.c         | 22 ++++++++++++++++++++++
 3 files changed, 42 insertions(+)

diff --git a/include/ui/gtk.h b/include/ui/gtk.h
index aaef884b95..3c1cd98db8 100644
--- a/include/ui/gtk.h
+++ b/include/ui/gtk.h
@@ -134,6 +134,8 @@ QEMUGLContext gd_gl_area_create_context(DisplayChangeListener *dcl,
                                         QEMUGLParams *params);
 void gd_gl_area_destroy_context(DisplayChangeListener *dcl,
                                 QEMUGLContext ctx);
+void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
+                               QemuDmaBuf *dmabuf);
 void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
                                 uint32_t backing_id,
                                 bool backing_y_0_top,
diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index 96fbe75387..72bcd94918 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -213,6 +213,24 @@ void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
     gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
 }
 
+void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
+                               QemuDmaBuf *dmabuf)
+{
+#ifdef CONFIG_OPENGL_DMABUF
+    VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
+
+    gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
+    egl_dmabuf_import_texture(dmabuf);
+    if (!dmabuf->texture) {
+        return;
+    }
+
+    gd_gl_area_scanout_texture(dcl, dmabuf->texture,
+                               false, dmabuf->width, dmabuf->height,
+                               0, 0, dmabuf->width, dmabuf->height);
+#endif
+}
+
 void gtk_gl_area_init(void)
 {
     display_opengl = 1;
diff --git a/ui/gtk.c b/ui/gtk.c
index f41c396cb9..79dc240120 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -627,6 +627,12 @@ static bool gd_has_dmabuf(DisplayChangeListener *dcl)
 {
     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
 
+    if (gtk_use_gl_area && !gtk_widget_get_realized(vc->gfx.drawing_area)) {
+        /* FIXME: Assume it will work, actual check done after realize */
+        /* fixing this would require delaying listener registration */
+        return true;
+    }
+
     return vc->gfx.has_dmabuf;
 }
 
@@ -647,6 +653,8 @@ static const DisplayChangeListenerOps dcl_gl_area_ops = {
     .dpy_gl_scanout_texture  = gd_gl_area_scanout_texture,
     .dpy_gl_scanout_disable  = gd_gl_area_scanout_disable,
     .dpy_gl_update           = gd_gl_area_scanout_flush,
+    .dpy_gl_scanout_dmabuf   = gd_gl_area_scanout_dmabuf,
+    .dpy_has_dmabuf          = gd_has_dmabuf,
 };
 
 static const DisplayChangeListenerOps dcl_egl_ops = {
@@ -1983,6 +1991,18 @@ static GtkWidget *gd_create_menu_machine(GtkDisplayState *s)
     return machine_menu;
 }
 
+#if defined(CONFIG_OPENGL)
+static void gl_area_realize(GtkGLArea *area, VirtualConsole *vc)
+{
+    gtk_gl_area_make_current(area);
+    qemu_egl_display = eglGetCurrentDisplay();
+    vc->gfx.has_dmabuf = qemu_egl_has_dmabuf();
+    if (!vc->gfx.has_dmabuf) {
+        error_report("GtkGLArea console lacks DMABUF support.");
+    }
+}
+#endif
+
 static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
                               QemuConsole *con, int idx,
                               GSList *group, GtkWidget *view_menu)
@@ -1998,6 +2018,8 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
     if (display_opengl) {
         if (gtk_use_gl_area) {
             vc->gfx.drawing_area = gtk_gl_area_new();
+            g_signal_connect(vc->gfx.drawing_area, "realize",
+                             G_CALLBACK(gl_area_realize), vc);
             vc->gfx.dcl.ops = &dcl_gl_area_ops;
         } else {
             vc->gfx.drawing_area = gtk_drawing_area_new();
-- 
2.29.0



  parent reply	other threads:[~2021-02-04 11:04 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 01/20] vhost-user-gpu: check backend for EDID support marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 02/20] vhost-user-gpu: handle vhost-user-gpu features in a callback marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 03/20] vhost-user-gpu: use an extandable state enum for commands marcandre.lureau
2021-02-04 11:26   ` Philippe Mathieu-Daudé
2021-02-04 13:43     ` Philippe Mathieu-Daudé
2021-02-04 10:52 ` [PATCH v2 04/20] vhost-user-gpu: handle display-info in a callback marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 05/20] ui: remove extra #ifdef CONFIG_OPENGL marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 06/20] ui: remove gl_ctx_get_current marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 07/20] ui: add gd_gl_area_scanout_disable marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 08/20] ui: annotate DCLOps callback requirements marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 09/20] ui: remove console_has_gl_dmabuf() marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 10/20] vhost-user-gpu: add a configuration flag for dmabuf usage marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 11/20] ui: add an optional get_flags callback to GraphicHwOps marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 12/20] ui: add a DCLOps callback to check dmabuf support marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 13/20] ui: check hw requirements during DCL registration marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 14/20] ui: add qemu_egl_has_dmabuf helper marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 15/20] ui: check gtk-egl dmabuf support marcandre.lureau
2021-02-04 10:52 ` marcandre.lureau [this message]
2021-02-04 10:52 ` [PATCH v2 17/20] virtio-gpu: avoid re-entering cmdq processing marcandre.lureau
2021-02-05  8:09   ` Alexander Bulekov
2021-02-04 10:52 ` [PATCH v2 18/20] display/ui: add a callback to indicate GL state is flushed marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 19/20] chardev: check if the chardev is registered for yanking marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 20/20] tests: add some virtio-gpu & vhost-user-gpu acceptance test marcandre.lureau
2021-02-16 16:34   ` Alex Bennée
2021-02-16 17:43     ` Cleber Rosa
2021-02-17  8:27       ` Marc-André Lureau
2021-02-17 12:12         ` Alex Bennée

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210204105232.834642-17-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.