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.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/timer/timer.h" |
12 #include "cc/output/copy_output_request.h" | 13 #include "cc/output/copy_output_request.h" |
13 #include "cc/output/copy_output_result.h" | 14 #include "cc/output/copy_output_result.h" |
14 #include "content/browser/compositor/gl_helper.h" | 15 #include "content/browser/compositor/gl_helper.h" |
15 #include "content/browser/compositor/image_transport_factory.h" | 16 #include "content/browser/compositor/image_transport_factory.h" |
16 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" | 17 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/power_save_blocker.h" | 19 #include "content/public/browser/power_save_blocker.h" |
19 #include "media/base/video_capture_types.h" | 20 #include "media/base/video_capture_types.h" |
20 #include "media/base/video_util.h" | 21 #include "media/base/video_util.h" |
21 #include "media/capture/content/thread_safe_capture_oracle.h" | 22 #include "media/capture/content/thread_safe_capture_oracle.h" |
22 #include "media/capture/content/video_capture_oracle.h" | 23 #include "media/capture/content/video_capture_oracle.h" |
23 #include "skia/ext/image_operations.h" | 24 #include "skia/ext/image_operations.h" |
24 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
25 #include "ui/aura/client/screen_position_client.h" | 26 #include "ui/aura/client/screen_position_client.h" |
26 #include "ui/aura/env.h" | 27 #include "ui/aura/env.h" |
27 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
28 #include "ui/aura/window_observer.h" | 29 #include "ui/aura/window_observer.h" |
29 #include "ui/aura/window_tree_host.h" | 30 #include "ui/aura/window_tree_host.h" |
30 #include "ui/base/cursor/cursors_aura.h" | 31 #include "ui/base/cursor/cursors_aura.h" |
31 #include "ui/compositor/compositor.h" | 32 #include "ui/compositor/compositor.h" |
32 #include "ui/compositor/dip_util.h" | 33 #include "ui/compositor/dip_util.h" |
33 #include "ui/compositor/layer.h" | 34 #include "ui/compositor/layer.h" |
34 #include "ui/gfx/screen.h" | 35 #include "ui/gfx/screen.h" |
35 #include "ui/wm/public/activation_client.h" | 36 #include "ui/wm/public/activation_client.h" |
36 | 37 |
37 namespace content { | 38 namespace content { |
38 | 39 |
39 AuraWindowCaptureMachine::AuraWindowCaptureMachine() | 40 AuraWindowCaptureMachine::AuraWindowCaptureMachine() |
40 : desktop_window_(NULL), | 41 : desktop_window_(NULL), |
| 42 timer_(true, true), |
41 screen_capture_(false), | 43 screen_capture_(false), |
42 weak_factory_(this) {} | 44 weak_factory_(this) {} |
43 | 45 |
44 AuraWindowCaptureMachine::~AuraWindowCaptureMachine() {} | 46 AuraWindowCaptureMachine::~AuraWindowCaptureMachine() {} |
45 | 47 |
46 void AuraWindowCaptureMachine::Start( | 48 void AuraWindowCaptureMachine::Start( |
47 const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, | 49 const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, |
48 const media::VideoCaptureParams& params, | 50 const media::VideoCaptureParams& params, |
49 const base::Callback<void(bool)> callback) { | 51 const base::Callback<void(bool)> callback) { |
50 // Starts the capture machine asynchronously. | 52 // Starts the capture machine asynchronously. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // Start observing compositor updates. | 84 // Start observing compositor updates. |
83 if (desktop_window_->GetHost()) | 85 if (desktop_window_->GetHost()) |
84 desktop_window_->GetHost()->compositor()->AddObserver(this); | 86 desktop_window_->GetHost()->compositor()->AddObserver(this); |
85 | 87 |
86 power_save_blocker_.reset( | 88 power_save_blocker_.reset( |
87 PowerSaveBlocker::Create( | 89 PowerSaveBlocker::Create( |
88 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 90 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, |
89 PowerSaveBlocker::kReasonOther, | 91 PowerSaveBlocker::kReasonOther, |
90 "DesktopCaptureDevice is running").release()); | 92 "DesktopCaptureDevice is running").release()); |
91 | 93 |
| 94 // Starts timer. |
| 95 timer_.Start(FROM_HERE, |
| 96 std::max(oracle_proxy_->min_capture_period(), |
| 97 base::TimeDelta::FromMilliseconds(media:: |
| 98 VideoCaptureOracle::kMinTimerPollPeriodMillis)), |
| 99 base::Bind(&AuraWindowCaptureMachine::Capture, |
| 100 base::Unretained(this), false)); |
| 101 |
92 return true; | 102 return true; |
93 } | 103 } |
94 | 104 |
95 void AuraWindowCaptureMachine::Stop(const base::Closure& callback) { | 105 void AuraWindowCaptureMachine::Stop(const base::Closure& callback) { |
96 // Stops the capture machine asynchronously. | 106 // Stops the capture machine asynchronously. |
97 BrowserThread::PostTask( | 107 BrowserThread::PostTask( |
98 BrowserThread::UI, FROM_HERE, base::Bind( | 108 BrowserThread::UI, FROM_HERE, base::Bind( |
99 &AuraWindowCaptureMachine::InternalStop, | 109 &AuraWindowCaptureMachine::InternalStop, |
100 base::Unretained(this), | 110 base::Unretained(this), |
101 callback)); | 111 callback)); |
(...skipping 11 matching lines...) Expand all Loading... |
113 if (desktop_window_) { | 123 if (desktop_window_) { |
114 aura::WindowTreeHost* window_host = desktop_window_->GetHost(); | 124 aura::WindowTreeHost* window_host = desktop_window_->GetHost(); |
115 // In the host destructor the compositor is destroyed before the window. | 125 // In the host destructor the compositor is destroyed before the window. |
116 if (window_host && window_host->compositor()) | 126 if (window_host && window_host->compositor()) |
117 window_host->compositor()->RemoveObserver(this); | 127 window_host->compositor()->RemoveObserver(this); |
118 desktop_window_->RemoveObserver(this); | 128 desktop_window_->RemoveObserver(this); |
119 desktop_window_ = NULL; | 129 desktop_window_ = NULL; |
120 cursor_renderer_.reset(); | 130 cursor_renderer_.reset(); |
121 } | 131 } |
122 | 132 |
| 133 // Stop timer. |
| 134 timer_.Stop(); |
| 135 |
123 callback.Run(); | 136 callback.Run(); |
124 } | 137 } |
125 | 138 |
126 void AuraWindowCaptureMachine::MaybeCaptureForRefresh() { | |
127 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
128 Capture(false); | |
129 } | |
130 | |
131 void AuraWindowCaptureMachine::SetWindow(aura::Window* window) { | 139 void AuraWindowCaptureMachine::SetWindow(aura::Window* window) { |
132 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 140 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
133 | 141 |
134 DCHECK(!desktop_window_); | 142 DCHECK(!desktop_window_); |
135 desktop_window_ = window; | 143 desktop_window_ = window; |
136 cursor_renderer_.reset(new CursorRendererAura(window, kCursorAlwaysEnabled)); | 144 cursor_renderer_.reset(new CursorRendererAura(window, kCursorAlwaysEnabled)); |
137 | 145 |
138 // Start observing window events. | 146 // Start observing window events. |
139 desktop_window_->AddObserver(this); | 147 desktop_window_->AddObserver(this); |
140 | 148 |
(...skipping 23 matching lines...) Expand all Loading... |
164 | 172 |
165 scoped_refptr<media::VideoFrame> frame; | 173 scoped_refptr<media::VideoFrame> frame; |
166 media::ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; | 174 media::ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; |
167 | 175 |
168 // TODO(miu): Need to fix this so the compositor is providing the presentation | 176 // TODO(miu): Need to fix this so the compositor is providing the presentation |
169 // timestamps and damage regions, to leverage the frame timestamp rewriting | 177 // timestamps and damage regions, to leverage the frame timestamp rewriting |
170 // logic. http://crbug.com/492839 | 178 // logic. http://crbug.com/492839 |
171 const base::TimeTicks start_time = base::TimeTicks::Now(); | 179 const base::TimeTicks start_time = base::TimeTicks::Now(); |
172 const media::VideoCaptureOracle::Event event = | 180 const media::VideoCaptureOracle::Event event = |
173 dirty ? media::VideoCaptureOracle::kCompositorUpdate | 181 dirty ? media::VideoCaptureOracle::kCompositorUpdate |
174 : media::VideoCaptureOracle::kActiveRefreshRequest; | 182 : media::VideoCaptureOracle::kTimerPoll; |
175 if (oracle_proxy_->ObserveEventAndDecideCapture( | 183 if (oracle_proxy_->ObserveEventAndDecideCapture( |
176 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { | 184 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { |
177 scoped_ptr<cc::CopyOutputRequest> request = | 185 scoped_ptr<cc::CopyOutputRequest> request = |
178 cc::CopyOutputRequest::CreateRequest( | 186 cc::CopyOutputRequest::CreateRequest( |
179 base::Bind(&AuraWindowCaptureMachine::DidCopyOutput, | 187 base::Bind(&AuraWindowCaptureMachine::DidCopyOutput, |
180 weak_factory_.GetWeakPtr(), | 188 weak_factory_.GetWeakPtr(), |
181 frame, start_time, capture_frame_cb)); | 189 frame, start_time, capture_frame_cb)); |
182 gfx::Rect window_rect = gfx::Rect(desktop_window_->bounds().width(), | 190 gfx::Rect window_rect = gfx::Rect(desktop_window_->bounds().width(), |
183 desktop_window_->bounds().height()); | 191 desktop_window_->bounds().height()); |
184 request->set_area(window_rect); | 192 request->set_area(window_rect); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 // TODO(miu): The CopyOutputRequest should be made earlier, at WillCommit(). | 360 // TODO(miu): The CopyOutputRequest should be made earlier, at WillCommit(). |
353 // http://crbug.com/492839 | 361 // http://crbug.com/492839 |
354 BrowserThread::PostTask( | 362 BrowserThread::PostTask( |
355 BrowserThread::UI, | 363 BrowserThread::UI, |
356 FROM_HERE, | 364 FROM_HERE, |
357 base::Bind(&AuraWindowCaptureMachine::Capture, weak_factory_.GetWeakPtr(), | 365 base::Bind(&AuraWindowCaptureMachine::Capture, weak_factory_.GetWeakPtr(), |
358 true)); | 366 true)); |
359 } | 367 } |
360 | 368 |
361 } // namespace content | 369 } // namespace content |
OLD | NEW |