sergeyu@chromium.org | 3d34f66 | 2013-06-04 18:51:23 | [diff] [blame] | 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 | |
kwiberg | 2bb3afa | 2016-03-16 22:58:08 | [diff] [blame] | 11 | #include <memory> |
kwiberg | 0eb15ed | 2015-12-17 11:04:15 | [diff] [blame] | 12 | #include <utility> |
| 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 14 | #include "modules/desktop_capture/blank_detector_desktop_capturer_wrapper.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 15 | #include "modules/desktop_capture/desktop_capture_options.h" |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 16 | #include "modules/desktop_capture/desktop_capturer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 17 | #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.org | 3d34f66 | 2013-06-04 18:51:23 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | |
zijiehe | ccf57a7 | 2017-03-03 22:40:15 | [diff] [blame] | 25 | namespace { |
| 26 | |
zijiehe | 6dd77c4 | 2017-06-19 20:59:42 | [diff] [blame] | 27 | std::unique_ptr<DesktopCapturer> CreateScreenCapturerWinDirectx() { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 28 | std::unique_ptr<DesktopCapturer> capturer(new ScreenCapturerWinDirectx()); |
zijiehe | ccf57a7 | 2017-03-03 22:40:15 | [diff] [blame] | 29 | capturer.reset(new BlankDetectorDesktopCapturerWrapper( |
| 30 | std::move(capturer), RgbaColor(0, 0, 0, 0))); |
| 31 | return capturer; |
| 32 | } |
| 33 | |
henrika | 9204210 | 2023-03-25 14:29:30 | [diff] [blame^] | 34 | std::unique_ptr<DesktopCapturer> CreateScreenCapturerWinMagnifier() { |
| 35 | std::unique_ptr<DesktopCapturer> capturer(new ScreenCapturerWinMagnifier()); |
| 36 | return capturer; |
| 37 | } |
| 38 | |
zijiehe | ccf57a7 | 2017-03-03 22:40:15 | [diff] [blame] | 39 | } // namespace |
| 40 | |
sergeyu@chromium.org | 3d34f66 | 2013-06-04 18:51:23 | [diff] [blame] | 41 | // static |
zijiehe | 54fd579 | 2016-11-02 21:49:35 | [diff] [blame] | 42 | std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer( |
| 43 | const DesktopCaptureOptions& options) { |
henrika | 9204210 | 2023-03-25 14:29:30 | [diff] [blame^] | 44 | // Default capturer if no options are enabled is GDI. |
zijiehe | ccf57a7 | 2017-03-03 22:40:15 | [diff] [blame] | 45 | std::unique_ptr<DesktopCapturer> capturer(new ScreenCapturerWinGdi(options)); |
henrika | 9204210 | 2023-03-25 14:29:30 | [diff] [blame^] | 46 | |
| 47 | // If DirectX is enabled use it as main capturer with GDI as fallback. |
zijiehe | 6dd77c4 | 2017-06-19 20:59:42 | [diff] [blame] | 48 | if (options.allow_directx_capturer()) { |
Artem Titov | cec4343 | 2021-07-28 21:35:39 | [diff] [blame] | 49 | // `dxgi_duplicator_controller` should be alive in this scope to ensure it |
zijiehe | 6dd77c4 | 2017-06-19 20:59:42 | [diff] [blame] | 50 | // 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))); |
henrika | 9204210 | 2023-03-25 14:29:30 | [diff] [blame^] | 55 | return capturer; |
zijiehe | 6dd77c4 | 2017-06-19 20:59:42 | [diff] [blame] | 56 | } |
henrika | 9204210 | 2023-03-25 14:29:30 | [diff] [blame^] | 57 | } else if (options.allow_use_magnification_api()) { |
zijiehe | 3fa87f7 | 2017-02-22 21:47:00 | [diff] [blame] | 58 | // 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( |
henrika | 9204210 | 2023-03-25 14:29:30 | [diff] [blame^] | 62 | CreateScreenCapturerWinMagnifier(), std::move(capturer))); |
| 63 | return capturer; |
zijiehe | 54fd579 | 2016-11-02 21:49:35 | [diff] [blame] | 64 | } |
| 65 | |
henrika | 9204210 | 2023-03-25 14:29:30 | [diff] [blame^] | 66 | // Use GDI as default capturer without any fallback solution. |
zijiehe | 54fd579 | 2016-11-02 21:49:35 | [diff] [blame] | 67 | return capturer; |
| 68 | } |
| 69 | |
sergeyu@chromium.org | 3d34f66 | 2013-06-04 18:51:23 | [diff] [blame] | 70 | } // namespace webrtc |