trunk/src/osd/sdl/window.h
| r243485 | r243486 | |
| 32 | 32 | // TYPE DEFINITIONS |
| 33 | 33 | //============================================================ |
| 34 | 34 | |
| 35 | | class sdl_window_info; |
| 35 | class osd_window |
| 36 | { |
| 37 | public: |
| 38 | osd_window() |
| 39 | : m_primlist(NULL), |
| 40 | m_start_viewscreen(0) |
| 41 | {} |
| 42 | virtual ~osd_window() { } |
| 43 | #ifdef OSD_SDL |
| 44 | virtual void blit_surface_size(int &blitwidth, int &blitheight) = 0; |
| 45 | virtual sdl_monitor_info *monitor() const = 0; |
| 46 | virtual render_target *target() = 0; |
| 47 | virtual void get_size(int &w, int &h) = 0; |
| 48 | virtual int fullscreen() const = 0; |
| 49 | virtual int index() const = 0; |
| 50 | virtual int prescale() const = 0; |
| 51 | #if (SDLMAME_SDL2) |
| 52 | virtual SDL_Window *sdl_window() = 0; |
| 53 | #else |
| 54 | virtual SDL_Surface *sdl_surface() = 0; |
| 55 | #endif |
| 36 | 56 | |
| 57 | virtual running_machine &machine() const = 0; |
| 58 | |
| 59 | render_primitive_list *m_primlist; |
| 60 | int m_start_viewscreen; |
| 61 | |
| 62 | #endif |
| 63 | }; |
| 64 | |
| 37 | 65 | class osd_renderer |
| 38 | 66 | { |
| 39 | 67 | public: |
| r243485 | r243486 | |
| 48 | 76 | static const int FLAG_NEEDS_ASYNCBLIT = 0x0200; |
| 49 | 77 | #endif |
| 50 | 78 | |
| 51 | | osd_renderer(sdl_window_info *window, const int flags) |
| 79 | osd_renderer(osd_window *window, const int flags) |
| 52 | 80 | : m_window(window), m_flags(flags) { } |
| 53 | 81 | |
| 54 | 82 | virtual ~osd_renderer() { } |
| 55 | 83 | |
| 56 | | sdl_window_info &window() { return *m_window; } |
| 84 | osd_window &window() { return *m_window; } |
| 57 | 85 | int flags() const { return m_flags; } |
| 58 | 86 | bool has_flags(const int flag) { return ((m_flags & flag)) == flag; } |
| 59 | 87 | |
| r243485 | r243486 | |
| 62 | 90 | /* Interface to be implemented by render code */ |
| 63 | 91 | |
| 64 | 92 | virtual int create() = 0; |
| 93 | virtual render_primitive_list *get_primitives() = 0; |
| 94 | |
| 95 | #ifdef OSD_SDL |
| 65 | 96 | virtual int draw(const UINT32 dc, const int update) = 0; |
| 66 | | virtual render_primitive_list *get_primitives() = 0; |
| 67 | 97 | virtual int xy_to_render_target(const int x, const int y, int *xt, int *yt) = 0; |
| 98 | #else |
| 99 | virtual int draw(HDC dc, int update) = 0; |
| 100 | virtual void save() = 0; |
| 101 | virtual void record() = 0; |
| 102 | virtual void toggle_fsfx() = 0; |
| 103 | #endif |
| 104 | |
| 68 | 105 | virtual void destroy() = 0; |
| 69 | 106 | |
| 70 | 107 | protected: |
| r243485 | r243486 | |
| 76 | 113 | |
| 77 | 114 | private: |
| 78 | 115 | |
| 79 | | sdl_window_info *m_window; |
| 116 | osd_window *m_window; |
| 80 | 117 | int m_flags; |
| 81 | 118 | }; |
| 82 | 119 | |
| 83 | 120 | #define OSDWORK_CALLBACK(name) void *name(void *param, ATTR_UNUSED int threadid) |
| 84 | 121 | |
| 85 | | class sdl_window_info |
| 122 | class sdl_window_info : public osd_window |
| 86 | 123 | { |
| 87 | 124 | public: |
| 88 | 125 | sdl_window_info(running_machine &a_machine, int index, sdl_monitor_info *a_monitor, |
| 89 | 126 | const sdl_window_config *config) |
| 90 | | : m_next(NULL), m_primlist(NULL), |
| 91 | | m_start_viewscreen(0), |
| 127 | : osd_window(), m_next(NULL), |
| 92 | 128 | // Following three are used by input code to defer resizes |
| 93 | 129 | #if (SDLMAME_SDL2) |
| 94 | 130 | m_resize_width(0), |
| r243485 | r243486 | |
| 164 | 200 | // Pointer to next window |
| 165 | 201 | sdl_window_info * m_next; |
| 166 | 202 | |
| 167 | | // FIXME: renderer should deal with this |
| 168 | | render_primitive_list *m_primlist; |
| 169 | | int m_start_viewscreen; |
| 170 | 203 | #if (SDLMAME_SDL2) |
| 171 | 204 | // These are used in combine resizing events ... #if SDL13_COMBINE_RESIZE |
| 172 | 205 | int m_resize_width; |
trunk/src/osd/windows/drawd3d.c
| r243485 | r243486 | |
| 184 | 184 | // drawd3d_window_init |
| 185 | 185 | //============================================================ |
| 186 | 186 | |
| 187 | | int d3d::renderer::init() |
| 187 | int d3d::renderer::create() |
| 188 | 188 | { |
| 189 | 189 | if (!initialize()) |
| 190 | 190 | { |
| r243485 | r243486 | |
| 244 | 244 | { |
| 245 | 245 | RECT client; |
| 246 | 246 | |
| 247 | | GetClientRectExceptMenu(window().m_hwnd, &client, window().m_fullscreen); |
| 247 | GetClientRectExceptMenu(window().m_hwnd, &client, window().fullscreen()); |
| 248 | 248 | if (rect_width(&client) > 0 && rect_height(&client) > 0) |
| 249 | 249 | { |
| 250 | | window().m_target->set_bounds(rect_width(&client), rect_height(&client), window().m_monitor->get_aspect()); |
| 251 | | window().m_target->set_max_update_rate((get_refresh() == 0) ? get_origmode().RefreshRate : get_refresh()); |
| 250 | window().target()->set_bounds(rect_width(&client), rect_height(&client), window().m_monitor->get_aspect()); |
| 251 | window().target()->set_max_update_rate((get_refresh() == 0) ? get_origmode().RefreshRate : get_refresh()); |
| 252 | 252 | } |
| 253 | | return &window().m_target->get_primitives(); |
| 253 | return &window().target()->get_primitives(); |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | //============================================================ |
| r243485 | r243486 | |
| 468 | 468 | osd_printf_verbose("Direct3D: YUV format = %s\n", (m_yuv_format == D3DFMT_YUY2) ? "YUY2" : (m_yuv_format == D3DFMT_UYVY) ? "UYVY" : "RGB"); |
| 469 | 469 | |
| 470 | 470 | // set the max texture size |
| 471 | | d3d->window().m_target->set_max_texture_size(m_texture_max_width, m_texture_max_height); |
| 471 | d3d->window().target()->set_max_texture_size(m_texture_max_width, m_texture_max_height); |
| 472 | 472 | osd_printf_verbose("Direct3D: Max texture size = %dx%d\n", (int)m_texture_max_width, (int)m_texture_max_height); |
| 473 | 473 | } |
| 474 | 474 | |
| r243485 | r243486 | |
| 644 | 644 | return false; |
| 645 | 645 | |
| 646 | 646 | // create the device immediately for the full screen case (defer for window mode) |
| 647 | | if (window().m_fullscreen && device_create()) |
| 647 | if (window().fullscreen() && device_create()) |
| 648 | 648 | return false; |
| 649 | 649 | |
| 650 | 650 | return true; |
| r243485 | r243486 | |
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | // in window mode, we need to track the window size |
| 681 | | if (!window().m_fullscreen || m_device == NULL) |
| 681 | if (!window().fullscreen() || m_device == NULL) |
| 682 | 682 | { |
| 683 | 683 | // if the size changes, skip this update since the render target will be out of date |
| 684 | 684 | if (update_window_size()) |
| r243485 | r243486 | |
| 866 | 866 | m_presentation.MultiSampleType = D3DMULTISAMPLE_NONE; |
| 867 | 867 | m_presentation.SwapEffect = D3DSWAPEFFECT_DISCARD; |
| 868 | 868 | m_presentation.hDeviceWindow = window().m_hwnd; |
| 869 | | m_presentation.Windowed = !window().m_fullscreen || win_has_menu(&window()); |
| 869 | m_presentation.Windowed = !window().fullscreen() || window().win_has_menu(); |
| 870 | 870 | m_presentation.EnableAutoDepthStencil = FALSE; |
| 871 | 871 | m_presentation.AutoDepthStencilFormat = D3DFMT_D16; |
| 872 | 872 | m_presentation.Flags = 0; |
| 873 | 873 | m_presentation.FullScreen_RefreshRateInHz = m_refresh; |
| 874 | | m_presentation.PresentationInterval = ((video_config.triplebuf && window().m_fullscreen) || |
| 874 | m_presentation.PresentationInterval = ((video_config.triplebuf && window().fullscreen()) || |
| 875 | 875 | video_config.waitvsync || video_config.syncrefresh) ? |
| 876 | 876 | D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; |
| 877 | 877 | |
| r243485 | r243486 | |
| 899 | 899 | osd_printf_verbose("Direct3D: Device created at %dx%d\n", m_width, m_height); |
| 900 | 900 | |
| 901 | 901 | // set the gamma if we need to |
| 902 | | if (window().m_fullscreen) |
| 902 | if (window().fullscreen()) |
| 903 | 903 | { |
| 904 | 904 | // only set the gamma if it's not 1.0f |
| 905 | 905 | windows_options &options = downcast<windows_options &>(window().machine().options()); |
| r243485 | r243486 | |
| 1064 | 1064 | int retval = 0; |
| 1065 | 1065 | |
| 1066 | 1066 | m_shaders = global_alloc_clear(shaders); |
| 1067 | | m_shaders->init(d3dintf, &window()); |
| 1067 | // FIXME: Dynamic cast |
| 1068 | m_shaders->init(d3dintf, dynamic_cast<win_window_info *>(&window())); |
| 1068 | 1069 | |
| 1069 | 1070 | DWORD tempcaps; |
| 1070 | 1071 | HRESULT result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_MAX_PS30_INSN_SLOTS, &tempcaps); |
| r243485 | r243486 | |
| 1203 | 1204 | } |
| 1204 | 1205 | |
| 1205 | 1206 | // choose a resolution: window mode case |
| 1206 | | if (!window().m_fullscreen || !video_config.switchres || win_has_menu(&window())) |
| 1207 | if (!window().fullscreen() || !video_config.switchres || window().win_has_menu()) |
| 1207 | 1208 | { |
| 1208 | 1209 | RECT client; |
| 1209 | 1210 | |
| 1210 | 1211 | // bounds are from the window client rect |
| 1211 | | GetClientRectExceptMenu(window().m_hwnd, &client, window().m_fullscreen); |
| 1212 | GetClientRectExceptMenu(window().m_hwnd, &client, window().fullscreen()); |
| 1212 | 1213 | m_width = client.right - client.left; |
| 1213 | 1214 | m_height = client.bottom - client.top; |
| 1214 | 1215 | |
| r243485 | r243486 | |
| 1244 | 1245 | } |
| 1245 | 1246 | |
| 1246 | 1247 | // see if we can handle the device type |
| 1247 | | result = (*d3dintf->d3d.check_device_type)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_pixformat, !window().m_fullscreen); |
| 1248 | result = (*d3dintf->d3d.check_device_type)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_pixformat, !window().fullscreen()); |
| 1248 | 1249 | if (result != D3D_OK) |
| 1249 | 1250 | { |
| 1250 | 1251 | char *utf8_device = utf8_from_tstring(window().m_monitor->info.szDevice); |
| r243485 | r243486 | |
| 1308 | 1309 | // note: technically we should not be calling this from an alternate window |
| 1309 | 1310 | // thread; however, it is only done during init time, and the init code on |
| 1310 | 1311 | // the main thread is waiting for us to finish, so it is safe to do so here |
| 1311 | | window().m_target->compute_minimum_size(minwidth, minheight); |
| 1312 | window().target()->compute_minimum_size(minwidth, minheight); |
| 1312 | 1313 | |
| 1313 | 1314 | // use those as the target for now |
| 1314 | 1315 | INT32 target_width = minwidth; |
| r243485 | r243486 | |
| 1384 | 1385 | { |
| 1385 | 1386 | // get the current window bounds |
| 1386 | 1387 | RECT client; |
| 1387 | | GetClientRectExceptMenu(window().m_hwnd, &client, window().m_fullscreen); |
| 1388 | GetClientRectExceptMenu(window().m_hwnd, &client, window().fullscreen()); |
| 1388 | 1389 | |
| 1389 | 1390 | // if we have a device and matching width/height, nothing to do |
| 1390 | 1391 | if (m_device != NULL && rect_width(&client) == m_width && rect_height(&client) == m_height) |
trunk/src/osd/windows/drawdd.c
| r243485 | r243486 | |
| 63 | 63 | |
| 64 | 64 | virtual ~renderer_dd() { } |
| 65 | 65 | |
| 66 | | virtual int init(); |
| 66 | virtual int create(); |
| 67 | 67 | virtual render_primitive_list *get_primitives(); |
| 68 | 68 | virtual int draw(HDC dc, int update); |
| 69 | 69 | virtual void save() {}; |
| r243485 | r243486 | |
| 258 | 258 | // drawdd_window_init |
| 259 | 259 | //============================================================ |
| 260 | 260 | |
| 261 | | int renderer_dd::init() |
| 261 | int renderer_dd::create() |
| 262 | 262 | { |
| 263 | 263 | // configure the adapter for the mode we want |
| 264 | 264 | if (config_adapter_mode()) |
| r243485 | r243486 | |
| 297 | 297 | render_primitive_list *renderer_dd::get_primitives() |
| 298 | 298 | { |
| 299 | 299 | compute_blit_surface_size(); |
| 300 | | window().m_target->set_bounds(blitwidth, blitheight, 0); |
| 301 | | window().m_target->set_max_update_rate((refresh == 0) ? origmode.dwRefreshRate : refresh); |
| 300 | window().target()->set_bounds(blitwidth, blitheight, 0); |
| 301 | window().target()->set_max_update_rate((refresh == 0) ? origmode.dwRefreshRate : refresh); |
| 302 | 302 | |
| 303 | | return &window().m_target->get_primitives(); |
| 303 | return &window().target()->get_primitives(); |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | |
| r243485 | r243486 | |
| 417 | 417 | if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X unlocking blit surface\n", (int)result); |
| 418 | 418 | |
| 419 | 419 | // sync to VBLANK |
| 420 | | if ((video_config.waitvsync || video_config.syncrefresh) && window().machine().video().throttled() && (!window().m_fullscreen || back == NULL)) |
| 420 | if ((video_config.waitvsync || video_config.syncrefresh) && window().machine().video().throttled() && (!window().fullscreen() || back == NULL)) |
| 421 | 421 | { |
| 422 | 422 | result = IDirectDraw7_WaitForVerticalBlank(ddraw, DDWAITVB_BLOCKBEGIN, NULL); |
| 423 | 423 | if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X waiting for VBLANK\n", (int)result); |
| r243485 | r243486 | |
| 469 | 469 | osd_printf_verbose("DirectDraw: Error %08X during IDirectDraw7_SetCooperativeLevel(FOCUSWINDOW) call\n", (int)result); |
| 470 | 470 | goto error; |
| 471 | 471 | } |
| 472 | | result = IDirectDraw7_SetCooperativeLevel(ddraw, window().m_hwnd, DDSCL_SETDEVICEWINDOW | (window().m_fullscreen ? DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE : DDSCL_NORMAL)); |
| 472 | result = IDirectDraw7_SetCooperativeLevel(ddraw, window().m_hwnd, DDSCL_SETDEVICEWINDOW | (window().fullscreen() ? DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE : DDSCL_NORMAL)); |
| 473 | 473 | if (result != DD_OK) |
| 474 | 474 | { |
| 475 | 475 | osd_printf_verbose("DirectDraw: Error %08X during IDirectDraw7_SetCooperativeLevel(DEVICEWINDOW) call\n", (int)result); |
| r243485 | r243486 | |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | // full screen mode: set the resolution |
| 480 | | if (window().m_fullscreen && video_config.switchres) |
| 480 | if (window().fullscreen() && video_config.switchres) |
| 481 | 481 | { |
| 482 | 482 | result = IDirectDraw7_SetDisplayMode(ddraw, width, height, 32, refresh, 0); |
| 483 | 483 | if (result != DD_OK) |
| r243485 | r243486 | |
| 511 | 511 | primarydesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; |
| 512 | 512 | |
| 513 | 513 | // for triple-buffered full screen mode, allocate flipping surfaces |
| 514 | | if (window().m_fullscreen && video_config.triplebuf) |
| 514 | if (window().fullscreen() && video_config.triplebuf) |
| 515 | 515 | { |
| 516 | 516 | primarydesc.dwFlags |= DDSD_BACKBUFFERCOUNT; |
| 517 | 517 | primarydesc.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX; |
| r243485 | r243486 | |
| 524 | 524 | |
| 525 | 525 | // full screen mode: get the back surface |
| 526 | 526 | back = NULL; |
| 527 | | if (window().m_fullscreen && video_config.triplebuf) |
| 527 | if (window().fullscreen() && video_config.triplebuf) |
| 528 | 528 | { |
| 529 | 529 | DDSCAPS2 caps = { DDSCAPS_BACKBUFFER }; |
| 530 | 530 | result = IDirectDrawSurface7_GetAttachedSurface(primary, &caps, &back); |
| r243485 | r243486 | |
| 564 | 564 | goto error; |
| 565 | 565 | |
| 566 | 566 | // create a clipper for windowed mode |
| 567 | | if (!window().m_fullscreen && create_clipper()) |
| 567 | if (!window().fullscreen() && create_clipper()) |
| 568 | 568 | goto error; |
| 569 | 569 | |
| 570 | 570 | // full screen mode: set the gamma |
| 571 | | if (window().m_fullscreen) |
| 571 | if (window().fullscreen()) |
| 572 | 572 | { |
| 573 | 573 | // only set the gamma if it's not 1.0f |
| 574 | 574 | windows_options &options = downcast<windows_options &>(window().machine().options()); |
| r243485 | r243486 | |
| 825 | 825 | RECT client; |
| 826 | 826 | |
| 827 | 827 | // start with the minimum size |
| 828 | | window().m_target->compute_minimum_size(newwidth, newheight); |
| 828 | window().target()->compute_minimum_size(newwidth, newheight); |
| 829 | 829 | |
| 830 | 830 | // get the window's client rectangle |
| 831 | 831 | GetClientRect(window().m_hwnd, &client); |
| r243485 | r243486 | |
| 854 | 854 | // compute the appropriate visible area if we're trying to keepaspect |
| 855 | 855 | if (video_config.keepaspect) |
| 856 | 856 | { |
| 857 | | win_monitor_info *monitor = winwindow_video_window_monitor(&window(), NULL); |
| 858 | | window().m_target->compute_visible_area(target_width, target_height, monitor->get_aspect(), window().m_target->orientation(), target_width, target_height); |
| 857 | win_monitor_info *monitor = window().winwindow_video_window_monitor(NULL); |
| 858 | window().target()->compute_visible_area(target_width, target_height, monitor->get_aspect(), window().target()->orientation(), target_width, target_height); |
| 859 | 859 | desired_aspect = (float)target_width / (float)target_height; |
| 860 | 860 | } |
| 861 | 861 | |
| r243485 | r243486 | |
| 920 | 920 | margins->right = desc_width; |
| 921 | 921 | margins->bottom = desc_height; |
| 922 | 922 | |
| 923 | | if (win_has_menu(&window())) |
| 923 | if (window().win_has_menu()) |
| 924 | 924 | { |
| 925 | 925 | static int height_with_menubar = 0; |
| 926 | 926 | if (height_with_menubar == 0) |
| r243485 | r243486 | |
| 944 | 944 | void renderer_dd::blit_to_primary(int srcwidth, int srcheight) |
| 945 | 945 | { |
| 946 | 946 | IDirectDrawSurface7 *target = (back != NULL) ? back : primary; |
| 947 | | win_monitor_info *monitor = winwindow_video_window_monitor(&window(), NULL); |
| 947 | win_monitor_info *monitor = window().winwindow_video_window_monitor(NULL); |
| 948 | 948 | DDBLTFX blitfx = { sizeof(DDBLTFX) }; |
| 949 | 949 | RECT clear, outer, dest, source; |
| 950 | 950 | INT32 dstwidth, dstheight; |
| r243485 | r243486 | |
| 956 | 956 | source.bottom = srcheight; |
| 957 | 957 | |
| 958 | 958 | // compute outer rect -- windowed version |
| 959 | | if (!window().m_fullscreen) |
| 959 | if (!window().fullscreen()) |
| 960 | 960 | { |
| 961 | 961 | GetClientRect(window().m_hwnd, &outer); |
| 962 | 962 | ClientToScreen(window().m_hwnd, &((LPPOINT)&outer)[0]); |
| r243485 | r243486 | |
| 999 | 999 | else if (video_config.keepaspect) |
| 1000 | 1000 | { |
| 1001 | 1001 | // compute the appropriate visible area |
| 1002 | | window().m_target->compute_visible_area(rect_width(&outer), rect_height(&outer), monitor->get_aspect(), window().m_target->orientation(), dstwidth, dstheight); |
| 1002 | window().target()->compute_visible_area(rect_width(&outer), rect_height(&outer), monitor->get_aspect(), window().target()->orientation(), dstwidth, dstheight); |
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | // center within |
| r243485 | r243486 | |
| 1062 | 1062 | if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X blitting to the screen\n", (int)result); |
| 1063 | 1063 | |
| 1064 | 1064 | // page flip if triple buffered |
| 1065 | | if (window().m_fullscreen && back != NULL) |
| 1065 | if (window().fullscreen() && back != NULL) |
| 1066 | 1066 | { |
| 1067 | 1067 | result = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT); |
| 1068 | 1068 | if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X waiting for VBLANK\n", (int)result); |
| r243485 | r243486 | |
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | 1114 | // choose a resolution: full screen mode case |
| 1115 | | if (window().m_fullscreen) |
| 1115 | if (window().fullscreen()) |
| 1116 | 1116 | { |
| 1117 | 1117 | // default to the current mode exactly |
| 1118 | 1118 | width = origmode.dwWidth; |
| r243485 | r243486 | |
| 1129 | 1129 | ddraw = NULL; |
| 1130 | 1130 | |
| 1131 | 1131 | // if we're not changing resolutions, make sure we have a resolution we can handle |
| 1132 | | if (!window().m_fullscreen || !video_config.switchres) |
| 1132 | if (!window().fullscreen() || !video_config.switchres) |
| 1133 | 1133 | { |
| 1134 | 1134 | switch (origmode.ddpfPixelFormat.dwRBitMask) |
| 1135 | 1135 | { |
| r243485 | r243486 | |
| 1268 | 1268 | // note: technically we should not be calling this from an alternate window |
| 1269 | 1269 | // thread; however, it is only done during init time, and the init code on |
| 1270 | 1270 | // the main thread is waiting for us to finish, so it is safe to do so here |
| 1271 | | window().m_target->compute_minimum_size(einfo.minimum_width, einfo.minimum_height); |
| 1271 | window().target()->compute_minimum_size(einfo.minimum_width, einfo.minimum_height); |
| 1272 | 1272 | |
| 1273 | 1273 | // use those as the target for now |
| 1274 | 1274 | einfo.target_width = einfo.minimum_width * MAX(1, video_config.prescale); |
| r243485 | r243486 | |
| 1296 | 1296 | } |
| 1297 | 1297 | |
| 1298 | 1298 | // fill in the rest of the data |
| 1299 | | einfo.window = &window(); |
| 1299 | einfo.window = dynamic_cast<win_window_info *>(&window()); |
| 1300 | 1300 | einfo.best_score = 0.0f; |
| 1301 | 1301 | |
| 1302 | 1302 | // enumerate the modes |
trunk/src/osd/windows/window.c
| r243485 | r243486 | |
| 299 | 299 | win_window_info::win_window_info(running_machine &machine) |
| 300 | 300 | : m_next(NULL), |
| 301 | 301 | m_init_state(0), |
| 302 | | m_hwnd(0), |
| 303 | | m_focus_hwnd(0), |
| 304 | 302 | m_startmaximized(0), |
| 305 | 303 | m_isminimized(0), |
| 306 | 304 | m_ismaximized(0), |
| 307 | | m_resize_state(0), |
| 308 | | m_monitor(0), |
| 309 | 305 | m_fullscreen(0), |
| 310 | 306 | m_fullscreen_safe(0), |
| 311 | | m_maxwidth(0), |
| 312 | | m_maxheight(0), |
| 313 | | m_refresh(0), |
| 314 | 307 | m_aspect(0), |
| 315 | 308 | m_render_lock(NULL), |
| 316 | 309 | m_target(NULL), |
| 317 | 310 | m_targetview(0), |
| 318 | 311 | m_targetorient(0), |
| 319 | | m_primlist(NULL), |
| 320 | 312 | m_lastclicktime(0), |
| 321 | 313 | m_lastclickx(0), |
| 322 | 314 | m_lastclicky(0), |
| r243485 | r243486 | |
| 620 | 612 | // 2. we also hide the cursor in full screen mode and when the window doesn't have a menu |
| 621 | 613 | // 3. we also hide the cursor in windowed mode if we're not paused and |
| 622 | 614 | // the input system requests it |
| 623 | | if (winwindow_has_focus() && ((!video_config.windowed && !win_has_menu(win_window_list)) || (!machine.paused() && wininput_should_hide_mouse()))) |
| 615 | if (winwindow_has_focus() && ((!video_config.windowed && !win_window_list->win_has_menu()) || (!machine.paused() && wininput_should_hide_mouse()))) |
| 624 | 616 | { |
| 625 | 617 | win_window_info *window = win_window_list; |
| 626 | 618 | RECT bounds; |
| r243485 | r243486 | |
| 849 | 841 | // (window thread) |
| 850 | 842 | //============================================================ |
| 851 | 843 | |
| 852 | | win_monitor_info *winwindow_video_window_monitor(win_window_info *window, const RECT *proposed) |
| 844 | win_monitor_info *win_window_info::winwindow_video_window_monitor(const RECT *proposed) |
| 853 | 845 | { |
| 854 | 846 | win_monitor_info *monitor; |
| 855 | 847 | |
| 856 | 848 | // in window mode, find the nearest |
| 857 | | if (!window->m_fullscreen) |
| 849 | if (!m_fullscreen) |
| 858 | 850 | { |
| 859 | 851 | if (proposed != NULL) |
| 860 | 852 | monitor = winvideo_monitor_from_handle(MonitorFromRect(proposed, MONITOR_DEFAULTTONEAREST)); |
| 861 | 853 | else |
| 862 | | monitor = winvideo_monitor_from_handle(MonitorFromWindow(window->m_hwnd, MONITOR_DEFAULTTONEAREST)); |
| 854 | monitor = winvideo_monitor_from_handle(MonitorFromWindow(m_hwnd, MONITOR_DEFAULTTONEAREST)); |
| 863 | 855 | } |
| 864 | 856 | |
| 865 | 857 | // in full screen, just use the configured monitor |
| 866 | 858 | else |
| 867 | | monitor = window->m_monitor; |
| 859 | monitor = m_monitor; |
| 868 | 860 | |
| 869 | 861 | // make sure we're up-to-date |
| 870 | 862 | monitor->refresh(); |
| r243485 | r243486 | |
| 1046 | 1038 | RECT temprect = { 100, 100, 200, 200 }; |
| 1047 | 1039 | if (window->m_fullscreen) |
| 1048 | 1040 | return 0; |
| 1049 | | AdjustWindowRectEx(&temprect, WINDOW_STYLE, win_has_menu(window), WINDOW_STYLE_EX); |
| 1041 | AdjustWindowRectEx(&temprect, WINDOW_STYLE, window->win_has_menu(), WINDOW_STYLE_EX); |
| 1050 | 1042 | return rect_width(&temprect) - 100; |
| 1051 | 1043 | } |
| 1052 | 1044 | |
| r243485 | r243486 | |
| 1062 | 1054 | RECT temprect = { 100, 100, 200, 200 }; |
| 1063 | 1055 | if (window->m_fullscreen) |
| 1064 | 1056 | return 0; |
| 1065 | | AdjustWindowRectEx(&temprect, WINDOW_STYLE, win_has_menu(window), WINDOW_STYLE_EX); |
| 1057 | AdjustWindowRectEx(&temprect, WINDOW_STYLE, window->win_has_menu(), WINDOW_STYLE_EX); |
| 1066 | 1058 | return rect_height(&temprect) - 100; |
| 1067 | 1059 | } |
| 1068 | 1060 | |
| r243485 | r243486 | |
| 1233 | 1225 | { |
| 1234 | 1226 | // finish off by trying to initialize DirectX; if we fail, ignore it |
| 1235 | 1227 | window->m_renderer = draw.create(window); |
| 1236 | | if (window->m_renderer->init()) |
| 1228 | if (window->m_renderer->create()) |
| 1237 | 1229 | return 1; |
| 1238 | 1230 | ShowWindow(window->m_hwnd, SW_SHOW); |
| 1239 | 1231 | } |
| r243485 | r243486 | |
| 1274 | 1266 | PAINTSTRUCT pstruct; |
| 1275 | 1267 | HDC hdc = BeginPaint(wnd, &pstruct); |
| 1276 | 1268 | draw_video_contents(window, hdc, TRUE); |
| 1277 | | if (win_has_menu(window)) |
| 1269 | if (window->win_has_menu()) |
| 1278 | 1270 | DrawMenuBar(window->m_hwnd); |
| 1279 | 1271 | EndPaint(wnd, &pstruct); |
| 1280 | 1272 | break; |
| r243485 | r243486 | |
| 1282 | 1274 | |
| 1283 | 1275 | // non-client paint: punt if full screen |
| 1284 | 1276 | case WM_NCPAINT: |
| 1285 | | if (!window->m_fullscreen || win_has_menu(window)) |
| 1277 | if (!window->m_fullscreen || window->win_has_menu()) |
| 1286 | 1278 | return DefWindowProc(wnd, message, wparam, lparam); |
| 1287 | 1279 | break; |
| 1288 | 1280 | |
| r243485 | r243486 | |
| 1515 | 1507 | |
| 1516 | 1508 | static void constrain_to_aspect_ratio(win_window_info *window, RECT *rect, int adjustment) |
| 1517 | 1509 | { |
| 1518 | | win_monitor_info *monitor = winwindow_video_window_monitor(window, rect); |
| 1510 | win_monitor_info *monitor = window->winwindow_video_window_monitor(rect); |
| 1519 | 1511 | INT32 extrawidth = wnd_extra_width(window); |
| 1520 | 1512 | INT32 extraheight = wnd_extra_height(window); |
| 1521 | 1513 | INT32 propwidth, propheight; |
| r243485 | r243486 | |
| 1828 | 1820 | // in full screen, make sure it covers the primary display |
| 1829 | 1821 | else |
| 1830 | 1822 | { |
| 1831 | | win_monitor_info *monitor = winwindow_video_window_monitor(window, NULL); |
| 1823 | win_monitor_info *monitor = window->winwindow_video_window_monitor(NULL); |
| 1832 | 1824 | newrect = monitor->info.rcMonitor; |
| 1833 | 1825 | } |
| 1834 | 1826 | |
| r243485 | r243486 | |
| 1849 | 1841 | } |
| 1850 | 1842 | |
| 1851 | 1843 | |
| 1852 | | |
| 1853 | 1844 | //============================================================ |
| 1854 | 1845 | // set_fullscreen |
| 1855 | 1846 | // (window thread) |
| r243485 | r243486 | |
| 1924 | 1915 | if (video_config.mode != VIDEO_MODE_NONE) |
| 1925 | 1916 | ShowWindow(window->m_hwnd, SW_SHOW); |
| 1926 | 1917 | window->m_renderer = draw.create(window); |
| 1927 | | if (window->m_renderer->init()) |
| 1918 | if (window->m_renderer->create()) |
| 1928 | 1919 | exit(1); |
| 1929 | 1920 | } |
| 1930 | 1921 | |
trunk/src/osd/windows/window.h
| r243485 | r243486 | |
| 34 | 34 | |
| 35 | 35 | class win_window_info; |
| 36 | 36 | |
| 37 | class osd_window |
| 38 | { |
| 39 | public: |
| 40 | osd_window() |
| 41 | : |
| 42 | #ifdef OSD_SDL |
| 43 | m_start_viewscreen(0), |
| 44 | #else |
| 45 | m_hwnd(0), m_focus_hwnd(0), m_monitor(NULL), m_resize_state(0), |
| 46 | m_maxwidth(0), m_maxheight(0), |
| 47 | m_refresh(0), |
| 48 | #endif |
| 49 | m_primlist(NULL) |
| 50 | {} |
| 51 | virtual ~osd_window() { } |
| 52 | |
| 53 | virtual render_target *target() = 0; |
| 54 | virtual int fullscreen() const = 0; |
| 55 | virtual running_machine &machine() const = 0; |
| 56 | |
| 57 | #ifdef OSD_SDL |
| 58 | virtual void blit_surface_size(int &blitwidth, int &blitheight) = 0; |
| 59 | virtual sdl_monitor_info *monitor() const = 0; |
| 60 | virtual void get_size(int &w, int &h) = 0; |
| 61 | virtual int index() const = 0; |
| 62 | virtual int prescale() const = 0; |
| 63 | #if (SDLMAME_SDL2) |
| 64 | virtual SDL_Window *sdl_window() = 0; |
| 65 | #else |
| 66 | virtual SDL_Surface *sdl_surface() = 0; |
| 67 | #endif |
| 68 | |
| 69 | int m_start_viewscreen; |
| 70 | |
| 71 | #else |
| 72 | virtual bool win_has_menu() = 0; |
| 73 | virtual win_monitor_info *winwindow_video_window_monitor(const RECT *proposed) = 0; |
| 74 | |
| 75 | // window handle and info |
| 76 | HWND m_hwnd; |
| 77 | HWND m_focus_hwnd; |
| 78 | |
| 79 | // monitor info |
| 80 | win_monitor_info * m_monitor; |
| 81 | int m_resize_state; |
| 82 | int m_maxwidth, m_maxheight; |
| 83 | int m_refresh; |
| 84 | #endif |
| 85 | |
| 86 | render_primitive_list * m_primlist; |
| 87 | |
| 88 | }; |
| 89 | |
| 37 | 90 | class osd_renderer |
| 38 | 91 | { |
| 39 | 92 | public: |
| r243485 | r243486 | |
| 46 | 99 | static const int FLAG_NEEDS_DOUBLEBUF = 0x0100; |
| 47 | 100 | static const int FLAG_NEEDS_ASYNCBLIT = 0x0200; |
| 48 | 101 | |
| 49 | | osd_renderer(win_window_info *window, const int flags) |
| 102 | osd_renderer(osd_window *window, const int flags) |
| 50 | 103 | : m_window(window), m_flags(flags) { } |
| 51 | 104 | |
| 52 | 105 | virtual ~osd_renderer() { } |
| 53 | 106 | |
| 54 | | win_window_info &window() { return *m_window; } |
| 107 | osd_window &window() { return *m_window; } |
| 55 | 108 | int flags() const { return m_flags; } |
| 56 | | bool check_flag(const int flag) { return ((m_flags & flag)) == flag; } |
| 109 | bool has_flags(const int flag) { return ((m_flags & flag)) == flag; } |
| 57 | 110 | |
| 58 | | virtual int init() = 0; |
| 111 | void notify_changed() { set_flags(FI_CHANGED); } |
| 112 | |
| 113 | /* Interface to be implemented by render code */ |
| 114 | |
| 115 | virtual int create() = 0; |
| 59 | 116 | virtual render_primitive_list *get_primitives() = 0; |
| 117 | |
| 118 | #ifdef OSD_SDL |
| 119 | virtual int draw(const UINT32 dc, const int update) = 0; |
| 120 | virtual int xy_to_render_target(const int x, const int y, int *xt, int *yt) = 0; |
| 121 | #else |
| 60 | 122 | virtual int draw(HDC dc, int update) = 0; |
| 61 | 123 | virtual void save() = 0; |
| 62 | 124 | virtual void record() = 0; |
| 63 | 125 | virtual void toggle_fsfx() = 0; |
| 126 | #endif |
| 127 | |
| 64 | 128 | virtual void destroy() = 0; |
| 65 | 129 | |
| 130 | protected: |
| 131 | /* Internal flags */ |
| 132 | static const int FI_CHANGED = 0x010000; |
| 133 | |
| 134 | void set_flags(int aflag) { m_flags |= aflag; } |
| 135 | void clear_flags(int aflag) { m_flags &= ~aflag; } |
| 136 | |
| 66 | 137 | private: |
| 67 | | win_window_info *m_window; |
| 138 | |
| 139 | osd_window *m_window; |
| 68 | 140 | int m_flags; |
| 69 | 141 | }; |
| 70 | 142 | |
| 71 | | class win_window_info |
| 143 | class win_window_info : public osd_window |
| 72 | 144 | { |
| 73 | 145 | public: |
| 74 | 146 | win_window_info(running_machine &machine); |
| r243485 | r243486 | |
| 76 | 148 | |
| 77 | 149 | running_machine &machine() const { return m_machine; } |
| 78 | 150 | |
| 151 | render_target *target() { return m_target; } |
| 152 | int fullscreen() const { return m_fullscreen; } |
| 153 | |
| 79 | 154 | void update(); |
| 80 | 155 | |
| 156 | win_monitor_info *winwindow_video_window_monitor(const RECT *proposed); |
| 157 | |
| 158 | bool win_has_menu() |
| 159 | { |
| 160 | return GetMenu(m_hwnd) ? true : false; |
| 161 | } |
| 162 | |
| 81 | 163 | win_window_info * m_next; |
| 82 | 164 | volatile int m_init_state; |
| 83 | 165 | |
| 84 | 166 | // window handle and info |
| 85 | | HWND m_hwnd; |
| 86 | | HWND m_focus_hwnd; |
| 87 | 167 | char m_title[256]; |
| 88 | 168 | RECT m_non_fullscreen_bounds; |
| 89 | 169 | int m_startmaximized; |
| 90 | 170 | int m_isminimized; |
| 91 | 171 | int m_ismaximized; |
| 92 | | int m_resize_state; |
| 93 | 172 | |
| 94 | 173 | // monitor info |
| 95 | | win_monitor_info * m_monitor; |
| 96 | 174 | int m_fullscreen; |
| 97 | 175 | int m_fullscreen_safe; |
| 98 | | int m_maxwidth, m_maxheight; |
| 99 | | int m_refresh; |
| 100 | 176 | float m_aspect; |
| 101 | 177 | |
| 102 | 178 | // rendering info |
| r243485 | r243486 | |
| 105 | 181 | int m_targetview; |
| 106 | 182 | int m_targetorient; |
| 107 | 183 | render_layer_config m_targetlayerconfig; |
| 108 | | render_primitive_list *m_primlist; |
| 109 | 184 | |
| 110 | 185 | // input info |
| 111 | 186 | DWORD m_lastclicktime; |
| r243485 | r243486 | |
| 145 | 220 | |
| 146 | 221 | BOOL winwindow_has_focus(void); |
| 147 | 222 | void winwindow_update_cursor_state(running_machine &machine); |
| 148 | | win_monitor_info *winwindow_video_window_monitor(win_window_info *window, const RECT *proposed); |
| 149 | 223 | |
| 150 | 224 | LRESULT CALLBACK winwindow_video_window_proc(HWND wnd, UINT message, WPARAM wparam, LPARAM lparam); |
| 151 | 225 | extern LRESULT CALLBACK winwindow_video_window_proc_ui(HWND wnd, UINT message, WPARAM wparam, LPARAM lparam); |
| r243485 | r243486 | |
| 170 | 244 | |
| 171 | 245 | |
| 172 | 246 | //============================================================ |
| 173 | | // win_has_menu |
| 174 | | //============================================================ |
| 175 | | |
| 176 | | INLINE BOOL win_has_menu(win_window_info *window) |
| 177 | | { |
| 178 | | return GetMenu(window->m_hwnd) ? TRUE : FALSE; |
| 179 | | } |
| 180 | | |
| 181 | | |
| 182 | | //============================================================ |
| 183 | 247 | // rect_width / rect_height |
| 184 | 248 | //============================================================ |
| 185 | 249 | |