Skip to contentSkip to conversation

Fix display breakage when resizing the screen

PATCH In review Avi Kivity 2 participants 4 messages Apr 4, 2009 – Apr 5, 2009 KVM

lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

PATCH 1/1 Fix display breakage when resizing the screen

When the vga resolution changes, a new display surface is not allocated immediately; instead that is deferred until the next update. However, if we're running without a display client attached, that won't happen and the next bitblt is likely to cause a segfault by overflowing the display surface.

Fix by reallocating the display immediately when the resolution changes.

Tested with (Windows|Linux) x (cirrus|std) x (curses|sdl).

---
 hw/cirrus_vga.c |   11 ++-
 hw/vga.c        |  261 ++++++++++++++++++++++++++++++-------------------------
 hw/vga_int.h    |    4 +
 3 files changed, 156 insertions(+), 120 deletions(-)
hw/cirrus_vga.c +10 -1
index 08fd4c2..223008e 100644
@@ -1392,6 +1392,8 @@ cirrus_hook_write_sr(CirrusVGAState * s, unsigned reg_index, int reg_value)
 	break;
     }
 
+    vga_update_resolution((VGAState *)s);
+
     return CIRRUS_HOOK_HANDLED;
 }
 
@@ -1419,6 +1421,7 @@ static void cirrus_write_hidden_dac(CirrusVGAState * s, int reg_value)
 #endif
     }
     s->cirrus_hidden_dac_lockindex = 0;
+    vga_update_resolution((VGAState *)s);
 }
 
 /***************************************
@@ -1705,6 +1708,8 @@ cirrus_hook_write_cr(CirrusVGAState * s, unsigned reg_index, int reg_value)
 	break;
     }
 
+    vga_update_resolution((VGAState *)s);
+
     return CIRRUS_HOOK_HANDLED;
 }
 
@@ -2830,6 +2835,7 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val)
 	if (s->ar_flip_flop == 0) {
 	    val &= 0x3f;
 	    s->ar_index = val;
+            vga_update_resolution((VGAState *)s);
 	} else {
 	    index = s->ar_index & 0x1f;
 	    switch (index) {
@@ -2923,6 +2929,7 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val)
 	    /* can always write bit 4 of CR7 */
 	    if (s->cr_index == 7)
 		s->cr[7] = (s->cr[7] & ~0x10) | (val & 0x10);
+            vga_update_resolution((VGAState *)s);
 	    return;
 	}
 	switch (s->cr_index) {
@@ -2951,6 +2958,7 @@ static void vga_ioport_write(void *opaque, uint32_t addr, uint32_t val)
 	    s->update_retrace_info((VGAState *) s);
 	    break;
 	}
+        vga_update_resolution((VGAState *)s);
 	break;
     case 0x3ba:
     case 0x3da:
@@ -3157,7 +3165,8 @@ static int cirrus_vga_load(QEMUFile *f, void *opaque, int version_id)
 
     cirrus_update_memory_access(s);
     /* force refresh */
-    s->graphic_mode = -1;
+    vga_update_resolution((VGAState *)s);
+    s->want_full_update = 1;
     cirrus_update_bank_ptr(s, 0);
     cirrus_update_bank_ptr(s, 1);
     return 0;
hw/vga.c +142 -119

476 lines not on this page · raw message

hw/vga_int.h +4 -0
index f97e98f..6ab9742 100644
@@ -147,8 +147,11 @@ typedef void (* vga_update_retrace_info_fn)(struct VGAState *s);
     DisplayState *ds;                                                   \
     uint32_t font_offsets[2];                                           \
     int graphic_mode;                                                   \
+    int want_full_update;                                               \
     uint8_t shift_control;                                              \
     uint8_t double_scan;                                                \
+    uint8_t multi_run;                                                  \
+    uint8_t multi_scan;                                                 \
     uint32_t line_offset;                                               \
     uint32_t line_compare;                                              \
     uint32_t start_addr;                                                \
@@ -195,6 +198,7 @@ void vga_common_init(VGAState *s, uint8_t *vga_ram_base,
                      ram_addr_t vga_ram_offset, int vga_ram_size);
 void vga_init(VGAState *s);
 void vga_reset(void *s);
+void vga_update_resolution(VGAState *s);
 
 void vga_dirty_log_start(VGAState *s);
 void vga_dirty_log_stop(VGAState *s);
Signature · 1 line
1.6.1.1
#1 lore raw
Quoted 11 lines · Avi Kivity

When the vga resolution changes, a new display surface is not allocated immediately; instead that is deferred until the next update. However, if we're running without a display client attached, that won't happen and the next bitblt is likely to cause a segfault by overflowing the display surface.

Fix by reallocating the display immediately when the resolution changes.

Tested with (Windows|Linux) x (cirrus|std) x (curses|sdl).

This patch breaks VC switching with -curses.

Regards,

Anthony Liguori

author
#2 lore raw
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Avi Kivity

When the vga resolution changes, a new display surface is not allocated immediately; instead that is deferred until the next update. However, if we're running without a display client attached, that won't happen and the next bitblt is likely to cause a segfault by overflowing the display surface.

Quoted 8 lines
Quoted 5 lines

Fix by reallocating the display immediately when the resolution changes.

Tested with (Windows|Linux) x (cirrus|std) x (curses|sdl).

This patch breaks VC switching with -curses.

Can someone explain what DisplaySurface::width means when using curses?

It is initialized to a pixel value:

ds->surface = qemu_create_displaysurface_from(640, 400, 0, 0,
(uint8_t*) screen);

then read in from the current surface:

static void curses_resize(DisplayState *ds)
{
if (ds_get_width(ds) == gwidth && ds_get_height(ds) == gheight)

       return;
   gwidth = ds_get_width(ds);
   gheight = ds_get_height(ds);

curses_calc_pad();
ds->surface->width = width * FONT_WIDTH;
ds->surface->height = height * FONT_HEIGHT;
}

But curses_calc_pad() does

static void curses_calc_pad(void)
{

   if (is_fixedsize_console()) {
       width = gwidth;
       height = gheight;
   } else {
       width = COLS;
       height = LINES;

}

If !is_fixedsize_console(), then the global width takes on a character cell count, later multiplied by FONT_WIDTH to become a pixel value again. But if is_fixedsize_console() is true (which happens to be the case here), then the global width is a pixel value (from gwidth), and when multiplied by FONT_WIDTH it becomes nonsense. Repeated calls to curses_resize() will inflate the value to hell.

Signature · 1 line
error compiling committee.c: too many arguments to function
author
#3 lore raw
In reply to Anthony Liguori
Quoted 3 lines · Anthony Liguori

This patch breaks VC switching with -curses.

The attached incremental fixes it, by basically replicating the previous behaviour. I'll follow up with a new combined patch.

Signature · 1 line
error compiling committee.c: too many arguments to function
hw/vga.c +15 -1
index 404450f..54d0246 100644
@@ -1631,6 +1631,9 @@ static void vga_update_resolution_graphics(VGAState *s)
         s->multi_run != multi_run ||
         s->multi_scan != multi_scan ||
         s->want_full_update) {
+        if (s->ds->surface->pf.depth == 0) {
+            goto dont_touch_display_surface;
+        }
 #if defined(WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
         if (depth == 16 || depth == 32) {
 #else
@@ -1647,6 +1650,7 @@ static void vga_update_resolution_graphics(VGAState *s)
         } else {
             qemu_console_resize(s->ds, disp_width, height);
         }
+    dont_touch_display_surface:
         s->last_scr_width = disp_width;
         s->last_scr_height = height;
         s->last_width = disp_width;
@@ -1668,7 +1672,17 @@ static void vga_update_resolution_text(VGAState *s)
         cw != s->last_cw || cheight != s->last_ch || s->last_depth) {
         s->last_scr_width = width * cw;
         s->last_scr_height = height * cheight;
-        qemu_console_resize(s->ds, s->last_scr_width, s->last_scr_height);
+        if (s->ds->surface->pf.depth != 0) {
+            qemu_console_resize(s->ds, s->last_scr_width, s->last_scr_height);
+        } else {
+            /*
+             * curses expects width and height to be in character cell
+             * dimensions, not pixels.
+             */
+            s->ds->surface->width = width;
+            s->ds->surface->height = height;
+            dpy_resize(s->ds);
+        }
         s->last_depth = 0;
         s->last_width = width;
         s->last_height = height;