vnc.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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 "monitor/monitor.h"
  33. #include "audio/audio.h"
  34. #include "qemu/bitmap.h"
  35. #include <zlib.h>
  36. #include <stdbool.h>
  37. #include "keymaps.h"
  38. #include "vnc-palette.h"
  39. #include "vnc-enc-zrle.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_MAX_WIDTH must be a multiple of 16. */
  69. #define VNC_MAX_WIDTH 2560
  70. #define VNC_MAX_HEIGHT 2048
  71. /* VNC_DIRTY_PIXELS_PER_BIT is the number of dirty pixels represented
  72. * by one bit in the dirty bitmap */
  73. #define VNC_DIRTY_PIXELS_PER_BIT 16
  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], VNC_MAX_WIDTH / 16);
  107. VncRectStat stats[VNC_STAT_ROWS][VNC_STAT_COLS];
  108. pixman_image_t *fb;
  109. pixman_format_code_t format;
  110. };
  111. typedef enum VncShareMode {
  112. VNC_SHARE_MODE_CONNECTING = 1,
  113. VNC_SHARE_MODE_SHARED,
  114. VNC_SHARE_MODE_EXCLUSIVE,
  115. VNC_SHARE_MODE_DISCONNECTED,
  116. } VncShareMode;
  117. typedef enum VncSharePolicy {
  118. VNC_SHARE_POLICY_IGNORE = 1,
  119. VNC_SHARE_POLICY_ALLOW_EXCLUSIVE,
  120. VNC_SHARE_POLICY_FORCE_SHARED,
  121. } VncSharePolicy;
  122. struct VncDisplay
  123. {
  124. QTAILQ_HEAD(, VncState) clients;
  125. int num_exclusive;
  126. VncSharePolicy share_policy;
  127. int lsock;
  128. #ifdef CONFIG_VNC_WS
  129. int lwebsock;
  130. bool websocket;
  131. char *ws_display;
  132. #endif
  133. DisplaySurface *ds;
  134. DisplayChangeListener dcl;
  135. kbd_layout_t *kbd_layout;
  136. int lock_key_sync;
  137. QemuMutex mutex;
  138. QEMUCursor *cursor;
  139. int cursor_msize;
  140. uint8_t *cursor_mask;
  141. struct VncSurface guest; /* guest visible surface (aka ds->surface) */
  142. pixman_image_t *server; /* vnc server surface */
  143. char *display;
  144. char *password;
  145. time_t expires;
  146. int auth;
  147. bool lossy;
  148. bool non_adaptive;
  149. #ifdef CONFIG_VNC_TLS
  150. int subauth; /* Used by VeNCrypt */
  151. VncDisplayTLS tls;
  152. #endif
  153. #ifdef CONFIG_VNC_SASL
  154. VncDisplaySASL sasl;
  155. #endif
  156. };
  157. typedef struct VncTight {
  158. int type;
  159. uint8_t quality;
  160. uint8_t compression;
  161. uint8_t pixel24;
  162. Buffer tight;
  163. Buffer tmp;
  164. Buffer zlib;
  165. Buffer gradient;
  166. #ifdef CONFIG_VNC_JPEG
  167. Buffer jpeg;
  168. #endif
  169. #ifdef CONFIG_VNC_PNG
  170. Buffer png;
  171. #endif
  172. int levels[4];
  173. z_stream stream[4];
  174. } VncTight;
  175. typedef struct VncHextile {
  176. VncSendHextileTile *send_tile;
  177. } VncHextile;
  178. typedef struct VncZlib {
  179. Buffer zlib;
  180. Buffer tmp;
  181. z_stream stream;
  182. int level;
  183. } VncZlib;
  184. typedef struct VncZrle {
  185. int type;
  186. Buffer fb;
  187. Buffer zrle;
  188. Buffer tmp;
  189. Buffer zlib;
  190. z_stream stream;
  191. VncPalette palette;
  192. } VncZrle;
  193. typedef struct VncZywrle {
  194. int buf[VNC_ZRLE_TILE_WIDTH * VNC_ZRLE_TILE_HEIGHT];
  195. } VncZywrle;
  196. struct VncRect
  197. {
  198. int x;
  199. int y;
  200. int w;
  201. int h;
  202. };
  203. struct VncRectEntry
  204. {
  205. struct VncRect rect;
  206. QLIST_ENTRY(VncRectEntry) next;
  207. };
  208. struct VncJob
  209. {
  210. VncState *vs;
  211. QLIST_HEAD(, VncRectEntry) rectangles;
  212. QTAILQ_ENTRY(VncJob) next;
  213. };
  214. struct VncState
  215. {
  216. int csock;
  217. DECLARE_BITMAP(dirty[VNC_MAX_HEIGHT], VNC_DIRTY_BITS);
  218. uint8_t **lossy_rect; /* Not an Array to avoid costly memcpy in
  219. * vnc-jobs-async.c */
  220. VncDisplay *vd;
  221. int need_update;
  222. int force_update;
  223. uint32_t features;
  224. int absolute;
  225. int last_x;
  226. int last_y;
  227. uint32_t last_bmask;
  228. int client_width;
  229. int client_height;
  230. VncShareMode share_mode;
  231. uint32_t vnc_encoding;
  232. int major;
  233. int minor;
  234. int auth;
  235. char challenge[VNC_AUTH_CHALLENGE_SIZE];
  236. #ifdef CONFIG_VNC_TLS
  237. int subauth; /* Used by VeNCrypt */
  238. VncStateTLS tls;
  239. #endif
  240. #ifdef CONFIG_VNC_SASL
  241. VncStateSASL sasl;
  242. #endif
  243. #ifdef CONFIG_VNC_WS
  244. #ifdef CONFIG_VNC_TLS
  245. VncStateTLS ws_tls;
  246. #endif /* CONFIG_VNC_TLS */
  247. bool encode_ws;
  248. bool websocket;
  249. #endif /* CONFIG_VNC_WS */
  250. QObject *info;
  251. Buffer output;
  252. Buffer input;
  253. #ifdef CONFIG_VNC_WS
  254. Buffer ws_input;
  255. Buffer ws_output;
  256. #endif
  257. /* current output mode information */
  258. VncWritePixels *write_pixels;
  259. PixelFormat client_pf;
  260. pixman_format_code_t client_format;
  261. bool client_be;
  262. CaptureVoiceOut *audio_cap;
  263. struct audsettings as;
  264. VncReadEvent *read_handler;
  265. size_t read_handler_expect;
  266. /* input */
  267. uint8_t modifiers_state[256];
  268. QEMUPutLEDEntry *led;
  269. bool abort;
  270. bool initialized;
  271. QemuMutex output_mutex;
  272. QEMUBH *bh;
  273. Buffer jobs_buffer;
  274. /* Encoding specific, if you add something here, don't forget to
  275. * update vnc_async_encoding_start()
  276. */
  277. VncTight tight;
  278. VncZlib zlib;
  279. VncHextile hextile;
  280. VncZrle zrle;
  281. VncZywrle zywrle;
  282. Notifier mouse_mode_notifier;
  283. QTAILQ_ENTRY(VncState) next;
  284. };
  285. /*****************************************************************************
  286. *
  287. * Authentication modes
  288. *
  289. *****************************************************************************/
  290. enum {
  291. VNC_AUTH_INVALID = 0,
  292. VNC_AUTH_NONE = 1,
  293. VNC_AUTH_VNC = 2,
  294. VNC_AUTH_RA2 = 5,
  295. VNC_AUTH_RA2NE = 6,
  296. VNC_AUTH_TIGHT = 16,
  297. VNC_AUTH_ULTRA = 17,
  298. VNC_AUTH_TLS = 18, /* Supported in GTK-VNC & VINO */
  299. VNC_AUTH_VENCRYPT = 19, /* Supported in GTK-VNC & VeNCrypt */
  300. VNC_AUTH_SASL = 20, /* Supported in GTK-VNC & VINO */
  301. };
  302. enum {
  303. VNC_AUTH_VENCRYPT_PLAIN = 256,
  304. VNC_AUTH_VENCRYPT_TLSNONE = 257,
  305. VNC_AUTH_VENCRYPT_TLSVNC = 258,
  306. VNC_AUTH_VENCRYPT_TLSPLAIN = 259,
  307. VNC_AUTH_VENCRYPT_X509NONE = 260,
  308. VNC_AUTH_VENCRYPT_X509VNC = 261,
  309. VNC_AUTH_VENCRYPT_X509PLAIN = 262,
  310. VNC_AUTH_VENCRYPT_X509SASL = 263,
  311. VNC_AUTH_VENCRYPT_TLSSASL = 264,
  312. };
  313. /*****************************************************************************
  314. *
  315. * Encoding types
  316. *
  317. *****************************************************************************/
  318. #define VNC_ENCODING_RAW 0x00000000
  319. #define VNC_ENCODING_COPYRECT 0x00000001
  320. #define VNC_ENCODING_RRE 0x00000002
  321. #define VNC_ENCODING_CORRE 0x00000004
  322. #define VNC_ENCODING_HEXTILE 0x00000005
  323. #define VNC_ENCODING_ZLIB 0x00000006
  324. #define VNC_ENCODING_TIGHT 0x00000007
  325. #define VNC_ENCODING_ZLIBHEX 0x00000008
  326. #define VNC_ENCODING_TRLE 0x0000000f
  327. #define VNC_ENCODING_ZRLE 0x00000010
  328. #define VNC_ENCODING_ZYWRLE 0x00000011
  329. #define VNC_ENCODING_COMPRESSLEVEL0 0xFFFFFF00 /* -256 */
  330. #define VNC_ENCODING_QUALITYLEVEL0 0xFFFFFFE0 /* -32 */
  331. #define VNC_ENCODING_XCURSOR 0xFFFFFF10 /* -240 */
  332. #define VNC_ENCODING_RICH_CURSOR 0xFFFFFF11 /* -239 */
  333. #define VNC_ENCODING_POINTER_POS 0xFFFFFF18 /* -232 */
  334. #define VNC_ENCODING_LASTRECT 0xFFFFFF20 /* -224 */
  335. #define VNC_ENCODING_DESKTOPRESIZE 0xFFFFFF21 /* -223 */
  336. #define VNC_ENCODING_POINTER_TYPE_CHANGE 0XFFFFFEFF /* -257 */
  337. #define VNC_ENCODING_EXT_KEY_EVENT 0XFFFFFEFE /* -258 */
  338. #define VNC_ENCODING_AUDIO 0XFFFFFEFD /* -259 */
  339. #define VNC_ENCODING_TIGHT_PNG 0xFFFFFEFC /* -260 */
  340. #define VNC_ENCODING_LED_STATE 0XFFFFFEFB /* -261 */
  341. #define VNC_ENCODING_WMVi 0x574D5669
  342. /*****************************************************************************
  343. *
  344. * Other tight constants
  345. *
  346. *****************************************************************************/
  347. /*
  348. * Vendors known by TightVNC: standard VNC/RealVNC, TridiaVNC, and TightVNC.
  349. */
  350. #define VNC_TIGHT_CCB_RESET_MASK (0x0f)
  351. #define VNC_TIGHT_CCB_TYPE_MASK (0x0f << 4)
  352. #define VNC_TIGHT_CCB_TYPE_FILL (0x08 << 4)
  353. #define VNC_TIGHT_CCB_TYPE_JPEG (0x09 << 4)
  354. #define VNC_TIGHT_CCB_TYPE_PNG (0x0A << 4)
  355. #define VNC_TIGHT_CCB_BASIC_MAX (0x07 << 4)
  356. #define VNC_TIGHT_CCB_BASIC_ZLIB (0x03 << 4)
  357. #define VNC_TIGHT_CCB_BASIC_FILTER (0x04 << 4)
  358. /*****************************************************************************
  359. *
  360. * Features
  361. *
  362. *****************************************************************************/
  363. #define VNC_FEATURE_RESIZE 0
  364. #define VNC_FEATURE_HEXTILE 1
  365. #define VNC_FEATURE_POINTER_TYPE_CHANGE 2
  366. #define VNC_FEATURE_WMVI 3
  367. #define VNC_FEATURE_TIGHT 4
  368. #define VNC_FEATURE_ZLIB 5
  369. #define VNC_FEATURE_COPYRECT 6
  370. #define VNC_FEATURE_RICH_CURSOR 7
  371. #define VNC_FEATURE_TIGHT_PNG 8
  372. #define VNC_FEATURE_ZRLE 9
  373. #define VNC_FEATURE_ZYWRLE 10
  374. #define VNC_FEATURE_LED_STATE 11
  375. #define VNC_FEATURE_RESIZE_MASK (1 << VNC_FEATURE_RESIZE)
  376. #define VNC_FEATURE_HEXTILE_MASK (1 << VNC_FEATURE_HEXTILE)
  377. #define VNC_FEATURE_POINTER_TYPE_CHANGE_MASK (1 << VNC_FEATURE_POINTER_TYPE_CHANGE)
  378. #define VNC_FEATURE_WMVI_MASK (1 << VNC_FEATURE_WMVI)
  379. #define VNC_FEATURE_TIGHT_MASK (1 << VNC_FEATURE_TIGHT)
  380. #define VNC_FEATURE_ZLIB_MASK (1 << VNC_FEATURE_ZLIB)
  381. #define VNC_FEATURE_COPYRECT_MASK (1 << VNC_FEATURE_COPYRECT)
  382. #define VNC_FEATURE_RICH_CURSOR_MASK (1 << VNC_FEATURE_RICH_CURSOR)
  383. #define VNC_FEATURE_TIGHT_PNG_MASK (1 << VNC_FEATURE_TIGHT_PNG)
  384. #define VNC_FEATURE_ZRLE_MASK (1 << VNC_FEATURE_ZRLE)
  385. #define VNC_FEATURE_ZYWRLE_MASK (1 << VNC_FEATURE_ZYWRLE)
  386. #define VNC_FEATURE_LED_STATE_MASK (1 << VNC_FEATURE_LED_STATE)
  387. /* Client -> Server message IDs */
  388. #define VNC_MSG_CLIENT_SET_PIXEL_FORMAT 0
  389. #define VNC_MSG_CLIENT_SET_ENCODINGS 2
  390. #define VNC_MSG_CLIENT_FRAMEBUFFER_UPDATE_REQUEST 3
  391. #define VNC_MSG_CLIENT_KEY_EVENT 4
  392. #define VNC_MSG_CLIENT_POINTER_EVENT 5
  393. #define VNC_MSG_CLIENT_CUT_TEXT 6
  394. #define VNC_MSG_CLIENT_VMWARE_0 127
  395. #define VNC_MSG_CLIENT_CALL_CONTROL 249
  396. #define VNC_MSG_CLIENT_XVP 250
  397. #define VNC_MSG_CLIENT_SET_DESKTOP_SIZE 251
  398. #define VNC_MSG_CLIENT_TIGHT 252
  399. #define VNC_MSG_CLIENT_GII 253
  400. #define VNC_MSG_CLIENT_VMWARE_1 254
  401. #define VNC_MSG_CLIENT_QEMU 255
  402. /* Server -> Client message IDs */
  403. #define VNC_MSG_SERVER_FRAMEBUFFER_UPDATE 0
  404. #define VNC_MSG_SERVER_SET_COLOUR_MAP_ENTRIES 1
  405. #define VNC_MSG_SERVER_BELL 2
  406. #define VNC_MSG_SERVER_CUT_TEXT 3
  407. #define VNC_MSG_SERVER_VMWARE_0 127
  408. #define VNC_MSG_SERVER_CALL_CONTROL 249
  409. #define VNC_MSG_SERVER_XVP 250
  410. #define VNC_MSG_SERVER_TIGHT 252
  411. #define VNC_MSG_SERVER_GII 253
  412. #define VNC_MSG_SERVER_VMWARE_1 254
  413. #define VNC_MSG_SERVER_QEMU 255
  414. /* QEMU client -> server message IDs */
  415. #define VNC_MSG_CLIENT_QEMU_EXT_KEY_EVENT 0
  416. #define VNC_MSG_CLIENT_QEMU_AUDIO 1
  417. /* QEMU server -> client message IDs */
  418. #define VNC_MSG_SERVER_QEMU_AUDIO 1
  419. /* QEMU client -> server audio message IDs */
  420. #define VNC_MSG_CLIENT_QEMU_AUDIO_ENABLE 0
  421. #define VNC_MSG_CLIENT_QEMU_AUDIO_DISABLE 1
  422. #define VNC_MSG_CLIENT_QEMU_AUDIO_SET_FORMAT 2
  423. /* QEMU server -> client audio message IDs */
  424. #define VNC_MSG_SERVER_QEMU_AUDIO_END 0
  425. #define VNC_MSG_SERVER_QEMU_AUDIO_BEGIN 1
  426. #define VNC_MSG_SERVER_QEMU_AUDIO_DATA 2
  427. /*****************************************************************************
  428. *
  429. * Internal APIs
  430. *
  431. *****************************************************************************/
  432. /* Event loop functions */
  433. void vnc_client_read(void *opaque);
  434. void vnc_client_write(void *opaque);
  435. long vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen);
  436. long vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen);
  437. /* Protocol I/O functions */
  438. void vnc_write(VncState *vs, const void *data, size_t len);
  439. void vnc_write_u32(VncState *vs, uint32_t value);
  440. void vnc_write_s32(VncState *vs, int32_t value);
  441. void vnc_write_u16(VncState *vs, uint16_t value);
  442. void vnc_write_u8(VncState *vs, uint8_t value);
  443. void vnc_flush(VncState *vs);
  444. void vnc_read_when(VncState *vs, VncReadEvent *func, size_t expecting);
  445. void vnc_disconnect_finish(VncState *vs);
  446. void vnc_init_state(VncState *vs);
  447. /* Buffer I/O functions */
  448. uint32_t read_u32(uint8_t *data, size_t offset);
  449. /* Protocol stage functions */
  450. void vnc_client_error(VncState *vs);
  451. int vnc_client_io_error(VncState *vs, int ret, int last_errno);
  452. void start_client_init(VncState *vs);
  453. void start_auth_vnc(VncState *vs);
  454. /* Buffer management */
  455. void buffer_reserve(Buffer *buffer, size_t len);
  456. void buffer_reset(Buffer *buffer);
  457. void buffer_free(Buffer *buffer);
  458. void buffer_append(Buffer *buffer, const void *data, size_t len);
  459. void buffer_advance(Buffer *buf, size_t len);
  460. uint8_t *buffer_end(Buffer *buffer);
  461. /* Misc helpers */
  462. char *vnc_socket_local_addr(const char *format, int fd);
  463. char *vnc_socket_remote_addr(const char *format, int fd);
  464. static inline uint32_t vnc_has_feature(VncState *vs, int feature) {
  465. return (vs->features & (1 << feature));
  466. }
  467. /* Framebuffer */
  468. void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
  469. int32_t encoding);
  470. /* server fb is in PIXMAN_x8r8g8b8 */
  471. #define VNC_SERVER_FB_FORMAT PIXMAN_FORMAT(32, PIXMAN_TYPE_ARGB, 0, 8, 8, 8)
  472. #define VNC_SERVER_FB_BITS (PIXMAN_FORMAT_BPP(VNC_SERVER_FB_FORMAT))
  473. #define VNC_SERVER_FB_BYTES ((VNC_SERVER_FB_BITS+7)/8)
  474. void *vnc_server_fb_ptr(VncDisplay *vd, int x, int y);
  475. int vnc_server_fb_stride(VncDisplay *vd);
  476. void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v);
  477. double vnc_update_freq(VncState *vs, int x, int y, int w, int h);
  478. void vnc_sent_lossy_rect(VncState *vs, int x, int y, int w, int h);
  479. /* Encodings */
  480. int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  481. int vnc_raw_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  482. int vnc_hextile_send_framebuffer_update(VncState *vs, int x,
  483. int y, int w, int h);
  484. void vnc_hextile_set_pixel_conversion(VncState *vs, int generic);
  485. void *vnc_zlib_zalloc(void *x, unsigned items, unsigned size);
  486. void vnc_zlib_zfree(void *x, void *addr);
  487. int vnc_zlib_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  488. void vnc_zlib_clear(VncState *vs);
  489. int vnc_tight_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  490. int vnc_tight_png_send_framebuffer_update(VncState *vs, int x, int y,
  491. int w, int h);
  492. void vnc_tight_clear(VncState *vs);
  493. int vnc_zrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  494. int vnc_zywrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
  495. void vnc_zrle_clear(VncState *vs);
  496. #endif /* __QEMU_VNC_H */