OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" | 11 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" |
12 | 12 |
13 #include <windows.h> | 13 #include <windows.h> |
14 | 14 |
15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
16 | 16 |
17 namespace webrtc { | 17 namespace webrtc { |
18 | 18 |
19 bool GetScreenList(DesktopCapturer::SourceList* screens) { | 19 bool GetScreenList(DesktopCapturer::SourceList* screens) { |
20 RTC_DCHECK(screens->size() == 0); | 20 RTC_DCHECK(screens->size() == 0); |
21 | 21 |
22 BOOL enum_result = TRUE; | 22 BOOL enum_result = TRUE; |
23 for (int device_index = 0;; ++device_index) { | 23 for (int device_index = 0;; ++device_index) { |
24 DISPLAY_DEVICE device; | 24 DISPLAY_DEVICE device; |
25 device.cb = sizeof(device); | 25 device.cb = sizeof(device); |
26 enum_result = EnumDisplayDevices(NULL, device_index, &device, 0); | 26 enum_result = EnumDisplayDevices(nullptr, device_index, &device, 0); |
27 | 27 |
28 // |enum_result| is 0 if we have enumerated all devices. | 28 // |enum_result| is 0 if we have enumerated all devices. |
29 if (!enum_result) | 29 if (!enum_result) |
30 break; | 30 break; |
31 | 31 |
32 // We only care about active displays. | 32 // We only care about active displays. |
33 if (!(device.StateFlags & DISPLAY_DEVICE_ACTIVE)) | 33 if (!(device.StateFlags & DISPLAY_DEVICE_ACTIVE)) |
34 continue; | 34 continue; |
35 | 35 |
36 screens->push_back({device_index, std::string()}); | 36 screens->push_back({device_index, std::string()}); |
37 } | 37 } |
38 return true; | 38 return true; |
39 } | 39 } |
40 | 40 |
41 bool IsScreenValid(DesktopCapturer::SourceId screen, std::wstring* device_key) { | 41 bool IsScreenValid(DesktopCapturer::SourceId screen, std::wstring* device_key) { |
42 if (screen == kFullDesktopScreenId) { | 42 if (screen == kFullDesktopScreenId) { |
43 *device_key = L""; | 43 *device_key = L""; |
44 return true; | 44 return true; |
45 } | 45 } |
46 | 46 |
47 DISPLAY_DEVICE device; | 47 DISPLAY_DEVICE device; |
48 device.cb = sizeof(device); | 48 device.cb = sizeof(device); |
49 BOOL enum_result = EnumDisplayDevices(NULL, screen, &device, 0); | 49 BOOL enum_result = EnumDisplayDevices(nullptr, screen, &device, 0); |
50 if (enum_result) | 50 if (enum_result) |
51 *device_key = device.DeviceKey; | 51 *device_key = device.DeviceKey; |
52 | 52 |
53 return !!enum_result; | 53 return !!enum_result; |
54 } | 54 } |
55 | 55 |
56 DesktopRect GetScreenRect(DesktopCapturer::SourceId screen, | 56 DesktopRect GetScreenRect(DesktopCapturer::SourceId screen, |
57 const std::wstring& device_key) { | 57 const std::wstring& device_key) { |
58 if (screen == kFullDesktopScreenId) { | 58 if (screen == kFullDesktopScreenId) { |
59 return DesktopRect::MakeXYWH(GetSystemMetrics(SM_XVIRTUALSCREEN), | 59 return DesktopRect::MakeXYWH(GetSystemMetrics(SM_XVIRTUALSCREEN), |
60 GetSystemMetrics(SM_YVIRTUALSCREEN), | 60 GetSystemMetrics(SM_YVIRTUALSCREEN), |
61 GetSystemMetrics(SM_CXVIRTUALSCREEN), | 61 GetSystemMetrics(SM_CXVIRTUALSCREEN), |
62 GetSystemMetrics(SM_CYVIRTUALSCREEN)); | 62 GetSystemMetrics(SM_CYVIRTUALSCREEN)); |
63 } | 63 } |
64 | 64 |
65 DISPLAY_DEVICE device; | 65 DISPLAY_DEVICE device; |
66 device.cb = sizeof(device); | 66 device.cb = sizeof(device); |
67 BOOL result = EnumDisplayDevices(NULL, screen, &device, 0); | 67 BOOL result = EnumDisplayDevices(nullptr, screen, &device, 0); |
68 if (!result) | 68 if (!result) |
69 return DesktopRect(); | 69 return DesktopRect(); |
70 | 70 |
71 // Verifies the device index still maps to the same display device, to make | 71 // Verifies the device index still maps to the same display device, to make |
72 // sure we are capturing the same device when devices are added or removed. | 72 // sure we are capturing the same device when devices are added or removed. |
73 // DeviceKey is documented as reserved, but it actually contains the registry | 73 // DeviceKey is documented as reserved, but it actually contains the registry |
74 // key for the device and is unique for each monitor, while DeviceID is not. | 74 // key for the device and is unique for each monitor, while DeviceID is not. |
75 if (device_key != device.DeviceKey) | 75 if (device_key != device.DeviceKey) |
76 return DesktopRect(); | 76 return DesktopRect(); |
77 | 77 |
78 DEVMODE device_mode; | 78 DEVMODE device_mode; |
79 device_mode.dmSize = sizeof(device_mode); | 79 device_mode.dmSize = sizeof(device_mode); |
80 device_mode.dmDriverExtra = 0; | 80 device_mode.dmDriverExtra = 0; |
81 result = EnumDisplaySettingsEx( | 81 result = EnumDisplaySettingsEx( |
82 device.DeviceName, ENUM_CURRENT_SETTINGS, &device_mode, 0); | 82 device.DeviceName, ENUM_CURRENT_SETTINGS, &device_mode, 0); |
83 if (!result) | 83 if (!result) |
84 return DesktopRect(); | 84 return DesktopRect(); |
85 | 85 |
86 return DesktopRect::MakeXYWH(device_mode.dmPosition.x, | 86 return DesktopRect::MakeXYWH(device_mode.dmPosition.x, |
87 device_mode.dmPosition.y, | 87 device_mode.dmPosition.y, |
88 device_mode.dmPelsWidth, | 88 device_mode.dmPelsWidth, |
89 device_mode.dmPelsHeight); | 89 device_mode.dmPelsHeight); |
90 } | 90 } |
91 | 91 |
92 } // namespace webrtc | 92 } // namespace webrtc |
OLD | NEW |