trunk/src/osd/windows/drawd3d.c
| r31854 | r31855 | |
| 196 | 196 | { |
| 197 | 197 | // allocate memory for our structures |
| 198 | 198 | d3d::renderer *d3d = global_alloc(d3d::renderer(window)); |
| 199 | | window->drawdata = d3d; |
| 199 | window->m_drawdata = d3d; |
| 200 | 200 | |
| 201 | 201 | if (!d3d->initialize()) |
| 202 | 202 | { |
| r31854 | r31855 | |
| 220 | 220 | |
| 221 | 221 | static void drawd3d_window_toggle_fsfx(win_window_info *window) |
| 222 | 222 | { |
| 223 | | d3d::renderer *d3d = (d3d::renderer *)window->drawdata; |
| 223 | d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata; |
| 224 | 224 | d3d->set_restarting(true); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | static void drawd3d_window_record(win_window_info *window) |
| 228 | 228 | { |
| 229 | | d3d::renderer *d3d = (d3d::renderer *)window->drawdata; |
| 229 | d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata; |
| 230 | 230 | d3d->get_shaders()->window_record(); |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | static void drawd3d_window_save(win_window_info *window) |
| 234 | 234 | { |
| 235 | | d3d::renderer *d3d = (d3d::renderer *)window->drawdata; |
| 235 | d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata; |
| 236 | 236 | d3d->get_shaders()->window_save(); |
| 237 | 237 | } |
| 238 | 238 | |
| r31854 | r31855 | |
| 244 | 244 | |
| 245 | 245 | static void drawd3d_window_destroy(win_window_info *window) |
| 246 | 246 | { |
| 247 | | d3d::renderer *d3d = (d3d::renderer *)window->drawdata; |
| 247 | d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata; |
| 248 | 248 | |
| 249 | 249 | // skip if nothing |
| 250 | 250 | if (d3d == NULL) |
| r31854 | r31855 | |
| 255 | 255 | |
| 256 | 256 | // free the memory in the window |
| 257 | 257 | global_free(d3d); |
| 258 | | window->drawdata = NULL; |
| 258 | window->m_drawdata = NULL; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | |
| r31854 | r31855 | |
| 266 | 266 | |
| 267 | 267 | static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window) |
| 268 | 268 | { |
| 269 | | d3d::renderer *d3d = (d3d::renderer *)window->drawdata; |
| 269 | d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata; |
| 270 | 270 | RECT client; |
| 271 | 271 | |
| 272 | | GetClientRectExceptMenu(window->hwnd, &client, window->fullscreen); |
| 272 | GetClientRectExceptMenu(window->m_hwnd, &client, window->m_fullscreen); |
| 273 | 273 | if (rect_width(&client) > 0 && rect_height(&client) > 0) |
| 274 | 274 | { |
| 275 | | window->target->set_bounds(rect_width(&client), rect_height(&client), winvideo_monitor_get_aspect(window->monitor)); |
| 276 | | window->target->set_max_update_rate((d3d->get_refresh() == 0) ? d3d->get_origmode().RefreshRate : d3d->get_refresh()); |
| 275 | window->m_target->set_bounds(rect_width(&client), rect_height(&client), window->m_monitor->get_aspect()); |
| 276 | window->m_target->set_max_update_rate((d3d->get_refresh() == 0) ? d3d->get_origmode().RefreshRate : d3d->get_refresh()); |
| 277 | 277 | } |
| 278 | | return &window->target->get_primitives(); |
| 278 | return &window->m_target->get_primitives(); |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | int drawd3d_init(running_machine &machine, win_draw_callbacks *callbacks) |
| r31854 | r31855 | |
| 311 | 311 | |
| 312 | 312 | static int drawd3d_window_draw(win_window_info *window, HDC dc, int update) |
| 313 | 313 | { |
| 314 | | d3d::renderer *d3d = (d3d::renderer *)window->drawdata; |
| 314 | d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata; |
| 315 | 315 | |
| 316 | 316 | // if we haven't been created, just punt |
| 317 | 317 | if (d3d == NULL) |
| r31854 | r31855 | |
| 496 | 496 | osd_printf_verbose("Direct3D: YUV format = %s\n", (m_yuv_format == D3DFMT_YUY2) ? "YUY2" : (m_yuv_format == D3DFMT_UYVY) ? "UYVY" : "RGB"); |
| 497 | 497 | |
| 498 | 498 | // set the max texture size |
| 499 | | d3d->get_window()->target->set_max_texture_size(m_texture_max_width, m_texture_max_height); |
| 499 | d3d->get_window()->m_target->set_max_texture_size(m_texture_max_width, m_texture_max_height); |
| 500 | 500 | osd_printf_verbose("Direct3D: Max texture size = %dx%d\n", (int)m_texture_max_width, (int)m_texture_max_height); |
| 501 | 501 | } |
| 502 | 502 | |
| r31854 | r31855 | |
| 672 | 672 | return false; |
| 673 | 673 | |
| 674 | 674 | // create the device immediately for the full screen case (defer for window mode) |
| 675 | | if (m_window->fullscreen && device_create()) |
| 675 | if (m_window->m_fullscreen && device_create()) |
| 676 | 676 | return false; |
| 677 | 677 | |
| 678 | 678 | return true; |
| r31854 | r31855 | |
| 681 | 681 | int renderer::pre_window_draw_check() |
| 682 | 682 | { |
| 683 | 683 | // if we're in the middle of resizing, leave things alone |
| 684 | | if (m_window->resize_state == RESIZE_STATE_RESIZING) |
| 684 | if (m_window->m_resize_state == RESIZE_STATE_RESIZING) |
| 685 | 685 | return 0; |
| 686 | 686 | |
| 687 | 687 | // if we're restarting the renderer, leave things alone |
| r31854 | r31855 | |
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | // in window mode, we need to track the window size |
| 709 | | if (!m_window->fullscreen || m_device == NULL) |
| 709 | if (!m_window->m_fullscreen || m_device == NULL) |
| 710 | 710 | { |
| 711 | 711 | // if the size changes, skip this update since the render target will be out of date |
| 712 | 712 | if (update_window_size()) |
| r31854 | r31855 | |
| 722 | 722 | |
| 723 | 723 | void texture_manager::update_textures() |
| 724 | 724 | { |
| 725 | | for (render_primitive *prim = m_renderer->get_window()->primlist->first(); prim != NULL; prim = prim->next()) |
| 725 | for (render_primitive *prim = m_renderer->get_window()->m_primlist->first(); prim != NULL; prim = prim->next()) |
| 726 | 726 | { |
| 727 | 727 | if (prim->texture.base != NULL) |
| 728 | 728 | { |
| r31854 | r31855 | |
| 759 | 759 | |
| 760 | 760 | m_shaders->begin_frame(); |
| 761 | 761 | |
| 762 | | m_window->primlist->acquire_lock(); |
| 762 | m_window->m_primlist->acquire_lock(); |
| 763 | 763 | |
| 764 | 764 | // first update any textures |
| 765 | 765 | m_texture_manager->update_textures(); |
| r31854 | r31855 | |
| 780 | 780 | m_line_count = 0; |
| 781 | 781 | |
| 782 | 782 | // loop over primitives |
| 783 | | for (render_primitive *prim = m_window->primlist->first(); prim != NULL; prim = prim->next()) |
| 783 | for (render_primitive *prim = m_window->m_primlist->first(); prim != NULL; prim = prim->next()) |
| 784 | 784 | if (prim->type == render_primitive::LINE && PRIMFLAG_GET_VECTOR(prim->flags)) |
| 785 | 785 | m_line_count++; |
| 786 | 786 | } |
| r31854 | r31855 | |
| 788 | 788 | void renderer::process_primitives() |
| 789 | 789 | { |
| 790 | 790 | // Rotating index for vector time offsets |
| 791 | | for (render_primitive *prim = m_window->primlist->first(); prim != NULL; prim = prim->next()) |
| 791 | for (render_primitive *prim = m_window->m_primlist->first(); prim != NULL; prim = prim->next()) |
| 792 | 792 | { |
| 793 | 793 | switch (prim->type) |
| 794 | 794 | { |
| r31854 | r31855 | |
| 818 | 818 | |
| 819 | 819 | void renderer::end_frame() |
| 820 | 820 | { |
| 821 | | m_window->primlist->release_lock(); |
| 821 | m_window->m_primlist->release_lock(); |
| 822 | 822 | |
| 823 | 823 | // flush any pending polygons |
| 824 | 824 | primitive_flush_pending(); |
| r31854 | r31855 | |
| 893 | 893 | m_presentation.BackBufferCount = video_config.triplebuf ? 2 : 1; |
| 894 | 894 | m_presentation.MultiSampleType = D3DMULTISAMPLE_NONE; |
| 895 | 895 | m_presentation.SwapEffect = D3DSWAPEFFECT_DISCARD; |
| 896 | | m_presentation.hDeviceWindow = m_window->hwnd; |
| 897 | | m_presentation.Windowed = !m_window->fullscreen || win_has_menu(m_window); |
| 896 | m_presentation.hDeviceWindow = m_window->m_hwnd; |
| 897 | m_presentation.Windowed = !m_window->m_fullscreen || win_has_menu(m_window); |
| 898 | 898 | m_presentation.EnableAutoDepthStencil = FALSE; |
| 899 | 899 | m_presentation.AutoDepthStencilFormat = D3DFMT_D16; |
| 900 | 900 | m_presentation.Flags = 0; |
| 901 | 901 | m_presentation.FullScreen_RefreshRateInHz = m_refresh; |
| 902 | | m_presentation.PresentationInterval = ((video_config.triplebuf && m_window->fullscreen) || |
| 902 | m_presentation.PresentationInterval = ((video_config.triplebuf && m_window->m_fullscreen) || |
| 903 | 903 | video_config.waitvsync || video_config.syncrefresh) ? |
| 904 | 904 | D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; |
| 905 | 905 | |
| 906 | 906 | // create the D3D device |
| 907 | | result = (*d3dintf->d3d.create_device)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_window->focus_hwnd, |
| 907 | result = (*d3dintf->d3d.create_device)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_window->m_focus_hwnd, |
| 908 | 908 | D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &m_presentation, &m_device); |
| 909 | 909 | if (result != D3D_OK) |
| 910 | 910 | { |
| r31854 | r31855 | |
| 927 | 927 | osd_printf_verbose("Direct3D: Device created at %dx%d\n", m_width, m_height); |
| 928 | 928 | |
| 929 | 929 | // set the gamma if we need to |
| 930 | | if (m_window->fullscreen) |
| 930 | if (m_window->m_fullscreen) |
| 931 | 931 | { |
| 932 | 932 | // only set the gamma if it's not 1.0f |
| 933 | 933 | windows_options &options = downcast<windows_options &>(m_window->machine().options()); |
| r31854 | r31855 | |
| 1227 | 1227 | } |
| 1228 | 1228 | |
| 1229 | 1229 | // choose a resolution: window mode case |
| 1230 | | if (!m_window->fullscreen || !video_config.switchres || win_has_menu(m_window)) |
| 1230 | if (!m_window->m_fullscreen || !video_config.switchres || win_has_menu(m_window)) |
| 1231 | 1231 | { |
| 1232 | 1232 | RECT client; |
| 1233 | 1233 | |
| 1234 | 1234 | // bounds are from the window client rect |
| 1235 | | GetClientRectExceptMenu(m_window->hwnd, &client, m_window->fullscreen); |
| 1235 | GetClientRectExceptMenu(m_window->m_hwnd, &client, m_window->m_fullscreen); |
| 1236 | 1236 | m_width = client.right - client.left; |
| 1237 | 1237 | m_height = client.bottom - client.top; |
| 1238 | 1238 | |
| r31854 | r31855 | |
| 1243 | 1243 | // make sure it's a pixel format we can get behind |
| 1244 | 1244 | if (m_pixformat != D3DFMT_X1R5G5B5 && m_pixformat != D3DFMT_R5G6B5 && m_pixformat != D3DFMT_X8R8G8B8) |
| 1245 | 1245 | { |
| 1246 | | char *utf8_device = utf8_from_tstring(m_window->monitor->info.szDevice); |
| 1246 | char *utf8_device = utf8_from_tstring(m_window->m_monitor->info.szDevice); |
| 1247 | 1247 | if (utf8_device != NULL) |
| 1248 | 1248 | { |
| 1249 | 1249 | osd_printf_error("Device %s currently in an unsupported mode\n", utf8_device); |
| r31854 | r31855 | |
| 1268 | 1268 | } |
| 1269 | 1269 | |
| 1270 | 1270 | // see if we can handle the device type |
| 1271 | | result = (*d3dintf->d3d.check_device_type)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_pixformat, !m_window->fullscreen); |
| 1271 | result = (*d3dintf->d3d.check_device_type)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_pixformat, !m_window->m_fullscreen); |
| 1272 | 1272 | if (result != D3D_OK) |
| 1273 | 1273 | { |
| 1274 | | char *utf8_device = utf8_from_tstring(m_window->monitor->info.szDevice); |
| 1274 | char *utf8_device = utf8_from_tstring(m_window->m_monitor->info.szDevice); |
| 1275 | 1275 | if (utf8_device != NULL) |
| 1276 | 1276 | { |
| 1277 | 1277 | osd_printf_error("Proposed video mode not supported on device %s\n", utf8_device); |
| r31854 | r31855 | |
| 1299 | 1299 | HMONITOR curmonitor = (*d3dintf->d3d.get_adapter_monitor)(d3dintf, adapternum); |
| 1300 | 1300 | |
| 1301 | 1301 | // if we match the proposed monitor, this is it |
| 1302 | | if (curmonitor == m_window->monitor->handle) |
| 1302 | if (curmonitor == m_window->m_monitor->handle) |
| 1303 | 1303 | { |
| 1304 | 1304 | return adapternum; |
| 1305 | 1305 | } |
| r31854 | r31855 | |
| 1332 | 1332 | // note: technically we should not be calling this from an alternate window |
| 1333 | 1333 | // thread; however, it is only done during init time, and the init code on |
| 1334 | 1334 | // the main thread is waiting for us to finish, so it is safe to do so here |
| 1335 | | m_window->target->compute_minimum_size(minwidth, minheight); |
| 1335 | m_window->m_target->compute_minimum_size(minwidth, minheight); |
| 1336 | 1336 | |
| 1337 | 1337 | // use those as the target for now |
| 1338 | 1338 | INT32 target_width = minwidth; |
| r31854 | r31855 | |
| 1367 | 1367 | size_score *= 0.1f; |
| 1368 | 1368 | |
| 1369 | 1369 | // if we're looking for a particular mode, that's a winner |
| 1370 | | if (mode.Width == m_window->maxwidth && mode.Height == m_window->maxheight) |
| 1370 | if (mode.Width == m_window->m_maxwidth && mode.Height == m_window->m_maxheight) |
| 1371 | 1371 | size_score = 2.0f; |
| 1372 | 1372 | |
| 1373 | 1373 | // compute refresh score |
| r31854 | r31855 | |
| 1378 | 1378 | refresh_score *= 0.1f; |
| 1379 | 1379 | |
| 1380 | 1380 | // if we're looking for a particular refresh, make sure it matches |
| 1381 | | if (mode.RefreshRate == m_window->refresh) |
| 1381 | if (mode.RefreshRate == m_window->m_refresh) |
| 1382 | 1382 | refresh_score = 2.0f; |
| 1383 | 1383 | |
| 1384 | 1384 | // weight size and refresh equally |
| r31854 | r31855 | |
| 1408 | 1408 | { |
| 1409 | 1409 | // get the current window bounds |
| 1410 | 1410 | RECT client; |
| 1411 | | GetClientRectExceptMenu(m_window->hwnd, &client, m_window->fullscreen); |
| 1411 | GetClientRectExceptMenu(m_window->m_hwnd, &client, m_window->m_fullscreen); |
| 1412 | 1412 | |
| 1413 | 1413 | // if we have a device and matching width/height, nothing to do |
| 1414 | 1414 | if (m_device != NULL && rect_width(&client) == m_width && rect_height(&client) == m_height) |
| 1415 | 1415 | { |
| 1416 | 1416 | // clear out any pending resizing if the area didn't change |
| 1417 | | if (m_window->resize_state == RESIZE_STATE_PENDING) |
| 1418 | | m_window->resize_state = RESIZE_STATE_NORMAL; |
| 1417 | if (m_window->m_resize_state == RESIZE_STATE_PENDING) |
| 1418 | m_window->m_resize_state = RESIZE_STATE_NORMAL; |
| 1419 | 1419 | return FALSE; |
| 1420 | 1420 | } |
| 1421 | 1421 | |
| 1422 | 1422 | // if we're in the middle of resizing, leave it alone as well |
| 1423 | | if (m_window->resize_state == RESIZE_STATE_RESIZING) |
| 1423 | if (m_window->m_resize_state == RESIZE_STATE_RESIZING) |
| 1424 | 1424 | return FALSE; |
| 1425 | 1425 | |
| 1426 | 1426 | // set the new bounds and create the device again |
| r31854 | r31855 | |
| 1430 | 1430 | return FALSE; |
| 1431 | 1431 | |
| 1432 | 1432 | // reset the resize state to normal, and indicate we made a change |
| 1433 | | m_window->resize_state = RESIZE_STATE_NORMAL; |
| 1433 | m_window->m_resize_state = RESIZE_STATE_NORMAL; |
| 1434 | 1434 | return TRUE; |
| 1435 | 1435 | } |
| 1436 | 1436 | |
| r31854 | r31855 | |
| 1450 | 1450 | int line_index = 0; |
| 1451 | 1451 | float period = options.screen_vector_time_period(); |
| 1452 | 1452 | UINT32 cached_flags = 0; |
| 1453 | | for (render_primitive *prim = m_window->primlist->first(); prim != NULL; prim = prim->next()) |
| 1453 | for (render_primitive *prim = m_window->m_primlist->first(); prim != NULL; prim = prim->next()) |
| 1454 | 1454 | { |
| 1455 | 1455 | switch (prim->type) |
| 1456 | 1456 | { |
trunk/src/osd/windows/drawdd.c
| r31854 | r31855 | |
| 219 | 219 | |
| 220 | 220 | // allocate memory for our structures |
| 221 | 221 | dd = global_alloc_clear(dd_info); |
| 222 | | window->drawdata = dd; |
| 222 | window->m_drawdata = dd; |
| 223 | 223 | |
| 224 | 224 | // configure the adapter for the mode we want |
| 225 | 225 | if (config_adapter_mode(window)) |
| r31854 | r31855 | |
| 245 | 245 | |
| 246 | 246 | static void drawdd_window_destroy(win_window_info *window) |
| 247 | 247 | { |
| 248 | | dd_info *dd = (dd_info *)window->drawdata; |
| 248 | dd_info *dd = (dd_info *)window->m_drawdata; |
| 249 | 249 | |
| 250 | 250 | // skip if nothing |
| 251 | 251 | if (dd == NULL) |
| r31854 | r31855 | |
| 256 | 256 | |
| 257 | 257 | // free the memory in the window |
| 258 | 258 | global_free(dd); |
| 259 | | window->drawdata = NULL; |
| 259 | window->m_drawdata = NULL; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | |
| r31854 | r31855 | |
| 267 | 267 | |
| 268 | 268 | static render_primitive_list *drawdd_window_get_primitives(win_window_info *window) |
| 269 | 269 | { |
| 270 | | dd_info *dd = (dd_info *)window->drawdata; |
| 270 | dd_info *dd = (dd_info *)window->m_drawdata; |
| 271 | 271 | |
| 272 | 272 | compute_blit_surface_size(window); |
| 273 | | window->target->set_bounds(dd->blitwidth, dd->blitheight, 0); |
| 274 | | window->target->set_max_update_rate((dd->refresh == 0) ? dd->origmode.dwRefreshRate : dd->refresh); |
| 273 | window->m_target->set_bounds(dd->blitwidth, dd->blitheight, 0); |
| 274 | window->m_target->set_max_update_rate((dd->refresh == 0) ? dd->origmode.dwRefreshRate : dd->refresh); |
| 275 | 275 | |
| 276 | | return &window->target->get_primitives(); |
| 276 | return &window->m_target->get_primitives(); |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | |
| r31854 | r31855 | |
| 284 | 284 | |
| 285 | 285 | static int drawdd_window_draw(win_window_info *window, HDC dc, int update) |
| 286 | 286 | { |
| 287 | | dd_info *dd = (dd_info *)window->drawdata; |
| 287 | dd_info *dd = (dd_info *)window->m_drawdata; |
| 288 | 288 | render_primitive *prim; |
| 289 | 289 | int usemembuffer = FALSE; |
| 290 | 290 | HRESULT result; |
| r31854 | r31855 | |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | // render to it |
| 327 | | window->primlist->acquire_lock(); |
| 327 | window->m_primlist->acquire_lock(); |
| 328 | 328 | |
| 329 | 329 | // scan the list of primitives for tricky stuff |
| 330 | | for (prim = window->primlist->first(); prim != NULL; prim = prim->next()) |
| 330 | for (prim = window->m_primlist->first(); prim != NULL; prim = prim->next()) |
| 331 | 331 | if (PRIMFLAG_GET_BLENDMODE(prim->flags) != BLENDMODE_NONE || |
| 332 | 332 | (prim->texture.base != NULL && PRIMFLAG_GET_TEXFORMAT(prim->flags) == TEXFORMAT_ARGB32)) |
| 333 | 333 | { |
| r31854 | r31855 | |
| 343 | 343 | // based on the target format, use one of our standard renderers |
| 344 | 344 | switch (dd->blitdesc.ddpfPixelFormat.dwRBitMask) |
| 345 | 345 | { |
| 346 | | case 0x00ff0000: software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window->primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth); break; |
| 347 | | case 0x000000ff: software_renderer<UINT32, 0,0,0, 0,8,16>::draw_primitives(*window->primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth); break; |
| 348 | | case 0xf800: software_renderer<UINT16, 3,2,3, 11,5,0>::draw_primitives(*window->primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth); break; |
| 349 | | case 0x7c00: software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window->primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth); break; |
| 346 | case 0x00ff0000: software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window->m_primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth); break; |
| 347 | case 0x000000ff: software_renderer<UINT32, 0,0,0, 0,8,16>::draw_primitives(*window->m_primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth); break; |
| 348 | case 0xf800: software_renderer<UINT16, 3,2,3, 11,5,0>::draw_primitives(*window->m_primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth); break; |
| 349 | case 0x7c00: software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window->m_primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth); break; |
| 350 | 350 | default: |
| 351 | 351 | osd_printf_verbose("DirectDraw: Unknown target mode: R=%08X G=%08X B=%08X\n", (int)dd->blitdesc.ddpfPixelFormat.dwRBitMask, (int)dd->blitdesc.ddpfPixelFormat.dwGBitMask, (int)dd->blitdesc.ddpfPixelFormat.dwBBitMask); |
| 352 | 352 | break; |
| r31854 | r31855 | |
| 379 | 379 | // based on the target format, use one of our standard renderers |
| 380 | 380 | switch (dd->blitdesc.ddpfPixelFormat.dwRBitMask) |
| 381 | 381 | { |
| 382 | | case 0x00ff0000: software_renderer<UINT32, 0,0,0, 16,8,0, true>::draw_primitives(*window->primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 4); break; |
| 383 | | case 0x000000ff: software_renderer<UINT32, 0,0,0, 0,8,16, true>::draw_primitives(*window->primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 4); break; |
| 384 | | case 0xf800: software_renderer<UINT16, 3,2,3, 11,5,0, true>::draw_primitives(*window->primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 2); break; |
| 385 | | case 0x7c00: software_renderer<UINT16, 3,3,3, 10,5,0, true>::draw_primitives(*window->primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 2); break; |
| 382 | case 0x00ff0000: software_renderer<UINT32, 0,0,0, 16,8,0, true>::draw_primitives(*window->m_primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 4); break; |
| 383 | case 0x000000ff: software_renderer<UINT32, 0,0,0, 0,8,16, true>::draw_primitives(*window->m_primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 4); break; |
| 384 | case 0xf800: software_renderer<UINT16, 3,2,3, 11,5,0, true>::draw_primitives(*window->m_primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 2); break; |
| 385 | case 0x7c00: software_renderer<UINT16, 3,3,3, 10,5,0, true>::draw_primitives(*window->m_primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 2); break; |
| 386 | 386 | default: |
| 387 | 387 | osd_printf_verbose("DirectDraw: Unknown target mode: R=%08X G=%08X B=%08X\n", (int)dd->blitdesc.ddpfPixelFormat.dwRBitMask, (int)dd->blitdesc.ddpfPixelFormat.dwGBitMask, (int)dd->blitdesc.ddpfPixelFormat.dwBBitMask); |
| 388 | 388 | break; |
| 389 | 389 | } |
| 390 | 390 | } |
| 391 | | window->primlist->release_lock(); |
| 391 | window->m_primlist->release_lock(); |
| 392 | 392 | |
| 393 | 393 | // unlock and blit |
| 394 | 394 | result = IDirectDrawSurface7_Unlock(dd->blit, NULL); |
| 395 | 395 | if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X unlocking blit surface\n", (int)result); |
| 396 | 396 | |
| 397 | 397 | // sync to VBLANK |
| 398 | | if ((video_config.waitvsync || video_config.syncrefresh) && window->machine().video().throttled() && (!window->fullscreen || dd->back == NULL)) |
| 398 | if ((video_config.waitvsync || video_config.syncrefresh) && window->machine().video().throttled() && (!window->m_fullscreen || dd->back == NULL)) |
| 399 | 399 | { |
| 400 | 400 | result = IDirectDraw7_WaitForVerticalBlank(dd->ddraw, DDWAITVB_BLOCKBEGIN, NULL); |
| 401 | 401 | if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X waiting for VBLANK\n", (int)result); |
| r31854 | r31855 | |
| 414 | 414 | |
| 415 | 415 | static int ddraw_create(win_window_info *window) |
| 416 | 416 | { |
| 417 | | dd_info *dd = (dd_info *)window->drawdata; |
| 417 | dd_info *dd = (dd_info *)window->m_drawdata; |
| 418 | 418 | HRESULT result; |
| 419 | 419 | int verify; |
| 420 | 420 | |
| r31854 | r31855 | |
| 442 | 442 | |
| 443 | 443 | // set the cooperative level |
| 444 | 444 | // for non-window modes, we will use full screen here |
| 445 | | result = IDirectDraw7_SetCooperativeLevel(dd->ddraw, win_window_list->hwnd, DDSCL_SETFOCUSWINDOW); |
| 445 | result = IDirectDraw7_SetCooperativeLevel(dd->ddraw, win_window_list->m_hwnd, DDSCL_SETFOCUSWINDOW); |
| 446 | 446 | if (result != DD_OK) |
| 447 | 447 | { |
| 448 | 448 | osd_printf_verbose("DirectDraw: Error %08X during IDirectDraw7_SetCooperativeLevel(FOCUSWINDOW) call\n", (int)result); |
| 449 | 449 | goto error; |
| 450 | 450 | } |
| 451 | | result = IDirectDraw7_SetCooperativeLevel(dd->ddraw, window->hwnd, DDSCL_SETDEVICEWINDOW | (window->fullscreen ? DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE : DDSCL_NORMAL)); |
| 451 | result = IDirectDraw7_SetCooperativeLevel(dd->ddraw, window->m_hwnd, DDSCL_SETDEVICEWINDOW | (window->m_fullscreen ? DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE : DDSCL_NORMAL)); |
| 452 | 452 | if (result != DD_OK) |
| 453 | 453 | { |
| 454 | 454 | osd_printf_verbose("DirectDraw: Error %08X during IDirectDraw7_SetCooperativeLevel(DEVICEWINDOW) call\n", (int)result); |
| r31854 | r31855 | |
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | // full screen mode: set the resolution |
| 459 | | if (window->fullscreen && video_config.switchres) |
| 459 | if (window->m_fullscreen && video_config.switchres) |
| 460 | 460 | { |
| 461 | 461 | result = IDirectDraw7_SetDisplayMode(dd->ddraw, dd->width, dd->height, 32, dd->refresh, 0); |
| 462 | 462 | if (result != DD_OK) |
| r31854 | r31855 | |
| 481 | 481 | |
| 482 | 482 | static int ddraw_create_surfaces(win_window_info *window) |
| 483 | 483 | { |
| 484 | | dd_info *dd = (dd_info *)window->drawdata; |
| 484 | dd_info *dd = (dd_info *)window->m_drawdata; |
| 485 | 485 | HRESULT result; |
| 486 | 486 | |
| 487 | 487 | // make a description of the primary surface |
| r31854 | r31855 | |
| 491 | 491 | dd->primarydesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; |
| 492 | 492 | |
| 493 | 493 | // for triple-buffered full screen mode, allocate flipping surfaces |
| 494 | | if (window->fullscreen && video_config.triplebuf) |
| 494 | if (window->m_fullscreen && video_config.triplebuf) |
| 495 | 495 | { |
| 496 | 496 | dd->primarydesc.dwFlags |= DDSD_BACKBUFFERCOUNT; |
| 497 | 497 | dd->primarydesc.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX; |
| r31854 | r31855 | |
| 504 | 504 | |
| 505 | 505 | // full screen mode: get the back surface |
| 506 | 506 | dd->back = NULL; |
| 507 | | if (window->fullscreen && video_config.triplebuf) |
| 507 | if (window->m_fullscreen && video_config.triplebuf) |
| 508 | 508 | { |
| 509 | 509 | DDSCAPS2 caps = { DDSCAPS_BACKBUFFER }; |
| 510 | 510 | result = IDirectDrawSurface7_GetAttachedSurface(dd->primary, &caps, &dd->back); |
| r31854 | r31855 | |
| 544 | 544 | goto error; |
| 545 | 545 | |
| 546 | 546 | // create a clipper for windowed mode |
| 547 | | if (!window->fullscreen && create_clipper(window)) |
| 547 | if (!window->m_fullscreen && create_clipper(window)) |
| 548 | 548 | goto error; |
| 549 | 549 | |
| 550 | 550 | // full screen mode: set the gamma |
| 551 | | if (window->fullscreen) |
| 551 | if (window->m_fullscreen) |
| 552 | 552 | { |
| 553 | 553 | // only set the gamma if it's not 1.0f |
| 554 | 554 | windows_options &options = downcast<windows_options &>(window->machine().options()); |
| r31854 | r31855 | |
| 600 | 600 | |
| 601 | 601 | static void ddraw_delete(win_window_info *window) |
| 602 | 602 | { |
| 603 | | dd_info *dd = (dd_info *)window->drawdata; |
| 603 | dd_info *dd = (dd_info *)window->m_drawdata; |
| 604 | 604 | |
| 605 | 605 | // free surfaces |
| 606 | 606 | ddraw_delete_surfaces(window); |
| r31854 | r31855 | |
| 610 | 610 | IDirectDraw7_RestoreDisplayMode(dd->ddraw); |
| 611 | 611 | |
| 612 | 612 | // reset cooperative level |
| 613 | | if (dd->ddraw != NULL && window->hwnd != NULL) |
| 614 | | IDirectDraw7_SetCooperativeLevel(dd->ddraw, window->hwnd, DDSCL_NORMAL); |
| 613 | if (dd->ddraw != NULL && window->m_hwnd != NULL) |
| 614 | IDirectDraw7_SetCooperativeLevel(dd->ddraw, window->m_hwnd, DDSCL_NORMAL); |
| 615 | 615 | |
| 616 | 616 | // release the DirectDraw object itself |
| 617 | 617 | if (dd->ddraw != NULL) |
| r31854 | r31855 | |
| 627 | 627 | |
| 628 | 628 | static void ddraw_delete_surfaces(win_window_info *window) |
| 629 | 629 | { |
| 630 | | dd_info *dd = (dd_info *)window->drawdata; |
| 630 | dd_info *dd = (dd_info *)window->m_drawdata; |
| 631 | 631 | |
| 632 | 632 | // release the gamma control |
| 633 | 633 | if (dd->gamma != NULL) |
| r31854 | r31855 | |
| 699 | 699 | |
| 700 | 700 | static int ddraw_test_cooperative(win_window_info *window) |
| 701 | 701 | { |
| 702 | | dd_info *dd = (dd_info *)window->drawdata; |
| 702 | dd_info *dd = (dd_info *)window->m_drawdata; |
| 703 | 703 | HRESULT result; |
| 704 | 704 | |
| 705 | 705 | // check our current status; if we lost the device, punt to GDI |
| r31854 | r31855 | |
| 769 | 769 | |
| 770 | 770 | static int create_clipper(win_window_info *window) |
| 771 | 771 | { |
| 772 | | dd_info *dd = (dd_info *)window->drawdata; |
| 772 | dd_info *dd = (dd_info *)window->m_drawdata; |
| 773 | 773 | HRESULT result; |
| 774 | 774 | |
| 775 | 775 | // create a clipper for the primary surface |
| r31854 | r31855 | |
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | // set the clipper's hwnd |
| 784 | | result = IDirectDrawClipper_SetHWnd(dd->clipper, 0, window->hwnd); |
| 784 | result = IDirectDrawClipper_SetHWnd(dd->clipper, 0, window->m_hwnd); |
| 785 | 785 | if (result != DD_OK) |
| 786 | 786 | { |
| 787 | 787 | osd_printf_verbose("DirectDraw: Error %08X setting clipper hwnd\n", (int)result); |
| r31854 | r31855 | |
| 806 | 806 | |
| 807 | 807 | static void compute_blit_surface_size(win_window_info *window) |
| 808 | 808 | { |
| 809 | | dd_info *dd = (dd_info *)window->drawdata; |
| 809 | dd_info *dd = (dd_info *)window->m_drawdata; |
| 810 | 810 | INT32 newwidth, newheight; |
| 811 | 811 | int xscale, yscale; |
| 812 | 812 | RECT client; |
| 813 | 813 | |
| 814 | 814 | // start with the minimum size |
| 815 | | window->target->compute_minimum_size(newwidth, newheight); |
| 815 | window->m_target->compute_minimum_size(newwidth, newheight); |
| 816 | 816 | |
| 817 | 817 | // get the window's client rectangle |
| 818 | | GetClientRect(window->hwnd, &client); |
| 818 | GetClientRect(window->m_hwnd, &client); |
| 819 | 819 | |
| 820 | 820 | // hardware stretch case: apply prescale |
| 821 | 821 | if (video_config.hwstretch) |
| r31854 | r31855 | |
| 842 | 842 | if (video_config.keepaspect) |
| 843 | 843 | { |
| 844 | 844 | win_monitor_info *monitor = winwindow_video_window_monitor(window, NULL); |
| 845 | | window->target->compute_visible_area(target_width, target_height, winvideo_monitor_get_aspect(monitor), window->target->orientation(), target_width, target_height); |
| 845 | window->m_target->compute_visible_area(target_width, target_height, monitor->get_aspect(), window->m_target->orientation(), target_width, target_height); |
| 846 | 846 | desired_aspect = (float)target_width / (float)target_height; |
| 847 | 847 | } |
| 848 | 848 | |
| r31854 | r31855 | |
| 930 | 930 | |
| 931 | 931 | static void blit_to_primary(win_window_info *window, int srcwidth, int srcheight) |
| 932 | 932 | { |
| 933 | | dd_info *dd = (dd_info *)window->drawdata; |
| 933 | dd_info *dd = (dd_info *)window->m_drawdata; |
| 934 | 934 | IDirectDrawSurface7 *target = (dd->back != NULL) ? dd->back : dd->primary; |
| 935 | 935 | win_monitor_info *monitor = winwindow_video_window_monitor(window, NULL); |
| 936 | 936 | DDBLTFX blitfx = { sizeof(DDBLTFX) }; |
| r31854 | r31855 | |
| 944 | 944 | source.bottom = srcheight; |
| 945 | 945 | |
| 946 | 946 | // compute outer rect -- windowed version |
| 947 | | if (!window->fullscreen) |
| 947 | if (!window->m_fullscreen) |
| 948 | 948 | { |
| 949 | | GetClientRect(window->hwnd, &outer); |
| 950 | | ClientToScreen(window->hwnd, &((LPPOINT)&outer)[0]); |
| 951 | | ClientToScreen(window->hwnd, &((LPPOINT)&outer)[1]); |
| 949 | GetClientRect(window->m_hwnd, &outer); |
| 950 | ClientToScreen(window->m_hwnd, &((LPPOINT)&outer)[0]); |
| 951 | ClientToScreen(window->m_hwnd, &((LPPOINT)&outer)[1]); |
| 952 | 952 | |
| 953 | 953 | // adjust to be relative to the monitor |
| 954 | 954 | outer.left -= monitor->info.rcMonitor.left; |
| r31854 | r31855 | |
| 987 | 987 | else if (video_config.keepaspect) |
| 988 | 988 | { |
| 989 | 989 | // compute the appropriate visible area |
| 990 | | window->target->compute_visible_area(rect_width(&outer), rect_height(&outer), winvideo_monitor_get_aspect(monitor), window->target->orientation(), dstwidth, dstheight); |
| 990 | window->m_target->compute_visible_area(rect_width(&outer), rect_height(&outer), monitor->get_aspect(), window->m_target->orientation(), dstwidth, dstheight); |
| 991 | 991 | } |
| 992 | 992 | |
| 993 | 993 | // center within |
| r31854 | r31855 | |
| 1050 | 1050 | if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X blitting to the screen\n", (int)result); |
| 1051 | 1051 | |
| 1052 | 1052 | // page flip if triple buffered |
| 1053 | | if (window->fullscreen && dd->back != NULL) |
| 1053 | if (window->m_fullscreen && dd->back != NULL) |
| 1054 | 1054 | { |
| 1055 | 1055 | result = IDirectDrawSurface7_Flip(dd->primary, NULL, DDFLIP_WAIT); |
| 1056 | 1056 | if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X waiting for VBLANK\n", (int)result); |
| r31854 | r31855 | |
| 1066 | 1066 | static int config_adapter_mode(win_window_info *window) |
| 1067 | 1067 | { |
| 1068 | 1068 | DDDEVICEIDENTIFIER2 identifier; |
| 1069 | | dd_info *dd = (dd_info *)window->drawdata; |
| 1069 | dd_info *dd = (dd_info *)window->m_drawdata; |
| 1070 | 1070 | HRESULT result; |
| 1071 | 1071 | |
| 1072 | 1072 | // choose the monitor number |
| 1073 | | get_adapter_for_monitor(dd, window->monitor); |
| 1073 | get_adapter_for_monitor(dd, window->m_monitor); |
| 1074 | 1074 | |
| 1075 | 1075 | // create a temporary DirectDraw object |
| 1076 | 1076 | result = (*directdrawcreateex)(dd->adapter_ptr, (LPVOID *)&dd->ddraw, WRAP_REFIID(IID_IDirectDraw7), NULL); |
| r31854 | r31855 | |
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | // choose a resolution: full screen mode case |
| 1104 | | if (window->fullscreen) |
| 1104 | if (window->m_fullscreen) |
| 1105 | 1105 | { |
| 1106 | 1106 | // default to the current mode exactly |
| 1107 | 1107 | dd->width = dd->origmode.dwWidth; |
| r31854 | r31855 | |
| 1118 | 1118 | dd->ddraw = NULL; |
| 1119 | 1119 | |
| 1120 | 1120 | // if we're not changing resolutions, make sure we have a resolution we can handle |
| 1121 | | if (!window->fullscreen || !video_config.switchres) |
| 1121 | if (!window->m_fullscreen || !video_config.switchres) |
| 1122 | 1122 | { |
| 1123 | 1123 | switch (dd->origmode.ddpfPixelFormat.dwRBitMask) |
| 1124 | 1124 | { |
| r31854 | r31855 | |
| 1195 | 1195 | { |
| 1196 | 1196 | float size_score, refresh_score, final_score; |
| 1197 | 1197 | mode_enum_info *einfo = (mode_enum_info *)context; |
| 1198 | | dd_info *dd = (dd_info *)einfo->window->drawdata; |
| 1198 | dd_info *dd = (dd_info *)einfo->window->m_drawdata; |
| 1199 | 1199 | |
| 1200 | 1200 | // skip non-32 bit modes |
| 1201 | 1201 | if (desc->ddpfPixelFormat.dwRGBBitCount != 32) |
| r31854 | r31855 | |
| 1213 | 1213 | size_score *= 0.1f; |
| 1214 | 1214 | |
| 1215 | 1215 | // if we're looking for a particular mode, that's a winner |
| 1216 | | if (desc->dwWidth == einfo->window->maxwidth && desc->dwHeight == einfo->window->maxheight) |
| 1216 | if (desc->dwWidth == einfo->window->m_maxwidth && desc->dwHeight == einfo->window->m_maxheight) |
| 1217 | 1217 | size_score = 2.0f; |
| 1218 | 1218 | |
| 1219 | 1219 | // compute refresh score |
| r31854 | r31855 | |
| 1224 | 1224 | refresh_score *= 0.1f; |
| 1225 | 1225 | |
| 1226 | 1226 | // if we're looking for a particular refresh, make sure it matches |
| 1227 | | if (desc->dwRefreshRate == einfo->window->refresh) |
| 1227 | if (desc->dwRefreshRate == einfo->window->m_refresh) |
| 1228 | 1228 | refresh_score = 2.0f; |
| 1229 | 1229 | |
| 1230 | 1230 | // weight size and refresh equally |
| r31854 | r31855 | |
| 1250 | 1250 | |
| 1251 | 1251 | static void pick_best_mode(win_window_info *window) |
| 1252 | 1252 | { |
| 1253 | | dd_info *dd = (dd_info *)window->drawdata; |
| 1253 | dd_info *dd = (dd_info *)window->m_drawdata; |
| 1254 | 1254 | mode_enum_info einfo; |
| 1255 | 1255 | HRESULT result; |
| 1256 | 1256 | |
| r31854 | r31855 | |
| 1258 | 1258 | // note: technically we should not be calling this from an alternate window |
| 1259 | 1259 | // thread; however, it is only done during init time, and the init code on |
| 1260 | 1260 | // the main thread is waiting for us to finish, so it is safe to do so here |
| 1261 | | window->target->compute_minimum_size(einfo.minimum_width, einfo.minimum_height); |
| 1261 | window->m_target->compute_minimum_size(einfo.minimum_width, einfo.minimum_height); |
| 1262 | 1262 | |
| 1263 | 1263 | // use those as the target for now |
| 1264 | 1264 | einfo.target_width = einfo.minimum_width * MAX(1, video_config.prescale); |
trunk/src/osd/windows/window.c
| r31854 | r31855 | |
| 117 | 117 | // PROTOTYPES |
| 118 | 118 | //============================================================ |
| 119 | 119 | |
| 120 | | static void winwindow_exit(running_machine &machine); |
| 121 | 120 | static void winwindow_video_window_destroy(win_window_info *window); |
| 122 | 121 | static void draw_video_contents(win_window_info *window, HDC dc, int update); |
| 123 | 122 | |
| r31854 | r31855 | |
| 181 | 180 | |
| 182 | 181 | |
| 183 | 182 | //============================================================ |
| 184 | | // winwindow_init |
| 183 | // window_init |
| 185 | 184 | // (main thread) |
| 186 | 185 | //============================================================ |
| 187 | 186 | |
| 188 | | void winwindow_init(running_machine &machine) |
| 187 | bool windows_osd_interface::window_init() |
| 189 | 188 | { |
| 190 | 189 | size_t temp; |
| 191 | 190 | |
| 192 | 191 | // determine if we are using multithreading or not |
| 193 | | multithreading_enabled = downcast<windows_options &>(machine.options()).multithreading(); |
| 192 | multithreading_enabled = downcast<windows_options &>(machine().options()).multithreading(); |
| 194 | 193 | |
| 195 | 194 | // get the main thread ID before anything else |
| 196 | 195 | main_threadid = GetCurrentThreadId(); |
| 197 | 196 | |
| 198 | | // ensure we get called on the way out |
| 199 | | machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(winwindow_exit), &machine)); |
| 200 | | |
| 201 | 197 | // set up window class and register it |
| 202 | 198 | create_window_class(); |
| 203 | 199 | |
| r31854 | r31855 | |
| 234 | 230 | // initialize the drawers |
| 235 | 231 | if (video_config.mode == VIDEO_MODE_D3D) |
| 236 | 232 | { |
| 237 | | if (drawd3d_init(machine, &draw)) |
| 233 | if (drawd3d_init(machine(), &draw)) |
| 238 | 234 | video_config.mode = VIDEO_MODE_GDI; |
| 239 | 235 | } |
| 240 | 236 | if (video_config.mode == VIDEO_MODE_DDRAW) |
| 241 | 237 | { |
| 242 | | if (drawdd_init(machine, &draw)) |
| 238 | if (drawdd_init(machine(), &draw)) |
| 243 | 239 | video_config.mode = VIDEO_MODE_GDI; |
| 244 | 240 | } |
| 245 | 241 | if (video_config.mode == VIDEO_MODE_GDI) |
| 246 | | drawgdi_init(machine, &draw); |
| 242 | drawgdi_init(machine(), &draw); |
| 247 | 243 | if (video_config.mode == VIDEO_MODE_NONE) |
| 248 | | drawnone_init(machine, &draw); |
| 244 | drawnone_init(machine(), &draw); |
| 249 | 245 | |
| 250 | 246 | // set up the window list |
| 251 | 247 | last_window_ptr = &win_window_list; |
| 248 | |
| 249 | return true; |
| 252 | 250 | } |
| 253 | 251 | |
| 254 | 252 | |
| r31854 | r31855 | |
| 258 | 256 | // (main thread) |
| 259 | 257 | //============================================================ |
| 260 | 258 | |
| 261 | | static void winwindow_exit(running_machine &machine) |
| 259 | void windows_osd_interface::window_exit() |
| 262 | 260 | { |
| 263 | 261 | assert(GetCurrentThreadId() == main_threadid); |
| 264 | 262 | |
| r31854 | r31855 | |
| 266 | 264 | while (win_window_list != NULL) |
| 267 | 265 | { |
| 268 | 266 | win_window_info *temp = win_window_list; |
| 269 | | win_window_list = temp->next; |
| 267 | win_window_list = temp->m_next; |
| 270 | 268 | winwindow_video_window_destroy(temp); |
| 271 | 269 | } |
| 272 | 270 | |
| r31854 | r31855 | |
| 295 | 293 | } |
| 296 | 294 | |
| 297 | 295 | |
| 296 | win_window_info::win_window_info(running_machine &machine) |
| 297 | : m_next(NULL), |
| 298 | m_init_state(0), |
| 299 | m_hwnd(0), |
| 300 | m_focus_hwnd(0), |
| 301 | m_startmaximized(0), |
| 302 | m_isminimized(0), |
| 303 | m_ismaximized(0), |
| 304 | m_resize_state(0), |
| 305 | m_monitor(0), |
| 306 | m_fullscreen(0), |
| 307 | m_fullscreen_safe(0), |
| 308 | m_maxwidth(0), |
| 309 | m_maxheight(0), |
| 310 | m_refresh(0), |
| 311 | m_aspect(0), |
| 312 | m_render_lock(NULL), |
| 313 | m_target(NULL), |
| 314 | m_targetview(0), |
| 315 | m_targetorient(0), |
| 316 | m_primlist(NULL), |
| 317 | m_lastclicktime(0), |
| 318 | m_lastclickx(0), |
| 319 | m_lastclicky(0), |
| 320 | m_drawdata(NULL), |
| 321 | m_machine(machine) |
| 322 | { |
| 323 | memset(m_title,0,sizeof(m_title)); |
| 324 | m_non_fullscreen_bounds.left = 0; |
| 325 | m_non_fullscreen_bounds.top = 0; |
| 326 | m_non_fullscreen_bounds.right = 0; |
| 327 | m_non_fullscreen_bounds.bottom = 0; |
| 328 | } |
| 298 | 329 | |
| 330 | win_window_info::~win_window_info() |
| 331 | { |
| 332 | } |
| 333 | |
| 334 | |
| 299 | 335 | //============================================================ |
| 300 | 336 | // winwindow_process_events_periodic |
| 301 | 337 | // (main thread) |
| r31854 | r31855 | |
| 323 | 359 | { |
| 324 | 360 | win_window_info *window; |
| 325 | 361 | |
| 326 | | for (window = win_window_list; window != NULL; window = window->next) |
| 327 | | if (window->hwnd == hwnd) |
| 362 | for (window = win_window_list; window != NULL; window = window->m_next) |
| 363 | if (window->m_hwnd == hwnd) |
| 328 | 364 | return TRUE; |
| 329 | 365 | |
| 330 | 366 | return FALSE; |
| r31854 | r31855 | |
| 473 | 509 | assert(GetCurrentThreadId() == main_threadid); |
| 474 | 510 | |
| 475 | 511 | // iterate over windows and request a snap |
| 476 | | for (window = win_window_list; window != NULL; window = window->next) |
| 512 | for (window = win_window_list; window != NULL; window = window->m_next) |
| 477 | 513 | { |
| 478 | 514 | (*draw.window_save)(window); |
| 479 | 515 | } |
| r31854 | r31855 | |
| 496 | 532 | assert(GetCurrentThreadId() == main_threadid); |
| 497 | 533 | |
| 498 | 534 | // iterate over windows and request a snap |
| 499 | | for (window = win_window_list; window != NULL; window = window->next) |
| 535 | for (window = win_window_list; window != NULL; window = window->m_next) |
| 500 | 536 | { |
| 501 | 537 | (*draw.window_toggle_fsfx)(window); |
| 502 | 538 | } |
| r31854 | r31855 | |
| 519 | 555 | assert(GetCurrentThreadId() == main_threadid); |
| 520 | 556 | |
| 521 | 557 | // iterate over windows and request a snap |
| 522 | | for (window = win_window_list; window != NULL; window = window->next) |
| 558 | for (window = win_window_list; window != NULL; window = window->m_next) |
| 523 | 559 | { |
| 524 | 560 | (*draw.window_record)(window); |
| 525 | 561 | } |
| r31854 | r31855 | |
| 539 | 575 | assert(GetCurrentThreadId() == main_threadid); |
| 540 | 576 | |
| 541 | 577 | // if we are in debug mode, never go full screen |
| 542 | | for (window = win_window_list; window != NULL; window = window->next) |
| 578 | for (window = win_window_list; window != NULL; window = window->m_next) |
| 543 | 579 | if (window->machine().debug_flags & DEBUG_FLAG_OSD_ENABLED) |
| 544 | 580 | return; |
| 545 | 581 | |
| r31854 | r31855 | |
| 547 | 583 | video_config.windowed = !video_config.windowed; |
| 548 | 584 | |
| 549 | 585 | // iterate over windows and toggle their fullscreen state |
| 550 | | for (window = win_window_list; window != NULL; window = window->next) |
| 551 | | SendMessage(window->hwnd, WM_USER_SET_FULLSCREEN, !video_config.windowed, 0); |
| 552 | | SetForegroundWindow(win_window_list->hwnd); |
| 586 | for (window = win_window_list; window != NULL; window = window->m_next) |
| 587 | SendMessage(window->m_hwnd, WM_USER_SET_FULLSCREEN, !video_config.windowed, 0); |
| 588 | SetForegroundWindow(win_window_list->m_hwnd); |
| 553 | 589 | } |
| 554 | 590 | |
| 555 | 591 | |
| r31854 | r31855 | |
| 565 | 601 | win_window_info *window; |
| 566 | 602 | |
| 567 | 603 | // see if one of the video windows has focus |
| 568 | | for (window = win_window_list; window != NULL; window = window->next) |
| 569 | | if (focuswnd == window->hwnd) |
| 604 | for (window = win_window_list; window != NULL; window = window->m_next) |
| 605 | if (focuswnd == window->m_hwnd) |
| 570 | 606 | return TRUE; |
| 571 | 607 | |
| 572 | 608 | return FALSE; |
| r31854 | r31855 | |
| 603 | 639 | GetCursorPos(&saved_cursor_pos); |
| 604 | 640 | |
| 605 | 641 | // clip cursor to game video window |
| 606 | | GetClientRect(window->hwnd, &bounds); |
| 607 | | ClientToScreen(window->hwnd, &((POINT *)&bounds)[0]); |
| 608 | | ClientToScreen(window->hwnd, &((POINT *)&bounds)[1]); |
| 642 | GetClientRect(window->m_hwnd, &bounds); |
| 643 | ClientToScreen(window->m_hwnd, &((POINT *)&bounds)[0]); |
| 644 | ClientToScreen(window->m_hwnd, &((POINT *)&bounds)[1]); |
| 609 | 645 | ClipCursor(&bounds); |
| 610 | 646 | } |
| 611 | 647 | else |
| r31854 | r31855 | |
| 638 | 674 | assert(GetCurrentThreadId() == main_threadid); |
| 639 | 675 | |
| 640 | 676 | // allocate a new window object |
| 641 | | window = global_alloc_clear(win_window_info(machine)); |
| 677 | window = global_alloc(win_window_info(machine)); |
| 642 | 678 | //printf("%d, %d\n", config->width, config->height); |
| 643 | | window->maxwidth = config->width; |
| 644 | | window->maxheight = config->height; |
| 645 | | window->refresh = config->refresh; |
| 646 | | window->monitor = monitor; |
| 647 | | window->fullscreen = !video_config.windowed; |
| 679 | window->m_maxwidth = config->width; |
| 680 | window->m_maxheight = config->height; |
| 681 | window->m_refresh = config->refresh; |
| 682 | window->m_monitor = monitor; |
| 683 | window->m_fullscreen = !video_config.windowed; |
| 648 | 684 | |
| 649 | 685 | // see if we are safe for fullscreen |
| 650 | | window->fullscreen_safe = TRUE; |
| 651 | | for (win = win_window_list; win != NULL; win = win->next) |
| 652 | | if (win->monitor == monitor) |
| 653 | | window->fullscreen_safe = FALSE; |
| 686 | window->m_fullscreen_safe = TRUE; |
| 687 | for (win = win_window_list; win != NULL; win = win->m_next) |
| 688 | if (win->m_monitor == monitor) |
| 689 | window->m_fullscreen_safe = FALSE; |
| 654 | 690 | |
| 655 | 691 | // add us to the list |
| 656 | 692 | *last_window_ptr = window; |
| 657 | | last_window_ptr = &window->next; |
| 693 | last_window_ptr = &window->m_next; |
| 658 | 694 | |
| 659 | 695 | // create a lock that we can use to skip blitting |
| 660 | | window->render_lock = osd_lock_alloc(); |
| 696 | window->m_render_lock = osd_lock_alloc(); |
| 661 | 697 | |
| 662 | 698 | // load the layout |
| 663 | | window->target = machine.render().target_alloc(); |
| 699 | window->m_target = machine.render().target_alloc(); |
| 664 | 700 | |
| 665 | 701 | // set the specific view |
| 666 | 702 | windows_options &options = downcast<windows_options &>(machine.options()); |
| 667 | 703 | set_starting_view(index, window, options.view(index)); |
| 668 | 704 | |
| 669 | 705 | // remember the current values in case they change |
| 670 | | window->targetview = window->target->view(); |
| 671 | | window->targetorient = window->target->orientation(); |
| 672 | | window->targetlayerconfig = window->target->layer_config(); |
| 706 | window->m_targetview = window->m_target->view(); |
| 707 | window->m_targetorient = window->m_target->orientation(); |
| 708 | window->m_targetlayerconfig = window->m_target->layer_config(); |
| 673 | 709 | |
| 674 | 710 | // make the window title |
| 675 | 711 | if (video_config.numscreens == 1) |
| 676 | | sprintf(window->title, "%s: %s [%s]", emulator_info::get_appname(), machine.system().description, machine.system().name); |
| 712 | sprintf(window->m_title, "%s: %s [%s]", emulator_info::get_appname(), machine.system().description, machine.system().name); |
| 677 | 713 | else |
| 678 | | sprintf(window->title, "%s: %s [%s] - Screen %d", emulator_info::get_appname(), machine.system().description, machine.system().name, index); |
| 714 | sprintf(window->m_title, "%s: %s [%s] - Screen %d", emulator_info::get_appname(), machine.system().description, machine.system().name, index); |
| 679 | 715 | |
| 680 | 716 | // set the initial maximized state |
| 681 | | window->startmaximized = options.maximize(); |
| 717 | window->m_startmaximized = options.maximize(); |
| 682 | 718 | |
| 683 | 719 | // finish the window creation on the window thread |
| 684 | 720 | if (multithreading_enabled) |
| r31854 | r31855 | |
| 687 | 723 | WaitForSingleObject(window_thread_ready_event, INFINITE); |
| 688 | 724 | |
| 689 | 725 | PostThreadMessage(window_threadid, WM_USER_FINISH_CREATE_WINDOW, 0, (LPARAM)window); |
| 690 | | while (window->init_state == 0) |
| 726 | while (window->m_init_state == 0) |
| 691 | 727 | { |
| 692 | 728 | winwindow_process_events(machine, 0, 1); //pump the message queue |
| 693 | 729 | Sleep(1); |
| 694 | 730 | } |
| 695 | 731 | } |
| 696 | 732 | else |
| 697 | | window->init_state = complete_create(window) ? -1 : 1; |
| 733 | window->m_init_state = complete_create(window) ? -1 : 1; |
| 698 | 734 | |
| 699 | 735 | // handle error conditions |
| 700 | | if (window->init_state == -1) |
| 736 | if (window->m_init_state == -1) |
| 701 | 737 | fatalerror("Unable to complete window creation\n"); |
| 702 | 738 | } |
| 703 | 739 | |
| r31854 | r31855 | |
| 715 | 751 | assert(GetCurrentThreadId() == main_threadid); |
| 716 | 752 | |
| 717 | 753 | // remove us from the list |
| 718 | | for (prevptr = &win_window_list; *prevptr != NULL; prevptr = &(*prevptr)->next) |
| 754 | for (prevptr = &win_window_list; *prevptr != NULL; prevptr = &(*prevptr)->m_next) |
| 719 | 755 | if (*prevptr == window) |
| 720 | 756 | { |
| 721 | | *prevptr = window->next; |
| 757 | *prevptr = window->m_next; |
| 722 | 758 | break; |
| 723 | 759 | } |
| 724 | 760 | |
| 725 | 761 | // destroy the window |
| 726 | | if (window->hwnd != NULL) |
| 727 | | SendMessage(window->hwnd, WM_USER_SELF_TERMINATE, 0, 0); |
| 762 | if (window->m_hwnd != NULL) |
| 763 | SendMessage(window->m_hwnd, WM_USER_SELF_TERMINATE, 0, 0); |
| 728 | 764 | |
| 729 | 765 | // free the render target |
| 730 | | window->machine().render().target_free(window->target); |
| 766 | window->machine().render().target_free(window->m_target); |
| 731 | 767 | |
| 732 | 768 | // free the lock |
| 733 | | osd_lock_free(window->render_lock); |
| 769 | osd_lock_free(window->m_render_lock); |
| 734 | 770 | |
| 735 | 771 | // free the window itself |
| 736 | 772 | global_free(window); |
| r31854 | r31855 | |
| 743 | 779 | // (main thread) |
| 744 | 780 | //============================================================ |
| 745 | 781 | |
| 746 | | void winwindow_video_window_update(win_window_info *window) |
| 782 | void win_window_info::update() |
| 747 | 783 | { |
| 748 | 784 | int targetview, targetorient; |
| 749 | 785 | render_layer_config targetlayerconfig; |
| r31854 | r31855 | |
| 753 | 789 | mtlog_add("winwindow_video_window_update: begin"); |
| 754 | 790 | |
| 755 | 791 | // see if the target has changed significantly in window mode |
| 756 | | targetview = window->target->view(); |
| 757 | | targetorient = window->target->orientation(); |
| 758 | | targetlayerconfig = window->target->layer_config(); |
| 759 | | if (targetview != window->targetview || targetorient != window->targetorient || targetlayerconfig != window->targetlayerconfig) |
| 792 | targetview = m_target->view(); |
| 793 | targetorient = m_target->orientation(); |
| 794 | targetlayerconfig = m_target->layer_config(); |
| 795 | if (targetview != m_targetview || targetorient != m_targetorient || targetlayerconfig != m_targetlayerconfig) |
| 760 | 796 | { |
| 761 | | window->targetview = targetview; |
| 762 | | window->targetorient = targetorient; |
| 763 | | window->targetlayerconfig = targetlayerconfig; |
| 797 | m_targetview = targetview; |
| 798 | m_targetorient = targetorient; |
| 799 | m_targetlayerconfig = targetlayerconfig; |
| 764 | 800 | |
| 765 | 801 | // in window mode, reminimize/maximize |
| 766 | | if (!window->fullscreen) |
| 802 | if (!m_fullscreen) |
| 767 | 803 | { |
| 768 | | if (window->isminimized) |
| 769 | | SendMessage(window->hwnd, WM_USER_SET_MINSIZE, 0, 0); |
| 770 | | if (window->ismaximized) |
| 771 | | SendMessage(window->hwnd, WM_USER_SET_MAXSIZE, 0, 0); |
| 804 | if (m_isminimized) |
| 805 | SendMessage(m_hwnd, WM_USER_SET_MINSIZE, 0, 0); |
| 806 | if (m_ismaximized) |
| 807 | SendMessage(m_hwnd, WM_USER_SET_MAXSIZE, 0, 0); |
| 772 | 808 | } |
| 773 | 809 | } |
| 774 | 810 | |
| 775 | 811 | // if we're visible and running and not in the middle of a resize, draw |
| 776 | | if (window->hwnd != NULL && window->target != NULL && window->drawdata != NULL) |
| 812 | if (m_hwnd != NULL && m_target != NULL && m_drawdata != NULL) |
| 777 | 813 | { |
| 778 | 814 | int got_lock = TRUE; |
| 779 | 815 | |
| 780 | 816 | mtlog_add("winwindow_video_window_update: try lock"); |
| 781 | 817 | |
| 782 | 818 | // only block if we're throttled |
| 783 | | if (window->machine().video().throttled() || timeGetTime() - last_update_time > 250) |
| 784 | | osd_lock_acquire(window->render_lock); |
| 819 | if (machine().video().throttled() || timeGetTime() - last_update_time > 250) |
| 820 | osd_lock_acquire(m_render_lock); |
| 785 | 821 | else |
| 786 | | got_lock = osd_lock_try(window->render_lock); |
| 822 | got_lock = osd_lock_try(m_render_lock); |
| 787 | 823 | |
| 788 | 824 | // only render if we were able to get the lock |
| 789 | 825 | if (got_lock) |
| r31854 | r31855 | |
| 793 | 829 | mtlog_add("winwindow_video_window_update: got lock"); |
| 794 | 830 | |
| 795 | 831 | // don't hold the lock; we just used it to see if rendering was still happening |
| 796 | | osd_lock_release(window->render_lock); |
| 832 | osd_lock_release(m_render_lock); |
| 797 | 833 | |
| 798 | 834 | // ensure the target bounds are up-to-date, and then get the primitives |
| 799 | | primlist = (*draw.window_get_primitives)(window); |
| 835 | primlist = (*draw.window_get_primitives)(this); |
| 800 | 836 | |
| 801 | 837 | // post a redraw request with the primitive list as a parameter |
| 802 | 838 | last_update_time = timeGetTime(); |
| 803 | 839 | mtlog_add("winwindow_video_window_update: PostMessage start"); |
| 804 | 840 | if (multithreading_enabled) |
| 805 | | PostMessage(window->hwnd, WM_USER_REDRAW, 0, (LPARAM)primlist); |
| 841 | PostMessage(m_hwnd, WM_USER_REDRAW, 0, (LPARAM)primlist); |
| 806 | 842 | else |
| 807 | | SendMessage(window->hwnd, WM_USER_REDRAW, 0, (LPARAM)primlist); |
| 843 | SendMessage(m_hwnd, WM_USER_REDRAW, 0, (LPARAM)primlist); |
| 808 | 844 | mtlog_add("winwindow_video_window_update: PostMessage end"); |
| 809 | 845 | } |
| 810 | 846 | } |
| r31854 | r31855 | |
| 824 | 860 | win_monitor_info *monitor; |
| 825 | 861 | |
| 826 | 862 | // in window mode, find the nearest |
| 827 | | if (!window->fullscreen) |
| 863 | if (!window->m_fullscreen) |
| 828 | 864 | { |
| 829 | 865 | if (proposed != NULL) |
| 830 | 866 | monitor = winvideo_monitor_from_handle(MonitorFromRect(proposed, MONITOR_DEFAULTTONEAREST)); |
| 831 | 867 | else |
| 832 | | monitor = winvideo_monitor_from_handle(MonitorFromWindow(window->hwnd, MONITOR_DEFAULTTONEAREST)); |
| 868 | monitor = winvideo_monitor_from_handle(MonitorFromWindow(window->m_hwnd, MONITOR_DEFAULTTONEAREST)); |
| 833 | 869 | } |
| 834 | 870 | |
| 835 | 871 | // in full screen, just use the configured monitor |
| 836 | 872 | else |
| 837 | | monitor = window->monitor; |
| 873 | monitor = window->m_monitor; |
| 838 | 874 | |
| 839 | 875 | // make sure we're up-to-date |
| 840 | | winvideo_monitor_refresh(monitor); |
| 876 | monitor->refresh(); |
| 841 | 877 | return monitor; |
| 842 | 878 | } |
| 843 | 879 | |
| r31854 | r31855 | |
| 891 | 927 | view = defview; |
| 892 | 928 | |
| 893 | 929 | // query the video system to help us pick a view |
| 894 | | viewindex = window->target->configured_view(view, index, video_config.numscreens); |
| 930 | viewindex = window->m_target->configured_view(view, index, video_config.numscreens); |
| 895 | 931 | |
| 896 | 932 | // set the view |
| 897 | | window->target->set_view(viewindex); |
| 933 | window->m_target->set_view(viewindex); |
| 898 | 934 | } |
| 899 | 935 | |
| 900 | 936 | |
| r31854 | r31855 | |
| 1014 | 1050 | INLINE int wnd_extra_width(win_window_info *window) |
| 1015 | 1051 | { |
| 1016 | 1052 | RECT temprect = { 100, 100, 200, 200 }; |
| 1017 | | if (window->fullscreen) |
| 1053 | if (window->m_fullscreen) |
| 1018 | 1054 | return 0; |
| 1019 | 1055 | AdjustWindowRectEx(&temprect, WINDOW_STYLE, win_has_menu(window), WINDOW_STYLE_EX); |
| 1020 | 1056 | return rect_width(&temprect) - 100; |
| r31854 | r31855 | |
| 1030 | 1066 | INLINE int wnd_extra_height(win_window_info *window) |
| 1031 | 1067 | { |
| 1032 | 1068 | RECT temprect = { 100, 100, 200, 200 }; |
| 1033 | | if (window->fullscreen) |
| 1069 | if (window->m_fullscreen) |
| 1034 | 1070 | return 0; |
| 1035 | 1071 | AdjustWindowRectEx(&temprect, WINDOW_STYLE, win_has_menu(window), WINDOW_STYLE_EX); |
| 1036 | 1072 | return rect_height(&temprect) - 100; |
| r31854 | r31855 | |
| 1115 | 1151 | case WM_USER_FINISH_CREATE_WINDOW: |
| 1116 | 1152 | { |
| 1117 | 1153 | win_window_info *window = (win_window_info *)message.lParam; |
| 1118 | | window->init_state = complete_create(window) ? -1 : 1; |
| 1154 | window->m_init_state = complete_create(window) ? -1 : 1; |
| 1119 | 1155 | dispatch = FALSE; |
| 1120 | 1156 | break; |
| 1121 | 1157 | } |
| r31854 | r31855 | |
| 1149 | 1185 | assert(GetCurrentThreadId() == window_threadid); |
| 1150 | 1186 | |
| 1151 | 1187 | // get the monitor bounds |
| 1152 | | monitorbounds = window->monitor->info.rcMonitor; |
| 1188 | monitorbounds = window->m_monitor->info.rcMonitor; |
| 1153 | 1189 | |
| 1154 | 1190 | // create the window menu if needed |
| 1155 | 1191 | if (downcast<windows_options &>(window->machine().options()).menu()) |
| r31854 | r31855 | |
| 1159 | 1195 | } |
| 1160 | 1196 | |
| 1161 | 1197 | // create the window, but don't show it yet |
| 1162 | | window->hwnd = win_create_window_ex_utf8( |
| 1163 | | window->fullscreen ? FULLSCREEN_STYLE_EX : WINDOW_STYLE_EX, |
| 1198 | window->m_hwnd = win_create_window_ex_utf8( |
| 1199 | window->m_fullscreen ? FULLSCREEN_STYLE_EX : WINDOW_STYLE_EX, |
| 1164 | 1200 | "MAME", |
| 1165 | | window->title, |
| 1166 | | window->fullscreen ? FULLSCREEN_STYLE : WINDOW_STYLE, |
| 1201 | window->m_title, |
| 1202 | window->m_fullscreen ? FULLSCREEN_STYLE : WINDOW_STYLE, |
| 1167 | 1203 | monitorbounds.left + 20, monitorbounds.top + 20, |
| 1168 | 1204 | monitorbounds.left + 100, monitorbounds.top + 100, |
| 1169 | | NULL,//(win_window_list != NULL) ? win_window_list->hwnd : NULL, |
| 1205 | NULL,//(win_window_list != NULL) ? win_window_list->m_hwnd : NULL, |
| 1170 | 1206 | menu, |
| 1171 | 1207 | GetModuleHandle(NULL), |
| 1172 | 1208 | NULL); |
| 1173 | | if (window->hwnd == NULL) |
| 1209 | if (window->m_hwnd == NULL) |
| 1174 | 1210 | return 1; |
| 1175 | 1211 | |
| 1176 | 1212 | // set window #0 as the focus window for all windows, required for D3D & multimonitor |
| 1177 | | window->focus_hwnd = win_window_list->hwnd; |
| 1213 | window->m_focus_hwnd = win_window_list->m_hwnd; |
| 1178 | 1214 | |
| 1179 | 1215 | // set a pointer back to us |
| 1180 | | SetWindowLongPtr(window->hwnd, GWLP_USERDATA, (LONG_PTR)window); |
| 1216 | SetWindowLongPtr(window->m_hwnd, GWLP_USERDATA, (LONG_PTR)window); |
| 1181 | 1217 | |
| 1182 | 1218 | // skip the positioning stuff for -video none */ |
| 1183 | 1219 | if (video_config.mode == VIDEO_MODE_NONE) |
| 1184 | 1220 | return 0; |
| 1185 | 1221 | |
| 1186 | 1222 | // adjust the window position to the initial width/height |
| 1187 | | tempwidth = (window->maxwidth != 0) ? window->maxwidth : 640; |
| 1188 | | tempheight = (window->maxheight != 0) ? window->maxheight : 480; |
| 1189 | | SetWindowPos(window->hwnd, NULL, monitorbounds.left + 20, monitorbounds.top + 20, |
| 1223 | tempwidth = (window->m_maxwidth != 0) ? window->m_maxwidth : 640; |
| 1224 | tempheight = (window->m_maxheight != 0) ? window->m_maxheight : 480; |
| 1225 | SetWindowPos(window->m_hwnd, NULL, monitorbounds.left + 20, monitorbounds.top + 20, |
| 1190 | 1226 | monitorbounds.left + tempwidth + wnd_extra_width(window), |
| 1191 | 1227 | monitorbounds.top + tempheight + wnd_extra_height(window), |
| 1192 | 1228 | SWP_NOZORDER); |
| 1193 | 1229 | |
| 1194 | 1230 | // maximum or minimize as appropriate |
| 1195 | | if (window->startmaximized) |
| 1231 | if (window->m_startmaximized) |
| 1196 | 1232 | maximize_window(window); |
| 1197 | 1233 | else |
| 1198 | 1234 | minimize_window(window); |
| 1199 | 1235 | adjust_window_position_after_major_change(window); |
| 1200 | 1236 | |
| 1201 | 1237 | // show the window |
| 1202 | | if (!window->fullscreen || window->fullscreen_safe) |
| 1238 | if (!window->m_fullscreen || window->m_fullscreen_safe) |
| 1203 | 1239 | { |
| 1204 | 1240 | // finish off by trying to initialize DirectX; if we fail, ignore it |
| 1205 | 1241 | if ((*draw.window_init)(window)) |
| 1206 | 1242 | return 1; |
| 1207 | | ShowWindow(window->hwnd, SW_SHOW); |
| 1243 | ShowWindow(window->m_hwnd, SW_SHOW); |
| 1208 | 1244 | } |
| 1209 | 1245 | |
| 1210 | 1246 | // clear the window |
| 1211 | | dc = GetDC(window->hwnd); |
| 1212 | | GetClientRect(window->hwnd, &client); |
| 1247 | dc = GetDC(window->m_hwnd); |
| 1248 | GetClientRect(window->m_hwnd, &client); |
| 1213 | 1249 | FillRect(dc, &client, (HBRUSH)GetStockObject(BLACK_BRUSH)); |
| 1214 | | ReleaseDC(window->hwnd, dc); |
| 1250 | ReleaseDC(window->m_hwnd, dc); |
| 1215 | 1251 | return 0; |
| 1216 | 1252 | } |
| 1217 | 1253 | |
| r31854 | r31855 | |
| 1244 | 1280 | HDC hdc = BeginPaint(wnd, &pstruct); |
| 1245 | 1281 | draw_video_contents(window, hdc, TRUE); |
| 1246 | 1282 | if (win_has_menu(window)) |
| 1247 | | DrawMenuBar(window->hwnd); |
| 1283 | DrawMenuBar(window->m_hwnd); |
| 1248 | 1284 | EndPaint(wnd, &pstruct); |
| 1249 | 1285 | break; |
| 1250 | 1286 | } |
| 1251 | 1287 | |
| 1252 | 1288 | // non-client paint: punt if full screen |
| 1253 | 1289 | case WM_NCPAINT: |
| 1254 | | if (!window->fullscreen || win_has_menu(window)) |
| 1290 | if (!window->m_fullscreen || win_has_menu(window)) |
| 1255 | 1291 | return DefWindowProc(wnd, message, wparam, lparam); |
| 1256 | 1292 | break; |
| 1257 | 1293 | |
| r31854 | r31855 | |
| 1267 | 1303 | |
| 1268 | 1304 | // input events |
| 1269 | 1305 | case WM_MOUSEMOVE: |
| 1270 | | ui_input_push_mouse_move_event(window->machine(), window->target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)); |
| 1306 | ui_input_push_mouse_move_event(window->machine(), window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)); |
| 1271 | 1307 | break; |
| 1272 | 1308 | |
| 1273 | 1309 | case WM_MOUSELEAVE: |
| 1274 | | ui_input_push_mouse_leave_event(window->machine(), window->target); |
| 1310 | ui_input_push_mouse_leave_event(window->machine(), window->m_target); |
| 1275 | 1311 | break; |
| 1276 | 1312 | |
| 1277 | 1313 | case WM_LBUTTONDOWN: |
| 1278 | 1314 | { |
| 1279 | 1315 | DWORD ticks = GetTickCount(); |
| 1280 | | ui_input_push_mouse_down_event(window->machine(), window->target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)); |
| 1316 | ui_input_push_mouse_down_event(window->machine(), window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)); |
| 1281 | 1317 | |
| 1282 | 1318 | // check for a double-click |
| 1283 | | if (ticks - window->lastclicktime < GetDoubleClickTime() && |
| 1284 | | GET_X_LPARAM(lparam) >= window->lastclickx - 4 && GET_X_LPARAM(lparam) <= window->lastclickx + 4 && |
| 1285 | | GET_Y_LPARAM(lparam) >= window->lastclicky - 4 && GET_Y_LPARAM(lparam) <= window->lastclicky + 4) |
| 1319 | if (ticks - window->m_lastclicktime < GetDoubleClickTime() && |
| 1320 | GET_X_LPARAM(lparam) >= window->m_lastclickx - 4 && GET_X_LPARAM(lparam) <= window->m_lastclickx + 4 && |
| 1321 | GET_Y_LPARAM(lparam) >= window->m_lastclicky - 4 && GET_Y_LPARAM(lparam) <= window->m_lastclicky + 4) |
| 1286 | 1322 | { |
| 1287 | | window->lastclicktime = 0; |
| 1288 | | ui_input_push_mouse_double_click_event(window->machine(), window->target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)); |
| 1323 | window->m_lastclicktime = 0; |
| 1324 | ui_input_push_mouse_double_click_event(window->machine(), window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)); |
| 1289 | 1325 | } |
| 1290 | 1326 | else |
| 1291 | 1327 | { |
| 1292 | | window->lastclicktime = ticks; |
| 1293 | | window->lastclickx = GET_X_LPARAM(lparam); |
| 1294 | | window->lastclicky = GET_Y_LPARAM(lparam); |
| 1328 | window->m_lastclicktime = ticks; |
| 1329 | window->m_lastclickx = GET_X_LPARAM(lparam); |
| 1330 | window->m_lastclicky = GET_Y_LPARAM(lparam); |
| 1295 | 1331 | } |
| 1296 | 1332 | break; |
| 1297 | 1333 | } |
| 1298 | 1334 | |
| 1299 | 1335 | case WM_LBUTTONUP: |
| 1300 | | ui_input_push_mouse_up_event(window->machine(), window->target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)); |
| 1336 | ui_input_push_mouse_up_event(window->machine(), window->m_target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)); |
| 1301 | 1337 | break; |
| 1302 | 1338 | |
| 1303 | 1339 | case WM_CHAR: |
| 1304 | | ui_input_push_char_event(window->machine(), window->target, (unicode_char) wparam); |
| 1340 | ui_input_push_char_event(window->machine(), window->m_target, (unicode_char) wparam); |
| 1305 | 1341 | break; |
| 1306 | 1342 | |
| 1307 | 1343 | // pause the system when we start a menu or resize |
| 1308 | 1344 | case WM_ENTERSIZEMOVE: |
| 1309 | | window->resize_state = RESIZE_STATE_RESIZING; |
| 1345 | window->m_resize_state = RESIZE_STATE_RESIZING; |
| 1310 | 1346 | case WM_ENTERMENULOOP: |
| 1311 | 1347 | winwindow_ui_pause_from_window_thread(window->machine(), TRUE); |
| 1312 | 1348 | break; |
| 1313 | 1349 | |
| 1314 | 1350 | // unpause the system when we stop a menu or resize and force a redraw |
| 1315 | 1351 | case WM_EXITSIZEMOVE: |
| 1316 | | window->resize_state = RESIZE_STATE_PENDING; |
| 1352 | window->m_resize_state = RESIZE_STATE_PENDING; |
| 1317 | 1353 | case WM_EXITMENULOOP: |
| 1318 | 1354 | winwindow_ui_pause_from_window_thread(window->machine(), FALSE); |
| 1319 | 1355 | InvalidateRect(wnd, NULL, FALSE); |
| r31854 | r31855 | |
| 1354 | 1390 | if (cmd == SC_MAXIMIZE) |
| 1355 | 1391 | { |
| 1356 | 1392 | update_minmax_state(window); |
| 1357 | | if (window->ismaximized) |
| 1393 | if (window->m_ismaximized) |
| 1358 | 1394 | minimize_window(window); |
| 1359 | 1395 | else |
| 1360 | 1396 | maximize_window(window); |
| r31854 | r31855 | |
| 1379 | 1415 | // destroy: clean up all attached rendering bits and NULL out our hwnd |
| 1380 | 1416 | case WM_DESTROY: |
| 1381 | 1417 | (*draw.window_destroy)(window); |
| 1382 | | window->hwnd = NULL; |
| 1418 | window->m_hwnd = NULL; |
| 1383 | 1419 | return DefWindowProc(wnd, message, wparam, lparam); |
| 1384 | 1420 | |
| 1385 | 1421 | // self redraw: draw ourself in a non-painty way |
| r31854 | r31855 | |
| 1388 | 1424 | HDC hdc = GetDC(wnd); |
| 1389 | 1425 | |
| 1390 | 1426 | mtlog_add("winwindow_video_window_proc: WM_USER_REDRAW begin"); |
| 1391 | | window->primlist = (render_primitive_list *)lparam; |
| 1427 | window->m_primlist = (render_primitive_list *)lparam; |
| 1392 | 1428 | draw_video_contents(window, hdc, FALSE); |
| 1393 | 1429 | mtlog_add("winwindow_video_window_proc: WM_USER_REDRAW end"); |
| 1394 | 1430 | |
| r31854 | r31855 | |
| 1398 | 1434 | |
| 1399 | 1435 | // self destruct |
| 1400 | 1436 | case WM_USER_SELF_TERMINATE: |
| 1401 | | DestroyWindow(window->hwnd); |
| 1437 | DestroyWindow(window->m_hwnd); |
| 1402 | 1438 | break; |
| 1403 | 1439 | |
| 1404 | 1440 | // fullscreen set |
| r31854 | r31855 | |
| 1420 | 1456 | // commented out ATM because this prevents us from resizing secondary windows |
| 1421 | 1457 | // case WM_SETFOCUS: |
| 1422 | 1458 | // if (window != win_window_list && win_window_list != NULL) |
| 1423 | | // SetFocus(win_window_list->hwnd); |
| 1459 | // SetFocus(win_window_list->m_hwnd); |
| 1424 | 1460 | // break; |
| 1425 | 1461 | |
| 1426 | 1462 | // everything else: defaults |
| r31854 | r31855 | |
| 1445 | 1481 | mtlog_add("draw_video_contents: begin"); |
| 1446 | 1482 | |
| 1447 | 1483 | mtlog_add("draw_video_contents: render lock acquire"); |
| 1448 | | osd_lock_acquire(window->render_lock); |
| 1484 | osd_lock_acquire(window->m_render_lock); |
| 1449 | 1485 | mtlog_add("draw_video_contents: render lock acquired"); |
| 1450 | 1486 | |
| 1451 | 1487 | // if we're iconic, don't bother |
| 1452 | | if (window->hwnd != NULL && !IsIconic(window->hwnd)) |
| 1488 | if (window->m_hwnd != NULL && !IsIconic(window->m_hwnd)) |
| 1453 | 1489 | { |
| 1454 | 1490 | // if no bitmap, just fill |
| 1455 | | if (window->primlist == NULL) |
| 1491 | if (window->m_primlist == NULL) |
| 1456 | 1492 | { |
| 1457 | 1493 | RECT fill; |
| 1458 | | GetClientRect(window->hwnd, &fill); |
| 1494 | GetClientRect(window->m_hwnd, &fill); |
| 1459 | 1495 | FillRect(dc, &fill, (HBRUSH)GetStockObject(BLACK_BRUSH)); |
| 1460 | 1496 | } |
| 1461 | 1497 | |
| r31854 | r31855 | |
| 1467 | 1503 | } |
| 1468 | 1504 | } |
| 1469 | 1505 | |
| 1470 | | osd_lock_release(window->render_lock); |
| 1506 | osd_lock_release(window->m_render_lock); |
| 1471 | 1507 | mtlog_add("draw_video_contents: render lock released"); |
| 1472 | 1508 | |
| 1473 | 1509 | mtlog_add("draw_video_contents: end"); |
| r31854 | r31855 | |
| 1495 | 1531 | assert(GetCurrentThreadId() == window_threadid); |
| 1496 | 1532 | |
| 1497 | 1533 | // get the pixel aspect ratio for the target monitor |
| 1498 | | pixel_aspect = winvideo_monitor_get_aspect(monitor); |
| 1534 | pixel_aspect = monitor->get_aspect(); |
| 1499 | 1535 | |
| 1500 | 1536 | // determine the proposed width/height |
| 1501 | 1537 | propwidth = rect_width(rect) - extrawidth; |
| r31854 | r31855 | |
| 1507 | 1543 | { |
| 1508 | 1544 | case WMSZ_BOTTOM: |
| 1509 | 1545 | case WMSZ_TOP: |
| 1510 | | window->target->compute_visible_area(10000, propheight, pixel_aspect, window->target->orientation(), propwidth, propheight); |
| 1546 | window->m_target->compute_visible_area(10000, propheight, pixel_aspect, window->m_target->orientation(), propwidth, propheight); |
| 1511 | 1547 | break; |
| 1512 | 1548 | |
| 1513 | 1549 | case WMSZ_LEFT: |
| 1514 | 1550 | case WMSZ_RIGHT: |
| 1515 | | window->target->compute_visible_area(propwidth, 10000, pixel_aspect, window->target->orientation(), propwidth, propheight); |
| 1551 | window->m_target->compute_visible_area(propwidth, 10000, pixel_aspect, window->m_target->orientation(), propwidth, propheight); |
| 1516 | 1552 | break; |
| 1517 | 1553 | |
| 1518 | 1554 | default: |
| 1519 | | window->target->compute_visible_area(propwidth, propheight, pixel_aspect, window->target->orientation(), propwidth, propheight); |
| 1555 | window->m_target->compute_visible_area(propwidth, propheight, pixel_aspect, window->m_target->orientation(), propwidth, propheight); |
| 1520 | 1556 | break; |
| 1521 | 1557 | } |
| 1522 | 1558 | |
| 1523 | 1559 | // get the minimum width/height for the current layout |
| 1524 | | window->target->compute_minimum_size(minwidth, minheight); |
| 1560 | window->m_target->compute_minimum_size(minwidth, minheight); |
| 1525 | 1561 | |
| 1526 | 1562 | // clamp against the absolute minimum |
| 1527 | 1563 | propwidth = MAX(propwidth, MIN_WINDOW_DIM); |
| r31854 | r31855 | |
| 1532 | 1568 | propheight = MAX(propheight, minheight); |
| 1533 | 1569 | |
| 1534 | 1570 | // clamp against the maximum (fit on one screen for full screen mode) |
| 1535 | | if (window->fullscreen) |
| 1571 | if (window->m_fullscreen) |
| 1536 | 1572 | { |
| 1537 | 1573 | maxwidth = rect_width(&monitor->info.rcMonitor) - extrawidth; |
| 1538 | 1574 | maxheight = rect_height(&monitor->info.rcMonitor) - extraheight; |
| r31854 | r31855 | |
| 1543 | 1579 | maxheight = rect_height(&monitor->info.rcWork) - extraheight; |
| 1544 | 1580 | |
| 1545 | 1581 | // further clamp to the maximum width/height in the window |
| 1546 | | if (window->maxwidth != 0) |
| 1547 | | maxwidth = MIN(maxwidth, window->maxwidth + extrawidth); |
| 1548 | | if (window->maxheight != 0) |
| 1549 | | maxheight = MIN(maxheight, window->maxheight + extraheight); |
| 1582 | if (window->m_maxwidth != 0) |
| 1583 | maxwidth = MIN(maxwidth, window->m_maxwidth + extrawidth); |
| 1584 | if (window->m_maxheight != 0) |
| 1585 | maxheight = MIN(maxheight, window->m_maxheight + extraheight); |
| 1550 | 1586 | } |
| 1551 | 1587 | |
| 1552 | 1588 | // clamp to the maximum |
| r31854 | r31855 | |
| 1554 | 1590 | propheight = MIN(propheight, maxheight); |
| 1555 | 1591 | |
| 1556 | 1592 | // compute the visible area based on the proposed rectangle |
| 1557 | | window->target->compute_visible_area(propwidth, propheight, pixel_aspect, window->target->orientation(), viswidth, visheight); |
| 1593 | window->m_target->compute_visible_area(propwidth, propheight, pixel_aspect, window->m_target->orientation(), viswidth, visheight); |
| 1558 | 1594 | |
| 1559 | 1595 | // compute the adjustments we need to make |
| 1560 | 1596 | adjwidth = (viswidth + extrawidth) - rect_width(rect); |
| r31854 | r31855 | |
| 1603 | 1639 | assert(GetCurrentThreadId() == window_threadid); |
| 1604 | 1640 | |
| 1605 | 1641 | // get the minimum target size |
| 1606 | | window->target->compute_minimum_size(minwidth, minheight); |
| 1642 | window->m_target->compute_minimum_size(minwidth, minheight); |
| 1607 | 1643 | |
| 1608 | 1644 | // expand to our minimum dimensions |
| 1609 | 1645 | if (minwidth < MIN_WINDOW_DIM) |
| r31854 | r31855 | |
| 1646 | 1682 | } |
| 1647 | 1683 | |
| 1648 | 1684 | // get the window rect |
| 1649 | | GetWindowRect(window->hwnd, bounds); |
| 1685 | GetWindowRect(window->m_hwnd, bounds); |
| 1650 | 1686 | |
| 1651 | 1687 | // now adjust |
| 1652 | 1688 | bounds->right = bounds->left + minwidth; |
| r31854 | r31855 | |
| 1667 | 1703 | assert(GetCurrentThreadId() == window_threadid); |
| 1668 | 1704 | |
| 1669 | 1705 | // compute the maximum client area |
| 1670 | | winvideo_monitor_refresh(window->monitor); |
| 1671 | | maximum = window->monitor->info.rcWork; |
| 1706 | window->m_monitor->refresh(); |
| 1707 | maximum = window->m_monitor->info.rcWork; |
| 1672 | 1708 | |
| 1673 | 1709 | // clamp to the window's max |
| 1674 | | if (window->maxwidth != 0) |
| 1710 | if (window->m_maxwidth != 0) |
| 1675 | 1711 | { |
| 1676 | | int temp = window->maxwidth + wnd_extra_width(window); |
| 1712 | int temp = window->m_maxwidth + wnd_extra_width(window); |
| 1677 | 1713 | if (temp < rect_width(&maximum)) |
| 1678 | 1714 | maximum.right = maximum.left + temp; |
| 1679 | 1715 | } |
| 1680 | | if (window->maxheight != 0) |
| 1716 | if (window->m_maxheight != 0) |
| 1681 | 1717 | { |
| 1682 | | int temp = window->maxheight + wnd_extra_height(window); |
| 1718 | int temp = window->m_maxheight + wnd_extra_height(window); |
| 1683 | 1719 | if (temp < rect_height(&maximum)) |
| 1684 | 1720 | maximum.bottom = maximum.top + temp; |
| 1685 | 1721 | } |
| r31854 | r31855 | |
| 1694 | 1730 | } |
| 1695 | 1731 | |
| 1696 | 1732 | // center within the work area |
| 1697 | | bounds->left = window->monitor->info.rcWork.left + (rect_width(&window->monitor->info.rcWork) - rect_width(&maximum)) / 2; |
| 1698 | | bounds->top = window->monitor->info.rcWork.top + (rect_height(&window->monitor->info.rcWork) - rect_height(&maximum)) / 2; |
| 1733 | bounds->left = window->m_monitor->info.rcWork.left + (rect_width(&window->m_monitor->info.rcWork) - rect_width(&maximum)) / 2; |
| 1734 | bounds->top = window->m_monitor->info.rcWork.top + (rect_height(&window->m_monitor->info.rcWork) - rect_height(&maximum)) / 2; |
| 1699 | 1735 | bounds->right = bounds->left + rect_width(&maximum); |
| 1700 | 1736 | bounds->bottom = bounds->top + rect_height(&maximum); |
| 1701 | 1737 | } |
| r31854 | r31855 | |
| 1711 | 1747 | { |
| 1712 | 1748 | assert(GetCurrentThreadId() == window_threadid); |
| 1713 | 1749 | |
| 1714 | | if (!window->fullscreen) |
| 1750 | if (!window->m_fullscreen) |
| 1715 | 1751 | { |
| 1716 | 1752 | RECT bounds, minbounds, maxbounds; |
| 1717 | 1753 | |
| 1718 | 1754 | // compare the maximum bounds versus the current bounds |
| 1719 | 1755 | get_min_bounds(window, &minbounds, video_config.keepaspect); |
| 1720 | 1756 | get_max_bounds(window, &maxbounds, video_config.keepaspect); |
| 1721 | | GetWindowRect(window->hwnd, &bounds); |
| 1757 | GetWindowRect(window->m_hwnd, &bounds); |
| 1722 | 1758 | |
| 1723 | 1759 | // if either the width or height matches, we were maximized |
| 1724 | | window->isminimized = (rect_width(&bounds) == rect_width(&minbounds) || |
| 1760 | window->m_isminimized = (rect_width(&bounds) == rect_width(&minbounds) || |
| 1725 | 1761 | rect_height(&bounds) == rect_height(&minbounds)); |
| 1726 | | window->ismaximized = (rect_width(&bounds) == rect_width(&maxbounds) || |
| 1762 | window->m_ismaximized = (rect_width(&bounds) == rect_width(&maxbounds) || |
| 1727 | 1763 | rect_height(&bounds) == rect_height(&maxbounds)); |
| 1728 | 1764 | } |
| 1729 | 1765 | else |
| 1730 | 1766 | { |
| 1731 | | window->isminimized = FALSE; |
| 1732 | | window->ismaximized = TRUE; |
| 1767 | window->m_isminimized = FALSE; |
| 1768 | window->m_ismaximized = TRUE; |
| 1733 | 1769 | } |
| 1734 | 1770 | } |
| 1735 | 1771 | |
| r31854 | r31855 | |
| 1747 | 1783 | assert(GetCurrentThreadId() == window_threadid); |
| 1748 | 1784 | |
| 1749 | 1785 | get_min_bounds(window, &newsize, video_config.keepaspect); |
| 1750 | | SetWindowPos(window->hwnd, NULL, newsize.left, newsize.top, rect_width(&newsize), rect_height(&newsize), SWP_NOZORDER); |
| 1786 | SetWindowPos(window->m_hwnd, NULL, newsize.left, newsize.top, rect_width(&newsize), rect_height(&newsize), SWP_NOZORDER); |
| 1751 | 1787 | } |
| 1752 | 1788 | |
| 1753 | 1789 | |
| r31854 | r31855 | |
| 1764 | 1800 | assert(GetCurrentThreadId() == window_threadid); |
| 1765 | 1801 | |
| 1766 | 1802 | get_max_bounds(window, &newsize, video_config.keepaspect); |
| 1767 | | SetWindowPos(window->hwnd, NULL, newsize.left, newsize.top, rect_width(&newsize), rect_height(&newsize), SWP_NOZORDER); |
| 1803 | SetWindowPos(window->m_hwnd, NULL, newsize.left, newsize.top, rect_width(&newsize), rect_height(&newsize), SWP_NOZORDER); |
| 1768 | 1804 | } |
| 1769 | 1805 | |
| 1770 | 1806 | |
| r31854 | r31855 | |
| 1781 | 1817 | assert(GetCurrentThreadId() == window_threadid); |
| 1782 | 1818 | |
| 1783 | 1819 | // get the current size |
| 1784 | | GetWindowRect(window->hwnd, &oldrect); |
| 1820 | GetWindowRect(window->m_hwnd, &oldrect); |
| 1785 | 1821 | |
| 1786 | 1822 | // adjust the window size so the client area is what we want |
| 1787 | | if (!window->fullscreen) |
| 1823 | if (!window->m_fullscreen) |
| 1788 | 1824 | { |
| 1789 | 1825 | // constrain the existing size to the aspect ratio |
| 1790 | 1826 | newrect = oldrect; |
| r31854 | r31855 | |
| 1802 | 1838 | // adjust the position if different |
| 1803 | 1839 | if (oldrect.left != newrect.left || oldrect.top != newrect.top || |
| 1804 | 1840 | oldrect.right != newrect.right || oldrect.bottom != newrect.bottom) |
| 1805 | | SetWindowPos(window->hwnd, window->fullscreen ? HWND_TOPMOST : HWND_TOP, |
| 1841 | SetWindowPos(window->m_hwnd, window->m_fullscreen ? HWND_TOPMOST : HWND_TOP, |
| 1806 | 1842 | newrect.left, newrect.top, |
| 1807 | 1843 | rect_width(&newrect), rect_height(&newrect), 0); |
| 1808 | 1844 | |
| r31854 | r31855 | |
| 1827 | 1863 | assert(GetCurrentThreadId() == window_threadid); |
| 1828 | 1864 | |
| 1829 | 1865 | // if we're in the right state, punt |
| 1830 | | if (window->fullscreen == fullscreen) |
| 1866 | if (window->m_fullscreen == fullscreen) |
| 1831 | 1867 | return; |
| 1832 | | window->fullscreen = fullscreen; |
| 1868 | window->m_fullscreen = fullscreen; |
| 1833 | 1869 | |
| 1834 | 1870 | // kill off the drawers |
| 1835 | 1871 | (*draw.window_destroy)(window); |
| 1836 | 1872 | |
| 1837 | 1873 | // hide ourself |
| 1838 | | ShowWindow(window->hwnd, SW_HIDE); |
| 1874 | ShowWindow(window->m_hwnd, SW_HIDE); |
| 1839 | 1875 | |
| 1840 | 1876 | // configure the window if non-fullscreen |
| 1841 | 1877 | if (!fullscreen) |
| 1842 | 1878 | { |
| 1843 | 1879 | // adjust the style |
| 1844 | | SetWindowLong(window->hwnd, GWL_STYLE, WINDOW_STYLE); |
| 1845 | | SetWindowLong(window->hwnd, GWL_EXSTYLE, WINDOW_STYLE_EX); |
| 1846 | | SetWindowPos(window->hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); |
| 1880 | SetWindowLong(window->m_hwnd, GWL_STYLE, WINDOW_STYLE); |
| 1881 | SetWindowLong(window->m_hwnd, GWL_EXSTYLE, WINDOW_STYLE_EX); |
| 1882 | SetWindowPos(window->m_hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); |
| 1847 | 1883 | |
| 1848 | 1884 | // force to the bottom, then back on top |
| 1849 | | SetWindowPos(window->hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); |
| 1850 | | SetWindowPos(window->hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); |
| 1885 | SetWindowPos(window->m_hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); |
| 1886 | SetWindowPos(window->m_hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); |
| 1851 | 1887 | |
| 1852 | 1888 | // if we have previous non-fullscreen bounds, use those |
| 1853 | | if (window->non_fullscreen_bounds.right != window->non_fullscreen_bounds.left) |
| 1889 | if (window->m_non_fullscreen_bounds.right != window->m_non_fullscreen_bounds.left) |
| 1854 | 1890 | { |
| 1855 | | SetWindowPos(window->hwnd, HWND_TOP, window->non_fullscreen_bounds.left, window->non_fullscreen_bounds.top, |
| 1856 | | rect_width(&window->non_fullscreen_bounds), rect_height(&window->non_fullscreen_bounds), |
| 1891 | SetWindowPos(window->m_hwnd, HWND_TOP, window->m_non_fullscreen_bounds.left, window->m_non_fullscreen_bounds.top, |
| 1892 | rect_width(&window->m_non_fullscreen_bounds), rect_height(&window->m_non_fullscreen_bounds), |
| 1857 | 1893 | SWP_NOZORDER); |
| 1858 | 1894 | } |
| 1859 | 1895 | |
| 1860 | 1896 | // otherwise, set a small size and maximize from there |
| 1861 | 1897 | else |
| 1862 | 1898 | { |
| 1863 | | SetWindowPos(window->hwnd, HWND_TOP, 0, 0, MIN_WINDOW_DIM, MIN_WINDOW_DIM, SWP_NOZORDER); |
| 1899 | SetWindowPos(window->m_hwnd, HWND_TOP, 0, 0, MIN_WINDOW_DIM, MIN_WINDOW_DIM, SWP_NOZORDER); |
| 1864 | 1900 | maximize_window(window); |
| 1865 | 1901 | } |
| 1866 | 1902 | } |
| r31854 | r31855 | |
| 1869 | 1905 | else |
| 1870 | 1906 | { |
| 1871 | 1907 | // save the bounds |
| 1872 | | GetWindowRect(window->hwnd, &window->non_fullscreen_bounds); |
| 1908 | GetWindowRect(window->m_hwnd, &window->m_non_fullscreen_bounds); |
| 1873 | 1909 | |
| 1874 | 1910 | // adjust the style |
| 1875 | | SetWindowLong(window->hwnd, GWL_STYLE, FULLSCREEN_STYLE); |
| 1876 | | SetWindowLong(window->hwnd, GWL_EXSTYLE, FULLSCREEN_STYLE_EX); |
| 1877 | | SetWindowPos(window->hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); |
| 1911 | SetWindowLong(window->m_hwnd, GWL_STYLE, FULLSCREEN_STYLE); |
| 1912 | SetWindowLong(window->m_hwnd, GWL_EXSTYLE, FULLSCREEN_STYLE_EX); |
| 1913 | SetWindowPos(window->m_hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); |
| 1878 | 1914 | |
| 1879 | 1915 | // set topmost |
| 1880 | | SetWindowPos(window->hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); |
| 1916 | SetWindowPos(window->m_hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); |
| 1881 | 1917 | } |
| 1882 | 1918 | |
| 1883 | 1919 | // adjust the window to compensate for the change |
| 1884 | 1920 | adjust_window_position_after_major_change(window); |
| 1885 | 1921 | |
| 1886 | 1922 | // show ourself |
| 1887 | | if (!window->fullscreen || window->fullscreen_safe) |
| 1923 | if (!window->m_fullscreen || window->m_fullscreen_safe) |
| 1888 | 1924 | { |
| 1889 | 1925 | if (video_config.mode != VIDEO_MODE_NONE) |
| 1890 | | ShowWindow(window->hwnd, SW_SHOW); |
| 1926 | ShowWindow(window->m_hwnd, SW_SHOW); |
| 1891 | 1927 | if ((*draw.window_init)(window)) |
| 1892 | 1928 | exit(1); |
| 1893 | 1929 | } |