Qemu vnc color depth
Hi all,
the qemu vnc server changes its internal colour depth based on the client request. This way just one colour conversion is done: the one in vga_template.h, from the guest colour depth and the vnc server internal colour depth.
This patch is meant to remove this colour conversion to improve performances. It accomplishes the goal making the qemu internal colour depth always the same as the guest colour depth.
The basic idea is that the vnc client is the one that should do the colour conversion, if necessary. In general it should accept the pixel format suggested by the server during the initial negotiation. This behaviour can be set in most vnc clients (vncviewer included).
If the guest changes colour depth, the qemu vnc server changes colour depth too and notifies the client. The problem is that the vnc protocol doesn't provide a message from the server to the client to ask for a colour depth change. So what I am doing is either:
1) quietly starting to do the conversion on vnc server (not gaining any performances here);
2) closing the vnc connection with the client, so the client can reconnect and choose the new pixel format.
By default I am doing 1), however the second choice can be enabled passing the -vnc-switch-bpp command line option.
In order to do the colour conversion on the vnc server I had to improve the colour conversion code already in place because it only supported conversions from 32 bpp. The patch adds colour conversion code that support conversions from any resolution to any resolution.
A last note: to get most out of this patch it is best to set Windows to 16 bit colour depth, because the 24 bit mode is 24 bit depth and 24 bpp, meaning no alpha channel. The vnc protocol doesn't support 24 bpp, only 32 bpp, so this conversion is unavoidable.
Comments and critics are welcome.
Best Regards,
Stefano Stabellini
tools/ioemu/console.c +2 -6
@@ -169,16 +169,12 @@ static unsigned int vga_get_color(Displaunsigned int r, g, b, color;switch (ds->depth) { -#if 0 case 8 : r = (rgba >>16 ) &0xff ; g = (rgba >>8 ) &0xff ; b = (rgba) &0xff ; - color = (rgb_to_index[r] *6 *6 ) + - (rgb_to_index[g] *6 ) + - (rgb_to_index[b]); -break ; -#endif + color = ((r >>5 ) <<5 | (g >>5 ) <<2 | (b >>6 )); +break ;case 15 : r = (rgba >>16 ) &0xff ; g = (rgba >>8 ) &0xff ;
tools/ioemu/hw/vga.c +12 -2
@@ -1071,7 +1071,7 @@ static const uint8_t cursor_glyph[32 * 4*/ static void vga_draw_text (VGAState *s,int full_update) { -int cx, cy, cheight, cw, ch, cattr, height, width, ch_attr; +int cx, cy, cheight, cw, ch, cattr, height, width, ch_attr, depth;int cx_min, cx_max, linesize, x_incr;uint32_t offset, fgcol, bgcol, v, cursor_offset;uint8_t *d1, *d, *src, *s1, *dest, *cursor_ptr;
@@ -1134,6 +1134,11 @@ static void vga_draw_text(VGAState *s, ireturn ; } + 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 || cw != s->last_cw || cheight != s->last_ch) { s->last_scr_width = width * cw;
@@ -1477,7 +1482,7 @@ void check_sse2(void)*/ static void vga_draw_graphic (VGAState *s,int full_update) { -int y1, y, update, linesize, y_start, double_scan, mask; +int y1, y, update, linesize, y_start, double_scan, mask, depth;int width, height, shift_control, line_offset, bwidth;ram_addr_t page0, page1;int disp_width, multi_scan, multi_run;
@@ -1551,6 +1556,11 @@ 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 (disp_width != s->last_width || height != s->last_height) {dpy_resize (s->ds, disp_width, height);
tools/ioemu/sdl.c +1 -0
@@ -499,6 +499,7 @@ void sdl_display_init(DisplayState *ds, ds->dpy_update = sdl_update; ds->dpy_resize = sdl_resize; ds->dpy_refresh = sdl_refresh; + ds->dpy_colourdepth =NULL ;sdl_resize (ds,640 ,400 );sdl_update_caption ();
tools/ioemu/vl.c +10 -0
@@ -146,6 +146,7 @@ int nographic;int nographic;int vncviewer;int vncunused; +int vncswitchbpp;const char * keyboard_layout =NULL ;int64_t ticks_per_sec;char *boot_device =NULL ;
@@ -4397,6 +4398,7 @@ void dumb_display_init(DisplayState *ds) ds->depth =0 ; ds->dpy_update = dumb_update; ds->dpy_resize = dumb_resize; + ds->dpy_colourdepth =NULL ; ds->dpy_refresh = dumb_refresh; }
@@ -6510,6 +6512,7 @@ void help(void)"-vnc display start a VNC server on display\n" "-vncviewer start a vncviewer process for this domain\n" "-vncunused bind the VNC server to an unused port\n" +"-vnc-switch-bpp VNC server closes connections when the guest OS changes colour depth\n" #ifndef _WIN32"-daemonize daemonize QEMU after initializing\n" #endif
@@ -6609,6 +6612,7 @@ enum { QEMU_OPTION_acpi, QEMU_OPTION_vncviewer, QEMU_OPTION_vncunused, + QEMU_OPTION_vncswitchbpp, QEMU_OPTION_pci, };
@@ -6692,6 +6696,7 @@ const QEMUOption qemu_options[] = { { "vnc", HAS_ARG, QEMU_OPTION_vnc }, { "vncviewer", 0, QEMU_OPTION_vncviewer }, { "vncunused", 0, QEMU_OPTION_vncunused }, + { "vnc-switch-bpp", 0, QEMU_OPTION_vncswitchbpp },/* temporary options */ { "usb", 0, QEMU_OPTION_usb },
@@ -7103,6 +7108,7 @@ int main(int argc, char **argv) nographic =0 ; vncviewer =0 ; vncunused =0 ; + vncswitchbpp =0 ; kernel_filename =NULL ; kernel_cmdline ="" ;#ifndef CONFIG_DM
@@ -7531,6 +7537,9 @@ int main(int argc, char **argv)case QEMU_OPTION_vncunused: vncunused++;break ; +case QEMU_OPTION_vncswitchbpp: + vncswitchbpp++; +break ;case QEMU_OPTION_pci: direct_pci = optarg;break ;
@@ -7755,6 +7764,7 @@ int main(int argc, char **argv) }else if (vnc_display !=NULL || vncunused !=0 ) {int vnc_display_port;char password[20 ]; + ds->switchbpp = vncswitchbpp;vnc_display_init (ds);xenstore_read_vncpasswd (domid, password,sizeof (password));vnc_display_password (ds, password);
tools/ioemu/vl.h +3 -0
@@ -912,8 +912,11 @@ struct DisplayState {int height;void *opaque; +int switchbpp; +void (*dpy_update)(struct DisplayState *s,int x,int y,int w,int h);void (*dpy_resize)(struct DisplayState *s,int w,int h); +void (*dpy_colourdepth)(struct DisplayState *s,int depth);void (*dpy_refresh)(struct DisplayState *s);void (*dpy_copy)(struct DisplayState *s,int src_x,int src_y,int dst_x,int dst_y,int w,int h); };
tools/ioemu/vnc.c +179 -72
369 lines not on this page · raw message
tools/ioemu/vnchextile.h +6 -6
@@ -2,29 +2,29 @@#define CONCAT (a, b) CONCAT_I(a, b)#define pixel_t CONCAT(uint, CONCAT(BPP, _t))#ifdef GENERIC -#define NAME generic +#define NAME CONCAT(generic_, BPP)#else #define NAME BPP#endif static void CONCAT (send_hextile_tile_ ,NAME )(VncState *vs,int x,int y,int w,int h, -uint32_t *last_bg32, -uint32_t *last_fg32, +void *last_bg_, +void *last_fg_,int *has_bg,int *has_fg) {uint8_t *row = (vs->ds->data + y * vs->ds->linesize + x * vs->depth);pixel_t *irow = (pixel_t *)row;int j, i; -pixel_t *last_bg = (pixel_t *)last_bg32; -pixel_t *last_fg = (pixel_t *)last_fg32; +pixel_t *last_bg = (pixel_t *)last_bg_; +pixel_t *last_fg = (pixel_t *)last_fg_;pixel_t bg =0 ;pixel_t fg =0 ;int n_colors =0 ;int bg_count =0 ;int fg_count =0 ;int flags =0 ; -uint8_t data[(sizeof (pixel_t) +2 ) *16 *16 ]; +uint8_t data[(vs->pix_bpp +2 ) *16 *16 ];int n_data =0 ;int n_subtiles =0 ;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 2 lines
The basic idea is that the vnc client is the one that should do the colour conversion, if necessary.
What impact, if any, does this have on the bandwidth required for the VNC connection? I've been using VNC to access HVM Xen clients over a 512k link lately and it's only barely acceptable. My color level is set to 'Low (64 Colors)'. If the client is doing the conversion then doesn't this mean that the server has to transmit 16/24/32 bits of color information to the client, rather than 6?
Or more likely, maybe I don't understand the implications of your patch :)
James
Quoted 10 lines · James Harper
Quoted 2 lines
The basic idea is that the vnc client is the one that should do the colour conversion, if necessary.
What impact, if any, does this have on the bandwidth required for the VNC connection? I've been using VNC to access HVM Xen clients over a 512k link lately and it's only barely acceptable. My color level is set to 'Low (64 Colors)'. If the client is doing the conversion then doesn't this mean that the server has to transmit 16/24/32 bits of color information to the client, rather than 6?
Quoted 3 lines
Or more likely, maybe I don't understand the implications of your patch :)
It is the opposite :)
Now most vnc clients run on 32 bpp display, so they automatically ask for 32 bpp connections to the server, even if the guest is using 16 bpp.
This is a waste of bandwidth.
Using my patch together with the right configuration of your vnc client you can just use the bandwidth needed to preserve the colour depth resolution of the guest and nothing more.
Quoted 13 lines · Stefano Stabellini
the qemu vnc server changes its internal colour depth based on the client request. This way just one colour conversion is done: the one in
vga_template.h, from the guest colour depth and the vnc server internal colour depth.This patch is meant to remove this colour conversion to improve performances. It accomplishes the goal making the qemu internal colour depth always the same as the guest colour depth.
The basic idea is that the vnc client is the one that should do the colour conversion, if necessary. In general it should accept the pixel format suggested by the server during the initial negotiation. This behaviour can be set in most vnc clients (vncviewer included).
Quoted 7 lines
If the guest changes colour depth, the qemu vnc server changes colour depth too and notifies the client. The problem is that the vnc protocol doesn't provide a message from the server to the client to ask for a colour depth change. So what I am doing is either:
1) quietly starting to do the conversion on vnc server (not gaining any performances here);
This should be the default behaviour
Quoted 2 lines
2) closing the vnc connection with the client, so the client can reconnect and choose the new pixel format.
This is evil. If we need a way to notify the client of colour depth changes, then we should define an official VNC extension for this that clients can implement. cf the desktop-resize extension
So, if the client supports the extension use that to notify, otherwise fallback to doing server-side conversions.
Quoted 2 lines
By default I am doing 1), however the second choice can be enabled passing the -vnc-switch-bpp command line option.
Don't add more command line options - the existing -vnc flag already has the ability to take multiple flags in the format:
-vnc hostname:display,flag,flag,flag,flag
eg
-vnc localhost:1,passwd,tls
Quoted 6 lines
A last note: to get most out of this patch it is best to set Windows to 16 bit colour depth, because the 24 bit mode is 24 bit depth and 24 bpp, meaning no alpha channel. The vnc protocol doesn't support 24 bpp, only 32 bpp, so this conversion is unavoidable.
Comments and critics are welcome.
Please send this to qemu-devel - we should not be introducing yet more xen-specific forks to the QEMU code we have - it is a maintainance disaster already with the number of patches we have.
Dan.
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
Quoted 11 lines · Daniel P. Berrange
Quoted 1 line
1) quietly starting to do the conversion on vnc server (not gaining any performances here);
This should be the default behaviour
Quoted 1 line
2) closing the vnc connection with the client, so the client can reconnect and choose the new pixel format.
This is evil. If we need a way to notify the client of colour depth
changes, then we should define an official VNC extension for this that clients can implement. cf the desktop-resize extensionSo, if the client supports the extension use that to notify, otherwise fallback to doing server-side conversions.
This is a good idea, I just hope it won't take ages to be accepted. I'll work on this.
Quoted 10 lines
Quoted 1 line
By default I am doing 1), however the second choice can be enabled passing the -vnc-switch-bpp command line option.
Don't add more command line options - the existing -vnc flag already has the ability to take multiple flags in the format:
-vnc hostname:display,flag,flag,flag,flag
eg
-vnc localhost:1,passwd,tls
another good suggestion, I'll modify the patch to use this.
Quoted 5 lines
Please send this to qemu-devel - we should not be introducing yet more xen-specific forks to the QEMU code we have - it is a maintainance disaster already with the number of patches we have.
Yeah I know, but sending patches to qemu-devel is like &>/dev/null
Quoted 13 lines · Stefano Stabellini
Quoted 12 lines · Daniel P. Berrange
Quoted 2 lines
1) quietly starting to do the conversion on vnc server (not gaining any performances here);
This should be the default behaviour
Quoted 2 lines
2) closing the vnc connection with the client, so the client can reconnect and choose the new pixel format.
This is evil. If we need a way to notify the client of colour depth changes, then we should define an official VNC extension for this that clients can implement. cf the desktop-resize extension
Quoted 5 lines
Quoted 2 lines
So, if the client supports the extension use that to notify, otherwise fallback to doing server-side conversions.
This is a good idea, I just hope it won't take ages to be accepted. I'll work on this.
There's not really any formal process for VNC extensions. You pretty much just post to the vnc mailing list & propose what you want to do and unless its absolutely insane you should get given a psuedo encoding number reasonably quickly.
Getting it implement in clients is more fun - but feel free to propose patches to the gtk-vnc mailing list - we aim to be broad compatability with as many servers as possible & are particularly interested in stuff that is useful to virtualization. Also send ideas for the protocol extension there & we can give feedback on how well it'll work from the client POV.
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
By default I am doing 1), however the second choice can be enabled passing the -vnc-switch-bpp command line option.
Don't add more command line options - the existing -vnc flag already has the ability to take multiple flags in the format:
Quoted 7 lines
Quoted 5 lines
-vnc hostname:display,flag,flag,flag,flag
eg
-vnc localhost:1,passwd,tls
another good suggestion, I'll modify the patch to use this.
Great, thanks.
Quoted 6 lines
Quoted 4 lines
Please send this to qemu-devel - we should not be introducing yet more xen-specific forks to the QEMU code we have - it is a maintainance disaster already with the number of patches we have.
Yeah I know, but sending patches to qemu-devel is like &>/dev/null
Yes it can be - you may not get it mereged quickly, but there are quite a few people who are knowledgable about the VNC server (who don't read xen-devel) & might give useful feedback.
Regards,
Dan.
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
Quoted 10 lines · Daniel P. Berrange
Quoted 4 lines · Stefano Stabellini
Quoted 2 lines
So, if the client supports the extension use that to notify, otherwise fallback to doing server-side conversions.
This is a good idea, I just hope it won't take ages to be accepted. I'll work on this.
There's not really any formal process for VNC extensions. You pretty much just post to the vnc mailing list & propose what you want to do and unless its absolutely insane you should get given a psuedo encoding number reasonably quickly.
We can use the existing space for gtk-vnc although VMware actually already has an extension to support server initiated pixel format changes. See http://wiki.multimedia.cx/index.php?title=VMNC
The extension is VMVi (display mode change). I would much rather just implement that in QEMU and in gtk-vnc.
This would also count in my mind as finally fixing SetPixelFormat since a client could rely on getting the DisplayModeChange message before the server starts using the new pixel format.
Quoted 6 lines
Getting it implement in clients is more fun - but feel free to propose patches to the gtk-vnc mailing list - we aim to be broad compatability with as many servers as possible & are particularly interested in stuff that is useful to virtualization. Also send ideas for the protocol extension there & we can give feedback on how well it'll work from the client POV.
Regards,
Anthony Liguori
Quoted 5 lines · Anthony Liguori
We can use the existing space for gtk-vnc although VMware actually already has an extension to support server initiated pixel format changes. See http://wiki.multimedia.cx/index.php?title=VMNC
The extension is VMVi (display mode change). I would much rather just implement that in QEMU and in gtk-vnc.
This would also count in my mind as finally fixing SetPixelFormat since a client could rely on getting the DisplayModeChange message before the server starts using the new pixel format.
I have given a look at WMVi: the message format is fine as it is identical to the PIXEL_FORMAT part of the ServerInit message. However I couldn't see the pseudo encoding number or any client side implementation.
I think they used WMVi as part of their format to record AVI videos and not as a VNC protocol extension.
We can use the message format they proposed, but we need also a proper pseudo encoding number. Then we'll send "DisplayModeChange" messages as 1 rectangle framebuffer updates.
Quoted 5 lines · Stefano Stabellini
Quoted 4 lines · Anthony Liguori
We can use the existing space for gtk-vnc although VMware actually already has an extension to support server initiated pixel format changes. See http://wiki.multimedia.cx/index.php?title=VMNC
The extension is VMVi (display mode change). I would much rather just implement that in QEMU and in gtk-vnc.
Quoted 8 lines
Quoted 1 line
This would also count in my mind as finally fixing SetPixelFormat since a client could rely on getting the DisplayModeChange message before the server starts using the new pixel format.
I have given a look at WMVi: the message format is fine as it is identical to the
PIXEL_FORMATpart of the ServerInit message. However I couldn't see the pseudo encoding number or any client side implementation.
I think they used WMVi as part of their format to record AVI videos and not as a VNC protocol extension.We can use the message format they proposed, but we need also a proper pseudo encoding number. Then we'll send "DisplayModeChange" messages as 1 rectangle framebuffer updates.
0x574D5669
The encoding number they use is 0x574D5669 and it is registered in the latest RFB spec.
Regards,
Anthony Liguori
Quoted 2 lines · Anthony Liguori
The encoding number they use is
0x574D5669and it is registered in the latest RFB spec.
Thanks for looking it up.
I'll post the updated patch soon.