1 /* 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURE_UTILS_H_ 12 #define MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURE_UTILS_H_ 13 14 #if defined(WEBRTC_WIN) 15 // Forward declare HMONITOR in a windows.h compatible way so that we can avoid 16 // including windows.h. 17 #define WEBRTC_DECLARE_HANDLE(name) \ 18 struct name##__; \ 19 typedef struct name##__* name 20 WEBRTC_DECLARE_HANDLE(HMONITOR); 21 #undef WEBRTC_DECLARE_HANDLE 22 #endif 23 24 #include <string> 25 #include <vector> 26 27 #include "modules/desktop_capture/desktop_capturer.h" 28 #include "rtc_base/system/rtc_export.h" 29 30 namespace webrtc { 31 32 // Returns true if the system has at least one active display. 33 bool HasActiveDisplay(); 34 35 // Output the list of active screens into `screens`. Returns true if succeeded, 36 // or false if it fails to enumerate the display devices. If the `device_names` 37 // is provided, it will be filled with the DISPLAY_DEVICE.DeviceName in UTF-8 38 // encoding. If this function returns true, consumers can always assume that 39 // `screens`[i] and `device_names`[i] indicate the same monitor on the system. 40 bool GetScreenList(DesktopCapturer::SourceList* screens, 41 std::vector<std::string>* device_names = nullptr); 42 43 // Converts a device index (which are returned by `GetScreenList`) into an 44 // HMONITOR. 45 bool GetHmonitorFromDeviceIndex(DesktopCapturer::SourceId device_index, 46 HMONITOR* hmonitor); 47 48 // Returns true if `monitor` represents a valid display 49 // monitor. Consumers should recheck the validity of HMONITORs before use if a 50 // WM_DISPLAYCHANGE message has been received. 51 bool IsMonitorValid(HMONITOR monitor); 52 53 // Returns the rect of the monitor identified by `monitor`, relative to the 54 // primary display's top-left. On failure, returns an empty rect. 55 DesktopRect GetMonitorRect(HMONITOR monitor); 56 57 // Returns true if `screen` is a valid screen. The screen device key is 58 // returned through `device_key` if the screen is valid. The device key can be 59 // used in GetScreenRect to verify the screen matches the previously obtained 60 // id. 61 bool IsScreenValid(DesktopCapturer::SourceId screen, std::wstring* device_key); 62 63 // Get the rect of the entire system in system coordinate system. I.e. the 64 // primary monitor always starts from (0, 0). 65 DesktopRect GetFullscreenRect(); 66 67 // Get the rect of the screen identified by `screen`, relative to the primary 68 // display's top-left. If the screen device key does not match `device_key`, or 69 // the screen does not exist, or any error happens, an empty rect is returned. 70 RTC_EXPORT DesktopRect GetScreenRect(DesktopCapturer::SourceId screen, 71 const std::wstring& device_key); 72 73 } // namespace webrtc 74 75 #endif // MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURE_UTILS_H_ 76