M4Err GetDisplayMode(DDContext *dd) { if (dd->switch_res) { HRESULT hr; Bool temp_dd = 0;; if (!dd->pDD) { LPDIRECTDRAW ddraw; DirectDrawCreate(NULL, &ddraw, NULL); #ifdef USE_DX_3 IDirectDraw_QueryInterface(ddraw, &IID_IDirectDraw, (LPVOID *)&dd->pDD); #else IDirectDraw_QueryInterface(ddraw, &IID_IDirectDraw7, (LPVOID *)&dd->pDD); #endif temp_dd = 1; } //we start with a hugde res and downscale dd->fs_width = dd->fs_height = 50000; #ifdef USE_DX_3 hr = IDirectDraw_EnumDisplayModes(dd->pDD, 0L, NULL, dd, (LPDDENUMMODESCALLBACK) EnumDisplayModes); #else hr = IDirectDraw7_EnumDisplayModes(dd->pDD, 0L, NULL, dd, (LPDDENUMMODESCALLBACK2) EnumDisplayModes); #endif if (temp_dd) SAFE_DD_RELEASE(dd->pDD); if (FAILED(hr)) return M4IOErr; } else { dd->fs_width = GetSystemMetrics(SM_CXSCREEN); dd->fs_height = GetSystemMetrics(SM_CYSCREEN); } return M4OK; }
static HRESULT WINAPI IDirectDraw4Impl_EnumDisplayModes(LPDIRECTDRAW4 This, DWORD dwFlags, LPDDSURFACEDESC2 pDDSD, LPVOID context, LPDDENUMMODESCALLBACK2 cb) { return IDirectDraw7_EnumDisplayModes((IDirectDraw7 *)ddraw_from_ddraw4(This), dwFlags, pDDSD, context, cb); }
static HRESULT WINAPI IDirectDraw3Impl_EnumDisplayModes(LPDIRECTDRAW3 This, DWORD dwFlags, LPDDSURFACEDESC pDDSD, LPVOID context, LPDDENUMMODESCALLBACK cb) { struct displaymodescallback_context cbcontext; cbcontext.func = cb; cbcontext.context = context; return IDirectDraw7_EnumDisplayModes((IDirectDraw7 *)ddraw_from_ddraw3(This), dwFlags, (LPDDSURFACEDESC2)pDDSD, &cbcontext, EnumDisplayModesCallbackThunk); }
static void pick_best_mode(win_window_info *window) { dd_info *dd = (dd_info *)window->drawdata; mode_enum_info einfo; HRESULT result; // determine the minimum width/height for the selected target // note: technically we should not be calling this from an alternate window // thread; however, it is only done during init time, and the init code on // the main thread is waiting for us to finish, so it is safe to do so here window->target->compute_minimum_size(einfo.minimum_width, einfo.minimum_height); // use those as the target for now einfo.target_width = einfo.minimum_width * MAX(1, video_config.prescale); einfo.target_height = einfo.minimum_height * MAX(1, video_config.prescale); // determine the refresh rate of the primary screen einfo.target_refresh = 60.0; const screen_device *primary_screen = window->machine().config().first_screen(); if (primary_screen != NULL) einfo.target_refresh = ATTOSECONDS_TO_HZ(primary_screen->refresh_attoseconds()); printf("Target refresh = %f\n", einfo.target_refresh); // if we're not stretching, allow some slop on the minimum since we can handle it if (!video_config.hwstretch) { einfo.minimum_width -= 4; einfo.minimum_height -= 4; } // if we are stretching, aim for a mode approximately 2x the game's resolution else if (video_config.prescale <= 1) { einfo.target_width *= 2; einfo.target_height *= 2; } // fill in the rest of the data einfo.window = window; einfo.best_score = 0.0f; // enumerate the modes mame_printf_verbose("DirectDraw: Selecting video mode...\n"); result = IDirectDraw7_EnumDisplayModes(dd->ddraw, DDEDM_REFRESHRATES, NULL, &einfo, enum_modes_callback); if (result != DD_OK) mame_printf_verbose("DirectDraw: Error %08X during EnumDisplayModes call\n", (int)result); mame_printf_verbose("DirectDraw: Mode selected = %4dx%4d@%3dHz\n", dd->width, dd->height, dd->refresh); }