tor-browser

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

display_configuration_monitor.cc (2220B)


      1 /*
      2 *  Copyright (c) 2017 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 #include "modules/desktop_capture/win/display_configuration_monitor.h"
     12 
     13 #include <windows.h>
     14 
     15 #include <utility>
     16 
     17 #include "modules/desktop_capture/desktop_capture_types.h"
     18 #include "modules/desktop_capture/desktop_capturer.h"
     19 #include "modules/desktop_capture/desktop_geometry.h"
     20 #include "modules/desktop_capture/win/screen_capture_utils.h"
     21 #include "rtc_base/logging.h"
     22 
     23 namespace webrtc {
     24 
     25 bool DisplayConfigurationMonitor::IsChanged(
     26    DesktopCapturer::SourceId source_id) {
     27  DesktopRect rect = GetFullscreenRect();
     28  DesktopVector dpi = GetDpiForSourceId(source_id);
     29 
     30  if (!initialized_) {
     31    initialized_ = true;
     32    rect_ = rect;
     33    source_dpis_.emplace(source_id, std::move(dpi));
     34    return false;
     35  }
     36 
     37  if (!source_dpis_.contains(source_id)) {
     38    // If this is the first time we've seen this source_id, use the current DPI
     39    // so the monitor does not indicate a change and possibly get reset.
     40    source_dpis_.emplace(source_id, dpi);
     41  }
     42 
     43  bool has_changed = false;
     44  if (!rect.equals(rect_) || !source_dpis_.at(source_id).equals(dpi)) {
     45    has_changed = true;
     46    rect_ = rect;
     47    source_dpis_.emplace(source_id, std::move(dpi));
     48  }
     49 
     50  return has_changed;
     51 }
     52 
     53 void DisplayConfigurationMonitor::Reset() {
     54  initialized_ = false;
     55  source_dpis_.clear();
     56  rect_ = {};
     57 }
     58 
     59 DesktopVector DisplayConfigurationMonitor::GetDpiForSourceId(
     60    DesktopCapturer::SourceId source_id) {
     61  HMONITOR monitor = 0;
     62  if (source_id == kFullDesktopScreenId) {
     63    // Get a handle to the primary monitor when capturing the full desktop.
     64    monitor = MonitorFromPoint({0, 0}, MONITOR_DEFAULTTOPRIMARY);
     65  } else if (!GetHmonitorFromDeviceIndex(source_id, &monitor)) {
     66    RTC_LOG(LS_WARNING) << "GetHmonitorFromDeviceIndex failed.";
     67  }
     68  return GetDpiForMonitor(monitor);
     69 }
     70 
     71 }  // namespace webrtc