From 7425e1f879698119b0dd94d4d085d01ae873440c Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 7 Aug 2011 15:00:34 +0200 Subject: [PATCH] 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