OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/aura_window_capture_machine.h" | 5 #include "content/browser/media/capture/aura_window_capture_machine.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
12 #include "cc/output/copy_output_request.h" | 12 #include "cc/output/copy_output_request.h" |
13 #include "cc/output/copy_output_result.h" | 13 #include "cc/output/copy_output_result.h" |
14 #include "components/viz/display_compositor/gl_helper.h" | 14 #include "components/viz/display_compositor/gl_helper.h" |
15 #include "content/browser/compositor/image_transport_factory.h" | 15 #include "content/browser/compositor/image_transport_factory.h" |
16 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" | 16 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "device/power_save_blocker/power_save_blocker.h" | 18 #include "content/public/common/service_manager_connection.h" |
| 19 #include "device/wake_lock/public/interfaces/wake_lock_provider.mojom.h" |
19 #include "media/base/video_util.h" | 20 #include "media/base/video_util.h" |
20 #include "media/capture/content/thread_safe_capture_oracle.h" | 21 #include "media/capture/content/thread_safe_capture_oracle.h" |
21 #include "media/capture/content/video_capture_oracle.h" | 22 #include "media/capture/content/video_capture_oracle.h" |
22 #include "media/capture/video_capture_types.h" | 23 #include "media/capture/video_capture_types.h" |
| 24 #include "services/device/public/interfaces/constants.mojom.h" |
| 25 #include "services/service_manager/public/cpp/connector.h" |
23 #include "skia/ext/image_operations.h" | 26 #include "skia/ext/image_operations.h" |
24 #include "third_party/skia/include/core/SkBitmap.h" | 27 #include "third_party/skia/include/core/SkBitmap.h" |
25 #include "ui/aura/client/screen_position_client.h" | 28 #include "ui/aura/client/screen_position_client.h" |
26 #include "ui/aura/env.h" | 29 #include "ui/aura/env.h" |
27 #include "ui/aura/window.h" | 30 #include "ui/aura/window.h" |
28 #include "ui/aura/window_observer.h" | 31 #include "ui/aura/window_observer.h" |
29 #include "ui/aura/window_tree_host.h" | 32 #include "ui/aura/window_tree_host.h" |
30 #include "ui/base/cursor/cursors_aura.h" | 33 #include "ui/base/cursor/cursors_aura.h" |
31 #include "ui/compositor/compositor.h" | 34 #include "ui/compositor/compositor.h" |
32 #include "ui/compositor/dip_util.h" | 35 #include "ui/compositor/dip_util.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // Update capture size. | 82 // Update capture size. |
80 UpdateCaptureSize(); | 83 UpdateCaptureSize(); |
81 | 84 |
82 // Start observing compositor updates. | 85 // Start observing compositor updates. |
83 aura::WindowTreeHost* const host = desktop_window_->GetHost(); | 86 aura::WindowTreeHost* const host = desktop_window_->GetHost(); |
84 ui::Compositor* const compositor = host ? host->compositor() : nullptr; | 87 ui::Compositor* const compositor = host ? host->compositor() : nullptr; |
85 if (!compositor) | 88 if (!compositor) |
86 return false; | 89 return false; |
87 compositor->AddAnimationObserver(this); | 90 compositor->AddAnimationObserver(this); |
88 | 91 |
89 power_save_blocker_.reset(new device::PowerSaveBlocker( | 92 DCHECK(!wake_lock_); |
90 device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 93 // Request Wake Lock. In some testing contexts, the service manager |
91 device::PowerSaveBlocker::kReasonOther, "DesktopCaptureDevice is running", | 94 // connection isn't initialized. |
92 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 95 if (ServiceManagerConnection::GetForProcess()) { |
93 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 96 service_manager::Connector* connector = |
| 97 ServiceManagerConnection::GetForProcess()->GetConnector(); |
| 98 DCHECK(connector); |
| 99 device::mojom::WakeLockProviderPtr wake_lock_provider; |
| 100 connector->BindInterface(device::mojom::kServiceName, |
| 101 mojo::MakeRequest(&wake_lock_provider)); |
| 102 wake_lock_provider->GetWakeLockWithoutContext( |
| 103 device::mojom::WakeLockType::PreventDisplaySleep, |
| 104 device::mojom::WakeLockReason::ReasonOther, |
| 105 "Desktop capturer is running", mojo::MakeRequest(&wake_lock_)); |
| 106 |
| 107 wake_lock_->RequestWakeLock(); |
| 108 } |
94 | 109 |
95 return true; | 110 return true; |
96 } | 111 } |
97 | 112 |
98 void AuraWindowCaptureMachine::Suspend() { | 113 void AuraWindowCaptureMachine::Suspend() { |
99 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 114 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
100 base::Bind(&AuraWindowCaptureMachine::InternalSuspend, | 115 base::Bind(&AuraWindowCaptureMachine::InternalSuspend, |
101 base::Unretained(this))); | 116 base::Unretained(this))); |
102 } | 117 } |
103 | 118 |
(...skipping 26 matching lines...) Expand all Loading... |
130 base::Unretained(this), | 145 base::Unretained(this), |
131 callback)); | 146 callback)); |
132 } | 147 } |
133 | 148 |
134 void AuraWindowCaptureMachine::InternalStop(const base::Closure& callback) { | 149 void AuraWindowCaptureMachine::InternalStop(const base::Closure& callback) { |
135 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 150 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
136 | 151 |
137 // Cancel any and all outstanding callbacks owned by external modules. | 152 // Cancel any and all outstanding callbacks owned by external modules. |
138 weak_factory_.InvalidateWeakPtrs(); | 153 weak_factory_.InvalidateWeakPtrs(); |
139 | 154 |
140 power_save_blocker_.reset(); | 155 if (wake_lock_) |
141 | 156 wake_lock_->CancelWakeLock(); |
142 // Stop observing compositor and window events. | 157 // Stop observing compositor and window events. |
143 if (desktop_window_) { | 158 if (desktop_window_) { |
144 if (aura::WindowTreeHost* host = desktop_window_->GetHost()) { | 159 if (aura::WindowTreeHost* host = desktop_window_->GetHost()) { |
145 if (ui::Compositor* compositor = host->compositor()) | 160 if (ui::Compositor* compositor = host->compositor()) |
146 compositor->RemoveAnimationObserver(this); | 161 compositor->RemoveAnimationObserver(this); |
147 } | 162 } |
148 desktop_window_->RemoveObserver(this); | 163 desktop_window_->RemoveObserver(this); |
149 desktop_window_ = NULL; | 164 desktop_window_ = NULL; |
150 cursor_renderer_.reset(); | 165 cursor_renderer_.reset(); |
151 } | 166 } |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 Capture(timestamp); | 455 Capture(timestamp); |
441 } | 456 } |
442 | 457 |
443 void AuraWindowCaptureMachine::OnCompositingShuttingDown( | 458 void AuraWindowCaptureMachine::OnCompositingShuttingDown( |
444 ui::Compositor* compositor) { | 459 ui::Compositor* compositor) { |
445 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 460 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
446 compositor->RemoveAnimationObserver(this); | 461 compositor->RemoveAnimationObserver(this); |
447 } | 462 } |
448 | 463 |
449 } // namespace content | 464 } // namespace content |
OLD | NEW |