Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed Nov 7, 2021
1 parent c0585fe commit 88c771f
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 144 deletions.
2 changes: 1 addition & 1 deletion audio/audio_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@ void audio_driver_menu_sample(void)
const struct retro_system_timing *info =
(const struct retro_system_timing*)&av_info->timing;
unsigned sample_count = (info->sample_rate / info->fps) * 2;
audio_driver_state_t *audio_st = audio_state_get_ptr();
audio_driver_state_t *audio_st = &audio_driver_st;
bool check_flush = !(
runloop_st->paused
|| !audio_st->active
Expand Down
29 changes: 29 additions & 0 deletions driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <boolean.h>
#include <retro_common_api.h>

#include "configuration.h"

RETRO_BEGIN_DECLS

enum
Expand Down Expand Up @@ -101,6 +103,33 @@ int driver_find_index(const char *label, const char *drv);
* audio and video drivers instead. */
void driver_set_nonblock_state(void);

/**
* drivers_init:
* @flags : Bitmask of drivers to initialize.
*
* Initializes drivers.
* @flags determines which drivers get initialized.
**/
void drivers_init(settings_t *settings, int flags,
bool verbosity_enabled);

/**
* Driver ownership - set this to true if the platform in
* question needs to 'own'
* the respective handle and therefore skip regular RetroArch
* driver teardown/reiniting procedure.
*
* If to true, the 'free' function will get skipped. It is
* then up to the driver implementation to properly handle
* 'reiniting' inside the 'init' function and make sure it
* returns the existing handle instead of allocating and
* returning a pointer to a new handle.
*
* Typically, if a driver intends to make use of this, it should
* set this to true at the end of its 'init' function.
**/
void driver_uninit(int flags);

RETRO_END_DECLS

#endif
33 changes: 33 additions & 0 deletions gfx/video_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -3940,3 +3940,36 @@ void video_driver_frame(const void *data, unsigned width,
#endif
video_st->crt_switching_active = false;
}

static void video_driver_reinit_context(settings_t *settings, int flags)
{
/* RARCH_DRIVER_CTL_UNINIT clears the callback struct so we
* need to make sure to keep a copy */
struct retro_hw_render_callback hwr_copy;
video_driver_state_t *video_st = &video_driver_st;
struct retro_hw_render_callback *hwr =
VIDEO_DRIVER_GET_HW_CONTEXT_INTERNAL(video_st);
const struct retro_hw_render_context_negotiation_interface *iface =
video_st->hw_render_context_negotiation;
memcpy(&hwr_copy, hwr, sizeof(hwr_copy));

driver_uninit(flags);

memcpy(hwr, &hwr_copy, sizeof(*hwr));
video_st->hw_render_context_negotiation = iface;

drivers_init(settings, flags, verbosity_is_enabled());
}

void video_driver_reinit(int flags)
{
settings_t *settings = config_get_ptr();
video_driver_state_t *video_st = &video_driver_st;
struct retro_hw_render_callback *hwr =
VIDEO_DRIVER_GET_HW_CONTEXT_INTERNAL(video_st);

video_st->cache_context = (hwr->cache_context != false);
video_st->cache_context_ack = false;
video_driver_reinit_context(settings, flags);
video_st->cache_context = false;
}
2 changes: 1 addition & 1 deletion input/input_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -5555,7 +5555,7 @@ void input_keyboard_event(bool down, unsigned code,
retro_keyboard_event_t
*key_event = &runloop_st->key_event;
input_driver_state_t
*input_st = input_state_get_ptr();
*input_st = &input_driver_st;
access_state_t *access_st = access_state_get_ptr();
#ifdef HAVE_ACCESSIBILITY
settings_t *settings = config_get_ptr();
Expand Down
Loading

0 comments on commit 88c771f

Please sign in to comment.