diff options
Diffstat (limited to 'src/osd/sdl/video.cpp')
-rw-r--r-- | src/osd/sdl/video.cpp | 237 |
1 files changed, 234 insertions, 3 deletions
diff --git a/src/osd/sdl/video.cpp b/src/osd/sdl/video.cpp index ca7286d5696..c5de6be41d9 100644 --- a/src/osd/sdl/video.cpp +++ b/src/osd/sdl/video.cpp @@ -7,6 +7,33 @@ // SDLMAME by Olivier Galibert and R. Belmont // //============================================================ + +#ifdef SDLMAME_X11 +#include <X11/extensions/Xinerama.h> +#endif + +#ifdef SDLMAME_MACOSX +#undef Status +#include <Carbon/Carbon.h> +#endif + +#ifdef SDLMAME_WIN32 +// for multimonitor +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x501 +#endif + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +#include "strconv.h" +#endif + +#ifdef SDLMAME_OS2 +#define INCL_WINSYS +#include <os2.h> +#endif + #include "sdlinc.h" // MAME headers @@ -107,9 +134,15 @@ void sdl_osd_interface::video_exit() //============================================================ // sdlvideo_monitor_refresh //============================================================ - +#if defined(SDLMAME_WIN32) // Win32 version +inline osd_rect RECT_to_osd_rect(const RECT &r) +{ + return osd_rect(r.left, r.top, r.right - r.left, r.bottom - r.top); +} +#endif void sdl_monitor_info::refresh() { + #if (SDLMAME_SDL2) SDL_DisplayMode dmode; #if defined(SDLMAME_WIN32) @@ -123,8 +156,128 @@ void sdl_monitor_info::refresh() m_pos_size = SDL_Rect_to_osd_rect(dimensions); m_usuable_pos_size = SDL_Rect_to_osd_rect(dimensions); m_is_primary = (m_handle == 0); + + #else + #if defined(SDLMAME_WIN32) // Win32 version + MONITORINFOEX info; + info.cbSize = sizeof(info); + GetMonitorInfo((HMONITOR)m_handle, (LPMONITORINFO)&info); + m_pos_size = RECT_to_osd_rect(info.rcMonitor); + m_usuable_pos_size = RECT_to_osd_rect(info.rcWork); + m_is_primary = ((info.dwFlags & MONITORINFOF_PRIMARY) != 0); + char *temp = utf8_from_wstring(info.szDevice); + strncpy(m_name, temp, ARRAY_LENGTH(m_name) - 1); + osd_free(temp); + #elif defined(SDLMAME_MACOSX) // Mac OS X Core Imaging version + CGDirectDisplayID primary; + CGRect dbounds; + + // get the main display + primary = CGMainDisplayID(); + dbounds = CGDisplayBounds(primary); + + m_is_primary = (m_handle == 0); + m_pos_size = osd_rect(0, 0, dbounds.size.width - dbounds.origin.x, dbounds.size.height - dbounds.origin.y); + m_usuable_pos_size = m_pos_size; + strncpy(m_name, "Mac OS X display", ARRAY_LENGTH(m_name) - 1); + #elif defined(SDLMAME_X11) || defined(SDLMAME_NO_X11) // X11 version + { + #if defined(SDLMAME_X11) + // X11 version + int screen; + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + + if ( SDL_GetWMInfo(&info) && (info.subsystem == SDL_SYSWM_X11) ) + { + screen = DefaultScreen(info.info.x11.display); + SDL_VideoDriverName(m_name, ARRAY_LENGTH(m_name) - 1); + m_pos_size = osd_rect(0, 0, + DisplayWidth(info.info.x11.display, screen), + DisplayHeight(info.info.x11.display, screen)); + + /* FIXME: If Xinerame is used we should compile a list of monitors + * like we do for other targets and ignore SDL. + */ + if ((XineramaIsActive(info.info.x11.display)) && video_config.restrictonemonitor) + { + XineramaScreenInfo *xineinfo; + int numscreens; + + xineinfo = XineramaQueryScreens(info.info.x11.display, &numscreens); + + m_pos_size = osd_rect(0, 0, xineinfo[0].width, xineinfo[0].height); + + XFree(xineinfo); + } + m_usuable_pos_size = m_pos_size; + m_is_primary = (m_handle == 0); + } + else + #endif // defined(SDLMAME_X11) + { + static int first_call=0; + static int cw = 0, ch = 0; + + SDL_VideoDriverName(m_name, ARRAY_LENGTH(m_name) - 1); + if (first_call==0) + { + const char *dimstr = osd_getenv(SDLENV_DESKTOPDIM); + const SDL_VideoInfo *sdl_vi; + + sdl_vi = SDL_GetVideoInfo(); + #if (SDL_VERSION_ATLEAST(1,2,10)) + cw = sdl_vi->current_w; + ch = sdl_vi->current_h; + #endif + first_call=1; + if ((cw==0) || (ch==0)) + { + if (dimstr != NULL) + { + sscanf(dimstr, "%dx%d", &cw, &ch); + } + if ((cw==0) || (ch==0)) + { + osd_printf_warning("WARNING: SDL_GetVideoInfo() for driver <%s> is broken.\n", m_name); + osd_printf_warning(" You should set SDLMAME_DESKTOPDIM to your desktop size.\n"); + osd_printf_warning(" e.g. export SDLMAME_DESKTOPDIM=800x600\n"); + osd_printf_warning(" Assuming 1024x768 now!\n"); + cw=1024; + ch=768; + } + } + } + m_pos_size = osd_rect(0, 0, cw, ch); + m_usuable_pos_size = m_pos_size; + m_is_primary = (m_handle == 0); + } + } + #elif defined(SDLMAME_OS2) // OS2 version + m_pos_size = osd_rect(0, 0, + WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ), + WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ) ); + m_usuable_pos_size = m_pos_size; + m_is_primary = (m_handle == 0); + strncpy(m_name, "OS/2 display", ARRAY_LENGTH(m_name) - 1); + #else + #error Unknown SDLMAME_xx OS type! + #endif + + { + static int info_shown=0; + if (!info_shown) + { + osd_printf_verbose("SDL Device Driver : %s\n", m_name); + osd_printf_verbose("SDL Monitor Dimensions: %d x %d\n", m_pos_size.width(), m_pos_size.height()); + info_shown = 1; + } + } + #endif // (SDLMAME_SDL2) } + + //============================================================ // sdlvideo_monitor_get_aspect //============================================================ @@ -172,6 +325,68 @@ void sdl_osd_interface::update(bool skip_redraw) //============================================================ +// add_primary_monitor +//============================================================ + +#if !defined(SDLMAME_WIN32) && !(SDLMAME_SDL2) +void sdl_monitor_info::add_primary_monitor(void *data) +{ + // make a list of monitors + osd_monitor_info::list = NULL; + osd_monitor_info **tailptr = &sdl_monitor_info::list; + + // allocate a new monitor info + osd_monitor_info *monitor = global_alloc_clear<sdl_monitor_info>(0, "", 1.0f); + + //monitor->refresh(); + // guess the aspect ratio assuming square pixels + monitor->set_aspect((float)(monitor->position_size().width()) / (float)(monitor->position_size().height())); + + // hook us into the list + *tailptr = monitor; + //tailptr = &monitor->m_next; +} +#endif + + +//============================================================ +// monitor_enum_callback +//============================================================ + +#if defined(SDLMAME_WIN32) && !(SDLMAME_SDL2) +BOOL CALLBACK sdl_monitor_info::monitor_enum_callback(HMONITOR handle, HDC dc, LPRECT rect, LPARAM data) +{ + osd_monitor_info ***tailptr = (osd_monitor_info ***)data; + osd_monitor_info *monitor; + MONITORINFOEX info; + BOOL result; + + // get the monitor info + info.cbSize = sizeof(info); + result = GetMonitorInfo(handle, (LPMONITORINFO)&info); + assert(result); + (void)result; // to silence gcc 4.6 + + // guess the aspect ratio assuming square pixels + float aspect = (float)(info.rcMonitor.right - info.rcMonitor.left) / (float)(info.rcMonitor.bottom - info.rcMonitor.top); + + // allocate a new monitor info + char *temp = utf8_from_wstring(info.szDevice); + // copy in the data + monitor = global_alloc(sdl_monitor_info((UINT64) handle, temp, aspect)); + osd_free(temp); + + // hook us into the list + **tailptr = monitor; + *tailptr = &monitor->m_next; + + // enumerate all the available monitors so to list their names in verbose mode + return TRUE; +} +#endif + + +//============================================================ // init_monitors //============================================================ @@ -183,6 +398,7 @@ void sdl_monitor_info::init() osd_monitor_info::list = NULL; tailptr = &osd_monitor_info::list; + #if (SDLMAME_SDL2) { int i; @@ -211,6 +427,11 @@ void sdl_monitor_info::init() } } osd_printf_verbose("Leave init_monitors\n"); + #elif defined(SDLMAME_WIN32) + EnumDisplayMonitors(NULL, NULL, monitor_enum_callback, (LPARAM)&tailptr); + #else + add_primary_monitor((void *)&tailptr); + #endif } void sdl_monitor_info::exit() @@ -313,7 +534,7 @@ static void check_osd_inputs(running_machine &machine) machine.ui().popup_time(1, "Keepaspect %s", video_config.keepaspect? "enabled":"disabled"); } - #if (USE_OPENGL) + #if (USE_OPENGL || SDLMAME_SDL2) //FIXME: on a per window basis if (machine.ui_input().pressed(IPT_OSD_5)) { @@ -379,14 +600,16 @@ void sdl_osd_interface::extract_video_config() } else if (USE_OPENGL && (strcmp(stemp, SDLOPTVAL_OPENGL) == 0)) video_config.mode = VIDEO_MODE_OPENGL; - else if ((strcmp(stemp, SDLOPTVAL_SDL2ACCEL) == 0)) + else if (SDLMAME_SDL2 && (strcmp(stemp, SDLOPTVAL_SDL2ACCEL) == 0)) { video_config.mode = VIDEO_MODE_SDL2ACCEL; } +#ifdef USE_BGFX else if (strcmp(stemp, SDLOPTVAL_BGFX) == 0) { video_config.mode = VIDEO_MODE_BGFX; } +#endif else { osd_printf_warning("Invalid video value %s; reverting to software\n", stemp); @@ -470,11 +693,19 @@ void sdl_osd_interface::extract_video_config() // misc options: sanity check values // global options: sanity check values +#if (!SDLMAME_SDL2) + if (video_config.numscreens < 1 || video_config.numscreens > 1) //MAX_VIDEO_WINDOWS) + { + osd_printf_warning("Invalid numscreens value %d; reverting to 1\n", video_config.numscreens); + video_config.numscreens = 1; + } +#else if (video_config.numscreens < 1 || video_config.numscreens > MAX_VIDEO_WINDOWS) { osd_printf_warning("Invalid numscreens value %d; reverting to 1\n", video_config.numscreens); video_config.numscreens = 1; } +#endif // yuv settings ... stemp = options().scale_mode(); video_config.scale_mode = drawsdl_scale_mode(stemp); |