From 7425e1f879698119b0dd94d4d085d01ae873440c Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 7 Aug 2011 15:00:34 +0200 Subject: [PATCH 1/5] Allow disabling composition in Win Vista/7Allow disabling composition in Win Vista/7. --- config.def.h | 3 +++ general.h | 1 + gfx/gfx_common.c | 35 +++++++++++++++++++++++++++++++++++ gfx/gfx_common.h | 4 ++++ gfx/gl.c | 4 ++++ settings.c | 2 ++ ssnes.cfg | 3 +++ 7 files changed, 52 insertions(+) diff --git a/config.def.h b/config.def.h index 12477d45ae..9f3bd6e56e 100644 --- a/config.def.h +++ b/config.def.h @@ -126,6 +126,9 @@ static const unsigned fullscreen_y = 0; // Force 16-bit colors. static const bool force_16bit = false; +// Forcibly disable composition. Only valid on Windows Vista/7 for now. +static const bool disable_composition = false; + // Video VSYNC (recommended) static const bool vsync = true; diff --git a/general.h b/general.h index 9494a8ed92..4754249e91 100644 --- a/general.h +++ b/general.h @@ -89,6 +89,7 @@ struct settings float msg_pos_y; bool force_16bit; + bool disable_composition; char external_driver[256]; } video; diff --git a/gfx/gfx_common.c b/gfx/gfx_common.c index ee49e8b755..5bf00bb6c7 100644 --- a/gfx/gfx_common.c +++ b/gfx/gfx_common.c @@ -60,4 +60,39 @@ bool gfx_window_title(char *buf, size_t size) return ret; } +#ifdef _WIN32 +#include +#include "dynamic.h" +void gfx_set_composition(void) +{ + if (!g_settings.video.disable_composition) + return; + + static bool inited = false; + if (inited) + return; + inited = true; + + dylib_t lib = dylib_load("dwmapi.dll"); + if (!lib) + { + SSNES_ERR("Did not find dwmapi.dll"); + return; + } + + HRESULT (WINAPI *composition_enable)(UINT) = (HRESULT (WINAPI*)(UINT))dylib_proc(lib, "DwmEnableComposition"); + if (!composition_enable) + { + SSNES_ERR("Did not find DwmEnableComposition ...\n"); + dylib_close(lib); + return; + } + + HRESULT ret = composition_enable(0); + if (FAILED(ret)) + SSNES_ERR("Failed to set composition state ...\n"); + + dylib_close(lib); +} +#endif diff --git a/gfx/gfx_common.h b/gfx/gfx_common.h index 97baee203b..2a24933da6 100644 --- a/gfx/gfx_common.h +++ b/gfx/gfx_common.h @@ -24,4 +24,8 @@ bool gfx_window_title(char *buf, size_t size); void gfx_window_title_reset(void); +#ifdef _WIN32 +void gfx_set_composition(void); +#endif + #endif diff --git a/gfx/gl.c b/gfx/gl.c index ac6f469b0d..3e844e6dca 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1036,6 +1036,10 @@ static void gl_set_nonblock_state(void *data, bool state) static void* gl_init(const video_info_t *video, const input_driver_t **input, void **input_data) { +#ifdef _WIN32 + gfx_set_composition(); +#endif + if (SDL_Init(SDL_INIT_VIDEO) < 0) return NULL; diff --git a/settings.c b/settings.c index e8dad3b9d9..e0e9b1a32f 100644 --- a/settings.c +++ b/settings.c @@ -118,6 +118,7 @@ static void set_defaults(void) g_settings.video.fullscreen_x = fullscreen_x; g_settings.video.fullscreen_y = fullscreen_y; g_settings.video.force_16bit = force_16bit; + g_settings.video.disable_composition = disable_composition; g_settings.video.vsync = vsync; g_settings.video.smooth = video_smooth; g_settings.video.force_aspect = force_aspect; @@ -299,6 +300,7 @@ static void parse_config_file(void) } CONFIG_GET_BOOL(video.force_16bit, "video_force_16bit"); + CONFIG_GET_BOOL(video.disable_composition, "video_disable_composition"); CONFIG_GET_BOOL(video.vsync, "video_vsync"); CONFIG_GET_BOOL(video.smooth, "video_smooth"); CONFIG_GET_BOOL(video.force_aspect, "video_force_aspect"); diff --git a/ssnes.cfg b/ssnes.cfg index c31cb263cd..595f1d5368 100644 --- a/ssnes.cfg +++ b/ssnes.cfg @@ -25,6 +25,9 @@ # Force 16-bit colors. Apparently some video cards in use today have troubles with 32-bit ... # video_force_16bit = false +# Forcibly disable composition. Only works in Windows Vista/7 for now. +# video_disable_composition = false + # Video vsync. # video_vsync = true From fc2a39cd58b8ef9df45d2ae6a25141f9e51e0bff Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 7 Aug 2011 21:15:50 +0200 Subject: [PATCH 2/5] More appropriate renaming. --- gfx/gfx_common.c | 18 +++++++++++++----- gfx/gfx_common.h | 2 +- gfx/gl.c | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/gfx/gfx_common.c b/gfx/gfx_common.c index 5bf00bb6c7..abbe69a60d 100644 --- a/gfx/gfx_common.c +++ b/gfx/gfx_common.c @@ -63,11 +63,8 @@ bool gfx_window_title(char *buf, size_t size) #ifdef _WIN32 #include #include "dynamic.h" -void gfx_set_composition(void) +void gfx_set_dwm(void) { - if (!g_settings.video.disable_composition) - return; - static bool inited = false; if (inited) return; @@ -76,10 +73,20 @@ void gfx_set_composition(void) dylib_t lib = dylib_load("dwmapi.dll"); if (!lib) { - SSNES_ERR("Did not find dwmapi.dll"); + SSNES_LOG("Did not find dwmapi.dll"); return; } + HRESULT (WINAPI *mmcss)(BOOL) = (HRESULT (WINAPI*)(BOOL))dylib_proc(lib, "DwmEnableMMCSS"); + if (mmcss) + { + SSNES_LOG("Setting multimedia scheduling for DWM.\n"); + mmcss(TRUE); + } + + if (!g_settings.video.disable_composition) + return; + HRESULT (WINAPI *composition_enable)(UINT) = (HRESULT (WINAPI*)(UINT))dylib_proc(lib, "DwmEnableComposition"); if (!composition_enable) { @@ -94,5 +101,6 @@ void gfx_set_composition(void) dylib_close(lib); } + #endif diff --git a/gfx/gfx_common.h b/gfx/gfx_common.h index 2a24933da6..e73f757f02 100644 --- a/gfx/gfx_common.h +++ b/gfx/gfx_common.h @@ -25,7 +25,7 @@ bool gfx_window_title(char *buf, size_t size); void gfx_window_title_reset(void); #ifdef _WIN32 -void gfx_set_composition(void); +void gfx_set_dwm(void); #endif #endif diff --git a/gfx/gl.c b/gfx/gl.c index 3e844e6dca..4fd2a91d46 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1037,7 +1037,7 @@ static void gl_set_nonblock_state(void *data, bool state) static void* gl_init(const video_info_t *video, const input_driver_t **input, void **input_data) { #ifdef _WIN32 - gfx_set_composition(); + gfx_set_dwm(); #endif if (SDL_Init(SDL_INIT_VIDEO) < 0) From 1fb53627ac4c5c8b1c8dbf569c96ea3cdb2cb7ff Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 7 Aug 2011 21:18:51 +0200 Subject: [PATCH 3/5] Make sure to free lib. --- gfx/gfx_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gfx/gfx_common.c b/gfx/gfx_common.c index abbe69a60d..5d13cfa597 100644 --- a/gfx/gfx_common.c +++ b/gfx/gfx_common.c @@ -85,7 +85,7 @@ void gfx_set_dwm(void) } if (!g_settings.video.disable_composition) - return; + goto end; HRESULT (WINAPI *composition_enable)(UINT) = (HRESULT (WINAPI*)(UINT))dylib_proc(lib, "DwmEnableComposition"); if (!composition_enable) @@ -99,6 +99,7 @@ void gfx_set_dwm(void) if (FAILED(ret)) SSNES_ERR("Failed to set composition state ...\n"); +end: dylib_close(lib); } From a2ec78320b18fdb16cdbfa3f2c55b52dda308269 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 7 Aug 2011 22:31:59 +0200 Subject: [PATCH 4/5] Improve behavior a bit. --- gfx/gfx_common.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/gfx/gfx_common.c b/gfx/gfx_common.c index 5d13cfa597..89c47243aa 100644 --- a/gfx/gfx_common.c +++ b/gfx/gfx_common.c @@ -63,6 +63,17 @@ bool gfx_window_title(char *buf, size_t size) #ifdef _WIN32 #include #include "dynamic.h" +// We only load this library once, so we let it be unloaded at application shutdown, +// since unloading it early seems to cause issues on some systems. + +static dylib_t dwmlib = NULL; + +static void gfx_dwm_shutdown(void) +{ + if (dwmlib) + dylib_close(dwmlib); +} + void gfx_set_dwm(void) { static bool inited = false; @@ -70,14 +81,15 @@ void gfx_set_dwm(void) return; inited = true; - dylib_t lib = dylib_load("dwmapi.dll"); - if (!lib) + dwmlib = dylib_load("dwmapi.dll"); + if (!dwmlib) { SSNES_LOG("Did not find dwmapi.dll"); return; } + atexit(gfx_dwm_shutdown); - HRESULT (WINAPI *mmcss)(BOOL) = (HRESULT (WINAPI*)(BOOL))dylib_proc(lib, "DwmEnableMMCSS"); + HRESULT (WINAPI *mmcss)(BOOL) = (HRESULT (WINAPI*)(BOOL))dylib_proc(dwmlib, "DwmEnableMMCSS"); if (mmcss) { SSNES_LOG("Setting multimedia scheduling for DWM.\n"); @@ -85,22 +97,18 @@ void gfx_set_dwm(void) } if (!g_settings.video.disable_composition) - goto end; + return; - HRESULT (WINAPI *composition_enable)(UINT) = (HRESULT (WINAPI*)(UINT))dylib_proc(lib, "DwmEnableComposition"); + HRESULT (WINAPI *composition_enable)(UINT) = (HRESULT (WINAPI*)(UINT))dylib_proc(dwmlib, "DwmEnableComposition"); if (!composition_enable) { SSNES_ERR("Did not find DwmEnableComposition ...\n"); - dylib_close(lib); return; } HRESULT ret = composition_enable(0); if (FAILED(ret)) SSNES_ERR("Failed to set composition state ...\n"); - -end: - dylib_close(lib); } #endif From 777e6a53343afcf4dcee521c1863cfa91819470a Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 7 Aug 2011 23:35:54 +0200 Subject: [PATCH 5/5] Better shader path semantics. --- gfx/ext.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gfx/ext.c b/gfx/ext.c index d4e866e528..ce7fcbf42a 100644 --- a/gfx/ext.c +++ b/gfx/ext.c @@ -224,6 +224,15 @@ static bool setup_video(ext_t *ext, const video_info_t *video, const input_drive return false; } + const char *cg_shader = NULL; + const char *xml_shader = NULL; + enum ssnes_shader_type type = g_settings.video.shader_type; + if ((type == SSNES_SHADER_CG || type == SSNES_SHADER_AUTO) && *g_settings.video.cg_shader_path) + cg_shader = g_settings.video.cg_shader_path; + else if ((type == SSNES_SHADER_BSNES || type == SSNES_SHADER_AUTO) && *g_settings.video.bsnes_shader_path) + xml_shader = g_settings.video.bsnes_shader_path; + + ssnes_video_info_t info = { .width = video->width, .height = video->height, @@ -234,8 +243,8 @@ static bool setup_video(ext_t *ext, const video_info_t *video, const input_drive .smooth = video->smooth, .input_scale = video->input_scale, .color_format = video->rgb32 ? SSNES_COLOR_FORMAT_ARGB8888 : SSNES_COLOR_FORMAT_XRGB1555, - .xml_shader = g_settings.video.bsnes_shader_path, - .cg_shader = g_settings.video.cg_shader_path, + .xml_shader = xml_shader, + .cg_shader = cg_shader, .ttf_font = *g_settings.video.font_path ? g_settings.video.font_path : NULL, .ttf_font_size = g_settings.video.font_size };