vnc.h 18.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/*
 * QEMU VNC display driver
 *
 * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>
 * Copyright (C) 2006 Fabrice Bellard
 * Copyright (C) 2009 Red Hat, Inc
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef __QEMU_VNC_H
#define __QEMU_VNC_H

#include "qemu-common.h"
31 32
#include "qemu/queue.h"
#include "qemu/thread.h"
33
#include "ui/console.h"
34
#include "audio/audio.h"
35
#include "qemu/bitmap.h"
36
#include <zlib.h>
C
Corentin Chary 已提交
37
#include <stdbool.h>
38 39

#include "keymaps.h"
40 41
#include "vnc-palette.h"
#include "vnc-enc-zrle.h"
W
Wenchao Xia 已提交
42
#include "qapi-types.h"
43

44 45 46 47 48 49 50 51
// #define _VNC_DEBUG 1

#ifdef _VNC_DEBUG
#define VNC_DEBUG(fmt, ...) do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
#else
#define VNC_DEBUG(fmt, ...) do { } while (0)
#endif

52 53 54 55 56 57 58 59 60 61 62 63 64 65
/*****************************************************************************
 *
 * Core data structures
 *
 *****************************************************************************/

typedef struct Buffer
{
    size_t capacity;
    size_t offset;
    uint8_t *buffer;
} Buffer;

typedef struct VncState VncState;
C
Corentin Chary 已提交
66 67 68
typedef struct VncJob VncJob;
typedef struct VncRect VncRect;
typedef struct VncRectEntry VncRectEntry;
69 70 71

typedef int VncReadEvent(VncState *vs, uint8_t *data, size_t len);

72
typedef void VncWritePixels(VncState *vs, void *data, int size);
73 74 75 76 77 78 79

typedef void VncSendHextileTile(VncState *vs,
                                int x, int y, int w, int h,
                                void *last_bg,
                                void *last_fg,
                                int *has_bg, int *has_fg);

80
/* VNC_DIRTY_PIXELS_PER_BIT is the number of dirty pixels represented
81
 * by one bit in the dirty bitmap, should be a power of 2 */
82 83
#define VNC_DIRTY_PIXELS_PER_BIT 16

84 85 86 87 88
/* VNC_MAX_WIDTH must be a multiple of VNC_DIRTY_PIXELS_PER_BIT. */

#define VNC_MAX_WIDTH ROUND_UP(2560, VNC_DIRTY_PIXELS_PER_BIT)
#define VNC_MAX_HEIGHT 2048

89
/* VNC_DIRTY_BITS is the number of bits in the dirty bitmap. */
90
#define VNC_DIRTY_BITS (VNC_MAX_WIDTH / VNC_DIRTY_PIXELS_PER_BIT)
91

92 93 94 95
/* VNC_DIRTY_BPL (BPL = bits per line) might be greater than
 * VNC_DIRTY_BITS due to alignment */
#define VNC_DIRTY_BPL(x) (sizeof((x)->dirty) / VNC_MAX_HEIGHT * BITS_PER_BYTE)

96 97 98 99
#define VNC_STAT_RECT  64
#define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT)
#define VNC_STAT_ROWS (VNC_MAX_HEIGHT / VNC_STAT_RECT)

100 101 102 103
#define VNC_AUTH_CHALLENGE_SIZE 16

typedef struct VncDisplay VncDisplay;

104 105 106 107
#ifdef CONFIG_VNC_TLS
#include "vnc-tls.h"
#include "vnc-auth-vencrypt.h"
#endif
108 109 110
#ifdef CONFIG_VNC_SASL
#include "vnc-auth-sasl.h"
#endif
111 112 113
#ifdef CONFIG_VNC_WS
#include "vnc-ws.h"
#endif
114

115 116 117 118 119 120 121 122 123 124 125 126
struct VncRectStat
{
    /* time of last 10 updates, to find update frequency */
    struct timeval times[10];
    int idx;

    double freq;        /* Update frequency (in Hz) */
    bool updated;       /* Already updated during this refresh */
};

typedef struct VncRectStat VncRectStat;

S
Stefano Stabellini 已提交
127 128
struct VncSurface
{
129
    struct timeval last_freq_check;
130 131
    DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT],
                   VNC_MAX_WIDTH / VNC_DIRTY_PIXELS_PER_BIT);
132
    VncRectStat stats[VNC_STAT_ROWS][VNC_STAT_COLS];
133 134
    pixman_image_t *fb;
    pixman_format_code_t format;
S
Stefano Stabellini 已提交
135
};
136

137 138 139 140 141 142 143 144 145 146 147 148 149
typedef enum VncShareMode {
    VNC_SHARE_MODE_CONNECTING = 1,
    VNC_SHARE_MODE_SHARED,
    VNC_SHARE_MODE_EXCLUSIVE,
    VNC_SHARE_MODE_DISCONNECTED,
} VncShareMode;

typedef enum VncSharePolicy {
    VNC_SHARE_POLICY_IGNORE = 1,
    VNC_SHARE_POLICY_ALLOW_EXCLUSIVE,
    VNC_SHARE_POLICY_FORCE_SHARED,
} VncSharePolicy;

150 151
struct VncDisplay
{
152
    QTAILQ_HEAD(, VncState) clients;
153 154
    int num_exclusive;
    VncSharePolicy share_policy;
155
    int lsock;
156 157 158 159 160
#ifdef CONFIG_VNC_WS
    int lwebsock;
    bool websocket;
    char *ws_display;
#endif
G
Gerd Hoffmann 已提交
161
    DisplaySurface *ds;
162
    DisplayChangeListener dcl;
A
Anthony Liguori 已提交
163
    kbd_layout_t *kbd_layout;
G
Gerd Hoffmann 已提交
164
    int lock_key_sync;
C
Corentin Chary 已提交
165
    QemuMutex mutex;
166

G
Gerd Hoffmann 已提交
167 168 169 170
    QEMUCursor *cursor;
    int cursor_msize;
    uint8_t *cursor_mask;

S
Stefano Stabellini 已提交
171
    struct VncSurface guest;   /* guest visible surface (aka ds->surface) */
172
    pixman_image_t *server;    /* vnc server surface */
S
Stefano Stabellini 已提交
173

174 175
    char *display;
    char *password;
G
Gerd Hoffmann 已提交
176
    time_t expires;
177
    int auth;
C
Corentin Chary 已提交
178
    bool lossy;
C
Corentin Chary 已提交
179
    bool non_adaptive;
180
#ifdef CONFIG_VNC_TLS
181 182
    int subauth; /* Used by VeNCrypt */
    VncDisplayTLS tls;
183
#endif
184 185 186
#ifdef CONFIG_VNC_SASL
    VncDisplaySASL sasl;
#endif
187 188
};

189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
typedef struct VncTight {
    int type;
    uint8_t quality;
    uint8_t compression;
    uint8_t pixel24;
    Buffer tight;
    Buffer tmp;
    Buffer zlib;
    Buffer gradient;
#ifdef CONFIG_VNC_JPEG
    Buffer jpeg;
#endif
#ifdef CONFIG_VNC_PNG
    Buffer png;
#endif
    int levels[4];
    z_stream stream[4];
} VncTight;

typedef struct VncHextile {
    VncSendHextileTile *send_tile;
} VncHextile;

typedef struct VncZlib {
    Buffer zlib;
    Buffer tmp;
    z_stream stream;
    int level;
} VncZlib;

219 220 221 222 223 224 225 226 227 228 229 230 231 232
typedef struct VncZrle {
    int type;
    Buffer fb;
    Buffer zrle;
    Buffer tmp;
    Buffer zlib;
    z_stream stream;
    VncPalette palette;
} VncZrle;

typedef struct VncZywrle {
    int buf[VNC_ZRLE_TILE_WIDTH * VNC_ZRLE_TILE_HEIGHT];
} VncZywrle;

C
Corentin Chary 已提交
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
struct VncRect
{
    int x;
    int y;
    int w;
    int h;
};

struct VncRectEntry
{
    struct VncRect rect;
    QLIST_ENTRY(VncRectEntry) next;
};

struct VncJob
{
    VncState *vs;

    QLIST_HEAD(, VncRectEntry) rectangles;
    QTAILQ_ENTRY(VncJob) next;
};

255 256 257
struct VncState
{
    int csock;
258

259
    DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT], VNC_DIRTY_BITS);
260 261
    uint8_t **lossy_rect; /* Not an Array to avoid costly memcpy in
                           * vnc-jobs-async.c */
262

263 264
    VncDisplay *vd;
    int need_update;
265
    int force_update;
G
Gerd Hoffmann 已提交
266
    int has_dirty;
267 268 269 270
    uint32_t features;
    int absolute;
    int last_x;
    int last_y;
271
    uint32_t last_bmask;
272 273
    int client_width;
    int client_height;
274
    VncShareMode share_mode;
275 276 277 278 279 280

    uint32_t vnc_encoding;

    int major;
    int minor;

281
    int auth;
282 283
    char challenge[VNC_AUTH_CHALLENGE_SIZE];
#ifdef CONFIG_VNC_TLS
284
    int subauth; /* Used by VeNCrypt */
285
    VncStateTLS tls;
286
#endif
287 288 289
#ifdef CONFIG_VNC_SASL
    VncStateSASL sasl;
#endif
290
#ifdef CONFIG_VNC_WS
T
Tim Hardeck 已提交
291 292 293
#ifdef CONFIG_VNC_TLS
    VncStateTLS ws_tls;
#endif /* CONFIG_VNC_TLS */
294 295
    bool encode_ws;
    bool websocket;
T
Tim Hardeck 已提交
296
#endif /* CONFIG_VNC_WS */
297

W
Wenchao Xia 已提交
298
    VncClientInfo *info;
299

300 301
    Buffer output;
    Buffer input;
302 303 304 305
#ifdef CONFIG_VNC_WS
    Buffer ws_input;
    Buffer ws_output;
#endif
306 307
    /* current output mode information */
    VncWritePixels *write_pixels;
308 309 310
    PixelFormat client_pf;
    pixman_format_code_t client_format;
    bool client_be;
311 312 313 314 315 316 317 318

    CaptureVoiceOut *audio_cap;
    struct audsettings as;

    VncReadEvent *read_handler;
    size_t read_handler_expect;
    /* input */
    uint8_t modifiers_state[256];
G
Gerd Hoffmann 已提交
319
    QEMUPutLEDEntry *led;
320

C
Corentin Chary 已提交
321
    bool abort;
322
    bool initialized;
C
Corentin Chary 已提交
323
    QemuMutex output_mutex;
324 325
    QEMUBH *bh;
    Buffer jobs_buffer;
C
Corentin Chary 已提交
326 327 328 329

    /* Encoding specific, if you add something here, don't forget to
     *  update vnc_async_encoding_start()
     */
330 331 332
    VncTight tight;
    VncZlib zlib;
    VncHextile hextile;
333 334
    VncZrle zrle;
    VncZywrle zywrle;
335

336 337
    Notifier mouse_mode_notifier;

338
    QTAILQ_ENTRY(VncState) next;
339 340
};

341 342 343 344 345 346 347 348 349 350 351 352 353 354 355

/*****************************************************************************
 *
 * Authentication modes
 *
 *****************************************************************************/

enum {
    VNC_AUTH_INVALID = 0,
    VNC_AUTH_NONE = 1,
    VNC_AUTH_VNC = 2,
    VNC_AUTH_RA2 = 5,
    VNC_AUTH_RA2NE = 6,
    VNC_AUTH_TIGHT = 16,
    VNC_AUTH_ULTRA = 17,
356 357 358
    VNC_AUTH_TLS = 18,      /* Supported in GTK-VNC & VINO */
    VNC_AUTH_VENCRYPT = 19, /* Supported in GTK-VNC & VeNCrypt */
    VNC_AUTH_SASL = 20,     /* Supported in GTK-VNC & VINO */
359 360 361 362 363 364 365 366 367 368
};

enum {
    VNC_AUTH_VENCRYPT_PLAIN = 256,
    VNC_AUTH_VENCRYPT_TLSNONE = 257,
    VNC_AUTH_VENCRYPT_TLSVNC = 258,
    VNC_AUTH_VENCRYPT_TLSPLAIN = 259,
    VNC_AUTH_VENCRYPT_X509NONE = 260,
    VNC_AUTH_VENCRYPT_X509VNC = 261,
    VNC_AUTH_VENCRYPT_X509PLAIN = 262,
369 370
    VNC_AUTH_VENCRYPT_X509SASL = 263,
    VNC_AUTH_VENCRYPT_TLSSASL = 264,
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
};


/*****************************************************************************
 *
 * Encoding types
 *
 *****************************************************************************/

#define VNC_ENCODING_RAW                  0x00000000
#define VNC_ENCODING_COPYRECT             0x00000001
#define VNC_ENCODING_RRE                  0x00000002
#define VNC_ENCODING_CORRE                0x00000004
#define VNC_ENCODING_HEXTILE              0x00000005
#define VNC_ENCODING_ZLIB                 0x00000006
#define VNC_ENCODING_TIGHT                0x00000007
#define VNC_ENCODING_ZLIBHEX              0x00000008
#define VNC_ENCODING_TRLE                 0x0000000f
#define VNC_ENCODING_ZRLE                 0x00000010
#define VNC_ENCODING_ZYWRLE               0x00000011
#define VNC_ENCODING_COMPRESSLEVEL0       0xFFFFFF00 /* -256 */
#define VNC_ENCODING_QUALITYLEVEL0        0xFFFFFFE0 /* -32  */
#define VNC_ENCODING_XCURSOR              0xFFFFFF10 /* -240 */
#define VNC_ENCODING_RICH_CURSOR          0xFFFFFF11 /* -239 */
#define VNC_ENCODING_POINTER_POS          0xFFFFFF18 /* -232 */
#define VNC_ENCODING_LASTRECT             0xFFFFFF20 /* -224 */
#define VNC_ENCODING_DESKTOPRESIZE        0xFFFFFF21 /* -223 */
#define VNC_ENCODING_POINTER_TYPE_CHANGE  0XFFFFFEFF /* -257 */
#define VNC_ENCODING_EXT_KEY_EVENT        0XFFFFFEFE /* -258 */
#define VNC_ENCODING_AUDIO                0XFFFFFEFD /* -259 */
C
Corentin Chary 已提交
401
#define VNC_ENCODING_TIGHT_PNG            0xFFFFFEFC /* -260 */
L
Lei Li 已提交
402
#define VNC_ENCODING_LED_STATE            0XFFFFFEFB /* -261 */
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
#define VNC_ENCODING_WMVi                 0x574D5669

/*****************************************************************************
 *
 * Other tight constants
 *
 *****************************************************************************/

/*
 * Vendors known by TightVNC: standard VNC/RealVNC, TridiaVNC, and TightVNC.
 */

#define VNC_TIGHT_CCB_RESET_MASK   (0x0f)
#define VNC_TIGHT_CCB_TYPE_MASK    (0x0f << 4)
#define VNC_TIGHT_CCB_TYPE_FILL    (0x08 << 4)
#define VNC_TIGHT_CCB_TYPE_JPEG    (0x09 << 4)
C
Corentin Chary 已提交
419
#define VNC_TIGHT_CCB_TYPE_PNG     (0x0A << 4)
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
#define VNC_TIGHT_CCB_BASIC_MAX    (0x07 << 4)
#define VNC_TIGHT_CCB_BASIC_ZLIB   (0x03 << 4)
#define VNC_TIGHT_CCB_BASIC_FILTER (0x04 << 4)

/*****************************************************************************
 *
 * Features
 *
 *****************************************************************************/

#define VNC_FEATURE_RESIZE                   0
#define VNC_FEATURE_HEXTILE                  1
#define VNC_FEATURE_POINTER_TYPE_CHANGE      2
#define VNC_FEATURE_WMVI                     3
#define VNC_FEATURE_TIGHT                    4
#define VNC_FEATURE_ZLIB                     5
436
#define VNC_FEATURE_COPYRECT                 6
G
Gerd Hoffmann 已提交
437
#define VNC_FEATURE_RICH_CURSOR              7
C
Corentin Chary 已提交
438
#define VNC_FEATURE_TIGHT_PNG                8
439 440
#define VNC_FEATURE_ZRLE                     9
#define VNC_FEATURE_ZYWRLE                  10
L
Lei Li 已提交
441
#define VNC_FEATURE_LED_STATE               11
442 443 444 445 446 447 448

#define VNC_FEATURE_RESIZE_MASK              (1 << VNC_FEATURE_RESIZE)
#define VNC_FEATURE_HEXTILE_MASK             (1 << VNC_FEATURE_HEXTILE)
#define VNC_FEATURE_POINTER_TYPE_CHANGE_MASK (1 << VNC_FEATURE_POINTER_TYPE_CHANGE)
#define VNC_FEATURE_WMVI_MASK                (1 << VNC_FEATURE_WMVI)
#define VNC_FEATURE_TIGHT_MASK               (1 << VNC_FEATURE_TIGHT)
#define VNC_FEATURE_ZLIB_MASK                (1 << VNC_FEATURE_ZLIB)
449
#define VNC_FEATURE_COPYRECT_MASK            (1 << VNC_FEATURE_COPYRECT)
G
Gerd Hoffmann 已提交
450
#define VNC_FEATURE_RICH_CURSOR_MASK         (1 << VNC_FEATURE_RICH_CURSOR)
C
Corentin Chary 已提交
451
#define VNC_FEATURE_TIGHT_PNG_MASK           (1 << VNC_FEATURE_TIGHT_PNG)
452 453
#define VNC_FEATURE_ZRLE_MASK                (1 << VNC_FEATURE_ZRLE)
#define VNC_FEATURE_ZYWRLE_MASK              (1 << VNC_FEATURE_ZYWRLE)
L
Lei Li 已提交
454
#define VNC_FEATURE_LED_STATE_MASK           (1 << VNC_FEATURE_LED_STATE)
455

456

457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
/* Client -> Server message IDs */
#define VNC_MSG_CLIENT_SET_PIXEL_FORMAT           0
#define VNC_MSG_CLIENT_SET_ENCODINGS              2
#define VNC_MSG_CLIENT_FRAMEBUFFER_UPDATE_REQUEST 3
#define VNC_MSG_CLIENT_KEY_EVENT                  4
#define VNC_MSG_CLIENT_POINTER_EVENT              5
#define VNC_MSG_CLIENT_CUT_TEXT                   6
#define VNC_MSG_CLIENT_VMWARE_0                   127
#define VNC_MSG_CLIENT_CALL_CONTROL               249
#define VNC_MSG_CLIENT_XVP                        250
#define VNC_MSG_CLIENT_SET_DESKTOP_SIZE           251
#define VNC_MSG_CLIENT_TIGHT                      252
#define VNC_MSG_CLIENT_GII                        253
#define VNC_MSG_CLIENT_VMWARE_1                   254
#define VNC_MSG_CLIENT_QEMU                       255

/* Server -> Client message IDs */
#define VNC_MSG_SERVER_FRAMEBUFFER_UPDATE         0
#define VNC_MSG_SERVER_SET_COLOUR_MAP_ENTRIES     1
#define VNC_MSG_SERVER_BELL                       2
#define VNC_MSG_SERVER_CUT_TEXT                   3
#define VNC_MSG_SERVER_VMWARE_0                   127
#define VNC_MSG_SERVER_CALL_CONTROL               249
#define VNC_MSG_SERVER_XVP                        250
#define VNC_MSG_SERVER_TIGHT                      252
#define VNC_MSG_SERVER_GII                        253
#define VNC_MSG_SERVER_VMWARE_1                   254
#define VNC_MSG_SERVER_QEMU                       255



/* QEMU client -> server message IDs */
#define VNC_MSG_CLIENT_QEMU_EXT_KEY_EVENT         0
#define VNC_MSG_CLIENT_QEMU_AUDIO                 1

/* QEMU server -> client message IDs */
#define VNC_MSG_SERVER_QEMU_AUDIO                 1



/* QEMU client -> server audio message IDs */
#define VNC_MSG_CLIENT_QEMU_AUDIO_ENABLE          0
#define VNC_MSG_CLIENT_QEMU_AUDIO_DISABLE         1
#define VNC_MSG_CLIENT_QEMU_AUDIO_SET_FORMAT      2

/* QEMU server -> client audio message IDs */
#define VNC_MSG_SERVER_QEMU_AUDIO_END             0
#define VNC_MSG_SERVER_QEMU_AUDIO_BEGIN           1
#define VNC_MSG_SERVER_QEMU_AUDIO_DATA            2


508 509 510 511 512 513 514 515 516 517
/*****************************************************************************
 *
 * Internal APIs
 *
 *****************************************************************************/

/* Event loop functions */
void vnc_client_read(void *opaque);
void vnc_client_write(void *opaque);

518 519
long vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen);
long vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen);
520 521 522 523 524 525 526 527 528

/* Protocol I/O functions */
void vnc_write(VncState *vs, const void *data, size_t len);
void vnc_write_u32(VncState *vs, uint32_t value);
void vnc_write_s32(VncState *vs, int32_t value);
void vnc_write_u16(VncState *vs, uint16_t value);
void vnc_write_u8(VncState *vs, uint8_t value);
void vnc_flush(VncState *vs);
void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting);
529 530
void vnc_disconnect_finish(VncState *vs);
void vnc_init_state(VncState *vs);
531 532 533 534 535 536 537


/* Buffer I/O functions */
uint32_t read_u32(uint8_t *data, size_t offset);

/* Protocol stage functions */
void vnc_client_error(VncState *vs);
538
int vnc_client_io_error(VncState *vs, int ret, int last_errno);
539 540 541 542

void start_client_init(VncState *vs);
void start_auth_vnc(VncState *vs);

543 544 545
/* Buffer management */
void buffer_reserve(Buffer *buffer, size_t len);
void buffer_reset(Buffer *buffer);
C
Corentin Chary 已提交
546
void buffer_free(Buffer *buffer);
547
void buffer_append(Buffer *buffer, const void *data, size_t len);
T
Tim Hardeck 已提交
548
void buffer_advance(Buffer *buf, size_t len);
549
uint8_t *buffer_end(Buffer *buffer);
550 551 552 553 554 555 556


/* Misc helpers */

char *vnc_socket_local_addr(const char *format, int fd);
char *vnc_socket_remote_addr(const char *format, int fd);

C
Corentin Chary 已提交
557 558 559 560
static inline uint32_t vnc_has_feature(VncState *vs, int feature) {
    return (vs->features & (1 << feature));
}

561 562 563 564
/* Framebuffer */
void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
                            int32_t encoding);

565 566 567 568 569 570 571 572
/* server fb is in PIXMAN_x8r8g8b8 */
#define VNC_SERVER_FB_FORMAT PIXMAN_FORMAT(32, PIXMAN_TYPE_ARGB, 0, 8, 8, 8)
#define VNC_SERVER_FB_BITS   (PIXMAN_FORMAT_BPP(VNC_SERVER_FB_FORMAT))
#define VNC_SERVER_FB_BYTES  ((VNC_SERVER_FB_BITS+7)/8)

void *vnc_server_fb_ptr(VncDisplay *vd, int x, int y);
int vnc_server_fb_stride(VncDisplay *vd);

573
void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v);
574
double vnc_update_freq(VncState *vs, int x, int y, int w, int h);
575
void vnc_sent_lossy_rect(VncState *vs, int x, int y, int w, int h);
576 577

/* Encodings */
C
Corentin Chary 已提交
578 579
int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);

580
int vnc_raw_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
581

582
int vnc_hextile_send_framebuffer_update(VncState *vs, int x,
583 584 585
                                         int y, int w, int h);
void vnc_hextile_set_pixel_conversion(VncState *vs, int generic);

C
Corentin Chary 已提交
586 587
void *vnc_zlib_zalloc(void *x, unsigned items, unsigned size);
void vnc_zlib_zfree(void *x, void *addr);
588
int vnc_zlib_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
589
void vnc_zlib_clear(VncState *vs);
590

C
Corentin Chary 已提交
591
int vnc_tight_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
C
Corentin Chary 已提交
592 593
int vnc_tight_png_send_framebuffer_update(VncState *vs, int x, int y,
                                          int w, int h);
C
Corentin Chary 已提交
594 595
void vnc_tight_clear(VncState *vs);

596 597 598 599
int vnc_zrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
int vnc_zywrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
void vnc_zrle_clear(VncState *vs);

600
#endif /* __QEMU_VNC_H */