| 47 | |
| 48 | |
| 49 | double GetRefreshRate(const wchar_t* displayName) |
| 50 | { |
| 51 | UINT32 num_paths; |
| 52 | UINT32 num_modes; |
| 53 | std::vector<DISPLAYCONFIG_PATH_INFO> paths; |
| 54 | std::vector<DISPLAYCONFIG_MODE_INFO> modes; |
| 55 | LONG res; |
| 56 | |
| 57 | // The display configuration could change between the call to |
| 58 | // GetDisplayConfigBufferSizes and the call to QueryDisplayConfig, so call |
| 59 | // them in a loop until the correct buffer size is chosen |
| 60 | do { |
| 61 | res = GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &num_paths, &num_modes); |
| 62 | if (res == ERROR_SUCCESS) { |
| 63 | paths.resize(num_paths); |
| 64 | modes.resize(num_modes); |
| 65 | res = QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &num_paths, paths.data(), &num_modes, modes.data(), nullptr); |
| 66 | } |
| 67 | } while (res == ERROR_INSUFFICIENT_BUFFER); |
| 68 | |
| 69 | if (res == ERROR_SUCCESS) { |
| 70 | // num_paths and num_modes could decrease in a loop |
| 71 | paths.resize(num_paths); |
| 72 | modes.resize(num_modes); |
| 73 | |
| 74 | for (const auto& path : paths) { |
| 75 | // Send a GET_SOURCE_NAME request |
| 76 | DISPLAYCONFIG_SOURCE_DEVICE_NAME source = { |
| 77 | {DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME, sizeof(source), path.sourceInfo.adapterId, path.sourceInfo.id}, {}, |
| 78 | }; |
| 79 | if (DisplayConfigGetDeviceInfo(&source.header) == ERROR_SUCCESS) { |
| 80 | if (wcscmp(displayName, source.viewGdiDeviceName) == 0) { |
| 81 | return get_refresh_rate(path, modes.data()); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return 0.0; |
| 88 | } |
| 89 | |
| 90 | static bool is_valid_refresh_rate(const DISPLAYCONFIG_RATIONAL& rr) |
| 91 | { |
nothing calls this directly
no test coverage detected