ia64/xen-unstable

changeset 17094:6e096456b3e1

ioemu: Share framebuffer between VGA device model and VNC server.

Now that the qemu WMVi patch is applied we can take full advantage of
it sharing the video buffer between the vga driver and the qemu vnc
server. This saves a lot of memcpy. It's worth mentioning again that
when the guest colour depth is 24 bit we cannot share the buffer
because 24 bpp is not supported by the vnc protocol, so we still have
to do the translation 24 bpp -> 32 bpp.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Feb 20 17:47:58 2008 +0000 (2008-02-20)
parents e3c722d483f5
children 28dcae176191
files tools/ioemu/hw/vga.c tools/ioemu/vl.h tools/ioemu/vnc.c
line diff
     1.1 --- a/tools/ioemu/hw/vga.c	Wed Feb 20 17:46:10 2008 +0000
     1.2 +++ b/tools/ioemu/hw/vga.c	Wed Feb 20 17:47:58 2008 +0000
     1.3 @@ -1135,8 +1135,6 @@ static void vga_draw_text(VGAState *s, i
     1.4      }
     1.5  
     1.6      depth = s->get_bpp(s);
     1.7 -    if (depth == 24)
     1.8 -        depth = 32;
     1.9      if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth)
    1.10          s->ds->dpy_colourdepth(s->ds, depth);
    1.11      if (width != s->last_width || height != s->last_height ||
    1.12 @@ -1557,10 +1555,10 @@ static void vga_draw_graphic(VGAState *s
    1.13      vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + get_depth_index(s->ds)];
    1.14  
    1.15      depth = s->get_bpp(s);
    1.16 -    if (depth == 24)
    1.17 -        depth = 32;
    1.18 -    if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth)
    1.19 -        s->ds->dpy_colourdepth(s->ds, depth);
    1.20 +    if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth) {
    1.21 +        if (depth != 24 || s->ds->depth != 32)
    1.22 +            s->ds->dpy_colourdepth(s->ds, depth);
    1.23 +    }
    1.24      if (disp_width != s->last_width ||
    1.25          height != s->last_height) {
    1.26          dpy_resize(s->ds, disp_width, height);
    1.27 @@ -1570,7 +1568,9 @@ static void vga_draw_graphic(VGAState *s
    1.28          s->last_height = height;
    1.29          full_update = 1;
    1.30      }
    1.31 -    if (s->cursor_invalidate)
    1.32 +    if (s->ds->shared_buf && s->ds->data != s->vram_ptr + (s->start_addr * 4))
    1.33 +        s->ds->data = s->vram_ptr + (s->start_addr * 4);
    1.34 +    if (!s->ds->shared_buf && s->cursor_invalidate)
    1.35          s->cursor_invalidate(s);
    1.36      
    1.37      line_offset = s->line_offset;
    1.38 @@ -1621,9 +1621,11 @@ static void vga_draw_graphic(VGAState *s
    1.39                  page_min = page0;
    1.40              if (page_max == 0 || page1 > page_max)
    1.41                  page_max = page1;
    1.42 -            vga_draw_line(s, d, s->vram_ptr + addr, width);
    1.43 -            if (s->cursor_draw_line)
    1.44 -                s->cursor_draw_line(s, d, y);
    1.45 +            if (!s->ds->shared_buf) {
    1.46 +                vga_draw_line(s, d, s->vram_ptr + addr, width);
    1.47 +                if (s->cursor_draw_line)
    1.48 +                    s->cursor_draw_line(s, d, y);
    1.49 +            }
    1.50          } else {
    1.51              if (y_start >= 0) {
    1.52                  /* flush to display */
     2.1 --- a/tools/ioemu/vl.h	Wed Feb 20 17:46:10 2008 +0000
     2.2 +++ b/tools/ioemu/vl.h	Wed Feb 20 17:47:58 2008 +0000
     2.3 @@ -935,6 +935,7 @@ struct DisplayState {
     2.4      void *opaque;
     2.5  
     2.6      int switchbpp;
     2.7 +    int shared_buf;
     2.8      
     2.9      void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
    2.10      void (*dpy_resize)(struct DisplayState *s, int w, int h);
     3.1 --- a/tools/ioemu/vnc.c	Wed Feb 20 17:46:10 2008 +0000
     3.2 +++ b/tools/ioemu/vnc.c	Wed Feb 20 17:47:58 2008 +0000
     3.3 @@ -336,11 +336,21 @@ static void vnc_framebuffer_update(VncSt
     3.4  
     3.5  static void vnc_dpy_resize(DisplayState *ds, int w, int h)
     3.6  {
     3.7 +    static int allocated;
     3.8      int size_changed;
     3.9      VncState *vs = ds->opaque;
    3.10      int o;
    3.11  
    3.12 -    ds->data = realloc(ds->data, w * h * vs->depth);
    3.13 +    if (!ds->shared_buf) {
    3.14 +        if (allocated)
    3.15 +            ds->data = realloc(ds->data, w * h * vs->depth);
    3.16 +        else
    3.17 +            ds->data = malloc(w * h * vs->depth);
    3.18 +        allocated = 1;
    3.19 +    } else if (allocated) {
    3.20 +        free(ds->data);
    3.21 +        allocated = 0;
    3.22 +    }
    3.23      vs->old_data = realloc(vs->old_data, w * h * vs->depth);
    3.24      vs->dirty_row = realloc(vs->dirty_row, h * sizeof(vs->dirty_row[0]));
    3.25      vs->update_row = realloc(vs->update_row, h * sizeof(vs->dirty_row[0]));
    3.26 @@ -538,6 +548,11 @@ static void vnc_copy(DisplayState *ds, i
    3.27      VncState *vs = ds->opaque;
    3.28      int updating_client = 1;
    3.29  
    3.30 +    if (ds->shared_buf) {
    3.31 +        framebuffer_set_updated(vs, dst_x, dst_y, w, h);
    3.32 +        return;
    3.33 +    }
    3.34 +
    3.35      if (src_x < vs->visible_x || src_y < vs->visible_y ||
    3.36  	dst_x < vs->visible_x || dst_y < vs->visible_y ||
    3.37  	(src_x + w) > (vs->visible_x + vs->visible_w) ||
    3.38 @@ -1409,9 +1424,6 @@ static void set_pixel_format(VncState *v
    3.39      vs->blue_shift = blue_shift;
    3.40      vs->blue_max = blue_max;
    3.41      vs->pix_bpp = bits_per_pixel / 8;
    3.42 -
    3.43 -    vga_hw_invalidate();
    3.44 -    vga_hw_update();
    3.45  }
    3.46  
    3.47  static void pixel_format_message (VncState *vs) {
    3.48 @@ -1468,16 +1480,26 @@ static void pixel_format_message (VncSta
    3.49  static void vnc_dpy_colourdepth(DisplayState *ds, int depth)
    3.50  {
    3.51      int host_big_endian_flag;
    3.52 -    struct VncState *vs;
    3.53 -    
    3.54 -    if (!depth) return;
    3.55 -    
    3.56 +    struct VncState *vs = ds->opaque;
    3.57 +
    3.58 +    switch (depth) {
    3.59 +        case 24:
    3.60 +            ds->shared_buf = 0;
    3.61 +            depth = 32;
    3.62 +            break;
    3.63 +        case 0:
    3.64 +            ds->shared_buf = 0;
    3.65 +            return;
    3.66 +        default:
    3.67 +            ds->shared_buf = 1;
    3.68 +            break;
    3.69 +    }
    3.70 +
    3.71  #ifdef WORDS_BIGENDIAN
    3.72      host_big_endian_flag = 1;
    3.73  #else
    3.74      host_big_endian_flag = 0;
    3.75 -#endif
    3.76 -    vs = ds->opaque;   
    3.77 +#endif   
    3.78      
    3.79      switch (depth) {
    3.80          case 8:
    3.81 @@ -2312,7 +2334,7 @@ void vnc_display_init(DisplayState *ds)
    3.82  
    3.83      vs->ds->width = 640;
    3.84      vs->ds->height = 400;
    3.85 -    vnc_dpy_colourdepth(vs->ds, 32);
    3.86 +    vnc_dpy_colourdepth(vs->ds, 24);
    3.87  }
    3.88  
    3.89  #if CONFIG_VNC_TLS