diff mbox series

[v2,1/3] stdvga: fix screen blanking

Message ID 20240603151825.188353-2-kraxel@redhat.com (mailing list archive)
State New, archived
Headers show
Series stdvga: fix screen blanking | expand

Commit Message

Gerd Hoffmann June 3, 2024, 3:18 p.m. UTC
In case the display surface uses a shared buffer (i.e. uses vga vram
directly instead of a shadow) go unshare the buffer before clearing it.

This avoids vga memory corruption, which in turn fixes unblanking not
working properly with X11.

Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2067
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/display/vga.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Marc-André Lureau June 4, 2024, 6:27 a.m. UTC | #1
Hi

On Mon, Jun 3, 2024 at 7:18 PM Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> In case the display surface uses a shared buffer (i.e. uses vga vram
> directly instead of a shadow) go unshare the buffer before clearing it.
>
> This avoids vga memory corruption, which in turn fixes unblanking not
> working properly with X11.
>
> Cc: qemu-stable@nongnu.org
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2067
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  hw/display/vga.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/hw/display/vga.c b/hw/display/vga.c
> index 30facc6c8e33..474b6b14c327 100644
> --- a/hw/display/vga.c
> +++ b/hw/display/vga.c
> @@ -1762,6 +1762,12 @@ static void vga_draw_blank(VGACommonState *s, int full_update)
>      if (s->last_scr_width <= 0 || s->last_scr_height <= 0)
>          return;
>
> +    if (is_buffer_shared(surface)) {

Perhaps the suggestion to rename the function (in the following patch)
should instead be surface_is_allocated() ? that would match the actual
flag check. But callers would have to ! the result. Wdyt?

> +        /* unshare buffer, otherwise the blanking corrupts vga vram */
> +        surface = qemu_create_displaysurface(s->last_scr_width, s->last_scr_height);
> +        dpy_gfx_replace_surface(s->con, surface);

Ok, this looks safer than calling "resize".

thanks

> +    }
> +
>      w = s->last_scr_width * surface_bytes_per_pixel(surface);
>      d = surface_data(surface);
>      for(i = 0; i < s->last_scr_height; i++) {
> --
> 2.45.1
>
Gerd Hoffmann June 5, 2024, 7:36 a.m. UTC | #2
On Tue, Jun 04, 2024 at 10:27:18AM GMT, Marc-André Lureau wrote:
> Hi
> 
> > +    if (is_buffer_shared(surface)) {
> 
> Perhaps the suggestion to rename the function (in the following patch)
> should instead be surface_is_allocated() ? that would match the actual
> flag check. But callers would have to ! the result. Wdyt?

surface_is_shadow() ?  Comes closer to the typical naming in computer
graphics.

take care,
  Gerd
Marc-André Lureau June 5, 2024, 12:08 p.m. UTC | #3
Hi

On Wed, Jun 5, 2024 at 11:36 AM Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> On Tue, Jun 04, 2024 at 10:27:18AM GMT, Marc-André Lureau wrote:
> > Hi
> >
> > > +    if (is_buffer_shared(surface)) {
> >
> > Perhaps the suggestion to rename the function (in the following patch)
> > should instead be surface_is_allocated() ? that would match the actual
> > flag check. But callers would have to ! the result. Wdyt?
>
> surface_is_shadow() ?  Comes closer to the typical naming in computer
> graphics.

If the underlying flag is renamed too, that's ok to me.
diff mbox series

Patch

diff --git a/hw/display/vga.c b/hw/display/vga.c
index 30facc6c8e33..474b6b14c327 100644
--- a/hw/display/vga.c
+++ b/hw/display/vga.c
@@ -1762,6 +1762,12 @@  static void vga_draw_blank(VGACommonState *s, int full_update)
     if (s->last_scr_width <= 0 || s->last_scr_height <= 0)
         return;
 
+    if (is_buffer_shared(surface)) {
+        /* unshare buffer, otherwise the blanking corrupts vga vram */
+        surface = qemu_create_displaysurface(s->last_scr_width, s->last_scr_height);
+        dpy_gfx_replace_surface(s->con, surface);
+    }
+
     w = s->last_scr_width * surface_bytes_per_pixel(surface);
     d = surface_data(surface);
     for(i = 0; i < s->last_scr_height; i++) {