ia64/xen-unstable

view tools/ioemu/patches/vnc-fixes @ 11569:317e8516d464

[qemu patches] Update patches for changeset 11561:c742b2ae920c.

Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
author Christian Limpach <Christian.Limpach@xensource.com>
date Thu Sep 21 19:28:35 2006 +0100 (2006-09-21)
parents a7dcafb540be
children 55ff34dceb0b
line source
1 Index: ioemu/vl.c
2 ===================================================================
3 --- ioemu.orig/vl.c 2006-09-21 19:08:18.000000000 +0100
4 +++ ioemu/vl.c 2006-09-21 19:26:24.000000000 +0100
5 @@ -6534,8 +6534,10 @@
6 }
7 }
9 - gui_timer = qemu_new_timer(rt_clock, gui_update, NULL);
10 - qemu_mod_timer(gui_timer, qemu_get_clock(rt_clock));
11 + if (vnc_display == -1) {
12 + gui_timer = qemu_new_timer(rt_clock, gui_update, NULL);
13 + qemu_mod_timer(gui_timer, qemu_get_clock(rt_clock));
14 + }
16 #ifdef CONFIG_GDBSTUB
17 if (use_gdbstub) {
18 Index: ioemu/vnc.c
19 ===================================================================
20 --- ioemu.orig/vnc.c 2006-09-21 19:08:18.000000000 +0100
21 +++ ioemu/vnc.c 2006-09-21 19:26:38.000000000 +0100
22 @@ -3,6 +3,7 @@
23 *
24 * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>
25 * Copyright (C) 2006 Fabrice Bellard
26 + * Copyright (C) 2006 Christian Limpach <Christian.Limpach@xensource.com>
27 *
28 * Permission is hereby granted, free of charge, to any person obtaining a copy
29 * of this software and associated documentation files (the "Software"), to deal
30 @@ -50,9 +51,11 @@
31 uint32_t *last_fg,
32 int *has_bg, int *has_fg);
34 +#if 0
35 #define VNC_MAX_WIDTH 2048
36 #define VNC_MAX_HEIGHT 2048
37 #define VNC_DIRTY_WORDS (VNC_MAX_WIDTH / (16 * 32))
38 +#endif
40 struct VncState
41 {
42 @@ -63,7 +66,11 @@
43 int need_update;
44 int width;
45 int height;
46 - uint32_t dirty_row[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS];
47 + uint64_t *dirty_row; /* screen regions which are possibly dirty */
48 + int dirty_pixel_shift;
49 + uint64_t *update_row; /* outstanding updates */
50 + int has_update; /* there's outstanding updates in the
51 + * visible area */
52 char *old_data;
53 int depth; /* internal VNC frame buffer byte per pixel */
54 int has_resize;
55 @@ -81,13 +88,25 @@
57 VncReadEvent *read_handler;
58 size_t read_handler_expect;
59 +
60 + int visible_x;
61 + int visible_y;
62 + int visible_w;
63 + int visible_h;
64 +
65 + int slow_client;
66 };
68 +#define DIRTY_PIXEL_BITS 64
69 +#define X2DP_DOWN(vs, x) ((x) >> (vs)->dirty_pixel_shift)
70 +#define X2DP_UP(vs, x) \
71 + (((x) + (1ULL << (vs)->dirty_pixel_shift) - 1) >> (vs)->dirty_pixel_shift)
72 +#define DP2X(vs, x) ((x) << (vs)->dirty_pixel_shift)
73 +
74 /* TODO
75 1) Get the queue working for IO.
76 2) there is some weirdness when using the -S option (the screen is grey
77 and not totally invalidated
78 - 3) resolutions > 1024
79 */
81 static void vnc_write(VncState *vs, const void *data, size_t len);
82 @@ -96,9 +115,12 @@
83 static void vnc_write_u16(VncState *vs, uint16_t value);
84 static void vnc_write_u8(VncState *vs, uint8_t value);
85 static void vnc_flush(VncState *vs);
86 +static void _vnc_update_client(void *opaque);
87 static void vnc_update_client(void *opaque);
88 static void vnc_client_read(void *opaque);
89 +static void framebuffer_set_updated(VncState *vs, int x, int y, int w, int h);
91 +#if 0
92 static inline void vnc_set_bit(uint32_t *d, int k)
93 {
94 d[k >> 5] |= 1 << (k & 0x1f);
95 @@ -139,20 +161,35 @@
96 }
97 return 0;
98 }
99 +#endif
101 -static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h)
102 +static void set_bits_in_row(VncState *vs, uint64_t *row,
103 + int x, int y, int w, int h)
104 {
105 - VncState *vs = ds->opaque;
106 + int x1, x2;
107 uint64_t mask;
109 - h += y;
110 - if (w != 1024)
111 - mask = ((1ULL << (w / 16)) - 1) << (x / 16);
112 + if (w == 0)
113 + return;
114 +
115 + x1 = X2DP_DOWN(vs, x);
116 + x2 = X2DP_UP(vs, x + w);
117 +
118 + if (X2DP_UP(vs, w) != DIRTY_PIXEL_BITS)
119 + mask = ((1ULL << (x2 - x1)) - 1) << x1;
120 else
121 mask = ~(0ULL);
123 + h += y;
124 for (; y < h; y++)
125 - vs->dirty_row[y] |= mask;
126 + row[y] |= mask;
127 +}
128 +
129 +static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h)
130 +{
131 + VncState *vs = ds->opaque;
132 +
133 + set_bits_in_row(vs, vs->dirty_row, x, y, w, h);
134 }
136 static void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
137 @@ -169,16 +206,23 @@
138 static void vnc_dpy_resize(DisplayState *ds, int w, int h)
139 {
140 VncState *vs = ds->opaque;
141 + int o;
143 ds->data = realloc(ds->data, w * h * vs->depth);
144 vs->old_data = realloc(vs->old_data, w * h * vs->depth);
145 + vs->dirty_row = realloc(vs->dirty_row, h * sizeof(vs->dirty_row[0]));
146 + vs->update_row = realloc(vs->update_row, h * sizeof(vs->dirty_row[0]));
148 - if (ds->data == NULL || vs->old_data == NULL) {
149 + if (ds->data == NULL || vs->old_data == NULL ||
150 + vs->dirty_row == NULL || vs->update_row == NULL) {
151 fprintf(stderr, "vnc: memory allocation failed\n");
152 exit(1);
153 }
155 - ds->depth = vs->depth * 8;
156 + if (ds->depth != vs->depth * 8) {
157 + ds->depth = vs->depth * 8;
158 + set_color_table(ds);
159 + }
160 ds->width = w;
161 ds->height = h;
162 ds->linesize = w * vs->depth;
163 @@ -191,6 +235,10 @@
164 vs->width = ds->width;
165 vs->height = ds->height;
166 }
167 + vs->dirty_pixel_shift = 0;
168 + for (o = DIRTY_PIXEL_BITS; o < ds->width; o *= 2)
169 + vs->dirty_pixel_shift++;
170 + framebuffer_set_updated(vs, 0, 0, ds->width, ds->height);
171 }
173 /* fastest code */
174 @@ -326,8 +374,20 @@
175 int y = 0;
176 int pitch = ds->linesize;
177 VncState *vs = ds->opaque;
178 + int updating_client = !vs->slow_client;
180 - vnc_update_client(vs);
181 + if (src_x < vs->visible_x || src_y < vs->visible_y ||
182 + dst_x < vs->visible_x || dst_y < vs->visible_y ||
183 + (src_x + w) > (vs->visible_x + vs->visible_w) ||
184 + (src_y + h) > (vs->visible_y + vs->visible_h) ||
185 + (dst_x + w) > (vs->visible_x + vs->visible_w) ||
186 + (dst_y + h) > (vs->visible_y + vs->visible_h))
187 + updating_client = 0;
188 +
189 + if (updating_client) {
190 + vs->need_update = 1;
191 + _vnc_update_client(vs);
192 + }
194 if (dst_y > src_y) {
195 y = h - 1;
196 @@ -349,31 +409,34 @@
197 old_row += pitch;
198 }
200 - vnc_write_u8(vs, 0); /* msg id */
201 - vnc_write_u8(vs, 0);
202 - vnc_write_u16(vs, 1); /* number of rects */
203 - vnc_framebuffer_update(vs, dst_x, dst_y, w, h, 1);
204 - vnc_write_u16(vs, src_x);
205 - vnc_write_u16(vs, src_y);
206 - vnc_flush(vs);
207 + if (updating_client && vs->csock != -1 && !vs->has_update) {
208 + vnc_write_u8(vs, 0); /* msg id */
209 + vnc_write_u8(vs, 0);
210 + vnc_write_u16(vs, 1); /* number of rects */
211 + vnc_framebuffer_update(vs, dst_x, dst_y, w, h, 1);
212 + vnc_write_u16(vs, src_x);
213 + vnc_write_u16(vs, src_y);
214 + vnc_flush(vs);
215 + } else
216 + framebuffer_set_updated(vs, dst_x, dst_y, w, h);
217 }
219 -static int find_dirty_height(VncState *vs, int y, int last_x, int x)
220 +static int find_update_height(VncState *vs, int y, int maxy, int last_x, int x)
221 {
222 int h;
224 - for (h = 1; h < (vs->height - y); h++) {
225 + for (h = 1; y + h < maxy; h++) {
226 int tmp_x;
227 - if (!vnc_get_bit(vs->dirty_row[y + h], last_x))
228 + if (!(vs->update_row[y + h] & (1ULL << last_x)))
229 break;
230 for (tmp_x = last_x; tmp_x < x; tmp_x++)
231 - vnc_clear_bit(vs->dirty_row[y + h], tmp_x);
232 + vs->update_row[y + h] &= ~(1ULL << tmp_x);
233 }
235 return h;
236 }
238 -static void vnc_update_client(void *opaque)
239 +static void _vnc_update_client(void *opaque)
240 {
241 VncState *vs = opaque;
242 int64_t now = qemu_get_clock(rt_clock);
243 @@ -382,14 +445,18 @@
244 int y;
245 char *row;
246 char *old_row;
247 - uint32_t width_mask[VNC_DIRTY_WORDS];
248 + uint64_t width_mask;
249 int n_rectangles;
250 int saved_offset;
251 - int has_dirty = 0;
252 + int maxx, maxy;
253 + int tile_bytes = vs->depth * DP2X(vs, 1);
255 qemu_mod_timer(vs->timer, now + VNC_REFRESH_INTERVAL);
257 - vnc_set_bits(width_mask, (vs->width / 16), VNC_DIRTY_WORDS);
258 + if (vs->width != DP2X(vs, DIRTY_PIXEL_BITS))
259 + width_mask = (1ULL << X2DP_UP(vs, vs->ds->width)) - 1;
260 + else
261 + width_mask = ~(0ULL);
263 /* Walk through the dirty map and eliminate tiles that
264 really aren't dirty */
265 @@ -397,23 +464,25 @@
266 old_row = vs->old_data;
268 for (y = 0; y < vs->ds->height; y++) {
269 - if (vnc_and_bits(vs->dirty_row[y], width_mask, VNC_DIRTY_WORDS)) {
270 + if (vs->dirty_row[y] & width_mask) {
271 int x;
272 char *ptr, *old_ptr;
274 ptr = row;
275 old_ptr = old_row;
277 - for (x = 0; x < vs->ds->width; x += 16) {
278 - if (memcmp(old_ptr, ptr, 16 * vs->depth) == 0) {
279 - vnc_clear_bit(vs->dirty_row[y], (x / 16));
280 - } else {
281 - has_dirty = 1;
282 - memcpy(old_ptr, ptr, 16 * vs->depth);
283 + for (x = 0; x < X2DP_UP(vs, vs->ds->width); x++) {
284 + if (vs->dirty_row[y] & (1ULL << x)) {
285 + if (memcmp(old_ptr, ptr, tile_bytes)) {
286 + vs->has_update = 1;
287 + vs->update_row[y] |= (1ULL << x);
288 + memcpy(old_ptr, ptr, tile_bytes);
289 + }
290 + vs->dirty_row[y] &= ~(1ULL << x);
291 }
293 - ptr += 16 * vs->depth;
294 - old_ptr += 16 * vs->depth;
295 + ptr += tile_bytes;
296 + old_ptr += tile_bytes;
297 }
298 }
300 @@ -421,7 +490,8 @@
301 old_row += vs->ds->linesize;
302 }
304 - if (!has_dirty)
305 + if (!vs->has_update || vs->visible_y >= vs->ds->height ||
306 + vs->visible_x >= vs->ds->width)
307 return;
309 /* Count rectangles */
310 @@ -431,34 +501,56 @@
311 saved_offset = vs->output.offset;
312 vnc_write_u16(vs, 0);
314 - for (y = 0; y < vs->height; y++) {
315 + maxy = vs->visible_y + vs->visible_h;
316 + if (maxy > vs->ds->height)
317 + maxy = vs->ds->height;
318 + maxx = vs->visible_x + vs->visible_w;
319 + if (maxx > vs->ds->width)
320 + maxx = vs->ds->width;
321 +
322 + for (y = vs->visible_y; y < maxy; y++) {
323 int x;
324 int last_x = -1;
325 - for (x = 0; x < vs->width / 16; x++) {
326 - if (vnc_get_bit(vs->dirty_row[y], x)) {
327 - if (last_x == -1) {
328 + for (x = X2DP_DOWN(vs, vs->visible_x);
329 + x < X2DP_UP(vs, maxx); x++) {
330 + if (vs->update_row[y] & (1ULL << x)) {
331 + if (last_x == -1)
332 last_x = x;
333 - }
334 - vnc_clear_bit(vs->dirty_row[y], x);
335 + vs->update_row[y] &= ~(1ULL << x);
336 } else {
337 if (last_x != -1) {
338 - int h = find_dirty_height(vs, y, last_x, x);
339 - send_framebuffer_update(vs, last_x * 16, y, (x - last_x) * 16, h);
340 + int h = find_update_height(vs, y, maxy, last_x, x);
341 + send_framebuffer_update(vs, DP2X(vs, last_x), y,
342 + DP2X(vs, (x - last_x)), h);
343 n_rectangles++;
344 }
345 last_x = -1;
346 }
347 }
348 if (last_x != -1) {
349 - int h = find_dirty_height(vs, y, last_x, x);
350 - send_framebuffer_update(vs, last_x * 16, y, (x - last_x) * 16, h);
351 + int h = find_update_height(vs, y, maxy, last_x, x);
352 + send_framebuffer_update(vs, DP2X(vs, last_x), y,
353 + DP2X(vs, (x - last_x)), h);
354 n_rectangles++;
355 }
356 }
357 vs->output.buffer[saved_offset] = (n_rectangles >> 8) & 0xFF;
358 vs->output.buffer[saved_offset + 1] = n_rectangles & 0xFF;
359 +
360 + vs->has_update = 0;
361 + vs->need_update = 0;
362 vnc_flush(vs);
363 - }
364 + vs->slow_client = 0;
365 + } else
366 + vs->slow_client = 1;
367 +}
368 +
369 +static void vnc_update_client(void *opaque)
370 +{
371 + VncState *vs = opaque;
372 +
373 + vs->ds->dpy_refresh(vs->ds);
374 + _vnc_update_client(vs);
375 }
377 static void vnc_timer_init(VncState *vs)
378 @@ -469,8 +561,6 @@
380 static void vnc_dpy_refresh(DisplayState *ds)
381 {
382 - VncState *vs = ds->opaque;
383 - vnc_timer_init(vs);
384 vga_hw_update();
385 }
387 @@ -506,7 +596,7 @@
389 static void buffer_reset(Buffer *buffer)
390 {
391 - buffer->offset = 0;
392 + buffer->offset = 0;
393 }
395 static void buffer_append(Buffer *buffer, const void *data, size_t len)
396 @@ -547,12 +637,12 @@
397 if (!ret)
398 return;
400 - memmove(vs->output.buffer, vs->output.buffer + ret, (vs->output.offset - ret));
401 + memmove(vs->output.buffer, vs->output.buffer + ret,
402 + vs->output.offset - ret);
403 vs->output.offset -= ret;
405 - if (vs->output.offset == 0) {
406 + if (vs->output.offset == 0)
407 qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
408 - }
409 }
411 static void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting)
412 @@ -584,11 +674,11 @@
413 return;
415 if (!ret) {
416 - memmove(vs->input.buffer, vs->input.buffer + len, (vs->input.offset - len));
417 + memmove(vs->input.buffer, vs->input.buffer + len,
418 + vs->input.offset - len);
419 vs->input.offset -= len;
420 - } else {
421 + } else
422 vs->read_handler_expect = ret;
423 - }
424 }
425 }
427 @@ -596,9 +686,9 @@
428 {
429 buffer_reserve(&vs->output, len);
431 - if (buffer_empty(&vs->output)) {
432 - qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, vnc_client_write, vs);
433 - }
434 + if (buffer_empty(&vs->output))
435 + qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read,
436 + vnc_client_write, vs);
438 buffer_append(&vs->output, data, len);
439 }
440 @@ -720,22 +810,25 @@
441 do_key_event(vs, down, sym);
442 }
444 +static void framebuffer_set_updated(VncState *vs, int x, int y, int w, int h)
445 +{
446 +
447 + set_bits_in_row(vs, vs->update_row, x, y, w, h);
448 +
449 + vs->has_update = 1;
450 +}
451 +
452 static void framebuffer_update_request(VncState *vs, int incremental,
453 int x_position, int y_position,
454 int w, int h)
455 {
456 - int i;
457 vs->need_update = 1;
458 - if (!incremental) {
459 - char *old_row = vs->old_data + y_position * vs->ds->linesize;
460 -
461 - for (i = 0; i < h; i++) {
462 - vnc_set_bits(vs->dirty_row[y_position + i],
463 - (vs->ds->width / 16), VNC_DIRTY_WORDS);
464 - memset(old_row, 42, vs->ds->width * vs->depth);
465 - old_row += vs->ds->linesize;
466 - }
467 - }
468 + if (!incremental)
469 + framebuffer_set_updated(vs, x_position, y_position, w, h);
470 + vs->visible_x = x_position;
471 + vs->visible_y = y_position;
472 + vs->visible_w = w;
473 + vs->visible_h = h;
475 qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock));
476 }
477 @@ -843,8 +936,6 @@
478 }
480 vnc_dpy_resize(vs->ds, vs->ds->width, vs->ds->height);
481 - memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row));
482 - memset(vs->old_data, 42, vs->ds->linesize * vs->ds->height);
484 vga_hw_invalidate();
485 vga_hw_update();
486 @@ -1010,11 +1101,11 @@
487 vnc_write(vs, "RFB 003.003\n", 12);
488 vnc_flush(vs);
489 vnc_read_when(vs, protocol_version, 12);
490 - memset(vs->old_data, 0, vs->ds->linesize * vs->ds->height);
491 - memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row));
492 + framebuffer_set_updated(vs, 0, 0, vs->ds->width, vs->ds->height);
493 vs->has_resize = 0;
494 vs->has_hextile = 0;
495 vs->ds->dpy_copy = NULL;
496 + vnc_timer_init(vs);
497 }
498 }
500 @@ -1071,17 +1162,15 @@
501 exit(1);
502 }
504 - ret = qemu_set_fd_handler2(vs->lsock, vnc_listen_poll, vnc_listen_read, NULL, vs);
505 - if (ret == -1) {
506 + ret = qemu_set_fd_handler2(vs->lsock, vnc_listen_poll, vnc_listen_read,
507 + NULL, vs);
508 + if (ret == -1)
509 exit(1);
510 - }
512 vs->ds->data = NULL;
513 vs->ds->dpy_update = vnc_dpy_update;
514 vs->ds->dpy_resize = vnc_dpy_resize;
515 vs->ds->dpy_refresh = vnc_dpy_refresh;
517 - memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row));
518 -
519 vnc_dpy_resize(vs->ds, 640, 400);
520 }
521 Index: ioemu/vl.h
522 ===================================================================
523 --- ioemu.orig/vl.h 2006-09-21 19:00:48.000000000 +0100
524 +++ ioemu/vl.h 2006-09-21 19:26:24.000000000 +0100
525 @@ -319,6 +319,7 @@
526 int is_graphic_console(void);
527 CharDriverState *text_console_init(DisplayState *ds);
528 void console_select(unsigned int index);
529 +void set_color_table(DisplayState *ds);
531 /* serial ports */