ia64/xen-unstable

changeset 17797:638811f870ba

ioemu: cleaning DisplayState->dpy_resize interface

Bring the DisplayState dpy_resize interface back to how it is in qemu
mainstream, thus making the code easier to merge.
In order to support sharing the framebuffer, I am adding a new resize
interface called dpy_resize_shared that also has a depth and a pixels
parameters. As a consequence I could remove the dpy_colourdepth
callback and make the code cleaner and easier to read.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jun 09 09:39:15 2008 +0100 (2008-06-09)
parents 1de5d17497fd
children 4ecc3ac69819
files tools/ioemu/cocoa.m tools/ioemu/hw/pl110.c tools/ioemu/hw/tcx.c tools/ioemu/hw/vga.c tools/ioemu/hw/xenfb.c tools/ioemu/sdl.c tools/ioemu/vl.c tools/ioemu/vl.h tools/ioemu/vnc.c
line diff
     1.1 --- a/tools/ioemu/cocoa.m	Mon Jun 09 09:37:56 2008 +0100
     1.2 +++ b/tools/ioemu/cocoa.m	Mon Jun 09 09:39:15 2008 +0100
     1.3 @@ -96,7 +96,7 @@ static void cocoa_update(DisplayState *d
     1.4      cocoa_resize
     1.5   ------------------------------------------------------
     1.6  */
     1.7 -static void cocoa_resize(DisplayState *ds, int w, int h, int linesize)
     1.8 +static void cocoa_resize(DisplayState *ds, int w, int h)
     1.9  {
    1.10      const int device_bpp = 32;
    1.11      static void *screen_pixels;
     2.1 --- a/tools/ioemu/hw/pl110.c	Mon Jun 09 09:37:56 2008 +0100
     2.2 +++ b/tools/ioemu/hw/pl110.c	Mon Jun 09 09:39:15 2008 +0100
     2.3 @@ -262,7 +262,7 @@ static void pl110_resize(pl110_state *s,
     2.4  {
     2.5      if (width != s->cols || height != s->rows) {
     2.6          if (pl110_enabled(s)) {
     2.7 -            dpy_resize(s->ds, width, height, width * 4);
     2.8 +            dpy_resize(s->ds, width, height);
     2.9          }
    2.10      }
    2.11      s->cols = width;
    2.12 @@ -375,7 +375,7 @@ static void pl110_write(void *opaque, ta
    2.13          s->cr = val;
    2.14          s->bpp = (val >> 1) & 7;
    2.15          if (pl110_enabled(s)) {
    2.16 -            dpy_resize(s->ds, s->cols, s->rows, s->cols * 4);
    2.17 +            dpy_resize(s->ds, s->cols, s->rows);
    2.18          }
    2.19          break;
    2.20      case 10: /* LCDICR */
     3.1 --- a/tools/ioemu/hw/tcx.c	Mon Jun 09 09:37:56 2008 +0100
     3.2 +++ b/tools/ioemu/hw/tcx.c	Mon Jun 09 09:39:15 2008 +0100
     3.3 @@ -342,7 +342,7 @@ void tcx_init(DisplayState *ds, uint32_t
     3.4      register_savevm("tcx", addr, 1, tcx_save, tcx_load, s);
     3.5      qemu_register_reset(tcx_reset, s);
     3.6      tcx_reset(s);
     3.7 -    dpy_resize(s->ds, width, height, width * 1);
     3.8 +    dpy_resize(s->ds, width, height);
     3.9  }
    3.10  
    3.11  static void tcx_screen_dump(void *opaque, const char *filename)
     4.1 --- a/tools/ioemu/hw/vga.c	Mon Jun 09 09:37:56 2008 +0100
     4.2 +++ b/tools/ioemu/hw/vga.c	Mon Jun 09 09:39:15 2008 +0100
     4.3 @@ -1065,6 +1065,8 @@ typedef unsigned int rgb_to_pixel_dup_fu
     4.4  
     4.5  static rgb_to_pixel_dup_func *rgb_to_pixel_dup_table[NB_DEPTHS];
     4.6  
     4.7 +static int old_depth = 0;
     4.8 +
     4.9  /* 
    4.10   * Text mode update 
    4.11   * Missing:
    4.12 @@ -1089,14 +1091,51 @@ static void vga_draw_text(VGAState *s, i
    4.13      /* Disable dirty bit tracking */
    4.14      xc_hvm_track_dirty_vram(xc_handle, domid, 0, 0, NULL);
    4.15  
    4.16 -    if (s->ds->dpy_colourdepth != NULL && s->ds->depth != 0)
    4.17 -        s->ds->dpy_colourdepth(s->ds, 0);
    4.18 +    /* total width & height */
    4.19 +    cheight = (s->cr[9] & 0x1f) + 1;
    4.20 +    cw = 8;
    4.21 +    if (!(s->sr[1] & 0x01))
    4.22 +        cw = 9;
    4.23 +    if (s->sr[1] & 0x08)
    4.24 +        cw = 16; /* NOTE: no 18 pixel wide */
    4.25 +    width = (s->cr[0x01] + 1);
    4.26 +    if (s->cr[0x06] == 100) {
    4.27 +        /* ugly hack for CGA 160x100x16 - explain me the logic */
    4.28 +        height = 100;
    4.29 +    } else {
    4.30 +        height = s->cr[0x12] | 
    4.31 +            ((s->cr[0x07] & 0x02) << 7) | 
    4.32 +            ((s->cr[0x07] & 0x40) << 3);
    4.33 +        height = (height + 1) / cheight;
    4.34 +    }
    4.35 +    if ((height * width) > CH_ATTR_SIZE) {
    4.36 +        /* better than nothing: exit if transient size is too big */
    4.37 +        return;
    4.38 +    }
    4.39 +
    4.40 +    s->last_scr_width = width * cw;
    4.41 +    s->last_scr_height = height * cheight;
    4.42 +    if (s->ds->dpy_resize_shared && old_depth) {
    4.43 +        dpy_resize_shared(s->ds, s->last_scr_width, s->last_scr_height, 0, s->last_scr_width * (s->ds->depth / 8), NULL);
    4.44 +        old_depth = 0;
    4.45 +        full_update = 1;
    4.46 +    } else if (width != s->last_width || height != s->last_height ||
    4.47 +        cw != s->last_cw || cheight != s->last_ch) {
    4.48 +        dpy_resize(s->ds, s->last_scr_width, s->last_scr_height);
    4.49 +        full_update = 1;
    4.50 +    }
    4.51 +    s->last_width = width;
    4.52 +    s->last_height = height;
    4.53 +    s->last_ch = cheight;
    4.54 +    s->last_cw = cw;
    4.55 +
    4.56      s->rgb_to_pixel = 
    4.57          rgb_to_pixel_dup_table[get_depth_index(s->ds)];
    4.58  
    4.59      full_update |= update_palette16(s);
    4.60      palette = s->last_palette;
    4.61      
    4.62 +    x_incr = cw * ((s->ds->depth + 7) >> 3);
    4.63      /* compute font data address (in plane 2) */
    4.64      v = s->sr[3];
    4.65      offset = (((v >> 4) & 1) | ((v << 1) & 6)) * 8192 * 4 + 2;
    4.66 @@ -1123,40 +1162,6 @@ static void vga_draw_text(VGAState *s, i
    4.67      line_offset = s->line_offset;
    4.68      s1 = s->vram_ptr + (s->start_addr * 4);
    4.69  
    4.70 -    /* total width & height */
    4.71 -    cheight = (s->cr[9] & 0x1f) + 1;
    4.72 -    cw = 8;
    4.73 -    if (!(s->sr[1] & 0x01))
    4.74 -        cw = 9;
    4.75 -    if (s->sr[1] & 0x08)
    4.76 -        cw = 16; /* NOTE: no 18 pixel wide */
    4.77 -    x_incr = cw * ((s->ds->depth + 7) >> 3);
    4.78 -    width = (s->cr[0x01] + 1);
    4.79 -    if (s->cr[0x06] == 100) {
    4.80 -        /* ugly hack for CGA 160x100x16 - explain me the logic */
    4.81 -        height = 100;
    4.82 -    } else {
    4.83 -        height = s->cr[0x12] | 
    4.84 -            ((s->cr[0x07] & 0x02) << 7) | 
    4.85 -            ((s->cr[0x07] & 0x40) << 3);
    4.86 -        height = (height + 1) / cheight;
    4.87 -    }
    4.88 -    if ((height * width) > CH_ATTR_SIZE) {
    4.89 -        /* better than nothing: exit if transient size is too big */
    4.90 -        return;
    4.91 -    }
    4.92 -
    4.93 -    if (width != s->last_width || height != s->last_height ||
    4.94 -        cw != s->last_cw || cheight != s->last_ch) {
    4.95 -        s->last_scr_width = width * cw;
    4.96 -        s->last_scr_height = height * cheight;
    4.97 -        dpy_resize(s->ds, s->last_scr_width, s->last_scr_height, s->last_scr_width * (s->ds->depth / 8));
    4.98 -        s->last_width = width;
    4.99 -        s->last_height = height;
   4.100 -        s->last_ch = cheight;
   4.101 -        s->last_cw = cw;
   4.102 -        full_update = 1;
   4.103 -    }
   4.104      cursor_offset = ((s->cr[0x0e] << 8) | s->cr[0x0f]) - s->start_addr;
   4.105      if (cursor_offset != s->cursor_offset ||
   4.106          s->cr[0xa] != s->cursor_start ||
   4.107 @@ -1501,16 +1506,6 @@ static void vga_draw_graphic(VGAState *s
   4.108      s->get_resolution(s, &width, &height);
   4.109      disp_width = width;
   4.110  
   4.111 -    ds_depth = s->ds->depth;
   4.112 -    depth = s->get_bpp(s);
   4.113 -    if (s->ds->dpy_colourdepth != NULL && 
   4.114 -            (ds_depth != depth || !s->ds->shared_buf))
   4.115 -        s->ds->dpy_colourdepth(s->ds, depth);
   4.116 -    if (ds_depth != s->ds->depth) full_update = 1;
   4.117 -
   4.118 -    s->rgb_to_pixel = 
   4.119 -        rgb_to_pixel_dup_table[get_depth_index(s->ds)];
   4.120 -
   4.121      shift_control = (s->gr[0x05] >> 5) & 3;
   4.122      double_scan = (s->cr[0x09] >> 7);
   4.123      if (shift_control != 1) {
   4.124 @@ -1527,12 +1522,44 @@ static void vga_draw_graphic(VGAState *s
   4.125          s->shift_control = shift_control;
   4.126          s->double_scan = double_scan;
   4.127      }
   4.128 -    
   4.129 +    if (shift_control == 1 && (s->sr[0x01] & 8)) {
   4.130 +        disp_width <<= 1;
   4.131 +    }
   4.132 +
   4.133 +    ds_depth = s->ds->depth;
   4.134 +    depth = s->get_bpp(s);
   4.135 +    if (s->ds->dpy_resize_shared) {
   4.136 +        if (s->line_offset != s->last_line_offset || 
   4.137 +            disp_width != s->last_width ||
   4.138 +            height != s->last_height ||
   4.139 +            old_depth != depth) {
   4.140 +            dpy_resize_shared(s->ds, disp_width, height, depth, s->line_offset, s->vram_ptr + (s->start_addr * 4));
   4.141 +            s->last_scr_width = disp_width;
   4.142 +            s->last_scr_height = height;
   4.143 +            s->last_width = disp_width;
   4.144 +            s->last_height = height;
   4.145 +            s->last_line_offset = s->line_offset;
   4.146 +            old_depth = depth;
   4.147 +            full_update = 1;
   4.148 +        } else if (s->ds->shared_buf && (full_update || s->ds->data != s->vram_ptr + (s->start_addr * 4)))
   4.149 +            s->ds->dpy_setdata(s->ds, s->vram_ptr + (s->start_addr * 4));
   4.150 +    } else if (disp_width != s->last_width ||
   4.151 +               height != s->last_height) {
   4.152 +        dpy_resize(s->ds, disp_width, height);
   4.153 +        s->last_scr_width = disp_width;
   4.154 +        s->last_scr_height = height;
   4.155 +        s->last_width = disp_width;
   4.156 +        s->last_height = height;
   4.157 +        full_update = 1;
   4.158 +    }
   4.159 +
   4.160 +    s->rgb_to_pixel = 
   4.161 +        rgb_to_pixel_dup_table[get_depth_index(s->ds)];
   4.162 +
   4.163      if (shift_control == 0) {
   4.164          full_update |= update_palette16(s);
   4.165          if (s->sr[0x01] & 8) {
   4.166              v = VGA_DRAW_LINE4D2;
   4.167 -            disp_width <<= 1;
   4.168          } else {
   4.169              v = VGA_DRAW_LINE4;
   4.170          }
   4.171 @@ -1541,7 +1568,6 @@ static void vga_draw_graphic(VGAState *s
   4.172          full_update |= update_palette16(s);
   4.173          if (s->sr[0x01] & 8) {
   4.174              v = VGA_DRAW_LINE2D2;
   4.175 -            disp_width <<= 1;
   4.176          } else {
   4.177              v = VGA_DRAW_LINE2;
   4.178          }
   4.179 @@ -1579,19 +1605,6 @@ static void vga_draw_graphic(VGAState *s
   4.180      }
   4.181  
   4.182      vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + get_depth_index(s->ds)];
   4.183 -    if (s->line_offset != s->last_line_offset || 
   4.184 -        disp_width != s->last_width ||
   4.185 -        height != s->last_height) {
   4.186 -        dpy_resize(s->ds, disp_width, height, s->line_offset);
   4.187 -        s->last_scr_width = disp_width;
   4.188 -        s->last_scr_height = height;
   4.189 -        s->last_width = disp_width;
   4.190 -        s->last_height = height;
   4.191 -        s->last_line_offset = s->line_offset; 
   4.192 -        full_update = 1;
   4.193 -    }
   4.194 -    if (s->ds->shared_buf && (full_update || s->ds->data != s->vram_ptr + (s->start_addr * 4)))
   4.195 -        s->ds->dpy_setdata(s->ds, s->vram_ptr + (s->start_addr * 4));
   4.196      if (!s->ds->shared_buf && s->cursor_invalidate)
   4.197          s->cursor_invalidate(s);
   4.198      
   4.199 @@ -2311,7 +2324,7 @@ static void vga_save_dpy_update(DisplayS
   4.200  {
   4.201  }
   4.202  
   4.203 -static void vga_save_dpy_resize(DisplayState *s, int w, int h, int linesize)
   4.204 +static void vga_save_dpy_resize(DisplayState *s, int w, int h)
   4.205  {
   4.206      s->linesize = w * 4;
   4.207      s->data = qemu_malloc(h * s->linesize);
     5.1 --- a/tools/ioemu/hw/xenfb.c	Mon Jun 09 09:37:56 2008 +0100
     5.2 +++ b/tools/ioemu/hw/xenfb.c	Mon Jun 09 09:39:15 2008 +0100
     5.3 @@ -587,10 +587,10 @@ static void xenfb_on_fb_event(struct xen
     5.4  					       event->resize.offset,
     5.5  					       event->resize.stride) < 0)
     5.6  				break;
     5.7 -			dpy_colourdepth(xenfb->ds, xenfb->depth);
     5.8 -			dpy_resize(xenfb->ds, xenfb->width, xenfb->height, xenfb->row_stride);
     5.9 -			if (xenfb->ds->shared_buf)
    5.10 -				dpy_setdata(xenfb->ds, xenfb->pixels + xenfb->offset);
    5.11 +			if (xenfb->ds->dpy_resize_shared)
    5.12 +			    dpy_resize_shared(xenfb->ds, xenfb->width, xenfb->height, xenfb->depth, xenfb->row_stride, xenfb->pixels + xenfb->offset);
    5.13 +			else
    5.14 +			    dpy_resize(xenfb->ds, xenfb->width, xenfb->height);
    5.15  			xenfb_invalidate(xenfb);
    5.16  			break;
    5.17  		}
    5.18 @@ -1324,10 +1324,10 @@ static int xenfb_register_console(struct
    5.19  			     xenfb_invalidate,
    5.20  			     xenfb_screen_dump,
    5.21  			     xenfb);
    5.22 -	dpy_colourdepth(xenfb->ds, xenfb->depth);
    5.23 -        dpy_resize(xenfb->ds, xenfb->width, xenfb->height, xenfb->row_stride);
    5.24 -	if (xenfb->ds->shared_buf)
    5.25 -	    dpy_setdata(xenfb->ds, xenfb->pixels);
    5.26 +        if (xenfb->ds->dpy_resize_shared)
    5.27 +            dpy_resize_shared(xenfb->ds, xenfb->width, xenfb->height, xenfb->depth, xenfb->row_stride, xenfb->pixels + xenfb->offset);
    5.28 +        else
    5.29 +            dpy_resize(xenfb->ds, xenfb->width, xenfb->height);
    5.30  
    5.31  	if (qemu_set_fd_handler2(xc_evtchn_fd(xenfb->evt_xch), NULL, xenfb_dispatch_channel, NULL, xenfb) < 0)
    5.32  	        return -1;
    5.33 @@ -1353,6 +1353,8 @@ static char *kbd_path, *fb_path;
    5.34  
    5.35  static unsigned char linux2scancode[KEY_MAX + 1];
    5.36  
    5.37 +static void xenfb_pv_colourdepth(DisplayState *ds, int depth);
    5.38 +
    5.39  int xenfb_connect_vkbd(const char *path)
    5.40  {
    5.41      kbd_path = strdup(path);
    5.42 @@ -1374,11 +1376,13 @@ static void xenfb_pv_update(DisplayState
    5.43      fbfront_update(fb_dev, x, y, w, h);
    5.44  }
    5.45  
    5.46 -static void xenfb_pv_resize(DisplayState *ds, int w, int h, int linesize)
    5.47 +static void xenfb_pv_resize_shared(DisplayState *ds, int w, int h, int depth, int linesize, void *pixels)
    5.48  {
    5.49      XenFBState *xs = ds->opaque;
    5.50      struct fbfront_dev *fb_dev = xs->fb_dev;
    5.51 +    int offset;
    5.52      fprintf(stderr,"resize to %dx%d, %d required\n", w, h, linesize);
    5.53 +    xenfb_pv_colourdepth(ds, depth);
    5.54      ds->width = w;
    5.55      ds->height = h;
    5.56      if (!linesize)
    5.57 @@ -1389,13 +1393,20 @@ static void xenfb_pv_resize(DisplayState
    5.58      if (!fb_dev)
    5.59          return;
    5.60      if (ds->shared_buf) {
    5.61 -        ds->data = NULL;
    5.62 +        offset = pixels - xs->vga_vram;
    5.63 +        ds->data = pixels;
    5.64 +        fbfront_resize(fb_dev, ds->width, ds->height, ds->linesize, ds->depth, offset);
    5.65      } else {
    5.66          ds->data = xs->nonshared_vram;
    5.67          fbfront_resize(fb_dev, w, h, linesize, ds->depth, VGA_RAM_SIZE);
    5.68      }
    5.69  }
    5.70  
    5.71 +static void xenfb_pv_resize(DisplayState *ds, int w, int h)
    5.72 +{
    5.73 +    xenfb_pv_resize_shared(ds, w, h, 0, 0, NULL);
    5.74 +}
    5.75 +
    5.76  static void xenfb_pv_colourdepth(DisplayState *ds, int depth)
    5.77  {
    5.78      XenFBState *xs = ds->opaque;
    5.79 @@ -1418,7 +1429,6 @@ static void xenfb_pv_colourdepth(Display
    5.80          ds->data = NULL;
    5.81      } else {
    5.82          ds->data = xs->nonshared_vram;
    5.83 -        fbfront_resize(fb_dev, ds->width, ds->height, ds->linesize, ds->depth, VGA_RAM_SIZE);
    5.84      }
    5.85  }
    5.86  
    5.87 @@ -1597,7 +1607,7 @@ int xenfb_pv_display_init(DisplayState *
    5.88      ds->linesize = 640 * 4;
    5.89      ds->dpy_update = xenfb_pv_update;
    5.90      ds->dpy_resize = xenfb_pv_resize;
    5.91 -    ds->dpy_colourdepth = xenfb_pv_colourdepth;
    5.92 +    ds->dpy_resize_shared = xenfb_pv_resize_shared;
    5.93      ds->dpy_setdata = xenfb_pv_setdata;
    5.94      ds->dpy_refresh = xenfb_pv_refresh;
    5.95      return 0;
     6.1 --- a/tools/ioemu/sdl.c	Mon Jun 09 09:37:56 2008 +0100
     6.2 +++ b/tools/ioemu/sdl.c	Mon Jun 09 09:39:15 2008 +0100
     6.3 @@ -50,6 +50,8 @@ static SDL_Cursor *sdl_cursor_hidden;
     6.4  static int absolute_enabled = 0;
     6.5  static int opengl_enabled;
     6.6  
     6.7 +static void sdl_colourdepth(DisplayState *ds, int depth);
     6.8 +
     6.9  #ifdef CONFIG_OPENGL
    6.10  static GLint tex_format;
    6.11  static GLint tex_type;
    6.12 @@ -211,12 +213,14 @@ static void sdl_setdata(DisplayState *ds
    6.13      ds->data = pixels;
    6.14  }
    6.15  
    6.16 -static void sdl_resize(DisplayState *ds, int w, int h, int linesize)
    6.17 +static void sdl_resize_shared(DisplayState *ds, int w, int h, int depth, int linesize, void *pixels)
    6.18  {
    6.19      int flags;
    6.20  
    6.21      //    printf("resizing to %d %d\n", w, h);
    6.22  
    6.23 +    sdl_colourdepth(ds, depth);
    6.24 +
    6.25  #ifdef CONFIG_OPENGL
    6.26      if (ds->shared_buf && opengl_enabled)
    6.27          flags = SDL_OPENGL|SDL_RESIZABLE;
    6.28 @@ -245,7 +249,8 @@ static void sdl_resize(DisplayState *ds,
    6.29              opengl_enabled = 0;
    6.30              ds->dpy_update = sdl_update;
    6.31              ds->dpy_setdata = sdl_setdata;
    6.32 -            sdl_resize(ds, w, h, linesize);
    6.33 +            ds->dpy_resize_shared = sdl_resize_shared;
    6.34 +            sdl_resize_shared(ds, w, h, depth, linesize, pixels);
    6.35              return;
    6.36          }
    6.37          exit(1);
    6.38 @@ -272,6 +277,7 @@ static void sdl_resize(DisplayState *ds,
    6.39          } else {
    6.40              ds->bgr = 0;
    6.41          }
    6.42 +        shared = NULL;
    6.43          ds->data = screen->pixels;
    6.44          ds->linesize = screen->pitch;
    6.45      } else {
    6.46 @@ -296,21 +302,26 @@ static void sdl_resize(DisplayState *ds,
    6.47          };
    6.48  #endif
    6.49      }
    6.50 +    if (ds->shared_buf) ds->dpy_setdata(ds, pixels);
    6.51 +}
    6.52 +
    6.53 +static void sdl_resize(DisplayState *ds, int w, int h)
    6.54 +{
    6.55 +    sdl_resize_shared(ds, w, h, 0, w * (ds->depth / 8), NULL);
    6.56  }
    6.57  
    6.58  static void sdl_colourdepth(DisplayState *ds, int depth)
    6.59  {
    6.60      if (!depth || !ds->depth) {
    6.61          ds->shared_buf = 0;
    6.62 +        ds->dpy_update = sdl_update;
    6.63          return;
    6.64      }
    6.65      ds->shared_buf = 1;
    6.66      ds->depth = depth;
    6.67 -    ds->linesize = width * depth / 8;
    6.68  #ifdef CONFIG_OPENGL
    6.69      if (opengl_enabled) {
    6.70          ds->dpy_update = opengl_update;
    6.71 -        ds->dpy_setdata = opengl_setdata;
    6.72      }
    6.73  #endif
    6.74  }
    6.75 @@ -517,8 +528,7 @@ static void sdl_send_mouse_event(int dx,
    6.76  static void toggle_full_screen(DisplayState *ds)
    6.77  {
    6.78      gui_fullscreen = !gui_fullscreen;
    6.79 -    sdl_resize(ds, ds->width, ds->height, ds->linesize);
    6.80 -    ds->dpy_setdata(ds, ds->data);
    6.81 +    sdl_resize_shared(ds, ds->width, ds->height, ds->depth, ds->linesize, ds->data);
    6.82      if (gui_fullscreen) {
    6.83          gui_saved_grab = gui_grab;
    6.84          sdl_grab_start();
    6.85 @@ -760,11 +770,16 @@ void sdl_display_init(DisplayState *ds, 
    6.86  
    6.87      ds->dpy_update = sdl_update;
    6.88      ds->dpy_resize = sdl_resize;
    6.89 +    ds->dpy_resize_shared = sdl_resize_shared;
    6.90      ds->dpy_refresh = sdl_refresh;
    6.91 -    ds->dpy_colourdepth = sdl_colourdepth;
    6.92 -    ds->dpy_setdata = sdl_setdata;
    6.93 +#ifdef CONFIG_OPENGL
    6.94 +    if (opengl_enabled)
    6.95 +        ds->dpy_setdata = opengl_setdata;
    6.96 +    else
    6.97 +        ds->dpy_setdata = sdl_setdata;
    6.98 +#endif
    6.99  
   6.100 -    sdl_resize(ds, 640, 400, 640 * 4);
   6.101 +    sdl_resize(ds, 640, 400);
   6.102      sdl_update_caption();
   6.103      SDL_EnableKeyRepeat(250, 50);
   6.104      SDL_EnableUNICODE(1);
     7.1 --- a/tools/ioemu/vl.c	Mon Jun 09 09:37:56 2008 +0100
     7.2 +++ b/tools/ioemu/vl.c	Mon Jun 09 09:39:15 2008 +0100
     7.3 @@ -4463,7 +4463,6 @@ void dumb_display_init(DisplayState *ds)
     7.4      ds->depth = 0;
     7.5      ds->dpy_update = dumb_update;
     7.6      ds->dpy_resize = dumb_resize;
     7.7 -    ds->dpy_colourdepth = NULL;
     7.8      ds->dpy_refresh = dumb_refresh;
     7.9      ds->gui_timer_interval = 500;
    7.10      ds->idle = 1;
     8.1 --- a/tools/ioemu/vl.h	Mon Jun 09 09:37:56 2008 +0100
     8.2 +++ b/tools/ioemu/vl.h	Mon Jun 09 09:39:15 2008 +0100
     8.3 @@ -945,9 +945,9 @@ struct DisplayState {
     8.4      int shared_buf;
     8.5      
     8.6      void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
     8.7 -    void (*dpy_resize)(struct DisplayState *s, int w, int h, int linesize);
     8.8 -    void (*dpy_colourdepth)(struct DisplayState *s, int depth);
     8.9 +    void (*dpy_resize)(struct DisplayState *s, int w, int h);
    8.10      void (*dpy_setdata)(DisplayState *s, void *pixels);
    8.11 +    void (*dpy_resize_shared)(DisplayState *s, int w, int h, int depth, int linesize, void *pixels);
    8.12      void (*dpy_refresh)(struct DisplayState *s);
    8.13      void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y, int dst_x, int dst_y, int w, int h);
    8.14  };
    8.15 @@ -957,14 +957,14 @@ static inline void dpy_update(DisplaySta
    8.16      s->dpy_update(s, x, y, w, h);
    8.17  }
    8.18  
    8.19 -static inline void dpy_resize(DisplayState *s, int w, int h, int linesize)
    8.20 +static inline void dpy_resize(DisplayState *s, int w, int h)
    8.21  {
    8.22 -    s->dpy_resize(s, w, h, linesize);
    8.23 +    s->dpy_resize(s, w, h);
    8.24  }
    8.25  
    8.26 -static inline void dpy_colourdepth(struct DisplayState *s, int depth)
    8.27 +static inline void dpy_resize_shared(DisplayState *s, int w, int h, int depth, int linesize, void *pixels)
    8.28  {
    8.29 -    s->dpy_colourdepth(s, depth);
    8.30 +    s->dpy_resize_shared(s, w, h, depth, linesize, pixels);
    8.31  }
    8.32  
    8.33  static inline void dpy_setdata(DisplayState *s, void *pixels)
     9.1 --- a/tools/ioemu/vnc.c	Mon Jun 09 09:37:56 2008 +0100
     9.2 +++ b/tools/ioemu/vnc.c	Mon Jun 09 09:39:15 2008 +0100
     9.3 @@ -277,6 +277,7 @@ static void enqueue_framebuffer_update(V
     9.4  static void dequeue_framebuffer_update(VncState *vs);
     9.5  static int is_empty_queue(VncState *vs);
     9.6  static void free_queue(VncState *vs);
     9.7 +static void vnc_colourdepth(DisplayState *ds, int depth);
     9.8  
     9.9  #if 0
    9.10  static inline void vnc_set_bit(uint32_t *d, int k)
    9.11 @@ -363,13 +364,14 @@ static void vnc_framebuffer_update(VncSt
    9.12      vnc_write_s32(vs, encoding);
    9.13  }
    9.14  
    9.15 -static void vnc_dpy_resize(DisplayState *ds, int w, int h, int linesize)
    9.16 +static void vnc_dpy_resize_shared(DisplayState *ds, int w, int h, int depth, int linesize, void *pixels)
    9.17  {
    9.18      static int allocated;
    9.19      int size_changed;
    9.20      VncState *vs = ds->opaque;
    9.21      int o;
    9.22  
    9.23 +    vnc_colourdepth(ds, depth);
    9.24      if (!ds->shared_buf) {
    9.25          ds->linesize = w * vs->depth;
    9.26          if (allocated)
    9.27 @@ -419,6 +421,12 @@ static void vnc_dpy_resize(DisplayState 
    9.28      for (o = DIRTY_PIXEL_BITS; o < ds->width; o *= 2)
    9.29  	vs->dirty_pixel_shift++;
    9.30      framebuffer_set_updated(vs, 0, 0, ds->width, ds->height);
    9.31 +    if (ds->shared_buf) ds->data = pixels;
    9.32 +}
    9.33 +
    9.34 +static void vnc_dpy_resize(DisplayState *ds, int w, int h)
    9.35 +{
    9.36 +    vnc_dpy_resize_shared(ds, w, h, 0, w * (ds->depth / 8), NULL);
    9.37  }
    9.38  
    9.39  /* fastest code */
    9.40 @@ -1640,7 +1648,7 @@ static void vnc_dpy_setdata(DisplayState
    9.41      ds->data = pixels;
    9.42  }
    9.43  
    9.44 -static void vnc_dpy_colourdepth(DisplayState *ds, int depth)
    9.45 +static void vnc_colourdepth(DisplayState *ds, int depth)
    9.46  {
    9.47      int host_big_endian_flag;
    9.48      struct VncState *vs = ds->opaque;
    9.49 @@ -1742,8 +1750,6 @@ static void vnc_dpy_colourdepth(DisplayS
    9.50              vs->write_pixels = vnc_write_pixels_generic;
    9.51          }
    9.52      }
    9.53 -
    9.54 -    vnc_dpy_resize(ds, ds->width, ds->height, ds->linesize);
    9.55  }
    9.56  
    9.57  static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len)
    9.58 @@ -2502,14 +2508,14 @@ void vnc_display_init(DisplayState *ds)
    9.59      vs->ds->data = NULL;
    9.60      vs->ds->dpy_update = vnc_dpy_update;
    9.61      vs->ds->dpy_resize = vnc_dpy_resize;
    9.62 -    vs->ds->dpy_colourdepth = vnc_dpy_colourdepth;
    9.63      vs->ds->dpy_setdata = vnc_dpy_setdata;
    9.64 +    vs->ds->dpy_resize_shared = vnc_dpy_resize_shared;
    9.65      vs->ds->dpy_refresh = vnc_dpy_refresh;
    9.66  
    9.67      vs->ds->width = 640;
    9.68      vs->ds->height = 400;
    9.69      vs->ds->linesize = 640 * 4;
    9.70 -    vnc_dpy_colourdepth(vs->ds, 24);
    9.71 +    vnc_dpy_resize_shared(ds, ds->width, ds->height, 24, ds->linesize, NULL);
    9.72  }
    9.73  
    9.74  #if CONFIG_VNC_TLS