ui/gtk: no render event when vc is invisible
cover ui/gtk: no render event when vc is invisible
This patchset adds a new mechanism in gtk/ui that makes it stop scheduling a render event if VC is invisible and also change the status of guest display to disconnected so that the guest stop further submission of new frames.
This prevents the guest (using blob scanout w/ egl fence sync) from being locked up when the submitted frame is in pending state for too long when the VC is hidden behind a inactivated tab or detached window for it is minimized, where a render event is scheduled but doesn't get a chance to be executed until the VC is visible again.
A flag "visible" under vc->gfx was added to indicate the visibilty status of VC for the mechanism. And resizing VC to 0 was used to inactivate the scanout , which eventually makes the guest display shown as disconnected on the guest's side.
Dongwon Kim (3):
ui/gtk: skip drawing guest scanout when associated VC is invisible ui/gtk: set the ui size to 0 when invisible
ui/gtk: reset visible flag when window is minimized
include/ui/gtk.h | 1 + ui/gtk-egl.c | 8 ++++++++ ui/gtk-gl-area.c | 8 ++++++++ ui/gtk.c | 51 +++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 65 insertions(+), 3 deletions(-)
Signature · 1 line
2.30.2
RFC PATCH 1/3 ui/gtk: skip drawing guest scanout when associated VC is invisible
A new flag "visible" that shows visibility status of the gfx console. The polarity of the flag determines whether the drawing surface should continuously updated upon scanout flush. The flag is set to 'true' as far as it is in visible state but set to 'false' if its tab is inactivated or untabified window is closed. If set to 'false', QEMU will stop scheduling render events until it is visible again.
--- include/ui/gtk.h | 1 + ui/gtk-egl.c | 8 ++++++++ ui/gtk-gl-area.c | 8 ++++++++ ui/gtk.c | 11 ++++++++++- 4 files changed, 27 insertions(+), 1 deletion(-)
include/ui/gtk.h +1 -0
@@ -57,6 +57,7 @@ typedef struct VirtualGfxConsole {bool y0_top;bool scanout_mode;bool has_dmabuf; +bool visible;#endif } VirtualGfxConsole;
ui/gtk-egl.c +8 -0
@@ -247,6 +247,10 @@ void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,#ifdef CONFIG_GBM VirtualConsole *vc =container_of (dcl, VirtualConsole, gfx.dcl); +if (!vc->gfx.visible) { +return ; + } +eglMakeCurrent (qemu_egl_display, vc->gfx.esurface, vc->gfx.esurface, vc->gfx.ectx);
@@ -341,6 +345,10 @@ void gd_egl_flush(DisplayChangeListener *dcl,VirtualConsole *vc =container_of (dcl, VirtualConsole, gfx.dcl);GtkWidget *area = vc->gfx.drawing_area; +if (!vc->gfx.visible) { +return ; + } +if (vc->gfx.guest_fb.dmabuf) {graphic_hw_gl_block (vc->gfx.dcl.con, true); vc->gfx.guest_fb.dmabuf->draw_submitted = true;
ui/gtk-gl-area.c +8 -0
@@ -278,6 +278,10 @@ void gd_gl_area_scanout_flush(DisplayChangeListener *dcl, {VirtualConsole *vc =container_of (dcl, VirtualConsole, gfx.dcl); +if (!vc->gfx.visible) { +return ; + } +if (vc->gfx.guest_fb.dmabuf) {graphic_hw_gl_block (vc->gfx.dcl.con, true); vc->gfx.guest_fb.dmabuf->draw_submitted = true;
@@ -291,6 +295,10 @@ void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,#ifdef CONFIG_GBM VirtualConsole *vc =container_of (dcl, VirtualConsole, gfx.dcl); +if (!vc->gfx.visible) { +return ; + } +gtk_gl_area_make_current (GTK_GL_AREA (vc->gfx.drawing_area));egl_dmabuf_import_texture (dmabuf);if (!dmabuf->texture) {
ui/gtk.c +10 -1
@@ -1268,15 +1268,20 @@ static void gd_menu_quit(GtkMenuItem *item, void *opaque)static void gd_menu_switch_vc (GtkMenuItem *item,void *opaque) {GtkDisplayState *s = opaque; -VirtualConsole *vc =gd_vc_find_by_menu (s); +VirtualConsole *vc;GtkNotebook *nb =GTK_NOTEBOOK (s->notebook);gint page; + vc =gd_vc_find_current (s); + vc->gfx.visible = false; + + vc =gd_vc_find_by_menu (s);gtk_release_modifiers (s);if (vc) { page =gtk_notebook_page_num (nb, vc->tab_item);gtk_notebook_set_current_page (nb, page);gtk_widget_grab_focus (vc->focus); + vc->gfx.visible = true; } }
@@ -1306,6 +1311,7 @@ static gboolean gd_tab_window_close(GtkWidget *widget, GdkEvent *event,VirtualConsole *vc = opaque;GtkDisplayState *s = vc->s; + vc->gfx.visible = false;gtk_widget_set_sensitive (vc->menu_item, true);gd_widget_reparent (vc->window, s->notebook, vc->tab_item); gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(s->notebook),
@@ -1379,6 +1385,7 @@ static void gd_menu_untabify(GtkMenuItem *item, void *opaque)gd_update_geometry_hints (vc);gd_update_caption (s); } + vc->gfx.visible = true; }static void gd_menu_show_menubar (GtkMenuItem *item,void *opaque)
@@ -2404,6 +2411,8 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)gtk_menu_item_activate (GTK_MENU_ITEM (s->show_tabs_item)); }gd_clipboard_init (s); + + vc->gfx.visible = true; }static void early_gtk_display_init (DisplayOptions *opts)
Signature · 1 line
2.30.2
RFC PATCH 2/3 ui/gtk: set the ui size to 0 when invisible
In reply to Dongwon KimMake guest displays disconnected when not visible. Setting ui size to 0 is used to indicate that the display is disconnected. When the VC is visible again, the ui size is set to associated window's size again which makes the display reconnected and available to the guest.
--- ui/gtk.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
ui/gtk.c +14 -1
@@ -1270,10 +1270,12 @@ static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque)GtkDisplayState *s = opaque;VirtualConsole *vc;GtkNotebook *nb =GTK_NOTEBOOK (s->notebook); +GdkWindow *window;gint page; vc =gd_vc_find_current (s); vc->gfx.visible = false; +gd_set_ui_size (vc,0 ,0 ); vc =gd_vc_find_by_menu (s);gtk_release_modifiers (s);
@@ -1281,6 +1283,9 @@ static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque) page =gtk_notebook_page_num (nb, vc->tab_item);gtk_notebook_set_current_page (nb, page);gtk_widget_grab_focus (vc->focus); + window =gtk_widget_get_window (vc->gfx.drawing_area); +gd_set_ui_size (vc,gdk_window_get_width (window), +gdk_window_get_height (window)); vc->gfx.visible = true; } }
@@ -1312,6 +1317,7 @@ static gboolean gd_tab_window_close(GtkWidget *widget, GdkEvent *event,GtkDisplayState *s = vc->s; vc->gfx.visible = false; +gd_set_ui_size (vc,0 ,0 );gtk_widget_set_sensitive (vc->menu_item, true);gd_widget_reparent (vc->window, s->notebook, vc->tab_item); gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(s->notebook),
@@ -1347,6 +1353,7 @@ static gboolean gd_win_grab(void *opaque)static void gd_menu_untabify (GtkMenuItem *item,void *opaque) {GtkDisplayState *s = opaque; +GdkWindow *window;VirtualConsole *vc =gd_vc_find_current (s); if (vc->type == GD_VC_GFX &&
@@ -1385,6 +1392,10 @@ static void gd_menu_untabify(GtkMenuItem *item, void *opaque)gd_update_geometry_hints (vc);gd_update_caption (s); } + + window =gtk_widget_get_window (vc->gfx.drawing_area); +gd_set_ui_size (vc,gdk_window_get_width (window), +gdk_window_get_height (window)); vc->gfx.visible = true; }
@@ -1709,7 +1720,9 @@ static gboolean gd_configure(GtkWidget *widget, {VirtualConsole *vc = opaque; -gd_set_ui_size (vc, cfg->width, cfg->height); +if (vc->gfx.visible) { +gd_set_ui_size (vc, cfg->width, cfg->height); + }return FALSE; }
Signature · 1 line
2.30.2
RFC PATCH 3/3 ui/gtk: reset visible flag when window is minimized
In reply to Dongwon KimAdd a callback for window-state-event that resets vc->gfx.visible when associated window is minimized and vice versa.
--- ui/gtk.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
ui/gtk.c +24 -1
@@ -1337,6 +1337,24 @@ static gboolean gd_tab_window_close(GtkWidget *widget, GdkEvent *event,return TRUE; } +static gboolean gd_window_state_event (GtkWidget *widget,GdkEvent *event, +void *opaque) +{ +VirtualConsole *vc = opaque; + +if (!vc) { +return TRUE; + } + +if (event->window_state.new_window_state &GDK_WINDOW_STATE_ICONIFIED ) { + vc->gfx.visible = false; + }else { + vc->gfx.visible = true; + } + +return TRUE; +} +static gboolean gd_win_grab (void *opaque) {VirtualConsole *vc = opaque;
@@ -1378,6 +1396,9 @@ static void gd_menu_untabify(GtkMenuItem *item, void *opaque)g_signal_connect (vc->window,"delete-event" ,G_CALLBACK (gd_tab_window_close), vc); +g_signal_connect (vc->window,"window-state-event" , +G_CALLBACK (gd_window_state_event), vc); +gtk_widget_show_all (vc->window);if (qemu_console_is_graphic (vc->gfx.dcl.con)) {
@@ -2027,7 +2048,9 @@ static void gd_connect_signals(GtkDisplayState *s)g_signal_connect (s->window,"delete-event" ,G_CALLBACK (gd_window_close), s); - +g_signal_connect (s->window,"window-state-event" , +G_CALLBACK (gd_window_state_event), +gd_vc_find_current (s));g_signal_connect (s->pause_item,"activate" ,G_CALLBACK (gd_menu_pause), s); g_signal_connect(s->reset_item, "activate",
Signature · 1 line
2.30.2