ia64/xen-unstable

view tools/ioemu/patches/vnc-fixes @ 10803:42aa63188a88

IA64-specific code for new Qemu
Due to some ia64 patches aren't checked into xen-unstable.hg.
I reversed related logic.

Signed-off-by: Zhang xiantao <xiantao.zhang@intel.com>
Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
author chris@kneesaa.uk.xensource.com
date Wed Jul 26 13:41:10 2006 +0100 (2006-07-26)
parents ccf11affc545
children 060025203f54
line source
1 Index: ioemu/vl.c
2 ===================================================================
3 --- ioemu.orig/vl.c 2006-07-26 13:39:18.439320475 +0100
4 +++ ioemu/vl.c 2006-07-26 13:39:18.499314057 +0100
5 @@ -6003,8 +6003,10 @@
6 kernel_filename, kernel_cmdline, initrd_filename,
7 timeoffset);
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-07-26 13:39:18.437320689 +0100
21 +++ ioemu/vnc.c 2006-07-26 13:39:18.500313950 +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 @@ -51,7 +52,11 @@
31 int need_update;
32 int width;
33 int height;
34 - uint64_t dirty_row[768];
35 + uint64_t *dirty_row; /* screen regions which are possibly dirty */
36 + int dirty_pixel_shift;
37 + uint64_t *update_row; /* outstanding updates */
38 + int has_update; /* there's outstanding updates in the
39 + * visible area */
40 char *old_data;
41 int depth;
42 int has_resize;
43 @@ -62,13 +67,25 @@
45 VncReadEvent *read_handler;
46 size_t read_handler_expect;
47 +
48 + int visible_x;
49 + int visible_y;
50 + int visible_w;
51 + int visible_h;
52 +
53 + int slow_client;
54 };
56 +#define DIRTY_PIXEL_BITS 64
57 +#define X2DP_DOWN(vs, x) ((x) >> (vs)->dirty_pixel_shift)
58 +#define X2DP_UP(vs, x) \
59 + (((x) + (1ULL << (vs)->dirty_pixel_shift) - 1) >> (vs)->dirty_pixel_shift)
60 +#define DP2X(vs, x) ((x) << (vs)->dirty_pixel_shift)
61 +
62 /* TODO
63 1) Get the queue working for IO.
64 2) there is some weirdness when using the -S option (the screen is grey
65 and not totally invalidated
66 - 3) resolutions > 1024
67 */
69 static void vnc_write(VncState *vs, const void *data, size_t len);
70 @@ -77,22 +94,38 @@
71 static void vnc_write_u16(VncState *vs, uint16_t value);
72 static void vnc_write_u8(VncState *vs, uint8_t value);
73 static void vnc_flush(VncState *vs);
74 +static void _vnc_update_client(void *opaque);
75 static void vnc_update_client(void *opaque);
76 static void vnc_client_read(void *opaque);
77 +static void framebuffer_set_updated(VncState *vs, int x, int y, int w, int h);
79 -static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h)
80 +static void set_bits_in_row(VncState *vs, uint64_t *row,
81 + int x, int y, int w, int h)
82 {
83 - VncState *vs = ds->opaque;
84 + int x1, x2;
85 uint64_t mask;
87 - h += y;
88 - if (w != 1024)
89 - mask = ((1ULL << (w / 16)) - 1) << (x / 16);
90 + if (w == 0)
91 + return;
92 +
93 + x1 = X2DP_DOWN(vs, x);
94 + x2 = X2DP_UP(vs, x + w);
95 +
96 + if (X2DP_UP(vs, w) != DIRTY_PIXEL_BITS)
97 + mask = ((1ULL << (x2 - x1)) - 1) << x1;
98 else
99 mask = ~(0ULL);
101 + h += y;
102 for (; y < h; y++)
103 - vs->dirty_row[y] |= mask;
104 + row[y] |= mask;
105 +}
106 +
107 +static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h)
108 +{
109 + VncState *vs = ds->opaque;
110 +
111 + set_bits_in_row(vs, vs->dirty_row, x, y, w, h);
112 }
114 static void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
115 @@ -109,11 +142,15 @@
116 static void vnc_dpy_resize(DisplayState *ds, int w, int h)
117 {
118 VncState *vs = ds->opaque;
119 + int o;
121 ds->data = realloc(ds->data, w * h * vs->depth);
122 vs->old_data = realloc(vs->old_data, w * h * vs->depth);
123 + vs->dirty_row = realloc(vs->dirty_row, h * sizeof(vs->dirty_row[0]));
124 + vs->update_row = realloc(vs->update_row, h * sizeof(vs->dirty_row[0]));
126 - if (ds->data == NULL || vs->old_data == NULL) {
127 + if (ds->data == NULL || vs->old_data == NULL ||
128 + vs->dirty_row == NULL || vs->update_row == NULL) {
129 fprintf(stderr, "vnc: memory allocation failed\n");
130 exit(1);
131 }
132 @@ -131,6 +168,10 @@
133 vs->width = ds->width;
134 vs->height = ds->height;
135 }
136 + vs->dirty_pixel_shift = 0;
137 + for (o = DIRTY_PIXEL_BITS; o < ds->width; o *= 2)
138 + vs->dirty_pixel_shift++;
139 + framebuffer_set_updated(vs, 0, 0, ds->width, ds->height);
140 }
142 static void send_framebuffer_update_raw(VncState *vs, int x, int y, int w, int h)
143 @@ -215,8 +256,20 @@
144 int y = 0;
145 int pitch = ds->linesize;
146 VncState *vs = ds->opaque;
147 + int updating_client = !vs->slow_client;
149 - vnc_update_client(vs);
150 + if (src_x < vs->visible_x || src_y < vs->visible_y ||
151 + dst_x < vs->visible_x || dst_y < vs->visible_y ||
152 + (src_x + w) > (vs->visible_x + vs->visible_w) ||
153 + (src_y + h) > (vs->visible_y + vs->visible_h) ||
154 + (dst_x + w) > (vs->visible_x + vs->visible_w) ||
155 + (dst_y + h) > (vs->visible_y + vs->visible_h))
156 + updating_client = 0;
157 +
158 + if (updating_client) {
159 + vs->need_update = 1;
160 + _vnc_update_client(vs);
161 + }
163 if (dst_y > src_y) {
164 y = h - 1;
165 @@ -238,31 +291,34 @@
166 old_row += pitch;
167 }
169 - vnc_write_u8(vs, 0); /* msg id */
170 - vnc_write_u8(vs, 0);
171 - vnc_write_u16(vs, 1); /* number of rects */
172 - vnc_framebuffer_update(vs, dst_x, dst_y, w, h, 1);
173 - vnc_write_u16(vs, src_x);
174 - vnc_write_u16(vs, src_y);
175 - vnc_flush(vs);
176 + if (updating_client && vs->csock != -1 && !vs->has_update) {
177 + vnc_write_u8(vs, 0); /* msg id */
178 + vnc_write_u8(vs, 0);
179 + vnc_write_u16(vs, 1); /* number of rects */
180 + vnc_framebuffer_update(vs, dst_x, dst_y, w, h, 1);
181 + vnc_write_u16(vs, src_x);
182 + vnc_write_u16(vs, src_y);
183 + vnc_flush(vs);
184 + } else
185 + framebuffer_set_updated(vs, dst_x, dst_y, w, h);
186 }
188 -static int find_dirty_height(VncState *vs, int y, int last_x, int x)
189 +static int find_update_height(VncState *vs, int y, int maxy, int last_x, int x)
190 {
191 int h;
193 - for (h = 1; h < (vs->height - y); h++) {
194 + for (h = 1; y + h < maxy; h++) {
195 int tmp_x;
196 - if (!(vs->dirty_row[y + h] & (1ULL << last_x)))
197 + if (!(vs->update_row[y + h] & (1ULL << last_x)))
198 break;
199 for (tmp_x = last_x; tmp_x < x; tmp_x++)
200 - vs->dirty_row[y + h] &= ~(1ULL << tmp_x);
201 + vs->update_row[y + h] &= ~(1ULL << tmp_x);
202 }
204 return h;
205 }
207 -static void vnc_update_client(void *opaque)
208 +static void _vnc_update_client(void *opaque)
209 {
210 VncState *vs = opaque;
211 int64_t now = qemu_get_clock(rt_clock);
212 @@ -274,11 +330,12 @@
213 uint64_t width_mask;
214 int n_rectangles;
215 int saved_offset;
216 - int has_dirty = 0;
217 + int maxx, maxy;
218 + int tile_bytes = vs->depth * DP2X(vs, 1);
220 - width_mask = (1ULL << (vs->width / 16)) - 1;
221 -
222 - if (vs->width == 1024)
223 + if (vs->width != DP2X(vs, DIRTY_PIXEL_BITS))
224 + width_mask = (1ULL << X2DP_UP(vs, vs->ds->width)) - 1;
225 + else
226 width_mask = ~(0ULL);
228 /* Walk through the dirty map and eliminate tiles that
229 @@ -294,16 +351,18 @@
230 ptr = row;
231 old_ptr = old_row;
233 - for (x = 0; x < vs->ds->width; x += 16) {
234 - if (memcmp(old_ptr, ptr, 16 * vs->depth) == 0) {
235 - vs->dirty_row[y] &= ~(1ULL << (x / 16));
236 - } else {
237 - has_dirty = 1;
238 - memcpy(old_ptr, ptr, 16 * vs->depth);
239 + for (x = 0; x < X2DP_UP(vs, vs->ds->width); x++) {
240 + if (vs->dirty_row[y] & (1ULL << x)) {
241 + if (memcmp(old_ptr, ptr, tile_bytes)) {
242 + vs->has_update = 1;
243 + vs->update_row[y] |= (1ULL << x);
244 + memcpy(old_ptr, ptr, tile_bytes);
245 + }
246 + vs->dirty_row[y] &= ~(1ULL << x);
247 }
249 - ptr += 16 * vs->depth;
250 - old_ptr += 16 * vs->depth;
251 + ptr += tile_bytes;
252 + old_ptr += tile_bytes;
253 }
254 }
256 @@ -311,7 +370,8 @@
257 old_row += vs->ds->linesize;
258 }
260 - if (!has_dirty)
261 + if (!vs->has_update || vs->visible_y >= vs->ds->height ||
262 + vs->visible_x >= vs->ds->width)
263 goto out;
265 /* Count rectangles */
266 @@ -321,40 +381,61 @@
267 saved_offset = vs->output.offset;
268 vnc_write_u16(vs, 0);
270 - for (y = 0; y < vs->height; y++) {
271 + maxy = vs->visible_y + vs->visible_h;
272 + if (maxy > vs->ds->height)
273 + maxy = vs->ds->height;
274 + maxx = vs->visible_x + vs->visible_w;
275 + if (maxx > vs->ds->width)
276 + maxx = vs->ds->width;
277 +
278 + for (y = vs->visible_y; y < maxy; y++) {
279 int x;
280 int last_x = -1;
281 - for (x = 0; x < vs->width / 16; x++) {
282 - if (vs->dirty_row[y] & (1ULL << x)) {
283 - if (last_x == -1) {
284 + for (x = X2DP_DOWN(vs, vs->visible_x);
285 + x < X2DP_UP(vs, maxx); x++) {
286 + if (vs->update_row[y] & (1ULL << x)) {
287 + if (last_x == -1)
288 last_x = x;
289 - }
290 - vs->dirty_row[y] &= ~(1ULL << x);
291 + vs->update_row[y] &= ~(1ULL << x);
292 } else {
293 if (last_x != -1) {
294 - int h = find_dirty_height(vs, y, last_x, x);
295 - send_framebuffer_update(vs, last_x * 16, y, (x - last_x) * 16, h);
296 + int h = find_update_height(vs, y, maxy, last_x, x);
297 + send_framebuffer_update(vs, DP2X(vs, last_x), y,
298 + DP2X(vs, (x - last_x)), h);
299 n_rectangles++;
300 }
301 last_x = -1;
302 }
303 }
304 if (last_x != -1) {
305 - int h = find_dirty_height(vs, y, last_x, x);
306 - send_framebuffer_update(vs, last_x * 16, y, (x - last_x) * 16, h);
307 + int h = find_update_height(vs, y, maxy, last_x, x);
308 + send_framebuffer_update(vs, DP2X(vs, last_x), y,
309 + DP2X(vs, (x - last_x)), h);
310 n_rectangles++;
311 }
312 }
313 vs->output.buffer[saved_offset] = (n_rectangles >> 8) & 0xFF;
314 vs->output.buffer[saved_offset + 1] = n_rectangles & 0xFF;
315 - vnc_flush(vs);
317 - }
318 + vs->has_update = 0;
319 + vs->need_update = 0;
320 + vnc_flush(vs);
321 + vs->slow_client = 0;
322 + } else
323 + vs->slow_client = 1;
325 out:
326 qemu_mod_timer(vs->timer, now + VNC_REFRESH_INTERVAL);
327 }
329 +static void vnc_update_client(void *opaque)
330 +{
331 + VncState *vs = opaque;
332 +
333 + vs->ds->dpy_refresh(vs->ds);
334 + _vnc_update_client(vs);
335 +}
336 +
337 static void vnc_timer_init(VncState *vs)
338 {
339 if (vs->timer == NULL) {
340 @@ -365,8 +446,6 @@
342 static void vnc_dpy_refresh(DisplayState *ds)
343 {
344 - VncState *vs = ds->opaque;
345 - vnc_timer_init(vs);
346 vga_hw_update();
347 }
349 @@ -402,7 +481,7 @@
351 static void buffer_reset(Buffer *buffer)
352 {
353 - buffer->offset = 0;
354 + buffer->offset = 0;
355 }
357 static void buffer_append(Buffer *buffer, const void *data, size_t len)
358 @@ -443,12 +522,12 @@
359 if (!ret)
360 return;
362 - memmove(vs->output.buffer, vs->output.buffer + ret, (vs->output.offset - ret));
363 + memmove(vs->output.buffer, vs->output.buffer + ret,
364 + vs->output.offset - ret);
365 vs->output.offset -= ret;
367 - if (vs->output.offset == 0) {
368 + if (vs->output.offset == 0)
369 qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
370 - }
371 }
373 static void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting)
374 @@ -480,11 +559,11 @@
375 return;
377 if (!ret) {
378 - memmove(vs->input.buffer, vs->input.buffer + len, (vs->input.offset - len));
379 + memmove(vs->input.buffer, vs->input.buffer + len,
380 + vs->input.offset - len);
381 vs->input.offset -= len;
382 - } else {
383 + } else
384 vs->read_handler_expect = ret;
385 - }
386 }
387 }
389 @@ -492,9 +571,9 @@
390 {
391 buffer_reserve(&vs->output, len);
393 - if (buffer_empty(&vs->output)) {
394 - qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, vnc_client_write, vs);
395 - }
396 + if (buffer_empty(&vs->output))
397 + qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read,
398 + vnc_client_write, vs);
400 buffer_append(&vs->output, data, len);
401 }
402 @@ -616,24 +695,25 @@
403 do_key_event(vs, down, sym);
404 }
406 +static void framebuffer_set_updated(VncState *vs, int x, int y, int w, int h)
407 +{
408 +
409 + set_bits_in_row(vs, vs->update_row, x, y, w, h);
410 +
411 + vs->has_update = 1;
412 +}
413 +
414 static void framebuffer_update_request(VncState *vs, int incremental,
415 int x_position, int y_position,
416 int w, int h)
417 {
418 - int i;
419 vs->need_update = 1;
420 - if (!incremental) {
421 - char *old_row = vs->old_data + y_position * vs->ds->linesize;
422 -
423 - for (i = 0; i < h; i++) {
424 - vs->dirty_row[y_position + i] = (1ULL << (vs->ds->width / 16)) - 1;
425 - if (vs->ds->width == 1024) {
426 - vs->dirty_row[y_position + i] = ~(0ULL);
427 - }
428 - memset(old_row, 42, vs->ds->width * vs->depth);
429 - old_row += vs->ds->linesize;
430 - }
431 - }
432 + if (!incremental)
433 + framebuffer_set_updated(vs, x_position, y_position, w, h);
434 + vs->visible_x = x_position;
435 + vs->visible_y = y_position;
436 + vs->visible_w = w;
437 + vs->visible_h = h;
438 }
440 static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
441 @@ -690,8 +770,6 @@
442 vnc_client_error(vs);
444 vnc_dpy_resize(vs->ds, vs->ds->width, vs->ds->height);
445 - memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row));
446 - memset(vs->old_data, 42, vs->ds->linesize * vs->ds->height);
448 vga_hw_invalidate();
449 vga_hw_update();
450 @@ -848,11 +926,11 @@
451 vnc_write(vs, "RFB 003.003\n", 12);
452 vnc_flush(vs);
453 vnc_read_when(vs, protocol_version, 12);
454 - memset(vs->old_data, 0, vs->ds->linesize * vs->ds->height);
455 - memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row));
456 + framebuffer_set_updated(vs, 0, 0, vs->ds->width, vs->ds->height);
457 vs->has_resize = 0;
458 vs->has_hextile = 0;
459 vs->ds->dpy_copy = NULL;
460 + vnc_timer_init(vs);
461 }
462 }
464 @@ -909,17 +987,15 @@
465 exit(1);
466 }
468 - ret = qemu_set_fd_handler2(vs->lsock, vnc_listen_poll, vnc_listen_read, NULL, vs);
469 - if (ret == -1) {
470 + ret = qemu_set_fd_handler2(vs->lsock, vnc_listen_poll, vnc_listen_read,
471 + NULL, vs);
472 + if (ret == -1)
473 exit(1);
474 - }
476 vs->ds->data = NULL;
477 vs->ds->dpy_update = vnc_dpy_update;
478 vs->ds->dpy_resize = vnc_dpy_resize;
479 vs->ds->dpy_refresh = vnc_dpy_refresh;
481 - memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row));
482 -
483 vnc_dpy_resize(vs->ds, 640, 400);
484 }