desktop_display_info_loader_win.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "remoting/host/desktop_display_info_loader.h"
  5. #include <windows.h>
  6. namespace remoting {
  7. namespace {
  8. class DesktopDisplayInfoLoaderWin : public DesktopDisplayInfoLoader {
  9. public:
  10. DesktopDisplayInfoLoaderWin() = default;
  11. ~DesktopDisplayInfoLoaderWin() override = default;
  12. DesktopDisplayInfo GetCurrentDisplayInfo() override;
  13. };
  14. DesktopDisplayInfo DesktopDisplayInfoLoaderWin::GetCurrentDisplayInfo() {
  15. DesktopDisplayInfo result;
  16. BOOL enum_result = TRUE;
  17. for (int device_index = 0;; ++device_index) {
  18. DISPLAY_DEVICE device = {};
  19. device.cb = sizeof(device);
  20. enum_result = EnumDisplayDevices(NULL, device_index, &device, 0);
  21. // |enum_result| is 0 if we have enumerated all devices.
  22. if (!enum_result)
  23. break;
  24. // We only care about active displays.
  25. if (!(device.StateFlags & DISPLAY_DEVICE_ACTIVE))
  26. continue;
  27. bool is_default = false;
  28. if (device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
  29. is_default = true;
  30. // Get additional info about device.
  31. DEVMODE devmode;
  32. devmode.dmSize = sizeof(devmode);
  33. EnumDisplaySettingsEx(device.DeviceName, ENUM_CURRENT_SETTINGS, &devmode,
  34. 0);
  35. DisplayGeometry info;
  36. info.id = device_index;
  37. info.is_default = is_default;
  38. info.x = devmode.dmPosition.x;
  39. info.y = devmode.dmPosition.y;
  40. info.width = devmode.dmPelsWidth;
  41. info.height = devmode.dmPelsHeight;
  42. info.dpi = devmode.dmLogPixels;
  43. info.bpp = devmode.dmBitsPerPel;
  44. result.AddDisplay(info);
  45. }
  46. return result;
  47. }
  48. } // namespace
  49. // static
  50. std::unique_ptr<DesktopDisplayInfoLoader> DesktopDisplayInfoLoader::Create() {
  51. return std::make_unique<DesktopDisplayInfoLoaderWin>();
  52. }
  53. } // namespace remoting