mirror of
https://github.com/libretro/RetroArch
synced 2025-03-03 04:14:00 +00:00
Move video_driver_thread pointer grabbing to retroarch.c
This commit is contained in:
parent
21d3878d72
commit
a7c54f1848
@ -21,7 +21,6 @@
|
||||
|
||||
#include <compat/strl.h>
|
||||
#include <features/features_cpu.h>
|
||||
#include <rthreads/rthreads.h>
|
||||
#include <string/stdstring.h>
|
||||
|
||||
#include "video_thread_wrapper.h"
|
||||
@ -30,202 +29,6 @@
|
||||
#include "../retroarch.h"
|
||||
#include "../verbosity.h"
|
||||
|
||||
enum thread_cmd
|
||||
{
|
||||
CMD_VIDEO_NONE = 0,
|
||||
CMD_INIT,
|
||||
CMD_SET_SHADER,
|
||||
CMD_FREE,
|
||||
CMD_ALIVE, /* Blocking alive check. Used when paused. */
|
||||
CMD_SET_VIEWPORT,
|
||||
CMD_SET_ROTATION,
|
||||
CMD_READ_VIEWPORT,
|
||||
|
||||
CMD_OVERLAY_ENABLE,
|
||||
CMD_OVERLAY_LOAD,
|
||||
CMD_OVERLAY_TEX_GEOM,
|
||||
CMD_OVERLAY_VERTEX_GEOM,
|
||||
CMD_OVERLAY_FULL_SCREEN,
|
||||
|
||||
CMD_POKE_SET_VIDEO_MODE,
|
||||
CMD_POKE_SET_FILTERING,
|
||||
|
||||
CMD_POKE_SET_FBO_STATE,
|
||||
CMD_POKE_GET_FBO_STATE,
|
||||
|
||||
CMD_POKE_SET_ASPECT_RATIO,
|
||||
CMD_FONT_INIT,
|
||||
CMD_CUSTOM_COMMAND,
|
||||
|
||||
CMD_POKE_SHOW_MOUSE,
|
||||
CMD_POKE_GRAB_MOUSE_TOGGLE,
|
||||
|
||||
CMD_DUMMY = INT_MAX
|
||||
};
|
||||
|
||||
struct thread_packet
|
||||
{
|
||||
union
|
||||
{
|
||||
const char *str;
|
||||
void *v;
|
||||
int i;
|
||||
float f;
|
||||
bool b;
|
||||
|
||||
struct
|
||||
{
|
||||
enum rarch_shader_type type;
|
||||
const char *path;
|
||||
} set_shader;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
bool force_full;
|
||||
bool allow_rotate;
|
||||
} set_viewport;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned index;
|
||||
float x, y, w, h;
|
||||
} rect;
|
||||
|
||||
struct
|
||||
{
|
||||
const struct texture_image *data;
|
||||
unsigned num;
|
||||
} image;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
} output;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
bool fullscreen;
|
||||
} new_mode;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned index;
|
||||
bool smooth;
|
||||
bool ctx_scaling;
|
||||
} filtering;
|
||||
|
||||
struct
|
||||
{
|
||||
char msg[128];
|
||||
struct font_params params;
|
||||
} osd_message;
|
||||
|
||||
struct
|
||||
{
|
||||
custom_command_method_t method;
|
||||
void* data;
|
||||
int return_value;
|
||||
} custom_command;
|
||||
|
||||
struct
|
||||
{
|
||||
custom_font_command_method_t method;
|
||||
const void **font_driver;
|
||||
void **font_handle;
|
||||
void *video_data;
|
||||
const char *font_path;
|
||||
float font_size;
|
||||
bool return_value;
|
||||
bool is_threaded;
|
||||
enum font_driver_render_api api;
|
||||
} font_init;
|
||||
} data;
|
||||
enum thread_cmd type;
|
||||
};
|
||||
|
||||
struct thread_video
|
||||
{
|
||||
retro_time_t last_time;
|
||||
|
||||
slock_t *lock;
|
||||
scond_t *cond_cmd;
|
||||
scond_t *cond_thread;
|
||||
sthread_t *thread;
|
||||
|
||||
video_info_t info;
|
||||
const video_driver_t *driver;
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
const video_overlay_interface_t *overlay;
|
||||
#endif
|
||||
const video_poke_interface_t *poke;
|
||||
|
||||
void *driver_data;
|
||||
input_driver_t **input;
|
||||
void **input_data;
|
||||
|
||||
float *alpha_mod;
|
||||
slock_t *alpha_lock;
|
||||
void (*send_and_wait)(struct thread_video *, thread_packet_t*);
|
||||
|
||||
struct
|
||||
{
|
||||
void *frame;
|
||||
size_t frame_cap;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
float alpha;
|
||||
bool frame_updated;
|
||||
bool rgb32;
|
||||
bool enable;
|
||||
bool full_screen;
|
||||
} texture;
|
||||
|
||||
unsigned hit_count;
|
||||
unsigned miss_count;
|
||||
unsigned alpha_mods;
|
||||
|
||||
struct video_viewport vp;
|
||||
struct video_viewport read_vp; /* Last viewport reported to caller. */
|
||||
|
||||
thread_packet_t cmd_data;
|
||||
video_driver_t video_thread;
|
||||
|
||||
|
||||
enum thread_cmd send_cmd;
|
||||
enum thread_cmd reply_cmd;
|
||||
|
||||
bool alpha_update;
|
||||
|
||||
struct
|
||||
{
|
||||
uint64_t count;
|
||||
slock_t *lock;
|
||||
uint8_t *buffer;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
unsigned pitch;
|
||||
char msg[255];
|
||||
bool updated;
|
||||
bool within_thread;
|
||||
} frame;
|
||||
|
||||
|
||||
bool apply_state_changes;
|
||||
|
||||
bool alive;
|
||||
bool focus;
|
||||
bool suppress_screensaver;
|
||||
bool has_windowed;
|
||||
bool nonblock;
|
||||
bool is_idle;
|
||||
};
|
||||
|
||||
static void *video_thread_init_never_call(const video_info_t *video,
|
||||
input_driver_t **input, void **input_data)
|
||||
{
|
||||
@ -1443,47 +1246,11 @@ bool video_init_thread(const video_driver_t **out_driver,
|
||||
return video_thread_init(thr, info, input, input_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* video_thread_get_ptr:
|
||||
* @drv : Found driver.
|
||||
*
|
||||
* Gets the underlying video driver associated with the
|
||||
* threaded video wrapper. Sets @drv to the found
|
||||
* video driver.
|
||||
*
|
||||
* Returns: Video driver data of the video driver associated
|
||||
* with the threaded wrapper (if successful). If not successful,
|
||||
* NULL.
|
||||
**/
|
||||
void *video_thread_get_ptr(const video_driver_t **drv)
|
||||
{
|
||||
const thread_video_t *thr = (const thread_video_t*)
|
||||
video_driver_get_ptr(true);
|
||||
|
||||
if (drv)
|
||||
*drv = thr->driver;
|
||||
|
||||
if (!thr)
|
||||
return NULL;
|
||||
return thr->driver_data;
|
||||
}
|
||||
|
||||
const char *video_thread_get_ident(void)
|
||||
{
|
||||
const thread_video_t *thr = (const thread_video_t*)
|
||||
video_driver_get_ptr(true);
|
||||
|
||||
if (!thr || !thr->driver)
|
||||
return NULL;
|
||||
return thr->driver->ident;
|
||||
}
|
||||
|
||||
static void video_thread_send_and_wait(thread_video_t *thr,
|
||||
thread_packet_t *pkt)
|
||||
{
|
||||
if (!thr || !pkt)
|
||||
return;
|
||||
thr->send_and_wait(thr, pkt);
|
||||
if (thr && pkt)
|
||||
thr->send_and_wait(thr, pkt);
|
||||
}
|
||||
|
||||
bool video_thread_font_init(const void **font_driver, void **font_handle,
|
||||
|
@ -21,11 +21,45 @@
|
||||
|
||||
#include <boolean.h>
|
||||
#include <retro_common_api.h>
|
||||
#include <rthreads/rthreads.h>
|
||||
|
||||
#include "font_driver.h"
|
||||
|
||||
RETRO_BEGIN_DECLS
|
||||
|
||||
enum thread_cmd
|
||||
{
|
||||
CMD_VIDEO_NONE = 0,
|
||||
CMD_INIT,
|
||||
CMD_SET_SHADER,
|
||||
CMD_FREE,
|
||||
CMD_ALIVE, /* Blocking alive check. Used when paused. */
|
||||
CMD_SET_VIEWPORT,
|
||||
CMD_SET_ROTATION,
|
||||
CMD_READ_VIEWPORT,
|
||||
|
||||
CMD_OVERLAY_ENABLE,
|
||||
CMD_OVERLAY_LOAD,
|
||||
CMD_OVERLAY_TEX_GEOM,
|
||||
CMD_OVERLAY_VERTEX_GEOM,
|
||||
CMD_OVERLAY_FULL_SCREEN,
|
||||
|
||||
CMD_POKE_SET_VIDEO_MODE,
|
||||
CMD_POKE_SET_FILTERING,
|
||||
|
||||
CMD_POKE_SET_FBO_STATE,
|
||||
CMD_POKE_GET_FBO_STATE,
|
||||
|
||||
CMD_POKE_SET_ASPECT_RATIO,
|
||||
CMD_FONT_INIT,
|
||||
CMD_CUSTOM_COMMAND,
|
||||
|
||||
CMD_POKE_SHOW_MOUSE,
|
||||
CMD_POKE_GRAB_MOUSE_TOGGLE,
|
||||
|
||||
CMD_DUMMY = INT_MAX
|
||||
};
|
||||
|
||||
typedef int (*custom_command_method_t)(void*);
|
||||
|
||||
typedef bool (*custom_font_command_method_t)(const void **font_driver,
|
||||
@ -35,7 +69,168 @@ typedef bool (*custom_font_command_method_t)(const void **font_driver,
|
||||
|
||||
typedef struct thread_packet thread_packet_t;
|
||||
|
||||
typedef struct thread_video thread_video_t;
|
||||
struct thread_packet
|
||||
{
|
||||
union
|
||||
{
|
||||
const char *str;
|
||||
void *v;
|
||||
int i;
|
||||
float f;
|
||||
bool b;
|
||||
|
||||
struct
|
||||
{
|
||||
enum rarch_shader_type type;
|
||||
const char *path;
|
||||
} set_shader;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
bool force_full;
|
||||
bool allow_rotate;
|
||||
} set_viewport;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned index;
|
||||
float x, y, w, h;
|
||||
} rect;
|
||||
|
||||
struct
|
||||
{
|
||||
const struct texture_image *data;
|
||||
unsigned num;
|
||||
} image;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
} output;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
bool fullscreen;
|
||||
} new_mode;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned index;
|
||||
bool smooth;
|
||||
bool ctx_scaling;
|
||||
} filtering;
|
||||
|
||||
struct
|
||||
{
|
||||
char msg[128];
|
||||
struct font_params params;
|
||||
} osd_message;
|
||||
|
||||
struct
|
||||
{
|
||||
custom_command_method_t method;
|
||||
void* data;
|
||||
int return_value;
|
||||
} custom_command;
|
||||
|
||||
struct
|
||||
{
|
||||
custom_font_command_method_t method;
|
||||
const void **font_driver;
|
||||
void **font_handle;
|
||||
void *video_data;
|
||||
const char *font_path;
|
||||
float font_size;
|
||||
bool return_value;
|
||||
bool is_threaded;
|
||||
enum font_driver_render_api api;
|
||||
} font_init;
|
||||
} data;
|
||||
enum thread_cmd type;
|
||||
};
|
||||
|
||||
typedef struct thread_video
|
||||
{
|
||||
retro_time_t last_time;
|
||||
|
||||
slock_t *lock;
|
||||
scond_t *cond_cmd;
|
||||
scond_t *cond_thread;
|
||||
sthread_t *thread;
|
||||
|
||||
video_info_t info;
|
||||
const video_driver_t *driver;
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
const video_overlay_interface_t *overlay;
|
||||
#endif
|
||||
const video_poke_interface_t *poke;
|
||||
|
||||
void *driver_data;
|
||||
input_driver_t **input;
|
||||
void **input_data;
|
||||
|
||||
float *alpha_mod;
|
||||
slock_t *alpha_lock;
|
||||
void (*send_and_wait)(struct thread_video *, thread_packet_t*);
|
||||
|
||||
struct
|
||||
{
|
||||
void *frame;
|
||||
size_t frame_cap;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
float alpha;
|
||||
bool frame_updated;
|
||||
bool rgb32;
|
||||
bool enable;
|
||||
bool full_screen;
|
||||
} texture;
|
||||
|
||||
unsigned hit_count;
|
||||
unsigned miss_count;
|
||||
unsigned alpha_mods;
|
||||
|
||||
struct video_viewport vp;
|
||||
struct video_viewport read_vp; /* Last viewport reported to caller. */
|
||||
|
||||
thread_packet_t cmd_data;
|
||||
video_driver_t video_thread;
|
||||
|
||||
|
||||
enum thread_cmd send_cmd;
|
||||
enum thread_cmd reply_cmd;
|
||||
|
||||
bool alpha_update;
|
||||
|
||||
struct
|
||||
{
|
||||
uint64_t count;
|
||||
slock_t *lock;
|
||||
uint8_t *buffer;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
unsigned pitch;
|
||||
char msg[255];
|
||||
bool updated;
|
||||
bool within_thread;
|
||||
} frame;
|
||||
|
||||
|
||||
bool apply_state_changes;
|
||||
|
||||
bool alive;
|
||||
bool focus;
|
||||
bool suppress_screensaver;
|
||||
bool has_windowed;
|
||||
bool nonblock;
|
||||
bool is_idle;
|
||||
} thread_video_t;
|
||||
|
||||
/**
|
||||
* video_init_thread:
|
||||
@ -56,22 +251,6 @@ bool video_init_thread(
|
||||
input_driver_t **input, void **input_data,
|
||||
const video_driver_t *driver, const video_info_t info);
|
||||
|
||||
/**
|
||||
* video_thread_get_ptr:
|
||||
* @drv : Found driver.
|
||||
*
|
||||
* Gets the underlying video driver associated with the
|
||||
* threaded video wrapper. Sets @drv to the found
|
||||
* video driver.
|
||||
*
|
||||
* Returns: Video driver data of the video driver associated
|
||||
* with the threaded wrapper (if successful). If not successful,
|
||||
* NULL.
|
||||
**/
|
||||
void *video_thread_get_ptr(const video_driver_t **drv);
|
||||
|
||||
const char *video_thread_get_ident(void);
|
||||
|
||||
bool video_thread_font_init(
|
||||
const void **font_driver,
|
||||
void **font_handle,
|
||||
|
30
retroarch.c
30
retroarch.c
@ -1240,7 +1240,7 @@ static const camera_driver_t *camera_drivers[] = {
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
#define VIDEO_DRIVER_GET_PTR_INTERNAL(force) ((VIDEO_DRIVER_IS_THREADED_INTERNAL() && !force) ? video_thread_get_ptr(NULL) : p_rarch->video_driver_data)
|
||||
#define VIDEO_DRIVER_GET_PTR_INTERNAL(force) ((VIDEO_DRIVER_IS_THREADED_INTERNAL() && !force) ? video_thread_get_ptr(p_rarch) : p_rarch->video_driver_data)
|
||||
#else
|
||||
#define VIDEO_DRIVER_GET_PTR_INTERNAL(force) (p_rarch->video_driver_data)
|
||||
#endif
|
||||
@ -12692,6 +12692,26 @@ global_t *global_get_ptr(void)
|
||||
return &p_rarch->g_extern;
|
||||
}
|
||||
|
||||
/**
|
||||
* video_thread_get_ptr:
|
||||
* @drv : Found driver.
|
||||
*
|
||||
* Gets the underlying video driver associated with the
|
||||
* threaded video wrapper. Sets @drv to the found
|
||||
* video driver.
|
||||
*
|
||||
* Returns: Video driver data of the video driver associated
|
||||
* with the threaded wrapper (if successful). If not successful,
|
||||
* NULL.
|
||||
**/
|
||||
static void *video_thread_get_ptr(struct rarch_state *p_rarch)
|
||||
{
|
||||
const thread_video_t *thr = VIDEO_DRIVER_GET_PTR_INTERNAL(true);
|
||||
if (thr)
|
||||
return thr->driver_data;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* video_driver_get_ptr:
|
||||
*
|
||||
@ -31671,10 +31691,14 @@ const char *video_driver_get_ident(void)
|
||||
struct rarch_state *p_rarch = &rarch_st;
|
||||
if (!p_rarch->current_video)
|
||||
return NULL;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
if (VIDEO_DRIVER_IS_THREADED_INTERNAL())
|
||||
return video_thread_get_ident();
|
||||
{
|
||||
const thread_video_t *thr = VIDEO_DRIVER_GET_PTR_INTERNAL(true);
|
||||
if (!thr || !thr->driver)
|
||||
return NULL;
|
||||
return thr->driver->ident;
|
||||
}
|
||||
#endif
|
||||
|
||||
return p_rarch->current_video->ident;
|
||||
|
Loading…
x
Reference in New Issue
Block a user