| 3374 | } |
| 3375 | |
| 3376 | bool Win32Frame::GetBestDisplayResolutionForFullScreen(UINT& bestWidth, UINT& bestHeight, UINT userSpecifiedWidth/*=0*/, UINT userSpecifiedHeight/*=0*/) |
| 3377 | { |
| 3378 | m_bestWidthForFullScreen = 0; |
| 3379 | m_bestHeightForFullScreen = 0; |
| 3380 | |
| 3381 | typedef std::vector< std::pair<UINT,UINT> > VEC_PAIR; |
| 3382 | VEC_PAIR vecDisplayResolutions; |
| 3383 | |
| 3384 | for (UINT iModeNum = 0; ; iModeNum++) |
| 3385 | { |
| 3386 | DEVMODE devMode; |
| 3387 | devMode.dmSize = sizeof(DEVMODE); |
| 3388 | devMode.dmDriverExtra = 0; |
| 3389 | BOOL bValid = EnumDisplaySettings(NULL, iModeNum, &devMode); |
| 3390 | if (!bValid) |
| 3391 | break; |
| 3392 | if (iModeNum == 0) // 0 is the initial "cache info about display device" operation |
| 3393 | continue; |
| 3394 | |
| 3395 | if (devMode.dmBitsPerPel != 32) |
| 3396 | continue; |
| 3397 | |
| 3398 | if (userSpecifiedHeight == 0 || userSpecifiedHeight == devMode.dmPelsHeight) |
| 3399 | { |
| 3400 | if (vecDisplayResolutions.size() == 0 || vecDisplayResolutions.back() != std::pair<UINT,UINT>(devMode.dmPelsWidth, devMode.dmPelsHeight) ) // Skip duplicate resolutions |
| 3401 | { |
| 3402 | vecDisplayResolutions.push_back( std::pair<UINT,UINT>(devMode.dmPelsWidth, devMode.dmPelsHeight) ); |
| 3403 | LogFileOutput("EnumDisplaySettings(%d) - %d x %d (ratio=%f)\n", iModeNum, devMode.dmPelsWidth, devMode.dmPelsHeight, (float)devMode.dmPelsWidth/(float)devMode.dmPelsHeight); |
| 3404 | } |
| 3405 | } |
| 3406 | } |
| 3407 | |
| 3408 | if (userSpecifiedHeight) |
| 3409 | { |
| 3410 | if (vecDisplayResolutions.size() == 0) |
| 3411 | return false; |
| 3412 | |
| 3413 | // Pick user-specific width if it exists |
| 3414 | // Else pick least width (such that it's wide enough to scale) |
| 3415 | UINT width = (UINT)-1; |
| 3416 | for (VEC_PAIR::iterator it = vecDisplayResolutions.begin(); it!= vecDisplayResolutions.end(); ++it) |
| 3417 | { |
| 3418 | if (it->first == userSpecifiedWidth) |
| 3419 | { |
| 3420 | width = userSpecifiedWidth; |
| 3421 | break; |
| 3422 | } |
| 3423 | |
| 3424 | if (width > it->first) |
| 3425 | { |
| 3426 | UINT scaleFactor = it->second / GetVideo().GetFrameBufferBorderlessHeight(); |
| 3427 | if (it->first >= (GetVideo().GetFrameBufferBorderlessWidth() * scaleFactor)) |
| 3428 | { |
| 3429 | width = it->first; |
| 3430 | } |
| 3431 | } |
| 3432 | } |
| 3433 |
no test coverage detected