diff mbox series

ui/gtk: skip refresh if new dmabuf is submitted

Message ID 20230628185108.16697-1-dongwon.kim@intel.com (mailing list archive)
State New, archived
Headers show
Series ui/gtk: skip refresh if new dmabuf is submitted | expand

Commit Message

Kim, Dongwon June 28, 2023, 6:51 p.m. UTC
Skip refresh if a new dmabuf (guest scanout frame) is submitted
and ready to be drawn because the scanout will be refreshed with
new frame anyway.

Also, setting scanout mode is better to be done right before
a draw event is scheduled because the mode can be reset anytime
after it is set in dpy_gl_scanout_texture by any asynchronouse
dpy_refresh call, which eventually cancels the drawing of the
guest scanout texture.

Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Vivek Kasireddy <vivek.kasireddy@intel.com>
Signed-off-by: Dongwon Kim <dongwon.kim@intel.com>
---
 ui/gtk-egl.c     | 6 +++++-
 ui/gtk-gl-area.c | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

Comments

Marc-André Lureau July 4, 2023, 3:54 p.m. UTC | #1
Hi

On Wed, Jun 28, 2023 at 9:12 PM Dongwon Kim <dongwon.kim@intel.com> wrote:

> Skip refresh if a new dmabuf (guest scanout frame) is submitted
> and ready to be drawn because the scanout will be refreshed with
> new frame anyway.
>
> Also, setting scanout mode is better to be done right before
> a draw event is scheduled because the mode can be reset anytime
> after it is set in dpy_gl_scanout_texture by any asynchronouse
> dpy_refresh call, which eventually cancels the drawing of the
> guest scanout texture.
>

This is actually quite difficult to analyze. Can you be more explicit? Can
you split the patch and add comments, because the state conditions &
behavours aren't obvious.

Gerd, any chance you look at it too?


> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
> Cc: Vivek Kasireddy <vivek.kasireddy@intel.com>
> Signed-off-by: Dongwon Kim <dongwon.kim@intel.com>
> ---
>  ui/gtk-egl.c     | 6 +++++-
>  ui/gtk-gl-area.c | 6 +++++-
>  2 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
> index 19130041bc..62ff6812b6 100644
> --- a/ui/gtk-egl.c
> +++ b/ui/gtk-egl.c
> @@ -143,6 +143,10 @@ void gd_egl_refresh(DisplayChangeListener *dcl)
>      gd_update_monitor_refresh_rate(
>              vc, vc->window ? vc->window : vc->gfx.drawing_area);
>
> +    if (vc->gfx.guest_fb.dmabuf &&
> vc->gfx.guest_fb.dmabuf->draw_submitted) {
> +        return;
> +    }
> +
>      if (!vc->gfx.esurface) {
>          gd_egl_init(vc);
>          if (!vc->gfx.esurface) {
> @@ -236,7 +240,6 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl,
>      eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
>                     vc->gfx.esurface, vc->gfx.ectx);
>
> -    gtk_egl_set_scanout_mode(vc, true);
>      egl_fb_setup_for_tex(&vc->gfx.guest_fb, backing_width, backing_height,
>                           backing_id, false);
>  }
> @@ -344,6 +347,7 @@ void gd_egl_flush(DisplayChangeListener *dcl,
>      if (vc->gfx.guest_fb.dmabuf &&
> !vc->gfx.guest_fb.dmabuf->draw_submitted) {
>          graphic_hw_gl_block(vc->gfx.dcl.con, true);
>          vc->gfx.guest_fb.dmabuf->draw_submitted = true;
> +        gtk_egl_set_scanout_mode(vc, true);
>          gtk_widget_queue_draw_area(area, x, y, w, h);
>          return;
>      }
> diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
> index c384a1516b..68eff3435b 100644
> --- a/ui/gtk-gl-area.c
> +++ b/ui/gtk-gl-area.c
> @@ -123,6 +123,10 @@ void gd_gl_area_refresh(DisplayChangeListener *dcl)
>
>      gd_update_monitor_refresh_rate(vc, vc->window ? vc->window :
> vc->gfx.drawing_area);
>
> +    if (vc->gfx.guest_fb.dmabuf &&
> vc->gfx.guest_fb.dmabuf->draw_submitted) {
> +        return;
> +    }
> +
>      if (!vc->gfx.gls) {
>          if (!gtk_widget_get_realized(vc->gfx.drawing_area)) {
>              return;
> @@ -261,7 +265,6 @@ void gd_gl_area_scanout_texture(DisplayChangeListener
> *dcl,
>          return;
>      }
>
> -    gtk_gl_area_set_scanout_mode(vc, true);
>      egl_fb_setup_for_tex(&vc->gfx.guest_fb, backing_width, backing_height,
>                           backing_id, false);
>  }
> @@ -281,6 +284,7 @@ void gd_gl_area_scanout_flush(DisplayChangeListener
> *dcl,
>      if (vc->gfx.guest_fb.dmabuf &&
> !vc->gfx.guest_fb.dmabuf->draw_submitted) {
>          graphic_hw_gl_block(vc->gfx.dcl.con, true);
>          vc->gfx.guest_fb.dmabuf->draw_submitted = true;
> +        gtk_gl_area_set_scanout_mode(vc, true);
>      }
>      gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
>  }
> --
> 2.34.1
>
>
>
diff mbox series

Patch

diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
index 19130041bc..62ff6812b6 100644
--- a/ui/gtk-egl.c
+++ b/ui/gtk-egl.c
@@ -143,6 +143,10 @@  void gd_egl_refresh(DisplayChangeListener *dcl)
     gd_update_monitor_refresh_rate(
             vc, vc->window ? vc->window : vc->gfx.drawing_area);
 
+    if (vc->gfx.guest_fb.dmabuf && vc->gfx.guest_fb.dmabuf->draw_submitted) {
+        return;
+    }
+
     if (!vc->gfx.esurface) {
         gd_egl_init(vc);
         if (!vc->gfx.esurface) {
@@ -236,7 +240,6 @@  void gd_egl_scanout_texture(DisplayChangeListener *dcl,
     eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
                    vc->gfx.esurface, vc->gfx.ectx);
 
-    gtk_egl_set_scanout_mode(vc, true);
     egl_fb_setup_for_tex(&vc->gfx.guest_fb, backing_width, backing_height,
                          backing_id, false);
 }
@@ -344,6 +347,7 @@  void gd_egl_flush(DisplayChangeListener *dcl,
     if (vc->gfx.guest_fb.dmabuf && !vc->gfx.guest_fb.dmabuf->draw_submitted) {
         graphic_hw_gl_block(vc->gfx.dcl.con, true);
         vc->gfx.guest_fb.dmabuf->draw_submitted = true;
+        gtk_egl_set_scanout_mode(vc, true);
         gtk_widget_queue_draw_area(area, x, y, w, h);
         return;
     }
diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index c384a1516b..68eff3435b 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -123,6 +123,10 @@  void gd_gl_area_refresh(DisplayChangeListener *dcl)
 
     gd_update_monitor_refresh_rate(vc, vc->window ? vc->window : vc->gfx.drawing_area);
 
+    if (vc->gfx.guest_fb.dmabuf && vc->gfx.guest_fb.dmabuf->draw_submitted) {
+        return;
+    }
+
     if (!vc->gfx.gls) {
         if (!gtk_widget_get_realized(vc->gfx.drawing_area)) {
             return;
@@ -261,7 +265,6 @@  void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
         return;
     }
 
-    gtk_gl_area_set_scanout_mode(vc, true);
     egl_fb_setup_for_tex(&vc->gfx.guest_fb, backing_width, backing_height,
                          backing_id, false);
 }
@@ -281,6 +284,7 @@  void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
     if (vc->gfx.guest_fb.dmabuf && !vc->gfx.guest_fb.dmabuf->draw_submitted) {
         graphic_hw_gl_block(vc->gfx.dcl.con, true);
         vc->gfx.guest_fb.dmabuf->draw_submitted = true;
+        gtk_gl_area_set_scanout_mode(vc, true);
     }
     gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
 }