root / vnc.c @ 6f15b608
History | View | Annotate | Download (29 kB)
1 | 7d510b8c | bellard | /*
|
---|---|---|---|
2 | 7d510b8c | bellard | * QEMU VNC display driver
|
3 | 7d510b8c | bellard | *
|
4 | 7d510b8c | bellard | * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>
|
5 | 7d510b8c | bellard | * Copyright (C) 2006 Fabrice Bellard
|
6 | 7d510b8c | bellard | *
|
7 | 7d510b8c | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
8 | 7d510b8c | bellard | * of this software and associated documentation files (the "Software"), to deal
|
9 | 7d510b8c | bellard | * in the Software without restriction, including without limitation the rights
|
10 | 7d510b8c | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 | 7d510b8c | bellard | * copies of the Software, and to permit persons to whom the Software is
|
12 | 7d510b8c | bellard | * furnished to do so, subject to the following conditions:
|
13 | 7d510b8c | bellard | *
|
14 | 7d510b8c | bellard | * The above copyright notice and this permission notice shall be included in
|
15 | 7d510b8c | bellard | * all copies or substantial portions of the Software.
|
16 | 7d510b8c | bellard | *
|
17 | 7d510b8c | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18 | 7d510b8c | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19 | 7d510b8c | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
20 | 7d510b8c | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21 | 7d510b8c | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22 | 7d510b8c | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23 | 7d510b8c | bellard | * THE SOFTWARE.
|
24 | 7d510b8c | bellard | */
|
25 | 7d510b8c | bellard | |
26 | 24236869 | bellard | #include "vl.h" |
27 | 6ca957f0 | bellard | #include "qemu_socket.h" |
28 | 24236869 | bellard | |
29 | 24236869 | bellard | #define VNC_REFRESH_INTERVAL (1000 / 30) |
30 | 24236869 | bellard | |
31 | 24236869 | bellard | #include "vnc_keysym.h" |
32 | 24236869 | bellard | #include "keymaps.c" |
33 | 24236869 | bellard | |
34 | 24236869 | bellard | typedef struct Buffer |
35 | 24236869 | bellard | { |
36 | 24236869 | bellard | size_t capacity; |
37 | 24236869 | bellard | size_t offset; |
38 | 24236869 | bellard | char *buffer;
|
39 | 24236869 | bellard | } Buffer; |
40 | 24236869 | bellard | |
41 | 24236869 | bellard | typedef struct VncState VncState; |
42 | 24236869 | bellard | |
43 | 24236869 | bellard | typedef int VncReadEvent(VncState *vs, char *data, size_t len); |
44 | 24236869 | bellard | |
45 | 3512779a | bellard | typedef void VncWritePixels(VncState *vs, void *data, int size); |
46 | 3512779a | bellard | |
47 | 3512779a | bellard | typedef void VncSendHextileTile(VncState *vs, |
48 | 3512779a | bellard | int x, int y, int w, int h, |
49 | 3512779a | bellard | uint32_t *last_bg, |
50 | 3512779a | bellard | uint32_t *last_fg, |
51 | 3512779a | bellard | int *has_bg, int *has_fg); |
52 | 3512779a | bellard | |
53 | 99589bdc | bellard | #define VNC_MAX_WIDTH 2048 |
54 | 99589bdc | bellard | #define VNC_MAX_HEIGHT 2048 |
55 | 99589bdc | bellard | #define VNC_DIRTY_WORDS (VNC_MAX_WIDTH / (16 * 32)) |
56 | 99589bdc | bellard | |
57 | 24236869 | bellard | struct VncState
|
58 | 24236869 | bellard | { |
59 | 24236869 | bellard | QEMUTimer *timer; |
60 | 24236869 | bellard | int lsock;
|
61 | 24236869 | bellard | int csock;
|
62 | 24236869 | bellard | DisplayState *ds; |
63 | 24236869 | bellard | int need_update;
|
64 | 24236869 | bellard | int width;
|
65 | 24236869 | bellard | int height;
|
66 | 99589bdc | bellard | uint32_t dirty_row[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS]; |
67 | 24236869 | bellard | char *old_data;
|
68 | 3512779a | bellard | int depth; /* internal VNC frame buffer byte per pixel */ |
69 | 24236869 | bellard | int has_resize;
|
70 | 24236869 | bellard | int has_hextile;
|
71 | 24236869 | bellard | Buffer output; |
72 | 24236869 | bellard | Buffer input; |
73 | 24236869 | bellard | kbd_layout_t *kbd_layout; |
74 | 3512779a | bellard | /* current output mode information */
|
75 | 3512779a | bellard | VncWritePixels *write_pixels; |
76 | 3512779a | bellard | VncSendHextileTile *send_hextile_tile; |
77 | 3512779a | bellard | int pix_bpp, pix_big_endian;
|
78 | 3512779a | bellard | int red_shift, red_max, red_shift1;
|
79 | 3512779a | bellard | int green_shift, green_max, green_shift1;
|
80 | 3512779a | bellard | int blue_shift, blue_max, blue_shift1;
|
81 | 24236869 | bellard | |
82 | 24236869 | bellard | VncReadEvent *read_handler; |
83 | 24236869 | bellard | size_t read_handler_expect; |
84 | 64f5a135 | bellard | /* input */
|
85 | 64f5a135 | bellard | uint8_t modifiers_state[256];
|
86 | 24236869 | bellard | }; |
87 | 24236869 | bellard | |
88 | 24236869 | bellard | /* TODO
|
89 | 24236869 | bellard | 1) Get the queue working for IO.
|
90 | 24236869 | bellard | 2) there is some weirdness when using the -S option (the screen is grey
|
91 | 24236869 | bellard | and not totally invalidated
|
92 | 24236869 | bellard | 3) resolutions > 1024
|
93 | 24236869 | bellard | */
|
94 | 24236869 | bellard | |
95 | 24236869 | bellard | static void vnc_write(VncState *vs, const void *data, size_t len); |
96 | 24236869 | bellard | static void vnc_write_u32(VncState *vs, uint32_t value); |
97 | 24236869 | bellard | static void vnc_write_s32(VncState *vs, int32_t value); |
98 | 24236869 | bellard | static void vnc_write_u16(VncState *vs, uint16_t value); |
99 | 24236869 | bellard | static void vnc_write_u8(VncState *vs, uint8_t value); |
100 | 24236869 | bellard | static void vnc_flush(VncState *vs); |
101 | 24236869 | bellard | static void vnc_update_client(void *opaque); |
102 | 24236869 | bellard | static void vnc_client_read(void *opaque); |
103 | 24236869 | bellard | |
104 | 99589bdc | bellard | static inline void vnc_set_bit(uint32_t *d, int k) |
105 | 99589bdc | bellard | { |
106 | 99589bdc | bellard | d[k >> 5] |= 1 << (k & 0x1f); |
107 | 99589bdc | bellard | } |
108 | 99589bdc | bellard | |
109 | 99589bdc | bellard | static inline void vnc_clear_bit(uint32_t *d, int k) |
110 | 99589bdc | bellard | { |
111 | 99589bdc | bellard | d[k >> 5] &= ~(1 << (k & 0x1f)); |
112 | 99589bdc | bellard | } |
113 | 99589bdc | bellard | |
114 | 99589bdc | bellard | static inline void vnc_set_bits(uint32_t *d, int n, int nb_words) |
115 | 99589bdc | bellard | { |
116 | 99589bdc | bellard | int j;
|
117 | 99589bdc | bellard | |
118 | 99589bdc | bellard | j = 0;
|
119 | 99589bdc | bellard | while (n >= 32) { |
120 | 99589bdc | bellard | d[j++] = -1;
|
121 | 99589bdc | bellard | n -= 32;
|
122 | 99589bdc | bellard | } |
123 | 99589bdc | bellard | if (n > 0) |
124 | 99589bdc | bellard | d[j++] = (1 << n) - 1; |
125 | 99589bdc | bellard | while (j < nb_words)
|
126 | 99589bdc | bellard | d[j++] = 0;
|
127 | 99589bdc | bellard | } |
128 | 99589bdc | bellard | |
129 | 99589bdc | bellard | static inline int vnc_get_bit(const uint32_t *d, int k) |
130 | 99589bdc | bellard | { |
131 | 99589bdc | bellard | return (d[k >> 5] >> (k & 0x1f)) & 1; |
132 | 99589bdc | bellard | } |
133 | 99589bdc | bellard | |
134 | 99589bdc | bellard | static inline int vnc_and_bits(const uint32_t *d1, const uint32_t *d2, |
135 | 99589bdc | bellard | int nb_words)
|
136 | 99589bdc | bellard | { |
137 | 99589bdc | bellard | int i;
|
138 | 99589bdc | bellard | for(i = 0; i < nb_words; i++) { |
139 | 99589bdc | bellard | if ((d1[i] & d2[i]) != 0) |
140 | 99589bdc | bellard | return 1; |
141 | 99589bdc | bellard | } |
142 | 99589bdc | bellard | return 0; |
143 | 99589bdc | bellard | } |
144 | 99589bdc | bellard | |
145 | 24236869 | bellard | static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h) |
146 | 24236869 | bellard | { |
147 | 24236869 | bellard | VncState *vs = ds->opaque; |
148 | 24236869 | bellard | int i;
|
149 | 24236869 | bellard | |
150 | 24236869 | bellard | h += y; |
151 | 24236869 | bellard | |
152 | 24236869 | bellard | for (; y < h; y++)
|
153 | 24236869 | bellard | for (i = 0; i < w; i += 16) |
154 | 99589bdc | bellard | vnc_set_bit(vs->dirty_row[y], (x + i) / 16);
|
155 | 24236869 | bellard | } |
156 | 24236869 | bellard | |
157 | 24236869 | bellard | static void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h, |
158 | 24236869 | bellard | int32_t encoding) |
159 | 24236869 | bellard | { |
160 | 24236869 | bellard | vnc_write_u16(vs, x); |
161 | 24236869 | bellard | vnc_write_u16(vs, y); |
162 | 24236869 | bellard | vnc_write_u16(vs, w); |
163 | 24236869 | bellard | vnc_write_u16(vs, h); |
164 | 24236869 | bellard | |
165 | 24236869 | bellard | vnc_write_s32(vs, encoding); |
166 | 24236869 | bellard | } |
167 | 24236869 | bellard | |
168 | 24236869 | bellard | static void vnc_dpy_resize(DisplayState *ds, int w, int h) |
169 | 24236869 | bellard | { |
170 | 24236869 | bellard | VncState *vs = ds->opaque; |
171 | 24236869 | bellard | |
172 | 24236869 | bellard | ds->data = realloc(ds->data, w * h * vs->depth); |
173 | 24236869 | bellard | vs->old_data = realloc(vs->old_data, w * h * vs->depth); |
174 | 24236869 | bellard | |
175 | 24236869 | bellard | if (ds->data == NULL || vs->old_data == NULL) { |
176 | 24236869 | bellard | fprintf(stderr, "vnc: memory allocation failed\n");
|
177 | 24236869 | bellard | exit(1);
|
178 | 24236869 | bellard | } |
179 | 24236869 | bellard | |
180 | 24236869 | bellard | ds->depth = vs->depth * 8;
|
181 | 24236869 | bellard | ds->width = w; |
182 | 24236869 | bellard | ds->height = h; |
183 | 24236869 | bellard | ds->linesize = w * vs->depth; |
184 | 24236869 | bellard | if (vs->csock != -1 && vs->has_resize) { |
185 | 24236869 | bellard | vnc_write_u8(vs, 0); /* msg id */ |
186 | 24236869 | bellard | vnc_write_u8(vs, 0);
|
187 | 24236869 | bellard | vnc_write_u16(vs, 1); /* number of rects */ |
188 | 24236869 | bellard | vnc_framebuffer_update(vs, 0, 0, ds->width, ds->height, -223); |
189 | 24236869 | bellard | vnc_flush(vs); |
190 | 24236869 | bellard | vs->width = ds->width; |
191 | 24236869 | bellard | vs->height = ds->height; |
192 | 24236869 | bellard | } |
193 | 24236869 | bellard | } |
194 | 24236869 | bellard | |
195 | 3512779a | bellard | /* fastest code */
|
196 | 3512779a | bellard | static void vnc_write_pixels_copy(VncState *vs, void *pixels, int size) |
197 | 3512779a | bellard | { |
198 | 3512779a | bellard | vnc_write(vs, pixels, size); |
199 | 3512779a | bellard | } |
200 | 3512779a | bellard | |
201 | 3512779a | bellard | /* slowest but generic code. */
|
202 | 3512779a | bellard | static void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v) |
203 | 3512779a | bellard | { |
204 | 3512779a | bellard | unsigned int r, g, b; |
205 | 3512779a | bellard | |
206 | 3512779a | bellard | r = (v >> vs->red_shift1) & vs->red_max; |
207 | 3512779a | bellard | g = (v >> vs->green_shift1) & vs->green_max; |
208 | 3512779a | bellard | b = (v >> vs->blue_shift1) & vs->blue_max; |
209 | 3512779a | bellard | v = (r << vs->red_shift) | |
210 | 3512779a | bellard | (g << vs->green_shift) | |
211 | 3512779a | bellard | (b << vs->blue_shift); |
212 | 3512779a | bellard | switch(vs->pix_bpp) {
|
213 | 3512779a | bellard | case 1: |
214 | 3512779a | bellard | buf[0] = v;
|
215 | 3512779a | bellard | break;
|
216 | 3512779a | bellard | case 2: |
217 | 3512779a | bellard | if (vs->pix_big_endian) {
|
218 | 3512779a | bellard | buf[0] = v >> 8; |
219 | 3512779a | bellard | buf[1] = v;
|
220 | 3512779a | bellard | } else {
|
221 | 3512779a | bellard | buf[1] = v >> 8; |
222 | 3512779a | bellard | buf[0] = v;
|
223 | 3512779a | bellard | } |
224 | 3512779a | bellard | break;
|
225 | 3512779a | bellard | default:
|
226 | 3512779a | bellard | case 4: |
227 | 3512779a | bellard | if (vs->pix_big_endian) {
|
228 | 3512779a | bellard | buf[0] = v >> 24; |
229 | 3512779a | bellard | buf[1] = v >> 16; |
230 | 3512779a | bellard | buf[2] = v >> 8; |
231 | 3512779a | bellard | buf[3] = v;
|
232 | 3512779a | bellard | } else {
|
233 | 3512779a | bellard | buf[3] = v >> 24; |
234 | 3512779a | bellard | buf[2] = v >> 16; |
235 | 3512779a | bellard | buf[1] = v >> 8; |
236 | 3512779a | bellard | buf[0] = v;
|
237 | 3512779a | bellard | } |
238 | 3512779a | bellard | break;
|
239 | 3512779a | bellard | } |
240 | 3512779a | bellard | } |
241 | 3512779a | bellard | |
242 | 3512779a | bellard | static void vnc_write_pixels_generic(VncState *vs, void *pixels1, int size) |
243 | 3512779a | bellard | { |
244 | 3512779a | bellard | uint32_t *pixels = pixels1; |
245 | 3512779a | bellard | uint8_t buf[4];
|
246 | 3512779a | bellard | int n, i;
|
247 | 3512779a | bellard | |
248 | 3512779a | bellard | n = size >> 2;
|
249 | 3512779a | bellard | for(i = 0; i < n; i++) { |
250 | 3512779a | bellard | vnc_convert_pixel(vs, buf, pixels[i]); |
251 | 3512779a | bellard | vnc_write(vs, buf, vs->pix_bpp); |
252 | 3512779a | bellard | } |
253 | 3512779a | bellard | } |
254 | 3512779a | bellard | |
255 | 24236869 | bellard | static void send_framebuffer_update_raw(VncState *vs, int x, int y, int w, int h) |
256 | 24236869 | bellard | { |
257 | 24236869 | bellard | int i;
|
258 | 24236869 | bellard | char *row;
|
259 | 24236869 | bellard | |
260 | 24236869 | bellard | vnc_framebuffer_update(vs, x, y, w, h, 0);
|
261 | 24236869 | bellard | |
262 | 24236869 | bellard | row = vs->ds->data + y * vs->ds->linesize + x * vs->depth; |
263 | 24236869 | bellard | for (i = 0; i < h; i++) { |
264 | 3512779a | bellard | vs->write_pixels(vs, row, w * vs->depth); |
265 | 24236869 | bellard | row += vs->ds->linesize; |
266 | 24236869 | bellard | } |
267 | 24236869 | bellard | } |
268 | 24236869 | bellard | |
269 | 24236869 | bellard | static void hextile_enc_cord(uint8_t *ptr, int x, int y, int w, int h) |
270 | 24236869 | bellard | { |
271 | 24236869 | bellard | ptr[0] = ((x & 0x0F) << 4) | (y & 0x0F); |
272 | 24236869 | bellard | ptr[1] = (((w - 1) & 0x0F) << 4) | ((h - 1) & 0x0F); |
273 | 24236869 | bellard | } |
274 | 24236869 | bellard | |
275 | 24236869 | bellard | #define BPP 8 |
276 | 24236869 | bellard | #include "vnchextile.h" |
277 | 24236869 | bellard | #undef BPP
|
278 | 24236869 | bellard | |
279 | 24236869 | bellard | #define BPP 16 |
280 | 24236869 | bellard | #include "vnchextile.h" |
281 | 24236869 | bellard | #undef BPP
|
282 | 24236869 | bellard | |
283 | 24236869 | bellard | #define BPP 32 |
284 | 24236869 | bellard | #include "vnchextile.h" |
285 | 24236869 | bellard | #undef BPP
|
286 | 24236869 | bellard | |
287 | 3512779a | bellard | #define GENERIC
|
288 | 3512779a | bellard | #define BPP 32 |
289 | 3512779a | bellard | #include "vnchextile.h" |
290 | 3512779a | bellard | #undef BPP
|
291 | 3512779a | bellard | #undef GENERIC
|
292 | 3512779a | bellard | |
293 | 24236869 | bellard | static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, int h) |
294 | 24236869 | bellard | { |
295 | 24236869 | bellard | int i, j;
|
296 | 24236869 | bellard | int has_fg, has_bg;
|
297 | 24236869 | bellard | uint32_t last_fg32, last_bg32; |
298 | 24236869 | bellard | |
299 | 24236869 | bellard | vnc_framebuffer_update(vs, x, y, w, h, 5);
|
300 | 24236869 | bellard | |
301 | 24236869 | bellard | has_fg = has_bg = 0;
|
302 | 24236869 | bellard | for (j = y; j < (y + h); j += 16) { |
303 | 24236869 | bellard | for (i = x; i < (x + w); i += 16) { |
304 | 3512779a | bellard | vs->send_hextile_tile(vs, i, j, |
305 | 3512779a | bellard | MIN(16, x + w - i), MIN(16, y + h - j), |
306 | 3512779a | bellard | &last_bg32, &last_fg32, &has_bg, &has_fg); |
307 | 24236869 | bellard | } |
308 | 24236869 | bellard | } |
309 | 24236869 | bellard | } |
310 | 24236869 | bellard | |
311 | 24236869 | bellard | static void send_framebuffer_update(VncState *vs, int x, int y, int w, int h) |
312 | 24236869 | bellard | { |
313 | 24236869 | bellard | if (vs->has_hextile)
|
314 | 24236869 | bellard | send_framebuffer_update_hextile(vs, x, y, w, h); |
315 | 24236869 | bellard | else
|
316 | 24236869 | bellard | send_framebuffer_update_raw(vs, x, y, w, h); |
317 | 24236869 | bellard | } |
318 | 24236869 | bellard | |
319 | 24236869 | bellard | static void vnc_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int dst_y, int w, int h) |
320 | 24236869 | bellard | { |
321 | 24236869 | bellard | int src, dst;
|
322 | 24236869 | bellard | char *src_row;
|
323 | 24236869 | bellard | char *dst_row;
|
324 | 24236869 | bellard | char *old_row;
|
325 | 24236869 | bellard | int y = 0; |
326 | 24236869 | bellard | int pitch = ds->linesize;
|
327 | 24236869 | bellard | VncState *vs = ds->opaque; |
328 | 24236869 | bellard | |
329 | 24236869 | bellard | vnc_update_client(vs); |
330 | 24236869 | bellard | |
331 | 24236869 | bellard | if (dst_y > src_y) {
|
332 | 24236869 | bellard | y = h - 1;
|
333 | 24236869 | bellard | pitch = -pitch; |
334 | 24236869 | bellard | } |
335 | 24236869 | bellard | |
336 | 24236869 | bellard | src = (ds->linesize * (src_y + y) + vs->depth * src_x); |
337 | 24236869 | bellard | dst = (ds->linesize * (dst_y + y) + vs->depth * dst_x); |
338 | 24236869 | bellard | |
339 | 24236869 | bellard | src_row = ds->data + src; |
340 | 24236869 | bellard | dst_row = ds->data + dst; |
341 | 24236869 | bellard | old_row = vs->old_data + dst; |
342 | 24236869 | bellard | |
343 | 24236869 | bellard | for (y = 0; y < h; y++) { |
344 | 24236869 | bellard | memmove(old_row, src_row, w * vs->depth); |
345 | 24236869 | bellard | memmove(dst_row, src_row, w * vs->depth); |
346 | 24236869 | bellard | src_row += pitch; |
347 | 24236869 | bellard | dst_row += pitch; |
348 | 24236869 | bellard | old_row += pitch; |
349 | 24236869 | bellard | } |
350 | 24236869 | bellard | |
351 | 24236869 | bellard | vnc_write_u8(vs, 0); /* msg id */ |
352 | 24236869 | bellard | vnc_write_u8(vs, 0);
|
353 | 24236869 | bellard | vnc_write_u16(vs, 1); /* number of rects */ |
354 | 24236869 | bellard | vnc_framebuffer_update(vs, dst_x, dst_y, w, h, 1);
|
355 | 24236869 | bellard | vnc_write_u16(vs, src_x); |
356 | 24236869 | bellard | vnc_write_u16(vs, src_y); |
357 | 24236869 | bellard | vnc_flush(vs); |
358 | 24236869 | bellard | } |
359 | 24236869 | bellard | |
360 | 24236869 | bellard | static int find_dirty_height(VncState *vs, int y, int last_x, int x) |
361 | 24236869 | bellard | { |
362 | 24236869 | bellard | int h;
|
363 | 24236869 | bellard | |
364 | 24236869 | bellard | for (h = 1; h < (vs->height - y); h++) { |
365 | 24236869 | bellard | int tmp_x;
|
366 | 99589bdc | bellard | if (!vnc_get_bit(vs->dirty_row[y + h], last_x))
|
367 | 24236869 | bellard | break;
|
368 | 24236869 | bellard | for (tmp_x = last_x; tmp_x < x; tmp_x++)
|
369 | 99589bdc | bellard | vnc_clear_bit(vs->dirty_row[y + h], tmp_x); |
370 | 24236869 | bellard | } |
371 | 24236869 | bellard | |
372 | 24236869 | bellard | return h;
|
373 | 24236869 | bellard | } |
374 | 24236869 | bellard | |
375 | 24236869 | bellard | static void vnc_update_client(void *opaque) |
376 | 24236869 | bellard | { |
377 | 24236869 | bellard | VncState *vs = opaque; |
378 | 24236869 | bellard | |
379 | 24236869 | bellard | if (vs->need_update && vs->csock != -1) { |
380 | 24236869 | bellard | int y;
|
381 | 24236869 | bellard | char *row;
|
382 | 24236869 | bellard | char *old_row;
|
383 | 99589bdc | bellard | uint32_t width_mask[VNC_DIRTY_WORDS]; |
384 | 24236869 | bellard | int n_rectangles;
|
385 | 24236869 | bellard | int saved_offset;
|
386 | 24236869 | bellard | int has_dirty = 0; |
387 | 24236869 | bellard | |
388 | 99589bdc | bellard | vnc_set_bits(width_mask, (vs->width / 16), VNC_DIRTY_WORDS);
|
389 | 24236869 | bellard | |
390 | 24236869 | bellard | /* Walk through the dirty map and eliminate tiles that
|
391 | 24236869 | bellard | really aren't dirty */
|
392 | 24236869 | bellard | row = vs->ds->data; |
393 | 24236869 | bellard | old_row = vs->old_data; |
394 | 24236869 | bellard | |
395 | 24236869 | bellard | for (y = 0; y < vs->height; y++) { |
396 | 99589bdc | bellard | if (vnc_and_bits(vs->dirty_row[y], width_mask, VNC_DIRTY_WORDS)) {
|
397 | 24236869 | bellard | int x;
|
398 | 24236869 | bellard | char *ptr, *old_ptr;
|
399 | 24236869 | bellard | |
400 | 24236869 | bellard | ptr = row; |
401 | 24236869 | bellard | old_ptr = old_row; |
402 | 24236869 | bellard | |
403 | 24236869 | bellard | for (x = 0; x < vs->ds->width; x += 16) { |
404 | 24236869 | bellard | if (memcmp(old_ptr, ptr, 16 * vs->depth) == 0) { |
405 | 99589bdc | bellard | vnc_clear_bit(vs->dirty_row[y], (x / 16));
|
406 | 24236869 | bellard | } else {
|
407 | 24236869 | bellard | has_dirty = 1;
|
408 | 24236869 | bellard | memcpy(old_ptr, ptr, 16 * vs->depth);
|
409 | 24236869 | bellard | } |
410 | 24236869 | bellard | |
411 | 24236869 | bellard | ptr += 16 * vs->depth;
|
412 | 24236869 | bellard | old_ptr += 16 * vs->depth;
|
413 | 24236869 | bellard | } |
414 | 24236869 | bellard | } |
415 | 24236869 | bellard | |
416 | 24236869 | bellard | row += vs->ds->linesize; |
417 | 24236869 | bellard | old_row += vs->ds->linesize; |
418 | 24236869 | bellard | } |
419 | 24236869 | bellard | |
420 | 24236869 | bellard | if (!has_dirty) {
|
421 | 24236869 | bellard | qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock) + VNC_REFRESH_INTERVAL); |
422 | 24236869 | bellard | return;
|
423 | 24236869 | bellard | } |
424 | 24236869 | bellard | |
425 | 24236869 | bellard | /* Count rectangles */
|
426 | 24236869 | bellard | n_rectangles = 0;
|
427 | 24236869 | bellard | vnc_write_u8(vs, 0); /* msg id */ |
428 | 24236869 | bellard | vnc_write_u8(vs, 0);
|
429 | 24236869 | bellard | saved_offset = vs->output.offset; |
430 | 24236869 | bellard | vnc_write_u16(vs, 0);
|
431 | 24236869 | bellard | |
432 | 24236869 | bellard | for (y = 0; y < vs->height; y++) { |
433 | 24236869 | bellard | int x;
|
434 | 24236869 | bellard | int last_x = -1; |
435 | 24236869 | bellard | for (x = 0; x < vs->width / 16; x++) { |
436 | 99589bdc | bellard | if (vnc_get_bit(vs->dirty_row[y], x)) {
|
437 | 24236869 | bellard | if (last_x == -1) { |
438 | 24236869 | bellard | last_x = x; |
439 | 24236869 | bellard | } |
440 | 99589bdc | bellard | vnc_clear_bit(vs->dirty_row[y], x); |
441 | 24236869 | bellard | } else {
|
442 | 24236869 | bellard | if (last_x != -1) { |
443 | 24236869 | bellard | int h = find_dirty_height(vs, y, last_x, x);
|
444 | 24236869 | bellard | send_framebuffer_update(vs, last_x * 16, y, (x - last_x) * 16, h); |
445 | 24236869 | bellard | n_rectangles++; |
446 | 24236869 | bellard | } |
447 | 24236869 | bellard | last_x = -1;
|
448 | 24236869 | bellard | } |
449 | 24236869 | bellard | } |
450 | 24236869 | bellard | if (last_x != -1) { |
451 | 24236869 | bellard | int h = find_dirty_height(vs, y, last_x, x);
|
452 | 24236869 | bellard | send_framebuffer_update(vs, last_x * 16, y, (x - last_x) * 16, h); |
453 | 24236869 | bellard | n_rectangles++; |
454 | 24236869 | bellard | } |
455 | 24236869 | bellard | } |
456 | 24236869 | bellard | vs->output.buffer[saved_offset] = (n_rectangles >> 8) & 0xFF; |
457 | 24236869 | bellard | vs->output.buffer[saved_offset + 1] = n_rectangles & 0xFF; |
458 | 24236869 | bellard | vnc_flush(vs); |
459 | 24236869 | bellard | |
460 | 24236869 | bellard | } |
461 | 24236869 | bellard | qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock) + VNC_REFRESH_INTERVAL); |
462 | 24236869 | bellard | } |
463 | 24236869 | bellard | |
464 | 24236869 | bellard | static void vnc_timer_init(VncState *vs) |
465 | 24236869 | bellard | { |
466 | 24236869 | bellard | if (vs->timer == NULL) { |
467 | 24236869 | bellard | vs->timer = qemu_new_timer(rt_clock, vnc_update_client, vs); |
468 | 24236869 | bellard | qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock)); |
469 | 24236869 | bellard | } |
470 | 24236869 | bellard | } |
471 | 24236869 | bellard | |
472 | 24236869 | bellard | static void vnc_dpy_refresh(DisplayState *ds) |
473 | 24236869 | bellard | { |
474 | 24236869 | bellard | VncState *vs = ds->opaque; |
475 | 24236869 | bellard | vnc_timer_init(vs); |
476 | 24236869 | bellard | vga_hw_update(); |
477 | 24236869 | bellard | } |
478 | 24236869 | bellard | |
479 | 24236869 | bellard | static int vnc_listen_poll(void *opaque) |
480 | 24236869 | bellard | { |
481 | 24236869 | bellard | VncState *vs = opaque; |
482 | 24236869 | bellard | if (vs->csock == -1) |
483 | 24236869 | bellard | return 1; |
484 | 24236869 | bellard | return 0; |
485 | 24236869 | bellard | } |
486 | 24236869 | bellard | |
487 | 24236869 | bellard | static void buffer_reserve(Buffer *buffer, size_t len) |
488 | 24236869 | bellard | { |
489 | 24236869 | bellard | if ((buffer->capacity - buffer->offset) < len) {
|
490 | 24236869 | bellard | buffer->capacity += (len + 1024);
|
491 | 24236869 | bellard | buffer->buffer = realloc(buffer->buffer, buffer->capacity); |
492 | 24236869 | bellard | if (buffer->buffer == NULL) { |
493 | 24236869 | bellard | fprintf(stderr, "vnc: out of memory\n");
|
494 | 24236869 | bellard | exit(1);
|
495 | 24236869 | bellard | } |
496 | 24236869 | bellard | } |
497 | 24236869 | bellard | } |
498 | 24236869 | bellard | |
499 | 24236869 | bellard | static int buffer_empty(Buffer *buffer) |
500 | 24236869 | bellard | { |
501 | 24236869 | bellard | return buffer->offset == 0; |
502 | 24236869 | bellard | } |
503 | 24236869 | bellard | |
504 | 24236869 | bellard | static char *buffer_end(Buffer *buffer) |
505 | 24236869 | bellard | { |
506 | 24236869 | bellard | return buffer->buffer + buffer->offset;
|
507 | 24236869 | bellard | } |
508 | 24236869 | bellard | |
509 | 24236869 | bellard | static void buffer_reset(Buffer *buffer) |
510 | 24236869 | bellard | { |
511 | 24236869 | bellard | buffer->offset = 0;
|
512 | 24236869 | bellard | } |
513 | 24236869 | bellard | |
514 | 24236869 | bellard | static void buffer_append(Buffer *buffer, const void *data, size_t len) |
515 | 24236869 | bellard | { |
516 | 24236869 | bellard | memcpy(buffer->buffer + buffer->offset, data, len); |
517 | 24236869 | bellard | buffer->offset += len; |
518 | 24236869 | bellard | } |
519 | 24236869 | bellard | |
520 | 6ca957f0 | bellard | static int vnc_client_io_error(VncState *vs, int ret, int last_errno) |
521 | 24236869 | bellard | { |
522 | 24236869 | bellard | if (ret == 0 || ret == -1) { |
523 | 6ca957f0 | bellard | if (ret == -1 && (last_errno == EINTR || last_errno == EAGAIN)) |
524 | 24236869 | bellard | return 0; |
525 | 24236869 | bellard | |
526 | 24236869 | bellard | qemu_set_fd_handler2(vs->csock, NULL, NULL, NULL, NULL); |
527 | 6ca957f0 | bellard | closesocket(vs->csock); |
528 | 24236869 | bellard | vs->csock = -1;
|
529 | 24236869 | bellard | buffer_reset(&vs->input); |
530 | 24236869 | bellard | buffer_reset(&vs->output); |
531 | 24236869 | bellard | vs->need_update = 0;
|
532 | 24236869 | bellard | return 0; |
533 | 24236869 | bellard | } |
534 | 24236869 | bellard | return ret;
|
535 | 24236869 | bellard | } |
536 | 24236869 | bellard | |
537 | 24236869 | bellard | static void vnc_client_error(VncState *vs) |
538 | 24236869 | bellard | { |
539 | 6ca957f0 | bellard | vnc_client_io_error(vs, -1, EINVAL);
|
540 | 24236869 | bellard | } |
541 | 24236869 | bellard | |
542 | 24236869 | bellard | static void vnc_client_write(void *opaque) |
543 | 24236869 | bellard | { |
544 | ceb5caaf | bellard | long ret;
|
545 | 24236869 | bellard | VncState *vs = opaque; |
546 | 24236869 | bellard | |
547 | 6ca957f0 | bellard | ret = send(vs->csock, vs->output.buffer, vs->output.offset, 0);
|
548 | 6ca957f0 | bellard | ret = vnc_client_io_error(vs, ret, socket_error()); |
549 | 24236869 | bellard | if (!ret)
|
550 | 24236869 | bellard | return;
|
551 | 24236869 | bellard | |
552 | 24236869 | bellard | memmove(vs->output.buffer, vs->output.buffer + ret, (vs->output.offset - ret)); |
553 | 24236869 | bellard | vs->output.offset -= ret; |
554 | 24236869 | bellard | |
555 | 24236869 | bellard | if (vs->output.offset == 0) { |
556 | 24236869 | bellard | qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs); |
557 | 24236869 | bellard | } |
558 | 24236869 | bellard | } |
559 | 24236869 | bellard | |
560 | 24236869 | bellard | static void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting) |
561 | 24236869 | bellard | { |
562 | 24236869 | bellard | vs->read_handler = func; |
563 | 24236869 | bellard | vs->read_handler_expect = expecting; |
564 | 24236869 | bellard | } |
565 | 24236869 | bellard | |
566 | 24236869 | bellard | static void vnc_client_read(void *opaque) |
567 | 24236869 | bellard | { |
568 | 24236869 | bellard | VncState *vs = opaque; |
569 | ceb5caaf | bellard | long ret;
|
570 | 24236869 | bellard | |
571 | 24236869 | bellard | buffer_reserve(&vs->input, 4096);
|
572 | 24236869 | bellard | |
573 | 6ca957f0 | bellard | ret = recv(vs->csock, buffer_end(&vs->input), 4096, 0); |
574 | 6ca957f0 | bellard | ret = vnc_client_io_error(vs, ret, socket_error()); |
575 | 24236869 | bellard | if (!ret)
|
576 | 24236869 | bellard | return;
|
577 | 24236869 | bellard | |
578 | 24236869 | bellard | vs->input.offset += ret; |
579 | 24236869 | bellard | |
580 | 24236869 | bellard | while (vs->read_handler && vs->input.offset >= vs->read_handler_expect) {
|
581 | 24236869 | bellard | size_t len = vs->read_handler_expect; |
582 | 24236869 | bellard | int ret;
|
583 | 24236869 | bellard | |
584 | 24236869 | bellard | ret = vs->read_handler(vs, vs->input.buffer, len); |
585 | 24236869 | bellard | if (vs->csock == -1) |
586 | 24236869 | bellard | return;
|
587 | 24236869 | bellard | |
588 | 24236869 | bellard | if (!ret) {
|
589 | 24236869 | bellard | memmove(vs->input.buffer, vs->input.buffer + len, (vs->input.offset - len)); |
590 | 24236869 | bellard | vs->input.offset -= len; |
591 | 24236869 | bellard | } else {
|
592 | 24236869 | bellard | vs->read_handler_expect = ret; |
593 | 24236869 | bellard | } |
594 | 24236869 | bellard | } |
595 | 24236869 | bellard | } |
596 | 24236869 | bellard | |
597 | 24236869 | bellard | static void vnc_write(VncState *vs, const void *data, size_t len) |
598 | 24236869 | bellard | { |
599 | 24236869 | bellard | buffer_reserve(&vs->output, len); |
600 | 24236869 | bellard | |
601 | 24236869 | bellard | if (buffer_empty(&vs->output)) {
|
602 | 24236869 | bellard | qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, vnc_client_write, vs);
|
603 | 24236869 | bellard | } |
604 | 24236869 | bellard | |
605 | 24236869 | bellard | buffer_append(&vs->output, data, len); |
606 | 24236869 | bellard | } |
607 | 24236869 | bellard | |
608 | 24236869 | bellard | static void vnc_write_s32(VncState *vs, int32_t value) |
609 | 24236869 | bellard | { |
610 | 24236869 | bellard | vnc_write_u32(vs, *(uint32_t *)&value); |
611 | 24236869 | bellard | } |
612 | 24236869 | bellard | |
613 | 24236869 | bellard | static void vnc_write_u32(VncState *vs, uint32_t value) |
614 | 24236869 | bellard | { |
615 | 24236869 | bellard | uint8_t buf[4];
|
616 | 24236869 | bellard | |
617 | 24236869 | bellard | buf[0] = (value >> 24) & 0xFF; |
618 | 24236869 | bellard | buf[1] = (value >> 16) & 0xFF; |
619 | 24236869 | bellard | buf[2] = (value >> 8) & 0xFF; |
620 | 24236869 | bellard | buf[3] = value & 0xFF; |
621 | 24236869 | bellard | |
622 | 24236869 | bellard | vnc_write(vs, buf, 4);
|
623 | 24236869 | bellard | } |
624 | 24236869 | bellard | |
625 | 24236869 | bellard | static void vnc_write_u16(VncState *vs, uint16_t value) |
626 | 24236869 | bellard | { |
627 | 64f5a135 | bellard | uint8_t buf[2];
|
628 | 24236869 | bellard | |
629 | 24236869 | bellard | buf[0] = (value >> 8) & 0xFF; |
630 | 24236869 | bellard | buf[1] = value & 0xFF; |
631 | 24236869 | bellard | |
632 | 24236869 | bellard | vnc_write(vs, buf, 2);
|
633 | 24236869 | bellard | } |
634 | 24236869 | bellard | |
635 | 24236869 | bellard | static void vnc_write_u8(VncState *vs, uint8_t value) |
636 | 24236869 | bellard | { |
637 | 24236869 | bellard | vnc_write(vs, (char *)&value, 1); |
638 | 24236869 | bellard | } |
639 | 24236869 | bellard | |
640 | 24236869 | bellard | static void vnc_flush(VncState *vs) |
641 | 24236869 | bellard | { |
642 | 24236869 | bellard | if (vs->output.offset)
|
643 | 24236869 | bellard | vnc_client_write(vs); |
644 | 24236869 | bellard | } |
645 | 24236869 | bellard | |
646 | 64f5a135 | bellard | static uint8_t read_u8(uint8_t *data, size_t offset)
|
647 | 24236869 | bellard | { |
648 | 24236869 | bellard | return data[offset];
|
649 | 24236869 | bellard | } |
650 | 24236869 | bellard | |
651 | 64f5a135 | bellard | static uint16_t read_u16(uint8_t *data, size_t offset)
|
652 | 24236869 | bellard | { |
653 | 24236869 | bellard | return ((data[offset] & 0xFF) << 8) | (data[offset + 1] & 0xFF); |
654 | 24236869 | bellard | } |
655 | 24236869 | bellard | |
656 | 64f5a135 | bellard | static int32_t read_s32(uint8_t *data, size_t offset)
|
657 | 24236869 | bellard | { |
658 | 24236869 | bellard | return (int32_t)((data[offset] << 24) | (data[offset + 1] << 16) | |
659 | 24236869 | bellard | (data[offset + 2] << 8) | data[offset + 3]); |
660 | 24236869 | bellard | } |
661 | 24236869 | bellard | |
662 | 64f5a135 | bellard | static uint32_t read_u32(uint8_t *data, size_t offset)
|
663 | 24236869 | bellard | { |
664 | 24236869 | bellard | return ((data[offset] << 24) | (data[offset + 1] << 16) | |
665 | 24236869 | bellard | (data[offset + 2] << 8) | data[offset + 3]); |
666 | 24236869 | bellard | } |
667 | 24236869 | bellard | |
668 | 24236869 | bellard | static void client_cut_text(VncState *vs, size_t len, char *text) |
669 | 24236869 | bellard | { |
670 | 24236869 | bellard | } |
671 | 24236869 | bellard | |
672 | 24236869 | bellard | static void pointer_event(VncState *vs, int button_mask, int x, int y) |
673 | 24236869 | bellard | { |
674 | 24236869 | bellard | int buttons = 0; |
675 | 24236869 | bellard | int dz = 0; |
676 | 24236869 | bellard | |
677 | 24236869 | bellard | if (button_mask & 0x01) |
678 | 24236869 | bellard | buttons |= MOUSE_EVENT_LBUTTON; |
679 | 24236869 | bellard | if (button_mask & 0x02) |
680 | 24236869 | bellard | buttons |= MOUSE_EVENT_MBUTTON; |
681 | 24236869 | bellard | if (button_mask & 0x04) |
682 | 24236869 | bellard | buttons |= MOUSE_EVENT_RBUTTON; |
683 | 24236869 | bellard | if (button_mask & 0x08) |
684 | 24236869 | bellard | dz = -1;
|
685 | 24236869 | bellard | if (button_mask & 0x10) |
686 | 24236869 | bellard | dz = 1;
|
687 | 24236869 | bellard | |
688 | 24236869 | bellard | if (kbd_mouse_is_absolute()) {
|
689 | 24236869 | bellard | kbd_mouse_event(x * 0x7FFF / vs->ds->width,
|
690 | 24236869 | bellard | y * 0x7FFF / vs->ds->height,
|
691 | 24236869 | bellard | dz, buttons); |
692 | 24236869 | bellard | } else {
|
693 | 24236869 | bellard | static int last_x = -1; |
694 | 24236869 | bellard | static int last_y = -1; |
695 | 24236869 | bellard | |
696 | 24236869 | bellard | if (last_x != -1) |
697 | 24236869 | bellard | kbd_mouse_event(x - last_x, y - last_y, dz, buttons); |
698 | 24236869 | bellard | |
699 | 24236869 | bellard | last_x = x; |
700 | 24236869 | bellard | last_y = y; |
701 | 24236869 | bellard | } |
702 | 24236869 | bellard | } |
703 | 24236869 | bellard | |
704 | 64f5a135 | bellard | static void reset_keys(VncState *vs) |
705 | 64f5a135 | bellard | { |
706 | 64f5a135 | bellard | int i;
|
707 | 64f5a135 | bellard | for(i = 0; i < 256; i++) { |
708 | 64f5a135 | bellard | if (vs->modifiers_state[i]) {
|
709 | 64f5a135 | bellard | if (i & 0x80) |
710 | 64f5a135 | bellard | kbd_put_keycode(0xe0);
|
711 | 64f5a135 | bellard | kbd_put_keycode(i | 0x80);
|
712 | 64f5a135 | bellard | vs->modifiers_state[i] = 0;
|
713 | 64f5a135 | bellard | } |
714 | 64f5a135 | bellard | } |
715 | 64f5a135 | bellard | } |
716 | 64f5a135 | bellard | |
717 | bdbd7676 | bellard | static void do_key_event(VncState *vs, int down, uint32_t sym) |
718 | 24236869 | bellard | { |
719 | 24236869 | bellard | int keycode;
|
720 | 24236869 | bellard | |
721 | 24236869 | bellard | keycode = keysym2scancode(vs->kbd_layout, sym & 0xFFFF);
|
722 | 64f5a135 | bellard | |
723 | 64f5a135 | bellard | /* QEMU console switch */
|
724 | 64f5a135 | bellard | switch(keycode) {
|
725 | 64f5a135 | bellard | case 0x2a: /* Left Shift */ |
726 | 64f5a135 | bellard | case 0x36: /* Right Shift */ |
727 | 64f5a135 | bellard | case 0x1d: /* Left CTRL */ |
728 | 64f5a135 | bellard | case 0x9d: /* Right CTRL */ |
729 | 64f5a135 | bellard | case 0x38: /* Left ALT */ |
730 | 64f5a135 | bellard | case 0xb8: /* Right ALT */ |
731 | 64f5a135 | bellard | if (down)
|
732 | 64f5a135 | bellard | vs->modifiers_state[keycode] = 1;
|
733 | 64f5a135 | bellard | else
|
734 | 64f5a135 | bellard | vs->modifiers_state[keycode] = 0;
|
735 | 64f5a135 | bellard | break;
|
736 | 64f5a135 | bellard | case 0x02 ... 0x0a: /* '1' to '9' keys */ |
737 | 64f5a135 | bellard | if (down && vs->modifiers_state[0x1d] && vs->modifiers_state[0x38]) { |
738 | 64f5a135 | bellard | /* Reset the modifiers sent to the current console */
|
739 | 64f5a135 | bellard | reset_keys(vs); |
740 | 64f5a135 | bellard | console_select(keycode - 0x02);
|
741 | 64f5a135 | bellard | return;
|
742 | 64f5a135 | bellard | } |
743 | 64f5a135 | bellard | break;
|
744 | 64f5a135 | bellard | } |
745 | 24236869 | bellard | |
746 | 64f5a135 | bellard | if (is_graphic_console()) {
|
747 | 64f5a135 | bellard | if (keycode & 0x80) |
748 | 64f5a135 | bellard | kbd_put_keycode(0xe0);
|
749 | 64f5a135 | bellard | if (down)
|
750 | 64f5a135 | bellard | kbd_put_keycode(keycode & 0x7f);
|
751 | 64f5a135 | bellard | else
|
752 | 64f5a135 | bellard | kbd_put_keycode(keycode | 0x80);
|
753 | 64f5a135 | bellard | } else {
|
754 | 64f5a135 | bellard | /* QEMU console emulation */
|
755 | 64f5a135 | bellard | if (down) {
|
756 | 64f5a135 | bellard | switch (keycode) {
|
757 | 64f5a135 | bellard | case 0x2a: /* Left Shift */ |
758 | 64f5a135 | bellard | case 0x36: /* Right Shift */ |
759 | 64f5a135 | bellard | case 0x1d: /* Left CTRL */ |
760 | 64f5a135 | bellard | case 0x9d: /* Right CTRL */ |
761 | 64f5a135 | bellard | case 0x38: /* Left ALT */ |
762 | 64f5a135 | bellard | case 0xb8: /* Right ALT */ |
763 | 64f5a135 | bellard | break;
|
764 | 64f5a135 | bellard | case 0xc8: |
765 | 64f5a135 | bellard | kbd_put_keysym(QEMU_KEY_UP); |
766 | 64f5a135 | bellard | break;
|
767 | 64f5a135 | bellard | case 0xd0: |
768 | 64f5a135 | bellard | kbd_put_keysym(QEMU_KEY_DOWN); |
769 | 64f5a135 | bellard | break;
|
770 | 64f5a135 | bellard | case 0xcb: |
771 | 64f5a135 | bellard | kbd_put_keysym(QEMU_KEY_LEFT); |
772 | 64f5a135 | bellard | break;
|
773 | 64f5a135 | bellard | case 0xcd: |
774 | 64f5a135 | bellard | kbd_put_keysym(QEMU_KEY_RIGHT); |
775 | 64f5a135 | bellard | break;
|
776 | 64f5a135 | bellard | case 0xd3: |
777 | 64f5a135 | bellard | kbd_put_keysym(QEMU_KEY_DELETE); |
778 | 64f5a135 | bellard | break;
|
779 | 64f5a135 | bellard | case 0xc7: |
780 | 64f5a135 | bellard | kbd_put_keysym(QEMU_KEY_HOME); |
781 | 64f5a135 | bellard | break;
|
782 | 64f5a135 | bellard | case 0xcf: |
783 | 64f5a135 | bellard | kbd_put_keysym(QEMU_KEY_END); |
784 | 64f5a135 | bellard | break;
|
785 | 64f5a135 | bellard | case 0xc9: |
786 | 64f5a135 | bellard | kbd_put_keysym(QEMU_KEY_PAGEUP); |
787 | 64f5a135 | bellard | break;
|
788 | 64f5a135 | bellard | case 0xd1: |
789 | 64f5a135 | bellard | kbd_put_keysym(QEMU_KEY_PAGEDOWN); |
790 | 64f5a135 | bellard | break;
|
791 | 64f5a135 | bellard | default:
|
792 | 64f5a135 | bellard | kbd_put_keysym(sym); |
793 | 64f5a135 | bellard | break;
|
794 | 64f5a135 | bellard | } |
795 | 64f5a135 | bellard | } |
796 | 64f5a135 | bellard | } |
797 | 24236869 | bellard | } |
798 | 24236869 | bellard | |
799 | bdbd7676 | bellard | static void key_event(VncState *vs, int down, uint32_t sym) |
800 | bdbd7676 | bellard | { |
801 | bdbd7676 | bellard | if (sym >= 'A' && sym <= 'Z') |
802 | bdbd7676 | bellard | sym = sym - 'A' + 'a'; |
803 | bdbd7676 | bellard | do_key_event(vs, down, sym); |
804 | bdbd7676 | bellard | } |
805 | bdbd7676 | bellard | |
806 | 24236869 | bellard | static void framebuffer_update_request(VncState *vs, int incremental, |
807 | 24236869 | bellard | int x_position, int y_position, |
808 | 24236869 | bellard | int w, int h) |
809 | 24236869 | bellard | { |
810 | 24236869 | bellard | int i;
|
811 | 24236869 | bellard | vs->need_update = 1;
|
812 | 24236869 | bellard | if (!incremental) {
|
813 | 24236869 | bellard | char *old_row = vs->old_data + y_position * vs->ds->linesize;
|
814 | 24236869 | bellard | |
815 | 24236869 | bellard | for (i = 0; i < h; i++) { |
816 | 99589bdc | bellard | vnc_set_bits(vs->dirty_row[y_position + i], |
817 | 99589bdc | bellard | (vs->ds->width / 16), VNC_DIRTY_WORDS);
|
818 | 24236869 | bellard | memset(old_row, 42, vs->ds->width * vs->depth);
|
819 | 24236869 | bellard | old_row += vs->ds->linesize; |
820 | 24236869 | bellard | } |
821 | 24236869 | bellard | } |
822 | 24236869 | bellard | } |
823 | 24236869 | bellard | |
824 | 24236869 | bellard | static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings) |
825 | 24236869 | bellard | { |
826 | 24236869 | bellard | int i;
|
827 | 24236869 | bellard | |
828 | 24236869 | bellard | vs->has_hextile = 0;
|
829 | 24236869 | bellard | vs->has_resize = 0;
|
830 | 24236869 | bellard | vs->ds->dpy_copy = NULL;
|
831 | 24236869 | bellard | |
832 | 24236869 | bellard | for (i = n_encodings - 1; i >= 0; i--) { |
833 | 24236869 | bellard | switch (encodings[i]) {
|
834 | 24236869 | bellard | case 0: /* Raw */ |
835 | 24236869 | bellard | vs->has_hextile = 0;
|
836 | 24236869 | bellard | break;
|
837 | 24236869 | bellard | case 1: /* CopyRect */ |
838 | 24236869 | bellard | vs->ds->dpy_copy = vnc_copy; |
839 | 24236869 | bellard | break;
|
840 | 24236869 | bellard | case 5: /* Hextile */ |
841 | 24236869 | bellard | vs->has_hextile = 1;
|
842 | 24236869 | bellard | break;
|
843 | 24236869 | bellard | case -223: /* DesktopResize */ |
844 | 24236869 | bellard | vs->has_resize = 1;
|
845 | 24236869 | bellard | break;
|
846 | 24236869 | bellard | default:
|
847 | 24236869 | bellard | break;
|
848 | 24236869 | bellard | } |
849 | 24236869 | bellard | } |
850 | 24236869 | bellard | } |
851 | 24236869 | bellard | |
852 | 3512779a | bellard | static int compute_nbits(unsigned int val) |
853 | 3512779a | bellard | { |
854 | 3512779a | bellard | int n;
|
855 | 3512779a | bellard | n = 0;
|
856 | 3512779a | bellard | while (val != 0) { |
857 | 3512779a | bellard | n++; |
858 | 3512779a | bellard | val >>= 1;
|
859 | 3512779a | bellard | } |
860 | 3512779a | bellard | return n;
|
861 | 3512779a | bellard | } |
862 | 3512779a | bellard | |
863 | 24236869 | bellard | static void set_pixel_format(VncState *vs, |
864 | 24236869 | bellard | int bits_per_pixel, int depth, |
865 | 24236869 | bellard | int big_endian_flag, int true_color_flag, |
866 | 24236869 | bellard | int red_max, int green_max, int blue_max, |
867 | 24236869 | bellard | int red_shift, int green_shift, int blue_shift) |
868 | 24236869 | bellard | { |
869 | 3512779a | bellard | int host_big_endian_flag;
|
870 | 24236869 | bellard | |
871 | 3512779a | bellard | #ifdef WORDS_BIGENDIAN
|
872 | 3512779a | bellard | host_big_endian_flag = 1;
|
873 | 3512779a | bellard | #else
|
874 | 3512779a | bellard | host_big_endian_flag = 0;
|
875 | 3512779a | bellard | #endif
|
876 | 3512779a | bellard | if (!true_color_flag) {
|
877 | 3512779a | bellard | fail:
|
878 | 24236869 | bellard | vnc_client_error(vs); |
879 | 3512779a | bellard | return;
|
880 | 3512779a | bellard | } |
881 | 3512779a | bellard | if (bits_per_pixel == 32 && |
882 | 3512779a | bellard | host_big_endian_flag == big_endian_flag && |
883 | 3512779a | bellard | red_max == 0xff && green_max == 0xff && blue_max == 0xff && |
884 | 3512779a | bellard | red_shift == 16 && green_shift == 8 && blue_shift == 0) { |
885 | 3512779a | bellard | vs->depth = 4;
|
886 | 3512779a | bellard | vs->write_pixels = vnc_write_pixels_copy; |
887 | 3512779a | bellard | vs->send_hextile_tile = send_hextile_tile_32; |
888 | 3512779a | bellard | } else
|
889 | 3512779a | bellard | if (bits_per_pixel == 16 && |
890 | 3512779a | bellard | host_big_endian_flag == big_endian_flag && |
891 | 3512779a | bellard | red_max == 31 && green_max == 63 && blue_max == 31 && |
892 | 3512779a | bellard | red_shift == 11 && green_shift == 5 && blue_shift == 0) { |
893 | 3512779a | bellard | vs->depth = 2;
|
894 | 3512779a | bellard | vs->write_pixels = vnc_write_pixels_copy; |
895 | 3512779a | bellard | vs->send_hextile_tile = send_hextile_tile_16; |
896 | 3512779a | bellard | } else
|
897 | 3512779a | bellard | if (bits_per_pixel == 8 && |
898 | 3512779a | bellard | red_max == 7 && green_max == 7 && blue_max == 3 && |
899 | 3512779a | bellard | red_shift == 5 && green_shift == 2 && blue_shift == 0) { |
900 | 3512779a | bellard | vs->depth = 1;
|
901 | 3512779a | bellard | vs->write_pixels = vnc_write_pixels_copy; |
902 | 3512779a | bellard | vs->send_hextile_tile = send_hextile_tile_8; |
903 | 3512779a | bellard | } else
|
904 | 3512779a | bellard | { |
905 | 3512779a | bellard | /* generic and slower case */
|
906 | 3512779a | bellard | if (bits_per_pixel != 8 && |
907 | 3512779a | bellard | bits_per_pixel != 16 &&
|
908 | 3512779a | bellard | bits_per_pixel != 32)
|
909 | 3512779a | bellard | goto fail;
|
910 | 3512779a | bellard | vs->depth = 4;
|
911 | 3512779a | bellard | vs->red_shift = red_shift; |
912 | 3512779a | bellard | vs->red_max = red_max; |
913 | 3512779a | bellard | vs->red_shift1 = 24 - compute_nbits(red_max);
|
914 | 3512779a | bellard | vs->green_shift = green_shift; |
915 | 3512779a | bellard | vs->green_max = green_max; |
916 | 3512779a | bellard | vs->green_shift1 = 16 - compute_nbits(green_max);
|
917 | 3512779a | bellard | vs->blue_shift = blue_shift; |
918 | 3512779a | bellard | vs->blue_max = blue_max; |
919 | 3512779a | bellard | vs->blue_shift1 = 8 - compute_nbits(blue_max);
|
920 | 3512779a | bellard | vs->pix_bpp = bits_per_pixel / 8;
|
921 | 3512779a | bellard | vs->pix_big_endian = big_endian_flag; |
922 | 3512779a | bellard | vs->write_pixels = vnc_write_pixels_generic; |
923 | 3512779a | bellard | vs->send_hextile_tile = send_hextile_tile_generic; |
924 | 3512779a | bellard | } |
925 | 24236869 | bellard | |
926 | 24236869 | bellard | vnc_dpy_resize(vs->ds, vs->ds->width, vs->ds->height); |
927 | 24236869 | bellard | memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row)); |
928 | 24236869 | bellard | memset(vs->old_data, 42, vs->ds->linesize * vs->ds->height);
|
929 | 24236869 | bellard | |
930 | 24236869 | bellard | vga_hw_invalidate(); |
931 | 24236869 | bellard | vga_hw_update(); |
932 | 24236869 | bellard | } |
933 | 24236869 | bellard | |
934 | 24236869 | bellard | static int protocol_client_msg(VncState *vs, char *data, size_t len) |
935 | 24236869 | bellard | { |
936 | 24236869 | bellard | int i;
|
937 | 24236869 | bellard | uint16_t limit; |
938 | 24236869 | bellard | |
939 | 24236869 | bellard | switch (data[0]) { |
940 | 24236869 | bellard | case 0: |
941 | 24236869 | bellard | if (len == 1) |
942 | 24236869 | bellard | return 20; |
943 | 24236869 | bellard | |
944 | 24236869 | bellard | set_pixel_format(vs, read_u8(data, 4), read_u8(data, 5), |
945 | 24236869 | bellard | read_u8(data, 6), read_u8(data, 7), |
946 | 24236869 | bellard | read_u16(data, 8), read_u16(data, 10), |
947 | 24236869 | bellard | read_u16(data, 12), read_u8(data, 14), |
948 | 24236869 | bellard | read_u8(data, 15), read_u8(data, 16)); |
949 | 24236869 | bellard | break;
|
950 | 24236869 | bellard | case 2: |
951 | 24236869 | bellard | if (len == 1) |
952 | 24236869 | bellard | return 4; |
953 | 24236869 | bellard | |
954 | 24236869 | bellard | if (len == 4) |
955 | 24236869 | bellard | return 4 + (read_u16(data, 2) * 4); |
956 | 24236869 | bellard | |
957 | 24236869 | bellard | limit = read_u16(data, 2);
|
958 | 24236869 | bellard | for (i = 0; i < limit; i++) { |
959 | 24236869 | bellard | int32_t val = read_s32(data, 4 + (i * 4)); |
960 | 24236869 | bellard | memcpy(data + 4 + (i * 4), &val, sizeof(val)); |
961 | 24236869 | bellard | } |
962 | 24236869 | bellard | |
963 | 24236869 | bellard | set_encodings(vs, (int32_t *)(data + 4), limit);
|
964 | 24236869 | bellard | break;
|
965 | 24236869 | bellard | case 3: |
966 | 24236869 | bellard | if (len == 1) |
967 | 24236869 | bellard | return 10; |
968 | 24236869 | bellard | |
969 | 24236869 | bellard | framebuffer_update_request(vs, |
970 | 24236869 | bellard | read_u8(data, 1), read_u16(data, 2), read_u16(data, 4), |
971 | 24236869 | bellard | read_u16(data, 6), read_u16(data, 8)); |
972 | 24236869 | bellard | break;
|
973 | 24236869 | bellard | case 4: |
974 | 24236869 | bellard | if (len == 1) |
975 | 24236869 | bellard | return 8; |
976 | 24236869 | bellard | |
977 | 24236869 | bellard | key_event(vs, read_u8(data, 1), read_u32(data, 4)); |
978 | 24236869 | bellard | break;
|
979 | 24236869 | bellard | case 5: |
980 | 24236869 | bellard | if (len == 1) |
981 | 24236869 | bellard | return 6; |
982 | 24236869 | bellard | |
983 | 24236869 | bellard | pointer_event(vs, read_u8(data, 1), read_u16(data, 2), read_u16(data, 4)); |
984 | 24236869 | bellard | break;
|
985 | 24236869 | bellard | case 6: |
986 | 24236869 | bellard | if (len == 1) |
987 | 24236869 | bellard | return 8; |
988 | 24236869 | bellard | |
989 | 24236869 | bellard | if (len == 8) |
990 | 24236869 | bellard | return 8 + read_u32(data, 4); |
991 | 24236869 | bellard | |
992 | 24236869 | bellard | client_cut_text(vs, read_u32(data, 4), data + 8); |
993 | 24236869 | bellard | break;
|
994 | 24236869 | bellard | default:
|
995 | 24236869 | bellard | printf("Msg: %d\n", data[0]); |
996 | 24236869 | bellard | vnc_client_error(vs); |
997 | 24236869 | bellard | break;
|
998 | 24236869 | bellard | } |
999 | 24236869 | bellard | |
1000 | 24236869 | bellard | vnc_read_when(vs, protocol_client_msg, 1);
|
1001 | 24236869 | bellard | return 0; |
1002 | 24236869 | bellard | } |
1003 | 24236869 | bellard | |
1004 | 24236869 | bellard | static int protocol_client_init(VncState *vs, char *data, size_t len) |
1005 | 24236869 | bellard | { |
1006 | 24236869 | bellard | char pad[3] = { 0, 0, 0 }; |
1007 | 24236869 | bellard | |
1008 | 24236869 | bellard | vs->width = vs->ds->width; |
1009 | 24236869 | bellard | vs->height = vs->ds->height; |
1010 | 24236869 | bellard | vnc_write_u16(vs, vs->ds->width); |
1011 | 24236869 | bellard | vnc_write_u16(vs, vs->ds->height); |
1012 | 24236869 | bellard | |
1013 | 24236869 | bellard | vnc_write_u8(vs, vs->depth * 8); /* bits-per-pixel */ |
1014 | 24236869 | bellard | vnc_write_u8(vs, vs->depth * 8); /* depth */ |
1015 | 3512779a | bellard | #ifdef WORDS_BIGENDIAN
|
1016 | 3512779a | bellard | vnc_write_u8(vs, 1); /* big-endian-flag */ |
1017 | 3512779a | bellard | #else
|
1018 | 24236869 | bellard | vnc_write_u8(vs, 0); /* big-endian-flag */ |
1019 | 3512779a | bellard | #endif
|
1020 | 24236869 | bellard | vnc_write_u8(vs, 1); /* true-color-flag */ |
1021 | 24236869 | bellard | if (vs->depth == 4) { |
1022 | 24236869 | bellard | vnc_write_u16(vs, 0xFF); /* red-max */ |
1023 | 24236869 | bellard | vnc_write_u16(vs, 0xFF); /* green-max */ |
1024 | 24236869 | bellard | vnc_write_u16(vs, 0xFF); /* blue-max */ |
1025 | 24236869 | bellard | vnc_write_u8(vs, 16); /* red-shift */ |
1026 | 24236869 | bellard | vnc_write_u8(vs, 8); /* green-shift */ |
1027 | 24236869 | bellard | vnc_write_u8(vs, 0); /* blue-shift */ |
1028 | 3512779a | bellard | vs->send_hextile_tile = send_hextile_tile_32; |
1029 | 24236869 | bellard | } else if (vs->depth == 2) { |
1030 | 24236869 | bellard | vnc_write_u16(vs, 31); /* red-max */ |
1031 | 24236869 | bellard | vnc_write_u16(vs, 63); /* green-max */ |
1032 | 24236869 | bellard | vnc_write_u16(vs, 31); /* blue-max */ |
1033 | 24236869 | bellard | vnc_write_u8(vs, 11); /* red-shift */ |
1034 | 24236869 | bellard | vnc_write_u8(vs, 5); /* green-shift */ |
1035 | 24236869 | bellard | vnc_write_u8(vs, 0); /* blue-shift */ |
1036 | 3512779a | bellard | vs->send_hextile_tile = send_hextile_tile_16; |
1037 | 24236869 | bellard | } else if (vs->depth == 1) { |
1038 | 3512779a | bellard | /* XXX: change QEMU pixel 8 bit pixel format to match the VNC one ? */
|
1039 | 3512779a | bellard | vnc_write_u16(vs, 7); /* red-max */ |
1040 | 24236869 | bellard | vnc_write_u16(vs, 7); /* green-max */ |
1041 | 24236869 | bellard | vnc_write_u16(vs, 3); /* blue-max */ |
1042 | 24236869 | bellard | vnc_write_u8(vs, 5); /* red-shift */ |
1043 | 24236869 | bellard | vnc_write_u8(vs, 2); /* green-shift */ |
1044 | 24236869 | bellard | vnc_write_u8(vs, 0); /* blue-shift */ |
1045 | 3512779a | bellard | vs->send_hextile_tile = send_hextile_tile_8; |
1046 | 24236869 | bellard | } |
1047 | 3512779a | bellard | vs->write_pixels = vnc_write_pixels_copy; |
1048 | 24236869 | bellard | |
1049 | 24236869 | bellard | vnc_write(vs, pad, 3); /* padding */ |
1050 | 24236869 | bellard | |
1051 | 24236869 | bellard | vnc_write_u32(vs, 4);
|
1052 | 24236869 | bellard | vnc_write(vs, "QEMU", 4); |
1053 | 24236869 | bellard | vnc_flush(vs); |
1054 | 24236869 | bellard | |
1055 | 24236869 | bellard | vnc_read_when(vs, protocol_client_msg, 1);
|
1056 | 24236869 | bellard | |
1057 | 24236869 | bellard | return 0; |
1058 | 24236869 | bellard | } |
1059 | 24236869 | bellard | |
1060 | 24236869 | bellard | static int protocol_version(VncState *vs, char *version, size_t len) |
1061 | 24236869 | bellard | { |
1062 | 24236869 | bellard | char local[13]; |
1063 | 24236869 | bellard | int maj, min;
|
1064 | 24236869 | bellard | |
1065 | 24236869 | bellard | memcpy(local, version, 12);
|
1066 | 24236869 | bellard | local[12] = 0; |
1067 | 24236869 | bellard | |
1068 | 24236869 | bellard | if (sscanf(local, "RFB %03d.%03d\n", &maj, &min) != 2) { |
1069 | 24236869 | bellard | vnc_client_error(vs); |
1070 | 24236869 | bellard | return 0; |
1071 | 24236869 | bellard | } |
1072 | 24236869 | bellard | |
1073 | 24236869 | bellard | vnc_write_u32(vs, 1); /* None */ |
1074 | 24236869 | bellard | vnc_flush(vs); |
1075 | 24236869 | bellard | |
1076 | 24236869 | bellard | vnc_read_when(vs, protocol_client_init, 1);
|
1077 | 24236869 | bellard | |
1078 | 24236869 | bellard | return 0; |
1079 | 24236869 | bellard | } |
1080 | 24236869 | bellard | |
1081 | 24236869 | bellard | static void vnc_listen_read(void *opaque) |
1082 | 24236869 | bellard | { |
1083 | 24236869 | bellard | VncState *vs = opaque; |
1084 | 24236869 | bellard | struct sockaddr_in addr;
|
1085 | 24236869 | bellard | socklen_t addrlen = sizeof(addr);
|
1086 | 24236869 | bellard | |
1087 | 24236869 | bellard | vs->csock = accept(vs->lsock, (struct sockaddr *)&addr, &addrlen);
|
1088 | 24236869 | bellard | if (vs->csock != -1) { |
1089 | 6ca957f0 | bellard | socket_set_nonblock(vs->csock); |
1090 | 24236869 | bellard | qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, opaque); |
1091 | 24236869 | bellard | vnc_write(vs, "RFB 003.003\n", 12); |
1092 | 24236869 | bellard | vnc_flush(vs); |
1093 | 24236869 | bellard | vnc_read_when(vs, protocol_version, 12);
|
1094 | 24236869 | bellard | memset(vs->old_data, 0, vs->ds->linesize * vs->ds->height);
|
1095 | 24236869 | bellard | memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row)); |
1096 | 24236869 | bellard | vs->has_resize = 0;
|
1097 | 24236869 | bellard | vs->has_hextile = 0;
|
1098 | 24236869 | bellard | vs->ds->dpy_copy = NULL;
|
1099 | 24236869 | bellard | } |
1100 | 24236869 | bellard | } |
1101 | 24236869 | bellard | |
1102 | 24236869 | bellard | void vnc_display_init(DisplayState *ds, int display) |
1103 | 24236869 | bellard | { |
1104 | 24236869 | bellard | struct sockaddr_in addr;
|
1105 | 24236869 | bellard | int reuse_addr, ret;
|
1106 | 24236869 | bellard | VncState *vs; |
1107 | 24236869 | bellard | |
1108 | 24236869 | bellard | vs = qemu_mallocz(sizeof(VncState));
|
1109 | 24236869 | bellard | if (!vs)
|
1110 | 24236869 | bellard | exit(1);
|
1111 | 24236869 | bellard | |
1112 | 24236869 | bellard | ds->opaque = vs; |
1113 | 24236869 | bellard | |
1114 | 24236869 | bellard | vs->lsock = -1;
|
1115 | 24236869 | bellard | vs->csock = -1;
|
1116 | 24236869 | bellard | vs->depth = 4;
|
1117 | 24236869 | bellard | |
1118 | 24236869 | bellard | vs->ds = ds; |
1119 | 24236869 | bellard | |
1120 | 24236869 | bellard | if (!keyboard_layout)
|
1121 | 24236869 | bellard | keyboard_layout = "en-us";
|
1122 | 24236869 | bellard | |
1123 | 24236869 | bellard | vs->kbd_layout = init_keyboard_layout(keyboard_layout); |
1124 | 24236869 | bellard | if (!vs->kbd_layout)
|
1125 | 24236869 | bellard | exit(1);
|
1126 | 24236869 | bellard | |
1127 | 24236869 | bellard | vs->lsock = socket(PF_INET, SOCK_STREAM, 0);
|
1128 | 24236869 | bellard | if (vs->lsock == -1) { |
1129 | 24236869 | bellard | fprintf(stderr, "Could not create socket\n");
|
1130 | 24236869 | bellard | exit(1);
|
1131 | 24236869 | bellard | } |
1132 | 24236869 | bellard | |
1133 | 24236869 | bellard | addr.sin_family = AF_INET; |
1134 | 24236869 | bellard | addr.sin_port = htons(5900 + display);
|
1135 | 24236869 | bellard | memset(&addr.sin_addr, 0, sizeof(addr.sin_addr)); |
1136 | 24236869 | bellard | |
1137 | 24236869 | bellard | reuse_addr = 1;
|
1138 | 24236869 | bellard | ret = setsockopt(vs->lsock, SOL_SOCKET, SO_REUSEADDR, |
1139 | 6ca957f0 | bellard | (const char *)&reuse_addr, sizeof(reuse_addr)); |
1140 | 24236869 | bellard | if (ret == -1) { |
1141 | 24236869 | bellard | fprintf(stderr, "setsockopt() failed\n");
|
1142 | 24236869 | bellard | exit(1);
|
1143 | 24236869 | bellard | } |
1144 | 24236869 | bellard | |
1145 | 24236869 | bellard | if (bind(vs->lsock, (struct sockaddr *)&addr, sizeof(addr)) == -1) { |
1146 | 24236869 | bellard | fprintf(stderr, "bind() failed\n");
|
1147 | 24236869 | bellard | exit(1);
|
1148 | 24236869 | bellard | } |
1149 | 24236869 | bellard | |
1150 | 24236869 | bellard | if (listen(vs->lsock, 1) == -1) { |
1151 | 24236869 | bellard | fprintf(stderr, "listen() failed\n");
|
1152 | 24236869 | bellard | exit(1);
|
1153 | 24236869 | bellard | } |
1154 | 24236869 | bellard | |
1155 | 24236869 | bellard | ret = qemu_set_fd_handler2(vs->lsock, vnc_listen_poll, vnc_listen_read, NULL, vs);
|
1156 | 24236869 | bellard | if (ret == -1) { |
1157 | 24236869 | bellard | exit(1);
|
1158 | 24236869 | bellard | } |
1159 | 24236869 | bellard | |
1160 | 24236869 | bellard | vs->ds->data = NULL;
|
1161 | 24236869 | bellard | vs->ds->dpy_update = vnc_dpy_update; |
1162 | 24236869 | bellard | vs->ds->dpy_resize = vnc_dpy_resize; |
1163 | 24236869 | bellard | vs->ds->dpy_refresh = vnc_dpy_refresh; |
1164 | 24236869 | bellard | |
1165 | 24236869 | bellard | memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row)); |
1166 | 24236869 | bellard | |
1167 | 24236869 | bellard | vnc_dpy_resize(vs->ds, 640, 400); |
1168 | 24236869 | bellard | } |