| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/media/capture/desktop_capture_device.h" | 5 #include "content/browser/media/capture/desktop_capture_device.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 std::unique_ptr<service_manager::Connector> GetServiceConnector() { | 70 std::unique_ptr<service_manager::Connector> GetServiceConnector() { |
| 71 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 71 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 72 | 72 |
| 73 service_manager::Connector* connector = | 73 service_manager::Connector* connector = |
| 74 ServiceManagerConnection::GetForProcess()->GetConnector(); | 74 ServiceManagerConnection::GetForProcess()->GetConnector(); |
| 75 | 75 |
| 76 DCHECK(connector); | 76 DCHECK(connector); |
| 77 return connector->Clone(); | 77 return connector->Clone(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Creates a DesktopCaptureOptions with required settings. This function should |
| 81 // be consistent with CreateDesktopCaptureOptions() function in |
| 82 // desktop_capture_base.cc file at |
| 83 // https://cs.chromium.org/chromium/src/chrome/browser/extensions/api/desktop_ca
pture/desktop_capture_base.cc |
| 84 webrtc::DesktopCaptureOptions CreateDesktopCaptureOptions() { |
| 85 auto options = webrtc::DesktopCaptureOptions::CreateDefault(); |
| 86 // Leave desktop effects enabled during WebRTC captures. |
| 87 options.set_disable_effects(false); |
| 88 #if defined(OS_WIN) |
| 89 static constexpr base::Feature kDirectXCapturer{ |
| 90 "DirectXCapturer", |
| 91 base::FEATURE_ENABLED_BY_DEFAULT}; |
| 92 if (base::FeatureList::IsEnabled(kDirectXCapturer)) { |
| 93 options.set_allow_directx_capturer(true); |
| 94 options.set_allow_use_magnification_api(false); |
| 95 } else { |
| 96 options.set_allow_use_magnification_api(true); |
| 97 } |
| 98 #endif |
| 99 return options; |
| 100 } |
| 101 |
| 80 } // namespace | 102 } // namespace |
| 81 | 103 |
| 82 #if defined(OS_WIN) | |
| 83 const base::Feature kDirectXCapturer{"DirectXCapturer", | |
| 84 base::FEATURE_ENABLED_BY_DEFAULT}; | |
| 85 #endif | |
| 86 | |
| 87 class DesktopCaptureDevice::Core : public webrtc::DesktopCapturer::Callback { | 104 class DesktopCaptureDevice::Core : public webrtc::DesktopCapturer::Callback { |
| 88 public: | 105 public: |
| 89 Core(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 106 Core(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 90 std::unique_ptr<webrtc::DesktopCapturer> capturer, | 107 std::unique_ptr<webrtc::DesktopCapturer> capturer, |
| 91 DesktopMediaID::Type type); | 108 DesktopMediaID::Type type); |
| 92 ~Core() override; | 109 ~Core() override; |
| 93 | 110 |
| 94 // Implementation of VideoCaptureDevice methods. | 111 // Implementation of VideoCaptureDevice methods. |
| 95 void AllocateAndStart(const media::VideoCaptureParams& params, | 112 void AllocateAndStart(const media::VideoCaptureParams& params, |
| 96 std::unique_ptr<Client> client); | 113 std::unique_ptr<Client> client); |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 device::mojom::WakeLockType::PreventDisplaySleep, | 411 device::mojom::WakeLockType::PreventDisplaySleep, |
| 395 device::mojom::WakeLockReason::ReasonOther, "Desktop capture is running", | 412 device::mojom::WakeLockReason::ReasonOther, "Desktop capture is running", |
| 396 mojo::MakeRequest(&wake_lock_)); | 413 mojo::MakeRequest(&wake_lock_)); |
| 397 | 414 |
| 398 wake_lock_->RequestWakeLock(); | 415 wake_lock_->RequestWakeLock(); |
| 399 } | 416 } |
| 400 | 417 |
| 401 // static | 418 // static |
| 402 std::unique_ptr<media::VideoCaptureDevice> DesktopCaptureDevice::Create( | 419 std::unique_ptr<media::VideoCaptureDevice> DesktopCaptureDevice::Create( |
| 403 const DesktopMediaID& source) { | 420 const DesktopMediaID& source) { |
| 404 webrtc::DesktopCaptureOptions options = | 421 auto options = CreateDesktopCaptureOptions(); |
| 405 webrtc::DesktopCaptureOptions::CreateDefault(); | |
| 406 // Leave desktop effects enabled during WebRTC captures. | |
| 407 options.set_disable_effects(false); | |
| 408 | |
| 409 #if defined(OS_WIN) | |
| 410 if (!base::FeatureList::IsEnabled(kDirectXCapturer)) { | |
| 411 options.set_allow_use_magnification_api(true); | |
| 412 } else { | |
| 413 options.set_allow_directx_capturer(true); | |
| 414 options.set_allow_use_magnification_api(false); | |
| 415 } | |
| 416 #endif | |
| 417 | |
| 418 std::unique_ptr<webrtc::DesktopCapturer> capturer; | 422 std::unique_ptr<webrtc::DesktopCapturer> capturer; |
| 419 | 423 |
| 420 switch (source.type) { | 424 switch (source.type) { |
| 421 case DesktopMediaID::TYPE_SCREEN: { | 425 case DesktopMediaID::TYPE_SCREEN: { |
| 422 std::unique_ptr<webrtc::DesktopCapturer> screen_capturer( | 426 std::unique_ptr<webrtc::DesktopCapturer> screen_capturer( |
| 423 webrtc::DesktopCapturer::CreateScreenCapturer(options)); | 427 webrtc::DesktopCapturer::CreateScreenCapturer(options)); |
| 424 if (screen_capturer && screen_capturer->SelectSource(source.id)) { | 428 if (screen_capturer && screen_capturer->SelectSource(source.id)) { |
| 425 capturer.reset(new webrtc::DesktopAndCursorComposer( | 429 capturer.reset(new webrtc::DesktopAndCursorComposer( |
| 426 screen_capturer.release(), | 430 screen_capturer.release(), |
| 427 webrtc::MouseCursorMonitor::CreateForScreen(options, source.id))); | 431 webrtc::MouseCursorMonitor::CreateForScreen(options, source.id))); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 #else | 501 #else |
| 498 base::MessageLoop::Type thread_type = base::MessageLoop::TYPE_DEFAULT; | 502 base::MessageLoop::Type thread_type = base::MessageLoop::TYPE_DEFAULT; |
| 499 #endif | 503 #endif |
| 500 | 504 |
| 501 thread_.StartWithOptions(base::Thread::Options(thread_type, 0)); | 505 thread_.StartWithOptions(base::Thread::Options(thread_type, 0)); |
| 502 | 506 |
| 503 core_.reset(new Core(thread_.task_runner(), std::move(capturer), type)); | 507 core_.reset(new Core(thread_.task_runner(), std::move(capturer), type)); |
| 504 } | 508 } |
| 505 | 509 |
| 506 } // namespace content | 510 } // namespace content |
| OLD | NEW |