Commit 29fa4ed9f00507e3056210b5e72447659d66b881

Authored by aliguori
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
@@ -98,10 +98,7 @@ struct VncState @@ -98,10 +98,7 @@ struct VncState
98 int need_update; 98 int need_update;
99 uint32_t dirty_row[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS]; 99 uint32_t dirty_row[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS];
100 char *old_data; 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 int absolute; 102 int absolute;
106 int last_x; 103 int last_x;
107 int last_y; 104 int last_y;
@@ -164,6 +161,10 @@ void do_info_vnc(void) @@ -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 /* TODO 168 /* TODO
168 1) Get the queue working for IO. 169 1) Get the queue working for IO.
169 2) there is some weirdness when using the -S option (the screen is grey 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,11 +278,12 @@ static void vnc_dpy_resize(DisplayState *ds)
277 ds_get_height(ds) != vs->serverds.height; 278 ds_get_height(ds) != vs->serverds.height;
278 vs->serverds = *(ds->surface); 279 vs->serverds = *(ds->surface);
279 if (size_changed) { 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 vnc_write_u8(vs, 0); /* msg id */ 282 vnc_write_u8(vs, 0); /* msg id */
282 vnc_write_u8(vs, 0); 283 vnc_write_u8(vs, 0);
283 vnc_write_u16(vs, 1); /* number of rects */ 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 vnc_flush(vs); 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,7 +380,7 @@ static void send_framebuffer_update_raw(VncState *vs, int x, int y, int w, int h
378 int i; 380 int i;
379 uint8_t *row; 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 row = ds_get_data(vs->ds) + y * ds_get_linesize(vs->ds) + x * ds_get_bytes_per_pixel(vs->ds); 385 row = ds_get_data(vs->ds) + y * ds_get_linesize(vs->ds) + x * ds_get_bytes_per_pixel(vs->ds);
384 for (i = 0; i < h; i++) { 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,7 +431,7 @@ static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, i
429 int has_fg, has_bg; 431 int has_fg, has_bg;
430 uint8_t *last_fg, *last_bg; 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 last_fg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel); 436 last_fg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel);
435 last_bg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel); 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,7 +450,7 @@ static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, i
448 450
449 static void send_framebuffer_update(VncState *vs, int x, int y, int w, int h) 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 send_framebuffer_update_hextile(vs, x, y, w, h); 454 send_framebuffer_update_hextile(vs, x, y, w, h);
453 else 455 else
454 send_framebuffer_update_raw(vs, x, y, w, h); 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,7 +465,7 @@ static void vnc_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int dst_
463 vnc_write_u8(vs, 0); /* msg id */ 465 vnc_write_u8(vs, 0); /* msg id */
464 vnc_write_u8(vs, 0); 466 vnc_write_u8(vs, 0);
465 vnc_write_u16(vs, 1); /* number of rects */ 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 vnc_write_u16(vs, src_x); 469 vnc_write_u16(vs, src_x);
468 vnc_write_u16(vs, src_y); 470 vnc_write_u16(vs, src_y);
469 vnc_flush(vs); 471 vnc_flush(vs);
@@ -919,12 +921,13 @@ static void client_cut_text(VncState *vs, size_t len, uint8_t *text) @@ -919,12 +921,13 @@ static void client_cut_text(VncState *vs, size_t len, uint8_t *text)
919 921
920 static void check_pointer_type_change(VncState *vs, int absolute) 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 vnc_write_u8(vs, 0); 925 vnc_write_u8(vs, 0);
924 vnc_write_u8(vs, 0); 926 vnc_write_u8(vs, 0);
925 vnc_write_u16(vs, 1); 927 vnc_write_u16(vs, 1);
926 vnc_framebuffer_update(vs, absolute, 0, 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 vnc_flush(vs); 931 vnc_flush(vs);
929 } 932 }
930 vs->absolute = absolute; 933 vs->absolute = absolute;
@@ -950,7 +953,7 @@ static void pointer_event(VncState *vs, int button_mask, int x, int y) @@ -950,7 +953,7 @@ static void pointer_event(VncState *vs, int button_mask, int x, int y)
950 kbd_mouse_event(x * 0x7FFF / (ds_get_width(vs->ds) - 1), 953 kbd_mouse_event(x * 0x7FFF / (ds_get_width(vs->ds) - 1),
951 y * 0x7FFF / (ds_get_height(vs->ds) - 1), 954 y * 0x7FFF / (ds_get_height(vs->ds) - 1),
952 dz, buttons); 955 dz, buttons);
953 - } else if (vs->has_pointer_type_change) { 956 + } else if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE)) {
954 x -= 0x7FFF; 957 x -= 0x7FFF;
955 y -= 0x7FFF; 958 y -= 0x7FFF;
956 959
@@ -1140,7 +1143,8 @@ static void send_ext_key_event_ack(VncState *vs) @@ -1140,7 +1143,8 @@ static void send_ext_key_event_ack(VncState *vs)
1140 vnc_write_u8(vs, 0); 1143 vnc_write_u8(vs, 0);
1141 vnc_write_u8(vs, 0); 1144 vnc_write_u8(vs, 0);
1142 vnc_write_u16(vs, 1); 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 vnc_flush(vs); 1148 vnc_flush(vs);
1145 } 1149 }
1146 1150
@@ -1149,50 +1153,50 @@ static void send_ext_audio_ack(VncState *vs) @@ -1149,50 +1153,50 @@ static void send_ext_audio_ack(VncState *vs)
1149 vnc_write_u8(vs, 0); 1153 vnc_write_u8(vs, 0);
1150 vnc_write_u8(vs, 0); 1154 vnc_write_u8(vs, 0);
1151 vnc_write_u16(vs, 1); 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 vnc_flush(vs); 1158 vnc_flush(vs);
1154 } 1159 }
1155 1160
1156 static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings) 1161 static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
1157 { 1162 {
1158 int i; 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 vs->absolute = -1; 1167 vs->absolute = -1;
1165 dcl->dpy_copy = NULL; 1168 dcl->dpy_copy = NULL;
1166 1169
1167 for (i = n_encodings - 1; i >= 0; i--) { 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 send_ext_key_event_ack(vs); 1188 send_ext_key_event_ack(vs);
1186 break; 1189 break;
1187 - case -259: 1190 + case VNC_ENCODING_AUDIO:
1188 send_ext_audio_ack(vs); 1191 send_ext_audio_ack(vs);
1189 break; 1192 break;
1190 - case 0x574D5669:  
1191 - vs->has_WMVi = 1; 1193 + case VNC_ENCODING_WMVi:
  1194 + vs->features |= VNC_FEATURE_WMVI_MASK;
1192 break; 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 check_pointer_type_change(vs, kbd_mouse_is_absolute()); 1202 check_pointer_type_change(vs, kbd_mouse_is_absolute());
@@ -1306,12 +1310,13 @@ static void vnc_colordepth(DisplayState *ds) @@ -1306,12 +1310,13 @@ static void vnc_colordepth(DisplayState *ds)
1306 { 1310 {
1307 struct VncState *vs = ds->opaque; 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 /* Sending a WMVi message to notify the client*/ 1314 /* Sending a WMVi message to notify the client*/
1311 vnc_write_u8(vs, 0); /* msg id */ 1315 vnc_write_u8(vs, 0); /* msg id */
1312 vnc_write_u8(vs, 0); 1316 vnc_write_u8(vs, 0);
1313 vnc_write_u16(vs, 1); /* number of rects */ 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 pixel_format_message(vs); 1320 pixel_format_message(vs);
1316 vnc_flush(vs); 1321 vnc_flush(vs);
1317 } else { 1322 } else {
@@ -2079,9 +2084,7 @@ static void vnc_connect(VncState *vs) @@ -2079,9 +2084,7 @@ static void vnc_connect(VncState *vs)
2079 vnc_read_when(vs, protocol_version, 12); 2084 vnc_read_when(vs, protocol_version, 12);
2080 memset(vs->old_data, 0, ds_get_linesize(vs->ds) * ds_get_height(vs->ds)); 2085 memset(vs->old_data, 0, ds_get_linesize(vs->ds) * ds_get_height(vs->ds));
2081 memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row)); 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 dcl->dpy_copy = NULL; 2088 dcl->dpy_copy = NULL;
2086 vnc_update_client(vs); 2089 vnc_update_client(vs);
2087 reset_keys(vs); 2090 reset_keys(vs);