tor-browser

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

screen_capturer_win.cc (2600B)


      1 /*
      2 *  Copyright (c) 2013 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 <memory>
     12 #include <utility>
     13 
     14 #include "modules/desktop_capture/blank_detector_desktop_capturer_wrapper.h"
     15 #include "modules/desktop_capture/desktop_capture_options.h"
     16 #include "modules/desktop_capture/desktop_capturer.h"
     17 #include "modules/desktop_capture/fallback_desktop_capturer_wrapper.h"
     18 #include "modules/desktop_capture/rgba_color.h"
     19 #include "modules/desktop_capture/win/dxgi_duplicator_controller.h"
     20 #include "modules/desktop_capture/win/screen_capturer_win_directx.h"
     21 #include "modules/desktop_capture/win/screen_capturer_win_gdi.h"
     22 #include "rtc_base/logging.h"
     23 
     24 namespace webrtc {
     25 
     26 namespace {
     27 
     28 std::unique_ptr<DesktopCapturer> CreateScreenCapturerWinDirectx(
     29    const DesktopCaptureOptions& options) {
     30  RTC_LOG(LS_INFO)
     31      << "video capture: DesktopCapturer::CreateRawScreenCapturer creates "
     32         "DesktopCapturer of type ScreenCapturerWinDirectx";
     33  std::unique_ptr<DesktopCapturer> capturer(
     34      new ScreenCapturerWinDirectx(options));
     35  capturer.reset(new BlankDetectorDesktopCapturerWrapper(
     36      std::move(capturer), RgbaColor(0, 0, 0, 0)));
     37  return capturer;
     38 }
     39 
     40 }  // namespace
     41 
     42 // static
     43 std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer(
     44    const DesktopCaptureOptions& options) {
     45  // Default capturer if no options are enabled is GDI.
     46  RTC_LOG(LS_INFO) << "video capture: DesktopCapturer::CreateRawScreenCapturer "
     47                      "creates DesktopCapturer of type ScreenCapturerWinGdi";
     48  std::unique_ptr<DesktopCapturer> capturer(new ScreenCapturerWinGdi(options));
     49 
     50  // If DirectX is enabled use it as main capturer with GDI as fallback.
     51  if (options.allow_directx_capturer()) {
     52    // `dxgi_duplicator_controller` should be alive in this scope to ensure it
     53    // won't unload DxgiDuplicatorController.
     54    auto dxgi_duplicator_controller = DxgiDuplicatorController::Instance();
     55    if (ScreenCapturerWinDirectx::IsSupported()) {
     56      capturer.reset(new FallbackDesktopCapturerWrapper(
     57          CreateScreenCapturerWinDirectx(options), std::move(capturer)));
     58      return capturer;
     59    }
     60  }
     61 
     62  // Use GDI as default capturer without any fallback solution.
     63  return capturer;
     64 }
     65 
     66 }  // namespace webrtc