xenfb shared buffer
PATCH 1/1 xenfb shared buffer
After the recent DisplayState changes is now possible to share the xenfb backend buffer with the display frontend (sdl, vnc), avoid a memcpy for each screen update.
---
hw/xenfb.c +23 -10
@@ -595,14 +595,7 @@ {int line; -/* -* TODO: xen's qemu-dm seems to have some patches to -* make the qemu display code avoid unneeded -* work. -* - Port them over. -* - Put ds->shared_buf back into use then. -*/ -if (1 /* !xenfb->c.ds->shared_buf */ ) { +if (!is_buffer_shared (xenfb->c.ds->surface)) {if (xenfb->depth ==ds_get_bits_per_pixel (xenfb->c.ds)) {/* Perfect match can use fast path */ for (line = y ; line < (y+h) ; line++) { memcpy(ds_get_data(xenfb->c.ds) + (line * ds_get_linesize(xenfb->c.ds)) + (x * ds_get_bytes_per_pixel(xenfb->c.ds)),
@@ -735,10 +728,30 @@ }/* resize if needed */ -if (xenfb->width !=ds_get_width (xenfb->c.ds) || xenfb->height !=ds_get_height (xenfb->c.ds)) { +if (xenfb->width !=ds_get_width (xenfb->c.ds) || + xenfb->height !=ds_get_height (xenfb->c.ds) || + xenfb->depth !=ds_get_bits_per_pixel (xenfb->c.ds) || + xenfb->row_stride !=ds_get_linesize (xenfb->c.ds) || + xenfb->pixels + xenfb->offset !=ds_get_data (xenfb->c.ds)) { +switch (xenfb->depth) { +case 16 : +case 32 : +/* console.c supported depth -> buffer can be used directly */ +qemu_free_displaysurface (xenfb->c.ds); + xenfb->c.ds->surface =qemu_create_displaysurface_from + (xenfb->width, xenfb->height, xenfb->depth, + xenfb->row_stride, xenfb->pixels + xenfb->offset); +dpy_resize (xenfb->c.ds); +break ; +default : +/* we must convert stuff */ +qemu_resize_displaysurface (xenfb->c.ds, + xenfb->width, xenfb->height, + xenfb->depth, xenfb->row_stride); +break ; + }xen_be_printf (&xenfb->c.xendev,1 ,"update: resizing: %dx%d\n" , xenfb->width, xenfb->height); -qemu_console_resize (xenfb->c.ds, xenfb->width, xenfb->height); xenfb->up_fullscreen =1 ; }
Quoted 3 lines · Stefano Stabellini
After the recent DisplayState changes is now possible to share the xenfb backend buffer with the display frontend (sdl, vnc), avoid a memcpy for each screen update.
I have this and a few more updates to make xenfb work smoothly with displaystate already, look here:
http://git.et.redhat.com/?p=qemu-kraxel.git;a=commitdiff;h=34c58e4e1cc8450e7077a134c013ec805aa940fb
cheers,
Gerd
Quoted 5 lines · Gerd Hoffmann
Quoted 3 lines · Stefano Stabellini
After the recent DisplayState changes is now possible to share the xenfb backend buffer with the display frontend (sdl, vnc), avoid a memcpy for each screen update.
Quoted 9 lines
I have this and a few more updates to make xenfb work smoothly with displaystate already, look here:
http://git.et.redhat.com/?p=qemu-kraxel.git;a=commitdiff;h=34c58e4e1cc8450e7077a134c013ec805aa940fb
cheers,
Gerd
Your patch is correct, I only have a comment:
hw/xenfb.c +0 -0
Quoted 81 lines
(quoted diff) +31
-46@@ -590,62 +593,52 @@ static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, -/* This copies data from the guest framebuffer region, into QEMU's copy - * NB. QEMU's copy is stored in the pixel format of a) the local X - * server (SDL case) or b) the current VNC client pixel format. - * When shifting between colour depths we preserve the MSB. +/* + * This copies data from the guest framebuffer region, into QEMU's + * displaysurface. qemu uses 16 or 32 bpp. In case the pv framebuffer + * uses something else we must convert and copy, otherwise we can + * supply the buffer directly and no thing here. */ static void xenfb_guest_copy(struct XenFB *xenfb, int x, int y, int w, int h) { - int line; - - /* - * TODO: xen's qemu-dm seems to have some patches to - * make the qemu display code avoid unneeded - * work. - * - Port them over. - * - Put ds->shared_buf back into use then. - */ - if (1 /* !xenfb->c.ds->shared_buf */) { - if (xenfb->depth == xenfb->c.ds->depth) { /* Perfect match can use fast path */ - for (line = y ; line < (y+h) ; line++) { - memcpy(xenfb->c.ds->data + (line * xenfb->c.ds->linesize) + (x * xenfb->c.ds->depth / 8), - xenfb->pixels + xenfb->offset + (line * xenfb->row_stride) + (x * xenfb->depth / 8), - w * xenfb->depth / 8); - } - } else { /* Mismatch requires slow pixel munging */ - /* 8 bit == r:3 g:3 b:2 */ - /* 16 bit == r:5 g:6 b:5 */ - /* 24 bit == r:8 g:8 b:8 */ - /* 32 bit == r:8 g:8 b:8 (padding:8) */ - if (xenfb->depth == 8) { - if (xenfb->c.ds->depth == 16) { - BLT(uint8_t, uint16_t, 3, 3, 2, 5, 6, 5); - } else if (xenfb->c.ds->depth == 32) { - BLT(uint8_t, uint32_t, 3, 3, 2, 8, 8, 8); - } - } else if (xenfb->depth == 16) { - if (xenfb->c.ds->depth == 8) { - BLT(uint16_t, uint8_t, 5, 6, 5, 3, 3, 2); - } else if (xenfb->c.ds->depth == 32) { - BLT(uint16_t, uint32_t, 5, 6, 5, 8, 8, 8); - } - } else if (xenfb->depth == 24 || xenfb->depth == 32) { - if (xenfb->c.ds->depth == 8) { - BLT(uint32_t, uint8_t, 8, 8, 8, 3, 3, 2); - } else if (xenfb->c.ds->depth == 16) { - BLT(uint32_t, uint16_t, 8, 8, 8, 5, 6, 5); - } else if (xenfb->c.ds->depth == 32) { - BLT(uint32_t, uint32_t, 8, 8, 8, 8, 8, 8); - } - } + int line, oops = 0; + int bpp = ds_get_bits_per_pixel(xenfb->c.ds); + int linesize = ds_get_linesize(xenfb->c.ds); + uint8_t *data = ds_get_data(xenfb->c.ds); + + if (!is_buffer_shared(xenfb->c.ds->surface)) { + switch (xenfb->depth) { + case 8: + if (bpp == 16) { + BLT(uint8_t, uint16_t, 3, 3, 2, 5, 6, 5); + } else if (bpp == 32) { + BLT(uint8_t, uint32_t, 3, 3, 2, 8, 8, 8); + } else { + oops = 1; + } + break; + case 24: + if (bpp == 16) { + BLT(uint32_t, uint16_t, 8, 8, 8, 5, 6, 5); + } else if (bpp == 32) { + BLT(uint32_t, uint32_t, 8, 8, 8, 8, 8, 8); + } else { + oops = 1; + } + break; + default:
Review static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, · line 636
Quoted 10 lines
(quoted diff) +5
-0+ oops = 1; } } + if (oops) /* should not happen */ + xen_be_printf(&xenfb->c.xendev, 0, "%s: oops: convert %d -> %d bpp?\n", + __FUNCTION__, xenfb->depth, bpp); + dpy_update(xenfb->c.ds, x, y, w, h); }
I am OK with these changes but I wouldn't bother removing the 16 and 32 bpp conversion code even if currently it would never be used. After all is working and well tested code that may be useful in the future.
Quoted 4 lines · Stefano Stabellini
I am OK with these changes but I wouldn't bother removing the 16 and 32 bpp conversion code even if currently it would never be used. After all is working and well tested code that may be useful in the future.
Well I killed it intentionally. That way we'll notice for sure if xenfb doesn't share the buffer although it should. Restoring the functionality in case we ever need it again is easy as all the magic is in the BLT() macro anyway.
cheers
Gerd