2
0

vnc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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/queue.h"
  29. #include "qemu/thread.h"
  30. #include "ui/console.h"
  31. #include "audio/audio.h"
  32. #include "qemu/bitmap.h"
  33. #include "crypto/tlssession.h"
  34. #include "qemu/buffer.h"
  35. #include "io/channel-socket.h"
  36. #include "io/channel-tls.h"
  37. #include "io/net-listener.h"
  38. #include "authz/base.h"
  39. #include <zlib.h>
  40. #include "keymaps.h"
  41. #include "vnc-palette.h"
  42. #include "vnc-enc-zrle.h"
  43. #include "ui/kbd-state.h"
  44. // #define _VNC_DEBUG 1
  45. #ifdef _VNC_DEBUG
  46. #define VNC_DEBUG(fmt, ...) do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
  47. #else
  48. #define VNC_DEBUG(fmt, ...) do { } while (0)
  49. #endif
  50. /*****************************************************************************
  51. *
  52. * Core data structures
  53. *
  54. *****************************************************************************/
  55. typedef struct VncState VncState;
  56. typedef struct VncJob VncJob;
  57. typedef struct VncRect VncRect;
  58. typedef struct VncRectEntry VncRectEntry;
  59. typedef int VncReadEvent(VncState *vs, uint8_t *data, size_t len);
  60. typedef void VncWritePixels(VncState *vs, void *data, int size);
  61. typedef void VncSendHextileTile(VncState *vs,
  62. int x, int y, int w, int h,
  63. void *last_bg,
  64. void *last_fg,
  65. int *has_bg, int *has_fg);
  66. /* VNC_DIRTY_PIXELS_PER_BIT is the number of dirty pixels represented
  67. * by one bit in the dirty bitmap, should be a power of 2 */
  68. #define VNC_DIRTY_PIXELS_PER_BIT 16
  69. /* VNC_MAX_WIDTH must be a multiple of VNC_DIRTY_PIXELS_PER_BIT. */
  70. #define VNC_MAX_WIDTH ROUND_UP(2560, VNC_DIRTY_PIXELS_PER_BIT)
  71. #define VNC_MAX_HEIGHT 2048
  72. /* VNC_DIRTY_BITS is the number of bits in the dirty bitmap. */
  73. #define VNC_DIRTY_BITS (VNC_MAX_WIDTH / VNC_DIRTY_PIXELS_PER_BIT)
  74. /* VNC_DIRTY_BPL (BPL = bits per line) might be greater than
  75. * VNC_DIRTY_BITS due to alignment */
  76. #define VNC_DIRTY_BPL(x) (sizeof((x)->dirty) / VNC_MAX_HEIGHT * BITS_PER_BYTE)
  77. #define VNC_STAT_RECT 64
  78. #define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT)
  79. #define VNC_STAT_ROWS (VNC_MAX_HEIGHT / VNC_STAT_RECT)
  80. #define VNC_AUTH_CHALLENGE_SIZE 16
  81. typedef struct VncDisplay VncDisplay;
  82. #include "vnc-auth-vencrypt.h"
  83. #ifdef CONFIG_VNC_SASL
  84. #include "vnc-auth-sasl.h"
  85. #endif
  86. #include "vnc-ws.h"
  87. struct VncRectStat
  88. {
  89. /* time of last 10 updates, to find update frequency */
  90. struct timeval times[10];
  91. int idx;
  92. double freq; /* Update frequency (in Hz) */
  93. bool updated; /* Already updated during this refresh */
  94. };
  95. typedef struct VncRectStat VncRectStat;
  96. struct VncSurface
  97. {
  98. struct timeval last_freq_check;
  99. DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT],
  100. VNC_MAX_WIDTH / VNC_DIRTY_PIXELS_PER_BIT);
  101. VncRectStat stats[VNC_STAT_ROWS][VNC_STAT_COLS];
  102. pixman_image_t *fb;
  103. pixman_format_code_t format;
  104. };
  105. typedef enum VncShareMode {
  106. VNC_SHARE_MODE_CONNECTING = 1,
  107. VNC_SHARE_MODE_SHARED,
  108. VNC_SHARE_MODE_EXCLUSIVE,
  109. VNC_SHARE_MODE_DISCONNECTED,
  110. } VncShareMode;
  111. typedef enum VncSharePolicy {
  112. VNC_SHARE_POLICY_IGNORE = 1,
  113. VNC_SHARE_POLICY_ALLOW_EXCLUSIVE,
  114. VNC_SHARE_POLICY_FORCE_SHARED,
  115. } VncSharePolicy;
  116. struct VncDisplay
  117. {
  118. QTAILQ_HEAD(, VncState) clients;
  119. int num_connecting;
  120. int num_shared;
  121. int num_exclusive;
  122. int connections_limit;
  123. VncSharePolicy share_policy;
  124. QIONetListener *listener;
  125. QIONetListener *wslistener;
  126. DisplaySurface *ds;
  127. DisplayChangeListener dcl;
  128. kbd_layout_t *kbd_layout;
  129. int lock_key_sync;
  130. QEMUPutLEDEntry *led;
  131. int ledstate;
  132. QKbdState *kbd;
  133. QemuMutex mutex;
  134. QEMUCursor *cursor;
  135. int cursor_msize;
  136. uint8_t *cursor_mask;
  137. struct VncSurface guest; /* guest visible surface (aka ds->surface) */
  138. pixman_image_t *server; /* vnc server surface */
  139. const char *id;
  140. QTAILQ_ENTRY(VncDisplay) next;
  141. bool is_unix;
  142. char *password;
  143. time_t expires;
  144. int auth;
  145. int subauth; /* Used by VeNCrypt */
  146. int ws_auth; /* Used by websockets */
  147. int ws_subauth; /* Used by websockets */
  148. bool lossy;
  149. bool non_adaptive;
  150. QCryptoTLSCreds *tlscreds;
  151. QAuthZ *tlsauthz;
  152. char *tlsauthzid;
  153. #ifdef CONFIG_VNC_SASL
  154. VncDisplaySASL sasl;
  155. #endif
  156. AudioState *audio_state;
  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. typedef enum {
  216. VNC_STATE_UPDATE_NONE,
  217. VNC_STATE_UPDATE_INCREMENTAL,
  218. VNC_STATE_UPDATE_FORCE,
  219. } VncStateUpdate;
  220. #define VNC_MAGIC ((uint64_t)0x05b3f069b3d204bb)
  221. struct VncState
  222. {
  223. uint64_t magic;
  224. QIOChannelSocket *sioc; /* The underlying socket */
  225. QIOChannel *ioc; /* The channel currently used for I/O */
  226. guint ioc_tag;
  227. gboolean disconnecting;
  228. DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT], VNC_DIRTY_BITS);
  229. uint8_t **lossy_rect; /* Not an Array to avoid costly memcpy in
  230. * vnc-jobs-async.c */
  231. VncDisplay *vd;
  232. VncStateUpdate update; /* Most recent pending request from client */
  233. VncStateUpdate job_update; /* Currently processed by job thread */
  234. int has_dirty;
  235. uint32_t features;
  236. int absolute;
  237. int last_x;
  238. int last_y;
  239. uint32_t last_bmask;
  240. size_t client_width; /* limited to u16 by RFB proto */
  241. size_t client_height; /* limited to u16 by RFB proto */
  242. VncShareMode share_mode;
  243. uint32_t vnc_encoding;
  244. int major;
  245. int minor;
  246. int auth;
  247. int subauth; /* Used by VeNCrypt */
  248. char challenge[VNC_AUTH_CHALLENGE_SIZE];
  249. QCryptoTLSSession *tls; /* Borrowed pointer from channel, don't free */
  250. #ifdef CONFIG_VNC_SASL
  251. VncStateSASL sasl;
  252. #endif
  253. bool encode_ws;
  254. bool websocket;
  255. #ifdef CONFIG_VNC
  256. VncClientInfo *info;
  257. #endif
  258. /* Job thread bottom half has put data for a forced update
  259. * into the output buffer. This offset points to the end of
  260. * the update data in the output buffer. This lets us determine
  261. * when a force update is fully sent to the client, allowing
  262. * us to process further forced updates. */
  263. size_t force_update_offset;
  264. /* We allow multiple incremental updates or audio capture
  265. * samples to be queued in output buffer, provided the
  266. * buffer size doesn't exceed this threshold. The value
  267. * is calculating dynamically based on framebuffer size
  268. * and audio sample settings in vnc_update_throttle_offset() */
  269. size_t throttle_output_offset;
  270. Buffer output;
  271. Buffer input;
  272. /* current output mode information */
  273. VncWritePixels *write_pixels;
  274. PixelFormat client_pf;
  275. pixman_format_code_t client_format;
  276. bool client_be;
  277. CaptureVoiceOut *audio_cap;
  278. struct audsettings as;
  279. VncReadEvent *read_handler;
  280. size_t read_handler_expect;
  281. bool abort;
  282. QemuMutex output_mutex;
  283. QEMUBH *bh;
  284. Buffer jobs_buffer;
  285. /* Encoding specific, if you add something here, don't forget to
  286. * update vnc_async_encoding_start()
  287. */
  288. VncTight *tight;
  289. VncZlib zlib;
  290. VncHextile hextile;
  291. VncZrle *zrle;
  292. VncZywrle zywrle;
  293. Notifier mouse_mode_notifier;
  294. QTAILQ_ENTRY(VncState) next;
  295. };
  296. /*****************************************************************************
  297. *
  298. * Authentication modes
  299. *
  300. *****************************************************************************/
  301. enum {
  302. VNC_AUTH_INVALID = 0,
  303. VNC_AUTH_NONE = 1,
  304. VNC_AUTH_VNC = 2,
  305. VNC_AUTH_RA2 = 5,
  306. VNC_AUTH_RA2NE = 6,
  307. VNC_AUTH_TIGHT = 16,
  308. VNC_AUTH_ULTRA = 17,
  309. VNC_AUTH_TLS = 18, /* Supported in GTK-VNC & VINO */
  310. VNC_AUTH_VENCRYPT = 19, /* Supported in GTK-VNC & VeNCrypt */
  311. VNC_AUTH_SASL = 20, /* Supported in GTK-VNC & VINO */
  312. };
  313. enum {
  314. VNC_AUTH_VENCRYPT_PLAIN = 256,
  315. VNC_AUTH_VENCRYPT_TLSNONE = 257,
  316. VNC_AUTH_VENCRYPT_TLSVNC = 258,
  317. VNC_AUTH_VENCRYPT_TLSPLAIN = 259,
  318. VNC_AUTH_VENCRYPT_X509NONE = 260,
  319. VNC_AUTH_VENCRYPT_X509VNC = 261,
  320. VNC_AUTH_VENCRYPT_X509PLAIN = 262,
  321. VNC_AUTH_VENCRYPT_X509SASL = 263,
  322. VNC_AUTH_VENCRYPT_TLSSASL = 264,
  323. };
  324. /*****************************************************************************
  325. *
  326. * Encoding types
  327. *
  328. *****************************************************************************/
  329. #define VNC_ENCODING_RAW 0x00000000
  330. #define VNC_ENCODING_COPYRECT 0x00000001
  331. #define VNC_ENCODING_RRE 0x00000002
  332. #define VNC_ENCODING_CORRE 0x00000004
  333. #define VNC_ENCODING_HEXTILE 0x00000005
  334. #define VNC_ENCODING_ZLIB 0x00000006
  335. #define VNC_ENCODING_TIGHT 0x00000007
  336. #define VNC_ENCODING_ZLIBHEX 0x00000008
  337. #define VNC_ENCODING_TRLE 0x0000000f
  338. #define VNC_ENCODING_ZRLE 0x00000010
  339. #define VNC_ENCODING_ZYWRLE 0x00000011
  340. #define VNC_ENCODING_COMPRESSLEVEL0 0xFFFFFF00 /* -256 */
  341. #define VNC_ENCODING_QUALITYLEVEL0 0xFFFFFFE0 /* -32 */
  342. #define VNC_ENCODING_XCURSOR 0xFFFFFF10 /* -240 */
  343. #define VNC_ENCODING_RICH_CURSOR 0xFFFFFF11 /* -239 */
  344. #define VNC_ENCODING_POINTER_POS 0xFFFFFF18 /* -232 */
  345. #define VNC_ENCODING_LASTRECT 0xFFFFFF20 /* -224 */
  346. #define VNC_ENCODING_DESKTOPRESIZE 0xFFFFFF21 /* -223 */
  347. #define VNC_ENCODING_POINTER_TYPE_CHANGE 0XFFFFFEFF /* -257 */
  348. #define VNC_ENCODING_EXT_KEY_EVENT 0XFFFFFEFE /* -258 */
  349. #define VNC_ENCODING_AUDIO 0XFFFFFEFD /* -259 */
  350. #define VNC_ENCODING_TIGHT_PNG 0xFFFFFEFC /* -260 */
  351. #define VNC_ENCODING_LED_STATE 0XFFFFFEFB /* -261 */
  352. #define VNC_ENCODING_WMVi 0x574D5669
  353. /*****************************************************************************
  354. *
  355. * Other tight constants
  356. *
  357. *****************************************************************************/
  358. /*
  359. * Vendors known by TightVNC: standard VNC/RealVNC, TridiaVNC, and TightVNC.
  360. */
  361. #define VNC_TIGHT_CCB_RESET_MASK (0x0f)
  362. #define VNC_TIGHT_CCB_TYPE_MASK (0x0f << 4)
  363. #define VNC_TIGHT_CCB_TYPE_FILL (0x08 << 4)
  364. #define VNC_TIGHT_CCB_TYPE_JPEG (0x09 << 4)
  365. #define VNC_TIGHT_CCB_TYPE_PNG (0x0A << 4)
  366. #define VNC_TIGHT_CCB_BASIC_MAX (0x07 << 4)
  367. #define VNC_TIGHT_CCB_BASIC_ZLIB (0x03 << 4)
  368. #define VNC_TIGHT_CCB_BASIC_FILTER (0x04 << 4)
  369. /*****************************************************************************
  370. *
  371. * Features
  372. *
  373. *****************************************************************************/
  374. #define VNC_FEATURE_RESIZE 0
  375. #define VNC_FEATURE_HEXTILE 1
  376. #define VNC_FEATURE_POINTER_TYPE_CHANGE 2
  377. #define VNC_FEATURE_WMVI 3
  378. #define VNC_FEATURE_TIGHT 4
  379. #define VNC_FEATURE_ZLIB 5
  380. #define VNC_FEATURE_COPYRECT 6
  381. #define VNC_FEATURE_RICH_CURSOR 7
  382. #define VNC_FEATURE_TIGHT_PNG 8
  383. #define VNC_FEATURE_ZRLE 9
  384. #define VNC_FEATURE_ZYWRLE 10
  385. #define VNC_FEATURE_LED_STATE 11
  386. #define VNC_FEATURE_RESIZE_MASK (1 << VNC_FEATURE_RESIZE)
  387. #define VNC_FEATURE_HEXTILE_MASK (1 << VNC_FEATURE_HEXTILE)
  388. #define VNC_FEATURE_POINTER_TYPE_CHANGE_MASK (1 << VNC_FEATURE_POINTER_TYPE_CHANGE)
  389. #define VNC_FEATURE_WMVI_MASK (1 << VNC_FEATURE_WMVI)
  390. #define VNC_FEATURE_TIGHT_MASK (1 << VNC_FEATURE_TIGHT)
  391. #define VNC_FEATURE_ZLIB_MASK (1 << VNC_FEATURE_ZLIB)
  392. #define VNC_FEATURE_COPYRECT_MASK (1 << VNC_FEATURE_COPYRECT)
  393. #define VNC_FEATURE_RICH_CURSOR_MASK (1 << VNC_FEATURE_RICH_CURSOR)
  394. #define VNC_FEATURE_TIGHT_PNG_MASK (1 << VNC_FEATURE_TIGHT_PNG)
  395. #define VNC_FEATURE_ZRLE_MASK (1 << VNC_FEATURE_ZRLE)
  396. #define VNC_FEATURE_ZYWRLE_MASK (1 << VNC_FEATURE_ZYWRLE)
  397. #define VNC_FEATURE_LED_STATE_MASK (1 << VNC_FEATURE_LED_STATE)
  398. /* Client -> Server message IDs */
  399. #define VNC_MSG_CLIENT_SET_PIXEL_FORMAT 0
  400. #define VNC_MSG_CLIENT_SET_ENCODINGS 2
  401. #define VNC_MSG_CLIENT_FRAMEBUFFER_UPDATE_REQUEST 3
  402. #define VNC_MSG_CLIENT_KEY_EVENT 4
  403. #define VNC_MSG_CLIENT_POINTER_EVENT 5
  404. #define VNC_MSG_CLIENT_CUT_TEXT 6
  405. #define VNC_MSG_CLIENT_VMWARE_0 127
  406. #define VNC_MSG_CLIENT_CALL_CONTROL 249
  407. #define VNC_MSG_CLIENT_XVP 250
  408. #define VNC_MSG_CLIENT_SET_DESKTOP_SIZE 251
  409. #define VNC_MSG_CLIENT_TIGHT 252
  410. #define VNC_MSG_CLIENT_GII 253
  411. #define VNC_MSG_CLIENT_VMWARE_1 254
  412. #define VNC_MSG_CLIENT_QEMU 255
  413. /* Server -> Client message IDs */
  414. #define VNC_MSG_SERVER_FRAMEBUFFER_UPDATE 0
  415. #define VNC_MSG_SERVER_SET_COLOUR_MAP_ENTRIES 1
  416. #define VNC_MSG_SERVER_BELL 2
  417. #define VNC_MSG_SERVER_CUT_TEXT 3
  418. #define VNC_MSG_SERVER_VMWARE_0 127
  419. #define VNC_MSG_SERVER_CALL_CONTROL 249
  420. #define VNC_MSG_SERVER_XVP 250
  421. #define VNC_MSG_SERVER_TIGHT 252
  422. #define VNC_MSG_SERVER_GII 253
  423. #define VNC_MSG_SERVER_VMWARE_1 254
  424. #define VNC_MSG_SERVER_QEMU 255
  425. /* QEMU client -> server message IDs */
  426. #define VNC_MSG_CLIENT_QEMU_EXT_KEY_EVENT 0
  427. #define VNC_MSG_CLIENT_QEMU_AUDIO 1
  428. /* QEMU server -> client message IDs */
  429. #define VNC_MSG_SERVER_QEMU_AUDIO 1
  430. /* QEMU client -> server audio message IDs */
  431. #define VNC_MSG_CLIENT_QEMU_AUDIO_ENABLE 0
  432. #define VNC_MSG_CLIENT_QEMU_AUDIO_DISABLE 1
  433. #define VNC_MSG_CLIENT_QEMU_AUDIO_SET_FORMAT 2
  434. /* QEMU server -> client audio message IDs */
  435. #define VNC_MSG_SERVER_QEMU_AUDIO_END 0
  436. #define VNC_MSG_SERVER_QEMU_AUDIO_BEGIN 1
  437. #define VNC_MSG_SERVER_QEMU_AUDIO_DATA 2
  438. /*****************************************************************************
  439. *
  440. * Internal APIs
  441. *
  442. *****************************************************************************/
  443. /* Event loop functions */
  444. gboolean vnc_client_io(QIOChannel *ioc,
  445. GIOCondition condition,
  446. void *opaque);
  447. size_t vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen);
  448. size_t vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen);
  449. /* Protocol I/O functions */
  450. void vnc_write(VncState *vs, const void *data, size_t len);
  451. void vnc_write_u32(VncState *vs, uint32_t value);
  452. void vnc_write_s32(VncState *vs, int32_t value);
  453. void vnc_write_u16(VncState *vs, uint16_t value);
  454. void vnc_write_u8(VncState *vs, uint8_t value);
  455. void vnc_flush(VncState *vs);
  456. void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting);
  457. void vnc_disconnect_finish(VncState *vs);
  458. void vnc_start_protocol(VncState *vs);
  459. /* Buffer I/O functions */
  460. uint32_t read_u32(uint8_t *data, size_t offset);
  461. /* Protocol stage functions */
  462. void vnc_client_error(VncState *vs);
  463. size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error *err);
  464. void start_client_init(VncState *vs);
  465. void start_auth_vnc(VncState *vs);
  466. /* Misc helpers */
  467. static inline uint32_t vnc_has_feature(VncState *vs, int feature) {
  468. return (vs->features & (1 << feature));
  469. }
  470. /* Framebuffer */
  471. void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
  472. int32_t encoding);
  473. /* server fb is in PIXMAN_x8r8g8b8 */
  474. #define VNC_SERVER_FB_FORMAT PIXMAN_FORMAT(32, PIXMAN_TYPE_ARGB, 0, 8, 8, 8)
  475. #define VNC_SERVER_FB_BITS (PIXMAN_FORMAT_BPP(VNC_SERVER_FB_FORMAT))
  476. #define VNC_SERVER_FB_BYTES ((VNC_SERVER_FB_BITS+7)/8)
  477. void *vnc_server_fb_ptr(VncDisplay *vd, int x, int y);
  478. int vnc_server_fb_stride(VncDisplay *vd);
  479. void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v);
  480. double vnc_update_freq(VncState *vs, int x, int y, int w, int h);
  481. void vnc_sent_lossy_rect(VncState *vs, int x, int y, int w, int h);
  482. /* Encodings */
  483. int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  484. int vnc_raw_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  485. int vnc_hextile_send_framebuffer_update(VncState *vs, int x,
  486. int y, int w, int h);
  487. void vnc_hextile_set_pixel_conversion(VncState *vs, int generic);
  488. void *vnc_zlib_zalloc(void *x, unsigned items, unsigned size);
  489. void vnc_zlib_zfree(void *x, void *addr);
  490. int vnc_zlib_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  491. void vnc_zlib_clear(VncState *vs);
  492. int vnc_tight_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  493. int vnc_tight_png_send_framebuffer_update(VncState *vs, int x, int y,
  494. int w, int h);
  495. void vnc_tight_clear(VncState *vs);
  496. int vnc_zrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  497. int vnc_zywrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  498. void vnc_zrle_clear(VncState *vs);
  499. #endif /* QEMU_VNC_H */