/* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen * Copyright (C) 2011-2015 - Daniel De Matteis * Copyright (C) 2012-2015 - Michael Lelli * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- * ation, either version 3 of the License, or (at your option) any later version. * * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with RetroArch. * If not, see . */ #include #include #include #include #include #include #include #include "libretro.h" #include "general.h" #include "runloop.h" #include "runloop_data.h" #include "retroarch.h" #include "rewind.h" #include "performance.h" #include "input/input_common.h" #include "input/input_remapping.h" #include "audio/audio_driver.h" #include "record/record_driver.h" #include "verbosity.h" #ifdef HAVE_NETPLAY #include "netplay.h" #endif /** * video_frame: * @data : pointer to data of the video frame. * @width : width of the video frame. * @height : height of the video frame. * @pitch : pitch of the video frame. * * Video frame render callback function. **/ static void video_frame(const void *data, unsigned width, unsigned height, size_t pitch) { unsigned output_width = 0; unsigned output_height = 0; unsigned output_pitch = 0; const char *msg = NULL; driver_t *driver = driver_get_ptr(); global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr(); if (!driver->video_active) return; if (video_pixel_frame_scale(data, width, height, pitch)) { video_pixel_scaler_t *scaler = scaler_get_ptr(); data = scaler->scaler_out; pitch = scaler->scaler->out_stride; } video_driver_cached_frame_set(data, width, height, pitch); /* Slightly messy code, * but we really need to do processing before blocking on VSync * for best possible scheduling. */ if ((!video_driver_ctl(RARCH_DISPLAY_CTL_FRAME_FILTER_ALIVE, NULL) || !settings->video.post_filter_record || !data || global->record.gpu_buffer) ) recording_dump_frame(data, width, height, pitch); if (video_driver_frame_filter(data, width, height, pitch, &output_width, &output_height, &output_pitch)) { data = video_driver_frame_filter_get_buf_ptr(); width = output_width; height = output_height; pitch = output_pitch; } msg = rarch_main_msg_queue_pull(); video_driver_frame(data, width, height, pitch, msg); } /** * retro_set_default_callbacks: * @data : pointer to retro_callbacks object * * Binds the libretro callbacks to default callback functions. **/ void retro_set_default_callbacks(void *data) { struct retro_callbacks *cbs = (struct retro_callbacks*)data; if (!cbs) return; cbs->frame_cb = video_frame; cbs->sample_cb = audio_driver_sample; cbs->sample_batch_cb = audio_driver_sample_batch; cbs->state_cb = input_state; cbs->poll_cb = input_poll; } /** * retro_init_libretro_cbs: * @data : pointer to retro_callbacks object * * Initializes libretro callbacks, and binds the libretro callbacks * to default callback functions. **/ void retro_init_libretro_cbs(void *data) { struct retro_callbacks *cbs = (struct retro_callbacks*)data; driver_t *driver = driver_get_ptr(); global_t *global = global_get_ptr(); if (!cbs) return; (void)driver; (void)global; core.retro_set_video_refresh(video_frame); core.retro_set_audio_sample(audio_driver_sample); core.retro_set_audio_sample_batch(audio_driver_sample_batch); core.retro_set_input_state(input_state); core.retro_set_input_poll(input_poll); retro_set_default_callbacks(cbs); #ifdef HAVE_NETPLAY if (!driver->netplay_data) return; if (global->netplay.is_spectate) { core.retro_set_input_state( (global->netplay.is_client ? input_state_spectate_client : input_state_spectate) ); } else { core.retro_set_video_refresh(video_frame_net); core.retro_set_audio_sample(audio_sample_net); core.retro_set_audio_sample_batch(audio_sample_batch_net); core.retro_set_input_state(input_state_net); } #endif } /** * retro_set_rewind_callbacks: * * Sets the audio sampling callbacks based on whether or not * rewinding is currently activated. **/ void retro_set_rewind_callbacks(void) { if (state_manager_frame_is_reversed()) { core.retro_set_audio_sample(audio_driver_sample_rewind); core.retro_set_audio_sample_batch(audio_driver_sample_batch_rewind); } else { core.retro_set_audio_sample(audio_driver_sample); core.retro_set_audio_sample_batch(audio_driver_sample_batch); } }