trunk/src/osd/sdl/video.c
| r243237 | r243238 | |
| 69 | 69 | #endif |
| 70 | 70 | #endif |
| 71 | 71 | |
| 72 | sdl_monitor_info *sdl_monitor_info::primary_monitor = NULL; |
| 73 | sdl_monitor_info *sdl_monitor_info::list = NULL; |
| 74 | |
| 72 | 75 | //============================================================ |
| 73 | 76 | // LOCAL VARIABLES |
| 74 | 77 | //============================================================ |
| 75 | 78 | |
| 76 | | static sdl_monitor_info *primary_monitor; |
| 77 | | static sdl_monitor_info *sdl_monitor_list; |
| 78 | | |
| 79 | 79 | //============================================================ |
| 80 | 80 | // PROTOTYPES |
| 81 | 81 | //============================================================ |
| 82 | 82 | |
| 83 | | static void init_monitors(void); |
| 84 | | static sdl_monitor_info *pick_monitor(sdl_options &options, int index); |
| 85 | | |
| 86 | 83 | static void check_osd_inputs(running_machine &machine); |
| 87 | 84 | |
| 88 | 85 | static float get_aspect(const char *defdata, const char *data, int report_error); |
| r243237 | r243238 | |
| 101 | 98 | extract_video_config(machine()); |
| 102 | 99 | |
| 103 | 100 | // set up monitors first |
| 104 | | init_monitors(); |
| 101 | sdl_monitor_info::init(); |
| 105 | 102 | |
| 106 | 103 | // we need the beam width in a float, contrary to what the core does. |
| 107 | 104 | video_config.beamwidth = options().beam(); |
| r243237 | r243238 | |
| 115 | 112 | { |
| 116 | 113 | sdl_window_config conf; |
| 117 | 114 | memset(&conf, 0, sizeof(conf)); |
| 118 | | extract_window_config(index, &conf); |
| 119 | | if (sdlwindow_video_window_create(machine(), index, pick_monitor(options(), index), &conf)) |
| 115 | get_resolution(options().resolution(), options().resolution(index), &conf, TRUE); |
| 116 | if (sdlwindow_video_window_create(machine(), index, sdl_monitor_info::pick_monitor(options(), index), &conf)) |
| 120 | 117 | return false; |
| 121 | 118 | } |
| 122 | 119 | |
| r243237 | r243238 | |
| 131 | 128 | void sdl_osd_interface::video_exit() |
| 132 | 129 | { |
| 133 | 130 | window_exit(); |
| 134 | | |
| 135 | | // free all of our monitor information |
| 136 | | while (sdl_monitor_list != NULL) |
| 137 | | { |
| 138 | | sdl_monitor_info *temp = sdl_monitor_list; |
| 139 | | sdl_monitor_list = temp->next; |
| 140 | | global_free(temp); |
| 141 | | } |
| 142 | | |
| 131 | sdl_monitor_info::exit(); |
| 143 | 132 | } |
| 144 | 133 | |
| 145 | 134 | |
| r243237 | r243238 | |
| 147 | 136 | // sdlvideo_monitor_refresh |
| 148 | 137 | //============================================================ |
| 149 | 138 | |
| 150 | | void sdlvideo_monitor_refresh(sdl_monitor_info *monitor) |
| 139 | void sdl_monitor_info::refresh() |
| 151 | 140 | { |
| 152 | 141 | #if (SDLMAME_SDL2) |
| 153 | 142 | SDL_DisplayMode dmode; |
| 154 | 143 | |
| 155 | 144 | #if defined(SDLMAME_WIN32) |
| 156 | | SDL_GetDesktopDisplayMode(monitor->handle, &dmode); |
| 145 | SDL_GetDesktopDisplayMode(m_handle, &dmode); |
| 157 | 146 | #else |
| 158 | | SDL_GetCurrentDisplayMode(monitor->handle, &dmode); |
| 147 | SDL_GetCurrentDisplayMode(m_handle, &dmode); |
| 159 | 148 | #endif |
| 160 | | monitor->monitor_width = dmode.w; |
| 161 | | monitor->monitor_height = dmode.h; |
| 162 | | monitor->center_width = dmode.w; |
| 163 | | monitor->center_height = dmode.h; |
| 149 | SDL_GetDisplayBounds(m_handle, &m_dimensions); |
| 150 | m_center_width = m_dimensions.w; |
| 151 | m_center_height = m_dimensions.h; |
| 164 | 152 | |
| 165 | 153 | // FIXME: Use SDL_GetDisplayBounds(monitor->handle, &tt) to update monitor_x |
| 166 | 154 | // SDL_Rect tt; |
| r243237 | r243238 | |
| 169 | 157 | MONITORINFOEX info; |
| 170 | 158 | info.cbSize = sizeof(info); |
| 171 | 159 | GetMonitorInfo((HMONITOR)monitor->handle, (LPMONITORINFO)&info); |
| 172 | | monitor->center_width = monitor->monitor_width = info.rcMonitor.right - info.rcMonitor.left; |
| 173 | | monitor->center_height = monitor->monitor_height = info.rcMonitor.bottom - info.rcMonitor.top; |
| 160 | monitor->m_dimensions.x = monitor->m_dimensions.y = 0; |
| 161 | monitor->m_center_width = monitor->m_dimensions.w = info.rcMonitor.right - info.rcMonitor.left; |
| 162 | monitor->m_center_height = monitor->m_dimensions.h = info.rcMonitor.bottom - info.rcMonitor.top; |
| 174 | 163 | char *temp = utf8_from_wstring(info.szDevice); |
| 175 | 164 | strcpy(monitor->monitor_device, temp); |
| 176 | 165 | osd_free(temp); |
| r243237 | r243238 | |
| 285 | 274 | // sdlvideo_monitor_get_aspect |
| 286 | 275 | //============================================================ |
| 287 | 276 | |
| 288 | | float sdlvideo_monitor_get_aspect(sdl_monitor_info *monitor) |
| 277 | float sdl_monitor_info::aspect() |
| 289 | 278 | { |
| 290 | 279 | // refresh the monitor information and compute the aspect |
| 280 | refresh(); |
| 281 | // FIXME: returning 0 looks odd, video_config is bad |
| 291 | 282 | if (video_config.keepaspect) |
| 292 | 283 | { |
| 293 | | sdlvideo_monitor_refresh(monitor); |
| 294 | | return monitor->aspect / ((float)monitor->monitor_width / (float)monitor->monitor_height); |
| 284 | return m_aspect / ((float)m_dimensions.w / (float)m_dimensions.h); |
| 295 | 285 | } |
| 296 | 286 | return 0.0f; |
| 297 | 287 | } |
| 298 | 288 | |
| 299 | 289 | |
| 300 | 290 | |
| 301 | | //============================================================ |
| 302 | | // sdlvideo_monitor_from_handle |
| 303 | | //============================================================ |
| 304 | 291 | |
| 305 | | sdl_monitor_info *sdlvideo_monitor_from_handle(UINT32 hmonitor) |
| 306 | | { |
| 307 | | sdl_monitor_info *monitor; |
| 308 | | |
| 309 | | // find the matching monitor |
| 310 | | for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next) |
| 311 | | if (monitor->handle == hmonitor) |
| 312 | | return monitor; |
| 313 | | return NULL; |
| 314 | | } |
| 315 | | |
| 316 | | |
| 317 | 292 | //============================================================ |
| 318 | 293 | // update |
| 319 | 294 | //============================================================ |
| r243237 | r243238 | |
| 431 | 406 | // init_monitors |
| 432 | 407 | //============================================================ |
| 433 | 408 | |
| 434 | | static void init_monitors(void) |
| 409 | void sdl_monitor_info::init() |
| 435 | 410 | { |
| 436 | 411 | sdl_monitor_info **tailptr; |
| 437 | 412 | |
| 438 | 413 | // make a list of monitors |
| 439 | | sdl_monitor_list = NULL; |
| 440 | | tailptr = &sdl_monitor_list; |
| 414 | sdl_monitor_info::list = NULL; |
| 415 | tailptr = &sdl_monitor_info::list; |
| 441 | 416 | |
| 442 | 417 | #if (SDLMAME_SDL2) |
| 443 | 418 | { |
| r243237 | r243238 | |
| 452 | 427 | |
| 453 | 428 | // allocate a new monitor info |
| 454 | 429 | monitor = global_alloc_clear(sdl_monitor_info); |
| 430 | monitor->m_handle = i; |
| 455 | 431 | |
| 456 | | snprintf(monitor->monitor_device, sizeof(monitor->monitor_device)-1, "%s%d", OSDOPTION_SCREEN,i); |
| 432 | snprintf(monitor->m_monitor_device, sizeof(monitor->m_monitor_device)-1, "%s%d", OSDOPTION_SCREEN,i); |
| 457 | 433 | |
| 458 | 434 | SDL_GetDesktopDisplayMode(i, &dmode); |
| 459 | | monitor->monitor_width = dmode.w; |
| 460 | | monitor->monitor_height = dmode.h; |
| 461 | | monitor->center_width = dmode.w; |
| 462 | | monitor->center_height = dmode.h; |
| 463 | | // FIXME: this should use SDL_GetDisplayBounds! |
| 464 | | monitor->monitor_x = monx; |
| 465 | | monitor->handle = i; |
| 435 | SDL_GetDisplayBounds(i, &monitor->m_dimensions); |
| 436 | monitor->m_center_width = monitor->m_dimensions.w; |
| 437 | monitor->m_center_height = monitor->m_dimensions.h; |
| 438 | |
| 466 | 439 | // guess the aspect ratio assuming square pixels |
| 467 | | monitor->aspect = (float)(dmode.w) / (float)(dmode.h); |
| 468 | | osd_printf_verbose("Adding monitor %s (%d x %d)\n", monitor->monitor_device, dmode.w, dmode.h); |
| 440 | monitor->m_aspect = (float)(dmode.w) / (float)(dmode.h); |
| 469 | 441 | |
| 442 | osd_printf_verbose("Adding monitor %s (%d x %d)\n", monitor->m_monitor_device, dmode.w, dmode.h); |
| 443 | |
| 470 | 444 | monx += dmode.w; |
| 471 | 445 | |
| 472 | 446 | // save the primary monitor handle |
| r243237 | r243238 | |
| 486 | 460 | #endif |
| 487 | 461 | } |
| 488 | 462 | |
| 463 | void sdl_monitor_info::exit() |
| 464 | { |
| 465 | // free all of our monitor information |
| 466 | while (sdl_monitor_info::list != NULL) |
| 467 | { |
| 468 | sdl_monitor_info *temp = sdl_monitor_info::list; |
| 469 | sdl_monitor_info::list = temp->next; |
| 470 | global_free(temp); |
| 471 | } |
| 472 | } |
| 489 | 473 | |
| 474 | |
| 490 | 475 | //============================================================ |
| 491 | 476 | // pick_monitor |
| 492 | 477 | //============================================================ |
| 493 | 478 | |
| 494 | 479 | #if (SDLMAME_SDL2) || defined(SDLMAME_WIN32) |
| 495 | | static sdl_monitor_info *pick_monitor(sdl_options &options, int index) |
| 480 | sdl_monitor_info *sdl_monitor_info::pick_monitor(sdl_options &options, int index) |
| 496 | 481 | { |
| 497 | 482 | sdl_monitor_info *monitor; |
| 498 | 483 | const char *scrname, *scrname2; |
| r243237 | r243238 | |
| 513 | 498 | // look for a match in the name first |
| 514 | 499 | if (scrname != NULL) |
| 515 | 500 | { |
| 516 | | for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next) |
| 501 | for (monitor = sdl_monitor_info::list; monitor != NULL; monitor = monitor->next) |
| 517 | 502 | { |
| 518 | 503 | moncount++; |
| 519 | | if (strcmp(scrname, monitor->monitor_device) == 0) |
| 504 | if (strcmp(scrname, monitor->device()) == 0) |
| 520 | 505 | goto finishit; |
| 521 | 506 | } |
| 522 | 507 | } |
| 523 | 508 | |
| 524 | 509 | // didn't find it; alternate monitors until we hit the jackpot |
| 525 | 510 | index %= moncount; |
| 526 | | for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next) |
| 511 | for (monitor = sdl_monitor_info::list; monitor != NULL; monitor = monitor->next) |
| 527 | 512 | if (index-- == 0) |
| 528 | 513 | goto finishit; |
| 529 | 514 | |
| r243237 | r243238 | |
| 533 | 518 | finishit: |
| 534 | 519 | if (aspect != 0) |
| 535 | 520 | { |
| 536 | | monitor->aspect = aspect; |
| 521 | monitor->set_aspect(aspect); |
| 537 | 522 | } |
| 538 | 523 | return monitor; |
| 539 | 524 | } |
| r243237 | r243238 | |
| 609 | 594 | } |
| 610 | 595 | |
| 611 | 596 | //============================================================ |
| 612 | | // extract_window_config |
| 613 | | //============================================================ |
| 614 | | |
| 615 | | void sdl_osd_interface::extract_window_config(int index, sdl_window_config *conf) |
| 616 | | { |
| 617 | | // per-window options: extract the data |
| 618 | | get_resolution(options().resolution(), options().resolution(index), conf, TRUE); |
| 619 | | } |
| 620 | | |
| 621 | | //============================================================ |
| 622 | 597 | // extract_video_config |
| 623 | 598 | //============================================================ |
| 624 | 599 | |
trunk/src/osd/sdl/video.h
| r243237 | r243238 | |
| 12 | 12 | #ifndef __SDLVIDEO__ |
| 13 | 13 | #define __SDLVIDEO__ |
| 14 | 14 | |
| 15 | #include "osdsdl.h" |
| 16 | |
| 15 | 17 | //============================================================ |
| 16 | 18 | // CONSTANTS |
| 17 | 19 | //============================================================ |
| r243237 | r243238 | |
| 56 | 58 | int height; |
| 57 | 59 | }; |
| 58 | 60 | |
| 59 | | struct sdl_monitor_info |
| 61 | class sdl_monitor_info |
| 60 | 62 | { |
| 63 | public: |
| 61 | 64 | sdl_monitor_info * next; // pointer to next monitor in list |
| 62 | | #ifdef PTR64 |
| 63 | | UINT64 handle; // handle to the monitor |
| 64 | | #else |
| 65 | | UINT32 handle; // handle to the monitor |
| 66 | | #endif |
| 67 | | int monitor_width; |
| 68 | | int monitor_height; |
| 69 | | char monitor_device[64]; |
| 70 | | float aspect; // computed/configured aspect ratio of the physical device |
| 71 | | int center_width; // width of first physical screen for centering |
| 72 | | int center_height; // height of first physical screen for centering |
| 73 | | int monitor_x; // X position of this monitor in virtual desktop space (SDL virtual space has them all horizontally stacked, not real geometry) |
| 65 | |
| 66 | const UINT64 handle() { return m_handle; } |
| 67 | const SDL_Rect &position_size() { refresh(); return m_dimensions; } |
| 68 | |
| 69 | const char *device() { return m_monitor_device; } |
| 70 | |
| 71 | float aspect(); |
| 72 | int center_width() { refresh(); return m_center_width; } |
| 73 | int center_height() { refresh(); return m_center_height; } |
| 74 | |
| 75 | void set_aspect(const float aspect) { m_aspect = aspect; } |
| 76 | |
| 77 | // STATIC |
| 78 | static void init(); |
| 79 | static void exit(); |
| 80 | static sdl_monitor_info *pick_monitor(sdl_options &options, int index); |
| 81 | |
| 82 | private: |
| 83 | void refresh(); |
| 84 | |
| 85 | UINT64 m_handle; // handle to the monitor |
| 86 | SDL_Rect m_dimensions; |
| 87 | char m_monitor_device[64]; |
| 88 | float m_aspect; // computed/configured aspect ratio of the physical device |
| 89 | int m_center_width; // width of first physical screen for centering |
| 90 | int m_center_height; // height of first physical screen for centering |
| 91 | |
| 92 | // STATIC |
| 93 | static sdl_monitor_info *primary_monitor; |
| 94 | static sdl_monitor_info *list; |
| 95 | |
| 74 | 96 | }; |
| 75 | 97 | |
| 76 | 98 | |
| r243237 | r243238 | |
| 137 | 159 | |
| 138 | 160 | extern sdl_video_config video_config; |
| 139 | 161 | |
| 140 | | //============================================================ |
| 141 | | // PROTOTYPES |
| 142 | | //============================================================ |
| 143 | | |
| 144 | | void sdlvideo_monitor_refresh(sdl_monitor_info *monitor); |
| 145 | | float sdlvideo_monitor_get_aspect(sdl_monitor_info *monitor); |
| 146 | | sdl_monitor_info *sdlvideo_monitor_from_handle(UINT32 monitor); //FIXME: Remove? not referenced |
| 147 | | |
| 148 | 162 | #endif |
trunk/src/osd/sdl/window.c
| r243237 | r243238 | |
| 407 | 407 | if (video_config.keepaspect) |
| 408 | 408 | { |
| 409 | 409 | // make sure the monitor is up-to-date |
| 410 | | sdlvideo_monitor_refresh(m_monitor); |
| 411 | | target->compute_visible_area(target_width, target_height, sdlvideo_monitor_get_aspect(m_monitor), target->orientation(), target_width, target_height); |
| 410 | target->compute_visible_area(target_width, target_height, m_monitor->aspect(), target->orientation(), target_width, target_height); |
| 412 | 411 | desired_aspect = (float)target_width / (float)target_height; |
| 413 | 412 | } |
| 414 | 413 | |
| r243237 | r243238 | |
| 849 | 848 | minimum_height -= 4; |
| 850 | 849 | } |
| 851 | 850 | |
| 852 | | num = SDL_GetNumDisplayModes(m_monitor->handle); |
| 851 | num = SDL_GetNumDisplayModes(m_monitor->handle()); |
| 853 | 852 | |
| 854 | 853 | if (num == 0) |
| 855 | 854 | { |
| r243237 | r243238 | |
| 861 | 860 | for (i = 0; i < num; ++i) |
| 862 | 861 | { |
| 863 | 862 | SDL_DisplayMode mode; |
| 864 | | SDL_GetDisplayMode(m_monitor->handle, i, &mode); |
| 863 | SDL_GetDisplayMode(m_monitor->handle(), i, &mode); |
| 865 | 864 | |
| 866 | 865 | // compute initial score based on difference between target and current |
| 867 | 866 | size_score = 1.0f / (1.0f + fabsf((INT32)mode.w - target_width) + fabsf((INT32)mode.h - target_height)); |
| r243237 | r243238 | |
| 1024 | 1023 | } |
| 1025 | 1024 | else |
| 1026 | 1025 | { |
| 1027 | | blit_surface_size(monitor()->center_width, monitor()->center_height); |
| 1026 | blit_surface_size(monitor()->center_width(), monitor()->center_height()); |
| 1028 | 1027 | } |
| 1029 | 1028 | |
| 1030 | 1029 | // ensure the target bounds are up-to-date, and then get the primitives |
| r243237 | r243238 | |
| 1083 | 1082 | if (window->fullscreen()) |
| 1084 | 1083 | { |
| 1085 | 1084 | // default to the current mode exactly |
| 1086 | | tempwidth = window->monitor()->monitor_width; |
| 1087 | | tempheight = window->monitor()->monitor_height; |
| 1085 | tempwidth = window->monitor()->position_size().w; |
| 1086 | tempheight = window->monitor()->position_size().h; |
| 1088 | 1087 | |
| 1089 | 1088 | // if we're allowed to switch resolutions, override with something better |
| 1090 | 1089 | if (video_config.switchres) |
| r243237 | r243238 | |
| 1225 | 1224 | INT32 viswidth, visheight; |
| 1226 | 1225 | float pixel_aspect; |
| 1227 | 1226 | |
| 1228 | | // make sure the monitor is up-to-date |
| 1229 | | sdlvideo_monitor_refresh(m_monitor); |
| 1230 | | |
| 1231 | 1227 | // get the pixel aspect ratio for the target monitor |
| 1232 | | pixel_aspect = sdlvideo_monitor_get_aspect(m_monitor); |
| 1228 | pixel_aspect = m_monitor->aspect(); |
| 1233 | 1229 | |
| 1234 | 1230 | // determine the proposed width/height |
| 1235 | 1231 | propwidth = *window_width - extrawidth; |
| r243237 | r243238 | |
| 1268 | 1264 | // clamp against the maximum (fit on one screen for full screen mode) |
| 1269 | 1265 | if (this->m_fullscreen) |
| 1270 | 1266 | { |
| 1271 | | maxwidth = m_monitor->center_width - extrawidth; |
| 1272 | | maxheight = m_monitor->center_height - extraheight; |
| 1267 | maxwidth = m_monitor->center_width() - extrawidth; |
| 1268 | maxheight = m_monitor->center_height() - extraheight; |
| 1273 | 1269 | } |
| 1274 | 1270 | else |
| 1275 | 1271 | { |
| 1276 | | maxwidth = m_monitor->center_width - extrawidth; |
| 1277 | | maxheight = m_monitor->center_height - extraheight; |
| 1272 | maxwidth = m_monitor->center_width() - extrawidth; |
| 1273 | maxheight = m_monitor->center_height() - extraheight; |
| 1278 | 1274 | |
| 1279 | 1275 | // further clamp to the maximum width/height in the window |
| 1280 | 1276 | if (this->m_maxwidth != 0) |
| r243237 | r243238 | |
| 1355 | 1351 | INT32 maxwidth, maxheight; |
| 1356 | 1352 | |
| 1357 | 1353 | // compute the maximum client area |
| 1358 | | maxwidth = m_monitor->center_width; |
| 1359 | | maxheight = m_monitor->center_height; |
| 1354 | maxwidth = m_monitor->center_width(); |
| 1355 | maxheight = m_monitor->center_height(); |
| 1360 | 1356 | |
| 1361 | 1357 | // clamp to the window's max |
| 1362 | 1358 | if (this->m_maxwidth != 0) |