Use VNC protocol defines (Alexander Graf)

Now that we have nice defines for all sorts of constants, let's
use them!

This patch also takes the "feature variables", currently called has_*
into a single feature int. This way adding new features is a lot
easier and doesn't clutter the VncState struct.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6494 c046a42c-6fe2-441c-8c8c-71466251a162
master
aliguori 2009-02-02 15:58:29 +00:00
parent e06679fb76
commit 29fa4ed9f0
1 changed files with 50 additions and 47 deletions

97
vnc.c
View File

@ -98,10 +98,7 @@ struct VncState
int need_update;
uint32_t dirty_row[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS];
char *old_data;
int has_resize;
int has_hextile;
int has_pointer_type_change;
int has_WMVi;
uint32_t features;
int absolute;
int last_x;
int last_y;
@ -164,6 +161,10 @@ void do_info_vnc(void)
}
}
static inline uint32_t vnc_has_feature(VncState *vs, int feature) {
return (vs->features & (1 << feature));
}
/* TODO
1) Get the queue working for IO.
2) there is some weirdness when using the -S option (the screen is grey
@ -277,11 +278,12 @@ static void vnc_dpy_resize(DisplayState *ds)
ds_get_height(ds) != vs->serverds.height;
vs->serverds = *(ds->surface);
if (size_changed) {
if (vs->csock != -1 && vs->has_resize) {
if (vs->csock != -1 && vnc_has_feature(vs, VNC_FEATURE_RESIZE)) {
vnc_write_u8(vs, 0); /* msg id */
vnc_write_u8(vs, 0);
vnc_write_u16(vs, 1); /* number of rects */
vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds), -223);
vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds),
VNC_ENCODING_DESKTOPRESIZE);
vnc_flush(vs);
}
}
@ -378,7 +380,7 @@ static void send_framebuffer_update_raw(VncState *vs, int x, int y, int w, int h
int i;
uint8_t *row;
vnc_framebuffer_update(vs, x, y, w, h, 0);
vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_RAW);
row = ds_get_data(vs->ds) + y * ds_get_linesize(vs->ds) + x * ds_get_bytes_per_pixel(vs->ds);
for (i = 0; i < h; i++) {
@ -429,7 +431,7 @@ static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, i
int has_fg, has_bg;
uint8_t *last_fg, *last_bg;
vnc_framebuffer_update(vs, x, y, w, h, 5);
vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_HEXTILE);
last_fg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel);
last_bg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel);
@ -448,7 +450,7 @@ static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, i
static void send_framebuffer_update(VncState *vs, int x, int y, int w, int h)
{
if (vs->has_hextile)
if (vnc_has_feature(vs, VNC_FEATURE_HEXTILE))
send_framebuffer_update_hextile(vs, x, y, w, h);
else
send_framebuffer_update_raw(vs, x, y, w, h);
@ -463,7 +465,7 @@ static void vnc_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int dst_
vnc_write_u8(vs, 0); /* msg id */
vnc_write_u8(vs, 0);
vnc_write_u16(vs, 1); /* number of rects */
vnc_framebuffer_update(vs, dst_x, dst_y, w, h, 1);
vnc_framebuffer_update(vs, dst_x, dst_y, w, h, VNC_ENCODING_COPYRECT);
vnc_write_u16(vs, src_x);
vnc_write_u16(vs, src_y);
vnc_flush(vs);
@ -919,12 +921,13 @@ static void client_cut_text(VncState *vs, size_t len, uint8_t *text)
static void check_pointer_type_change(VncState *vs, int absolute)
{
if (vs->has_pointer_type_change && vs->absolute != absolute) {
if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE) && vs->absolute != absolute) {
vnc_write_u8(vs, 0);
vnc_write_u8(vs, 0);
vnc_write_u16(vs, 1);
vnc_framebuffer_update(vs, absolute, 0,
ds_get_width(vs->ds), ds_get_height(vs->ds), -257);
ds_get_width(vs->ds), ds_get_height(vs->ds),
VNC_ENCODING_POINTER_TYPE_CHANGE);
vnc_flush(vs);
}
vs->absolute = absolute;
@ -950,7 +953,7 @@ static void pointer_event(VncState *vs, int button_mask, int x, int y)
kbd_mouse_event(x * 0x7FFF / (ds_get_width(vs->ds) - 1),
y * 0x7FFF / (ds_get_height(vs->ds) - 1),
dz, buttons);
} else if (vs->has_pointer_type_change) {
} else if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE)) {
x -= 0x7FFF;
y -= 0x7FFF;
@ -1140,7 +1143,8 @@ static void send_ext_key_event_ack(VncState *vs)
vnc_write_u8(vs, 0);
vnc_write_u8(vs, 0);
vnc_write_u16(vs, 1);
vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds), -258);
vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds),
VNC_ENCODING_EXT_KEY_EVENT);
vnc_flush(vs);
}
@ -1149,50 +1153,50 @@ static void send_ext_audio_ack(VncState *vs)
vnc_write_u8(vs, 0);
vnc_write_u8(vs, 0);
vnc_write_u16(vs, 1);
vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds), -259);
vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds),
VNC_ENCODING_AUDIO);
vnc_flush(vs);
}
static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
{
int i;
unsigned int enc = 0;
vs->has_hextile = 0;
vs->has_resize = 0;
vs->has_pointer_type_change = 0;
vs->has_WMVi = 0;
vs->features = 0;
vs->absolute = -1;
dcl->dpy_copy = NULL;
for (i = n_encodings - 1; i >= 0; i--) {
switch (encodings[i]) {
case 0: /* Raw */
vs->has_hextile = 0;
break;
case 1: /* CopyRect */
dcl->dpy_copy = vnc_copy;
break;
case 5: /* Hextile */
vs->has_hextile = 1;
break;
case -223: /* DesktopResize */
vs->has_resize = 1;
break;
case -257:
vs->has_pointer_type_change = 1;
break;
case -258:
enc = encodings[i];
switch (enc) {
case VNC_ENCODING_RAW:
break;
case VNC_ENCODING_COPYRECT:
dcl->dpy_copy = vnc_copy;
break;
case VNC_ENCODING_HEXTILE:
vs->features |= VNC_FEATURE_HEXTILE_MASK;
break;
case VNC_ENCODING_DESKTOPRESIZE:
vs->features |= VNC_FEATURE_RESIZE_MASK;
break;
case VNC_ENCODING_POINTER_TYPE_CHANGE:
vs->features |= VNC_FEATURE_POINTER_TYPE_CHANGE_MASK;
break;
case VNC_ENCODING_EXT_KEY_EVENT:
send_ext_key_event_ack(vs);
break;
case -259:
case VNC_ENCODING_AUDIO:
send_ext_audio_ack(vs);
break;
case 0x574D5669:
vs->has_WMVi = 1;
case VNC_ENCODING_WMVi:
vs->features |= VNC_FEATURE_WMVI_MASK;
break;
default:
break;
}
default:
VNC_DEBUG("Unknown encoding: %d (0x%.8x): %d\n", i, enc, enc);
break;
}
}
check_pointer_type_change(vs, kbd_mouse_is_absolute());
@ -1306,12 +1310,13 @@ static void vnc_colordepth(DisplayState *ds)
{
struct VncState *vs = ds->opaque;
if (vs->csock != -1 && vs->has_WMVi) {
if (vs->csock != -1 && vnc_has_feature(vs, VNC_FEATURE_WMVI)) {
/* Sending a WMVi message to notify the client*/
vnc_write_u8(vs, 0); /* msg id */
vnc_write_u8(vs, 0);
vnc_write_u16(vs, 1); /* number of rects */
vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds), 0x574D5669);
vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds),
VNC_ENCODING_WMVi);
pixel_format_message(vs);
vnc_flush(vs);
} else {
@ -2079,9 +2084,7 @@ static void vnc_connect(VncState *vs)
vnc_read_when(vs, protocol_version, 12);
memset(vs->old_data, 0, ds_get_linesize(vs->ds) * ds_get_height(vs->ds));
memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row));
vs->has_resize = 0;
vs->has_hextile = 0;
vs->has_WMVi = 0;
vs->features = 0;
dcl->dpy_copy = NULL;
vnc_update_client(vs);
reset_keys(vs);