From 75d618140bd5bb724aee7629ebc562c437e1e4ab Mon Sep 17 00:00:00 2001 From: Themaister Date: Wed, 11 May 2011 17:52:16 +0200 Subject: [PATCH] Some more work on external API. --- Makefile | 3 ++- Makefile.win32 | 10 +++++++--- Makefile.win64 | 11 ++++++++--- config.def.h | 13 +++++++++++-- config.features.h | 6 +++--- driver.c | 4 ++-- general.h | 2 ++ gfx/ext/ssnes_video.h | 21 ++++++++++++--------- qb/config.libs.sh | 4 ++-- qb/config.params.sh | 2 +- settings.c | 3 ++- ssnes.c | 4 ++-- 12 files changed, 54 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 95f6cae0b5..7d82355959 100644 --- a/Makefile +++ b/Makefile @@ -97,7 +97,8 @@ ifeq ($(HAVE_XML), 1) DEFINES += $(XML_CFLAGS) endif -ifeq ($(HAVE_FILTER), 1) +ifeq ($(HAVE_DYLIB), 1) + OBJ += gfx/ext.o LIBS += -ldl endif diff --git a/Makefile.win32 b/Makefile.win32 index 1cfdcaea35..efdd7de4e0 100644 --- a/Makefile.win32 +++ b/Makefile.win32 @@ -12,7 +12,7 @@ HAVE_XML = 1 HAVE_FREETYPE = 1 HAVE_XAUDIO = 1 HAVE_RSOUND = 1 -HAVE_FILTER = 1 +HAVE_DYLIB = 1 HAVE_NETPLAY = 1 HAVE_FBO = 1 libsnes ?= -lsnes @@ -55,8 +55,8 @@ ifeq ($(HAVE_XML), 1) LIBS += -lxml2 endif -ifeq ($(HAVE_FILTER), 1) - DEFINES += -DHAVE_FILTER +ifeq ($(HAVE_DYLIB), 1) + DEFINES += -DHAVE_DYLIB endif ifeq ($(HAVE_NETPLAY), 1) @@ -81,6 +81,10 @@ ifeq ($(HAVE_FBO), 1) DEFINES += -DHAVE_FBO endif +ifeq ($(HAVE_DYLIB), 1) + OBJ += gfx/ext.c +endif + ifneq ($(V),1) Q := @ endif diff --git a/Makefile.win64 b/Makefile.win64 index e8778a815a..57b801c9c2 100644 --- a/Makefile.win64 +++ b/Makefile.win64 @@ -12,7 +12,7 @@ HAVE_XML = 1 HAVE_FREETYPE = 1 HAVE_XAUDIO = 1 HAVE_RSOUND = 0 -HAVE_FILTER = 1 +HAVE_DYLIB = 1 HAVE_NETPLAY = 1 HAVE_FBO = 1 libsnes ?= -lsnes @@ -55,8 +55,8 @@ ifeq ($(HAVE_XML), 1) LIBS += -lxml2 -lz -lws2_32 endif -ifeq ($(HAVE_FILTER), 1) - DEFINES += -DHAVE_FILTER +ifeq ($(HAVE_DYLIB), 1) + DEFINES += -DHAVE_DYLIB endif ifeq ($(HAVE_NETPLAY), 1) @@ -81,6 +81,11 @@ ifeq ($(HAVE_FBO), 1) DEFINES += -DHAVE_FBO endif +ifeq ($(HAVE_DYLIB), 1) + OBJ += gfx/ext.c +endif + + ifneq ($(V),1) Q := @ endif diff --git a/config.def.h b/config.def.h index a912edc37b..65db3a1c98 100644 --- a/config.def.h +++ b/config.def.h @@ -33,7 +33,7 @@ #ifdef HAVE_SDL #include "SDL.h" #else -#error HAVE_SDL is not defined! +#error "HAVE_SDL is not defined!" #endif #ifdef HAVE_SRC @@ -45,6 +45,7 @@ #define VIDEO_GL 0 #define VIDEO_XVIDEO 11 #define VIDEO_SDL 13 +#define VIDEO_EXT 14 //////////////////////// #define AUDIO_RSOUND 1 #define AUDIO_OSS 2 @@ -64,6 +65,12 @@ #define VIDEO_DEFAULT_DRIVER VIDEO_GL #elif defined(HAVE_XVIDEO) #define VIDEO_DEFAULT_DRIVER VIDEO_XVIDEO +#elif defined(HAVE_SDL) +#define VIDEO_DEFAULT_DRIVER VIDEO_SDL +#elif defined(HAVE_DYLIB) +#define VIDEO_DEFAULT_DRIVER VIDEO_EXT +#else +#error "Need at least one video driver!" #endif #if defined(HAVE_ALSA) @@ -85,13 +92,15 @@ #elif defined(HAVE_ROAR) #define AUDIO_DEFAULT_DRIVER AUDIO_ROAR #else -#error Need at least one audio driver! +#error "Need at least one audio driver!" #endif #if defined(HAVE_SDL) #define INPUT_DEFAULT_DRIVER INPUT_SDL #elif defined(HAVE_XVIDEO) #define INPUT_DEFAULT_DRIVER INPUT_X +#else +#error "Need at least one input driver!" #endif diff --git a/config.features.h b/config.features.h index 2726bab232..59264f639d 100644 --- a/config.features.h +++ b/config.features.h @@ -62,10 +62,10 @@ static const bool _xaudio_supp = true; static const bool _xaudio_supp = false; #endif -#ifdef HAVE_FILTER -static const bool _filter_supp = true; +#ifdef HAVE_DYLIB +static const bool _dylib_supp = true; #else -static const bool _filter_supp = false; +static const bool _dylib_supp = false; #endif #ifdef HAVE_CG diff --git a/driver.c b/driver.c index cc02b01284..3bfe332605 100644 --- a/driver.c +++ b/driver.c @@ -220,7 +220,7 @@ void uninit_audio(void) free(g_extern.audio_data.conv_outsamples); g_extern.audio_data.conv_outsamples = NULL; } -#ifdef HAVE_FILTER +#ifdef HAVE_DYLIB static void init_filter(void) { if (g_extern.filter.active) @@ -319,7 +319,7 @@ static void deinit_shader_dir(void) void init_video_input(void) { -#ifdef HAVE_FILTER +#ifdef HAVE_DYLIB init_filter(); #endif diff --git a/general.h b/general.h index 9259945202..9c6ec9fc79 100644 --- a/general.h +++ b/general.h @@ -88,6 +88,8 @@ struct settings float msg_pos_y; bool force_16bit; + + char external_driver[256]; } video; struct diff --git a/gfx/ext/ssnes_video.h b/gfx/ext/ssnes_video.h index 61765e67f7..98ac5399bd 100644 --- a/gfx/ext/ssnes_video.h +++ b/gfx/ext/ssnes_video.h @@ -63,10 +63,13 @@ typedef struct ssnes_video_info // If non-NULL, requests the use of an XML shader. Can be disregarded. const char *xml_shader; + // If non-NULL, requests the use of a Cg shader. Can be disregarded. If both are non-NULL, Cg or XML could be used at the discretion of the plugin. + const char *cg_shader; // Requestes that a certain TTF font is used for rendering messages to the screen. // Can be disregarded. const char *ttf_font; + unsigned ttf_font_size; } ssnes_video_info_t; #define SSNES_AXIS_NEG(x) (((unsigned)(x) << 16) | 0xFFFFU) @@ -107,14 +110,17 @@ struct ssnes_keybind typedef struct ssnes_input_driver { - // Inits input driver. - void* (*init)(const unsigned joypad_index[5]); + // Inits input driver. Joypad index denotes which joypads are desired for the various players. + // Should an entry be negative, do not open joypad for that player. + void* (*init)(const int joypad_index[5]); // Polls input. Called once every frame. void (*poll)(void* data); // Queries input state for a certain key on a certain player. Players are 1 - 5. - int (*input_state)(void* data, const struct snes_keybind *bind, unsigned player); + // For digital inputs, pressed key is 1, not pressed key is 0. + // Analog values have same range as a signed 16-bit integer. + int (*input_state)(void* data, const struct ssnes_keybind *bind, unsigned player); // Frees the input struct. void (*free)(void* data); @@ -131,7 +137,7 @@ typedef struct ssnes_video_driver // Should the video driver request that a certain input driver is used, // it is possible to set the driver to *input, and driver handle to *input_data. // If no certain driver is desired, set both of these to NULL. - void* (*init)(const video_info_t *video, const input_driver_t **input, void **input_data); + void* (*init)(const ssnes_video_info_t *video, const ssnes_input_driver_t **input, void **input_data); // Updates frame on the screen. frame can be either XRGB1555 or ARGB32 format depending on rgb32 setting in ssnes_video_info_t. Pitch is the distance in bytes between two scanlines in memory. When msg is non-NULL, it's a message that should be displayed to the user. int (*frame)(void* data, const void* frame, unsigned width, unsigned height, unsigned pitch, const char *msg); @@ -145,17 +151,14 @@ typedef struct ssnes_video_driver // Does the window have focus? int (*focus)(void *data); - // Sets an XML shader. Implementing this function is optional, and can be set to NULL. - int (*xml_shader)(void *data, const char *path); - // Frees the video driver. void (*free)(void* data); // A human-readable identification of the video driver. const char *ident; -} video_driver_t; +} ssnes_video_driver_t; -SSNES_API_DECL const ssnes_video_info_t* ssnes_video_init(void); +SSNES_API_DECL const ssnes_video_driver_t* ssnes_video_init(void); #ifdef __cplusplus } diff --git a/qb/config.libs.sh b/qb/config.libs.sh index e5d6622435..0ddc03939e 100644 --- a/qb/config.libs.sh +++ b/qb/config.libs.sh @@ -15,7 +15,7 @@ if [ $HAVE_DYNAMIC != yes ]; then add_define_make libsnes $LIBSNES fi -check_lib FILTER -ldl dlopen +check_lib DYLIB -ldl dlopen check_lib NETPLAY -lc socket check_lib ALSA -lasound snd_pcm_open @@ -64,7 +64,7 @@ check_lib XVIDEO -lXv XvShmCreateImage check_lib STRL -lc strlcpy # Creates config.mk and config.h. -VARS="ALSA OSS AL RSOUND ROAR JACK PULSE SDL FILTER CG XML DYNAMIC FFMPEG AVCODEC AVFORMAT AVCORE AVUTIL SWSCALE SRC CONFIGFILE FREETYPE XVIDEO NETPLAY FBO STRL" +VARS="ALSA OSS AL RSOUND ROAR JACK PULSE SDL DYLIB CG XML DYNAMIC FFMPEG AVCODEC AVFORMAT AVCORE AVUTIL SWSCALE SRC CONFIGFILE FREETYPE XVIDEO NETPLAY FBO STRL" create_config_make config.mk $VARS create_config_header config.h $VARS diff --git a/qb/config.params.sh b/qb/config.params.sh index d8b77623c5..d31d11f4ce 100644 --- a/qb/config.params.sh +++ b/qb/config.params.sh @@ -10,7 +10,7 @@ PACKAGE_VERSION=0.4.1 add_command_line_enable DYNAMIC "Enable dynamic loading of libsnes library." no add_command_line_string LIBSNES "libsnes library used" "-lsnes" add_command_line_enable FFMPEG "Enable FFmpeg recording support" no -add_command_line_enable FILTER "Enable CPU filter support" auto +add_command_line_enable DYLIB "Enable dynamic loading support" auto add_command_line_enable NETPLAY "Enable netplay support" auto add_command_line_enable SRC "Enable libsamplerate support" no add_command_line_enable CONFIGFILE "Disable support for config file" yes diff --git a/settings.c b/settings.c index 1f82900efa..7239e5330e 100644 --- a/settings.c +++ b/settings.c @@ -309,8 +309,9 @@ static void parse_config_file(void) CONFIG_GET_DOUBLE(video.msg_pos_y, "video_message_pos_y"); #endif -#ifdef HAVE_FILTER +#ifdef HAVE_DYLIB CONFIG_GET_STRING(video.filter_path, "video_filter"); + CONFIG_GET_STRING(video.external_driver, "video_external_driver"); #endif #if defined(HAVE_CG) || defined(HAVE_XML) diff --git a/ssnes.c b/ssnes.c index 87d897ea25..89b1fe185f 100644 --- a/ssnes.c +++ b/ssnes.c @@ -114,7 +114,7 @@ static void video_frame(const uint16_t *data, unsigned width, unsigned height) const char *msg = msg_queue_pull(g_extern.msg_queue); -#ifdef HAVE_FILTER +#ifdef HAVE_DYLIB if (g_extern.filter.active) { unsigned owidth = width; @@ -282,7 +282,7 @@ static void print_features(void) _PSUPP(pulse, "PulseAudio", "audio driver"); _PSUPP(xaudio, "XAudio2", "audio driver"); _PSUPP(al, "OpenAL", "audio driver"); - _PSUPP(filter, "Filter", "CPU based video filters"); + _PSUPP(dylib, "External", "External filter and driver support"); _PSUPP(cg, "Cg", "Cg pixel shaders"); _PSUPP(xml, "XML", "bSNES XML pixel shaders"); _PSUPP(fbo, "FBO", "OpenGL render-to-texture (multi-pass shaders)");