1 /* RetroArch - A frontend for libretro. 2 * Copyright (C) 2010-2014 - Hans-Kristian Arntzen 3 * Copyright (C) 2011-2016 - Daniel De Matteis 4 * Copyright (C) 2016-2019 - Brad Parker 5 * 6 * RetroArch is free software: you can redistribute it and/or modify it under the terms 7 * of the GNU General Public License as published by the Free Software Found- 8 * ation, either version 3 of the License, or (at your option) any later version. 9 * 10 * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 * PURPOSE. See the GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along with RetroArch. 15 * If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef __RETROARCH_H 19 #define __RETROARCH_H 20 21 #include <stdint.h> 22 #include <stddef.h> 23 #include <sys/types.h> 24 #include <stdlib.h> 25 26 #include <boolean.h> 27 #include <retro_inline.h> 28 #include <retro_common_api.h> 29 30 #ifdef HAVE_CONFIG_H 31 #include "config.h" 32 #endif 33 34 #include <lists/string_list.h> 35 #include <queues/task_queue.h> 36 #include <queues/message_queue.h> 37 #ifdef HAVE_AUDIOMIXER 38 #include <audio/audio_mixer.h> 39 #endif 40 41 #include "audio/audio_defines.h" 42 #include "gfx/video_shader_parse.h" 43 44 #include "core_type.h" 45 #include "core.h" 46 47 #ifdef HAVE_MENU 48 #include "menu/menu_defines.h" 49 #endif 50 51 RETRO_BEGIN_DECLS 52 53 #define RETRO_ENVIRONMENT_RETROARCH_START_BLOCK 0x800000 54 55 #define RETRO_ENVIRONMENT_SET_SAVE_STATE_IN_BACKGROUND (2 | RETRO_ENVIRONMENT_RETROARCH_START_BLOCK) 56 /* bool * -- 57 * Boolean value that tells the front end to save states in the 58 * background or not. 59 */ 60 61 #define RETRO_ENVIRONMENT_GET_CLEAR_ALL_THREAD_WAITS_CB (3 | RETRO_ENVIRONMENT_RETROARCH_START_BLOCK) 62 /* retro_environment_t * -- 63 * Provides the callback to the frontend method which will cancel 64 * all currently waiting threads. Used when coordination is needed 65 * between the core and the frontend to gracefully stop all threads. 66 */ 67 68 #define RETRO_ENVIRONMENT_POLL_TYPE_OVERRIDE (4 | RETRO_ENVIRONMENT_RETROARCH_START_BLOCK) 69 /* unsigned * -- 70 * Tells the frontend to override the poll type behavior. 71 * Allows the frontend to influence the polling behavior of the 72 * frontend. 73 * 74 * Will be unset when retro_unload_game is called. 75 * 76 * 0 - Don't Care, no changes, frontend still determines polling type behavior. 77 * 1 - Early 78 * 2 - Normal 79 * 3 - Late 80 */ 81 82 enum rarch_ctl_state 83 { 84 RARCH_CTL_NONE = 0, 85 86 /* Deinitializes RetroArch. */ 87 RARCH_CTL_MAIN_DEINIT, 88 89 RARCH_CTL_IS_INITED, 90 91 RARCH_CTL_IS_DUMMY_CORE, 92 RARCH_CTL_IS_CORE_LOADED, 93 94 RARCH_CTL_IS_BPS_PREF, 95 RARCH_CTL_UNSET_BPS_PREF, 96 97 RARCH_CTL_IS_PATCH_BLOCKED, 98 99 RARCH_CTL_IS_UPS_PREF, 100 RARCH_CTL_UNSET_UPS_PREF, 101 102 RARCH_CTL_IS_IPS_PREF, 103 RARCH_CTL_UNSET_IPS_PREF, 104 105 #ifdef HAVE_CONFIGFILE 106 /* Block config read */ 107 RARCH_CTL_SET_BLOCK_CONFIG_READ, 108 RARCH_CTL_UNSET_BLOCK_CONFIG_READ, 109 #endif 110 111 /* Username */ 112 RARCH_CTL_HAS_SET_USERNAME, 113 114 RARCH_CTL_HAS_SET_SUBSYSTEMS, 115 116 RARCH_CTL_IS_IDLE, 117 RARCH_CTL_SET_IDLE, 118 119 RARCH_CTL_SET_WINDOWED_SCALE, 120 121 #ifdef HAVE_CONFIGFILE 122 RARCH_CTL_IS_OVERRIDES_ACTIVE, 123 124 RARCH_CTL_IS_REMAPS_CORE_ACTIVE, 125 RARCH_CTL_SET_REMAPS_CORE_ACTIVE, 126 127 RARCH_CTL_IS_REMAPS_CONTENT_DIR_ACTIVE, 128 RARCH_CTL_SET_REMAPS_CONTENT_DIR_ACTIVE, 129 130 RARCH_CTL_IS_REMAPS_GAME_ACTIVE, 131 RARCH_CTL_SET_REMAPS_GAME_ACTIVE, 132 #endif 133 134 RARCH_CTL_IS_MISSING_BIOS, 135 RARCH_CTL_SET_MISSING_BIOS, 136 RARCH_CTL_UNSET_MISSING_BIOS, 137 138 RARCH_CTL_IS_GAME_OPTIONS_ACTIVE, 139 RARCH_CTL_IS_FOLDER_OPTIONS_ACTIVE, 140 141 RARCH_CTL_IS_PAUSED, 142 RARCH_CTL_SET_PAUSED, 143 144 RARCH_CTL_SET_SHUTDOWN, 145 146 /* Runloop state */ 147 RARCH_CTL_STATE_FREE, 148 149 /* Performance counters */ 150 RARCH_CTL_GET_PERFCNT, 151 RARCH_CTL_SET_PERFCNT_ENABLE, 152 RARCH_CTL_UNSET_PERFCNT_ENABLE, 153 RARCH_CTL_IS_PERFCNT_ENABLE, 154 155 /* Core options */ 156 RARCH_CTL_HAS_CORE_OPTIONS, 157 RARCH_CTL_GET_CORE_OPTION_SIZE, 158 RARCH_CTL_CORE_OPTIONS_LIST_GET, 159 RARCH_CTL_CORE_OPTION_PREV, 160 RARCH_CTL_CORE_OPTION_NEXT, 161 RARCH_CTL_CORE_IS_RUNNING, 162 163 /* BSV Movie */ 164 RARCH_CTL_BSV_MOVIE_IS_INITED 165 }; 166 167 enum rarch_capabilities 168 { 169 RARCH_CAPABILITIES_NONE = 0, 170 RARCH_CAPABILITIES_CPU, 171 RARCH_CAPABILITIES_COMPILER 172 }; 173 174 enum rarch_override_setting 175 { 176 RARCH_OVERRIDE_SETTING_NONE = 0, 177 RARCH_OVERRIDE_SETTING_LIBRETRO, 178 RARCH_OVERRIDE_SETTING_VERBOSITY, 179 RARCH_OVERRIDE_SETTING_LIBRETRO_DIRECTORY, 180 RARCH_OVERRIDE_SETTING_SAVE_PATH, 181 RARCH_OVERRIDE_SETTING_STATE_PATH, 182 #ifdef HAVE_NETWORKING 183 RARCH_OVERRIDE_SETTING_NETPLAY_MODE, 184 RARCH_OVERRIDE_SETTING_NETPLAY_IP_ADDRESS, 185 RARCH_OVERRIDE_SETTING_NETPLAY_IP_PORT, 186 RARCH_OVERRIDE_SETTING_NETPLAY_STATELESS_MODE, 187 RARCH_OVERRIDE_SETTING_NETPLAY_CHECK_FRAMES, 188 #endif 189 RARCH_OVERRIDE_SETTING_UPS_PREF, 190 RARCH_OVERRIDE_SETTING_BPS_PREF, 191 RARCH_OVERRIDE_SETTING_IPS_PREF, 192 RARCH_OVERRIDE_SETTING_LIBRETRO_DEVICE, 193 RARCH_OVERRIDE_SETTING_LOG_TO_FILE, 194 RARCH_OVERRIDE_SETTING_LAST 195 }; 196 197 enum runloop_action 198 { 199 RUNLOOP_ACTION_NONE = 0, 200 RUNLOOP_ACTION_AUTOSAVE 201 }; 202 203 struct rarch_main_wrap 204 { 205 char **argv; 206 const char *content_path; 207 const char *sram_path; 208 const char *state_path; 209 const char *config_path; 210 const char *libretro_path; 211 int argc; 212 bool verbose; 213 bool no_content; 214 bool touched; 215 }; 216 217 typedef struct rarch_resolution 218 { 219 unsigned idx; 220 unsigned id; 221 } rarch_resolution_t; 222 223 /* All run-time- / command line flag-related globals go here. */ 224 225 typedef struct global 226 { 227 #ifdef HAVE_MENU 228 struct 229 { 230 retro_time_t prev_start_time; 231 retro_time_t noop_press_time; 232 retro_time_t noop_start_time; 233 retro_time_t action_start_time; 234 retro_time_t action_press_time; 235 } menu; 236 #endif 237 struct 238 { 239 char *remapfile; 240 char savefile[8192]; 241 char savestate[8192]; 242 char cheatfile[8192]; 243 char ups[8192]; 244 char bps[8192]; 245 char ips[8192]; 246 char label[8192]; 247 } name; 248 249 /* Recording. */ 250 struct 251 { 252 size_t gpu_width; 253 size_t gpu_height; 254 unsigned width; 255 unsigned height; 256 char path[8192]; 257 char config[8192]; 258 char output_dir[8192]; 259 char config_dir[8192]; 260 bool use_output_dir; 261 } record; 262 263 /* Settings and/or global state that is specific to 264 * a console-style implementation. */ 265 struct 266 { 267 struct 268 { 269 struct 270 { 271 uint32_t *list; 272 unsigned count; 273 rarch_resolution_t current; 274 rarch_resolution_t initial; 275 bool check; 276 } resolutions; 277 unsigned gamma_correction; 278 unsigned int flicker_filter_index; 279 unsigned char soft_filter_index; 280 bool pal_enable; 281 bool pal60_enable; 282 } screen; 283 284 bool flickerfilter_enable; 285 bool softfilter_enable; 286 287 } console; 288 unsigned old_analog_dpad_mode[MAX_USERS]; 289 unsigned old_libretro_device[MAX_USERS]; 290 bool old_analog_dpad_mode_set; 291 bool old_libretro_device_set; 292 bool remapping_cache_active; 293 /* Settings and/or global states specific to menus */ 294 #ifdef HAVE_MENU 295 enum menu_action menu_prev_action; 296 #endif 297 bool launched_from_cli; 298 bool cli_load_menu_on_error; 299 } global_t; 300 301 typedef struct content_file_override 302 { 303 char *ext; 304 bool need_fullpath; 305 bool persistent_data; 306 } content_file_override_t; 307 308 typedef struct content_file_info 309 { 310 char *full_path; 311 char *archive_path; 312 char *archive_file; 313 char *dir; 314 char *name; 315 char *ext; 316 char *meta; /* Unused at present */ 317 void *data; 318 size_t data_size; 319 bool file_in_archive; 320 bool persistent_data; 321 } content_file_info_t; 322 323 typedef struct content_file_list 324 { 325 content_file_info_t *entries; 326 struct string_list *temporary_files; 327 struct retro_game_info *game_info; 328 struct retro_game_info_ext *game_info_ext; 329 size_t size; 330 } content_file_list_t; 331 332 typedef struct content_state 333 { 334 char *pending_subsystem_roms[RARCH_MAX_SUBSYSTEM_ROMS]; 335 336 content_file_override_t *content_override_list; 337 content_file_list_t *content_list; 338 339 int pending_subsystem_rom_num; 340 int pending_subsystem_id; 341 unsigned pending_subsystem_rom_id; 342 uint32_t rom_crc; 343 344 char companion_ui_crc32[32]; 345 char pending_subsystem_ident[255]; 346 char pending_rom_crc_path[PATH_MAX_LENGTH]; 347 char companion_ui_db_name[PATH_MAX_LENGTH]; 348 349 bool is_inited; 350 bool core_does_not_need_content; 351 bool pending_subsystem_init; 352 bool pending_rom_crc; 353 } content_state_t; 354 355 bool rarch_ctl(enum rarch_ctl_state state, void *data); 356 357 int retroarch_get_capabilities(enum rarch_capabilities type, 358 char *s, size_t len); 359 360 void retroarch_override_setting_set(enum rarch_override_setting enum_idx, void *data); 361 362 void retroarch_override_setting_unset(enum rarch_override_setting enum_idx, void *data); 363 364 bool retroarch_override_setting_is_set(enum rarch_override_setting enum_idx, void *data); 365 366 bool retroarch_is_forced_fullscreen(void); 367 368 void retroarch_set_current_core_type( 369 enum rarch_core_type type, bool explicitly_set); 370 371 const char* retroarch_get_shader_preset(void); 372 373 bool retroarch_is_switching_display_mode(void); 374 375 /** 376 * retroarch_main_init: 377 * @argc : Count of (commandline) arguments. 378 * @argv : (Commandline) arguments. 379 * 380 * Initializes the program. 381 * 382 * Returns: 1 (true) on success, otherwise false (0) if there was an error. 383 **/ 384 bool retroarch_main_init(int argc, char *argv[]); 385 386 bool retroarch_main_quit(void); 387 388 global_t *global_get_ptr(void); 389 390 content_state_t *content_state_get_ptr(void); 391 392 unsigned content_get_subsystem_rom_id(void); 393 394 int content_get_subsystem(void); 395 396 /** 397 * runloop_iterate: 398 * 399 * Run Libretro core in RetroArch for one frame. 400 * 401 * Returns: 0 on successful run, 402 * Returns 1 if we have to wait until button input in order 403 * to wake up the loop. 404 * Returns -1 if we forcibly quit out of the 405 * RetroArch iteration loop. 406 **/ 407 int runloop_iterate(void); 408 409 void runloop_msg_queue_push(const char *msg, 410 unsigned prio, unsigned duration, 411 bool flush, 412 char *title, 413 enum message_queue_icon icon, enum message_queue_category category); 414 415 void runloop_get_status(bool *is_paused, bool *is_idle, bool *is_slowmotion, 416 bool *is_perfcnt_enable); 417 418 void retroarch_menu_running(void); 419 420 void retroarch_menu_running_finished(bool quit); 421 422 rarch_system_info_t *runloop_get_system_info(void); 423 424 struct retro_system_info *runloop_get_libretro_system_info(void); 425 426 void retroarch_force_video_driver_fallback(const char *driver); 427 428 enum retro_language rarch_get_language_from_iso(const char *lang); 429 430 void rarch_favorites_init(void); 431 432 void rarch_favorites_deinit(void); 433 434 /* Audio */ 435 436 #ifdef HAVE_AUDIOMIXER 437 typedef struct audio_mixer_stream 438 { 439 audio_mixer_sound_t *handle; 440 audio_mixer_voice_t *voice; 441 audio_mixer_stop_cb_t stop_cb; 442 void *buf; 443 char *name; 444 size_t bufsize; 445 float volume; 446 enum audio_mixer_stream_type stream_type; 447 enum audio_mixer_type type; 448 enum audio_mixer_state state; 449 } audio_mixer_stream_t; 450 451 typedef struct audio_mixer_stream_params 452 { 453 void *buf; 454 char *basename; 455 audio_mixer_stop_cb_t cb; 456 size_t bufsize; 457 unsigned slot_selection_idx; 458 float volume; 459 enum audio_mixer_slot_selection_type slot_selection_type; 460 enum audio_mixer_stream_type stream_type; 461 enum audio_mixer_type type; 462 enum audio_mixer_state state; 463 } audio_mixer_stream_params_t; 464 #endif 465 466 typedef struct audio_driver 467 { 468 /* Creates and initializes handle to audio driver. 469 * 470 * Returns: audio driver handle on success, otherwise NULL. 471 **/ 472 void *(*init)(const char *device, unsigned rate, 473 unsigned latency, unsigned block_frames, unsigned *new_rate); 474 475 /* 476 * @data : Pointer to audio data handle. 477 * @buf : Audio buffer data. 478 * @size : Size of audio buffer. 479 * 480 * Write samples to audio driver. 481 * 482 * Write data in buffer to audio driver. 483 * A frame here is defined as one combined sample of left and right 484 * channels. (I.e. 44.1kHz, 16-bit stereo has 88.2k samples/s, and 485 * 44.1k frames/s.) 486 * 487 * Samples are interleaved in format LRLRLRLRLR ... 488 * If the driver returns true in use_float(), a floating point 489 * format will be used, with range [-1.0, 1.0]. 490 * If not, signed 16-bit samples in native byte ordering will be used. 491 * 492 * This function returns the number of frames successfully written. 493 * If an error occurs, -1 should be returned. 494 * Note that non-blocking behavior that cannot write at this time 495 * should return 0 as returning -1 will terminate the driver. 496 * 497 * Unless said otherwise with set_nonblock_state(), all writes 498 * are blocking, and it should block till it has written all frames. 499 */ 500 ssize_t (*write)(void *data, const void *buf, size_t size); 501 502 /* Temporarily pauses the audio driver. */ 503 bool (*stop)(void *data); 504 505 /* Resumes audio driver from the paused state. */ 506 bool (*start)(void *data, bool is_shutdown); 507 508 /* Is the audio driver currently running? */ 509 bool (*alive)(void *data); 510 511 /* Should we care about blocking in audio thread? Fast forwarding. 512 * 513 * If state is true, nonblocking operation is assumed. 514 * This is typically used for fast-forwarding. If driver cannot 515 * implement nonblocking writes, this can be disregarded, but should 516 * log a message to stderr. 517 * */ 518 void (*set_nonblock_state)(void *data, bool toggle); 519 520 /* Stops and frees driver data. */ 521 void (*free)(void *data); 522 523 /* Defines if driver will take standard floating point samples, 524 * or int16_t samples. 525 * 526 * If true is returned, the audio driver is capable of using 527 * floating point data. This will likely increase performance as the 528 * resampler unit uses floating point. The sample range is 529 * [-1.0, 1.0]. 530 * */ 531 bool (*use_float)(void *data); 532 533 /* Human-readable identifier. */ 534 const char *ident; 535 536 /* Optional. Get audio device list (allocates, caller has to free this) */ 537 void *(*device_list_new)(void *data); 538 539 /* Optional. Frees audio device list */ 540 void (*device_list_free)(void *data, void *data2); 541 542 /* Optional. */ 543 size_t (*write_avail)(void *data); 544 545 size_t (*buffer_size)(void *data); 546 } audio_driver_t; 547 548 bool audio_driver_enable_callback(void); 549 550 bool audio_driver_disable_callback(void); 551 552 /** 553 * config_get_audio_driver_options: 554 * 555 * Get an enumerated list of all audio driver names, separated by '|'. 556 * 557 * Returns: string listing of all audio driver names, separated by '|'. 558 **/ 559 const char* config_get_audio_driver_options(void); 560 561 bool audio_driver_mixer_extension_supported(const char *ext); 562 563 void audio_driver_dsp_filter_free(void); 564 565 bool audio_driver_dsp_filter_init(const char *device); 566 567 void audio_driver_set_buffer_size(size_t bufsize); 568 569 bool audio_driver_get_devices_list(void **ptr); 570 571 void audio_driver_setup_rewind(void); 572 573 bool audio_driver_callback(void); 574 575 bool audio_driver_has_callback(void); 576 577 void audio_driver_frame_is_reverse(void); 578 579 void audio_set_float(enum audio_action action, float val); 580 581 float *audio_get_float_ptr(enum audio_action action); 582 583 bool *audio_get_bool_ptr(enum audio_action action); 584 585 #ifdef HAVE_AUDIOMIXER 586 audio_mixer_stream_t *audio_driver_mixer_get_stream(unsigned i); 587 588 bool audio_driver_mixer_add_stream(audio_mixer_stream_params_t *params); 589 590 void audio_driver_mixer_play_stream(unsigned i); 591 592 void audio_driver_mixer_play_menu_sound(unsigned i); 593 594 void audio_driver_mixer_play_menu_sound_looped(unsigned i); 595 596 void audio_driver_mixer_play_stream_sequential(unsigned i); 597 598 void audio_driver_mixer_play_stream_looped(unsigned i); 599 600 void audio_driver_mixer_stop_stream(unsigned i); 601 602 float audio_driver_mixer_get_stream_volume(unsigned i); 603 604 void audio_driver_mixer_set_stream_volume(unsigned i, float vol); 605 606 void audio_driver_mixer_remove_stream(unsigned i); 607 608 enum audio_mixer_state audio_driver_mixer_get_stream_state(unsigned i); 609 610 const char *audio_driver_mixer_get_stream_name(unsigned i); 611 612 void audio_driver_load_system_sounds(void); 613 614 #endif 615 616 extern audio_driver_t audio_rsound; 617 extern audio_driver_t audio_audioio; 618 extern audio_driver_t audio_oss; 619 extern audio_driver_t audio_alsa; 620 extern audio_driver_t audio_alsathread; 621 extern audio_driver_t audio_tinyalsa; 622 extern audio_driver_t audio_roar; 623 extern audio_driver_t audio_openal; 624 extern audio_driver_t audio_opensl; 625 extern audio_driver_t audio_jack; 626 extern audio_driver_t audio_sdl; 627 extern audio_driver_t audio_xa; 628 extern audio_driver_t audio_pulse; 629 extern audio_driver_t audio_dsound; 630 extern audio_driver_t audio_wasapi; 631 extern audio_driver_t audio_coreaudio; 632 extern audio_driver_t audio_coreaudio3; 633 extern audio_driver_t audio_xenon360; 634 extern audio_driver_t audio_ps3; 635 extern audio_driver_t audio_gx; 636 extern audio_driver_t audio_ax; 637 extern audio_driver_t audio_psp; 638 extern audio_driver_t audio_ps2; 639 extern audio_driver_t audio_ctr_csnd; 640 extern audio_driver_t audio_ctr_dsp; 641 #ifdef HAVE_THREADS 642 extern audio_driver_t audio_ctr_dsp_thread; 643 #endif 644 extern audio_driver_t audio_switch; 645 extern audio_driver_t audio_switch_thread; 646 extern audio_driver_t audio_switch_libnx_audren; 647 extern audio_driver_t audio_switch_libnx_audren_thread; 648 extern audio_driver_t audio_rwebaudio; 649 650 /* Recording */ 651 652 enum ffemu_pix_format 653 { 654 FFEMU_PIX_RGB565 = 0, 655 FFEMU_PIX_BGR24, 656 FFEMU_PIX_ARGB8888 657 }; 658 659 enum streaming_mode 660 { 661 STREAMING_MODE_TWITCH = 0, 662 STREAMING_MODE_YOUTUBE, 663 STREAMING_MODE_FACEBOOK, 664 STREAMING_MODE_LOCAL, 665 STREAMING_MODE_CUSTOM 666 }; 667 668 enum record_config_type 669 { 670 RECORD_CONFIG_TYPE_RECORDING_CUSTOM = 0, 671 RECORD_CONFIG_TYPE_RECORDING_LOW_QUALITY, 672 RECORD_CONFIG_TYPE_RECORDING_MED_QUALITY, 673 RECORD_CONFIG_TYPE_RECORDING_HIGH_QUALITY, 674 RECORD_CONFIG_TYPE_RECORDING_LOSSLESS_QUALITY, 675 RECORD_CONFIG_TYPE_RECORDING_WEBM_FAST, 676 RECORD_CONFIG_TYPE_RECORDING_WEBM_HIGH_QUALITY, 677 RECORD_CONFIG_TYPE_RECORDING_GIF, 678 RECORD_CONFIG_TYPE_RECORDING_APNG, 679 RECORD_CONFIG_TYPE_STREAMING_CUSTOM, 680 RECORD_CONFIG_TYPE_STREAMING_LOW_QUALITY, 681 RECORD_CONFIG_TYPE_STREAMING_MED_QUALITY, 682 RECORD_CONFIG_TYPE_STREAMING_HIGH_QUALITY, 683 RECORD_CONFIG_TYPE_STREAMING_NETPLAY 684 685 }; 686 687 /* Parameters passed to ffemu_new() */ 688 struct record_params 689 { 690 /* Framerate per second of input video. */ 691 double fps; 692 /* Sample rate of input audio. */ 693 double samplerate; 694 695 /* Filename to dump to. */ 696 const char *filename; 697 698 /* Path to config. Optional. */ 699 const char *config; 700 701 const char *audio_resampler; 702 703 /* Desired output resolution. */ 704 unsigned out_width; 705 unsigned out_height; 706 707 /* Total size of framebuffer used in input. */ 708 unsigned fb_width; 709 unsigned fb_height; 710 711 /* Audio channels. */ 712 unsigned channels; 713 714 unsigned video_record_scale_factor; 715 unsigned video_stream_scale_factor; 716 unsigned video_record_threads; 717 unsigned streaming_mode; 718 719 /* Aspect ratio of input video. Parameters are passed to the muxer, 720 * the video itself is not scaled. 721 */ 722 float aspect_ratio; 723 724 enum record_config_type preset; 725 726 /* Input pixel format. */ 727 enum ffemu_pix_format pix_fmt; 728 729 bool video_gpu_record; 730 }; 731 732 struct record_video_data 733 { 734 const void *data; 735 unsigned width; 736 unsigned height; 737 int pitch; 738 bool is_dupe; 739 }; 740 741 struct record_audio_data 742 { 743 const void *data; 744 size_t frames; 745 }; 746 747 typedef struct record_driver 748 { 749 void *(*init)(const struct record_params *params); 750 void (*free)(void *data); 751 bool (*push_video)(void *data, const struct record_video_data *video_data); 752 bool (*push_audio)(void *data, const struct record_audio_data *audio_data); 753 bool (*finalize)(void *data); 754 const char *ident; 755 } record_driver_t; 756 757 extern const record_driver_t record_ffmpeg; 758 759 /** 760 * config_get_record_driver_options: 761 * 762 * Get an enumerated list of all record driver names, separated by '|'. 763 * 764 * Returns: string listing of all record driver names, separated by '|'. 765 **/ 766 const char* config_get_record_driver_options(void); 767 768 bool recording_is_enabled(void); 769 770 void streaming_set_state(bool state); 771 772 bool streaming_is_enabled(void); 773 774 void recording_driver_update_streaming_url(void); 775 776 /* Video */ 777 778 #ifdef HAVE_OVERLAY 779 #include "input/input_overlay.h" 780 #endif 781 782 #ifdef HAVE_VIDEO_LAYOUT 783 #include "gfx/video_layout.h" 784 #endif 785 786 #include "gfx/video_defines.h" 787 #include "gfx/video_coord_array.h" 788 789 #include "input/input_driver.h" 790 #include "input/input_types.h" 791 792 #define RARCH_SCALE_BASE 256 793 794 #define VIDEO_SHADER_STOCK_BLEND (GFX_MAX_SHADERS - 1) 795 #define VIDEO_SHADER_MENU (GFX_MAX_SHADERS - 2) 796 #define VIDEO_SHADER_MENU_2 (GFX_MAX_SHADERS - 3) 797 #define VIDEO_SHADER_MENU_3 (GFX_MAX_SHADERS - 4) 798 #define VIDEO_SHADER_MENU_4 (GFX_MAX_SHADERS - 5) 799 #define VIDEO_SHADER_MENU_5 (GFX_MAX_SHADERS - 6) 800 #define VIDEO_SHADER_MENU_6 (GFX_MAX_SHADERS - 7) 801 802 #if defined(_XBOX360) 803 #define DEFAULT_SHADER_TYPE RARCH_SHADER_HLSL 804 #elif defined(__PSL1GHT__) || defined(HAVE_OPENGLES2) || defined(HAVE_GLSL) 805 #define DEFAULT_SHADER_TYPE RARCH_SHADER_GLSL 806 #elif defined(HAVE_CG) 807 #define DEFAULT_SHADER_TYPE RARCH_SHADER_CG 808 #else 809 #define DEFAULT_SHADER_TYPE RARCH_SHADER_NONE 810 #endif 811 812 #ifndef MAX_EGLIMAGE_TEXTURES 813 #define MAX_EGLIMAGE_TEXTURES 32 814 #endif 815 816 #define MAX_VARIABLES 64 817 818 enum 819 { 820 TEXTURES = 8, 821 TEXTURESMASK = TEXTURES - 1 822 }; 823 824 struct LinkInfo 825 { 826 struct video_shader_pass *pass; 827 unsigned tex_w, tex_h; 828 }; 829 830 enum gfx_ctx_api 831 { 832 GFX_CTX_NONE = 0, 833 GFX_CTX_OPENGL_API, 834 GFX_CTX_OPENGL_ES_API, 835 GFX_CTX_DIRECT3D8_API, 836 GFX_CTX_DIRECT3D9_API, 837 GFX_CTX_DIRECT3D10_API, 838 GFX_CTX_DIRECT3D11_API, 839 GFX_CTX_DIRECT3D12_API, 840 GFX_CTX_OPENVG_API, 841 GFX_CTX_VULKAN_API, 842 GFX_CTX_METAL_API, 843 GFX_CTX_RSX_API 844 }; 845 846 enum display_metric_types 847 { 848 DISPLAY_METRIC_NONE = 0, 849 DISPLAY_METRIC_MM_WIDTH, 850 DISPLAY_METRIC_MM_HEIGHT, 851 DISPLAY_METRIC_DPI, 852 DISPLAY_METRIC_PIXEL_WIDTH, 853 DISPLAY_METRIC_PIXEL_HEIGHT 854 }; 855 856 enum display_flags 857 { 858 GFX_CTX_FLAGS_NONE = 0, 859 GFX_CTX_FLAGS_GL_CORE_CONTEXT, 860 GFX_CTX_FLAGS_MULTISAMPLING, 861 GFX_CTX_FLAGS_CUSTOMIZABLE_SWAPCHAIN_IMAGES, 862 GFX_CTX_FLAGS_HARD_SYNC, 863 GFX_CTX_FLAGS_BLACK_FRAME_INSERTION, 864 GFX_CTX_FLAGS_MENU_FRAME_FILTERING, 865 GFX_CTX_FLAGS_ADAPTIVE_VSYNC, 866 GFX_CTX_FLAGS_SHADERS_GLSL, 867 GFX_CTX_FLAGS_SHADERS_CG, 868 GFX_CTX_FLAGS_SHADERS_HLSL, 869 GFX_CTX_FLAGS_SHADERS_SLANG, 870 GFX_CTX_FLAGS_SCREENSHOTS_SUPPORTED 871 }; 872 873 enum shader_uniform_type 874 { 875 UNIFORM_1F = 0, 876 UNIFORM_2F, 877 UNIFORM_3F, 878 UNIFORM_4F, 879 UNIFORM_1FV, 880 UNIFORM_2FV, 881 UNIFORM_3FV, 882 UNIFORM_4FV, 883 UNIFORM_1I 884 }; 885 886 enum shader_program_type 887 { 888 SHADER_PROGRAM_VERTEX = 0, 889 SHADER_PROGRAM_FRAGMENT, 890 SHADER_PROGRAM_COMBINED 891 }; 892 893 struct shader_program_info 894 { 895 void *data; 896 const char *vertex; 897 const char *fragment; 898 const char *combined; 899 unsigned idx; 900 bool is_file; 901 }; 902 903 struct uniform_info 904 { 905 bool enabled; 906 907 int32_t location; 908 int32_t count; 909 unsigned type; /* shader uniform type */ 910 911 struct 912 { 913 enum shader_program_type type; 914 const char *ident; 915 uint32_t idx; 916 bool add_prefix; 917 bool enable; 918 } lookup; 919 920 struct 921 { 922 float *floatv; 923 intptr_t *integerv; 924 uintptr_t *unsigned_integerv; 925 926 struct 927 { 928 intptr_t v0; 929 intptr_t v1; 930 intptr_t v2; 931 intptr_t v3; 932 } integer; 933 934 struct 935 { 936 uintptr_t v0; 937 uintptr_t v1; 938 uintptr_t v2; 939 uintptr_t v3; 940 } unsigned_integer; 941 942 struct 943 { 944 float v0; 945 float v1; 946 float v2; 947 float v3; 948 } f; 949 950 } result; 951 }; 952 953 typedef struct shader_backend 954 { 955 void *(*init)(void *data, const char *path); 956 void (*init_menu_shaders)(void *data); 957 void (*deinit)(void *data); 958 959 /* Set shader parameters. */ 960 void (*set_params)(void *data, void *shader_data); 961 962 void (*set_uniform_parameter)(void *data, struct uniform_info *param, 963 void *uniform_data); 964 965 /* Compile a shader program. */ 966 bool (*compile_program)(void *data, unsigned idx, 967 void *program_data, struct shader_program_info *program_info); 968 969 /* Use a shader program specified by variable 'index'. */ 970 void (*use)(void *data, void *shader_data, unsigned index, bool set_active); 971 972 /* Returns the number of currently loaded shaders. */ 973 unsigned (*num_shaders)(void *data); 974 975 bool (*filter_type)(void *data, unsigned index, bool *smooth); 976 enum gfx_wrap_type (*wrap_type)(void *data, unsigned index); 977 void (*shader_scale)(void *data, 978 unsigned index, struct gfx_fbo_scale *scale); 979 bool (*set_coords)(void *shader_data, const struct video_coords *coords); 980 bool (*set_mvp)(void *shader_data, const void *mat_data); 981 unsigned (*get_prev_textures)(void *data); 982 bool (*get_feedback_pass)(void *data, unsigned *pass); 983 bool (*mipmap_input)(void *data, unsigned index); 984 985 struct video_shader *(*get_current_shader)(void *data); 986 987 void (*get_flags)(uint32_t*); 988 989 enum rarch_shader_type type; 990 991 /* Human readable string. */ 992 const char *ident; 993 } shader_backend_t; 994 995 typedef struct video_shader_ctx_init 996 { 997 const char *path; 998 const shader_backend_t *shader; 999 void *data; 1000 void *shader_data; 1001 enum rarch_shader_type shader_type; 1002 struct 1003 { 1004 bool core_context_enabled; 1005 } gl; 1006 } video_shader_ctx_init_t; 1007 1008 typedef struct video_shader_ctx_params 1009 { 1010 void *data; 1011 const void *info; 1012 const void *prev_info; 1013 const void *feedback_info; 1014 const void *fbo_info; 1015 unsigned width; 1016 unsigned height; 1017 unsigned tex_width; 1018 unsigned tex_height; 1019 unsigned out_width; 1020 unsigned out_height; 1021 unsigned frame_counter; 1022 unsigned fbo_info_cnt; 1023 } video_shader_ctx_params_t; 1024 1025 typedef struct video_shader_ctx_coords 1026 { 1027 void *handle_data; 1028 const void *data; 1029 } video_shader_ctx_coords_t; 1030 1031 typedef struct video_shader_ctx_scale 1032 { 1033 struct gfx_fbo_scale *scale; 1034 unsigned idx; 1035 } video_shader_ctx_scale_t; 1036 1037 typedef struct video_shader_ctx_info 1038 { 1039 void *data; 1040 unsigned num; 1041 unsigned idx; 1042 bool set_active; 1043 } video_shader_ctx_info_t; 1044 1045 typedef struct video_shader_ctx_mvp 1046 { 1047 void *data; 1048 const void *matrix; 1049 } video_shader_ctx_mvp_t; 1050 1051 typedef struct video_shader_ctx_filter 1052 { 1053 bool *smooth; 1054 unsigned index; 1055 } video_shader_ctx_filter_t; 1056 1057 typedef struct video_shader_ctx 1058 { 1059 struct video_shader *data; 1060 } video_shader_ctx_t; 1061 1062 typedef struct video_shader_ctx_texture 1063 { 1064 unsigned id; 1065 } video_shader_ctx_texture_t; 1066 1067 typedef void (*gfx_ctx_proc_t)(void); 1068 1069 typedef struct video_info 1070 { 1071 const char *path_font; 1072 1073 uintptr_t parent; 1074 1075 int swap_interval; 1076 1077 1078 /* Width of window. 1079 * If fullscreen mode is requested, 1080 * a width of 0 means the resolution of the 1081 * desktop should be used. */ 1082 unsigned width; 1083 1084 /* Height of window. 1085 * If fullscreen mode is requested, 1086 * a height of 0 means the resolutiof the desktop should be used. 1087 */ 1088 unsigned height; 1089 1090 #ifdef GEKKO 1091 /* TODO - we can't really have driver system-specific 1092 * variables in here. There should be some 1093 * kind of publicly accessible driver implementation 1094 * video struct for specific things like this. 1095 */ 1096 1097 /* Wii-specific settings. Ignored for everything else. */ 1098 unsigned viwidth; 1099 #endif 1100 1101 /* 1102 * input_scale defines the maximum size of the picture that will 1103 * ever be used with the frame callback. 1104 * 1105 * The maximum resolution is a multiple of 256x256 size (RARCH_SCALE_BASE), 1106 * so an input scale of 2 means you should allocate a texture or of 512x512. 1107 * 1108 * Maximum input size: RARCH_SCALE_BASE * input_scale 1109 */ 1110 unsigned input_scale; 1111 1112 float font_size; 1113 1114 bool adaptive_vsync; 1115 1116 #ifdef GEKKO 1117 bool vfilter; 1118 #endif 1119 1120 /* If true, applies bilinear filtering to the image, 1121 * otherwise nearest filtering. */ 1122 bool smooth; 1123 1124 bool ctx_scaling; 1125 1126 bool is_threaded; 1127 1128 /* Use 32bit RGBA rather than native RGB565/XBGR1555. 1129 * 1130 * XRGB1555 format is 16-bit and has byte ordering: 0RRRRRGGGGGBBBBB, 1131 * in native endian. 1132 * 1133 * ARGB8888 is AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB, native endian. 1134 * Alpha channel should be disregarded. 1135 * */ 1136 bool rgb32; 1137 1138 /* Launch in fullscreen mode instead of windowed mode. */ 1139 bool fullscreen; 1140 1141 /* Start with V-Sync enabled. */ 1142 bool vsync; 1143 1144 /* If true, the output image should have the aspect ratio 1145 * as set in aspect_ratio. */ 1146 bool force_aspect; 1147 1148 bool font_enable; 1149 } video_info_t; 1150 1151 typedef struct video_frame_info 1152 { 1153 void *userdata; 1154 void *widgets_userdata; 1155 void *disp_userdata; 1156 1157 int custom_vp_x; 1158 int custom_vp_y; 1159 int crt_switch_center_adjust; 1160 int crt_switch_porch_adjust; 1161 1162 unsigned hard_sync_frames; 1163 unsigned aspect_ratio_idx; 1164 unsigned max_swapchain_images; 1165 unsigned monitor_index; 1166 unsigned crt_switch_resolution; 1167 unsigned crt_switch_resolution_super; 1168 unsigned width; 1169 unsigned height; 1170 unsigned xmb_theme; 1171 unsigned xmb_color_theme; 1172 unsigned menu_shader_pipeline; 1173 unsigned materialui_color_theme; 1174 unsigned ozone_color_theme; 1175 unsigned custom_vp_width; 1176 unsigned custom_vp_height; 1177 unsigned custom_vp_full_width; 1178 unsigned custom_vp_full_height; 1179 unsigned black_frame_insertion; 1180 unsigned fps_update_interval; 1181 unsigned memory_update_interval; 1182 1183 float menu_wallpaper_opacity; 1184 float menu_framebuffer_opacity; 1185 float menu_header_opacity; 1186 float menu_footer_opacity; 1187 float refresh_rate; 1188 float font_msg_pos_x; 1189 float font_msg_pos_y; 1190 float font_msg_color_r; 1191 float font_msg_color_g; 1192 float font_msg_color_b; 1193 float xmb_alpha_factor; 1194 1195 1196 struct 1197 { 1198 /* Drop shadow offset. 1199 * If both are 0, no drop shadow will be rendered. */ 1200 int drop_x, drop_y; 1201 /* ABGR. Use the macros. */ 1202 uint32_t color; 1203 float x; 1204 float y; 1205 float scale; 1206 /* Drop shadow color multiplier. */ 1207 float drop_mod; 1208 /* Drop shadow alpha */ 1209 float drop_alpha; 1210 enum text_alignment text_align; 1211 bool full_screen; 1212 } osd_stat_params; 1213 1214 char stat_text[512]; 1215 1216 bool widgets_active; 1217 bool menu_mouse_enable; 1218 bool widgets_is_paused; 1219 bool widgets_is_fast_forwarding; 1220 bool widgets_is_rewinding; 1221 bool input_menu_swap_ok_cancel_buttons; 1222 bool input_driver_nonblock_state; 1223 bool input_driver_grab_mouse_state; 1224 bool hard_sync; 1225 bool fps_show; 1226 bool memory_show; 1227 bool statistics_show; 1228 bool framecount_show; 1229 bool core_status_msg_show; 1230 bool post_filter_record; 1231 bool windowed_fullscreen; 1232 bool fullscreen; 1233 bool font_enable; 1234 bool use_rgba; 1235 bool libretro_running; 1236 bool xmb_shadows_enable; 1237 bool battery_level_enable; 1238 bool timedate_enable; 1239 bool runloop_is_slowmotion; 1240 bool runloop_is_paused; 1241 bool menu_is_alive; 1242 bool menu_screensaver_active; 1243 bool msg_bgcolor_enable; 1244 bool crt_switch_hires_menu; 1245 1246 } video_frame_info_t; 1247 1248 typedef void (*update_window_title_cb)(void*); 1249 typedef bool (*get_metrics_cb)(void *data, enum display_metric_types type, 1250 float *value); 1251 typedef bool (*set_resize_cb)(void*, unsigned, unsigned); 1252 1253 typedef struct gfx_ctx_driver 1254 { 1255 /* The opaque pointer is the underlying video driver data (e.g. gl_t for 1256 * OpenGL contexts). Although not advised, the context driver is allowed 1257 * to hold a pointer to it as the context never outlives the video driver. 1258 * 1259 * The context driver is responsible for it's own data.*/ 1260 void* (*init)(void *video_driver); 1261 void (*destroy)(void *data); 1262 1263 enum gfx_ctx_api (*get_api)(void *data); 1264 1265 /* Which API to bind to. */ 1266 bool (*bind_api)(void *video_driver, enum gfx_ctx_api, 1267 unsigned major, unsigned minor); 1268 1269 /* Sets the swap interval. */ 1270 void (*swap_interval)(void *data, int); 1271 1272 /* Sets video mode. Creates a window, etc. */ 1273 bool (*set_video_mode)(void*, unsigned, unsigned, bool); 1274 1275 /* Gets current window size. 1276 * If not initialized yet, it returns current screen size. */ 1277 void (*get_video_size)(void*, unsigned*, unsigned*); 1278 1279 float (*get_refresh_rate)(void*); 1280 1281 void (*get_video_output_size)(void*, unsigned*, unsigned*); 1282 1283 void (*get_video_output_prev)(void*); 1284 1285 void (*get_video_output_next)(void*); 1286 1287 get_metrics_cb get_metrics; 1288 1289 /* Translates a window size to an aspect ratio. 1290 * In most cases this will be just width / height, but 1291 * some contexts will better know which actual aspect ratio is used. 1292 * This can be NULL to assume the default behavior. 1293 */ 1294 float (*translate_aspect)(void*, unsigned, unsigned); 1295 1296 /* Asks driver to update window title (FPS, etc). */ 1297 update_window_title_cb update_window_title; 1298 1299 /* Queries for resize and quit events. 1300 * Also processes events. */ 1301 void (*check_window)(void*, bool*, bool*, 1302 unsigned*, unsigned*); 1303 1304 /* Acknowledge a resize event. This is needed for some APIs. 1305 * Most backends will ignore this. */ 1306 set_resize_cb set_resize; 1307 1308 /* Checks if window has input focus. */ 1309 bool (*has_focus)(void*); 1310 1311 /* Should the screensaver be suppressed? */ 1312 bool (*suppress_screensaver)(void *data, bool enable); 1313 1314 /* Checks if context driver has windowed support. */ 1315 bool has_windowed; 1316 1317 /* Swaps buffers. VBlank sync depends on 1318 * earlier calls to swap_interval. */ 1319 void (*swap_buffers)(void*); 1320 1321 /* Most video backends will want to use a certain input driver. 1322 * Checks for it here. */ 1323 void (*input_driver)(void*, const char *, input_driver_t**, void**); 1324 1325 /* Wraps whatever gl_proc_address() there is. 1326 * Does not take opaque, to avoid lots of ugly wrapper code. */ 1327 gfx_ctx_proc_t (*get_proc_address)(const char*); 1328 1329 /* Returns true if this context supports EGLImage buffers for 1330 * screen drawing and was initalized correctly. */ 1331 bool (*image_buffer_init)(void*, const video_info_t*); 1332 1333 /* Writes the frame to the EGLImage and sets image_handle to it. 1334 * Returns true if a new image handle is created. 1335 * Always returns true the first time it's called for a new index. 1336 * The graphics core must handle a change in the handle correctly. */ 1337 bool (*image_buffer_write)(void*, const void *frame, unsigned width, 1338 unsigned height, unsigned pitch, bool rgb32, 1339 unsigned index, void **image_handle); 1340 1341 /* Shows or hides mouse. Can be NULL if context doesn't 1342 * have a concept of mouse pointer. */ 1343 void (*show_mouse)(void *data, bool state); 1344 1345 /* Human readable string. */ 1346 const char *ident; 1347 1348 uint32_t (*get_flags)(void *data); 1349 1350 void (*set_flags)(void *data, uint32_t flags); 1351 1352 /* Optional. Binds HW-render offscreen context. */ 1353 void (*bind_hw_render)(void *data, bool enable); 1354 1355 /* Optional. Gets base data for the context which is used by the driver. 1356 * This is mostly relevant for graphics APIs such as Vulkan 1357 * which do not have global context state. */ 1358 void *(*get_context_data)(void *data); 1359 1360 /* Optional. Makes driver context (only GL right now) 1361 * active for this thread. */ 1362 void (*make_current)(bool release); 1363 } gfx_ctx_driver_t; 1364 1365 typedef struct gfx_ctx_size 1366 { 1367 bool *quit; 1368 bool *resize; 1369 unsigned *width; 1370 unsigned *height; 1371 } gfx_ctx_size_t; 1372 1373 typedef struct gfx_ctx_mode 1374 { 1375 unsigned width; 1376 unsigned height; 1377 bool fullscreen; 1378 } gfx_ctx_mode_t; 1379 1380 typedef struct gfx_ctx_metrics 1381 { 1382 float *value; 1383 enum display_metric_types type; 1384 } gfx_ctx_metrics_t; 1385 1386 typedef struct gfx_ctx_aspect 1387 { 1388 float *aspect; 1389 unsigned width; 1390 unsigned height; 1391 } gfx_ctx_aspect_t; 1392 1393 typedef struct gfx_ctx_input 1394 { 1395 input_driver_t **input; 1396 void **input_data; 1397 } gfx_ctx_input_t; 1398 1399 typedef struct gfx_ctx_ident 1400 { 1401 const char *ident; 1402 } gfx_ctx_ident_t; 1403 1404 struct aspect_ratio_elem 1405 { 1406 float value; 1407 char name[64]; 1408 }; 1409 1410 /* Optionally implemented interface to poke more 1411 * deeply into video driver. */ 1412 1413 typedef struct video_poke_interface 1414 { 1415 uint32_t (*get_flags)(void *data); 1416 uintptr_t (*load_texture)(void *video_data, void *data, 1417 bool threaded, enum texture_filter_type filter_type); 1418 void (*unload_texture)(void *data, bool threaded, uintptr_t id); 1419 void (*set_video_mode)(void *data, unsigned width, 1420 unsigned height, bool fullscreen); 1421 float (*get_refresh_rate)(void *data); 1422 void (*set_filtering)(void *data, unsigned index, bool smooth, bool ctx_scaling); 1423 void (*get_video_output_size)(void *data, 1424 unsigned *width, unsigned *height); 1425 1426 /* Move index to previous resolution */ 1427 void (*get_video_output_prev)(void *data); 1428 1429 /* Move index to next resolution */ 1430 void (*get_video_output_next)(void *data); 1431 1432 uintptr_t (*get_current_framebuffer)(void *data); 1433 retro_proc_address_t (*get_proc_address)(void *data, const char *sym); 1434 void (*set_aspect_ratio)(void *data, unsigned aspectratio_index); 1435 void (*apply_state_changes)(void *data); 1436 1437 /* Update texture. */ 1438 void (*set_texture_frame)(void *data, const void *frame, bool rgb32, 1439 unsigned width, unsigned height, float alpha); 1440 /* Enable or disable rendering. */ 1441 void (*set_texture_enable)(void *data, bool enable, bool full_screen); 1442 void (*set_osd_msg)(void *data, 1443 const char *msg, 1444 const void *params, void *font); 1445 1446 void (*show_mouse)(void *data, bool state); 1447 void (*grab_mouse_toggle)(void *data); 1448 1449 struct video_shader *(*get_current_shader)(void *data); 1450 bool (*get_current_software_framebuffer)(void *data, 1451 struct retro_framebuffer *framebuffer); 1452 bool (*get_hw_render_interface)(void *data, 1453 const struct retro_hw_render_interface **iface); 1454 } video_poke_interface_t; 1455 1456 /* msg is for showing a message on the screen 1457 * along with the video frame. */ 1458 typedef bool (*video_driver_frame_t)(void *data, 1459 const void *frame, unsigned width, 1460 unsigned height, uint64_t frame_count, 1461 unsigned pitch, const char *msg, video_frame_info_t *video_info); 1462 1463 typedef struct video_driver 1464 { 1465 /* Should the video driver act as an input driver as well? 1466 * The video initialization might preinitialize an input driver 1467 * to override the settings in case the video driver relies on 1468 * input driver for event handling. */ 1469 void *(*init)(const video_info_t *video, 1470 input_driver_t **input, 1471 void **input_data); 1472 1473 /* Updates frame on the screen. 1474 * Frame can be either XRGB1555, RGB565 or ARGB32 format 1475 * depending on rgb32 setting in video_info_t. 1476 * Pitch is the distance in bytes between two scanlines in memory. 1477 * 1478 * When msg is non-NULL, 1479 * it's a message that should be displayed to the user. */ 1480 video_driver_frame_t frame; 1481 1482 /* Should we care about syncing to vblank? Fast forwarding. 1483 * 1484 * Requests nonblocking operation. 1485 * 1486 * True = VSync is turned off. 1487 * False = VSync is turned on. 1488 * */ 1489 void (*set_nonblock_state)(void *data, bool toggle, 1490 bool adaptive_vsync_enabled, 1491 unsigned swap_interval); 1492 1493 /* Is the window still active? */ 1494 bool (*alive)(void *data); 1495 1496 /* Does the window have focus? */ 1497 bool (*focus)(void *data); 1498 1499 /* Should the screensaver be suppressed? */ 1500 bool (*suppress_screensaver)(void *data, bool enable); 1501 1502 /* Does the graphics context support windowed mode? */ 1503 bool (*has_windowed)(void *data); 1504 1505 /* Sets shader. Might not be implemented. Will be moved to 1506 * poke_interface later. */ 1507 bool (*set_shader)(void *data, enum rarch_shader_type type, 1508 const char *path); 1509 1510 /* Frees driver. */ 1511 void (*free)(void *data); 1512 1513 /* Human-readable identifier. */ 1514 const char *ident; 1515 1516 void (*set_viewport)(void *data, unsigned width, unsigned height, 1517 bool force_full, bool allow_rotate); 1518 1519 void (*set_rotation)(void *data, unsigned rotation); 1520 void (*viewport_info)(void *data, struct video_viewport *vp); 1521 1522 /* Reads out in BGR byte order (24bpp). */ 1523 bool (*read_viewport)(void *data, uint8_t *buffer, bool is_idle); 1524 1525 /* Returns a pointer to a newly allocated buffer that can 1526 * (and must) be passed to free() by the caller, containing a 1527 * copy of the current raw frame in the active pixel format 1528 * and sets width, height and pitch to the correct values. */ 1529 void* (*read_frame_raw)(void *data, unsigned *width, 1530 unsigned *height, size_t *pitch); 1531 1532 #ifdef HAVE_OVERLAY 1533 void (*overlay_interface)(void *data, 1534 const video_overlay_interface_t **iface); 1535 #endif 1536 #ifdef HAVE_VIDEO_LAYOUT 1537 const video_layout_render_interface_t *(*video_layout_render_interface)(void *data); 1538 #endif 1539 void (*poke_interface)(void *data, const video_poke_interface_t **iface); 1540 unsigned (*wrap_type_to_enum)(enum gfx_wrap_type type); 1541 1542 #if defined(HAVE_GFX_WIDGETS) 1543 /* if set to true, will use display widgets when applicable 1544 * if set to false, will use OSD as a fallback */ 1545 bool (*gfx_widgets_enabled)(void *data); 1546 #endif 1547 } video_driver_t; 1548 1549 extern struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END]; 1550 1551 bool video_driver_has_windowed(void); 1552 1553 bool video_driver_has_focus(void); 1554 1555 bool video_driver_cached_frame_has_valid_framebuffer(void); 1556 1557 void video_driver_set_cached_frame_ptr(const void *data); 1558 1559 void video_driver_set_stub_frame(void); 1560 1561 void video_driver_unset_stub_frame(void); 1562 1563 bool video_driver_supports_viewport_read(void); 1564 1565 bool video_driver_prefer_viewport_read(void); 1566 1567 bool video_driver_supports_read_frame_raw(void); 1568 1569 void video_driver_set_viewport_core(void); 1570 1571 void video_driver_set_viewport_full(void); 1572 1573 void video_driver_reset_custom_viewport(void); 1574 1575 void video_driver_set_rgba(void); 1576 1577 void video_driver_unset_rgba(void); 1578 1579 bool video_driver_supports_rgba(void); 1580 1581 bool video_driver_get_next_video_out(void); 1582 1583 bool video_driver_get_prev_video_out(void); 1584 1585 void video_driver_monitor_reset(void); 1586 1587 void video_driver_set_aspect_ratio(void); 1588 1589 void video_driver_update_viewport(struct video_viewport* vp, bool force_full, bool keep_aspect); 1590 1591 void video_driver_show_mouse(void); 1592 1593 void video_driver_hide_mouse(void); 1594 1595 void video_driver_apply_state_changes(void); 1596 1597 bool video_driver_read_viewport(uint8_t *buffer, bool is_idle); 1598 1599 void video_driver_cached_frame(void); 1600 1601 bool video_driver_is_hw_context(void); 1602 1603 struct retro_hw_render_callback *video_driver_get_hw_context(void); 1604 1605 const struct retro_hw_render_context_negotiation_interface 1606 *video_driver_get_context_negotiation_interface(void); 1607 1608 bool video_driver_is_video_cache_context(void); 1609 1610 void video_driver_set_video_cache_context_ack(void); 1611 1612 bool video_driver_get_viewport_info(struct video_viewport *viewport); 1613 1614 /** 1615 * config_get_video_driver_options: 1616 * 1617 * Get an enumerated list of all video driver names, separated by '|'. 1618 * 1619 * Returns: string listing of all video driver names, separated by '|'. 1620 **/ 1621 const char* config_get_video_driver_options(void); 1622 1623 /** 1624 * video_driver_get_ptr: 1625 * 1626 * Use this if you need the real video driver 1627 * and driver data pointers. 1628 * 1629 * Returns: video driver's userdata. 1630 **/ 1631 void *video_driver_get_ptr(void); 1632 1633 void *video_driver_get_data(void); 1634 1635 bool video_driver_set_rotation(unsigned rotation); 1636 1637 bool video_driver_set_video_mode(unsigned width, 1638 unsigned height, bool fullscreen); 1639 1640 bool video_driver_get_video_output_size( 1641 unsigned *width, unsigned *height); 1642 1643 void video_driver_set_texture_enable(bool enable, bool full_screen); 1644 1645 void video_driver_set_texture_frame(const void *frame, bool rgb32, 1646 unsigned width, unsigned height, float alpha); 1647 1648 #ifdef HAVE_VIDEO_LAYOUT 1649 const video_layout_render_interface_t *video_driver_layout_render_interface(void); 1650 #endif 1651 1652 void * video_driver_read_frame_raw(unsigned *width, 1653 unsigned *height, size_t *pitch); 1654 1655 void video_driver_set_filtering(unsigned index, bool smooth, bool ctx_scaling); 1656 1657 const char *video_driver_get_ident(void); 1658 1659 void video_driver_set_viewport(unsigned width, unsigned height, 1660 bool force_fullscreen, bool allow_rotate); 1661 1662 void video_driver_get_size(unsigned *width, unsigned *height); 1663 1664 void video_driver_set_size(unsigned width, unsigned height); 1665 1666 float video_driver_get_aspect_ratio(void); 1667 1668 void video_driver_set_aspect_ratio_value(float value); 1669 1670 enum retro_pixel_format video_driver_get_pixel_format(void); 1671 1672 void video_driver_cached_frame_set(const void *data, unsigned width, 1673 unsigned height, size_t pitch); 1674 1675 void video_driver_cached_frame_get(const void **data, unsigned *width, 1676 unsigned *height, size_t *pitch); 1677 1678 void video_driver_menu_settings(void **list_data, void *list_info_data, 1679 void *group_data, void *subgroup_data, const char *parent_group); 1680 1681 /** 1682 * video_viewport_get_scaled_integer: 1683 * @vp : Viewport handle 1684 * @width : Width. 1685 * @height : Height. 1686 * @aspect_ratio : Aspect ratio (in float). 1687 * @keep_aspect : Preserve aspect ratio? 1688 * 1689 * Gets viewport scaling dimensions based on 1690 * scaled integer aspect ratio. 1691 **/ 1692 void video_viewport_get_scaled_integer(struct video_viewport *vp, 1693 unsigned width, unsigned height, 1694 float aspect_ratio, bool keep_aspect); 1695 1696 struct retro_system_av_info *video_viewport_get_system_av_info(void); 1697 1698 struct video_viewport *video_viewport_get_custom(void); 1699 1700 /** 1701 * video_monitor_set_refresh_rate: 1702 * @hz : New refresh rate for monitor. 1703 * 1704 * Sets monitor refresh rate to new value. 1705 **/ 1706 void video_monitor_set_refresh_rate(float hz); 1707 1708 /** 1709 * video_monitor_fps_statistics 1710 * @refresh_rate : Monitor refresh rate. 1711 * @deviation : Deviation from measured refresh rate. 1712 * @sample_points : Amount of sampled points. 1713 * 1714 * Gets the monitor FPS statistics based on the current 1715 * runtime. 1716 * 1717 * Returns: true (1) on success. 1718 * false (0) if: 1719 * a) threaded video mode is enabled 1720 * b) less than 2 frame time samples. 1721 * c) FPS monitor enable is off. 1722 **/ 1723 bool video_monitor_fps_statistics(double *refresh_rate, 1724 double *deviation, unsigned *sample_points); 1725 1726 void crt_switch_driver_refresh(void); 1727 1728 char* crt_switch_core_name(void); 1729 1730 #define video_driver_translate_coord_viewport_wrap(vp, mouse_x, mouse_y, res_x, res_y, res_screen_x, res_screen_y) \ 1731 (video_driver_get_viewport_info(vp) ? video_driver_translate_coord_viewport(vp, mouse_x, mouse_y, res_x, res_y, res_screen_x, res_screen_y) : false) 1732 1733 /** 1734 * video_driver_translate_coord_viewport: 1735 * @mouse_x : Pointer X coordinate. 1736 * @mouse_y : Pointer Y coordinate. 1737 * @res_x : Scaled X coordinate. 1738 * @res_y : Scaled Y coordinate. 1739 * @res_screen_x : Scaled screen X coordinate. 1740 * @res_screen_y : Scaled screen Y coordinate. 1741 * 1742 * Translates pointer [X,Y] coordinates into scaled screen 1743 * coordinates based on viewport info. 1744 * 1745 * Returns: true (1) if successful, false if video driver doesn't support 1746 * viewport info. 1747 **/ 1748 bool video_driver_translate_coord_viewport( 1749 struct video_viewport *vp, 1750 int mouse_x, int mouse_y, 1751 int16_t *res_x, int16_t *res_y, int16_t *res_screen_x, 1752 int16_t *res_screen_y); 1753 1754 uintptr_t video_driver_display_userdata_get(void); 1755 1756 uintptr_t video_driver_display_get(void); 1757 1758 enum rarch_display_type video_driver_display_type_get(void); 1759 1760 uintptr_t video_driver_window_get(void); 1761 1762 void video_driver_display_type_set(enum rarch_display_type type); 1763 1764 void video_driver_display_set(uintptr_t idx); 1765 1766 void video_driver_display_userdata_set(uintptr_t idx); 1767 1768 void video_driver_window_set(uintptr_t idx); 1769 1770 uintptr_t video_driver_window_get(void); 1771 1772 bool video_driver_texture_load(void *data, 1773 enum texture_filter_type filter_type, 1774 uintptr_t *id); 1775 1776 bool video_driver_texture_unload(uintptr_t *id); 1777 1778 void video_driver_build_info(video_frame_info_t *video_info); 1779 1780 void video_driver_reinit(int flags); 1781 1782 void video_driver_get_window_title(char *buf, unsigned len); 1783 1784 bool *video_driver_get_threaded(void); 1785 1786 void video_driver_set_threaded(bool val); 1787 1788 /** 1789 * video_context_driver_init_first: 1790 * @data : Input data. 1791 * @ident : Identifier of graphics context driver to find. 1792 * @api : API of higher-level graphics API. 1793 * @major : Major version number of higher-level graphics API. 1794 * @minor : Minor version number of higher-level graphics API. 1795 * @hw_render_ctx : Request a graphics context driver capable of 1796 * hardware rendering? 1797 * 1798 * Finds first suitable graphics context driver and initializes. 1799 * 1800 * Returns: graphics context driver if found, otherwise NULL. 1801 **/ 1802 const gfx_ctx_driver_t *video_context_driver_init_first( 1803 void *data, const char *ident, 1804 enum gfx_ctx_api api, unsigned major, unsigned minor, 1805 bool hw_render_ctx, void **ctx_data); 1806 1807 bool video_context_driver_set(const gfx_ctx_driver_t *data); 1808 1809 void video_context_driver_destroy(void); 1810 1811 bool video_context_driver_get_ident(gfx_ctx_ident_t *ident); 1812 1813 bool video_context_driver_get_refresh_rate(float *refresh_rate); 1814 1815 bool video_context_driver_set_flags(gfx_ctx_flags_t *flags); 1816 1817 bool video_context_driver_get_metrics(gfx_ctx_metrics_t *metrics); 1818 1819 enum gfx_ctx_api video_context_driver_get_api(void); 1820 1821 void video_context_driver_free(void); 1822 1823 bool video_shader_driver_get_current_shader(video_shader_ctx_t *shader); 1824 1825 float video_driver_get_refresh_rate(void); 1826 1827 #if defined(HAVE_GFX_WIDGETS) 1828 bool video_driver_has_widgets(void); 1829 #endif 1830 1831 bool video_driver_started_fullscreen(void); 1832 1833 bool video_driver_is_threaded(void); 1834 1835 bool video_context_driver_get_flags(gfx_ctx_flags_t *flags); 1836 1837 bool video_driver_test_all_flags(enum display_flags testflag); 1838 1839 gfx_ctx_flags_t video_driver_get_flags_wrapper(void); 1840 1841 void video_driver_set_gpu_device_string(const char *str); 1842 1843 const char* video_driver_get_gpu_device_string(void); 1844 1845 void video_driver_set_gpu_api_version_string(const char *str); 1846 1847 const char* video_driver_get_gpu_api_version_string(void); 1848 1849 /* string list stays owned by the caller and must be available at all times after the video driver is inited */ 1850 void video_driver_set_gpu_api_devices(enum gfx_ctx_api api, struct string_list *list); 1851 1852 struct string_list* video_driver_get_gpu_api_devices(enum gfx_ctx_api api); 1853 1854 extern video_driver_t video_gl_core; 1855 extern video_driver_t video_gl2; 1856 extern video_driver_t video_gl1; 1857 extern video_driver_t video_vulkan; 1858 extern video_driver_t video_metal; 1859 extern video_driver_t video_psp1; 1860 extern video_driver_t video_vita2d; 1861 extern video_driver_t video_ps2; 1862 extern video_driver_t video_ctr; 1863 extern video_driver_t video_gcm; 1864 extern video_driver_t video_switch; 1865 extern video_driver_t video_d3d8; 1866 extern video_driver_t video_d3d9; 1867 extern video_driver_t video_d3d10; 1868 extern video_driver_t video_d3d11; 1869 extern video_driver_t video_d3d12; 1870 extern video_driver_t video_gx; 1871 extern video_driver_t video_wiiu; 1872 extern video_driver_t video_xenon360; 1873 extern video_driver_t video_xvideo; 1874 extern video_driver_t video_sdl; 1875 extern video_driver_t video_sdl2; 1876 extern video_driver_t video_sdl_dingux; 1877 extern video_driver_t video_sdl_rs90; 1878 extern video_driver_t video_vg; 1879 extern video_driver_t video_omap; 1880 extern video_driver_t video_exynos; 1881 extern video_driver_t video_dispmanx; 1882 extern video_driver_t video_sunxi; 1883 extern video_driver_t video_drm; 1884 extern video_driver_t video_xshm; 1885 extern video_driver_t video_caca; 1886 extern video_driver_t video_gdi; 1887 extern video_driver_t video_vga; 1888 extern video_driver_t video_fpga; 1889 extern video_driver_t video_sixel; 1890 extern video_driver_t video_network; 1891 extern video_driver_t video_oga; 1892 1893 extern const gfx_ctx_driver_t gfx_ctx_osmesa; 1894 extern const gfx_ctx_driver_t gfx_ctx_sdl_gl; 1895 extern const gfx_ctx_driver_t gfx_ctx_x_egl; 1896 extern const gfx_ctx_driver_t gfx_ctx_uwp; 1897 extern const gfx_ctx_driver_t gfx_ctx_vk_wayland; 1898 extern const gfx_ctx_driver_t gfx_ctx_wayland; 1899 extern const gfx_ctx_driver_t gfx_ctx_x; 1900 extern const gfx_ctx_driver_t gfx_ctx_vk_x; 1901 extern const gfx_ctx_driver_t gfx_ctx_drm; 1902 extern const gfx_ctx_driver_t gfx_ctx_go2_drm; 1903 extern const gfx_ctx_driver_t gfx_ctx_mali_fbdev; 1904 extern const gfx_ctx_driver_t gfx_ctx_vivante_fbdev; 1905 extern const gfx_ctx_driver_t gfx_ctx_android; 1906 extern const gfx_ctx_driver_t gfx_ctx_vk_android; 1907 extern const gfx_ctx_driver_t gfx_ctx_ps3; 1908 extern const gfx_ctx_driver_t gfx_ctx_w_vk; 1909 extern const gfx_ctx_driver_t gfx_ctx_wgl; 1910 extern const gfx_ctx_driver_t gfx_ctx_videocore; 1911 extern const gfx_ctx_driver_t gfx_ctx_qnx; 1912 extern const gfx_ctx_driver_t gfx_ctx_cgl; 1913 extern const gfx_ctx_driver_t gfx_ctx_cocoagl; 1914 extern const gfx_ctx_driver_t gfx_ctx_cocoavk; 1915 extern const gfx_ctx_driver_t gfx_ctx_emscripten; 1916 extern const gfx_ctx_driver_t gfx_ctx_opendingux_fbdev; 1917 extern const gfx_ctx_driver_t gfx_ctx_khr_display; 1918 extern const gfx_ctx_driver_t gfx_ctx_gdi; 1919 extern const gfx_ctx_driver_t gfx_ctx_fpga; 1920 extern const gfx_ctx_driver_t gfx_ctx_sixel; 1921 extern const gfx_ctx_driver_t gfx_ctx_network; 1922 extern const gfx_ctx_driver_t switch_ctx; 1923 extern const gfx_ctx_driver_t orbis_ctx; 1924 extern const gfx_ctx_driver_t vita_ctx; 1925 extern const gfx_ctx_driver_t gfx_ctx_null; 1926 1927 extern const shader_backend_t gl_glsl_backend; 1928 extern const shader_backend_t gl_cg_backend; 1929 1930 /* BSV Movie */ 1931 1932 void bsv_movie_frame_rewind(void); 1933 1934 /* Location */ 1935 1936 typedef struct location_driver 1937 { 1938 void *(*init)(void); 1939 void (*free)(void *data); 1940 1941 bool (*start)(void *data); 1942 void (*stop)(void *data); 1943 1944 bool (*get_position)(void *data, double *lat, double *lon, 1945 double *horiz_accuracy, double *vert_accuracy); 1946 void (*set_interval)(void *data, unsigned interval_msecs, 1947 unsigned interval_distance); 1948 const char *ident; 1949 } location_driver_t; 1950 1951 extern location_driver_t location_corelocation; 1952 extern location_driver_t location_android; 1953 1954 /** 1955 * config_get_location_driver_options: 1956 * 1957 * Get an enumerated list of all location driver names, 1958 * separated by '|'. 1959 * 1960 * Returns: string listing of all location driver names, 1961 * separated by '|'. 1962 **/ 1963 const char* config_get_location_driver_options(void); 1964 1965 /* Camera */ 1966 1967 typedef struct camera_driver 1968 { 1969 /* FIXME: params for initialization - queries for resolution, 1970 * framerate, color format which might or might not be honored. */ 1971 void *(*init)(const char *device, uint64_t buffer_types, 1972 unsigned width, unsigned height); 1973 1974 void (*free)(void *data); 1975 1976 bool (*start)(void *data); 1977 void (*stop)(void *data); 1978 1979 /* Polls the camera driver. 1980 * Will call the appropriate callback if a new frame is ready. 1981 * Returns true if a new frame was handled. */ 1982 bool (*poll)(void *data, 1983 retro_camera_frame_raw_framebuffer_t frame_raw_cb, 1984 retro_camera_frame_opengl_texture_t frame_gl_cb); 1985 1986 const char *ident; 1987 } camera_driver_t; 1988 1989 extern camera_driver_t camera_v4l2; 1990 extern camera_driver_t camera_android; 1991 extern camera_driver_t camera_rwebcam; 1992 extern camera_driver_t camera_avfoundation; 1993 1994 /** 1995 * config_get_camera_driver_options: 1996 * 1997 * Get an enumerated list of all camera driver names, 1998 * separated by '|'. 1999 * 2000 * Returns: string listing of all camera driver names, 2001 * separated by '|'. 2002 **/ 2003 const char* config_get_camera_driver_options(void); 2004 2005 bool menu_driver_is_alive(void); 2006 2007 bool gfx_widgets_ready(void); 2008 2009 unsigned int retroarch_get_rotation(void); 2010 2011 void retroarch_init_task_queue(void); 2012 2013 bool input_key_pressed(int key, bool keyboard_pressed); 2014 2015 bool input_mouse_grabbed(void); 2016 2017 const char *joypad_driver_name(unsigned i); 2018 void joypad_driver_reinit(void *data, const char *joypad_driver_name); 2019 2020 void input_driver_init_joypads(void); 2021 2022 void *input_driver_init_wrap(input_driver_t *input, const char *name); 2023 2024 /* Human readable order of input binds */ 2025 static const unsigned input_config_bind_order[] = { 2026 RETRO_DEVICE_ID_JOYPAD_UP, 2027 RETRO_DEVICE_ID_JOYPAD_DOWN, 2028 RETRO_DEVICE_ID_JOYPAD_LEFT, 2029 RETRO_DEVICE_ID_JOYPAD_RIGHT, 2030 RETRO_DEVICE_ID_JOYPAD_A, 2031 RETRO_DEVICE_ID_JOYPAD_B, 2032 RETRO_DEVICE_ID_JOYPAD_X, 2033 RETRO_DEVICE_ID_JOYPAD_Y, 2034 RETRO_DEVICE_ID_JOYPAD_SELECT, 2035 RETRO_DEVICE_ID_JOYPAD_START, 2036 RETRO_DEVICE_ID_JOYPAD_L, 2037 RETRO_DEVICE_ID_JOYPAD_R, 2038 RETRO_DEVICE_ID_JOYPAD_L2, 2039 RETRO_DEVICE_ID_JOYPAD_R2, 2040 RETRO_DEVICE_ID_JOYPAD_L3, 2041 RETRO_DEVICE_ID_JOYPAD_R3, 2042 19, /* Left Analog Up */ 2043 18, /* Left Analog Down */ 2044 17, /* Left Analog Left */ 2045 16, /* Left Analog Right */ 2046 23, /* Right Analog Up */ 2047 22, /* Right Analog Down */ 2048 21, /* Right Analog Left */ 2049 20, /* Right Analog Right */ 2050 }; 2051 2052 /* Creates folder and core options stub file for subsequent runs */ 2053 bool core_options_create_override(bool game_specific); 2054 bool core_options_remove_override(bool game_specific); 2055 void core_options_reset(void); 2056 2057 typedef enum apple_view_type 2058 { 2059 APPLE_VIEW_TYPE_NONE = 0, 2060 APPLE_VIEW_TYPE_OPENGL_ES, 2061 APPLE_VIEW_TYPE_OPENGL, 2062 APPLE_VIEW_TYPE_VULKAN, 2063 APPLE_VIEW_TYPE_METAL 2064 } apple_view_type_t; 2065 2066 RETRO_END_DECLS 2067 2068 #endif 2069