Commit 29fa4ed9f00507e3056210b5e72447659d66b881
1 parent
e06679fb
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
Showing
1 changed file
with
50 additions
and
47 deletions
vnc.c
... | ... | @@ -98,10 +98,7 @@ struct VncState |
98 | 98 | int need_update; |
99 | 99 | uint32_t dirty_row[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS]; |
100 | 100 | char *old_data; |
101 | - int has_resize; | |
102 | - int has_hextile; | |
103 | - int has_pointer_type_change; | |
104 | - int has_WMVi; | |
101 | + uint32_t features; | |
105 | 102 | int absolute; |
106 | 103 | int last_x; |
107 | 104 | int last_y; |
... | ... | @@ -164,6 +161,10 @@ void do_info_vnc(void) |
164 | 161 | } |
165 | 162 | } |
166 | 163 | |
164 | +static inline uint32_t vnc_has_feature(VncState *vs, int feature) { | |
165 | + return (vs->features & (1 << feature)); | |
166 | +} | |
167 | + | |
167 | 168 | /* TODO |
168 | 169 | 1) Get the queue working for IO. |
169 | 170 | 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) |
277 | 278 | ds_get_height(ds) != vs->serverds.height; |
278 | 279 | vs->serverds = *(ds->surface); |
279 | 280 | if (size_changed) { |
280 | - if (vs->csock != -1 && vs->has_resize) { | |
281 | + if (vs->csock != -1 && vnc_has_feature(vs, VNC_FEATURE_RESIZE)) { | |
281 | 282 | vnc_write_u8(vs, 0); /* msg id */ |
282 | 283 | vnc_write_u8(vs, 0); |
283 | 284 | vnc_write_u16(vs, 1); /* number of rects */ |
284 | - vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds), -223); | |
285 | + vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds), | |
286 | + VNC_ENCODING_DESKTOPRESIZE); | |
285 | 287 | vnc_flush(vs); |
286 | 288 | } |
287 | 289 | } |
... | ... | @@ -378,7 +380,7 @@ static void send_framebuffer_update_raw(VncState *vs, int x, int y, int w, int h |
378 | 380 | int i; |
379 | 381 | uint8_t *row; |
380 | 382 | |
381 | - vnc_framebuffer_update(vs, x, y, w, h, 0); | |
383 | + vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_RAW); | |
382 | 384 | |
383 | 385 | row = ds_get_data(vs->ds) + y * ds_get_linesize(vs->ds) + x * ds_get_bytes_per_pixel(vs->ds); |
384 | 386 | 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 |
429 | 431 | int has_fg, has_bg; |
430 | 432 | uint8_t *last_fg, *last_bg; |
431 | 433 | |
432 | - vnc_framebuffer_update(vs, x, y, w, h, 5); | |
434 | + vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_HEXTILE); | |
433 | 435 | |
434 | 436 | last_fg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel); |
435 | 437 | 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 |
448 | 450 | |
449 | 451 | static void send_framebuffer_update(VncState *vs, int x, int y, int w, int h) |
450 | 452 | { |
451 | - if (vs->has_hextile) | |
453 | + if (vnc_has_feature(vs, VNC_FEATURE_HEXTILE)) | |
452 | 454 | send_framebuffer_update_hextile(vs, x, y, w, h); |
453 | 455 | else |
454 | 456 | 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_ |
463 | 465 | vnc_write_u8(vs, 0); /* msg id */ |
464 | 466 | vnc_write_u8(vs, 0); |
465 | 467 | vnc_write_u16(vs, 1); /* number of rects */ |
466 | - vnc_framebuffer_update(vs, dst_x, dst_y, w, h, 1); | |
468 | + vnc_framebuffer_update(vs, dst_x, dst_y, w, h, VNC_ENCODING_COPYRECT); | |
467 | 469 | vnc_write_u16(vs, src_x); |
468 | 470 | vnc_write_u16(vs, src_y); |
469 | 471 | vnc_flush(vs); |
... | ... | @@ -919,12 +921,13 @@ static void client_cut_text(VncState *vs, size_t len, uint8_t *text) |
919 | 921 | |
920 | 922 | static void check_pointer_type_change(VncState *vs, int absolute) |
921 | 923 | { |
922 | - if (vs->has_pointer_type_change && vs->absolute != absolute) { | |
924 | + if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE) && vs->absolute != absolute) { | |
923 | 925 | vnc_write_u8(vs, 0); |
924 | 926 | vnc_write_u8(vs, 0); |
925 | 927 | vnc_write_u16(vs, 1); |
926 | 928 | vnc_framebuffer_update(vs, absolute, 0, |
927 | - ds_get_width(vs->ds), ds_get_height(vs->ds), -257); | |
929 | + ds_get_width(vs->ds), ds_get_height(vs->ds), | |
930 | + VNC_ENCODING_POINTER_TYPE_CHANGE); | |
928 | 931 | vnc_flush(vs); |
929 | 932 | } |
930 | 933 | vs->absolute = absolute; |
... | ... | @@ -950,7 +953,7 @@ static void pointer_event(VncState *vs, int button_mask, int x, int y) |
950 | 953 | kbd_mouse_event(x * 0x7FFF / (ds_get_width(vs->ds) - 1), |
951 | 954 | y * 0x7FFF / (ds_get_height(vs->ds) - 1), |
952 | 955 | dz, buttons); |
953 | - } else if (vs->has_pointer_type_change) { | |
956 | + } else if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE)) { | |
954 | 957 | x -= 0x7FFF; |
955 | 958 | y -= 0x7FFF; |
956 | 959 | |
... | ... | @@ -1140,7 +1143,8 @@ static void send_ext_key_event_ack(VncState *vs) |
1140 | 1143 | vnc_write_u8(vs, 0); |
1141 | 1144 | vnc_write_u8(vs, 0); |
1142 | 1145 | vnc_write_u16(vs, 1); |
1143 | - vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds), -258); | |
1146 | + vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds), | |
1147 | + VNC_ENCODING_EXT_KEY_EVENT); | |
1144 | 1148 | vnc_flush(vs); |
1145 | 1149 | } |
1146 | 1150 | |
... | ... | @@ -1149,50 +1153,50 @@ static void send_ext_audio_ack(VncState *vs) |
1149 | 1153 | vnc_write_u8(vs, 0); |
1150 | 1154 | vnc_write_u8(vs, 0); |
1151 | 1155 | vnc_write_u16(vs, 1); |
1152 | - vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds), -259); | |
1156 | + vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds), | |
1157 | + VNC_ENCODING_AUDIO); | |
1153 | 1158 | vnc_flush(vs); |
1154 | 1159 | } |
1155 | 1160 | |
1156 | 1161 | static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings) |
1157 | 1162 | { |
1158 | 1163 | int i; |
1164 | + unsigned int enc = 0; | |
1159 | 1165 | |
1160 | - vs->has_hextile = 0; | |
1161 | - vs->has_resize = 0; | |
1162 | - vs->has_pointer_type_change = 0; | |
1163 | - vs->has_WMVi = 0; | |
1166 | + vs->features = 0; | |
1164 | 1167 | vs->absolute = -1; |
1165 | 1168 | dcl->dpy_copy = NULL; |
1166 | 1169 | |
1167 | 1170 | for (i = n_encodings - 1; i >= 0; i--) { |
1168 | - switch (encodings[i]) { | |
1169 | - case 0: /* Raw */ | |
1170 | - vs->has_hextile = 0; | |
1171 | - break; | |
1172 | - case 1: /* CopyRect */ | |
1173 | - dcl->dpy_copy = vnc_copy; | |
1174 | - break; | |
1175 | - case 5: /* Hextile */ | |
1176 | - vs->has_hextile = 1; | |
1177 | - break; | |
1178 | - case -223: /* DesktopResize */ | |
1179 | - vs->has_resize = 1; | |
1180 | - break; | |
1181 | - case -257: | |
1182 | - vs->has_pointer_type_change = 1; | |
1183 | - break; | |
1184 | - case -258: | |
1171 | + enc = encodings[i]; | |
1172 | + switch (enc) { | |
1173 | + case VNC_ENCODING_RAW: | |
1174 | + break; | |
1175 | + case VNC_ENCODING_COPYRECT: | |
1176 | + dcl->dpy_copy = vnc_copy; | |
1177 | + break; | |
1178 | + case VNC_ENCODING_HEXTILE: | |
1179 | + vs->features |= VNC_FEATURE_HEXTILE_MASK; | |
1180 | + break; | |
1181 | + case VNC_ENCODING_DESKTOPRESIZE: | |
1182 | + vs->features |= VNC_FEATURE_RESIZE_MASK; | |
1183 | + break; | |
1184 | + case VNC_ENCODING_POINTER_TYPE_CHANGE: | |
1185 | + vs->features |= VNC_FEATURE_POINTER_TYPE_CHANGE_MASK; | |
1186 | + break; | |
1187 | + case VNC_ENCODING_EXT_KEY_EVENT: | |
1185 | 1188 | send_ext_key_event_ack(vs); |
1186 | 1189 | break; |
1187 | - case -259: | |
1190 | + case VNC_ENCODING_AUDIO: | |
1188 | 1191 | send_ext_audio_ack(vs); |
1189 | 1192 | break; |
1190 | - case 0x574D5669: | |
1191 | - vs->has_WMVi = 1; | |
1193 | + case VNC_ENCODING_WMVi: | |
1194 | + vs->features |= VNC_FEATURE_WMVI_MASK; | |
1192 | 1195 | break; |
1193 | - default: | |
1194 | - break; | |
1195 | - } | |
1196 | + default: | |
1197 | + VNC_DEBUG("Unknown encoding: %d (0x%.8x): %d\n", i, enc, enc); | |
1198 | + break; | |
1199 | + } | |
1196 | 1200 | } |
1197 | 1201 | |
1198 | 1202 | check_pointer_type_change(vs, kbd_mouse_is_absolute()); |
... | ... | @@ -1306,12 +1310,13 @@ static void vnc_colordepth(DisplayState *ds) |
1306 | 1310 | { |
1307 | 1311 | struct VncState *vs = ds->opaque; |
1308 | 1312 | |
1309 | - if (vs->csock != -1 && vs->has_WMVi) { | |
1313 | + if (vs->csock != -1 && vnc_has_feature(vs, VNC_FEATURE_WMVI)) { | |
1310 | 1314 | /* Sending a WMVi message to notify the client*/ |
1311 | 1315 | vnc_write_u8(vs, 0); /* msg id */ |
1312 | 1316 | vnc_write_u8(vs, 0); |
1313 | 1317 | vnc_write_u16(vs, 1); /* number of rects */ |
1314 | - vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds), 0x574D5669); | |
1318 | + vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds), | |
1319 | + VNC_ENCODING_WMVi); | |
1315 | 1320 | pixel_format_message(vs); |
1316 | 1321 | vnc_flush(vs); |
1317 | 1322 | } else { |
... | ... | @@ -2079,9 +2084,7 @@ static void vnc_connect(VncState *vs) |
2079 | 2084 | vnc_read_when(vs, protocol_version, 12); |
2080 | 2085 | memset(vs->old_data, 0, ds_get_linesize(vs->ds) * ds_get_height(vs->ds)); |
2081 | 2086 | memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row)); |
2082 | - vs->has_resize = 0; | |
2083 | - vs->has_hextile = 0; | |
2084 | - vs->has_WMVi = 0; | |
2087 | + vs->features = 0; | |
2085 | 2088 | dcl->dpy_copy = NULL; |
2086 | 2089 | vnc_update_client(vs); |
2087 | 2090 | reset_keys(vs); | ... | ... |