gl-nix.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 *
  35. gl_windowinfo_create(const struct gs_init_data *info)
  36. {
  37. return gl_vtable->windowinfo_create(info);
  38. }
  39. extern void gl_windowinfo_destroy(struct gl_windowinfo *info)
  40. {
  41. gl_vtable->windowinfo_destroy(info);
  42. }
  43. extern struct gl_platform *gl_platform_create(gs_device_t *device,
  44. uint32_t adapter)
  45. {
  46. init_winsys();
  47. return gl_vtable->platform_create(device, adapter);
  48. }
  49. extern void gl_platform_destroy(struct gl_platform *plat)
  50. {
  51. gl_vtable->platform_destroy(plat);
  52. gl_vtable = NULL;
  53. }
  54. extern bool gl_platform_init_swapchain(struct gs_swap_chain *swap)
  55. {
  56. return gl_vtable->platform_init_swapchain(swap);
  57. }
  58. extern void gl_platform_cleanup_swapchain(struct gs_swap_chain *swap)
  59. {
  60. gl_vtable->platform_cleanup_swapchain(swap);
  61. }
  62. extern void device_enter_context(gs_device_t *device)
  63. {
  64. gl_vtable->device_enter_context(device);
  65. }
  66. extern void device_leave_context(gs_device_t *device)
  67. {
  68. device->cur_render_target = NULL;
  69. device->cur_zstencil_buffer = NULL;
  70. device->cur_vertex_buffer = NULL;
  71. device->cur_index_buffer = NULL;
  72. device->cur_swap = NULL;
  73. device->cur_fbo = NULL;
  74. gl_vtable->device_leave_context(device);
  75. }
  76. extern bool device_enum_adapters(gs_device_t *device,
  77. bool (*callback)(void *param, const char *name,
  78. uint32_t id),
  79. void *param)
  80. {
  81. return gl_vtable->device_enum_adapters(device, callback, param);
  82. }
  83. extern void *device_get_device_obj(gs_device_t *device)
  84. {
  85. return gl_vtable->device_get_device_obj(device);
  86. }
  87. extern void gl_getclientsize(const struct gs_swap_chain *swap, uint32_t *width,
  88. uint32_t *height)
  89. {
  90. gl_vtable->getclientsize(swap, width, height);
  91. }
  92. extern void gl_clear_context(gs_device_t *device)
  93. {
  94. gl_vtable->clear_context(device);
  95. }
  96. extern void gl_update(gs_device_t *device)
  97. {
  98. gl_vtable->update(device);
  99. }
  100. extern void device_load_swapchain(gs_device_t *device, gs_swapchain_t *swap)
  101. {
  102. gl_vtable->device_load_swapchain(device, swap);
  103. }
  104. extern bool device_is_present_ready(gs_device_t *device)
  105. {
  106. UNUSED_PARAMETER(device);
  107. return true;
  108. }
  109. extern void device_present(gs_device_t *device)
  110. {
  111. gl_vtable->device_present(device);
  112. }
  113. extern bool device_is_monitor_hdr(gs_device_t *device, void *monitor)
  114. {
  115. UNUSED_PARAMETER(device);
  116. UNUSED_PARAMETER(monitor);
  117. return false;
  118. }
  119. extern struct gs_texture *device_texture_create_from_dmabuf(
  120. gs_device_t *device, unsigned int width, unsigned int height,
  121. uint32_t drm_format, enum gs_color_format color_format,
  122. uint32_t n_planes, const int *fds, const uint32_t *strides,
  123. const uint32_t *offsets, const uint64_t *modifiers)
  124. {
  125. return gl_vtable->device_texture_create_from_dmabuf(
  126. device, width, height, drm_format, color_format, n_planes, fds,
  127. strides, offsets, modifiers);
  128. }
  129. extern bool device_query_dmabuf_capabilities(gs_device_t *device,
  130. enum gs_dmabuf_flags *dmabuf_flags,
  131. uint32_t **drm_formats,
  132. size_t *n_formats)
  133. {
  134. return gl_vtable->device_query_dmabuf_capabilities(
  135. device, dmabuf_flags, drm_formats, n_formats);
  136. }
  137. extern bool device_query_dmabuf_modifiers_for_format(gs_device_t *device,
  138. uint32_t drm_format,
  139. uint64_t **modifiers,
  140. size_t *n_modifiers)
  141. {
  142. return gl_vtable->device_query_dmabuf_modifiers_for_format(
  143. device, drm_format, modifiers, n_modifiers);
  144. }
  145. struct gs_texture *device_texture_create_from_pixmap(
  146. gs_device_t *device, uint32_t width, uint32_t height,
  147. enum gs_color_format color_format, uint32_t target, void *pixmap)
  148. {
  149. return gl_vtable->device_texture_create_from_pixmap(
  150. device, width, height, color_format, target, pixmap);
  151. }