blob: c535ae86feaea87c8a3595a5ee9bbed6e7237955 [file] [log] [blame]
sergeyu@chromium.org3d34f662013-06-04 18:51:231/*
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
kwiberg2bb3afa2016-03-16 22:58:0811#include <memory>
kwiberg0eb15ed2015-12-17 11:04:1512#include <utility>
13
Mirko Bonadei92ea95e2017-09-15 04:47:3114#include "modules/desktop_capture/blank_detector_desktop_capturer_wrapper.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3115#include "modules/desktop_capture/desktop_capture_options.h"
Yves Gerey665174f2018-06-19 13:03:0516#include "modules/desktop_capture/desktop_capturer.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "modules/desktop_capture/fallback_desktop_capturer_wrapper.h"
18#include "modules/desktop_capture/rgba_color.h"
19#include "modules/desktop_capture/win/screen_capturer_win_directx.h"
20#include "modules/desktop_capture/win/screen_capturer_win_gdi.h"
21#include "modules/desktop_capture/win/screen_capturer_win_magnifier.h"
sergeyu@chromium.org3d34f662013-06-04 18:51:2322
23namespace webrtc {
24
zijieheccf57a72017-03-03 22:40:1525namespace {
26
zijiehe6dd77c42017-06-19 20:59:4227std::unique_ptr<DesktopCapturer> CreateScreenCapturerWinDirectx() {
Yves Gerey665174f2018-06-19 13:03:0528 std::unique_ptr<DesktopCapturer> capturer(new ScreenCapturerWinDirectx());
zijieheccf57a72017-03-03 22:40:1529 capturer.reset(new BlankDetectorDesktopCapturerWrapper(
30 std::move(capturer), RgbaColor(0, 0, 0, 0)));
31 return capturer;
32}
33
henrika92042102023-03-25 14:29:3034std::unique_ptr<DesktopCapturer> CreateScreenCapturerWinMagnifier() {
35 std::unique_ptr<DesktopCapturer> capturer(new ScreenCapturerWinMagnifier());
36 return capturer;
37}
38
zijieheccf57a72017-03-03 22:40:1539} // namespace
40
sergeyu@chromium.org3d34f662013-06-04 18:51:2341// static
zijiehe54fd5792016-11-02 21:49:3542std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer(
43 const DesktopCaptureOptions& options) {
henrika92042102023-03-25 14:29:3044 // Default capturer if no options are enabled is GDI.
zijieheccf57a72017-03-03 22:40:1545 std::unique_ptr<DesktopCapturer> capturer(new ScreenCapturerWinGdi(options));
henrika92042102023-03-25 14:29:3046
47 // If DirectX is enabled use it as main capturer with GDI as fallback.
zijiehe6dd77c42017-06-19 20:59:4248 if (options.allow_directx_capturer()) {
Artem Titovcec43432021-07-28 21:35:3949 // `dxgi_duplicator_controller` should be alive in this scope to ensure it
zijiehe6dd77c42017-06-19 20:59:4250 // won't unload DxgiDuplicatorController.
51 auto dxgi_duplicator_controller = DxgiDuplicatorController::Instance();
52 if (ScreenCapturerWinDirectx::IsSupported()) {
53 capturer.reset(new FallbackDesktopCapturerWrapper(
54 CreateScreenCapturerWinDirectx(), std::move(capturer)));
henrika92042102023-03-25 14:29:3055 return capturer;
zijiehe6dd77c42017-06-19 20:59:4256 }
henrika92042102023-03-25 14:29:3057 } else if (options.allow_use_magnification_api()) {
zijiehe3fa87f72017-02-22 21:47:0058 // ScreenCapturerWinMagnifier cannot work on Windows XP or earlier, as well
59 // as 64-bit only Windows, and it may randomly crash on multi-screen
60 // systems. So we may need to fallback to use original capturer.
61 capturer.reset(new FallbackDesktopCapturerWrapper(
henrika92042102023-03-25 14:29:3062 CreateScreenCapturerWinMagnifier(), std::move(capturer)));
63 return capturer;
zijiehe54fd5792016-11-02 21:49:3564 }
65
henrika92042102023-03-25 14:29:3066 // Use GDI as default capturer without any fallback solution.
zijiehe54fd5792016-11-02 21:49:3567 return capturer;
68}
69
sergeyu@chromium.org3d34f662013-06-04 18:51:2370} // namespace webrtc