gl-nix.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /******************************************************************************
  2. Copyright (C) 2019 by Jason Francis <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "gl-nix.h"
  15. #include "gl-x11-egl.h"
  16. #ifdef ENABLE_WAYLAND
  17. #include "gl-wayland-egl.h"
  18. #endif
  19. static const struct gl_winsys_vtable *gl_vtable = NULL;
  20. static void init_winsys(void)
  21. {
  22. assert(gl_vtable == NULL);
  23. enum obs_nix_platform_type platform = obs_get_nix_platform();
  24. if (platform == OBS_NIX_PLATFORM_X11_EGL)
  25. gl_vtable = gl_x11_egl_get_winsys_vtable();
  26. #ifdef ENABLE_WAYLAND
  27. if (platform == OBS_NIX_PLATFORM_WAYLAND) {
  28. gl_vtable = gl_wayland_egl_get_winsys_vtable();
  29. blog(LOG_INFO, "Using EGL/Wayland");
  30. }
  31. #endif
  32. assert(gl_vtable != NULL);
  33. }
  34. extern struct gl_windowinfo *gl_windowinfo_create(const struct gs_init_data *info)
  35. {
  36. return gl_vtable->windowinfo_create(info);
  37. }
  38. extern void gl_windowinfo_destroy(struct gl_windowinfo *info)
  39. {
  40. gl_vtable->windowinfo_destroy(info);
  41. }
  42. extern struct gl_platform *gl_platform_create(gs_device_t *device, uint32_t adapter)
  43. {
  44. init_winsys();
  45. return gl_vtable->platform_create(device, adapter);
  46. }
  47. extern void gl_platform_destroy(struct gl_platform *plat)
  48. {
  49. gl_vtable->platform_destroy(plat);
  50. gl_vtable = NULL;
  51. }
  52. extern bool gl_platform_init_swapchain(struct gs_swap_chain *swap)
  53. {
  54. return gl_vtable->platform_init_swapchain(swap);
  55. }
  56. extern void gl_platform_cleanup_swapchain(struct gs_swap_chain *swap)
  57. {
  58. gl_vtable->platform_cleanup_swapchain(swap);
  59. }
  60. extern void device_enter_context(gs_device_t *device)
  61. {
  62. gl_vtable->device_enter_context(device);
  63. }
  64. extern void device_leave_context(gs_device_t *device)
  65. {
  66. device->cur_render_target = NULL;
  67. device->cur_zstencil_buffer = NULL;
  68. device->cur_vertex_buffer = NULL;
  69. device->cur_index_buffer = NULL;
  70. device->cur_swap = NULL;
  71. device->cur_fbo = NULL;
  72. gl_vtable->device_leave_context(device);
  73. }
  74. extern bool device_enum_adapters(gs_device_t *device, bool (*callback)(void *param, const char *name, uint32_t id),
  75. void *param)
  76. {
  77. return gl_vtable->device_enum_adapters(device, callback, param);
  78. }
  79. extern void *device_get_device_obj(gs_device_t *device)
  80. {
  81. return gl_vtable->device_get_device_obj(device);
  82. }
  83. extern void gl_getclientsize(const struct gs_swap_chain *swap, uint32_t *width, uint32_t *height)
  84. {
  85. gl_vtable->getclientsize(swap, width, height);
  86. }
  87. extern void gl_clear_context(gs_device_t *device)
  88. {
  89. gl_vtable->clear_context(device);
  90. }
  91. extern void gl_update(gs_device_t *device)
  92. {
  93. gl_vtable->update(device);
  94. }
  95. extern void device_load_swapchain(gs_device_t *device, gs_swapchain_t *swap)
  96. {
  97. gl_vtable->device_load_swapchain(device, swap);
  98. }
  99. extern bool device_is_present_ready(gs_device_t *device)
  100. {
  101. UNUSED_PARAMETER(device);
  102. return true;
  103. }
  104. extern void device_present(gs_device_t *device)
  105. {
  106. gl_vtable->device_present(device);
  107. }
  108. extern bool device_is_monitor_hdr(gs_device_t *device, void *monitor)
  109. {
  110. UNUSED_PARAMETER(device);
  111. UNUSED_PARAMETER(monitor);
  112. return false;
  113. }
  114. extern struct gs_texture *device_texture_create_from_dmabuf(gs_device_t *device, unsigned int width,
  115. unsigned int height, uint32_t drm_format,
  116. enum gs_color_format color_format, uint32_t n_planes,
  117. const int *fds, const uint32_t *strides,
  118. const uint32_t *offsets, const uint64_t *modifiers)
  119. {
  120. return gl_vtable->device_texture_create_from_dmabuf(device, width, height, drm_format, color_format, n_planes,
  121. fds, strides, offsets, modifiers);
  122. }
  123. extern bool device_query_dmabuf_capabilities(gs_device_t *device, enum gs_dmabuf_flags *dmabuf_flags,
  124. uint32_t **drm_formats, size_t *n_formats)
  125. {
  126. return gl_vtable->device_query_dmabuf_capabilities(device, dmabuf_flags, drm_formats, n_formats);
  127. }
  128. extern bool device_query_dmabuf_modifiers_for_format(gs_device_t *device, uint32_t drm_format, uint64_t **modifiers,
  129. size_t *n_modifiers)
  130. {
  131. return gl_vtable->device_query_dmabuf_modifiers_for_format(device, drm_format, modifiers, n_modifiers);
  132. }
  133. struct gs_texture *device_texture_create_from_pixmap(gs_device_t *device, uint32_t width, uint32_t height,
  134. enum gs_color_format color_format, uint32_t target, void *pixmap)
  135. {
  136. return gl_vtable->device_texture_create_from_pixmap(device, width, height, color_format, target, pixmap);
  137. }
  138. bool device_query_sync_capabilities(gs_device_t *device)
  139. {
  140. return gl_vtable->device_query_sync_capabilities(device);
  141. }
  142. gs_sync_t *device_sync_create(gs_device_t *device)
  143. {
  144. return gl_vtable->device_sync_create(device);
  145. }
  146. gs_sync_t *device_sync_create_from_syncobj_timeline_point(gs_device_t *device, int syncobj_fd, uint64_t timeline_point)
  147. {
  148. return gl_vtable->device_sync_create_from_syncobj_timeline_point(device, syncobj_fd, timeline_point);
  149. }
  150. void device_sync_destroy(gs_device_t *device, gs_sync_t *sync)
  151. {
  152. return gl_vtable->device_sync_destroy(device, sync);
  153. }
  154. bool device_sync_export_syncobj_timeline_point(gs_device_t *device, gs_sync_t *sync, int syncobj_fd,
  155. uint64_t timeline_point)
  156. {
  157. return gl_vtable->device_sync_export_syncobj_timeline_point(device, sync, syncobj_fd, timeline_point);
  158. }
  159. bool device_sync_signal_syncobj_timeline_point(gs_device_t *device, int syncobj_fd, uint64_t timeline_point)
  160. {
  161. return gl_vtable->device_sync_signal_syncobj_timeline_point(device, syncobj_fd, timeline_point);
  162. }
  163. bool device_sync_wait(gs_device_t *device, gs_sync_t *sync)
  164. {
  165. return gl_vtable->device_sync_wait(device, sync);
  166. }