From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Stabellini Subject: [PATCH] vga shared memory Date: Tue, 19 Feb 2008 17:13:23 +0000 Message-ID: <47BB0E33.7040509@eu.citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010208000504010109090007" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------010208000504010109090007 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi all, 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 --------------010208000504010109090007 Content-Type: text/x-patch; name="vga-share-buffer.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="vga-share-buffer.patch" diff -r 8848d9e07584 tools/ioemu/hw/vga.c --- a/tools/ioemu/hw/vga.c Mon Feb 18 21:26:57 2008 +0000 +++ b/tools/ioemu/hw/vga.c Tue Feb 19 16:20:50 2008 +0000 @@ -1135,8 +1135,6 @@ static void vga_draw_text(VGAState *s, i } depth = s->get_bpp(s); - if (depth == 24) - depth = 32; if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth) s->ds->dpy_colourdepth(s->ds, depth); if (width != s->last_width || height != s->last_height || @@ -1557,10 +1555,10 @@ static void vga_draw_graphic(VGAState *s vga_draw_line = vga_draw_line_table[v * NB_DEPTHS + get_depth_index(s->ds)]; depth = s->get_bpp(s); - if (depth == 24) - depth = 32; - if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth) - s->ds->dpy_colourdepth(s->ds, depth); + if (s->ds->dpy_colourdepth != NULL && s->ds->depth != depth) { + if (depth != 24 || s->ds->depth != 32) + s->ds->dpy_colourdepth(s->ds, depth); + } if (disp_width != s->last_width || height != s->last_height) { dpy_resize(s->ds, disp_width, height); @@ -1570,7 +1568,9 @@ static void vga_draw_graphic(VGAState *s s->last_height = height; full_update = 1; } - if (s->cursor_invalidate) + if (s->ds->shared_buf && s->ds->data != s->vram_ptr + (s->start_addr * 4)) + s->ds->data = s->vram_ptr + (s->start_addr * 4); + if (!s->ds->shared_buf && s->cursor_invalidate) s->cursor_invalidate(s); line_offset = s->line_offset; @@ -1621,9 +1621,11 @@ static void vga_draw_graphic(VGAState *s page_min = page0; if (page_max == 0 || page1 > page_max) page_max = page1; - vga_draw_line(s, d, s->vram_ptr + addr, width); - if (s->cursor_draw_line) - s->cursor_draw_line(s, d, y); + if (!s->ds->shared_buf) { + vga_draw_line(s, d, s->vram_ptr + addr, width); + if (s->cursor_draw_line) + s->cursor_draw_line(s, d, y); + } } else { if (y_start >= 0) { /* flush to display */ diff -r 8848d9e07584 tools/ioemu/vl.h --- a/tools/ioemu/vl.h Mon Feb 18 21:26:57 2008 +0000 +++ b/tools/ioemu/vl.h Tue Feb 19 16:20:50 2008 +0000 @@ -935,6 +935,7 @@ struct DisplayState { void *opaque; int switchbpp; + int shared_buf; void (*dpy_update)(struct DisplayState *s, int x, int y, int w, int h); void (*dpy_resize)(struct DisplayState *s, int w, int h); diff -r 8848d9e07584 tools/ioemu/vnc.c --- a/tools/ioemu/vnc.c Mon Feb 18 21:26:57 2008 +0000 +++ b/tools/ioemu/vnc.c Tue Feb 19 16:20:50 2008 +0000 @@ -336,11 +336,21 @@ static void vnc_framebuffer_update(VncSt static void vnc_dpy_resize(DisplayState *ds, int w, int h) { + static int allocated; int size_changed; VncState *vs = ds->opaque; int o; - ds->data = realloc(ds->data, w * h * vs->depth); + if (!ds->shared_buf) { + if (allocated) + ds->data = realloc(ds->data, w * h * vs->depth); + else + ds->data = malloc(w * h * vs->depth); + allocated = 1; + } else if (allocated) { + free(ds->data); + allocated = 0; + } vs->old_data = realloc(vs->old_data, w * h * vs->depth); vs->dirty_row = realloc(vs->dirty_row, h * sizeof(vs->dirty_row[0])); vs->update_row = realloc(vs->update_row, h * sizeof(vs->dirty_row[0])); @@ -537,6 +547,11 @@ static void vnc_copy(DisplayState *ds, i int pitch = ds->linesize; VncState *vs = ds->opaque; int updating_client = 1; + + if (ds->shared_buf) { + framebuffer_set_updated(vs, dst_x, dst_y, w, h); + return; + } if (src_x < vs->visible_x || src_y < vs->visible_y || dst_x < vs->visible_x || dst_y < vs->visible_y || @@ -1409,9 +1424,6 @@ static void set_pixel_format(VncState *v vs->blue_shift = blue_shift; vs->blue_max = blue_max; vs->pix_bpp = bits_per_pixel / 8; - - vga_hw_invalidate(); - vga_hw_update(); } static void pixel_format_message (VncState *vs) { @@ -1468,16 +1480,26 @@ static void vnc_dpy_colourdepth(DisplayS static void vnc_dpy_colourdepth(DisplayState *ds, int depth) { int host_big_endian_flag; - struct VncState *vs; - - if (!depth) return; - + struct VncState *vs = ds->opaque; + + switch (depth) { + case 24: + ds->shared_buf = 0; + depth = 32; + break; + case 0: + ds->shared_buf = 0; + return; + default: + ds->shared_buf = 1; + break; + } + #ifdef WORDS_BIGENDIAN host_big_endian_flag = 1; #else host_big_endian_flag = 0; -#endif - vs = ds->opaque; +#endif switch (depth) { case 8: @@ -2312,7 +2334,7 @@ void vnc_display_init(DisplayState *ds) vs->ds->width = 640; vs->ds->height = 400; - vnc_dpy_colourdepth(vs->ds, 32); + vnc_dpy_colourdepth(vs->ds, 24); } #if CONFIG_VNC_TLS --------------010208000504010109090007 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------010208000504010109090007--