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.
This commit is contained in:
couriersud 2015-01-06 22:50:00 +01:00
parent d91c7ad1e5
commit 8da5cfa3dd
5 changed files with 53 additions and 12 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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

View File

@ -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);