Skip to content
Snippets Groups Projects
Commit 2606519b authored by Marc-André Lureau's avatar Marc-André Lureau Committed by Gerd Hoffmann
Browse files

ui: add egl dmabuf import to gtkglarea


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

Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20210204105232.834642-17-marcandre.lureau@redhat.com>
Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
parent 52a37e20
No related branches found
No related tags found
No related merge requests found
......@@ -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,
......
......@@ -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;
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment