From 8da5cfa3dd150a340457b4ed9deadc7135c29001 Mon Sep 17 00:00:00 2001 From: couriersud Date: Tue, 6 Jan 2015 22:50:00 +0100 Subject: Fixed two SDL2 bugs: - Window height was 0 after a switch from fullscreen to windowed if sdlmame was started in fullscreen - Fixed -switchres. This is now working on Ubuntu 14.04 again. Performance will vary on your hardware and drivers and I suspect SDL to be partly broken. --- src/osd/sdl/draw13.c | 35 +++++++++++++++++++++++++++++++---- src/osd/sdl/input.c | 13 +++++++++++-- src/osd/sdl/osdsdl.h | 2 +- src/osd/sdl/video.c | 8 ++++++++ src/osd/sdl/window.h | 7 ++----- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/osd/sdl/draw13.c b/src/osd/sdl/draw13.c index 166d9910cde..b165ca411b6 100644 --- a/src/osd/sdl/draw13.c +++ b/src/osd/sdl/draw13.c @@ -186,6 +186,9 @@ struct sdl_info // Stats INT64 m_last_blit_time; INT64 m_last_blit_pixels; + + // Original display_mode + SDL_DisplayMode m_original_mode; }; //============================================================ @@ -576,6 +579,13 @@ static int drawsdl2_window_create(sdl_window_info *window, int width, int height // allocate memory for our structures sdl_info *sdl = global_alloc(sdl_info); + /* FIXME: On Ubuntu and potentially other Linux OS you should use + * to disable panning. This has to be done before every invocation of mame. + * + * xrandr --output HDMI-0 --panning 0x0+0+0 --fb 0x0 + * + */ + osd_printf_verbose("Enter drawsdl2_window_create\n"); window->dxdata = sdl; @@ -590,7 +600,9 @@ static int drawsdl2_window_create(sdl_window_info *window, int width, int height if (window->fullscreen() && video_config.switchres) { SDL_DisplayMode mode; - SDL_GetCurrentDisplayMode(window->monitor()->handle, &mode); + //SDL_GetCurrentDisplayMode(window->monitor()->handle, &mode); + SDL_GetWindowDisplayMode(window->sdl_window, &mode); + sdl->m_original_mode = mode; mode.w = width; mode.h = height; if (window->refresh) @@ -615,7 +627,14 @@ static int drawsdl2_window_create(sdl_window_info *window, int width, int height osd_printf_warning("Ignoring depth %d\n", window->depth); } } - SDL_SetWindowDisplayMode(window->sdl_window, &mode); // Try to set mode + SDL_SetWindowDisplayMode(window->sdl_window, &mode); // Try to set mode +#ifndef SDLMAME_WIN32 + /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution + * is in place after the mode switch - which will most likely be the case + * This is a hack to work around a deficiency in SDL2 + */ + SDL_WarpMouseInWindow(window->sdl_window, 1, 1); +#endif } else SDL_SetWindowDisplayMode(window->sdl_window, NULL); // Use desktop @@ -639,7 +658,6 @@ static int drawsdl2_window_create(sdl_window_info *window, int width, int height SDL_RaiseWindow(window->sdl_window); SDL_GetWindowSize(window->sdl_window, &window->width, &window->height); - sdl->m_blittimer = 3; SDL_RenderPresent(sdl->m_renderer); @@ -715,6 +733,8 @@ static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update) SDL_GetWindowSize(window->sdl_window, &window->width, &window->height); sdl->m_resize_pending = 0; SDL_RenderSetViewport(sdl->m_renderer, NULL); + //sdlvideo_monitor_refresh(window->monitor()); + } //SDL_SelectRenderer(window->sdl_window); @@ -832,7 +852,14 @@ static void drawsdl2_window_destroy(sdl_window_info *window) drawsdl2_destroy_all_textures(window); - SDL_DestroyWindow(window->sdl_window); + if (window->fullscreen() && video_config.switchres) + { + SDL_SetWindowFullscreen(window->sdl_window, 0); // Try to set mode + SDL_SetWindowDisplayMode(window->sdl_window, &sdl->m_original_mode); // Try to set mode + SDL_SetWindowFullscreen(window->sdl_window, SDL_WINDOW_FULLSCREEN); // Try to set mode + } + + SDL_DestroyWindow(window->sdl_window); global_free(sdl); window->dxdata = NULL; diff --git a/src/osd/sdl/input.c b/src/osd/sdl/input.c index 3fe3c7fcbb0..13d5a8a1e64 100644 --- a/src/osd/sdl/input.c +++ b/src/osd/sdl/input.c @@ -1985,8 +1985,17 @@ void sdlinput_poll(running_machine &machine) } else { - if (event.window.data1 != window->width || event.window.data2 != window->height) - window->window_resize(event.window.data1, event.window.data2); +#ifndef SDLMAME_WIN32 + /* FIXME: SDL2 sends some spurious resize events on Ubuntu + * while in fullscreen mode. Ignore them for now. + */ + if (!window->fullscreen()) +#endif + { + //printf("event data1,data2 %d x %d %ld\n", event.window.data1, event.window.data2, sizeof(SDL_Event)); + if (event.window.data1 != window->width || event.window.data2 != window->height) + window->window_resize(event.window.data1, event.window.data2); + } } focus_window = window; break; diff --git a/src/osd/sdl/osdsdl.h b/src/osd/sdl/osdsdl.h index 5e039285369..d64841f1905 100644 --- a/src/osd/sdl/osdsdl.h +++ b/src/osd/sdl/osdsdl.h @@ -26,8 +26,8 @@ #define SDL13_COMBINE_RESIZE (0) #endif #else + #define SDLMAME_INIT_IN_WORKER_THREAD (0) #define SDL13_COMBINE_RESIZE (0) - #define SDLMAME_INIT_IN_WORKER_THREAD (0) #endif #if defined(NO_DEBUGGER) diff --git a/src/osd/sdl/video.c b/src/osd/sdl/video.c index 6c4e189a72f..e28198abb37 100644 --- a/src/osd/sdl/video.c +++ b/src/osd/sdl/video.c @@ -155,11 +155,18 @@ void sdlvideo_monitor_refresh(sdl_monitor_info *monitor) #if (SDLMAME_SDL2) SDL_DisplayMode dmode; + #if defined(SDLMAME_WIN32) SDL_GetDesktopDisplayMode(monitor->handle, &dmode); + #else + SDL_GetCurrentDisplayMode(monitor->handle, &dmode); + #endif monitor->monitor_width = dmode.w; monitor->monitor_height = dmode.h; monitor->center_width = dmode.w; monitor->center_height = dmode.h; + + // FIXME: Use SDL_GetDisplayBounds(monitor->handle, &tt) to update monitor_x + // SDL_Rect tt; #else #if defined(SDLMAME_WIN32) // Win32 version MONITORINFOEX info; @@ -456,6 +463,7 @@ static void init_monitors(void) monitor->monitor_height = dmode.h; monitor->center_width = dmode.w; monitor->center_height = dmode.h; + // FIXME: this should use SDL_GetDisplayBounds! monitor->monitor_x = monx; monitor->handle = i; // guess the aspect ratio assuming square pixels diff --git a/src/osd/sdl/window.h b/src/osd/sdl/window.h index a666b984674..3b47433a91d 100644 --- a/src/osd/sdl/window.h +++ b/src/osd/sdl/window.h @@ -61,11 +61,8 @@ struct sdl_window_info m_fullscreen = !video_config.windowed; prescale = video_config.prescale; - if (!m_fullscreen) - { - windowed_width = config->width; - windowed_height = config->height; - } + windowed_width = config->width; + windowed_height = config->height; } void video_window_update(running_machine &machine); -- cgit v1.2.3