tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

screen_capture_utils.h (3649B)


      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 #include <optional>
     15 #include <string>
     16 #include <vector>
     17 
     18 #include "modules/desktop_capture/desktop_capturer.h"
     19 #include "modules/desktop_capture/desktop_geometry.h"
     20 #include "rtc_base/system/rtc_export.h"
     21 
     22 #if defined(WEBRTC_WIN)
     23 // Forward declare HMONITOR in a windows.h compatible way so that we can avoid
     24 // including windows.h.
     25 #define WEBRTC_DECLARE_HANDLE(name) \
     26  struct name##__;                  \
     27  typedef struct name##__* name
     28 WEBRTC_DECLARE_HANDLE(HMONITOR);
     29 #undef WEBRTC_DECLARE_HANDLE
     30 #endif
     31 
     32 namespace webrtc {
     33 
     34 // Returns true if the system has at least one active display.
     35 bool HasActiveDisplay();
     36 
     37 // Output the list of active screens into `screens`. Returns true if succeeded,
     38 // or false if it fails to enumerate the display devices. If the `device_names`
     39 // is provided, it will be filled with the DISPLAY_DEVICE.DeviceName in UTF-8
     40 // encoding. If this function returns true, consumers can always assume that
     41 // `screens`[i] and `device_names`[i] indicate the same monitor on the system.
     42 bool GetScreenList(DesktopCapturer::SourceList* screens,
     43                   std::vector<std::string>* device_names = nullptr);
     44 
     45 // Converts a device index (which are returned by `GetScreenList`) into an
     46 // HMONITOR.
     47 bool GetHmonitorFromDeviceIndex(DesktopCapturer::SourceId device_index,
     48                                HMONITOR* hmonitor);
     49 
     50 // Returns true if `monitor` represents a valid display
     51 // monitor. Consumers should recheck the validity of HMONITORs before use if a
     52 // WM_DISPLAYCHANGE message has been received.
     53 bool IsMonitorValid(HMONITOR monitor);
     54 
     55 // Returns the rect of the monitor identified by `monitor`, relative to the
     56 // primary display's top-left. On failure, returns an empty rect.
     57 DesktopRect GetMonitorRect(HMONITOR monitor);
     58 
     59 // Returns the DPI for the specified monitor. On failure, returns the system DPI
     60 // or the Windows default DPI (96x96) if the system DPI can't be retrieved.
     61 DesktopVector GetDpiForMonitor(HMONITOR monitor);
     62 
     63 // Returns true if `screen` is a valid screen. The screen device key is
     64 // returned through `device_key` if the screen is valid. The device key can be
     65 // used in GetScreenRect to verify the screen matches the previously obtained
     66 // id. It calls the EnumDisplayDevices API to check if the screen is valid but
     67 // EnumDisplayDevices is quite slow so the caller of this function should
     68 // be aware of the performance impact.
     69 bool IsScreenValid(DesktopCapturer::SourceId screen, std::wstring* device_key);
     70 
     71 // Get the rect of the entire system in system coordinate system. I.e. the
     72 // primary monitor always starts from (0, 0).
     73 DesktopRect GetFullscreenRect();
     74 
     75 // Get the rect of the screen identified by `screen`, relative to the primary
     76 // display's top-left. If the optional screen device key exists, and does not
     77 // match `device_key`, or the screen does not exist, or any error happens,
     78 // an empty rect is returned.
     79 RTC_EXPORT DesktopRect
     80 GetScreenRect(DesktopCapturer::SourceId screen,
     81              const std::optional<std::wstring>& device_key);
     82 
     83 }  // namespace webrtc
     84 
     85 #endif  // MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURE_UTILS_H_