summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author couriersud <couriersud@arcor.de>2015-01-29 23:19:27 +0100
committer couriersud <couriersud@arcor.de>2015-01-29 23:19:27 +0100
commitf952a4a3ba3c790875dba0358116b306b8fdd8ac (patch)
tree330c1efa51fe006dbd6a84aef572b26fc5325fbc
parentf8de24c1e5f86be0e8a77dbc2ec2ae96aaddc45b (diff)
Converted sdl_monitor_info into a proper object. (nw)
-rw-r--r--src/osd/sdl/draw13.c9
-rw-r--r--src/osd/sdl/drawogl.c11
-rw-r--r--src/osd/sdl/drawsdl.c10
-rw-r--r--src/osd/sdl/osdsdl.h3
-rw-r--r--src/osd/sdl/video.c121
-rw-r--r--src/osd/sdl/video.h56
-rw-r--r--src/osd/sdl/window.c30
7 files changed, 112 insertions, 128 deletions
diff --git a/src/osd/sdl/draw13.c b/src/osd/sdl/draw13.c
index b6237557cad..885ae8ff424 100644
--- a/src/osd/sdl/draw13.c
+++ b/src/osd/sdl/draw13.c
@@ -593,7 +593,8 @@ static int drawsdl2_window_create(sdl_window_info *window, int width, int height
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
#endif
// create the SDL window
- window->sdl_window = SDL_CreateWindow(window->title, window->monitor()->monitor_x, 0,
+ window->sdl_window = SDL_CreateWindow(window->title,
+ window->monitor()->position_size().x, window->monitor()->position_size().y,
width, height, extra_flags);
if (window->fullscreen() && video_config.switchres)
@@ -710,7 +711,7 @@ static int drawsdl2_xy_to_render_target(sdl_window_info *window, int x, int y, i
static void drawsdl2_set_target_bounds(sdl_window_info *window)
{
- window->target->set_bounds(window->blitwidth, window->blitheight, sdlvideo_monitor_get_aspect(window->monitor()));
+ window->target->set_bounds(window->blitwidth, window->blitheight, window->monitor()->aspect());
}
//============================================================
@@ -761,8 +762,8 @@ static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update)
if ((window->fullscreen()) && (!video_config.switchres))
{
- ch = window->monitor()->center_height;
- cw = window->monitor()->center_width;
+ ch = window->monitor()->center_height();
+ cw = window->monitor()->center_width();
}
else
{
diff --git a/src/osd/sdl/drawogl.c b/src/osd/sdl/drawogl.c
index 7fe795b43ed..d21f14e6285 100644
--- a/src/osd/sdl/drawogl.c
+++ b/src/osd/sdl/drawogl.c
@@ -558,7 +558,8 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height)
//load_gl_lib(window->machine());
// create the SDL window
- window->sdl_window = SDL_CreateWindow(window->title, window->monitor()->monitor_x, 0,
+ window->sdl_window = SDL_CreateWindow(window->title,
+ window->monitor()->position_size().x, window->monitor()->position_size().y,
width, height, sdl->extra_flags);
if (!window->sdl_window )
@@ -570,7 +571,7 @@ static int drawogl_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);
mode.w = width;
mode.h = height;
if (window->refresh)
@@ -842,7 +843,7 @@ static int drawogl_xy_to_render_target(sdl_window_info *window, int x, int y, in
static void drawogl_set_target_bounds(sdl_window_info *window)
{
- window->target->set_bounds(window->blitwidth, window->blitheight, sdlvideo_monitor_get_aspect(window->monitor()));
+ window->target->set_bounds(window->blitwidth, window->blitheight, window->monitor()->aspect());
}
//============================================================
@@ -1312,8 +1313,8 @@ static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update)
if ((window->fullscreen()) && (!video_config.switchres))
{
- ch = window->monitor()->center_height;
- cw = window->monitor()->center_width;
+ ch = window->monitor()->center_height();
+ cw = window->monitor()->center_width();
}
else
{
diff --git a/src/osd/sdl/drawsdl.c b/src/osd/sdl/drawsdl.c
index fdfb05a45c8..4e52003eb5b 100644
--- a/src/osd/sdl/drawsdl.c
+++ b/src/osd/sdl/drawsdl.c
@@ -251,7 +251,7 @@ static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight
UINT32 fmt;
// Determine preferred pixelformat and set up yuv if necessary
- SDL_GetCurrentDisplayMode(window->monitor()->handle, &mode);
+ SDL_GetCurrentDisplayMode(window->monitor()->handle(), &mode);
if (sdl->yuv_bitmap)
{
@@ -412,7 +412,7 @@ static int drawsdl_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);
mode.w = width;
mode.h = height;
if (window->refresh)
@@ -623,7 +623,7 @@ static void drawsdl_set_target_bounds(sdl_window_info *window)
const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode];
if (!sm->is_scale)
- window->target->set_bounds(window->blitwidth, window->blitheight, sdlvideo_monitor_get_aspect(window->monitor()));
+ window->target->set_bounds(window->blitwidth, window->blitheight, window->monitor()->aspect());
else
window->target->set_bounds(sdl->hw_scale_width, sdl->hw_scale_height);
}
@@ -737,8 +737,8 @@ static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update)
// the first one only
if ((window->fullscreen()) && (!video_config.switchres))
{
- ch = window->monitor()->center_height;
- cw = window->monitor()->center_width;
+ ch = window->monitor()->center_height();
+ cw = window->monitor()->center_width();
}
else
{
diff --git a/src/osd/sdl/osdsdl.h b/src/osd/sdl/osdsdl.h
index 3bbed8efd16..f3271275a28 100644
--- a/src/osd/sdl/osdsdl.h
+++ b/src/osd/sdl/osdsdl.h
@@ -6,7 +6,6 @@
#include "watchdog.h"
#include "clifront.h"
#include "modules/lib/osdobj_common.h"
-#include "video.h"
#include "modules/osdmodule.h"
#include "modules/font/font_module.h"
@@ -215,8 +214,6 @@ public:
private:
virtual void osd_exit();
- void extract_window_config(int index, sdl_window_config *conf);
-
// FIXME: remove machine usage
void extract_video_config(running_machine &machine);
diff --git a/src/osd/sdl/video.c b/src/osd/sdl/video.c
index 5a8da9eb031..05b17fd45e1 100644
--- a/src/osd/sdl/video.c
+++ b/src/osd/sdl/video.c
@@ -69,20 +69,17 @@ osd_gl_dispatch *gl_dispatch;
#endif
#endif
+sdl_monitor_info *sdl_monitor_info::primary_monitor = NULL;
+sdl_monitor_info *sdl_monitor_info::list = NULL;
+
//============================================================
// LOCAL VARIABLES
//============================================================
-static sdl_monitor_info *primary_monitor;
-static sdl_monitor_info *sdl_monitor_list;
-
//============================================================
// PROTOTYPES
//============================================================
-static void init_monitors(void);
-static sdl_monitor_info *pick_monitor(sdl_options &options, int index);
-
static void check_osd_inputs(running_machine &machine);
static float get_aspect(const char *defdata, const char *data, int report_error);
@@ -101,7 +98,7 @@ bool sdl_osd_interface::video_init()
extract_video_config(machine());
// set up monitors first
- init_monitors();
+ sdl_monitor_info::init();
// we need the beam width in a float, contrary to what the core does.
video_config.beamwidth = options().beam();
@@ -115,8 +112,8 @@ bool sdl_osd_interface::video_init()
{
sdl_window_config conf;
memset(&conf, 0, sizeof(conf));
- extract_window_config(index, &conf);
- if (sdlwindow_video_window_create(machine(), index, pick_monitor(options(), index), &conf))
+ get_resolution(options().resolution(), options().resolution(index), &conf, TRUE);
+ if (sdlwindow_video_window_create(machine(), index, sdl_monitor_info::pick_monitor(options(), index), &conf))
return false;
}
@@ -131,15 +128,7 @@ bool sdl_osd_interface::video_init()
void sdl_osd_interface::video_exit()
{
window_exit();
-
- // free all of our monitor information
- while (sdl_monitor_list != NULL)
- {
- sdl_monitor_info *temp = sdl_monitor_list;
- sdl_monitor_list = temp->next;
- global_free(temp);
- }
-
+ sdl_monitor_info::exit();
}
@@ -147,20 +136,19 @@ void sdl_osd_interface::video_exit()
// sdlvideo_monitor_refresh
//============================================================
-void sdlvideo_monitor_refresh(sdl_monitor_info *monitor)
+void sdl_monitor_info::refresh()
{
#if (SDLMAME_SDL2)
SDL_DisplayMode dmode;
#if defined(SDLMAME_WIN32)
- SDL_GetDesktopDisplayMode(monitor->handle, &dmode);
+ SDL_GetDesktopDisplayMode(m_handle, &dmode);
#else
- SDL_GetCurrentDisplayMode(monitor->handle, &dmode);
+ SDL_GetCurrentDisplayMode(m_handle, &dmode);
#endif
- monitor->monitor_width = dmode.w;
- monitor->monitor_height = dmode.h;
- monitor->center_width = dmode.w;
- monitor->center_height = dmode.h;
+ SDL_GetDisplayBounds(m_handle, &m_dimensions);
+ m_center_width = m_dimensions.w;
+ m_center_height = m_dimensions.h;
// FIXME: Use SDL_GetDisplayBounds(monitor->handle, &tt) to update monitor_x
// SDL_Rect tt;
@@ -169,8 +157,9 @@ void sdlvideo_monitor_refresh(sdl_monitor_info *monitor)
MONITORINFOEX info;
info.cbSize = sizeof(info);
GetMonitorInfo((HMONITOR)monitor->handle, (LPMONITORINFO)&info);
- monitor->center_width = monitor->monitor_width = info.rcMonitor.right - info.rcMonitor.left;
- monitor->center_height = monitor->monitor_height = info.rcMonitor.bottom - info.rcMonitor.top;
+ monitor->m_dimensions.x = monitor->m_dimensions.y = 0;
+ monitor->m_center_width = monitor->m_dimensions.w = info.rcMonitor.right - info.rcMonitor.left;
+ monitor->m_center_height = monitor->m_dimensions.h = info.rcMonitor.bottom - info.rcMonitor.top;
char *temp = utf8_from_wstring(info.szDevice);
strcpy(monitor->monitor_device, temp);
osd_free(temp);
@@ -285,34 +274,20 @@ void sdlvideo_monitor_refresh(sdl_monitor_info *monitor)
// sdlvideo_monitor_get_aspect
//============================================================
-float sdlvideo_monitor_get_aspect(sdl_monitor_info *monitor)
+float sdl_monitor_info::aspect()
{
// refresh the monitor information and compute the aspect
+ refresh();
+ // FIXME: returning 0 looks odd, video_config is bad
if (video_config.keepaspect)
{
- sdlvideo_monitor_refresh(monitor);
- return monitor->aspect / ((float)monitor->monitor_width / (float)monitor->monitor_height);
+ return m_aspect / ((float)m_dimensions.w / (float)m_dimensions.h);
}
return 0.0f;
}
-//============================================================
-// sdlvideo_monitor_from_handle
-//============================================================
-
-sdl_monitor_info *sdlvideo_monitor_from_handle(UINT32 hmonitor)
-{
- sdl_monitor_info *monitor;
-
- // find the matching monitor
- for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next)
- if (monitor->handle == hmonitor)
- return monitor;
- return NULL;
-}
-
//============================================================
// update
@@ -431,13 +406,13 @@ static BOOL CALLBACK monitor_enum_callback(HMONITOR handle, HDC dc, LPRECT rect,
// init_monitors
//============================================================
-static void init_monitors(void)
+void sdl_monitor_info::init()
{
sdl_monitor_info **tailptr;
// make a list of monitors
- sdl_monitor_list = NULL;
- tailptr = &sdl_monitor_list;
+ sdl_monitor_info::list = NULL;
+ tailptr = &sdl_monitor_info::list;
#if (SDLMAME_SDL2)
{
@@ -452,20 +427,19 @@ static void init_monitors(void)
// allocate a new monitor info
monitor = global_alloc_clear(sdl_monitor_info);
+ monitor->m_handle = i;
- snprintf(monitor->monitor_device, sizeof(monitor->monitor_device)-1, "%s%d", OSDOPTION_SCREEN,i);
+ snprintf(monitor->m_monitor_device, sizeof(monitor->m_monitor_device)-1, "%s%d", OSDOPTION_SCREEN,i);
SDL_GetDesktopDisplayMode(i, &dmode);
- monitor->monitor_width = dmode.w;
- 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;
+ SDL_GetDisplayBounds(i, &monitor->m_dimensions);
+ monitor->m_center_width = monitor->m_dimensions.w;
+ monitor->m_center_height = monitor->m_dimensions.h;
+
// guess the aspect ratio assuming square pixels
- monitor->aspect = (float)(dmode.w) / (float)(dmode.h);
- osd_printf_verbose("Adding monitor %s (%d x %d)\n", monitor->monitor_device, dmode.w, dmode.h);
+ monitor->m_aspect = (float)(dmode.w) / (float)(dmode.h);
+
+ osd_printf_verbose("Adding monitor %s (%d x %d)\n", monitor->m_monitor_device, dmode.w, dmode.h);
monx += dmode.w;
@@ -486,13 +460,24 @@ static void init_monitors(void)
#endif
}
+void sdl_monitor_info::exit()
+{
+ // free all of our monitor information
+ while (sdl_monitor_info::list != NULL)
+ {
+ sdl_monitor_info *temp = sdl_monitor_info::list;
+ sdl_monitor_info::list = temp->next;
+ global_free(temp);
+ }
+}
+
//============================================================
// pick_monitor
//============================================================
#if (SDLMAME_SDL2) || defined(SDLMAME_WIN32)
-static sdl_monitor_info *pick_monitor(sdl_options &options, int index)
+sdl_monitor_info *sdl_monitor_info::pick_monitor(sdl_options &options, int index)
{
sdl_monitor_info *monitor;
const char *scrname, *scrname2;
@@ -513,17 +498,17 @@ static sdl_monitor_info *pick_monitor(sdl_options &options, int index)
// look for a match in the name first
if (scrname != NULL)
{
- for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next)
+ for (monitor = sdl_monitor_info::list; monitor != NULL; monitor = monitor->next)
{
moncount++;
- if (strcmp(scrname, monitor->monitor_device) == 0)
+ if (strcmp(scrname, monitor->device()) == 0)
goto finishit;
}
}
// didn't find it; alternate monitors until we hit the jackpot
index %= moncount;
- for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next)
+ for (monitor = sdl_monitor_info::list; monitor != NULL; monitor = monitor->next)
if (index-- == 0)
goto finishit;
@@ -533,7 +518,7 @@ static sdl_monitor_info *pick_monitor(sdl_options &options, int index)
finishit:
if (aspect != 0)
{
- monitor->aspect = aspect;
+ monitor->set_aspect(aspect);
}
return monitor;
}
@@ -609,16 +594,6 @@ static void check_osd_inputs(running_machine &machine)
}
//============================================================
-// extract_window_config
-//============================================================
-
-void sdl_osd_interface::extract_window_config(int index, sdl_window_config *conf)
-{
- // per-window options: extract the data
- get_resolution(options().resolution(), options().resolution(index), conf, TRUE);
-}
-
-//============================================================
// extract_video_config
//============================================================
diff --git a/src/osd/sdl/video.h b/src/osd/sdl/video.h
index 3588776e740..2e5cc4f0cce 100644
--- a/src/osd/sdl/video.h
+++ b/src/osd/sdl/video.h
@@ -12,6 +12,8 @@
#ifndef __SDLVIDEO__
#define __SDLVIDEO__
+#include "osdsdl.h"
+
//============================================================
// CONSTANTS
//============================================================
@@ -56,21 +58,41 @@ struct sdl_mode
int height;
};
-struct sdl_monitor_info
+class sdl_monitor_info
{
+public:
sdl_monitor_info * next; // pointer to next monitor in list
-#ifdef PTR64
- UINT64 handle; // handle to the monitor
-#else
- UINT32 handle; // handle to the monitor
-#endif
- int monitor_width;
- int monitor_height;
- char monitor_device[64];
- float aspect; // computed/configured aspect ratio of the physical device
- int center_width; // width of first physical screen for centering
- int center_height; // height of first physical screen for centering
- int monitor_x; // X position of this monitor in virtual desktop space (SDL virtual space has them all horizontally stacked, not real geometry)
+
+ const UINT64 handle() { return m_handle; }
+ const SDL_Rect &position_size() { refresh(); return m_dimensions; }
+
+ const char *device() { return m_monitor_device; }
+
+ float aspect();
+ int center_width() { refresh(); return m_center_width; }
+ int center_height() { refresh(); return m_center_height; }
+
+ void set_aspect(const float aspect) { m_aspect = aspect; }
+
+ // STATIC
+ static void init();
+ static void exit();
+ static sdl_monitor_info *pick_monitor(sdl_options &options, int index);
+
+private:
+ void refresh();
+
+ UINT64 m_handle; // handle to the monitor
+ SDL_Rect m_dimensions;
+ char m_monitor_device[64];
+ float m_aspect; // computed/configured aspect ratio of the physical device
+ int m_center_width; // width of first physical screen for centering
+ int m_center_height; // height of first physical screen for centering
+
+ // STATIC
+ static sdl_monitor_info *primary_monitor;
+ static sdl_monitor_info *list;
+
};
@@ -137,12 +159,4 @@ struct sdl_video_config
extern sdl_video_config video_config;
-//============================================================
-// PROTOTYPES
-//============================================================
-
-void sdlvideo_monitor_refresh(sdl_monitor_info *monitor);
-float sdlvideo_monitor_get_aspect(sdl_monitor_info *monitor);
-sdl_monitor_info *sdlvideo_monitor_from_handle(UINT32 monitor); //FIXME: Remove? not referenced
-
#endif
diff --git a/src/osd/sdl/window.c b/src/osd/sdl/window.c
index 88325d682ad..12a3fdb1e3d 100644
--- a/src/osd/sdl/window.c
+++ b/src/osd/sdl/window.c
@@ -407,8 +407,7 @@ void sdl_window_info::blit_surface_size(int window_width, int window_height)
if (video_config.keepaspect)
{
// make sure the monitor is up-to-date
- sdlvideo_monitor_refresh(m_monitor);
- target->compute_visible_area(target_width, target_height, sdlvideo_monitor_get_aspect(m_monitor), target->orientation(), target_width, target_height);
+ target->compute_visible_area(target_width, target_height, m_monitor->aspect(), target->orientation(), target_width, target_height);
desired_aspect = (float)target_width / (float)target_height;
}
@@ -849,7 +848,7 @@ void sdl_window_info::pick_best_mode(int *fswidth, int *fsheight)
minimum_height -= 4;
}
- num = SDL_GetNumDisplayModes(m_monitor->handle);
+ num = SDL_GetNumDisplayModes(m_monitor->handle());
if (num == 0)
{
@@ -861,7 +860,7 @@ void sdl_window_info::pick_best_mode(int *fswidth, int *fsheight)
for (i = 0; i < num; ++i)
{
SDL_DisplayMode mode;
- SDL_GetDisplayMode(m_monitor->handle, i, &mode);
+ SDL_GetDisplayMode(m_monitor->handle(), i, &mode);
// compute initial score based on difference between target and current
size_score = 1.0f / (1.0f + fabsf((INT32)mode.w - target_width) + fabsf((INT32)mode.h - target_height));
@@ -1024,7 +1023,7 @@ void sdl_window_info::video_window_update(running_machine &machine)
}
else
{
- blit_surface_size(monitor()->center_width, monitor()->center_height);
+ blit_surface_size(monitor()->center_width(), monitor()->center_height());
}
// ensure the target bounds are up-to-date, and then get the primitives
@@ -1083,8 +1082,8 @@ static OSDWORK_CALLBACK( complete_create_wt )
if (window->fullscreen())
{
// default to the current mode exactly
- tempwidth = window->monitor()->monitor_width;
- tempheight = window->monitor()->monitor_height;
+ tempwidth = window->monitor()->position_size().w;
+ tempheight = window->monitor()->position_size().h;
// if we're allowed to switch resolutions, override with something better
if (video_config.switchres)
@@ -1225,11 +1224,8 @@ void sdl_window_info::constrain_to_aspect_ratio(int *window_width, int *window_h
INT32 viswidth, visheight;
float pixel_aspect;
- // make sure the monitor is up-to-date
- sdlvideo_monitor_refresh(m_monitor);
-
// get the pixel aspect ratio for the target monitor
- pixel_aspect = sdlvideo_monitor_get_aspect(m_monitor);
+ pixel_aspect = m_monitor->aspect();
// determine the proposed width/height
propwidth = *window_width - extrawidth;
@@ -1268,13 +1264,13 @@ void sdl_window_info::constrain_to_aspect_ratio(int *window_width, int *window_h
// clamp against the maximum (fit on one screen for full screen mode)
if (this->m_fullscreen)
{
- maxwidth = m_monitor->center_width - extrawidth;
- maxheight = m_monitor->center_height - extraheight;
+ maxwidth = m_monitor->center_width() - extrawidth;
+ maxheight = m_monitor->center_height() - extraheight;
}
else
{
- maxwidth = m_monitor->center_width - extrawidth;
- maxheight = m_monitor->center_height - extraheight;
+ maxwidth = m_monitor->center_width() - extrawidth;
+ maxheight = m_monitor->center_height() - extraheight;
// further clamp to the maximum width/height in the window
if (this->m_maxwidth != 0)
@@ -1355,8 +1351,8 @@ void sdl_window_info::get_max_bounds(int *window_width, int *window_height, int
INT32 maxwidth, maxheight;
// compute the maximum client area
- maxwidth = m_monitor->center_width;
- maxheight = m_monitor->center_height;
+ maxwidth = m_monitor->center_width();
+ maxheight = m_monitor->center_height();
// clamp to the window's max
if (this->m_maxwidth != 0)