mirror of
https://github.com/libretro/RetroArch
synced 2025-01-31 06:32:48 +00:00
Move more code over to gfx/video_driver.c
This commit is contained in:
parent
3dee62ce62
commit
774dccca7c
@ -14,6 +14,7 @@
|
|||||||
* If not, see <http://www.gnu.org/licenses/>.
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
#include <string/stdstring.h>
|
#include <string/stdstring.h>
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
@ -357,6 +358,40 @@ void video_context_driver_destroy(gfx_ctx_driver_t *ctx_driver)
|
|||||||
ctx_driver->make_current = NULL;
|
ctx_driver->make_current = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gfx_ctx_driver_t *video_context_driver_init(
|
||||||
|
bool core_set_shared_context,
|
||||||
|
settings_t *settings,
|
||||||
|
void *data,
|
||||||
|
const gfx_ctx_driver_t *ctx,
|
||||||
|
const char *ident,
|
||||||
|
enum gfx_ctx_api api, unsigned major,
|
||||||
|
unsigned minor, bool hw_render_ctx,
|
||||||
|
void **ctx_data)
|
||||||
|
{
|
||||||
|
if (!ctx->bind_api(data, api, major, minor))
|
||||||
|
{
|
||||||
|
RARCH_WARN("Failed to bind API (#%u, version %u.%u)"
|
||||||
|
" on context driver \"%s\".\n",
|
||||||
|
(unsigned)api, major, minor, ctx->ident);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(*ctx_data = ctx->init(data)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (ctx->bind_hw_render)
|
||||||
|
{
|
||||||
|
bool video_shared_context =
|
||||||
|
settings->bools.video_shared_context || core_set_shared_context;
|
||||||
|
|
||||||
|
ctx->bind_hw_render(*ctx_data,
|
||||||
|
video_shared_context && hw_render_ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* config_get_video_driver_options:
|
* config_get_video_driver_options:
|
||||||
*
|
*
|
||||||
@ -443,3 +478,41 @@ error:
|
|||||||
#endif
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct video_viewport *video_viewport_get_custom(void)
|
||||||
|
{
|
||||||
|
return &config_get_ptr()->video_viewport_custom;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool video_driver_monitor_adjust_system_rates(
|
||||||
|
float timing_skew_hz,
|
||||||
|
float video_refresh_rate,
|
||||||
|
bool vrr_runloop_enable,
|
||||||
|
float audio_max_timing_skew,
|
||||||
|
double input_fps)
|
||||||
|
{
|
||||||
|
if (!vrr_runloop_enable)
|
||||||
|
{
|
||||||
|
float timing_skew = fabs(
|
||||||
|
1.0f - input_fps / timing_skew_hz);
|
||||||
|
/* We don't want to adjust pitch too much. If we have extreme cases,
|
||||||
|
* just don't readjust at all. */
|
||||||
|
if (timing_skew <= audio_max_timing_skew)
|
||||||
|
return true;
|
||||||
|
RARCH_LOG("[Video]: Timings deviate too much. Will not adjust."
|
||||||
|
" (Display = %.2f Hz, Game = %.2f Hz)\n",
|
||||||
|
video_refresh_rate,
|
||||||
|
(float)input_fps);
|
||||||
|
}
|
||||||
|
return input_fps <= timing_skew_hz;
|
||||||
|
}
|
||||||
|
|
||||||
|
void video_driver_reset_custom_viewport(settings_t *settings)
|
||||||
|
{
|
||||||
|
struct video_viewport *custom_vp = &settings->video_viewport_custom;
|
||||||
|
|
||||||
|
custom_vp->width = 0;
|
||||||
|
custom_vp->height = 0;
|
||||||
|
custom_vp->x = 0;
|
||||||
|
custom_vp->y = 0;
|
||||||
|
}
|
||||||
|
@ -19,8 +19,10 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
|
||||||
#include <libretro.h>
|
#include <libretro.h>
|
||||||
#include <retro_common_api.h>
|
#include <retro_common_api.h>
|
||||||
|
#include <boolean.h>
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
@ -29,6 +31,7 @@
|
|||||||
#include <gfx/scaler/pixconv.h>
|
#include <gfx/scaler/pixconv.h>
|
||||||
#include <gfx/scaler/scaler.h>
|
#include <gfx/scaler/scaler.h>
|
||||||
|
|
||||||
|
#include "../configuration.h"
|
||||||
#include "../input/input_driver.h"
|
#include "../input/input_driver.h"
|
||||||
#include "../input/input_types.h"
|
#include "../input/input_types.h"
|
||||||
|
|
||||||
@ -837,9 +840,7 @@ bool video_driver_supports_read_frame_raw(void);
|
|||||||
|
|
||||||
void video_driver_set_viewport_core(void);
|
void video_driver_set_viewport_core(void);
|
||||||
|
|
||||||
void video_driver_set_viewport_full(void);
|
void video_driver_reset_custom_viewport(settings_t *settings);
|
||||||
|
|
||||||
void video_driver_reset_custom_viewport(void *settings_data);
|
|
||||||
|
|
||||||
void video_driver_set_rgba(void);
|
void video_driver_set_rgba(void);
|
||||||
|
|
||||||
@ -1019,6 +1020,13 @@ void video_monitor_compute_fps_statistics(uint64_t
|
|||||||
bool video_monitor_fps_statistics(double *refresh_rate,
|
bool video_monitor_fps_statistics(double *refresh_rate,
|
||||||
double *deviation, unsigned *sample_points);
|
double *deviation, unsigned *sample_points);
|
||||||
|
|
||||||
|
bool video_driver_monitor_adjust_system_rates(
|
||||||
|
float timing_skew_hz,
|
||||||
|
float video_refresh_rate,
|
||||||
|
bool vrr_runloop_enable,
|
||||||
|
float audio_max_timing_skew,
|
||||||
|
double input_fps);
|
||||||
|
|
||||||
void crt_switch_driver_refresh(void);
|
void crt_switch_driver_refresh(void);
|
||||||
|
|
||||||
char* crt_switch_core_name(void);
|
char* crt_switch_core_name(void);
|
||||||
@ -1063,8 +1071,6 @@ void video_driver_display_userdata_set(uintptr_t idx);
|
|||||||
|
|
||||||
void video_driver_window_set(uintptr_t idx);
|
void video_driver_window_set(uintptr_t idx);
|
||||||
|
|
||||||
uintptr_t video_driver_window_get(void);
|
|
||||||
|
|
||||||
bool video_driver_texture_load(void *data,
|
bool video_driver_texture_load(void *data,
|
||||||
enum texture_filter_type filter_type,
|
enum texture_filter_type filter_type,
|
||||||
uintptr_t *id);
|
uintptr_t *id);
|
||||||
@ -1081,6 +1087,33 @@ bool *video_driver_get_threaded(void);
|
|||||||
|
|
||||||
void video_driver_set_threaded(bool val);
|
void video_driver_set_threaded(bool val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* video_context_driver_init:
|
||||||
|
* @core_set_shared_context : Boolean value that tells us whether shared context
|
||||||
|
* is set.
|
||||||
|
* @ctx : Graphics context driver to initialize.
|
||||||
|
* @ident : Identifier of graphics context driver to find.
|
||||||
|
* @api : API of higher-level graphics API.
|
||||||
|
* @major : Major version number of higher-level graphics API.
|
||||||
|
* @minor : Minor version number of higher-level graphics API.
|
||||||
|
* @hw_render_ctx : Request a graphics context driver capable of
|
||||||
|
* hardware rendering?
|
||||||
|
*
|
||||||
|
* Initialize graphics context driver.
|
||||||
|
*
|
||||||
|
* Returns: graphics context driver if successfully initialized,
|
||||||
|
* otherwise NULL.
|
||||||
|
**/
|
||||||
|
const gfx_ctx_driver_t *video_context_driver_init(
|
||||||
|
bool core_set_shared_context,
|
||||||
|
settings_t *settings,
|
||||||
|
void *data,
|
||||||
|
const gfx_ctx_driver_t *ctx,
|
||||||
|
const char *ident,
|
||||||
|
enum gfx_ctx_api api, unsigned major,
|
||||||
|
unsigned minor, bool hw_render_ctx,
|
||||||
|
void **ctx_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* video_context_driver_init_first:
|
* video_context_driver_init_first:
|
||||||
* @data : Input data.
|
* @data : Input data.
|
||||||
|
118
retroarch.c
118
retroarch.c
@ -1749,15 +1749,14 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data)
|
|||||||
break;
|
break;
|
||||||
case RARCH_MENU_CTL_OSK_PTR_AT_POS:
|
case RARCH_MENU_CTL_OSK_PTR_AT_POS:
|
||||||
{
|
{
|
||||||
unsigned width = 0;
|
unsigned width = p_rarch->video_driver_width;
|
||||||
unsigned height = 0;
|
unsigned height = p_rarch->video_driver_height;
|
||||||
menu_ctx_pointer_t *point = (menu_ctx_pointer_t*)data;
|
menu_ctx_pointer_t *point = (menu_ctx_pointer_t*)data;
|
||||||
if (!menu_st->driver_ctx || !menu_st->driver_ctx->osk_ptr_at_pos)
|
if (!menu_st->driver_ctx || !menu_st->driver_ctx->osk_ptr_at_pos)
|
||||||
{
|
{
|
||||||
point->retcode = 0;
|
point->retcode = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
video_driver_get_size(&width, &height);
|
|
||||||
point->retcode = menu_st->driver_ctx->osk_ptr_at_pos(
|
point->retcode = menu_st->driver_ctx->osk_ptr_at_pos(
|
||||||
menu_st->userdata,
|
menu_st->userdata,
|
||||||
point->x, point->y, width, height);
|
point->x, point->y, width, height);
|
||||||
@ -21427,29 +21426,6 @@ void video_driver_cached_frame(void)
|
|||||||
p_rarch->recording_data = recording;
|
p_rarch->recording_data = recording;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool video_driver_monitor_adjust_system_rates(
|
|
||||||
float timing_skew_hz,
|
|
||||||
float video_refresh_rate,
|
|
||||||
bool vrr_runloop_enable,
|
|
||||||
float audio_max_timing_skew,
|
|
||||||
double input_fps)
|
|
||||||
{
|
|
||||||
if (!vrr_runloop_enable)
|
|
||||||
{
|
|
||||||
float timing_skew = fabs(
|
|
||||||
1.0f - input_fps / timing_skew_hz);
|
|
||||||
/* We don't want to adjust pitch too much. If we have extreme cases,
|
|
||||||
* just don't readjust at all. */
|
|
||||||
if (timing_skew <= audio_max_timing_skew)
|
|
||||||
return true;
|
|
||||||
RARCH_LOG("[Video]: Timings deviate too much. Will not adjust."
|
|
||||||
" (Display = %.2f Hz, Game = %.2f Hz)\n",
|
|
||||||
video_refresh_rate,
|
|
||||||
(float)input_fps);
|
|
||||||
}
|
|
||||||
return input_fps <= timing_skew_hz;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void video_driver_lock_new(struct rarch_state *p_rarch)
|
static void video_driver_lock_new(struct rarch_state *p_rarch)
|
||||||
{
|
{
|
||||||
VIDEO_DRIVER_LOCK_FREE();
|
VIDEO_DRIVER_LOCK_FREE();
|
||||||
@ -21533,30 +21509,6 @@ void video_driver_set_viewport_core(void)
|
|||||||
(float)geom->base_width / geom->base_height;
|
(float)geom->base_width / geom->base_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void video_driver_set_viewport_full(void)
|
|
||||||
{
|
|
||||||
unsigned width = 0;
|
|
||||||
unsigned height = 0;
|
|
||||||
|
|
||||||
video_driver_get_size(&width, &height);
|
|
||||||
|
|
||||||
if (width == 0 || height == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
aspectratio_lut[ASPECT_RATIO_FULL].value = (float)width / (float)height;
|
|
||||||
}
|
|
||||||
|
|
||||||
void video_driver_reset_custom_viewport(void *settings_data)
|
|
||||||
{
|
|
||||||
settings_t *settings = (settings_t*)settings_data;
|
|
||||||
struct video_viewport *custom_vp = &settings->video_viewport_custom;
|
|
||||||
|
|
||||||
custom_vp->width = 0;
|
|
||||||
custom_vp->height = 0;
|
|
||||||
custom_vp->x = 0;
|
|
||||||
custom_vp->y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void video_driver_set_rgba(void)
|
void video_driver_set_rgba(void)
|
||||||
{
|
{
|
||||||
struct rarch_state *p_rarch = &rarch_st;
|
struct rarch_state *p_rarch = &rarch_st;
|
||||||
@ -21666,7 +21618,13 @@ void video_driver_set_aspect_ratio(void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ASPECT_RATIO_FULL:
|
case ASPECT_RATIO_FULL:
|
||||||
video_driver_set_viewport_full();
|
{
|
||||||
|
unsigned width = p_rarch->video_driver_width;
|
||||||
|
unsigned height = p_rarch->video_driver_height;
|
||||||
|
|
||||||
|
if (width != 0 && height != 0)
|
||||||
|
aspectratio_lut[ASPECT_RATIO_FULL].value = (float)width / (float)height;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -22101,13 +22059,6 @@ void video_viewport_get_scaled_integer(struct video_viewport *vp,
|
|||||||
vp->y = padding_y / 2;
|
vp->y = padding_y / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct video_viewport *video_viewport_get_custom(void)
|
|
||||||
{
|
|
||||||
struct rarch_state *p_rarch = &rarch_st;
|
|
||||||
settings_t *settings = p_rarch->configuration_settings;
|
|
||||||
return &settings->video_viewport_custom;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* video_driver_frame:
|
* video_driver_frame:
|
||||||
* @data : pointer to data of the video frame.
|
* @data : pointer to data of the video frame.
|
||||||
@ -22784,57 +22735,6 @@ void video_driver_get_window_title(char *buf, unsigned len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* video_context_driver_init:
|
|
||||||
* @core_set_shared_context : Boolean value that tells us whether shared context
|
|
||||||
* is set.
|
|
||||||
* @ctx : Graphics context driver to initialize.
|
|
||||||
* @ident : Identifier of graphics context driver to find.
|
|
||||||
* @api : API of higher-level graphics API.
|
|
||||||
* @major : Major version number of higher-level graphics API.
|
|
||||||
* @minor : Minor version number of higher-level graphics API.
|
|
||||||
* @hw_render_ctx : Request a graphics context driver capable of
|
|
||||||
* hardware rendering?
|
|
||||||
*
|
|
||||||
* Initialize graphics context driver.
|
|
||||||
*
|
|
||||||
* Returns: graphics context driver if successfully initialized,
|
|
||||||
* otherwise NULL.
|
|
||||||
**/
|
|
||||||
static const gfx_ctx_driver_t *video_context_driver_init(
|
|
||||||
bool core_set_shared_context,
|
|
||||||
settings_t *settings,
|
|
||||||
void *data,
|
|
||||||
const gfx_ctx_driver_t *ctx,
|
|
||||||
const char *ident,
|
|
||||||
enum gfx_ctx_api api, unsigned major,
|
|
||||||
unsigned minor, bool hw_render_ctx,
|
|
||||||
void **ctx_data)
|
|
||||||
{
|
|
||||||
if (!ctx->bind_api(data, api, major, minor))
|
|
||||||
{
|
|
||||||
RARCH_WARN("Failed to bind API (#%u, version %u.%u)"
|
|
||||||
" on context driver \"%s\".\n",
|
|
||||||
(unsigned)api, major, minor, ctx->ident);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(*ctx_data = ctx->init(data)))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (ctx->bind_hw_render)
|
|
||||||
{
|
|
||||||
bool video_shared_context =
|
|
||||||
settings->bools.video_shared_context || core_set_shared_context;
|
|
||||||
|
|
||||||
ctx->bind_hw_render(*ctx_data,
|
|
||||||
video_shared_context && hw_render_ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_VULKAN
|
#ifdef HAVE_VULKAN
|
||||||
static const gfx_ctx_driver_t *vk_context_driver_init_first(
|
static const gfx_ctx_driver_t *vk_context_driver_init_first(
|
||||||
struct rarch_state *p_rarch,
|
struct rarch_state *p_rarch,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user