vnc.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. /*
  2. * QEMU VNC display driver
  3. *
  4. * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>
  5. * Copyright (C) 2006 Fabrice Bellard
  6. * Copyright (C) 2009 Red Hat, Inc
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  21. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #ifndef __QEMU_VNC_H
  27. #define __QEMU_VNC_H
  28. #include "qemu-common.h"
  29. #include "qemu/queue.h"
  30. #include "qemu/thread.h"
  31. #include "ui/console.h"
  32. #include "audio/audio.h"
  33. #include "qemu/bitmap.h"
  34. #include <zlib.h>
  35. #include <stdbool.h>
  36. #include "keymaps.h"
  37. #include "vnc-palette.h"
  38. #include "vnc-enc-zrle.h"
  39. #include "qapi-types.h"
  40. // #define _VNC_DEBUG 1
  41. #ifdef _VNC_DEBUG
  42. #define VNC_DEBUG(fmt, ...) do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
  43. #else
  44. #define VNC_DEBUG(fmt, ...) do { } while (0)
  45. #endif
  46. /*****************************************************************************
  47. *
  48. * Core data structures
  49. *
  50. *****************************************************************************/
  51. typedef struct Buffer
  52. {
  53. size_t capacity;
  54. size_t offset;
  55. uint8_t *buffer;
  56. } Buffer;
  57. typedef struct VncState VncState;
  58. typedef struct VncJob VncJob;
  59. typedef struct VncRect VncRect;
  60. typedef struct VncRectEntry VncRectEntry;
  61. typedef int VncReadEvent(VncState *vs, uint8_t *data, size_t len);
  62. typedef void VncWritePixels(VncState *vs, void *data, int size);
  63. typedef void VncSendHextileTile(VncState *vs,
  64. int x, int y, int w, int h,
  65. void *last_bg,
  66. void *last_fg,
  67. int *has_bg, int *has_fg);
  68. /* VNC_DIRTY_PIXELS_PER_BIT is the number of dirty pixels represented
  69. * by one bit in the dirty bitmap, should be a power of 2 */
  70. #define VNC_DIRTY_PIXELS_PER_BIT 16
  71. /* VNC_MAX_WIDTH must be a multiple of VNC_DIRTY_PIXELS_PER_BIT. */
  72. #define VNC_MAX_WIDTH ROUND_UP(2560, VNC_DIRTY_PIXELS_PER_BIT)
  73. #define VNC_MAX_HEIGHT 2048
  74. /* VNC_DIRTY_BITS is the number of bits in the dirty bitmap. */
  75. #define VNC_DIRTY_BITS (VNC_MAX_WIDTH / VNC_DIRTY_PIXELS_PER_BIT)
  76. /* VNC_DIRTY_BPL (BPL = bits per line) might be greater than
  77. * VNC_DIRTY_BITS due to alignment */
  78. #define VNC_DIRTY_BPL(x) (sizeof((x)->dirty) / VNC_MAX_HEIGHT * BITS_PER_BYTE)
  79. #define VNC_STAT_RECT 64
  80. #define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT)
  81. #define VNC_STAT_ROWS (VNC_MAX_HEIGHT / VNC_STAT_RECT)
  82. #define VNC_AUTH_CHALLENGE_SIZE 16
  83. typedef struct VncDisplay VncDisplay;
  84. #ifdef CONFIG_VNC_TLS
  85. #include "vnc-tls.h"
  86. #include "vnc-auth-vencrypt.h"
  87. #endif
  88. #ifdef CONFIG_VNC_SASL
  89. #include "vnc-auth-sasl.h"
  90. #endif
  91. #ifdef CONFIG_VNC_WS
  92. #include "vnc-ws.h"
  93. #endif
  94. struct VncRectStat
  95. {
  96. /* time of last 10 updates, to find update frequency */
  97. struct timeval times[10];
  98. int idx;
  99. double freq; /* Update frequency (in Hz) */
  100. bool updated; /* Already updated during this refresh */
  101. };
  102. typedef struct VncRectStat VncRectStat;
  103. struct VncSurface
  104. {
  105. struct timeval last_freq_check;
  106. DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT],
  107. VNC_MAX_WIDTH / VNC_DIRTY_PIXELS_PER_BIT);
  108. VncRectStat stats[VNC_STAT_ROWS][VNC_STAT_COLS];
  109. pixman_image_t *fb;
  110. pixman_format_code_t format;
  111. };
  112. typedef enum VncShareMode {
  113. VNC_SHARE_MODE_CONNECTING = 1,
  114. VNC_SHARE_MODE_SHARED,
  115. VNC_SHARE_MODE_EXCLUSIVE,
  116. VNC_SHARE_MODE_DISCONNECTED,
  117. } VncShareMode;
  118. typedef enum VncSharePolicy {
  119. VNC_SHARE_POLICY_IGNORE = 1,
  120. VNC_SHARE_POLICY_ALLOW_EXCLUSIVE,
  121. VNC_SHARE_POLICY_FORCE_SHARED,
  122. } VncSharePolicy;
  123. struct VncDisplay
  124. {
  125. QTAILQ_HEAD(, VncState) clients;
  126. int num_exclusive;
  127. VncSharePolicy share_policy;
  128. int lsock;
  129. #ifdef CONFIG_VNC_WS
  130. int lwebsock;
  131. bool websocket;
  132. char *ws_display;
  133. #endif
  134. DisplaySurface *ds;
  135. DisplayChangeListener dcl;
  136. kbd_layout_t *kbd_layout;
  137. int lock_key_sync;
  138. QemuMutex mutex;
  139. QEMUCursor *cursor;
  140. int cursor_msize;
  141. uint8_t *cursor_mask;
  142. struct VncSurface guest; /* guest visible surface (aka ds->surface) */
  143. pixman_image_t *server; /* vnc server surface */
  144. char *display;
  145. char *password;
  146. time_t expires;
  147. int auth;
  148. bool lossy;
  149. bool non_adaptive;
  150. #ifdef CONFIG_VNC_TLS
  151. int subauth; /* Used by VeNCrypt */
  152. VncDisplayTLS tls;
  153. #endif
  154. #ifdef CONFIG_VNC_SASL
  155. VncDisplaySASL sasl;
  156. #endif
  157. };
  158. typedef struct VncTight {
  159. int type;
  160. uint8_t quality;
  161. uint8_t compression;
  162. uint8_t pixel24;
  163. Buffer tight;
  164. Buffer tmp;
  165. Buffer zlib;
  166. Buffer gradient;
  167. #ifdef CONFIG_VNC_JPEG
  168. Buffer jpeg;
  169. #endif
  170. #ifdef CONFIG_VNC_PNG
  171. Buffer png;
  172. #endif
  173. int levels[4];
  174. z_stream stream[4];
  175. } VncTight;
  176. typedef struct VncHextile {
  177. VncSendHextileTile *send_tile;
  178. } VncHextile;
  179. typedef struct VncZlib {
  180. Buffer zlib;
  181. Buffer tmp;
  182. z_stream stream;
  183. int level;
  184. } VncZlib;
  185. typedef struct VncZrle {
  186. int type;
  187. Buffer fb;
  188. Buffer zrle;
  189. Buffer tmp;
  190. Buffer zlib;
  191. z_stream stream;
  192. VncPalette palette;
  193. } VncZrle;
  194. typedef struct VncZywrle {
  195. int buf[VNC_ZRLE_TILE_WIDTH * VNC_ZRLE_TILE_HEIGHT];
  196. } VncZywrle;
  197. struct VncRect
  198. {
  199. int x;
  200. int y;
  201. int w;
  202. int h;
  203. };
  204. struct VncRectEntry
  205. {
  206. struct VncRect rect;
  207. QLIST_ENTRY(VncRectEntry) next;
  208. };
  209. struct VncJob
  210. {
  211. VncState *vs;
  212. QLIST_HEAD(, VncRectEntry) rectangles;
  213. QTAILQ_ENTRY(VncJob) next;
  214. };
  215. struct VncState
  216. {
  217. int csock;
  218. DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT], VNC_DIRTY_BITS);
  219. uint8_t **lossy_rect; /* Not an Array to avoid costly memcpy in
  220. * vnc-jobs-async.c */
  221. VncDisplay *vd;
  222. int need_update;
  223. int force_update;
  224. int has_dirty;
  225. uint32_t features;
  226. int absolute;
  227. int last_x;
  228. int last_y;
  229. uint32_t last_bmask;
  230. int client_width;
  231. int client_height;
  232. VncShareMode share_mode;
  233. uint32_t vnc_encoding;
  234. int major;
  235. int minor;
  236. int auth;
  237. char challenge[VNC_AUTH_CHALLENGE_SIZE];
  238. #ifdef CONFIG_VNC_TLS
  239. int subauth; /* Used by VeNCrypt */
  240. VncStateTLS tls;
  241. #endif
  242. #ifdef CONFIG_VNC_SASL
  243. VncStateSASL sasl;
  244. #endif
  245. #ifdef CONFIG_VNC_WS
  246. #ifdef CONFIG_VNC_TLS
  247. VncStateTLS ws_tls;
  248. #endif /* CONFIG_VNC_TLS */
  249. bool encode_ws;
  250. bool websocket;
  251. #endif /* CONFIG_VNC_WS */
  252. VncClientInfo *info;
  253. Buffer output;
  254. Buffer input;
  255. #ifdef CONFIG_VNC_WS
  256. Buffer ws_input;
  257. Buffer ws_output;
  258. #endif
  259. /* current output mode information */
  260. VncWritePixels *write_pixels;
  261. PixelFormat client_pf;
  262. pixman_format_code_t client_format;
  263. bool client_be;
  264. CaptureVoiceOut *audio_cap;
  265. struct audsettings as;
  266. VncReadEvent *read_handler;
  267. size_t read_handler_expect;
  268. /* input */
  269. uint8_t modifiers_state[256];
  270. QEMUPutLEDEntry *led;
  271. bool abort;
  272. bool initialized;
  273. QemuMutex output_mutex;
  274. QEMUBH *bh;
  275. Buffer jobs_buffer;
  276. /* Encoding specific, if you add something here, don't forget to
  277. * update vnc_async_encoding_start()
  278. */
  279. VncTight tight;
  280. VncZlib zlib;
  281. VncHextile hextile;
  282. VncZrle zrle;
  283. VncZywrle zywrle;
  284. Notifier mouse_mode_notifier;
  285. QTAILQ_ENTRY(VncState) next;
  286. };
  287. /*****************************************************************************
  288. *
  289. * Authentication modes
  290. *
  291. *****************************************************************************/
  292. enum {
  293. VNC_AUTH_INVALID = 0,
  294. VNC_AUTH_NONE = 1,
  295. VNC_AUTH_VNC = 2,
  296. VNC_AUTH_RA2 = 5,
  297. VNC_AUTH_RA2NE = 6,
  298. VNC_AUTH_TIGHT = 16,
  299. VNC_AUTH_ULTRA = 17,
  300. VNC_AUTH_TLS = 18, /* Supported in GTK-VNC & VINO */
  301. VNC_AUTH_VENCRYPT = 19, /* Supported in GTK-VNC & VeNCrypt */
  302. VNC_AUTH_SASL = 20, /* Supported in GTK-VNC & VINO */
  303. };
  304. enum {
  305. VNC_AUTH_VENCRYPT_PLAIN = 256,
  306. VNC_AUTH_VENCRYPT_TLSNONE = 257,
  307. VNC_AUTH_VENCRYPT_TLSVNC = 258,
  308. VNC_AUTH_VENCRYPT_TLSPLAIN = 259,
  309. VNC_AUTH_VENCRYPT_X509NONE = 260,
  310. VNC_AUTH_VENCRYPT_X509VNC = 261,
  311. VNC_AUTH_VENCRYPT_X509PLAIN = 262,
  312. VNC_AUTH_VENCRYPT_X509SASL = 263,
  313. VNC_AUTH_VENCRYPT_TLSSASL = 264,
  314. };
  315. /*****************************************************************************
  316. *
  317. * Encoding types
  318. *
  319. *****************************************************************************/
  320. #define VNC_ENCODING_RAW 0x00000000
  321. #define VNC_ENCODING_COPYRECT 0x00000001
  322. #define VNC_ENCODING_RRE 0x00000002
  323. #define VNC_ENCODING_CORRE 0x00000004
  324. #define VNC_ENCODING_HEXTILE 0x00000005
  325. #define VNC_ENCODING_ZLIB 0x00000006
  326. #define VNC_ENCODING_TIGHT 0x00000007
  327. #define VNC_ENCODING_ZLIBHEX 0x00000008
  328. #define VNC_ENCODING_TRLE 0x0000000f
  329. #define VNC_ENCODING_ZRLE 0x00000010
  330. #define VNC_ENCODING_ZYWRLE 0x00000011
  331. #define VNC_ENCODING_COMPRESSLEVEL0 0xFFFFFF00 /* -256 */
  332. #define VNC_ENCODING_QUALITYLEVEL0 0xFFFFFFE0 /* -32 */
  333. #define VNC_ENCODING_XCURSOR 0xFFFFFF10 /* -240 */
  334. #define VNC_ENCODING_RICH_CURSOR 0xFFFFFF11 /* -239 */
  335. #define VNC_ENCODING_POINTER_POS 0xFFFFFF18 /* -232 */
  336. #define VNC_ENCODING_LASTRECT 0xFFFFFF20 /* -224 */
  337. #define VNC_ENCODING_DESKTOPRESIZE 0xFFFFFF21 /* -223 */
  338. #define VNC_ENCODING_POINTER_TYPE_CHANGE 0XFFFFFEFF /* -257 */
  339. #define VNC_ENCODING_EXT_KEY_EVENT 0XFFFFFEFE /* -258 */
  340. #define VNC_ENCODING_AUDIO 0XFFFFFEFD /* -259 */
  341. #define VNC_ENCODING_TIGHT_PNG 0xFFFFFEFC /* -260 */
  342. #define VNC_ENCODING_LED_STATE 0XFFFFFEFB /* -261 */
  343. #define VNC_ENCODING_WMVi 0x574D5669
  344. /*****************************************************************************
  345. *
  346. * Other tight constants
  347. *
  348. *****************************************************************************/
  349. /*
  350. * Vendors known by TightVNC: standard VNC/RealVNC, TridiaVNC, and TightVNC.
  351. */
  352. #define VNC_TIGHT_CCB_RESET_MASK (0x0f)
  353. #define VNC_TIGHT_CCB_TYPE_MASK (0x0f << 4)
  354. #define VNC_TIGHT_CCB_TYPE_FILL (0x08 << 4)
  355. #define VNC_TIGHT_CCB_TYPE_JPEG (0x09 << 4)
  356. #define VNC_TIGHT_CCB_TYPE_PNG (0x0A << 4)
  357. #define VNC_TIGHT_CCB_BASIC_MAX (0x07 << 4)
  358. #define VNC_TIGHT_CCB_BASIC_ZLIB (0x03 << 4)
  359. #define VNC_TIGHT_CCB_BASIC_FILTER (0x04 << 4)
  360. /*****************************************************************************
  361. *
  362. * Features
  363. *
  364. *****************************************************************************/
  365. #define VNC_FEATURE_RESIZE 0
  366. #define VNC_FEATURE_HEXTILE 1
  367. #define VNC_FEATURE_POINTER_TYPE_CHANGE 2
  368. #define VNC_FEATURE_WMVI 3
  369. #define VNC_FEATURE_TIGHT 4
  370. #define VNC_FEATURE_ZLIB 5
  371. #define VNC_FEATURE_COPYRECT 6
  372. #define VNC_FEATURE_RICH_CURSOR 7
  373. #define VNC_FEATURE_TIGHT_PNG 8
  374. #define VNC_FEATURE_ZRLE 9
  375. #define VNC_FEATURE_ZYWRLE 10
  376. #define VNC_FEATURE_LED_STATE 11
  377. #define VNC_FEATURE_RESIZE_MASK (1 << VNC_FEATURE_RESIZE)
  378. #define VNC_FEATURE_HEXTILE_MASK (1 << VNC_FEATURE_HEXTILE)
  379. #define VNC_FEATURE_POINTER_TYPE_CHANGE_MASK (1 << VNC_FEATURE_POINTER_TYPE_CHANGE)
  380. #define VNC_FEATURE_WMVI_MASK (1 << VNC_FEATURE_WMVI)
  381. #define VNC_FEATURE_TIGHT_MASK (1 << VNC_FEATURE_TIGHT)
  382. #define VNC_FEATURE_ZLIB_MASK (1 << VNC_FEATURE_ZLIB)
  383. #define VNC_FEATURE_COPYRECT_MASK (1 << VNC_FEATURE_COPYRECT)
  384. #define VNC_FEATURE_RICH_CURSOR_MASK (1 << VNC_FEATURE_RICH_CURSOR)
  385. #define VNC_FEATURE_TIGHT_PNG_MASK (1 << VNC_FEATURE_TIGHT_PNG)
  386. #define VNC_FEATURE_ZRLE_MASK (1 << VNC_FEATURE_ZRLE)
  387. #define VNC_FEATURE_ZYWRLE_MASK (1 << VNC_FEATURE_ZYWRLE)
  388. #define VNC_FEATURE_LED_STATE_MASK (1 << VNC_FEATURE_LED_STATE)
  389. /* Client -> Server message IDs */
  390. #define VNC_MSG_CLIENT_SET_PIXEL_FORMAT 0
  391. #define VNC_MSG_CLIENT_SET_ENCODINGS 2
  392. #define VNC_MSG_CLIENT_FRAMEBUFFER_UPDATE_REQUEST 3
  393. #define VNC_MSG_CLIENT_KEY_EVENT 4
  394. #define VNC_MSG_CLIENT_POINTER_EVENT 5
  395. #define VNC_MSG_CLIENT_CUT_TEXT 6
  396. #define VNC_MSG_CLIENT_VMWARE_0 127
  397. #define VNC_MSG_CLIENT_CALL_CONTROL 249
  398. #define VNC_MSG_CLIENT_XVP 250
  399. #define VNC_MSG_CLIENT_SET_DESKTOP_SIZE 251
  400. #define VNC_MSG_CLIENT_TIGHT 252
  401. #define VNC_MSG_CLIENT_GII 253
  402. #define VNC_MSG_CLIENT_VMWARE_1 254
  403. #define VNC_MSG_CLIENT_QEMU 255
  404. /* Server -> Client message IDs */
  405. #define VNC_MSG_SERVER_FRAMEBUFFER_UPDATE 0
  406. #define VNC_MSG_SERVER_SET_COLOUR_MAP_ENTRIES 1
  407. #define VNC_MSG_SERVER_BELL 2
  408. #define VNC_MSG_SERVER_CUT_TEXT 3
  409. #define VNC_MSG_SERVER_VMWARE_0 127
  410. #define VNC_MSG_SERVER_CALL_CONTROL 249
  411. #define VNC_MSG_SERVER_XVP 250
  412. #define VNC_MSG_SERVER_TIGHT 252
  413. #define VNC_MSG_SERVER_GII 253
  414. #define VNC_MSG_SERVER_VMWARE_1 254
  415. #define VNC_MSG_SERVER_QEMU 255
  416. /* QEMU client -> server message IDs */
  417. #define VNC_MSG_CLIENT_QEMU_EXT_KEY_EVENT 0
  418. #define VNC_MSG_CLIENT_QEMU_AUDIO 1
  419. /* QEMU server -> client message IDs */
  420. #define VNC_MSG_SERVER_QEMU_AUDIO 1
  421. /* QEMU client -> server audio message IDs */
  422. #define VNC_MSG_CLIENT_QEMU_AUDIO_ENABLE 0
  423. #define VNC_MSG_CLIENT_QEMU_AUDIO_DISABLE 1
  424. #define VNC_MSG_CLIENT_QEMU_AUDIO_SET_FORMAT 2
  425. /* QEMU server -> client audio message IDs */
  426. #define VNC_MSG_SERVER_QEMU_AUDIO_END 0
  427. #define VNC_MSG_SERVER_QEMU_AUDIO_BEGIN 1
  428. #define VNC_MSG_SERVER_QEMU_AUDIO_DATA 2
  429. /*****************************************************************************
  430. *
  431. * Internal APIs
  432. *
  433. *****************************************************************************/
  434. /* Event loop functions */
  435. void vnc_client_read(void *opaque);
  436. void vnc_client_write(void *opaque);
  437. long vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen);
  438. long vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen);
  439. /* Protocol I/O functions */
  440. void vnc_write(VncState *vs, const void *data, size_t len);
  441. void vnc_write_u32(VncState *vs, uint32_t value);
  442. void vnc_write_s32(VncState *vs, int32_t value);
  443. void vnc_write_u16(VncState *vs, uint16_t value);
  444. void vnc_write_u8(VncState *vs, uint8_t value);
  445. void vnc_flush(VncState *vs);
  446. void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting);
  447. void vnc_disconnect_finish(VncState *vs);
  448. void vnc_init_state(VncState *vs);
  449. /* Buffer I/O functions */
  450. uint32_t read_u32(uint8_t *data, size_t offset);
  451. /* Protocol stage functions */
  452. void vnc_client_error(VncState *vs);
  453. int vnc_client_io_error(VncState *vs, int ret, int last_errno);
  454. void start_client_init(VncState *vs);
  455. void start_auth_vnc(VncState *vs);
  456. /* Buffer management */
  457. void buffer_reserve(Buffer *buffer, size_t len);
  458. void buffer_reset(Buffer *buffer);
  459. void buffer_free(Buffer *buffer);
  460. void buffer_append(Buffer *buffer, const void *data, size_t len);
  461. void buffer_advance(Buffer *buf, size_t len);
  462. uint8_t *buffer_end(Buffer *buffer);
  463. /* Misc helpers */
  464. char *vnc_socket_local_addr(const char *format, int fd);
  465. char *vnc_socket_remote_addr(const char *format, int fd);
  466. static inline uint32_t vnc_has_feature(VncState *vs, int feature) {
  467. return (vs->features & (1 << feature));
  468. }
  469. /* Framebuffer */
  470. void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
  471. int32_t encoding);
  472. /* server fb is in PIXMAN_x8r8g8b8 */
  473. #define VNC_SERVER_FB_FORMAT PIXMAN_FORMAT(32, PIXMAN_TYPE_ARGB, 0, 8, 8, 8)
  474. #define VNC_SERVER_FB_BITS (PIXMAN_FORMAT_BPP(VNC_SERVER_FB_FORMAT))
  475. #define VNC_SERVER_FB_BYTES ((VNC_SERVER_FB_BITS+7)/8)
  476. void *vnc_server_fb_ptr(VncDisplay *vd, int x, int y);
  477. int vnc_server_fb_stride(VncDisplay *vd);
  478. void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v);
  479. double vnc_update_freq(VncState *vs, int x, int y, int w, int h);
  480. void vnc_sent_lossy_rect(VncState *vs, int x, int y, int w, int h);
  481. /* Encodings */
  482. int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  483. int vnc_raw_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  484. int vnc_hextile_send_framebuffer_update(VncState *vs, int x,
  485. int y, int w, int h);
  486. void vnc_hextile_set_pixel_conversion(VncState *vs, int generic);
  487. void *vnc_zlib_zalloc(void *x, unsigned items, unsigned size);
  488. void vnc_zlib_zfree(void *x, void *addr);
  489. int vnc_zlib_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  490. void vnc_zlib_clear(VncState *vs);
  491. int vnc_tight_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  492. int vnc_tight_png_send_framebuffer_update(VncState *vs, int x, int y,
  493. int w, int h);
  494. void vnc_tight_clear(VncState *vs);
  495. int vnc_zrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  496. int vnc_zywrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  497. void vnc_zrle_clear(VncState *vs);
  498. #endif /* __QEMU_VNC_H */