spice-display.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright (C) 2010 Red Hat, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 or
  7. * (at your option) version 3 of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef UI_SPICE_DISPLAY_H
  18. #define UI_SPICE_DISPLAY_H
  19. #include <spice.h>
  20. #include <spice/ipc_ring.h>
  21. #include <spice/enums.h>
  22. #include <spice/qxl_dev.h>
  23. #include "qemu/thread.h"
  24. #include "ui/qemu-pixman.h"
  25. #include "ui/console.h"
  26. #if defined(CONFIG_IOSURFACE)
  27. #include <CoreFoundation/CoreFoundation.h>
  28. #include <IOSurface/IOSurfaceRef.h>
  29. #endif
  30. #if defined(CONFIG_OPENGL)
  31. # define HAVE_SPICE_GL 1
  32. # include "ui/egl-helpers.h"
  33. # include "ui/egl-context.h"
  34. #endif
  35. #define NUM_MEMSLOTS 8
  36. #define MEMSLOT_GENERATION_BITS 8
  37. #define MEMSLOT_SLOT_BITS 8
  38. #define MEMSLOT_GROUP_HOST 0
  39. #define MEMSLOT_GROUP_GUEST 1
  40. #define NUM_MEMSLOTS_GROUPS 2
  41. /*
  42. * Internal enum to differentiate between options for
  43. * io calls that have a sync (old) version and an _async (new)
  44. * version:
  45. * QXL_SYNC: use the old version
  46. * QXL_ASYNC: use the new version and make sure there are no two
  47. * happening at the same time. This is used for guest initiated
  48. * calls
  49. */
  50. typedef enum qxl_async_io {
  51. QXL_SYNC,
  52. QXL_ASYNC,
  53. } qxl_async_io;
  54. enum {
  55. QXL_COOKIE_TYPE_IO,
  56. QXL_COOKIE_TYPE_RENDER_UPDATE_AREA,
  57. QXL_COOKIE_TYPE_POST_LOAD_MONITORS_CONFIG,
  58. QXL_COOKIE_TYPE_GL_DRAW_DONE,
  59. };
  60. typedef struct QXLCookie {
  61. int type;
  62. uint64_t io;
  63. union {
  64. uint32_t surface_id;
  65. QXLRect area;
  66. struct {
  67. QXLRect area;
  68. int redraw;
  69. } render;
  70. void *data;
  71. } u;
  72. } QXLCookie;
  73. QXLCookie *qxl_cookie_new(int type, uint64_t io);
  74. typedef struct SimpleSpiceDisplay SimpleSpiceDisplay;
  75. typedef struct SimpleSpiceUpdate SimpleSpiceUpdate;
  76. typedef struct SimpleSpiceCursor SimpleSpiceCursor;
  77. struct SimpleSpiceDisplay {
  78. DisplaySurface *ds;
  79. DisplayGLCtx dgc;
  80. DisplayChangeListener dcl;
  81. void *buf;
  82. int bufsize;
  83. QXLInstance qxl;
  84. uint32_t unique;
  85. pixman_image_t *surface;
  86. pixman_image_t *mirror;
  87. int32_t num_surfaces;
  88. QXLRect dirty;
  89. int notify;
  90. /*
  91. * All struct members below this comment can be accessed from
  92. * both spice server and qemu (iothread) context and any access
  93. * to them must be protected by the lock.
  94. */
  95. QemuMutex lock;
  96. QTAILQ_HEAD(, SimpleSpiceUpdate) updates;
  97. /* cursor (without qxl): displaychangelistener -> spice server */
  98. SimpleSpiceCursor *ptr_define;
  99. SimpleSpiceCursor *ptr_move;
  100. int16_t ptr_x, ptr_y;
  101. int16_t hot_x, hot_y;
  102. /* cursor (with qxl): qxl local renderer -> displaychangelistener */
  103. QEMUCursor *cursor;
  104. int mouse_x, mouse_y;
  105. QEMUBH *cursor_bh;
  106. #ifdef HAVE_SPICE_GL
  107. /* opengl rendering */
  108. QEMUBH *gl_unblock_bh;
  109. QEMUTimer *gl_unblock_timer;
  110. QemuGLShader *gls;
  111. int gl_updates;
  112. bool have_scanout;
  113. bool have_surface;
  114. #if defined(CONFIG_GBM)
  115. QemuDmaBuf *guest_dmabuf;
  116. bool guest_dmabuf_refresh;
  117. #endif
  118. #if defined(CONFIG_IOSURFACE)
  119. IOSurfaceRef iosurface;
  120. int surface_send_fd;
  121. #endif
  122. #if defined(CONFIG_ANGLE)
  123. EGLSurface esurface;
  124. egl_fb iosurface_fb;
  125. DisplayGLTextureBorrower backing_borrow;
  126. uint32_t backing_id;
  127. #endif
  128. bool render_cursor;
  129. egl_fb guest_fb;
  130. egl_fb blit_fb;
  131. egl_fb cursor_fb;
  132. bool have_hot;
  133. #endif
  134. };
  135. struct SimpleSpiceUpdate {
  136. QXLDrawable drawable;
  137. QXLImage image;
  138. QXLCommandExt ext;
  139. uint8_t *bitmap;
  140. QTAILQ_ENTRY(SimpleSpiceUpdate) next;
  141. };
  142. struct SimpleSpiceCursor {
  143. QXLCursorCmd cmd;
  144. QXLCommandExt ext;
  145. QXLCursor cursor;
  146. };
  147. extern bool spice_opengl;
  148. int qemu_spice_rect_is_empty(const QXLRect* r);
  149. void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r);
  150. void qemu_spice_destroy_update(SimpleSpiceDisplay *sdpy, SimpleSpiceUpdate *update);
  151. void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd);
  152. void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd);
  153. void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd);
  154. void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd);
  155. void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
  156. int x, int y, int w, int h);
  157. void qemu_spice_display_switch(SimpleSpiceDisplay *ssd,
  158. DisplaySurface *surface);
  159. void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd);
  160. void qemu_spice_cursor_refresh_bh(void *opaque);
  161. void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot,
  162. qxl_async_io async);
  163. void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid,
  164. uint32_t sid);
  165. void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id,
  166. QXLDevSurfaceCreate *surface,
  167. qxl_async_io async);
  168. void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd,
  169. uint32_t id, qxl_async_io async);
  170. void qemu_spice_wakeup(SimpleSpiceDisplay *ssd);
  171. void qemu_spice_display_start(void);
  172. void qemu_spice_display_stop(void);
  173. int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd);
  174. #endif