video_thread_wrapper.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /* RetroArch - A frontend for libretro.
  2. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
  3. * Copyright (C) 2011-2017 - Daniel De Matteis
  4. *
  5. * RetroArch is free software: you can redistribute it and/or modify it under the terms
  6. * of the GNU General Public License as published by the Free Software Found-
  7. * ation, either version 3 of the License, or (at your option) any later version.
  8. *
  9. * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. * PURPOSE. See the GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with RetroArch.
  14. * If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef RARCH_VIDEO_THREAD_H__
  17. #define RARCH_VIDEO_THREAD_H__
  18. #include <limits.h>
  19. #include <boolean.h>
  20. #include <retro_common_api.h>
  21. #include <rthreads/rthreads.h>
  22. #include <retro_miscellaneous.h>
  23. #ifdef HAVE_FONT
  24. #include "font_driver.h"
  25. #endif
  26. RETRO_BEGIN_DECLS
  27. enum thread_cmd
  28. {
  29. CMD_VIDEO_NONE = 0,
  30. CMD_INIT,
  31. CMD_SET_SHADER,
  32. CMD_FREE,
  33. CMD_ALIVE, /* Blocking alive check. Used when paused. */
  34. CMD_SET_VIEWPORT,
  35. CMD_SET_ROTATION,
  36. CMD_READ_VIEWPORT,
  37. CMD_OVERLAY_ENABLE,
  38. CMD_OVERLAY_LOAD,
  39. CMD_OVERLAY_TEX_GEOM,
  40. CMD_OVERLAY_VERTEX_GEOM,
  41. CMD_OVERLAY_FULL_SCREEN,
  42. CMD_POKE_SET_VIDEO_MODE,
  43. CMD_POKE_SET_FILTERING,
  44. CMD_POKE_SET_FBO_STATE,
  45. CMD_POKE_GET_FBO_STATE,
  46. CMD_POKE_SET_ASPECT_RATIO,
  47. CMD_FONT_INIT,
  48. CMD_CUSTOM_COMMAND,
  49. CMD_POKE_SHOW_MOUSE,
  50. CMD_POKE_GRAB_MOUSE_TOGGLE,
  51. CMD_POKE_SET_HDR_MAX_NITS,
  52. CMD_POKE_SET_HDR_PAPER_WHITE_NITS,
  53. CMD_POKE_SET_HDR_CONTRAST,
  54. CMD_POKE_SET_HDR_EXPAND_GAMUT,
  55. CMD_DUMMY = INT_MAX
  56. };
  57. typedef int (*custom_command_method_t)(void*);
  58. typedef bool (*custom_font_command_method_t)(const void **font_driver,
  59. void **font_handle, void *video_data, const char *font_path,
  60. float font_size, enum font_driver_render_api api,
  61. bool is_threaded);
  62. typedef struct thread_packet
  63. {
  64. union
  65. {
  66. const char *str;
  67. void *v;
  68. int i;
  69. float f;
  70. bool b;
  71. struct
  72. {
  73. enum rarch_shader_type type;
  74. const char *path;
  75. } set_shader;
  76. struct
  77. {
  78. unsigned width;
  79. unsigned height;
  80. bool force_full;
  81. bool allow_rotate;
  82. } set_viewport;
  83. struct
  84. {
  85. unsigned index;
  86. float x, y, w, h;
  87. } rect;
  88. struct
  89. {
  90. const struct texture_image *data;
  91. unsigned num;
  92. } image;
  93. struct
  94. {
  95. unsigned width;
  96. unsigned height;
  97. } output;
  98. struct
  99. {
  100. unsigned width;
  101. unsigned height;
  102. bool fullscreen;
  103. } new_mode;
  104. struct
  105. {
  106. unsigned index;
  107. bool smooth;
  108. bool ctx_scaling;
  109. } filtering;
  110. struct
  111. {
  112. char msg[128];
  113. struct font_params params;
  114. } osd_message;
  115. struct
  116. {
  117. custom_command_method_t method;
  118. void* data;
  119. int return_value;
  120. } custom_command;
  121. struct
  122. {
  123. custom_font_command_method_t method;
  124. const void **font_driver;
  125. void **font_handle;
  126. void *video_data;
  127. const char *font_path;
  128. float font_size;
  129. bool return_value;
  130. bool is_threaded;
  131. enum font_driver_render_api api;
  132. } font_init;
  133. struct
  134. {
  135. float max_nits;
  136. float paper_white_nits;
  137. float contrast;
  138. bool expand_gamut;
  139. } hdr;
  140. } data;
  141. enum thread_cmd type;
  142. } thread_packet_t;
  143. typedef struct thread_video
  144. {
  145. retro_time_t last_time;
  146. slock_t *lock;
  147. scond_t *cond_cmd;
  148. scond_t *cond_thread;
  149. sthread_t *thread;
  150. video_info_t info;
  151. const video_driver_t *driver;
  152. #ifdef HAVE_OVERLAY
  153. const video_overlay_interface_t *overlay;
  154. #endif
  155. const video_poke_interface_t *poke;
  156. void *driver_data;
  157. input_driver_t **input;
  158. void **input_data;
  159. float *alpha_mod;
  160. slock_t *alpha_lock;
  161. struct
  162. {
  163. void *frame;
  164. size_t frame_cap;
  165. unsigned width;
  166. unsigned height;
  167. float alpha;
  168. bool frame_updated;
  169. bool rgb32;
  170. bool enable;
  171. bool full_screen;
  172. } texture;
  173. unsigned hit_count;
  174. unsigned miss_count;
  175. unsigned alpha_mods;
  176. struct video_viewport vp;
  177. struct video_viewport read_vp; /* Last viewport reported to caller. */
  178. thread_packet_t cmd_data;
  179. video_driver_t video_thread;
  180. enum thread_cmd send_cmd;
  181. enum thread_cmd reply_cmd;
  182. bool alpha_update;
  183. struct
  184. {
  185. uint64_t count;
  186. slock_t *lock;
  187. uint8_t *buffer;
  188. unsigned width;
  189. unsigned height;
  190. unsigned pitch;
  191. char msg[NAME_MAX_LENGTH];
  192. bool updated;
  193. bool within_thread;
  194. } frame;
  195. bool apply_state_changes;
  196. bool alive;
  197. bool focus;
  198. bool suppress_screensaver;
  199. bool has_windowed;
  200. bool nonblock;
  201. bool is_idle;
  202. } thread_video_t;
  203. /**
  204. * video_init_thread:
  205. * @out_driver : Output video driver
  206. * @out_data : Output video data
  207. * @input : Input input driver
  208. * @input_data : Input input data
  209. * @driver : Input Video driver
  210. * @info : Video info handle.
  211. *
  212. * Creates, initializes and starts a video driver in a new thread.
  213. * Access to video driver will be mediated through this driver.
  214. *
  215. * Returns: true (1) if successful, otherwise false (0).
  216. **/
  217. bool video_init_thread(
  218. const video_driver_t **out_driver, void **out_data,
  219. input_driver_t **input, void **input_data,
  220. const video_driver_t *driver, const video_info_t info);
  221. bool video_thread_font_init(
  222. const void **font_driver,
  223. void **font_handle,
  224. void *data,
  225. const char *font_path,
  226. float font_size,
  227. enum font_driver_render_api api,
  228. custom_font_command_method_t func,
  229. bool is_threaded);
  230. unsigned video_thread_texture_load(void *data,
  231. custom_command_method_t func);
  232. RETRO_END_DECLS
  233. #endif