ia64/xen-unstable

changeset 17171:69bb0c4af952

ioemu: sdl blitting

Right now qemu takes care of converting pixels between the guest pixel
format and the sdl pixel format, after that qemu also memcpy the
converted pixels to the sdl buffer in video ram. This process can be
improved using the SDL blit capabilities: the patch I am attaching
creates an SDL Surface from the Cirrus VGA framebuffer and uses SDL
blitting functions to convert and write pixels to video ram. SDL
blitting functions are optimized and can even be hardware accelerated
on some platforms.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Mar 03 11:06:31 2008 +0000 (2008-03-03)
parents be143a3a90c6
children 990eb630033a
files tools/ioemu/hw/vga.c tools/ioemu/sdl.c tools/ioemu/vl.h tools/ioemu/vnc.c
line diff
     1.1 --- a/tools/ioemu/hw/vga.c	Mon Mar 03 11:05:18 2008 +0000
     1.2 +++ b/tools/ioemu/hw/vga.c	Mon Mar 03 11:06:31 2008 +0000
     1.3 @@ -1481,7 +1481,7 @@ void check_sse2(void)
     1.4  static void vga_draw_graphic(VGAState *s, int full_update)
     1.5  {
     1.6      int y1, y, update, linesize, y_start, double_scan, mask, depth;
     1.7 -    int width, height, shift_control, line_offset, bwidth;
     1.8 +    int width, height, shift_control, line_offset, bwidth, changed_flag;
     1.9      ram_addr_t page0, page1;
    1.10      int disp_width, multi_scan, multi_run;
    1.11      uint8_t *d;
    1.12 @@ -1554,10 +1554,12 @@ static void vga_draw_graphic(VGAState *s
    1.13      }
    1.14      vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + get_depth_index(s->ds)];
    1.15  
    1.16 +    changed_flag = 0;
    1.17      depth = s->get_bpp(s);
    1.18 -    if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth) {
    1.19 -        if (depth != 24 || s->ds->depth != 32)
    1.20 -            s->ds->dpy_colourdepth(s->ds, depth);
    1.21 +    if (s->ds->dpy_colourdepth != NULL && 
    1.22 +            (s->ds->depth != depth || !s->ds->shared_buf)) {
    1.23 +        s->ds->dpy_colourdepth(s->ds, depth);
    1.24 +        changed_flag = 1;
    1.25      }
    1.26      if (disp_width != s->last_width ||
    1.27          height != s->last_height) {
    1.28 @@ -1567,9 +1569,10 @@ static void vga_draw_graphic(VGAState *s
    1.29          s->last_width = disp_width;
    1.30          s->last_height = height;
    1.31          full_update = 1;
    1.32 +        changed_flag = 1;
    1.33      }
    1.34 -    if (s->ds->shared_buf && s->ds->data != s->vram_ptr + (s->start_addr * 4))
    1.35 -        s->ds->data = s->vram_ptr + (s->start_addr * 4);
    1.36 +    if (s->ds->shared_buf && (changed_flag || s->ds->data != s->vram_ptr + (s->start_addr * 4)))
    1.37 +        s->ds->dpy_setdata(s->ds, s->vram_ptr + (s->start_addr * 4));
    1.38      if (!s->ds->shared_buf && s->cursor_invalidate)
    1.39          s->cursor_invalidate(s);
    1.40      
     2.1 --- a/tools/ioemu/sdl.c	Mon Mar 03 11:05:18 2008 +0000
     2.2 +++ b/tools/ioemu/sdl.c	Mon Mar 03 11:06:31 2008 +0000
     2.3 @@ -30,6 +30,7 @@
     2.4  #endif
     2.5  
     2.6  static SDL_Surface *screen;
     2.7 +static SDL_Surface *shared = NULL;
     2.8  static int gui_grab; /* if true, all keyboard/mouse events are grabbed */
     2.9  static int last_vm_running;
    2.10  static int gui_saved_grab;
    2.11 @@ -47,7 +48,46 @@ static int absolute_enabled = 0;
    2.12  static void sdl_update(DisplayState *ds, int x, int y, int w, int h)
    2.13  {
    2.14      //    printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h);
    2.15 -    SDL_UpdateRect(screen, x, y, w, h);
    2.16 +    if (shared) {
    2.17 +        SDL_Rect rec;
    2.18 +        rec.x = x;
    2.19 +        rec.y = y;
    2.20 +        rec.w = w;
    2.21 +        rec.h = h;
    2.22 +        SDL_BlitSurface(shared, &rec, screen, &rec);
    2.23 +    }
    2.24 +    SDL_Flip(screen);
    2.25 +}
    2.26 +
    2.27 +static void sdl_setdata(DisplayState *ds, void *pixels)
    2.28 +{
    2.29 +    uint32_t rmask, gmask, bmask, amask = 0;
    2.30 +    switch (ds->depth) {
    2.31 +        case 8:
    2.32 +            rmask = 0x000000E0;
    2.33 +            gmask = 0x0000001C;
    2.34 +            bmask = 0x00000003;
    2.35 +            break;
    2.36 +        case 16:
    2.37 +            rmask = 0x0000F800;
    2.38 +            gmask = 0x000007E0;
    2.39 +            bmask = 0x0000001F;
    2.40 +            break;
    2.41 +        case 24:
    2.42 +            rmask = 0x00FF0000;
    2.43 +            gmask = 0x0000FF00;
    2.44 +            bmask = 0x000000FF;
    2.45 +            break;
    2.46 +        case 32:
    2.47 +            rmask = 0x00FF0000;
    2.48 +            gmask = 0x0000FF00;
    2.49 +            bmask = 0x000000FF;
    2.50 +            break;
    2.51 +        default:
    2.52 +            return;
    2.53 +    }
    2.54 +    shared = SDL_CreateRGBSurfaceFrom(pixels, width, height, ds->depth, ds->linesize, rmask , gmask, bmask, amask);
    2.55 +    ds->data = pixels;
    2.56  }
    2.57  
    2.58  static void sdl_resize(DisplayState *ds, int w, int h)
    2.59 @@ -56,7 +96,7 @@ static void sdl_resize(DisplayState *ds,
    2.60  
    2.61      //    printf("resizing to %d %d\n", w, h);
    2.62  
    2.63 -    flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
    2.64 +    flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_DOUBLEBUF|SDL_HWPALETTE;
    2.65      if (gui_fullscreen)
    2.66          flags |= SDL_FULLSCREEN;
    2.67  
    2.68 @@ -78,16 +118,28 @@ static void sdl_resize(DisplayState *ds,
    2.69          fprintf(stderr, "Could not open SDL display\n");
    2.70          exit(1);
    2.71      }
    2.72 -    ds->data = screen->pixels;
    2.73 -    ds->linesize = screen->pitch;
    2.74 -    ds->depth = screen->format->BitsPerPixel;
    2.75 -    if (ds->depth == 32 && screen->format->Rshift == 0) {
    2.76 -        ds->bgr = 1;
    2.77 -    } else {
    2.78 -        ds->bgr = 0;
    2.79 -    }
    2.80      ds->width = w;
    2.81      ds->height = h;
    2.82 +    if (!ds->shared_buf) {
    2.83 +        ds->depth = screen->format->BitsPerPixel;
    2.84 +        if (ds->depth == 32 && screen->format->Rshift == 0) {
    2.85 +            ds->bgr = 1;
    2.86 +        } else {
    2.87 +            ds->bgr = 0;
    2.88 +        }
    2.89 +        ds->data = screen->pixels;
    2.90 +        ds->linesize = screen->pitch;
    2.91 +    } else {
    2.92 +        ds->linesize = (ds->depth / 8) * w;
    2.93 +    }
    2.94 +}
    2.95 +
    2.96 +static void sdl_colourdepth(DisplayState *ds, int depth)
    2.97 +{
    2.98 +    if (!depth || !ds->depth) return;
    2.99 +    ds->shared_buf = 1;
   2.100 +    ds->depth = depth;
   2.101 +    ds->linesize = width * depth / 8; 
   2.102  }
   2.103  
   2.104  /* generic keyboard conversion */
   2.105 @@ -508,7 +560,8 @@ void sdl_display_init(DisplayState *ds, 
   2.106      ds->dpy_update = sdl_update;
   2.107      ds->dpy_resize = sdl_resize;
   2.108      ds->dpy_refresh = sdl_refresh;
   2.109 -    ds->dpy_colourdepth = NULL;
   2.110 +    ds->dpy_colourdepth = sdl_colourdepth;
   2.111 +    ds->dpy_setdata = sdl_setdata;
   2.112  
   2.113      sdl_resize(ds, 640, 400);
   2.114      sdl_update_caption();
     3.1 --- a/tools/ioemu/vl.h	Mon Mar 03 11:05:18 2008 +0000
     3.2 +++ b/tools/ioemu/vl.h	Mon Mar 03 11:06:31 2008 +0000
     3.3 @@ -942,6 +942,7 @@ struct DisplayState {
     3.4      void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h);
     3.5      void (*dpy_resize)(struct DisplayState *s, int w, int h);
     3.6      void (*dpy_colourdepth)(struct DisplayState *s, int depth);
     3.7 +    void (*dpy_setdata)(DisplayState *ds, void *pixels);
     3.8      void (*dpy_refresh)(struct DisplayState *s);
     3.9      void (*dpy_copy)(struct DisplayState *s, int src_x, int src_y, int dst_x, int dst_y, int w, int h);
    3.10  };
     4.1 --- a/tools/ioemu/vnc.c	Mon Mar 03 11:05:18 2008 +0000
     4.2 +++ b/tools/ioemu/vnc.c	Mon Mar 03 11:06:31 2008 +0000
     4.3 @@ -1621,6 +1621,11 @@ static void pixel_format_message (VncSta
     4.4      vnc_write(vs, pad, 3);           /* padding */
     4.5  }
     4.6  
     4.7 +static void vnc_dpy_setdata(DisplayState *ds, void *pixels)
     4.8 +{
     4.9 +    ds->data = pixels;
    4.10 +}
    4.11 +
    4.12  static void vnc_dpy_colourdepth(DisplayState *ds, int depth)
    4.13  {
    4.14      int host_big_endian_flag;
    4.15 @@ -1628,6 +1633,7 @@ static void vnc_dpy_colourdepth(DisplayS
    4.16  
    4.17      switch (depth) {
    4.18          case 24:
    4.19 +            if (ds->depth == 32) return;
    4.20              ds->shared_buf = 0;
    4.21              depth = 32;
    4.22              break;
    4.23 @@ -2480,6 +2486,7 @@ void vnc_display_init(DisplayState *ds)
    4.24      vs->ds->dpy_update = vnc_dpy_update;
    4.25      vs->ds->dpy_resize = vnc_dpy_resize;
    4.26      vs->ds->dpy_colourdepth = vnc_dpy_colourdepth;
    4.27 +    vs->ds->dpy_setdata = vnc_dpy_setdata;
    4.28      vs->ds->dpy_refresh = vnc_dpy_refresh;
    4.29  
    4.30      vs->ds->width = 640;