gtk: add support for dmabufs
cover gtk: add support for dmabufs
Gerd Hoffmann (4):
gtk: make GtkGlArea usage a runtime option
gtk: use GtkGlArea on wayland only
gtk-egl: add scanout_dmabuf support
gtk-egl: add cursor_dmabuf support
include/ui/gtk.h | 14 ++++++++++++ ui/gtk-egl.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++- ui/gtk.c | 68 +++++++++++++++++++++++++++++++++----------------------- ui/Makefile.objs | 3 +-- 4 files changed, 117 insertions(+), 31 deletions(-)
Signature · 1 line
2.9.3
PATCH 1/4 gtk: make GtkGlArea usage a runtime option
Compile in both gtk-egl and gtk-gl-area, then allow to choose at runtime instead of compile time which opengl variant we want use.
--- include/ui/gtk.h | 2 ++ ui/gtk.c | 53 +++++++++++++++++++++++++++++------------------------ ui/Makefile.objs | 3 +-- 3 files changed, 32 insertions(+), 26 deletions(-)
include/ui/gtk.h +2 -0
@@ -90,6 +90,8 @@ typedef struct VirtualConsole { }; } VirtualConsole; +extern bool gtk_use_gl_area; +/* ui/gtk.c */ void gd_update_windowsize (VirtualConsole *vc);
ui/gtk.c +29 -24
108 lines not on this page · raw message
ui/Makefile.objs +1 -2
@@ -39,10 +39,9 @@ common-obj-y += egl-context.o common-obj-$(CONFIG_OPENGL_DMABUF) += egl-headless.o ifeq ($(CONFIG_GTK_GL),y) common-obj-$(CONFIG_GTK) += gtk-gl-area.o -else +endif common-obj-$(CONFIG_GTK) += gtk-egl.o endif -endif gtk.o-cflags := $(GTK_CFLAGS) $(VTE_CFLAGS) gtk-egl.o-cflags := $(GTK_CFLAGS) $(VTE_CFLAGS)
Signature · 1 line
2.9.3
PATCH 2/4 gtk: use GtkGlArea on wayland only
In reply to Gerd HoffmannFor dma-buf support we need a egl context. The gtk x11 backend uses glx contexts though. We can't use the GtkGlArea widget on x11 because of that, so use our own gtk-egl code instead. wayland continues to use the GtkGlArea widget.
--- ui/gtk.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
ui/gtk.c +8 -5
@@ -2440,12 +2440,15 @@ void early_gtk_display_init(DisplayOptions *opts)assert (opts->type ==DISPLAY_TYPE_GTK );if (opts->has_gl && opts->gl) {#if defined(CONFIG_OPENGL ) -#if defined(CONFIG_GTK_GL ) - gtk_use_gl_area = true; -gtk_gl_area_init (); -#else -gtk_egl_init (); +#if defined(CONFIG_GTK_GL ) && defined(GDK_WINDOWING_WAYLAND ) +if (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ())) { + gtk_use_gl_area = true; +gtk_gl_area_init (); + }#endif + { +gtk_egl_init (); + }#endif }
Signature · 1 line
2.9.3
PATCH 3/4 gtk-egl: add scanout_dmabuf support
In reply to Gerd HoffmannAdd support for dmabuf scanouts to gtk-egl.
--- include/ui/gtk.h | 4 ++++ ui/gtk-egl.c | 23 +++++++++++++++++++++++ ui/gtk.c | 2 ++ 3 files changed, 29 insertions(+)
include/ui/gtk.h +4 -0
@@ -113,6 +113,10 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl,uint32_t backing_height, uint32_t x, uint32_t y, uint32_t w, uint32_t h); +void gd_egl_scanout_dmabuf (DisplayChangeListener *dcl, +QemuDmaBuf *dmabuf); +void gd_egl_release_dmabuf (DisplayChangeListener *dcl, +QemuDmaBuf *dmabuf);void gd_egl_scanout_flush (DisplayChangeListener *dcl,uint32_t x,uint32_t y,uint32_t w,uint32_t h);void gtk_egl_init (void );
ui/gtk-egl.c +23 -0
@@ -194,6 +194,29 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl, backing_id, false); } +void gd_egl_scanout_dmabuf (DisplayChangeListener *dcl, +QemuDmaBuf *dmabuf) +{ +#ifdef CONFIG_OPENGL_DMABUF +egl_dmabuf_import_texture (dmabuf); +if (!dmabuf->texture) { +return ; + } + +gd_egl_scanout_texture (dcl, dmabuf->texture, + false, dmabuf->width, dmabuf->height, +0 ,0 , dmabuf->width, dmabuf->height); +#endif +} + +void gd_egl_release_dmabuf (DisplayChangeListener *dcl, +QemuDmaBuf *dmabuf) +{ +#ifdef CONFIG_OPENGL_DMABUF +egl_dmabuf_release_texture (dmabuf); +#endif +} +void gd_egl_scanout_flush (DisplayChangeListener *dcl,uint32_t x,uint32_t y,uint32_t w,uint32_t h) {
ui/gtk.c +2 -0
@@ -744,6 +744,8 @@ static const DisplayChangeListenerOps dcl_egl_ops = { .dpy_gl_ctx_get_current = qemu_egl_get_current_context, .dpy_gl_scanout_disable = gd_egl_scanout_disable, .dpy_gl_scanout_texture = gd_egl_scanout_texture, + .dpy_gl_scanout_dmabuf = gd_egl_scanout_dmabuf, + .dpy_gl_release_dmabuf = gd_egl_release_dmabuf, .dpy_gl_update = gd_egl_scanout_flush, };
Signature · 1 line
2.9.3
PATCH 4/4 gtk-egl: add cursor_dmabuf support
In reply to Gerd HoffmannAdd support for cursor dmabufs to gtk-egl. Just blend in the cursor (if we have one) when rendering the dmabuf.
--- include/ui/gtk.h | 8 ++++++++ ui/gtk-egl.c | 40 +++++++++++++++++++++++++++++++++++++++- ui/gtk.c | 2 ++ 3 files changed, 49 insertions(+), 1 deletion(-)
include/ui/gtk.h +8 -0
@@ -54,6 +54,9 @@ typedef struct VirtualGfxConsole {int x, y, w, h;egl_fb guest_fb;egl_fb win_fb; +egl_fb cursor_fb; +int cursor_x; +int cursor_y;bool y0_top;bool scanout_mode;#endif
@@ -115,6 +118,11 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl, uint32_t w, uint32_t h);void gd_egl_scanout_dmabuf (DisplayChangeListener *dcl,QemuDmaBuf *dmabuf); +void gd_egl_cursor_dmabuf (DisplayChangeListener *dcl, +QemuDmaBuf *dmabuf,bool have_hot, +uint32_t hot_x,uint32_t hot_y); +void gd_egl_cursor_position (DisplayChangeListener *dcl, +uint32_t pos_x,uint32_t pos_y);void gd_egl_release_dmabuf (DisplayChangeListener *dcl,QemuDmaBuf *dmabuf); void gd_egl_scanout_flush(DisplayChangeListener *dcl,
ui/gtk-egl.c +39 -1
@@ -19,6 +19,7 @@#include "ui/console.h" #include "ui/gtk.h" #include "ui/egl-helpers.h" +#include "ui/shader.h" #include "sysemu/sysemu.h"
@@ -209,6 +210,35 @@ void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,#endif } +void gd_egl_cursor_dmabuf (DisplayChangeListener *dcl, +QemuDmaBuf *dmabuf,bool have_hot, +uint32_t hot_x,uint32_t hot_y) +{ +#ifdef CONFIG_OPENGL_DMABUF +VirtualConsole *vc =container_of (dcl, VirtualConsole, gfx.dcl); + +if (dmabuf) { +egl_dmabuf_import_texture (dmabuf); +if (!dmabuf->texture) { +return ; + } +egl_fb_setup_for_tex (&vc->gfx.cursor_fb, dmabuf->width, dmabuf->height, + dmabuf->texture, false); + }else { +egl_fb_destroy (&vc->gfx.cursor_fb); + } +#endif +} + +void gd_egl_cursor_position (DisplayChangeListener *dcl, +uint32_t pos_x,uint32_t pos_y) +{ +VirtualConsole *vc =container_of (dcl, VirtualConsole, gfx.dcl); + + vc->gfx.cursor_x = pos_x; + vc->gfx.cursor_y = pos_y; +} +void gd_egl_release_dmabuf (DisplayChangeListener *dcl,QemuDmaBuf *dmabuf) {
@@ -237,7 +267,15 @@ void gd_egl_scanout_flush(DisplayChangeListener *dcl, window =gtk_widget_get_window (vc->gfx.drawing_area);gdk_drawable_get_size (window, &ww, &wh);egl_fb_setup_default (&vc->gfx.win_fb, ww, wh); -egl_fb_blit (&vc->gfx.win_fb, &vc->gfx.guest_fb, !vc->gfx.y0_top); +if (vc->gfx.cursor_fb.texture) { +egl_texture_blit (vc->gfx.gls, &vc->gfx.win_fb, &vc->gfx.guest_fb, + vc->gfx.y0_top); +egl_texture_blend (vc->gfx.gls, &vc->gfx.win_fb, &vc->gfx.cursor_fb, + vc->gfx.y0_top, + vc->gfx.cursor_x, vc->gfx.cursor_y); + }else { +egl_fb_blit (&vc->gfx.win_fb, &vc->gfx.guest_fb, !vc->gfx.y0_top); + }eglSwapBuffers (qemu_egl_display, vc->gfx.esurface); }
ui/gtk.c +2 -0
@@ -745,6 +745,8 @@ static const DisplayChangeListenerOps dcl_egl_ops = { .dpy_gl_scanout_disable = gd_egl_scanout_disable, .dpy_gl_scanout_texture = gd_egl_scanout_texture, .dpy_gl_scanout_dmabuf = gd_egl_scanout_dmabuf, + .dpy_gl_cursor_dmabuf = gd_egl_cursor_dmabuf, + .dpy_gl_cursor_position = gd_egl_cursor_position, .dpy_gl_release_dmabuf = gd_egl_release_dmabuf, .dpy_gl_update = gd_egl_scanout_flush, };
Signature · 1 line
2.9.3