obs-display.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[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 "obs.h"
  15. #include "obs-internal.h"
  16. obs_display_t obs_display_create(struct gs_init_data *graphics_data)
  17. {
  18. struct obs_display *display = bmalloc(sizeof(struct obs_display));
  19. memset(display, 0, sizeof(struct obs_display));
  20. if (graphics_data) {
  21. display->swap = gs_create_swapchain(graphics_data);
  22. if (!display->swap) {
  23. obs_display_destroy(display);
  24. return NULL;
  25. }
  26. }
  27. return display;
  28. }
  29. void obs_display_destroy(obs_display_t display)
  30. {
  31. if (display) {
  32. size_t i;
  33. pthread_mutex_lock(&obs->data.displays_mutex);
  34. da_erase_item(obs->data.displays, &display);
  35. pthread_mutex_unlock(&obs->data.displays_mutex);
  36. for (i = 0; i < MAX_CHANNELS; i++)
  37. obs_source_release(display->channels[i]);
  38. swapchain_destroy(display->swap);
  39. bfree(display);
  40. }
  41. }
  42. obs_source_t obs_display_getsource(obs_display_t display, uint32_t channel)
  43. {
  44. obs_source_t source;
  45. assert(channel < MAX_CHANNELS);
  46. source = display->channels[channel];
  47. if (source)
  48. obs_source_addref(source);
  49. return source;
  50. }
  51. void obs_display_setsource(obs_display_t display, uint32_t channel,
  52. obs_source_t source)
  53. {
  54. struct obs_source *prev_source;
  55. assert(channel < MAX_CHANNELS);
  56. prev_source = display->channels[channel];
  57. display->channels[channel] = source;
  58. if (source)
  59. obs_source_addref(source);
  60. if (prev_source)
  61. obs_source_release(prev_source);
  62. }